tsc2005.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * TSC2005 touchscreen driver
  3. *
  4. * Copyright (C) 2006-2010 Nokia Corporation
  5. * Copyright (C) 2015 QWERTY Embedded Design
  6. * Copyright (C) 2015 EMAC Inc.
  7. *
  8. * Based on original tsc2005.c by Lauri Leukkunen <lauri.leukkunen@nokia.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. */
  20. #include <linux/input.h>
  21. #include <linux/module.h>
  22. #include <linux/of.h>
  23. #include <linux/spi/spi.h>
  24. #include <linux/regmap.h>
  25. #include "tsc200x-core.h"
  26. static const struct input_id tsc2005_input_id = {
  27. .bustype = BUS_SPI,
  28. .product = 2005,
  29. };
  30. static int tsc2005_cmd(struct device *dev, u8 cmd)
  31. {
  32. u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
  33. struct spi_transfer xfer = {
  34. .tx_buf = &tx,
  35. .len = 1,
  36. .bits_per_word = 8,
  37. };
  38. struct spi_message msg;
  39. struct spi_device *spi = to_spi_device(dev);
  40. int error;
  41. spi_message_init(&msg);
  42. spi_message_add_tail(&xfer, &msg);
  43. error = spi_sync(spi, &msg);
  44. if (error) {
  45. dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
  46. __func__, cmd, error);
  47. return error;
  48. }
  49. return 0;
  50. }
  51. static int tsc2005_probe(struct spi_device *spi)
  52. {
  53. int error;
  54. spi->mode = SPI_MODE_0;
  55. spi->bits_per_word = 8;
  56. if (!spi->max_speed_hz)
  57. spi->max_speed_hz = TSC2005_SPI_MAX_SPEED_HZ;
  58. error = spi_setup(spi);
  59. if (error)
  60. return error;
  61. return tsc200x_probe(&spi->dev, spi->irq, &tsc2005_input_id,
  62. devm_regmap_init_spi(spi, &tsc200x_regmap_config),
  63. tsc2005_cmd);
  64. }
  65. static int tsc2005_remove(struct spi_device *spi)
  66. {
  67. return tsc200x_remove(&spi->dev);
  68. }
  69. #ifdef CONFIG_OF
  70. static const struct of_device_id tsc2005_of_match[] = {
  71. { .compatible = "ti,tsc2005" },
  72. { /* sentinel */ }
  73. };
  74. MODULE_DEVICE_TABLE(of, tsc2005_of_match);
  75. #endif
  76. static struct spi_driver tsc2005_driver = {
  77. .driver = {
  78. .name = "tsc2005",
  79. .of_match_table = of_match_ptr(tsc2005_of_match),
  80. .pm = &tsc200x_pm_ops,
  81. },
  82. .probe = tsc2005_probe,
  83. .remove = tsc2005_remove,
  84. };
  85. module_spi_driver(tsc2005_driver);
  86. MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
  87. MODULE_DESCRIPTION("TSC2005 Touchscreen Driver");
  88. MODULE_LICENSE("GPL");
  89. MODULE_ALIAS("spi:tsc2005");