st_pressure_i2c.c 3.0 KB

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