inv_mpu_spi.c 2.8 KB

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