1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2015 Intel Corporation Inc.
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"
12 static const struct regmap_config inv_mpu_regmap_config
= {
17 static int inv_mpu_i2c_disable(struct iio_dev
*indio_dev
)
19 struct inv_mpu6050_state
*st
= iio_priv(indio_dev
);
22 ret
= inv_mpu6050_set_power_itg(st
, true);
26 if (st
->reg
->i2c_if
) {
27 ret
= regmap_write(st
->map
, st
->reg
->i2c_if
,
28 INV_ICM20602_BIT_I2C_IF_DIS
);
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
);
35 inv_mpu6050_set_power_itg(st
, false);
39 return inv_mpu6050_set_power_itg(st
, false);
42 static int inv_mpu_probe(struct spi_device
*spi
)
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
;
50 if ((spi_id
= spi_get_device_id(spi
))) {
51 chip_type
= (enum inv_devices
)spi_id
->driver_data
;
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
;
59 regmap
= devm_regmap_init_spi(spi
, &inv_mpu_regmap_config
);
61 dev_err(&spi
->dev
, "Failed to register spi regmap %d\n",
62 (int)PTR_ERR(regmap
));
63 return PTR_ERR(regmap
);
66 return inv_mpu_core_probe(regmap
, spi
->irq
, name
,
67 inv_mpu_i2c_disable
, chip_type
);
71 * device id table is used to identify what device can be
72 * supported by this driver
74 static const struct spi_device_id inv_mpu_id
[] = {
75 {"mpu6000", INV_MPU6000
},
76 {"mpu6500", INV_MPU6500
},
77 {"mpu9250", INV_MPU9250
},
78 {"mpu9255", INV_MPU9255
},
79 {"icm20608", INV_ICM20608
},
80 {"icm20602", INV_ICM20602
},
84 MODULE_DEVICE_TABLE(spi
, inv_mpu_id
);
86 static const struct acpi_device_id inv_acpi_match
[] = {
87 {"INVN6000", INV_MPU6000
},
90 MODULE_DEVICE_TABLE(acpi
, inv_acpi_match
);
92 static struct spi_driver inv_mpu_driver
= {
93 .probe
= inv_mpu_probe
,
94 .id_table
= inv_mpu_id
,
96 .acpi_match_table
= ACPI_PTR(inv_acpi_match
),
97 .name
= "inv-mpu6000-spi",
102 module_spi_driver(inv_mpu_driver
);
104 MODULE_AUTHOR("Adriana Reus <adriana.reus@intel.com>");
105 MODULE_DESCRIPTION("Invensense device MPU6000 driver");
106 MODULE_LICENSE("GPL");