st_gyro_i2c.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * STMicroelectronics gyroscopes 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_gyro.h"
  18. #ifdef CONFIG_OF
  19. static const struct of_device_id st_gyro_of_match[] = {
  20. {
  21. .compatible = "st,l3g4200d-gyro",
  22. .data = L3G4200D_GYRO_DEV_NAME,
  23. },
  24. {
  25. .compatible = "st,lsm330d-gyro",
  26. .data = LSM330D_GYRO_DEV_NAME,
  27. },
  28. {
  29. .compatible = "st,lsm330dl-gyro",
  30. .data = LSM330DL_GYRO_DEV_NAME,
  31. },
  32. {
  33. .compatible = "st,lsm330dlc-gyro",
  34. .data = LSM330DLC_GYRO_DEV_NAME,
  35. },
  36. {
  37. .compatible = "st,l3gd20-gyro",
  38. .data = L3GD20_GYRO_DEV_NAME,
  39. },
  40. {
  41. .compatible = "st,l3gd20h-gyro",
  42. .data = L3GD20H_GYRO_DEV_NAME,
  43. },
  44. {
  45. .compatible = "st,l3g4is-gyro",
  46. .data = L3G4IS_GYRO_DEV_NAME,
  47. },
  48. {
  49. .compatible = "st,lsm330-gyro",
  50. .data = LSM330_GYRO_DEV_NAME,
  51. },
  52. {
  53. .compatible = "st,lsm9ds0-gyro",
  54. .data = LSM9DS0_GYRO_DEV_NAME,
  55. },
  56. {},
  57. };
  58. MODULE_DEVICE_TABLE(of, st_gyro_of_match);
  59. #else
  60. #define st_gyro_of_match NULL
  61. #endif
  62. static int st_gyro_i2c_probe(struct i2c_client *client,
  63. const struct i2c_device_id *id)
  64. {
  65. struct iio_dev *indio_dev;
  66. struct st_sensor_data *gdata;
  67. int err;
  68. indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*gdata));
  69. if (!indio_dev)
  70. return -ENOMEM;
  71. gdata = iio_priv(indio_dev);
  72. st_sensors_of_name_probe(&client->dev, st_gyro_of_match,
  73. client->name, sizeof(client->name));
  74. st_sensors_i2c_configure(indio_dev, client, gdata);
  75. err = st_gyro_common_probe(indio_dev);
  76. if (err < 0)
  77. return err;
  78. return 0;
  79. }
  80. static int st_gyro_i2c_remove(struct i2c_client *client)
  81. {
  82. st_gyro_common_remove(i2c_get_clientdata(client));
  83. return 0;
  84. }
  85. static const struct i2c_device_id st_gyro_id_table[] = {
  86. { L3G4200D_GYRO_DEV_NAME },
  87. { LSM330D_GYRO_DEV_NAME },
  88. { LSM330DL_GYRO_DEV_NAME },
  89. { LSM330DLC_GYRO_DEV_NAME },
  90. { L3GD20_GYRO_DEV_NAME },
  91. { L3GD20H_GYRO_DEV_NAME },
  92. { L3G4IS_GYRO_DEV_NAME },
  93. { LSM330_GYRO_DEV_NAME },
  94. { LSM9DS0_GYRO_DEV_NAME },
  95. {},
  96. };
  97. MODULE_DEVICE_TABLE(i2c, st_gyro_id_table);
  98. static struct i2c_driver st_gyro_driver = {
  99. .driver = {
  100. .name = "st-gyro-i2c",
  101. .of_match_table = of_match_ptr(st_gyro_of_match),
  102. },
  103. .probe = st_gyro_i2c_probe,
  104. .remove = st_gyro_i2c_remove,
  105. .id_table = st_gyro_id_table,
  106. };
  107. module_i2c_driver(st_gyro_driver);
  108. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  109. MODULE_DESCRIPTION("STMicroelectronics gyroscopes i2c driver");
  110. MODULE_LICENSE("GPL v2");