st_accel_spi.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * STMicroelectronics accelerometers driver
  3. *
  4. * Copyright 2012-2013 STMicroelectronics Inc.
  5. *
  6. * Denis Ciocca <[email protected]>
  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_accel.h"
  18. static int st_accel_spi_probe(struct spi_device *spi)
  19. {
  20. struct iio_dev *indio_dev;
  21. struct st_sensor_data *adata;
  22. int err;
  23. indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adata));
  24. if (!indio_dev)
  25. return -ENOMEM;
  26. adata = iio_priv(indio_dev);
  27. st_sensors_spi_configure(indio_dev, spi, adata);
  28. err = st_accel_common_probe(indio_dev);
  29. if (err < 0)
  30. return err;
  31. return 0;
  32. }
  33. static int st_accel_spi_remove(struct spi_device *spi)
  34. {
  35. st_accel_common_remove(spi_get_drvdata(spi));
  36. return 0;
  37. }
  38. static const struct spi_device_id st_accel_id_table[] = {
  39. { LSM303DLH_ACCEL_DEV_NAME },
  40. { LSM303DLHC_ACCEL_DEV_NAME },
  41. { LIS3DH_ACCEL_DEV_NAME },
  42. { LSM330D_ACCEL_DEV_NAME },
  43. { LSM330DL_ACCEL_DEV_NAME },
  44. { LSM330DLC_ACCEL_DEV_NAME },
  45. { LIS331DLH_ACCEL_DEV_NAME },
  46. { LSM303DL_ACCEL_DEV_NAME },
  47. { LSM303DLM_ACCEL_DEV_NAME },
  48. { LSM330_ACCEL_DEV_NAME },
  49. { LSM303AGR_ACCEL_DEV_NAME },
  50. { LIS2DH12_ACCEL_DEV_NAME },
  51. { LIS3L02DQ_ACCEL_DEV_NAME },
  52. {},
  53. };
  54. MODULE_DEVICE_TABLE(spi, st_accel_id_table);
  55. static struct spi_driver st_accel_driver = {
  56. .driver = {
  57. .name = "st-accel-spi",
  58. },
  59. .probe = st_accel_spi_probe,
  60. .remove = st_accel_spi_remove,
  61. .id_table = st_accel_id_table,
  62. };
  63. module_spi_driver(st_accel_driver);
  64. MODULE_AUTHOR("Denis Ciocca <[email protected]>");
  65. MODULE_DESCRIPTION("STMicroelectronics accelerometers spi driver");
  66. MODULE_LICENSE("GPL v2");