st_pressure_spi.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * STMicroelectronics pressures driver
  3. *
  4. * Copyright 2013 STMicroelectronics Inc.
  5. *
  6. * Denis Ciocca <denis.ciocca@st.com>
  7. *
  8. * Licensed under the GPL-2.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/slab.h>
  13. #include <linux/spi/spi.h>
  14. #include <linux/iio/iio.h>
  15. #include <linux/iio/common/st_sensors.h>
  16. #include <linux/iio/common/st_sensors_spi.h>
  17. #include "st_pressure.h"
  18. #ifdef CONFIG_OF
  19. /*
  20. * For new single-chip sensors use <device_name> as compatible string.
  21. * For old single-chip devices keep <device_name>-press to maintain
  22. * compatibility
  23. */
  24. static const struct of_device_id st_press_of_match[] = {
  25. {
  26. .compatible = "st,lps001wp-press",
  27. .data = LPS001WP_PRESS_DEV_NAME,
  28. },
  29. {
  30. .compatible = "st,lps25h-press",
  31. .data = LPS25H_PRESS_DEV_NAME,
  32. },
  33. {
  34. .compatible = "st,lps331ap-press",
  35. .data = LPS331AP_PRESS_DEV_NAME,
  36. },
  37. {
  38. .compatible = "st,lps22hb-press",
  39. .data = LPS22HB_PRESS_DEV_NAME,
  40. },
  41. {
  42. .compatible = "st,lps33hw",
  43. .data = LPS33HW_PRESS_DEV_NAME,
  44. },
  45. {
  46. .compatible = "st,lps35hw",
  47. .data = LPS35HW_PRESS_DEV_NAME,
  48. },
  49. {},
  50. };
  51. MODULE_DEVICE_TABLE(of, st_press_of_match);
  52. #else
  53. #define st_press_of_match NULL
  54. #endif
  55. static int st_press_spi_probe(struct spi_device *spi)
  56. {
  57. struct iio_dev *indio_dev;
  58. struct st_sensor_data *press_data;
  59. int err;
  60. indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*press_data));
  61. if (indio_dev == NULL)
  62. return -ENOMEM;
  63. press_data = iio_priv(indio_dev);
  64. st_sensors_of_name_probe(&spi->dev, st_press_of_match,
  65. spi->modalias, sizeof(spi->modalias));
  66. st_sensors_spi_configure(indio_dev, spi, press_data);
  67. err = st_press_common_probe(indio_dev);
  68. if (err < 0)
  69. return err;
  70. return 0;
  71. }
  72. static int st_press_spi_remove(struct spi_device *spi)
  73. {
  74. st_press_common_remove(spi_get_drvdata(spi));
  75. return 0;
  76. }
  77. static const struct spi_device_id st_press_id_table[] = {
  78. { LPS001WP_PRESS_DEV_NAME },
  79. { LPS25H_PRESS_DEV_NAME },
  80. { LPS331AP_PRESS_DEV_NAME },
  81. { LPS22HB_PRESS_DEV_NAME },
  82. { LPS33HW_PRESS_DEV_NAME },
  83. { LPS35HW_PRESS_DEV_NAME },
  84. {},
  85. };
  86. MODULE_DEVICE_TABLE(spi, st_press_id_table);
  87. static struct spi_driver st_press_driver = {
  88. .driver = {
  89. .name = "st-press-spi",
  90. .of_match_table = of_match_ptr(st_press_of_match),
  91. },
  92. .probe = st_press_spi_probe,
  93. .remove = st_press_spi_remove,
  94. .id_table = st_press_id_table,
  95. };
  96. module_spi_driver(st_press_driver);
  97. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  98. MODULE_DESCRIPTION("STMicroelectronics pressures spi driver");
  99. MODULE_LICENSE("GPL v2");