st_accel_i2c.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. .compatible = "st,lsm303agr-accel",
  70. .data = LSM303AGR_ACCEL_DEV_NAME,
  71. },
  72. {
  73. .compatible = "st,lis2dh12-accel",
  74. .data = LIS2DH12_ACCEL_DEV_NAME,
  75. },
  76. {
  77. .compatible = "st,h3lis331dl-accel",
  78. .data = H3LIS331DL_DRIVER_NAME,
  79. },
  80. {
  81. .compatible = "st,lis3l02dq",
  82. .data = LIS3L02DQ_ACCEL_DEV_NAME,
  83. },
  84. {
  85. .compatible = "st,lng2dm-accel",
  86. .data = LNG2DM_ACCEL_DEV_NAME,
  87. },
  88. {},
  89. };
  90. MODULE_DEVICE_TABLE(of, st_accel_of_match);
  91. #else
  92. #define st_accel_of_match NULL
  93. #endif
  94. static int st_accel_i2c_probe(struct i2c_client *client,
  95. const struct i2c_device_id *id)
  96. {
  97. struct iio_dev *indio_dev;
  98. struct st_sensor_data *adata;
  99. int err;
  100. indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata));
  101. if (!indio_dev)
  102. return -ENOMEM;
  103. adata = iio_priv(indio_dev);
  104. st_sensors_of_i2c_probe(client, st_accel_of_match);
  105. st_sensors_i2c_configure(indio_dev, client, adata);
  106. err = st_accel_common_probe(indio_dev);
  107. if (err < 0)
  108. return err;
  109. return 0;
  110. }
  111. static int st_accel_i2c_remove(struct i2c_client *client)
  112. {
  113. st_accel_common_remove(i2c_get_clientdata(client));
  114. return 0;
  115. }
  116. static const struct i2c_device_id st_accel_id_table[] = {
  117. { LSM303DLH_ACCEL_DEV_NAME },
  118. { LSM303DLHC_ACCEL_DEV_NAME },
  119. { LIS3DH_ACCEL_DEV_NAME },
  120. { LSM330D_ACCEL_DEV_NAME },
  121. { LSM330DL_ACCEL_DEV_NAME },
  122. { LSM330DLC_ACCEL_DEV_NAME },
  123. { LIS331DLH_ACCEL_DEV_NAME },
  124. { LSM303DL_ACCEL_DEV_NAME },
  125. { LSM303DLM_ACCEL_DEV_NAME },
  126. { LSM330_ACCEL_DEV_NAME },
  127. { LSM303AGR_ACCEL_DEV_NAME },
  128. { LIS2DH12_ACCEL_DEV_NAME },
  129. { LIS3L02DQ_ACCEL_DEV_NAME },
  130. { LNG2DM_ACCEL_DEV_NAME },
  131. {},
  132. };
  133. MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
  134. static struct i2c_driver st_accel_driver = {
  135. .driver = {
  136. .name = "st-accel-i2c",
  137. .of_match_table = of_match_ptr(st_accel_of_match),
  138. },
  139. .probe = st_accel_i2c_probe,
  140. .remove = st_accel_i2c_remove,
  141. .id_table = st_accel_id_table,
  142. };
  143. module_i2c_driver(st_accel_driver);
  144. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  145. MODULE_DESCRIPTION("STMicroelectronics accelerometers i2c driver");
  146. MODULE_LICENSE("GPL v2");