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
9#include <linux/module.h>
10#include <linux/input.h>
11#include <linux/of.h>
12#include <linux/i2c.h>
13#include <linux/regmap.h>
14#include "tsc200x-core.h"
15
16static const struct input_id tsc2004_input_id = {
17 .bustype = BUS_I2C,
18 .product = 2004,
19};
20
21static int tsc2004_cmd(struct device *dev, u8 cmd)
22{
23 u8 tx = TSC200X_CMD | TSC200X_CMD_12BIT | cmd;
24 s32 data;
25 struct i2c_client *i2c = to_i2c_client(dev);
26
27 data = i2c_smbus_write_byte(client: i2c, value: tx);
28 if (data < 0) {
29 dev_err(dev, "%s: failed, command: %x i2c error: %d\n",
30 __func__, cmd, data);
31 return data;
32 }
33
34 return 0;
35}
36
37static int tsc2004_probe(struct i2c_client *i2c)
38
39{
40 return tsc200x_probe(dev: &i2c->dev, irq: i2c->irq, tsc_id: &tsc2004_input_id,
41 devm_regmap_init_i2c(i2c, &tsc200x_regmap_config),
42 tsc200x_cmd: tsc2004_cmd);
43}
44
45static void tsc2004_remove(struct i2c_client *i2c)
46{
47 tsc200x_remove(dev: &i2c->dev);
48}
49
50static const struct i2c_device_id tsc2004_idtable[] = {
51 { "tsc2004", 0 },
52 { }
53};
54MODULE_DEVICE_TABLE(i2c, tsc2004_idtable);
55
56#ifdef CONFIG_OF
57static const struct of_device_id tsc2004_of_match[] = {
58 { .compatible = "ti,tsc2004" },
59 { /* sentinel */ }
60};
61MODULE_DEVICE_TABLE(of, tsc2004_of_match);
62#endif
63
64static struct i2c_driver tsc2004_driver = {
65 .driver = {
66 .name = "tsc2004",
67 .of_match_table = of_match_ptr(tsc2004_of_match),
68 .pm = pm_sleep_ptr(&tsc200x_pm_ops),
69 },
70 .id_table = tsc2004_idtable,
71 .probe = tsc2004_probe,
72 .remove = tsc2004_remove,
73};
74module_i2c_driver(tsc2004_driver);
75
76MODULE_AUTHOR("Michael Welling <mwelling@ieee.org>");
77MODULE_DESCRIPTION("TSC2004 Touchscreen Driver");
78MODULE_LICENSE("GPL");
79

source code of linux/drivers/input/touchscreen/tsc2004.c