st_uvis25_spi.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * STMicroelectronics uvis25 spi driver
  3. *
  4. * Copyright 2017 STMicroelectronics Inc.
  5. *
  6. * Lorenzo Bianconi <lorenzo.bianconi83@gmail.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 "st_uvis25.h"
  16. #define UVIS25_SENSORS_SPI_READ BIT(7)
  17. #define UVIS25_SPI_AUTO_INCREMENT BIT(6)
  18. static const struct regmap_config st_uvis25_spi_regmap_config = {
  19. .reg_bits = 8,
  20. .val_bits = 8,
  21. .read_flag_mask = UVIS25_SENSORS_SPI_READ | UVIS25_SPI_AUTO_INCREMENT,
  22. .write_flag_mask = UVIS25_SPI_AUTO_INCREMENT,
  23. };
  24. static int st_uvis25_spi_probe(struct spi_device *spi)
  25. {
  26. struct regmap *regmap;
  27. regmap = devm_regmap_init_spi(spi, &st_uvis25_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 st_uvis25_probe(&spi->dev, spi->irq, regmap);
  34. }
  35. static const struct of_device_id st_uvis25_spi_of_match[] = {
  36. { .compatible = "st,uvis25", },
  37. {},
  38. };
  39. MODULE_DEVICE_TABLE(of, st_uvis25_spi_of_match);
  40. static const struct spi_device_id st_uvis25_spi_id_table[] = {
  41. { ST_UVIS25_DEV_NAME },
  42. {},
  43. };
  44. MODULE_DEVICE_TABLE(spi, st_uvis25_spi_id_table);
  45. static struct spi_driver st_uvis25_driver = {
  46. .driver = {
  47. .name = "st_uvis25_spi",
  48. .pm = &st_uvis25_pm_ops,
  49. .of_match_table = of_match_ptr(st_uvis25_spi_of_match),
  50. },
  51. .probe = st_uvis25_spi_probe,
  52. .id_table = st_uvis25_spi_id_table,
  53. };
  54. module_spi_driver(st_uvis25_driver);
  55. MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>");
  56. MODULE_DESCRIPTION("STMicroelectronics uvis25 spi driver");
  57. MODULE_LICENSE("GPL v2");