|
| 1 | +/* |
| 2 | +* Copyright (C) 2015 Intel Corporation Inc. |
| 3 | +* |
| 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. |
| 7 | +* |
| 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. |
| 12 | +*/ |
| 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" |
| 19 | + |
| 20 | +static const struct regmap_config inv_mpu_regmap_config = { |
| 21 | + .reg_bits = 8, |
| 22 | + .val_bits = 8, |
| 23 | +}; |
| 24 | + |
| 25 | +static int inv_mpu_i2c_disable(struct iio_dev *indio_dev) |
| 26 | +{ |
| 27 | + struct inv_mpu6050_state *st = iio_priv(indio_dev); |
| 28 | + int ret = 0; |
| 29 | + |
| 30 | + ret = inv_mpu6050_set_power_itg(st, true); |
| 31 | + if (ret) |
| 32 | + return ret; |
| 33 | + |
| 34 | + ret = regmap_write(st->map, INV_MPU6050_REG_USER_CTRL, |
| 35 | + INV_MPU6050_BIT_I2C_IF_DIS); |
| 36 | + if (ret) { |
| 37 | + inv_mpu6050_set_power_itg(st, false); |
| 38 | + return ret; |
| 39 | + } |
| 40 | + |
| 41 | + return inv_mpu6050_set_power_itg(st, false); |
| 42 | +} |
| 43 | + |
| 44 | +static int inv_mpu_probe(struct spi_device *spi) |
| 45 | +{ |
| 46 | + struct regmap *regmap; |
| 47 | + const struct spi_device_id *id = spi_get_device_id(spi); |
| 48 | + const char *name = id ? id->name : NULL; |
| 49 | + |
| 50 | + regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config); |
| 51 | + if (IS_ERR(regmap)) { |
| 52 | + dev_err(&spi->dev, "Failed to register spi regmap %d\n", |
| 53 | + (int)PTR_ERR(regmap)); |
| 54 | + return PTR_ERR(regmap); |
| 55 | + } |
| 56 | + |
| 57 | + return inv_mpu_core_probe(regmap, spi->irq, name, inv_mpu_i2c_disable); |
| 58 | +} |
| 59 | + |
| 60 | +static int inv_mpu_remove(struct spi_device *spi) |
| 61 | +{ |
| 62 | + return inv_mpu_core_remove(&spi->dev); |
| 63 | +} |
| 64 | + |
| 65 | +/* |
| 66 | + * device id table is used to identify what device can be |
| 67 | + * supported by this driver |
| 68 | + */ |
| 69 | +static const struct spi_device_id inv_mpu_id[] = { |
| 70 | + {"mpu6000", INV_MPU6000}, |
| 71 | + {} |
| 72 | +}; |
| 73 | + |
| 74 | +MODULE_DEVICE_TABLE(spi, inv_mpu_id); |
| 75 | + |
| 76 | +static const struct acpi_device_id inv_acpi_match[] = { |
| 77 | + {"INVN6000", 0}, |
| 78 | + { }, |
| 79 | +}; |
| 80 | +MODULE_DEVICE_TABLE(acpi, inv_acpi_match); |
| 81 | + |
| 82 | +static struct spi_driver inv_mpu_driver = { |
| 83 | + .probe = inv_mpu_probe, |
| 84 | + .remove = inv_mpu_remove, |
| 85 | + .id_table = inv_mpu_id, |
| 86 | + .driver = { |
| 87 | + .acpi_match_table = ACPI_PTR(inv_acpi_match), |
| 88 | + .name = "inv-mpu6000-spi", |
| 89 | + .pm = &inv_mpu_pmops, |
| 90 | + }, |
| 91 | +}; |
| 92 | + |
| 93 | +module_spi_driver(inv_mpu_driver); |
| 94 | + |
| 95 | +MODULE_AUTHOR("Adriana Reus <adriana.reus@intel.com>"); |
| 96 | +MODULE_DESCRIPTION("Invensense device MPU6000 driver"); |
| 97 | +MODULE_LICENSE("GPL"); |
0 commit comments