tsc2004.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * TSC2004 touchscreen driver
  3. *
  4. * Copyright (C) 2015 QWERTY Embedded Design
  5. * Copyright (C) 2015 EMAC Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/input.h>
  19. #include <linux/of.h>
  20. #include <linux/i2c.h>
  21. #include <linux/regmap.h>
  22. #include "tsc200x-core.h"
  23. static int tsc2004_cmd(struct device *dev, u8 cmd)
  24. {
  25. u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
  26. s32 data;
  27. struct i2c_client *i2c = to_i2c_client(dev);
  28. data = i2c_smbus_write_byte(i2c, tx);
  29. if (data < 0) {
  30. dev_err(dev, "%s: failed, command: %x i2c error: %d\n",
  31. __func__, cmd, data);
  32. return data;
  33. }
  34. return 0;
  35. }
  36. static int tsc2004_probe(struct i2c_client *i2c,
  37. const struct i2c_device_id *id)
  38. {
  39. return tsc200x_probe(&i2c->dev, i2c->irq, BUS_I2C,
  40. devm_regmap_init_i2c(i2c, &tsc200x_regmap_config),
  41. tsc2004_cmd);
  42. }
  43. static int tsc2004_remove(struct i2c_client *i2c)
  44. {
  45. return tsc200x_remove(&i2c->dev);
  46. }
  47. static const struct i2c_device_id tsc2004_idtable[] = {
  48. { "tsc2004", 0 },
  49. { }
  50. };
  51. MODULE_DEVICE_TABLE(i2c, tsc2004_idtable);
  52. #ifdef CONFIG_OF
  53. static const struct of_device_id tsc2004_of_match[] = {
  54. { .compatible = "ti,tsc2004" },
  55. { /* sentinel */ }
  56. };
  57. MODULE_DEVICE_TABLE(of, tsc2004_of_match);
  58. #endif
  59. static struct i2c_driver tsc2004_driver = {
  60. .driver = {
  61. .name = "tsc2004",
  62. .of_match_table = of_match_ptr(tsc2004_of_match),
  63. .pm = &tsc200x_pm_ops,
  64. },
  65. .id_table = tsc2004_idtable,
  66. .probe = tsc2004_probe,
  67. .remove = tsc2004_remove,
  68. };
  69. module_i2c_driver(tsc2004_driver);
  70. MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
  71. MODULE_DESCRIPTION("TSC2004 Touchscreen Driver");
  72. MODULE_LICENSE("GPL");