st_pressure_spi.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * STMicroelectronics pressures driver
  4. *
  5. * Copyright 2013 STMicroelectronics Inc.
  6. *
  7. * Denis Ciocca <[email protected]>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/mod_devicetable.h>
  12. #include <linux/spi/spi.h>
  13. #include <linux/iio/iio.h>
  14. #include <linux/iio/common/st_sensors.h>
  15. #include <linux/iio/common/st_sensors_spi.h>
  16. #include "st_pressure.h"
  17. /*
  18. * For new single-chip sensors use <device_name> as compatible string.
  19. * For old single-chip devices keep <device_name>-press to maintain
  20. * compatibility
  21. */
  22. static const struct of_device_id st_press_of_match[] = {
  23. {
  24. .compatible = "st,lps001wp-press",
  25. .data = LPS001WP_PRESS_DEV_NAME,
  26. },
  27. {
  28. .compatible = "st,lps25h-press",
  29. .data = LPS25H_PRESS_DEV_NAME,
  30. },
  31. {
  32. .compatible = "st,lps331ap-press",
  33. .data = LPS331AP_PRESS_DEV_NAME,
  34. },
  35. {
  36. .compatible = "st,lps22hb-press",
  37. .data = LPS22HB_PRESS_DEV_NAME,
  38. },
  39. {
  40. .compatible = "st,lps33hw",
  41. .data = LPS33HW_PRESS_DEV_NAME,
  42. },
  43. {
  44. .compatible = "st,lps35hw",
  45. .data = LPS35HW_PRESS_DEV_NAME,
  46. },
  47. {
  48. .compatible = "st,lps22hh",
  49. .data = LPS22HH_PRESS_DEV_NAME,
  50. },
  51. {
  52. .compatible = "st,lps22df",
  53. .data = LPS22DF_PRESS_DEV_NAME,
  54. },
  55. {},
  56. };
  57. MODULE_DEVICE_TABLE(of, st_press_of_match);
  58. static int st_press_spi_probe(struct spi_device *spi)
  59. {
  60. const struct st_sensor_settings *settings;
  61. struct st_sensor_data *press_data;
  62. struct iio_dev *indio_dev;
  63. int err;
  64. st_sensors_dev_name_probe(&spi->dev, spi->modalias, sizeof(spi->modalias));
  65. settings = st_press_get_settings(spi->modalias);
  66. if (!settings) {
  67. dev_err(&spi->dev, "device name %s not recognized.\n",
  68. spi->modalias);
  69. return -ENODEV;
  70. }
  71. indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*press_data));
  72. if (!indio_dev)
  73. return -ENOMEM;
  74. press_data = iio_priv(indio_dev);
  75. press_data->sensor_settings = (struct st_sensor_settings *)settings;
  76. err = st_sensors_spi_configure(indio_dev, spi);
  77. if (err < 0)
  78. return err;
  79. err = st_sensors_power_enable(indio_dev);
  80. if (err)
  81. return err;
  82. return st_press_common_probe(indio_dev);
  83. }
  84. static const struct spi_device_id st_press_id_table[] = {
  85. { LPS001WP_PRESS_DEV_NAME },
  86. { LPS25H_PRESS_DEV_NAME },
  87. { LPS331AP_PRESS_DEV_NAME },
  88. { LPS22HB_PRESS_DEV_NAME },
  89. { LPS33HW_PRESS_DEV_NAME },
  90. { LPS35HW_PRESS_DEV_NAME },
  91. { LPS22HH_PRESS_DEV_NAME },
  92. { LPS22DF_PRESS_DEV_NAME },
  93. { "lps001wp-press" },
  94. { "lps25h-press", },
  95. { "lps331ap-press" },
  96. { "lps22hb-press" },
  97. {},
  98. };
  99. MODULE_DEVICE_TABLE(spi, st_press_id_table);
  100. static struct spi_driver st_press_driver = {
  101. .driver = {
  102. .name = "st-press-spi",
  103. .of_match_table = st_press_of_match,
  104. },
  105. .probe = st_press_spi_probe,
  106. .id_table = st_press_id_table,
  107. };
  108. module_spi_driver(st_press_driver);
  109. MODULE_AUTHOR("Denis Ciocca <[email protected]>");
  110. MODULE_DESCRIPTION("STMicroelectronics pressures spi driver");
  111. MODULE_LICENSE("GPL v2");
  112. MODULE_IMPORT_NS(IIO_ST_SENSORS);