ad7879-spi.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * AD7879/AD7889 touchscreen (SPI bus)
  3. *
  4. * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <linux/input.h> /* BUS_SPI */
  9. #include <linux/pm.h>
  10. #include <linux/spi/spi.h>
  11. #include <linux/module.h>
  12. #include <linux/of.h>
  13. #include <linux/regmap.h>
  14. #include "ad7879.h"
  15. #define AD7879_DEVID 0x7A /* AD7879/AD7889 */
  16. #define MAX_SPI_FREQ_HZ 5000000
  17. #define AD7879_CMD_MAGIC 0xE0
  18. #define AD7879_CMD_READ BIT(2)
  19. static const struct regmap_config ad7879_spi_regmap_config = {
  20. .reg_bits = 16,
  21. .val_bits = 16,
  22. .max_register = 15,
  23. .read_flag_mask = AD7879_CMD_MAGIC | AD7879_CMD_READ,
  24. .write_flag_mask = AD7879_CMD_MAGIC,
  25. };
  26. static int ad7879_spi_probe(struct spi_device *spi)
  27. {
  28. struct regmap *regmap;
  29. /* don't exceed max specified SPI CLK frequency */
  30. if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) {
  31. dev_err(&spi->dev, "SPI CLK %d Hz?\n", spi->max_speed_hz);
  32. return -EINVAL;
  33. }
  34. regmap = devm_regmap_init_spi(spi, &ad7879_spi_regmap_config);
  35. if (IS_ERR(regmap))
  36. return PTR_ERR(regmap);
  37. return ad7879_probe(&spi->dev, regmap, spi->irq, BUS_SPI, AD7879_DEVID);
  38. }
  39. #ifdef CONFIG_OF
  40. static const struct of_device_id ad7879_spi_dt_ids[] = {
  41. { .compatible = "adi,ad7879", },
  42. { }
  43. };
  44. MODULE_DEVICE_TABLE(of, ad7879_spi_dt_ids);
  45. #endif
  46. static struct spi_driver ad7879_spi_driver = {
  47. .driver = {
  48. .name = "ad7879",
  49. .pm = &ad7879_pm_ops,
  50. .of_match_table = of_match_ptr(ad7879_spi_dt_ids),
  51. },
  52. .probe = ad7879_spi_probe,
  53. };
  54. module_spi_driver(ad7879_spi_driver);
  55. MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
  56. MODULE_DESCRIPTION("AD7879(-1) touchscreen SPI bus driver");
  57. MODULE_LICENSE("GPL");
  58. MODULE_ALIAS("spi:ad7879");