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