perf python: Do not force closing original perf descriptor in evlist.get_pollfd()
[linux/fpc-iii.git] / drivers / iio / imu / inv_mpu6050 / inv_mpu_spi.c
blob227f50afff22f9c5329aeca129364e8770088dfb
1 /*
2 * Copyright (C) 2015 Intel Corporation Inc.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 #include <linux/module.h>
14 #include <linux/acpi.h>
15 #include <linux/spi/spi.h>
16 #include <linux/regmap.h>
17 #include <linux/iio/iio.h>
18 #include "inv_mpu_iio.h"
20 static const struct regmap_config inv_mpu_regmap_config = {
21 .reg_bits = 8,
22 .val_bits = 8,
25 static int inv_mpu_i2c_disable(struct iio_dev *indio_dev)
27 struct inv_mpu6050_state *st = iio_priv(indio_dev);
28 int ret = 0;
30 ret = inv_mpu6050_set_power_itg(st, true);
31 if (ret)
32 return ret;
34 st->chip_config.user_ctrl |= INV_MPU6050_BIT_I2C_IF_DIS;
35 ret = regmap_write(st->map, st->reg->user_ctrl,
36 st->chip_config.user_ctrl);
37 if (ret) {
38 inv_mpu6050_set_power_itg(st, false);
39 return ret;
42 return inv_mpu6050_set_power_itg(st, false);
45 static int inv_mpu_probe(struct spi_device *spi)
47 struct regmap *regmap;
48 const struct spi_device_id *spi_id;
49 const struct acpi_device_id *acpi_id;
50 const char *name = NULL;
51 enum inv_devices chip_type;
53 if ((spi_id = spi_get_device_id(spi))) {
54 chip_type = (enum inv_devices)spi_id->driver_data;
55 name = spi_id->name;
56 } else if ((acpi_id = acpi_match_device(spi->dev.driver->acpi_match_table, &spi->dev))) {
57 chip_type = (enum inv_devices)acpi_id->driver_data;
58 } else {
59 return -ENODEV;
62 regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config);
63 if (IS_ERR(regmap)) {
64 dev_err(&spi->dev, "Failed to register spi regmap %d\n",
65 (int)PTR_ERR(regmap));
66 return PTR_ERR(regmap);
69 return inv_mpu_core_probe(regmap, spi->irq, name,
70 inv_mpu_i2c_disable, chip_type);
74 * device id table is used to identify what device can be
75 * supported by this driver
77 static const struct spi_device_id inv_mpu_id[] = {
78 {"mpu6000", INV_MPU6000},
79 {"mpu6500", INV_MPU6500},
80 {"mpu9150", INV_MPU9150},
81 {"mpu9250", INV_MPU9250},
82 {"mpu9255", INV_MPU9255},
83 {"icm20608", INV_ICM20608},
87 MODULE_DEVICE_TABLE(spi, inv_mpu_id);
89 static const struct acpi_device_id inv_acpi_match[] = {
90 {"INVN6000", INV_MPU6000},
91 { },
93 MODULE_DEVICE_TABLE(acpi, inv_acpi_match);
95 static struct spi_driver inv_mpu_driver = {
96 .probe = inv_mpu_probe,
97 .id_table = inv_mpu_id,
98 .driver = {
99 .acpi_match_table = ACPI_PTR(inv_acpi_match),
100 .name = "inv-mpu6000-spi",
101 .pm = &inv_mpu_pmops,
105 module_spi_driver(inv_mpu_driver);
107 MODULE_AUTHOR("Adriana Reus <adriana.reus@intel.com>");
108 MODULE_DESCRIPTION("Invensense device MPU6000 driver");
109 MODULE_LICENSE("GPL");