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