hts221_spi.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * STMicroelectronics hts221 spi driver
  3. *
  4. * Copyright 2016 STMicroelectronics Inc.
  5. *
  6. * Lorenzo Bianconi <lorenzo.bianconi@st.com>
  7. *
  8. * Licensed under the GPL-2.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/spi/spi.h>
  13. #include <linux/slab.h>
  14. #include <linux/regmap.h>
  15. #include "hts221.h"
  16. #define HTS221_SPI_READ BIT(7)
  17. #define HTS221_SPI_AUTO_INCREMENT BIT(6)
  18. static const struct regmap_config hts221_spi_regmap_config = {
  19. .reg_bits = 8,
  20. .val_bits = 8,
  21. .write_flag_mask = HTS221_SPI_AUTO_INCREMENT,
  22. .read_flag_mask = HTS221_SPI_READ | HTS221_SPI_AUTO_INCREMENT,
  23. };
  24. static int hts221_spi_probe(struct spi_device *spi)
  25. {
  26. struct regmap *regmap;
  27. regmap = devm_regmap_init_spi(spi, &hts221_spi_regmap_config);
  28. if (IS_ERR(regmap)) {
  29. dev_err(&spi->dev, "Failed to register spi regmap %d\n",
  30. (int)PTR_ERR(regmap));
  31. return PTR_ERR(regmap);
  32. }
  33. return hts221_probe(&spi->dev, spi->irq,
  34. spi->modalias, regmap);
  35. }
  36. static const struct of_device_id hts221_spi_of_match[] = {
  37. { .compatible = "st,hts221", },
  38. {},
  39. };
  40. MODULE_DEVICE_TABLE(of, hts221_spi_of_match);
  41. static const struct spi_device_id hts221_spi_id_table[] = {
  42. { HTS221_DEV_NAME },
  43. {},
  44. };
  45. MODULE_DEVICE_TABLE(spi, hts221_spi_id_table);
  46. static struct spi_driver hts221_driver = {
  47. .driver = {
  48. .name = "hts221_spi",
  49. .pm = &hts221_pm_ops,
  50. .of_match_table = of_match_ptr(hts221_spi_of_match),
  51. },
  52. .probe = hts221_spi_probe,
  53. .id_table = hts221_spi_id_table,
  54. };
  55. module_spi_driver(hts221_driver);
  56. MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
  57. MODULE_DESCRIPTION("STMicroelectronics hts221 spi driver");
  58. MODULE_LICENSE("GPL v2");