tsc2004.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. const struct i2c_device_id *id)
  33. {
  34. return tsc200x_probe(&i2c->dev, i2c->irq, &tsc2004_input_id,
  35. devm_regmap_init_i2c(i2c, &tsc200x_regmap_config),
  36. tsc2004_cmd);
  37. }
  38. static void tsc2004_remove(struct i2c_client *i2c)
  39. {
  40. tsc200x_remove(&i2c->dev);
  41. }
  42. static const struct i2c_device_id tsc2004_idtable[] = {
  43. { "tsc2004", 0 },
  44. { }
  45. };
  46. MODULE_DEVICE_TABLE(i2c, tsc2004_idtable);
  47. #ifdef CONFIG_OF
  48. static const struct of_device_id tsc2004_of_match[] = {
  49. { .compatible = "ti,tsc2004" },
  50. { /* sentinel */ }
  51. };
  52. MODULE_DEVICE_TABLE(of, tsc2004_of_match);
  53. #endif
  54. static struct i2c_driver tsc2004_driver = {
  55. .driver = {
  56. .name = "tsc2004",
  57. .of_match_table = of_match_ptr(tsc2004_of_match),
  58. .pm = &tsc200x_pm_ops,
  59. },
  60. .id_table = tsc2004_idtable,
  61. .probe = tsc2004_probe,
  62. .remove = tsc2004_remove,
  63. };
  64. module_i2c_driver(tsc2004_driver);
  65. MODULE_AUTHOR("Michael Welling <[email protected]>");
  66. MODULE_DESCRIPTION("TSC2004 Touchscreen Driver");
  67. MODULE_LICENSE("GPL");