st_pressure_i2c.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/acpi.h>
  14. #include <linux/i2c.h>
  15. #include <linux/iio/iio.h>
  16. #include <linux/iio/common/st_sensors.h>
  17. #include <linux/iio/common/st_sensors_i2c.h>
  18. #include "st_pressure.h"
  19. #ifdef CONFIG_OF
  20. static const struct of_device_id st_press_of_match[] = {
  21. {
  22. .compatible = "st,lps001wp-press",
  23. .data = LPS001WP_PRESS_DEV_NAME,
  24. },
  25. {
  26. .compatible = "st,lps25h-press",
  27. .data = LPS25H_PRESS_DEV_NAME,
  28. },
  29. {
  30. .compatible = "st,lps331ap-press",
  31. .data = LPS331AP_PRESS_DEV_NAME,
  32. },
  33. {
  34. .compatible = "st,lps22hb-press",
  35. .data = LPS22HB_PRESS_DEV_NAME,
  36. },
  37. {},
  38. };
  39. MODULE_DEVICE_TABLE(of, st_press_of_match);
  40. #else
  41. #define st_press_of_match NULL
  42. #endif
  43. #ifdef CONFIG_ACPI
  44. static const struct acpi_device_id st_press_acpi_match[] = {
  45. {"SNO9210", LPS22HB},
  46. { },
  47. };
  48. MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
  49. #else
  50. #define st_press_acpi_match NULL
  51. #endif
  52. static const struct i2c_device_id st_press_id_table[] = {
  53. { LPS001WP_PRESS_DEV_NAME, LPS001WP },
  54. { LPS25H_PRESS_DEV_NAME, LPS25H },
  55. { LPS331AP_PRESS_DEV_NAME, LPS331AP },
  56. { LPS22HB_PRESS_DEV_NAME, LPS22HB },
  57. {},
  58. };
  59. MODULE_DEVICE_TABLE(i2c, st_press_id_table);
  60. static int st_press_i2c_probe(struct i2c_client *client,
  61. const struct i2c_device_id *id)
  62. {
  63. struct iio_dev *indio_dev;
  64. struct st_sensor_data *press_data;
  65. int ret;
  66. indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
  67. if (!indio_dev)
  68. return -ENOMEM;
  69. press_data = iio_priv(indio_dev);
  70. if (client->dev.of_node) {
  71. st_sensors_of_i2c_probe(client, st_press_of_match);
  72. } else if (ACPI_HANDLE(&client->dev)) {
  73. ret = st_sensors_match_acpi_device(&client->dev);
  74. if ((ret < 0) || (ret >= ST_PRESS_MAX))
  75. return -ENODEV;
  76. strncpy(client->name, st_press_id_table[ret].name,
  77. sizeof(client->name));
  78. client->name[sizeof(client->name) - 1] = '\0';
  79. } else if (!id)
  80. return -ENODEV;
  81. st_sensors_i2c_configure(indio_dev, client, press_data);
  82. ret = st_press_common_probe(indio_dev);
  83. if (ret < 0)
  84. return ret;
  85. return 0;
  86. }
  87. static int st_press_i2c_remove(struct i2c_client *client)
  88. {
  89. st_press_common_remove(i2c_get_clientdata(client));
  90. return 0;
  91. }
  92. static struct i2c_driver st_press_driver = {
  93. .driver = {
  94. .name = "st-press-i2c",
  95. .of_match_table = of_match_ptr(st_press_of_match),
  96. .acpi_match_table = ACPI_PTR(st_press_acpi_match),
  97. },
  98. .probe = st_press_i2c_probe,
  99. .remove = st_press_i2c_remove,
  100. .id_table = st_press_id_table,
  101. };
  102. module_i2c_driver(st_press_driver);
  103. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  104. MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
  105. MODULE_LICENSE("GPL v2");