aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen/ad7879-i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/touchscreen/ad7879-i2c.c')
-rw-r--r--drivers/input/touchscreen/ad7879-i2c.c143
1 files changed, 143 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/ad7879-i2c.c b/drivers/input/touchscreen/ad7879-i2c.c
new file mode 100644
index 000000000000..d82a38ee9a3e
--- /dev/null
+++ b/drivers/input/touchscreen/ad7879-i2c.c
@@ -0,0 +1,143 @@
1/*
2 * AD7879-1/AD7889-1 touchscreen (I2C bus)
3 *
4 * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/input.h> /* BUS_I2C */
10#include <linux/i2c.h>
11#include <linux/module.h>
12#include <linux/types.h>
13
14#include "ad7879.h"
15
16#define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
17
18#ifdef CONFIG_PM
19static int ad7879_i2c_suspend(struct i2c_client *client, pm_message_t message)
20{
21 struct ad7879 *ts = i2c_get_clientdata(client);
22
23 ad7879_suspend(ts);
24
25 return 0;
26}
27
28static int ad7879_i2c_resume(struct i2c_client *client)
29{
30 struct ad7879 *ts = i2c_get_clientdata(client);
31
32 ad7879_resume(ts);
33
34 return 0;
35}
36#else
37# define ad7879_i2c_suspend NULL
38# define ad7879_i2c_resume NULL
39#endif
40
41/* All registers are word-sized.
42 * AD7879 uses a high-byte first convention.
43 */
44static int ad7879_i2c_read(struct device *dev, u8 reg)
45{
46 struct i2c_client *client = to_i2c_client(dev);
47
48 return swab16(i2c_smbus_read_word_data(client, reg));
49}
50
51static int ad7879_i2c_multi_read(struct device *dev,
52 u8 first_reg, u8 count, u16 *buf)
53{
54 struct i2c_client *client = to_i2c_client(dev);
55 u8 idx;
56
57 i2c_smbus_read_i2c_block_data(client, first_reg, count * 2, (u8 *)buf);
58
59 for (idx = 0; idx < count; ++idx)
60 buf[idx] = swab16(buf[idx]);
61
62 return 0;
63}
64
65static int ad7879_i2c_write(struct device *dev, u8 reg, u16 val)
66{
67 struct i2c_client *client = to_i2c_client(dev);
68
69 return i2c_smbus_write_word_data(client, reg, swab16(val));
70}
71
72static const struct ad7879_bus_ops ad7879_i2c_bus_ops = {
73 .bustype = BUS_I2C,
74 .read = ad7879_i2c_read,
75 .multi_read = ad7879_i2c_multi_read,
76 .write = ad7879_i2c_write,
77};
78
79static int __devinit ad7879_i2c_probe(struct i2c_client *client,
80 const struct i2c_device_id *id)
81{
82 struct ad7879 *ts;
83
84 if (!i2c_check_functionality(client->adapter,
85 I2C_FUNC_SMBUS_WORD_DATA)) {
86 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
87 return -EIO;
88 }
89
90 ts = ad7879_probe(&client->dev, AD7879_DEVID, client->irq,
91 &ad7879_i2c_bus_ops);
92 if (IS_ERR(ts))
93 return PTR_ERR(ts);
94
95 i2c_set_clientdata(client, ts);
96
97 return 0;
98}
99
100static int __devexit ad7879_i2c_remove(struct i2c_client *client)
101{
102 struct ad7879 *ts = i2c_get_clientdata(client);
103
104 ad7879_remove(ts);
105
106 return 0;
107}
108
109static const struct i2c_device_id ad7879_id[] = {
110 { "ad7879", 0 },
111 { "ad7889", 0 },
112 { }
113};
114MODULE_DEVICE_TABLE(i2c, ad7879_id);
115
116static struct i2c_driver ad7879_i2c_driver = {
117 .driver = {
118 .name = "ad7879",
119 .owner = THIS_MODULE,
120 },
121 .probe = ad7879_i2c_probe,
122 .remove = __devexit_p(ad7879_i2c_remove),
123 .suspend = ad7879_i2c_suspend,
124 .resume = ad7879_i2c_resume,
125 .id_table = ad7879_id,
126};
127
128static int __init ad7879_i2c_init(void)
129{
130 return i2c_add_driver(&ad7879_i2c_driver);
131}
132module_init(ad7879_i2c_init);
133
134static void __exit ad7879_i2c_exit(void)
135{
136 i2c_del_driver(&ad7879_i2c_driver);
137}
138module_exit(ad7879_i2c_exit);
139
140MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
141MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver");
142MODULE_LICENSE("GPL");
143MODULE_ALIAS("i2c:ad7879");