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