rm3100-spi.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Support for PNI RM3100 3-axis geomagnetic sensor on a spi bus.
  4. *
  5. * Copyright (C) 2018 Song Qiang <[email protected]>
  6. */
  7. #include <linux/module.h>
  8. #include <linux/spi/spi.h>
  9. #include "rm3100.h"
  10. static const struct regmap_config rm3100_regmap_config = {
  11. .reg_bits = 8,
  12. .val_bits = 8,
  13. .rd_table = &rm3100_readable_table,
  14. .wr_table = &rm3100_writable_table,
  15. .volatile_table = &rm3100_volatile_table,
  16. .read_flag_mask = 0x80,
  17. .cache_type = REGCACHE_RBTREE,
  18. };
  19. static int rm3100_probe(struct spi_device *spi)
  20. {
  21. struct regmap *regmap;
  22. int ret;
  23. /* Actually this device supports both mode 0 and mode 3. */
  24. spi->mode = SPI_MODE_0;
  25. /* Data rates cannot exceed 1Mbits. */
  26. spi->max_speed_hz = 1000000;
  27. spi->bits_per_word = 8;
  28. ret = spi_setup(spi);
  29. if (ret)
  30. return ret;
  31. regmap = devm_regmap_init_spi(spi, &rm3100_regmap_config);
  32. if (IS_ERR(regmap))
  33. return PTR_ERR(regmap);
  34. return rm3100_common_probe(&spi->dev, regmap, spi->irq);
  35. }
  36. static const struct of_device_id rm3100_dt_match[] = {
  37. { .compatible = "pni,rm3100", },
  38. { }
  39. };
  40. MODULE_DEVICE_TABLE(of, rm3100_dt_match);
  41. static struct spi_driver rm3100_driver = {
  42. .driver = {
  43. .name = "rm3100-spi",
  44. .of_match_table = rm3100_dt_match,
  45. },
  46. .probe = rm3100_probe,
  47. };
  48. module_spi_driver(rm3100_driver);
  49. MODULE_AUTHOR("Song Qiang <[email protected]>");
  50. MODULE_DESCRIPTION("PNI RM3100 3-axis magnetometer spi driver");
  51. MODULE_LICENSE("GPL v2");
  52. MODULE_IMPORT_NS(IIO_RM3100);