st_pressure_i2c.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 *pdata;
  43. int err;
  44. indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*pdata));
  45. if (!indio_dev)
  46. return -ENOMEM;
  47. pdata = iio_priv(indio_dev);
  48. pdata->dev = &client->dev;
  49. st_sensors_of_i2c_probe(client, st_press_of_match);
  50. st_sensors_i2c_configure(indio_dev, client, pdata);
  51. err = st_press_common_probe(indio_dev, client->dev.platform_data);
  52. if (err < 0)
  53. return err;
  54. return 0;
  55. }
  56. static int st_press_i2c_remove(struct i2c_client *client)
  57. {
  58. st_press_common_remove(i2c_get_clientdata(client));
  59. return 0;
  60. }
  61. static const struct i2c_device_id st_press_id_table[] = {
  62. { LPS001WP_PRESS_DEV_NAME },
  63. { LPS25H_PRESS_DEV_NAME },
  64. { LPS331AP_PRESS_DEV_NAME },
  65. {},
  66. };
  67. MODULE_DEVICE_TABLE(i2c, st_press_id_table);
  68. static struct i2c_driver st_press_driver = {
  69. .driver = {
  70. .owner = THIS_MODULE,
  71. .name = "st-press-i2c",
  72. .of_match_table = of_match_ptr(st_press_of_match),
  73. },
  74. .probe = st_press_i2c_probe,
  75. .remove = st_press_i2c_remove,
  76. .id_table = st_press_id_table,
  77. };
  78. module_i2c_driver(st_press_driver);
  79. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  80. MODULE_DESCRIPTION("STMicroelectronics pressures i2c driver");
  81. MODULE_LICENSE("GPL v2");