zpa2326_spi.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Murata ZPA2326 SPI pressure and temperature sensor driver
  4. *
  5. * Copyright (c) 2016 Parrot S.A.
  6. *
  7. * Author: Gregor Boirie <[email protected]>
  8. */
  9. #include <linux/module.h>
  10. #include <linux/regmap.h>
  11. #include <linux/spi/spi.h>
  12. #include <linux/mod_devicetable.h>
  13. #include "zpa2326.h"
  14. /*
  15. * read_flag_mask:
  16. * - address bit 7 must be set to request a register read operation
  17. * - address bit 6 must be set to request register address auto increment
  18. */
  19. static const struct regmap_config zpa2326_regmap_spi_config = {
  20. .reg_bits = 8,
  21. .val_bits = 8,
  22. .writeable_reg = zpa2326_isreg_writeable,
  23. .readable_reg = zpa2326_isreg_readable,
  24. .precious_reg = zpa2326_isreg_precious,
  25. .max_register = ZPA2326_TEMP_OUT_H_REG,
  26. .read_flag_mask = BIT(7) | BIT(6),
  27. .cache_type = REGCACHE_NONE,
  28. };
  29. static int zpa2326_probe_spi(struct spi_device *spi)
  30. {
  31. struct regmap *regmap;
  32. int err;
  33. regmap = devm_regmap_init_spi(spi, &zpa2326_regmap_spi_config);
  34. if (IS_ERR(regmap)) {
  35. dev_err(&spi->dev, "failed to init registers map");
  36. return PTR_ERR(regmap);
  37. }
  38. /*
  39. * Enforce SPI slave settings to prevent from DT misconfiguration.
  40. *
  41. * Clock is idle high. Sampling happens on trailing edge, i.e., rising
  42. * edge. Maximum bus frequency is 1 MHz. Registers are 8 bits wide.
  43. */
  44. spi->mode = SPI_MODE_3;
  45. spi->max_speed_hz = min(spi->max_speed_hz, 1000000U);
  46. spi->bits_per_word = 8;
  47. err = spi_setup(spi);
  48. if (err < 0)
  49. return err;
  50. return zpa2326_probe(&spi->dev, spi_get_device_id(spi)->name,
  51. spi->irq, ZPA2326_DEVICE_ID, regmap);
  52. }
  53. static void zpa2326_remove_spi(struct spi_device *spi)
  54. {
  55. zpa2326_remove(&spi->dev);
  56. }
  57. static const struct spi_device_id zpa2326_spi_ids[] = {
  58. { "zpa2326", 0 },
  59. { },
  60. };
  61. MODULE_DEVICE_TABLE(spi, zpa2326_spi_ids);
  62. static const struct of_device_id zpa2326_spi_matches[] = {
  63. { .compatible = "murata,zpa2326" },
  64. { }
  65. };
  66. MODULE_DEVICE_TABLE(of, zpa2326_spi_matches);
  67. static struct spi_driver zpa2326_spi_driver = {
  68. .driver = {
  69. .name = "zpa2326-spi",
  70. .of_match_table = zpa2326_spi_matches,
  71. .pm = ZPA2326_PM_OPS,
  72. },
  73. .probe = zpa2326_probe_spi,
  74. .remove = zpa2326_remove_spi,
  75. .id_table = zpa2326_spi_ids,
  76. };
  77. module_spi_driver(zpa2326_spi_driver);
  78. MODULE_AUTHOR("Gregor Boirie <[email protected]>");
  79. MODULE_DESCRIPTION("SPI driver for Murata ZPA2326 pressure sensor");
  80. MODULE_LICENSE("GPL v2");
  81. MODULE_IMPORT_NS(IIO_ZPA2326);