st_gyro_i2c.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. static int st_gyro_i2c_probe(struct i2c_client *client,
  19. const struct i2c_device_id *id)
  20. {
  21. struct iio_dev *indio_dev;
  22. struct st_sensor_data *gdata;
  23. int err;
  24. indio_dev = iio_device_alloc(sizeof(*gdata));
  25. if (indio_dev == NULL) {
  26. err = -ENOMEM;
  27. goto iio_device_alloc_error;
  28. }
  29. gdata = iio_priv(indio_dev);
  30. gdata->dev = &client->dev;
  31. st_sensors_i2c_configure(indio_dev, client, gdata);
  32. err = st_gyro_common_probe(indio_dev);
  33. if (err < 0)
  34. goto st_gyro_common_probe_error;
  35. return 0;
  36. st_gyro_common_probe_error:
  37. iio_device_free(indio_dev);
  38. iio_device_alloc_error:
  39. return err;
  40. }
  41. static int st_gyro_i2c_remove(struct i2c_client *client)
  42. {
  43. st_gyro_common_remove(i2c_get_clientdata(client));
  44. return 0;
  45. }
  46. static const struct i2c_device_id st_gyro_id_table[] = {
  47. { L3G4200D_GYRO_DEV_NAME },
  48. { LSM330D_GYRO_DEV_NAME },
  49. { LSM330DL_GYRO_DEV_NAME },
  50. { LSM330DLC_GYRO_DEV_NAME },
  51. { L3GD20_GYRO_DEV_NAME },
  52. { L3GD20H_GYRO_DEV_NAME },
  53. { L3G4IS_GYRO_DEV_NAME },
  54. { LSM330_GYRO_DEV_NAME },
  55. {},
  56. };
  57. MODULE_DEVICE_TABLE(i2c, st_gyro_id_table);
  58. static struct i2c_driver st_gyro_driver = {
  59. .driver = {
  60. .owner = THIS_MODULE,
  61. .name = "st-gyro-i2c",
  62. },
  63. .probe = st_gyro_i2c_probe,
  64. .remove = st_gyro_i2c_remove,
  65. .id_table = st_gyro_id_table,
  66. };
  67. module_i2c_driver(st_gyro_driver);
  68. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  69. MODULE_DESCRIPTION("STMicroelectronics gyroscopes i2c driver");
  70. MODULE_LICENSE("GPL v2");