inv_mpu_spi.c 2.8 KB

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