tsc2005.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * TSC2005 touchscreen driver
  4. *
  5. * Copyright (C) 2006-2010 Nokia Corporation
  6. * Copyright (C) 2015 QWERTY Embedded Design
  7. * Copyright (C) 2015 EMAC Inc.
  8. *
  9. * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com>
  10. */
  11. #include <linux/input.h>
  12. #include <linux/module.h>
  13. #include <linux/of.h>
  14. #include <linux/spi/spi.h>
  15. #include <linux/regmap.h>
  16. #include "tsc200x-core.h"
  17. static const struct input_id tsc2005_input_id = {
  18. .bustype = BUS_SPI,
  19. .product = 2005,
  20. };
  21. static int tsc2005_cmd(struct device *dev, u8 cmd)
  22. {
  23. u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
  24. struct spi_transfer xfer = {
  25. .tx_buf = &tx,
  26. .len = 1,
  27. .bits_per_word = 8,
  28. };
  29. struct spi_message msg;
  30. struct spi_device *spi = to_spi_device(dev);
  31. int error;
  32. spi_message_init(&msg);
  33. spi_message_add_tail(&xfer, &msg);
  34. error = spi_sync(spi, &msg);
  35. if (error) {
  36. dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
  37. __func__, cmd, error);
  38. return error;
  39. }
  40. return 0;
  41. }
  42. static int tsc2005_probe(struct spi_device *spi)
  43. {
  44. int error;
  45. spi->mode = SPI_MODE_0;
  46. spi->bits_per_word = 8;
  47. if (!spi->max_speed_hz)
  48. spi->max_speed_hz = TSC2005_SPI_MAX_SPEED_HZ;
  49. error = spi_setup(spi);
  50. if (error)
  51. return error;
  52. return tsc200x_probe(&spi->dev, spi->irq, &tsc2005_input_id,
  53. devm_regmap_init_spi(spi, &tsc200x_regmap_config),
  54. tsc2005_cmd);
  55. }
  56. #ifdef CONFIG_OF
  57. static const struct of_device_id tsc2005_of_match[] = {
  58. { .compatible = "ti,tsc2005" },
  59. { /* sentinel */ }
  60. };
  61. MODULE_DEVICE_TABLE(of, tsc2005_of_match);
  62. #endif
  63. static struct spi_driver tsc2005_driver = {
  64. .driver = {
  65. .name = "tsc2005",
  66. .dev_groups = tsc200x_groups,
  67. .of_match_table = of_match_ptr(tsc2005_of_match),
  68. .pm = pm_sleep_ptr(&tsc200x_pm_ops),
  69. },
  70. .probe = tsc2005_probe,
  71. };
  72. module_spi_driver(tsc2005_driver);
  73. MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
  74. MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
  75. MODULE_LICENSE("GPL");
  76. MODULE_ALIAS("spi:tsc2005");