st_gyro_spi.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/spi/spi.h>
  14. #include <linux/iio/iio.h>
  15. #include <linux/iio/common/st_sensors.h>
  16. #include <linux/iio/common/st_sensors_spi.h>
  17. #include "st_gyro.h"
  18. static int st_gyro_spi_probe(struct spi_device *spi)
  19. {
  20. struct iio_dev *indio_dev;
  21. struct st_sensor_data *gdata;
  22. int err;
  23. indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*gdata));
  24. if (!indio_dev)
  25. return -ENOMEM;
  26. gdata = iio_priv(indio_dev);
  27. st_sensors_spi_configure(indio_dev, spi, gdata);
  28. err = st_gyro_common_probe(indio_dev);
  29. if (err < 0)
  30. return err;
  31. return 0;
  32. }
  33. static int st_gyro_spi_remove(struct spi_device *spi)
  34. {
  35. st_gyro_common_remove(spi_get_drvdata(spi));
  36. return 0;
  37. }
  38. static const struct spi_device_id st_gyro_id_table[] = {
  39. { L3G4200D_GYRO_DEV_NAME },
  40. { LSM330D_GYRO_DEV_NAME },
  41. { LSM330DL_GYRO_DEV_NAME },
  42. { LSM330DLC_GYRO_DEV_NAME },
  43. { L3GD20_GYRO_DEV_NAME },
  44. { L3G4IS_GYRO_DEV_NAME },
  45. { LSM330_GYRO_DEV_NAME },
  46. {},
  47. };
  48. MODULE_DEVICE_TABLE(spi, st_gyro_id_table);
  49. static struct spi_driver st_gyro_driver = {
  50. .driver = {
  51. .name = "st-gyro-spi",
  52. },
  53. .probe = st_gyro_spi_probe,
  54. .remove = st_gyro_spi_remove,
  55. .id_table = st_gyro_id_table,
  56. };
  57. module_spi_driver(st_gyro_driver);
  58. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  59. MODULE_DESCRIPTION("STMicroelectronics gyroscopes spi driver");
  60. MODULE_LICENSE("GPL v2");