Debian Codegraph @

drivers/iio/imu/inv_icm45600/inv_icm45600_spi.c

raw
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Copyright (C) 2025 InvenSense, Inc. */
3
4 #include <linux/bitfield.h>
5 #include <linux/device.h>
6 #include <linux/err.h>
7 #include <linux/module.h>
8 #include <linux/mod_devicetable.h>
9 #include <linux/regmap.h>
10
11 #include <linux/spi/spi.h>
12
13 #include "inv_icm45600.h"
14
15 static const struct regmap_config inv_icm45600_regmap_config = {
16 .reg_bits = 8,
17 .val_bits = 8,
18 };
19
20 static int inv_icm45600_spi_bus_setup(struct inv_icm45600_state *st)
21 {
22 /* Set slew rates for SPI. */
23 return regmap_update_bits(st->map, INV_ICM45600_REG_DRIVE_CONFIG0,
24 INV_ICM45600_DRIVE_CONFIG0_SPI_MASK,
25 FIELD_PREP(INV_ICM45600_DRIVE_CONFIG0_SPI_MASK,
26 INV_ICM45600_SPI_SLEW_RATE_5NS));
27 }
28
29 static int inv_icm45600_probe(struct spi_device *spi)
30 {
31 const struct inv_icm45600_chip_info *chip_info;
32 struct regmap *regmap;
33
34 chip_info = spi_get_device_match_data(spi);
35 if (!chip_info)
36 return -ENODEV;
37
38 /* Use SPI specific regmap. */
39 regmap = devm_regmap_init_spi(spi, &inv_icm45600_regmap_config);
40 if (IS_ERR(regmap))
41 return PTR_ERR(regmap);
42
43 return inv_icm45600_core_probe(regmap, chip_info, true,
44 inv_icm45600_spi_bus_setup);
45 }
46
47 /*
48 * The device id table is used to identify which device is
49 * supported by this driver.
50 */
51 static const struct spi_device_id inv_icm45600_id[] = {
52 { "icm45605", (kernel_ulong_t)&inv_icm45605_chip_info },
53 { "icm45606", (kernel_ulong_t)&inv_icm45606_chip_info },
54 { "icm45608", (kernel_ulong_t)&inv_icm45608_chip_info },
55 { "icm45634", (kernel_ulong_t)&inv_icm45634_chip_info },
56 { "icm45686", (kernel_ulong_t)&inv_icm45686_chip_info },
57 { "icm45687", (kernel_ulong_t)&inv_icm45687_chip_info },
58 { "icm45688p", (kernel_ulong_t)&inv_icm45688p_chip_info },
59 { "icm45689", (kernel_ulong_t)&inv_icm45689_chip_info },
60 { }
61 };
62 MODULE_DEVICE_TABLE(spi, inv_icm45600_id);
63
64 static const struct of_device_id inv_icm45600_of_matches[] = {
65 {
66 .compatible = "invensense,icm45605",
67 .data = &inv_icm45605_chip_info,
68 }, {
69 .compatible = "invensense,icm45606",
70 .data = &inv_icm45606_chip_info,
71 }, {
72 .compatible = "invensense,icm45608",
73 .data = &inv_icm45608_chip_info,
74 }, {
75 .compatible = "invensense,icm45634",
76 .data = &inv_icm45634_chip_info,
77 }, {
78 .compatible = "invensense,icm45686",
79 .data = &inv_icm45686_chip_info,
80 }, {
81 .compatible = "invensense,icm45687",
82 .data = &inv_icm45687_chip_info,
83 }, {
84 .compatible = "invensense,icm45688p",
85 .data = &inv_icm45688p_chip_info,
86 }, {
87 .compatible = "invensense,icm45689",
88 .data = &inv_icm45689_chip_info,
89 },
90 { }
91 };
92 MODULE_DEVICE_TABLE(of, inv_icm45600_of_matches);
93
94 static struct spi_driver inv_icm45600_driver = {
95 .driver = {
96 .name = "inv-icm45600-spi",
97 .of_match_table = inv_icm45600_of_matches,
98 .pm = pm_ptr(&inv_icm45600_pm_ops),
99 },
100 .id_table = inv_icm45600_id,
101 .probe = inv_icm45600_probe,
102 };
103 module_spi_driver(inv_icm45600_driver);
104
105 MODULE_AUTHOR("InvenSense, Inc.");
106 MODULE_DESCRIPTION("InvenSense ICM-456xx SPI driver");
107 MODULE_LICENSE("GPL");
108 MODULE_IMPORT_NS("IIO_ICM45600");