tsc2005.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/module.h>
  21. #include <linux/input.h>
  22. #include <linux/spi/spi.h>
  23. #include <linux/regmap.h>
  24. #include "tsc200x-core.h"
  25. static int tsc2005_cmd(struct device *dev, u8 cmd)
  26. {
  27. u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
  28. struct spi_transfer xfer = {
  29. .tx_buf = &tx,
  30. .len = 1,
  31. .bits_per_word = 8,
  32. };
  33. struct spi_message msg;
  34. struct spi_device *spi = to_spi_device(dev);
  35. int error;
  36. spi_message_init(&msg);
  37. spi_message_add_tail(&xfer, &msg);
  38. error = spi_sync(spi, &msg);
  39. if (error) {
  40. dev_err(dev, "%s: failed, command: %x, spi error: %d\n",
  41. __func__, cmd, error);
  42. return error;
  43. }
  44. return 0;
  45. }
  46. static int tsc2005_probe(struct spi_device *spi)
  47. {
  48. int error;
  49. spi->mode = SPI_MODE_0;
  50. spi->bits_per_word = 8;
  51. if (!spi->max_speed_hz)
  52. spi->max_speed_hz = TSC2005_SPI_MAX_SPEED_HZ;
  53. error = spi_setup(spi);
  54. if (error)
  55. return error;
  56. return tsc200x_probe(&spi->dev, spi->irq, BUS_SPI,
  57. devm_regmap_init_spi(spi, &tsc200x_regmap_config),
  58. tsc2005_cmd);
  59. }
  60. static int tsc2005_remove(struct spi_device *spi)
  61. {
  62. return tsc200x_remove(&spi->dev);
  63. }
  64. static struct spi_driver tsc2005_driver = {
  65. .driver = {
  66. .name = "tsc2005",
  67. .pm = &tsc200x_pm_ops,
  68. },
  69. .probe = tsc2005_probe,
  70. .remove = tsc2005_remove,
  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");