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.
9 #include <linux/input.h> /* BUS_I2C */
10 #include <linux/i2c.h>
11 #include <linux/module.h>
12 #include <linux/types.h>
17 #define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
19 /* All registers are word-sized.
20 * AD7879 uses a high-byte first convention.
22 static int ad7879_i2c_read(struct device
*dev
, u8 reg
)
24 struct i2c_client
*client
= to_i2c_client(dev
);
26 return i2c_smbus_read_word_swapped(client
, reg
);
29 static int ad7879_i2c_multi_read(struct device
*dev
,
30 u8 first_reg
, u8 count
, u16
*buf
)
32 struct i2c_client
*client
= to_i2c_client(dev
);
35 i2c_smbus_read_i2c_block_data(client
, first_reg
, count
* 2, (u8
*)buf
);
37 for (idx
= 0; idx
< count
; ++idx
)
38 buf
[idx
] = swab16(buf
[idx
]);
43 static int ad7879_i2c_write(struct device
*dev
, u8 reg
, u16 val
)
45 struct i2c_client
*client
= to_i2c_client(dev
);
47 return i2c_smbus_write_word_swapped(client
, reg
, val
);
50 static const struct ad7879_bus_ops ad7879_i2c_bus_ops
= {
52 .read
= ad7879_i2c_read
,
53 .multi_read
= ad7879_i2c_multi_read
,
54 .write
= ad7879_i2c_write
,
57 static int __devinit
ad7879_i2c_probe(struct i2c_client
*client
,
58 const struct i2c_device_id
*id
)
62 if (!i2c_check_functionality(client
->adapter
,
63 I2C_FUNC_SMBUS_WORD_DATA
)) {
64 dev_err(&client
->dev
, "SMBUS Word Data not Supported\n");
68 ts
= ad7879_probe(&client
->dev
, AD7879_DEVID
, client
->irq
,
73 i2c_set_clientdata(client
, ts
);
78 static int __devexit
ad7879_i2c_remove(struct i2c_client
*client
)
80 struct ad7879
*ts
= i2c_get_clientdata(client
);
87 static const struct i2c_device_id ad7879_id
[] = {
92 MODULE_DEVICE_TABLE(i2c
, ad7879_id
);
94 static struct i2c_driver ad7879_i2c_driver
= {
100 .probe
= ad7879_i2c_probe
,
101 .remove
= __devexit_p(ad7879_i2c_remove
),
102 .id_table
= ad7879_id
,
105 static int __init
ad7879_i2c_init(void)
107 return i2c_add_driver(&ad7879_i2c_driver
);
109 module_init(ad7879_i2c_init
);
111 static void __exit
ad7879_i2c_exit(void)
113 i2c_del_driver(&ad7879_i2c_driver
);
115 module_exit(ad7879_i2c_exit
);
117 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
118 MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver");
119 MODULE_LICENSE("GPL");