adxl372_spi.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * ADXL372 3-Axis Digital Accelerometer SPI driver
  4. *
  5. * Copyright 2018 Analog Devices Inc.
  6. */
  7. #include <linux/module.h>
  8. #include <linux/regmap.h>
  9. #include <linux/of.h>
  10. #include <linux/of_device.h>
  11. #include <linux/spi/spi.h>
  12. #include "adxl372.h"
  13. static const struct regmap_config adxl372_spi_regmap_config = {
  14. .reg_bits = 7,
  15. .pad_bits = 1,
  16. .val_bits = 8,
  17. .read_flag_mask = BIT(0),
  18. .readable_noinc_reg = adxl372_readable_noinc_reg,
  19. };
  20. static int adxl372_spi_probe(struct spi_device *spi)
  21. {
  22. const struct spi_device_id *id = spi_get_device_id(spi);
  23. struct regmap *regmap;
  24. regmap = devm_regmap_init_spi(spi, &adxl372_spi_regmap_config);
  25. if (IS_ERR(regmap))
  26. return PTR_ERR(regmap);
  27. return adxl372_probe(&spi->dev, regmap, spi->irq, id->name);
  28. }
  29. static const struct spi_device_id adxl372_spi_id[] = {
  30. { "adxl372", 0 },
  31. {}
  32. };
  33. MODULE_DEVICE_TABLE(spi, adxl372_spi_id);
  34. static const struct of_device_id adxl372_of_match[] = {
  35. { .compatible = "adi,adxl372" },
  36. { }
  37. };
  38. MODULE_DEVICE_TABLE(of, adxl372_of_match);
  39. static struct spi_driver adxl372_spi_driver = {
  40. .driver = {
  41. .name = "adxl372_spi",
  42. .of_match_table = adxl372_of_match,
  43. },
  44. .probe = adxl372_spi_probe,
  45. .id_table = adxl372_spi_id,
  46. };
  47. module_spi_driver(adxl372_spi_driver);
  48. MODULE_AUTHOR("Stefan Popa <[email protected]>");
  49. MODULE_DESCRIPTION("Analog Devices ADXL372 3-axis accelerometer SPI driver");
  50. MODULE_LICENSE("GPL");
  51. MODULE_IMPORT_NS(IIO_ADXL372);