This source file includes following definitions.
- inv_mpu_i2c_disable
- inv_mpu_probe
1
2
3
4
5 #include <linux/module.h>
6 #include <linux/acpi.h>
7 #include <linux/spi/spi.h>
8 #include <linux/regmap.h>
9 #include <linux/iio/iio.h>
10 #include "inv_mpu_iio.h"
11
12 static const struct regmap_config inv_mpu_regmap_config = {
13 .reg_bits = 8,
14 .val_bits = 8,
15 };
16
17 static int inv_mpu_i2c_disable(struct iio_dev *indio_dev)
18 {
19 struct inv_mpu6050_state *st = iio_priv(indio_dev);
20 int ret = 0;
21
22 ret = inv_mpu6050_set_power_itg(st, true);
23 if (ret)
24 return ret;
25
26 if (st->reg->i2c_if) {
27 ret = regmap_write(st->map, st->reg->i2c_if,
28 INV_ICM20602_BIT_I2C_IF_DIS);
29 } else {
30 st->chip_config.user_ctrl |= INV_MPU6050_BIT_I2C_IF_DIS;
31 ret = regmap_write(st->map, st->reg->user_ctrl,
32 st->chip_config.user_ctrl);
33 }
34 if (ret) {
35 inv_mpu6050_set_power_itg(st, false);
36 return ret;
37 }
38
39 return inv_mpu6050_set_power_itg(st, false);
40 }
41
42 static int inv_mpu_probe(struct spi_device *spi)
43 {
44 struct regmap *regmap;
45 const struct spi_device_id *spi_id;
46 const struct acpi_device_id *acpi_id;
47 const char *name = NULL;
48 enum inv_devices chip_type;
49
50 if ((spi_id = spi_get_device_id(spi))) {
51 chip_type = (enum inv_devices)spi_id->driver_data;
52 name = spi_id->name;
53 } else if ((acpi_id = acpi_match_device(spi->dev.driver->acpi_match_table, &spi->dev))) {
54 chip_type = (enum inv_devices)acpi_id->driver_data;
55 } else {
56 return -ENODEV;
57 }
58
59 regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config);
60 if (IS_ERR(regmap)) {
61 dev_err(&spi->dev, "Failed to register spi regmap %d\n",
62 (int)PTR_ERR(regmap));
63 return PTR_ERR(regmap);
64 }
65
66 return inv_mpu_core_probe(regmap, spi->irq, name,
67 inv_mpu_i2c_disable, chip_type);
68 }
69
70
71
72
73
74 static const struct spi_device_id inv_mpu_id[] = {
75 {"mpu6000", INV_MPU6000},
76 {"mpu6500", INV_MPU6500},
77 {"mpu9150", INV_MPU9150},
78 {"mpu9250", INV_MPU9250},
79 {"mpu9255", INV_MPU9255},
80 {"icm20608", INV_ICM20608},
81 {"icm20602", INV_ICM20602},
82 {}
83 };
84
85 MODULE_DEVICE_TABLE(spi, inv_mpu_id);
86
87 static const struct acpi_device_id inv_acpi_match[] = {
88 {"INVN6000", INV_MPU6000},
89 { },
90 };
91 MODULE_DEVICE_TABLE(acpi, inv_acpi_match);
92
93 static struct spi_driver inv_mpu_driver = {
94 .probe = inv_mpu_probe,
95 .id_table = inv_mpu_id,
96 .driver = {
97 .acpi_match_table = ACPI_PTR(inv_acpi_match),
98 .name = "inv-mpu6000-spi",
99 .pm = &inv_mpu_pmops,
100 },
101 };
102
103 module_spi_driver(inv_mpu_driver);
104
105 MODULE_AUTHOR("Adriana Reus <adriana.reus@intel.com>");
106 MODULE_DESCRIPTION("Invensense device MPU6000 driver");
107 MODULE_LICENSE("GPL");