fxas21002c_spi.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Driver for NXP Fxas21002c Gyroscope - SPI
  4. *
  5. * Copyright (C) 2019 Linaro Ltd.
  6. */
  7. #include <linux/err.h>
  8. #include <linux/mod_devicetable.h>
  9. #include <linux/module.h>
  10. #include <linux/regmap.h>
  11. #include <linux/spi/spi.h>
  12. #include "fxas21002c.h"
  13. static const struct regmap_config fxas21002c_regmap_spi_conf = {
  14. .reg_bits = 8,
  15. .val_bits = 8,
  16. .max_register = FXAS21002C_REG_CTRL3,
  17. };
  18. static int fxas21002c_spi_probe(struct spi_device *spi)
  19. {
  20. const struct spi_device_id *id = spi_get_device_id(spi);
  21. struct regmap *regmap;
  22. regmap = devm_regmap_init_spi(spi, &fxas21002c_regmap_spi_conf);
  23. if (IS_ERR(regmap)) {
  24. dev_err(&spi->dev, "Failed to register spi regmap: %ld\n",
  25. PTR_ERR(regmap));
  26. return PTR_ERR(regmap);
  27. }
  28. return fxas21002c_core_probe(&spi->dev, regmap, spi->irq, id->name);
  29. }
  30. static void fxas21002c_spi_remove(struct spi_device *spi)
  31. {
  32. fxas21002c_core_remove(&spi->dev);
  33. }
  34. static const struct spi_device_id fxas21002c_spi_id[] = {
  35. { "fxas21002c", 0 },
  36. { }
  37. };
  38. MODULE_DEVICE_TABLE(spi, fxas21002c_spi_id);
  39. static const struct of_device_id fxas21002c_spi_of_match[] = {
  40. { .compatible = "nxp,fxas21002c", },
  41. { }
  42. };
  43. MODULE_DEVICE_TABLE(of, fxas21002c_spi_of_match);
  44. static struct spi_driver fxas21002c_spi_driver = {
  45. .driver = {
  46. .name = "fxas21002c_spi",
  47. .pm = &fxas21002c_pm_ops,
  48. .of_match_table = fxas21002c_spi_of_match,
  49. },
  50. .probe = fxas21002c_spi_probe,
  51. .remove = fxas21002c_spi_remove,
  52. .id_table = fxas21002c_spi_id,
  53. };
  54. module_spi_driver(fxas21002c_spi_driver);
  55. MODULE_AUTHOR("Rui Miguel Silva <[email protected]>");
  56. MODULE_LICENSE("GPL v2");
  57. MODULE_DESCRIPTION("FXAS21002C SPI Gyro driver");