st_gyro_i2c.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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,l3g4is-gyro",
  42. .data = L3G4IS_GYRO_DEV_NAME,
  43. },
  44. {
  45. .compatible = "st,lsm330-gyro",
  46. .data = LSM330_GYRO_DEV_NAME,
  47. },
  48. {},
  49. };
  50. MODULE_DEVICE_TABLE(of, st_gyro_of_match);
  51. #else
  52. #define st_gyro_of_match NULL
  53. #endif
  54. static int st_gyro_i2c_probe(struct i2c_client *client,
  55. const struct i2c_device_id *id)
  56. {
  57. struct iio_dev *indio_dev;
  58. struct st_sensor_data *gdata;
  59. int err;
  60. indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*gdata));
  61. if (!indio_dev)
  62. return -ENOMEM;
  63. gdata = iio_priv(indio_dev);
  64. st_sensors_of_i2c_probe(client, st_gyro_of_match);
  65. st_sensors_i2c_configure(indio_dev, client, gdata);
  66. err = st_gyro_common_probe(indio_dev);
  67. if (err < 0)
  68. return err;
  69. return 0;
  70. }
  71. static int st_gyro_i2c_remove(struct i2c_client *client)
  72. {
  73. st_gyro_common_remove(i2c_get_clientdata(client));
  74. return 0;
  75. }
  76. static const struct i2c_device_id st_gyro_id_table[] = {
  77. { L3G4200D_GYRO_DEV_NAME },
  78. { LSM330D_GYRO_DEV_NAME },
  79. { LSM330DL_GYRO_DEV_NAME },
  80. { LSM330DLC_GYRO_DEV_NAME },
  81. { L3GD20_GYRO_DEV_NAME },
  82. { L3G4IS_GYRO_DEV_NAME },
  83. { LSM330_GYRO_DEV_NAME },
  84. {},
  85. };
  86. MODULE_DEVICE_TABLE(i2c, st_gyro_id_table);
  87. static struct i2c_driver st_gyro_driver = {
  88. .driver = {
  89. .name = "st-gyro-i2c",
  90. .of_match_table = of_match_ptr(st_gyro_of_match),
  91. },
  92. .probe = st_gyro_i2c_probe,
  93. .remove = st_gyro_i2c_remove,
  94. .id_table = st_gyro_id_table,
  95. };
  96. module_i2c_driver(st_gyro_driver);
  97. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  98. MODULE_DESCRIPTION("STMicroelectronics gyroscopes i2c driver");
  99. MODULE_LICENSE("GPL v2");