tsc2004.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * TSC2004 touchscreen driver
  4. *
  5. * Copyright (C) 2015 QWERTY Embedded Design
  6. * Copyright (C) 2015 EMAC Inc.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/input.h>
  10. #include <linux/of.h>
  11. #include <linux/i2c.h>
  12. #include <linux/regmap.h>
  13. #include "tsc200x-core.h"
  14. static const struct input_id tsc2004_input_id = {
  15. .bustype = BUS_I2C,
  16. .product = 2004,
  17. };
  18. static int tsc2004_cmd(struct device *dev, u8 cmd)
  19. {
  20. u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
  21. s32 data;
  22. struct i2c_client *i2c = to_i2c_client(dev);
  23. data = i2c_smbus_write_byte(i2c, tx);
  24. if (data < 0) {
  25. dev_err(dev, "%s: failed, command: %x i2c error: %d\n",
  26. __func__, cmd, data);
  27. return data;
  28. }
  29. return 0;
  30. }
  31. static int tsc2004_probe(struct i2c_client *i2c)
  32. {
  33. return tsc200x_probe(&i2c->dev, i2c->irq, &tsc2004_input_id,
  34. devm_regmap_init_i2c(i2c, &tsc200x_regmap_config),
  35. tsc2004_cmd);
  36. }
  37. static const struct i2c_device_id tsc2004_idtable[] = {
  38. { "tsc2004" },
  39. { }
  40. };
  41. MODULE_DEVICE_TABLE(i2c, tsc2004_idtable);
  42. #ifdef CONFIG_OF
  43. static const struct of_device_id tsc2004_of_match[] = {
  44. { .compatible = "ti,tsc2004" },
  45. { /* sentinel */ }
  46. };
  47. MODULE_DEVICE_TABLE(of, tsc2004_of_match);
  48. #endif
  49. static struct i2c_driver tsc2004_driver = {
  50. .driver = {
  51. .name = "tsc2004",
  52. .dev_groups = tsc200x_groups,
  53. .of_match_table = of_match_ptr(tsc2004_of_match),
  54. .pm = pm_sleep_ptr(&tsc200x_pm_ops),
  55. },
  56. .id_table = tsc2004_idtable,
  57. .probe = tsc2004_probe,
  58. };
  59. module_i2c_driver(tsc2004_driver);
  60. MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
  61. MODULE_DESCRIPTION("TSC2004 Touchscreen Driver");
  62. MODULE_LICENSE("GPL");