st_accel_i2c.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * STMicroelectronics accelerometers driver
  3. *
  4. * Copyright 2012-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_accel.h"
  18. #ifdef CONFIG_OF
  19. static const struct of_device_id st_accel_of_match[] = {
  20. {
  21. .compatible = "st,lis3lv02dl-accel",
  22. .data = LIS3LV02DL_ACCEL_DEV_NAME,
  23. },
  24. {
  25. .compatible = "st,lsm303dlh-accel",
  26. .data = LSM303DLH_ACCEL_DEV_NAME,
  27. },
  28. {
  29. .compatible = "st,lsm303dlhc-accel",
  30. .data = LSM303DLHC_ACCEL_DEV_NAME,
  31. },
  32. {
  33. .compatible = "st,lis3dh-accel",
  34. .data = LIS3DH_ACCEL_DEV_NAME,
  35. },
  36. {
  37. .compatible = "st,lsm330d-accel",
  38. .data = LSM330D_ACCEL_DEV_NAME,
  39. },
  40. {
  41. .compatible = "st,lsm330dl-accel",
  42. .data = LSM330DL_ACCEL_DEV_NAME,
  43. },
  44. {
  45. .compatible = "st,lsm330dlc-accel",
  46. .data = LSM330DLC_ACCEL_DEV_NAME,
  47. },
  48. {
  49. .compatible = "st,lis331dl-accel",
  50. .data = LIS331DL_ACCEL_DEV_NAME,
  51. },
  52. {
  53. .compatible = "st,lis331dlh-accel",
  54. .data = LIS331DLH_ACCEL_DEV_NAME,
  55. },
  56. {
  57. .compatible = "st,lsm303dl-accel",
  58. .data = LSM303DL_ACCEL_DEV_NAME,
  59. },
  60. {
  61. .compatible = "st,lsm303dlm-accel",
  62. .data = LSM303DLM_ACCEL_DEV_NAME,
  63. },
  64. {
  65. .compatible = "st,lsm330-accel",
  66. .data = LSM330_ACCEL_DEV_NAME,
  67. },
  68. {},
  69. };
  70. MODULE_DEVICE_TABLE(of, st_accel_of_match);
  71. #else
  72. #define st_accel_of_match NULL
  73. #endif
  74. static int st_accel_i2c_probe(struct i2c_client *client,
  75. const struct i2c_device_id *id)
  76. {
  77. struct iio_dev *indio_dev;
  78. struct st_sensor_data *adata;
  79. int err;
  80. indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata));
  81. if (!indio_dev)
  82. return -ENOMEM;
  83. adata = iio_priv(indio_dev);
  84. st_sensors_of_i2c_probe(client, st_accel_of_match);
  85. st_sensors_i2c_configure(indio_dev, client, adata);
  86. err = st_accel_common_probe(indio_dev);
  87. if (err < 0)
  88. return err;
  89. return 0;
  90. }
  91. static int st_accel_i2c_remove(struct i2c_client *client)
  92. {
  93. st_accel_common_remove(i2c_get_clientdata(client));
  94. return 0;
  95. }
  96. static const struct i2c_device_id st_accel_id_table[] = {
  97. { LSM303DLH_ACCEL_DEV_NAME },
  98. { LSM303DLHC_ACCEL_DEV_NAME },
  99. { LIS3DH_ACCEL_DEV_NAME },
  100. { LSM330D_ACCEL_DEV_NAME },
  101. { LSM330DL_ACCEL_DEV_NAME },
  102. { LSM330DLC_ACCEL_DEV_NAME },
  103. { LIS331DLH_ACCEL_DEV_NAME },
  104. { LSM303DL_ACCEL_DEV_NAME },
  105. { LSM303DLM_ACCEL_DEV_NAME },
  106. { LSM330_ACCEL_DEV_NAME },
  107. {},
  108. };
  109. MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
  110. static struct i2c_driver st_accel_driver = {
  111. .driver = {
  112. .owner = THIS_MODULE,
  113. .name = "st-accel-i2c",
  114. .of_match_table = of_match_ptr(st_accel_of_match),
  115. },
  116. .probe = st_accel_i2c_probe,
  117. .remove = st_accel_i2c_remove,
  118. .id_table = st_accel_id_table,
  119. };
  120. module_i2c_driver(st_accel_driver);
  121. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  122. MODULE_DESCRIPTION("STMicroelectronics accelerometers i2c driver");
  123. MODULE_LICENSE("GPL v2");