bmi160_spi.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * BMI160 - Bosch IMU, SPI bits
  3. *
  4. * Copyright (c) 2016, Intel Corporation.
  5. *
  6. * This file is subject to the terms and conditions of version 2 of
  7. * the GNU General Public License. See the file COPYING in the main
  8. * directory of this archive for more details.
  9. */
  10. #include <linux/acpi.h>
  11. #include <linux/module.h>
  12. #include <linux/of.h>
  13. #include <linux/regmap.h>
  14. #include <linux/spi/spi.h>
  15. #include "bmi160.h"
  16. static int bmi160_spi_probe(struct spi_device *spi)
  17. {
  18. struct regmap *regmap;
  19. const struct spi_device_id *id = spi_get_device_id(spi);
  20. regmap = devm_regmap_init_spi(spi, &bmi160_regmap_config);
  21. if (IS_ERR(regmap)) {
  22. dev_err(&spi->dev, "Failed to register spi regmap %d\n",
  23. (int)PTR_ERR(regmap));
  24. return PTR_ERR(regmap);
  25. }
  26. return bmi160_core_probe(&spi->dev, regmap, id->name, true);
  27. }
  28. static int bmi160_spi_remove(struct spi_device *spi)
  29. {
  30. bmi160_core_remove(&spi->dev);
  31. return 0;
  32. }
  33. static const struct spi_device_id bmi160_spi_id[] = {
  34. {"bmi160", 0},
  35. {}
  36. };
  37. MODULE_DEVICE_TABLE(spi, bmi160_spi_id);
  38. static const struct acpi_device_id bmi160_acpi_match[] = {
  39. {"BMI0160", 0},
  40. { },
  41. };
  42. MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
  43. #ifdef CONFIG_OF
  44. static const struct of_device_id bmi160_of_match[] = {
  45. { .compatible = "bosch,bmi160" },
  46. { },
  47. };
  48. MODULE_DEVICE_TABLE(of, bmi160_of_match);
  49. #endif
  50. static struct spi_driver bmi160_spi_driver = {
  51. .probe = bmi160_spi_probe,
  52. .remove = bmi160_spi_remove,
  53. .id_table = bmi160_spi_id,
  54. .driver = {
  55. .acpi_match_table = ACPI_PTR(bmi160_acpi_match),
  56. .of_match_table = of_match_ptr(bmi160_of_match),
  57. .name = "bmi160_spi",
  58. },
  59. };
  60. module_spi_driver(bmi160_spi_driver);
  61. MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com");
  62. MODULE_DESCRIPTION("Bosch BMI160 SPI driver");
  63. MODULE_LICENSE("GPL v2");