st_pressure_i2c.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * STMicroelectronics pressures driver
  4. *
  5. * Copyright 2013 STMicroelectronics Inc.
  6. *
  7. * Denis Ciocca <denis.ciocca@st.com>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/mod_devicetable.h>
  12. #include <linux/i2c.h>
  13. #include <linux/iio/iio.h>
  14. #include <linux/iio/common/st_sensors.h>
  15. #include <linux/iio/common/st_sensors_i2c.h>
  16. #include "st_pressure.h"
  17. static const struct of_device_id st_press_of_match[] = {
  18. {
  19. .compatible = "st,lps001wp-press",
  20. .data = LPS001WP_PRESS_DEV_NAME,
  21. },
  22. {
  23. .compatible = "st,lps25h-press",
  24. .data = LPS25H_PRESS_DEV_NAME,
  25. },
  26. {
  27. .compatible = "st,lps331ap-press",
  28. .data = LPS331AP_PRESS_DEV_NAME,
  29. },
  30. {
  31. .compatible = "st,lps22hb-press",
  32. .data = LPS22HB_PRESS_DEV_NAME,
  33. },
  34. {
  35. .compatible = "st,lps33hw",
  36. .data = LPS33HW_PRESS_DEV_NAME,
  37. },
  38. {
  39. .compatible = "st,lps35hw",
  40. .data = LPS35HW_PRESS_DEV_NAME,
  41. },
  42. {
  43. .compatible = "st,lps22hh",
  44. .data = LPS22HH_PRESS_DEV_NAME,
  45. },
  46. {
  47. .compatible = "st,lps22df",
  48. .data = LPS22DF_PRESS_DEV_NAME,
  49. },
  50. { }
  51. };
  52. MODULE_DEVICE_TABLE(of, st_press_of_match);
  53. static const struct acpi_device_id st_press_acpi_match[] = {
  54. {"SNO9210", LPS22HB},
  55. { }
  56. };
  57. MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
  58. static const struct i2c_device_id st_press_id_table[] = {
  59. { LPS001WP_PRESS_DEV_NAME, LPS001WP },
  60. { LPS25H_PRESS_DEV_NAME, LPS25H },
  61. { LPS331AP_PRESS_DEV_NAME, LPS331AP },
  62. { LPS22HB_PRESS_DEV_NAME, LPS22HB },
  63. { LPS33HW_PRESS_DEV_NAME, LPS33HW },
  64. { LPS35HW_PRESS_DEV_NAME, LPS35HW },
  65. { LPS22HH_PRESS_DEV_NAME, LPS22HH },
  66. { LPS22DF_PRESS_DEV_NAME, LPS22DF },
  67. { }
  68. };
  69. MODULE_DEVICE_TABLE(i2c, st_press_id_table);
  70. static int st_press_i2c_probe(struct i2c_client *client)
  71. {
  72. const struct st_sensor_settings *settings;
  73. struct st_sensor_data *press_data;
  74. struct iio_dev *indio_dev;
  75. int ret;
  76. st_sensors_dev_name_probe(&client->dev, client->name, sizeof(client->name));
  77. settings = st_press_get_settings(client->name);
  78. if (!settings) {
  79. dev_err(&client->dev, "device name %s not recognized.\n",
  80. client->name);
  81. return -ENODEV;
  82. }
  83. indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
  84. if (!indio_dev)
  85. return -ENOMEM;
  86. press_data = iio_priv(indio_dev);
  87. press_data->sensor_settings = (struct st_sensor_settings *)settings;
  88. ret = st_sensors_i2c_configure(indio_dev, client);
  89. if (ret < 0)
  90. return ret;
  91. ret = st_sensors_power_enable(indio_dev);
  92. if (ret)
  93. return ret;
  94. return st_press_common_probe(indio_dev);
  95. }
  96. static struct i2c_driver st_press_driver = {
  97. .driver = {
  98. .name = "st-press-i2c",
  99. .of_match_table = st_press_of_match,
  100. .acpi_match_table = st_press_acpi_match,
  101. },
  102. .probe = st_press_i2c_probe,
  103. .id_table = st_press_id_table,
  104. };
  105. module_i2c_driver(st_press_driver);
  106. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  107. MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
  108. MODULE_LICENSE("GPL v2");
  109. MODULE_IMPORT_NS("IIO_ST_SENSORS");