adxl355_spi.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ADXL355 3-Axis Digital Accelerometer SPI driver
  4. *
  5. * Copyright (c) 2021 Puranjay Mohan <puranjay12@gmail.com>
  6. */
  7. #include <linux/module.h>
  8. #include <linux/mod_devicetable.h>
  9. #include <linux/regmap.h>
  10. #include <linux/spi/spi.h>
  11. #include <linux/property.h>
  12. #include "adxl355.h"
  13. static const struct regmap_config adxl355_spi_regmap_config = {
  14. .reg_bits = 7,
  15. .pad_bits = 1,
  16. .val_bits = 8,
  17. .read_flag_mask = BIT(0),
  18. .max_register = 0x2F,
  19. .rd_table = &adxl355_readable_regs_tbl,
  20. .wr_table = &adxl355_writeable_regs_tbl,
  21. };
  22. static int adxl355_spi_probe(struct spi_device *spi)
  23. {
  24. const struct adxl355_chip_info *chip_data;
  25. struct regmap *regmap;
  26. chip_data = spi_get_device_match_data(spi);
  27. if (!chip_data)
  28. return -EINVAL;
  29. regmap = devm_regmap_init_spi(spi, &adxl355_spi_regmap_config);
  30. if (IS_ERR(regmap)) {
  31. dev_err(&spi->dev, "Error initializing spi regmap: %ld\n",
  32. PTR_ERR(regmap));
  33. return PTR_ERR(regmap);
  34. }
  35. return adxl355_core_probe(&spi->dev, regmap, chip_data);
  36. }
  37. static const struct spi_device_id adxl355_spi_id[] = {
  38. { "adxl355", (kernel_ulong_t)&adxl35x_chip_info[ADXL355] },
  39. { "adxl359", (kernel_ulong_t)&adxl35x_chip_info[ADXL359] },
  40. { }
  41. };
  42. MODULE_DEVICE_TABLE(spi, adxl355_spi_id);
  43. static const struct of_device_id adxl355_of_match[] = {
  44. { .compatible = "adi,adxl355", .data = &adxl35x_chip_info[ADXL355] },
  45. { .compatible = "adi,adxl359", .data = &adxl35x_chip_info[ADXL359] },
  46. { }
  47. };
  48. MODULE_DEVICE_TABLE(of, adxl355_of_match);
  49. static struct spi_driver adxl355_spi_driver = {
  50. .driver = {
  51. .name = "adxl355_spi",
  52. .of_match_table = adxl355_of_match,
  53. },
  54. .probe = adxl355_spi_probe,
  55. .id_table = adxl355_spi_id,
  56. };
  57. module_spi_driver(adxl355_spi_driver);
  58. MODULE_AUTHOR("Puranjay Mohan <puranjay12@gmail.com>");
  59. MODULE_DESCRIPTION("ADXL355 3-Axis Digital Accelerometer SPI driver");
  60. MODULE_LICENSE("GPL v2");
  61. MODULE_IMPORT_NS(IIO_ADXL355);