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.c140
1 files changed, 140 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..85dfdd27df5a
--- /dev/null
+++ b/drivers/input/touchscreen/ad7879-i2c.c
@@ -0,0 +1,140 @@
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_disable(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_enable(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 u8 idx;
55
56 for (idx = 0; idx < count; ++idx)
57 buf[idx] = ad7879_i2c_read(dev, first_reg + idx);
58
59 return 0;
60}
61
62static int ad7879_i2c_write(struct device *dev, u8 reg, u16 val)
63{
64 struct i2c_client *client = to_i2c_client(dev);
65
66 return i2c_smbus_write_word_data(client, reg, swab16(val));
67}
68
69static const struct ad7879_bus_ops ad7879_i2c_bus_ops = {
70 .bustype = BUS_I2C,
71 .read = ad7879_i2c_read,
72 .multi_read = ad7879_i2c_multi_read,
73 .write = ad7879_i2c_write,
74};
75
76static int __devinit ad7879_i2c_probe(struct i2c_client *client,
77 const struct i2c_device_id *id)
78{
79 struct ad7879 *ts;
80
81 if (!i2c_check_functionality(client->adapter,
82 I2C_FUNC_SMBUS_WORD_DATA)) {
83 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
84 return -EIO;
85 }
86
87 ts = ad7879_probe(&client->dev, AD7879_DEVID, client->irq,
88 &ad7879_i2c_bus_ops);
89 if (IS_ERR(ts))
90 return PTR_ERR(ts);
91
92 i2c_set_clientdata(client, ts);
93
94 return 0;
95}
96
97static int __devexit ad7879_i2c_remove(struct i2c_client *client)
98{
99 struct ad7879 *ts = i2c_get_clientdata(client);
100
101 ad7879_remove(ts);
102
103 return 0;
104}
105
106static const struct i2c_device_id ad7879_id[] = {
107 { "ad7879", 0 },
108 { "ad7889", 0 },
109 { }
110};
111MODULE_DEVICE_TABLE(i2c, ad7879_id);
112
113static struct i2c_driver ad7879_i2c_driver = {
114 .driver = {
115 .name = "ad7879",
116 .owner = THIS_MODULE,
117 },
118 .probe = ad7879_i2c_probe,
119 .remove = __devexit_p(ad7879_i2c_remove),
120 .suspend = ad7879_i2c_suspend,
121 .resume = ad7879_i2c_resume,
122 .id_table = ad7879_id,
123};
124
125static int __init ad7879_i2c_init(void)
126{
127 return i2c_add_driver(&ad7879_i2c_driver);
128}
129module_init(ad7879_i2c_init);
130
131static void __exit ad7879_i2c_exit(void)
132{
133 i2c_del_driver(&ad7879_i2c_driver);
134}
135module_exit(ad7879_i2c_exit);
136
137MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
138MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver");
139MODULE_LICENSE("GPL");
140MODULE_ALIAS("i2c:ad7879");