bmc150-accel-spi.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * 3-axis accelerometer driver supporting SPI Bosch-Sensortec accelerometer chip
  3. * Copyright © 2015 Pengutronix, Markus Pargmann <[email protected]>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/device.h>
  19. #include <linux/mod_devicetable.h>
  20. #include <linux/module.h>
  21. #include <linux/acpi.h>
  22. #include <linux/regmap.h>
  23. #include <linux/spi/spi.h>
  24. #include "bmc150-accel.h"
  25. static int bmc150_accel_probe(struct spi_device *spi)
  26. {
  27. struct regmap *regmap;
  28. const struct spi_device_id *id = spi_get_device_id(spi);
  29. regmap = devm_regmap_init_spi(spi, &bmc150_regmap_conf);
  30. if (IS_ERR(regmap)) {
  31. dev_err(&spi->dev, "Failed to initialize spi regmap\n");
  32. return PTR_ERR(regmap);
  33. }
  34. return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, id->name,
  35. true);
  36. }
  37. static int bmc150_accel_remove(struct spi_device *spi)
  38. {
  39. return bmc150_accel_core_remove(&spi->dev);
  40. }
  41. static const struct acpi_device_id bmc150_accel_acpi_match[] = {
  42. {"BSBA0150", bmc150},
  43. {"BMC150A", bmc150},
  44. {"BMI055A", bmi055},
  45. {"BMA0255", bma255},
  46. {"BMA250E", bma250e},
  47. {"BMA222E", bma222e},
  48. {"BMA0280", bma280},
  49. { },
  50. };
  51. MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match);
  52. static const struct spi_device_id bmc150_accel_id[] = {
  53. {"bmc150_accel", bmc150},
  54. {"bmi055_accel", bmi055},
  55. {"bma255", bma255},
  56. {"bma250e", bma250e},
  57. {"bma222e", bma222e},
  58. {"bma280", bma280},
  59. {}
  60. };
  61. MODULE_DEVICE_TABLE(spi, bmc150_accel_id);
  62. static struct spi_driver bmc150_accel_driver = {
  63. .driver = {
  64. .name = "bmc150_accel_spi",
  65. .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match),
  66. .pm = &bmc150_accel_pm_ops,
  67. },
  68. .probe = bmc150_accel_probe,
  69. .remove = bmc150_accel_remove,
  70. .id_table = bmc150_accel_id,
  71. };
  72. module_spi_driver(bmc150_accel_driver);
  73. MODULE_AUTHOR("Markus Pargmann <[email protected]>");
  74. MODULE_LICENSE("GPL v2");
  75. MODULE_DESCRIPTION("BMC150 SPI accelerometer driver");