st_pressure_i2c.c 2.1 KB

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