st_pressure_i2c.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/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. #ifdef CONFIG_OF
  19. static const struct of_device_id st_press_of_match[] = {
  20. {
  21. .compatible = "st,lps001wp-press",
  22. .data = LPS001WP_PRESS_DEV_NAME,
  23. },
  24. {
  25. .compatible = "st,lps25h-press",
  26. .data = LPS25H_PRESS_DEV_NAME,
  27. },
  28. {
  29. .compatible = "st,lps331ap-press",
  30. .data = LPS331AP_PRESS_DEV_NAME,
  31. },
  32. {},
  33. };
  34. MODULE_DEVICE_TABLE(of, st_press_of_match);
  35. #else
  36. #define st_press_of_match NULL
  37. #endif
  38. static int st_press_i2c_probe(struct i2c_client *client,
  39. const struct i2c_device_id *id)
  40. {
  41. struct iio_dev *indio_dev;
  42. struct st_sensor_data *press_data;
  43. int err;
  44. indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
  45. if (!indio_dev)
  46. return -ENOMEM;
  47. press_data = iio_priv(indio_dev);
  48. st_sensors_of_i2c_probe(client, st_press_of_match);
  49. st_sensors_i2c_configure(indio_dev, client, press_data);
  50. err = st_press_common_probe(indio_dev);
  51. if (err < 0)
  52. return err;
  53. return 0;
  54. }
  55. static int st_press_i2c_remove(struct i2c_client *client)
  56. {
  57. st_press_common_remove(i2c_get_clientdata(client));
  58. return 0;
  59. }
  60. static const struct i2c_device_id st_press_id_table[] = {
  61. { LPS001WP_PRESS_DEV_NAME },
  62. { LPS25H_PRESS_DEV_NAME },
  63. { LPS331AP_PRESS_DEV_NAME },
  64. {},
  65. };
  66. MODULE_DEVICE_TABLE(i2c, st_press_id_table);
  67. static struct i2c_driver st_press_driver = {
  68. .driver = {
  69. .name = "st-press-i2c",
  70. .of_match_table = of_match_ptr(st_press_of_match),
  71. },
  72. .probe = st_press_i2c_probe,
  73. .remove = st_press_i2c_remove,
  74. .id_table = st_press_id_table,
  75. };
  76. module_i2c_driver(st_press_driver);
  77. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  78. MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
  79. MODULE_LICENSE("GPL v2");