hts221_spi.c 1.7 KB

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