Linux 2.6.36-rc5
[linux-2.6/next.git] / drivers / input / touchscreen / ad7879-i2c.c
blobd82a38ee9a3ea6bcde188883233a9af311acd58d
1 /*
2 * AD7879-1/AD7889-1 touchscreen (I2C bus)
4 * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
7 */
9 #include <linux/input.h> /* BUS_I2C */
10 #include <linux/i2c.h>
11 #include <linux/module.h>
12 #include <linux/types.h>
14 #include "ad7879.h"
16 #define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
18 #ifdef CONFIG_PM
19 static int ad7879_i2c_suspend(struct i2c_client *client, pm_message_t message)
21 struct ad7879 *ts = i2c_get_clientdata(client);
23 ad7879_suspend(ts);
25 return 0;
28 static int ad7879_i2c_resume(struct i2c_client *client)
30 struct ad7879 *ts = i2c_get_clientdata(client);
32 ad7879_resume(ts);
34 return 0;
36 #else
37 # define ad7879_i2c_suspend NULL
38 # define ad7879_i2c_resume NULL
39 #endif
41 /* All registers are word-sized.
42 * AD7879 uses a high-byte first convention.
44 static int ad7879_i2c_read(struct device *dev, u8 reg)
46 struct i2c_client *client = to_i2c_client(dev);
48 return swab16(i2c_smbus_read_word_data(client, reg));
51 static int ad7879_i2c_multi_read(struct device *dev,
52 u8 first_reg, u8 count, u16 *buf)
54 struct i2c_client *client = to_i2c_client(dev);
55 u8 idx;
57 i2c_smbus_read_i2c_block_data(client, first_reg, count * 2, (u8 *)buf);
59 for (idx = 0; idx < count; ++idx)
60 buf[idx] = swab16(buf[idx]);
62 return 0;
65 static int ad7879_i2c_write(struct device *dev, u8 reg, u16 val)
67 struct i2c_client *client = to_i2c_client(dev);
69 return i2c_smbus_write_word_data(client, reg, swab16(val));
72 static 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,
79 static int __devinit ad7879_i2c_probe(struct i2c_client *client,
80 const struct i2c_device_id *id)
82 struct ad7879 *ts;
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;
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);
95 i2c_set_clientdata(client, ts);
97 return 0;
100 static int __devexit ad7879_i2c_remove(struct i2c_client *client)
102 struct ad7879 *ts = i2c_get_clientdata(client);
104 ad7879_remove(ts);
106 return 0;
109 static const struct i2c_device_id ad7879_id[] = {
110 { "ad7879", 0 },
111 { "ad7889", 0 },
114 MODULE_DEVICE_TABLE(i2c, ad7879_id);
116 static struct i2c_driver ad7879_i2c_driver = {
117 .driver = {
118 .name = "ad7879",
119 .owner = THIS_MODULE,
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,
128 static int __init ad7879_i2c_init(void)
130 return i2c_add_driver(&ad7879_i2c_driver);
132 module_init(ad7879_i2c_init);
134 static void __exit ad7879_i2c_exit(void)
136 i2c_del_driver(&ad7879_i2c_driver);
138 module_exit(ad7879_i2c_exit);
140 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
141 MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver");
142 MODULE_LICENSE("GPL");
143 MODULE_ALIAS("i2c:ad7879");