ad7879-spi.c 1.7 KB

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