bmg160_spi.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <linux/spi/spi.h>
  2. #include <linux/regmap.h>
  3. #include <linux/iio/iio.h>
  4. #include <linux/module.h>
  5. #include "bmg160.h"
  6. static const struct regmap_config bmg160_regmap_spi_conf = {
  7. .reg_bits = 8,
  8. .val_bits = 8,
  9. .max_register = 0x3f,
  10. };
  11. static int bmg160_spi_probe(struct spi_device *spi)
  12. {
  13. struct regmap *regmap;
  14. const struct spi_device_id *id = spi_get_device_id(spi);
  15. regmap = devm_regmap_init_spi(spi, &bmg160_regmap_spi_conf);
  16. if (IS_ERR(regmap)) {
  17. dev_err(&spi->dev, "Failed to register spi regmap %d\n",
  18. (int)PTR_ERR(regmap));
  19. return PTR_ERR(regmap);
  20. }
  21. return bmg160_core_probe(&spi->dev, regmap, spi->irq, id->name);
  22. }
  23. static int bmg160_spi_remove(struct spi_device *spi)
  24. {
  25. bmg160_core_remove(&spi->dev);
  26. return 0;
  27. }
  28. static const struct spi_device_id bmg160_spi_id[] = {
  29. {"bmg160", 0},
  30. {"bmi055_gyro", 0},
  31. {}
  32. };
  33. MODULE_DEVICE_TABLE(spi, bmg160_spi_id);
  34. static struct spi_driver bmg160_spi_driver = {
  35. .driver = {
  36. .name = "bmg160_spi",
  37. .pm = &bmg160_pm_ops,
  38. },
  39. .probe = bmg160_spi_probe,
  40. .remove = bmg160_spi_remove,
  41. .id_table = bmg160_spi_id,
  42. };
  43. module_spi_driver(bmg160_spi_driver);
  44. MODULE_AUTHOR("Markus Pargmann <mpa@pengutronix.de>");
  45. MODULE_LICENSE("GPL v2");
  46. MODULE_DESCRIPTION("BMG160 SPI Gyro driver");