st_pressure_i2c.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. .compatible = "st,lps33hw",
  39. .data = LPS33HW_PRESS_DEV_NAME,
  40. },
  41. {
  42. .compatible = "st,lps35hw",
  43. .data = LPS35HW_PRESS_DEV_NAME,
  44. },
  45. {},
  46. };
  47. MODULE_DEVICE_TABLE(of, st_press_of_match);
  48. #else
  49. #define st_press_of_match NULL
  50. #endif
  51. #ifdef CONFIG_ACPI
  52. static const struct acpi_device_id st_press_acpi_match[] = {
  53. {"SNO9210", LPS22HB},
  54. { },
  55. };
  56. MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
  57. #else
  58. #define st_press_acpi_match NULL
  59. #endif
  60. static const struct i2c_device_id st_press_id_table[] = {
  61. { LPS001WP_PRESS_DEV_NAME, LPS001WP },
  62. { LPS25H_PRESS_DEV_NAME, LPS25H },
  63. { LPS331AP_PRESS_DEV_NAME, LPS331AP },
  64. { LPS22HB_PRESS_DEV_NAME, LPS22HB },
  65. { LPS33HW_PRESS_DEV_NAME, LPS33HW },
  66. { LPS35HW_PRESS_DEV_NAME, LPS35HW },
  67. {},
  68. };
  69. MODULE_DEVICE_TABLE(i2c, st_press_id_table);
  70. static int st_press_i2c_probe(struct i2c_client *client,
  71. const struct i2c_device_id *id)
  72. {
  73. struct iio_dev *indio_dev;
  74. struct st_sensor_data *press_data;
  75. int ret;
  76. indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
  77. if (!indio_dev)
  78. return -ENOMEM;
  79. press_data = iio_priv(indio_dev);
  80. if (client->dev.of_node) {
  81. st_sensors_of_name_probe(&client->dev, st_press_of_match,
  82. client->name, sizeof(client->name));
  83. } else if (ACPI_HANDLE(&client->dev)) {
  84. ret = st_sensors_match_acpi_device(&client->dev);
  85. if ((ret < 0) || (ret >= ST_PRESS_MAX))
  86. return -ENODEV;
  87. strlcpy(client->name, st_press_id_table[ret].name,
  88. sizeof(client->name));
  89. } else if (!id)
  90. return -ENODEV;
  91. st_sensors_i2c_configure(indio_dev, client, press_data);
  92. ret = st_press_common_probe(indio_dev);
  93. if (ret < 0)
  94. return ret;
  95. return 0;
  96. }
  97. static int st_press_i2c_remove(struct i2c_client *client)
  98. {
  99. st_press_common_remove(i2c_get_clientdata(client));
  100. return 0;
  101. }
  102. static struct i2c_driver st_press_driver = {
  103. .driver = {
  104. .name = "st-press-i2c",
  105. .of_match_table = of_match_ptr(st_press_of_match),
  106. .acpi_match_table = ACPI_PTR(st_press_acpi_match),
  107. },
  108. .probe = st_press_i2c_probe,
  109. .remove = st_press_i2c_remove,
  110. .id_table = st_press_id_table,
  111. };
  112. module_i2c_driver(st_press_driver);
  113. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  114. MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
  115. MODULE_LICENSE("GPL v2");