st_magn_spi.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * STMicroelectronics magnetometers 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_magn.h"
  18. static int st_magn_spi_probe(struct spi_device *spi)
  19. {
  20. struct iio_dev *indio_dev;
  21. struct st_sensor_data *mdata;
  22. int err;
  23. indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*mdata));
  24. if (!indio_dev)
  25. return -ENOMEM;
  26. mdata = iio_priv(indio_dev);
  27. st_sensors_spi_configure(indio_dev, spi, mdata);
  28. err = st_magn_common_probe(indio_dev);
  29. if (err < 0)
  30. return err;
  31. return 0;
  32. }
  33. static int st_magn_spi_remove(struct spi_device *spi)
  34. {
  35. struct iio_dev *indio_dev = spi_get_drvdata(spi);
  36. st_magn_common_remove(indio_dev);
  37. return 0;
  38. }
  39. static const struct spi_device_id st_magn_id_table[] = {
  40. { LIS3MDL_MAGN_DEV_NAME },
  41. { LSM303AGR_MAGN_DEV_NAME },
  42. {},
  43. };
  44. MODULE_DEVICE_TABLE(spi, st_magn_id_table);
  45. static struct spi_driver st_magn_driver = {
  46. .driver = {
  47. .name = "st-magn-spi",
  48. },
  49. .probe = st_magn_spi_probe,
  50. .remove = st_magn_spi_remove,
  51. .id_table = st_magn_id_table,
  52. };
  53. module_spi_driver(st_magn_driver);
  54. MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
  55. MODULE_DESCRIPTION("STMicroelectronics magnetometers spi driver");
  56. MODULE_LICENSE("GPL v2");