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>
18 #define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
20 /* All registers are word-sized.
21 * AD7879 uses a high-byte first convention.
23 static int ad7879_i2c_read(struct device
*dev
, u8 reg
)
25 struct i2c_client
*client
= to_i2c_client(dev
);
27 return i2c_smbus_read_word_swapped(client
, reg
);
30 static int ad7879_i2c_multi_read(struct device
*dev
,
31 u8 first_reg
, u8 count
, u16
*buf
)
33 struct i2c_client
*client
= to_i2c_client(dev
);
36 i2c_smbus_read_i2c_block_data(client
, first_reg
, count
* 2, (u8
*)buf
);
38 for (idx
= 0; idx
< count
; ++idx
)
39 buf
[idx
] = swab16(buf
[idx
]);
44 static int ad7879_i2c_write(struct device
*dev
, u8 reg
, u16 val
)
46 struct i2c_client
*client
= to_i2c_client(dev
);
48 return i2c_smbus_write_word_swapped(client
, reg
, val
);
51 static const struct ad7879_bus_ops ad7879_i2c_bus_ops
= {
53 .read
= ad7879_i2c_read
,
54 .multi_read
= ad7879_i2c_multi_read
,
55 .write
= ad7879_i2c_write
,
58 static int ad7879_i2c_probe(struct i2c_client
*client
,
59 const struct i2c_device_id
*id
)
63 if (!i2c_check_functionality(client
->adapter
,
64 I2C_FUNC_SMBUS_WORD_DATA
)) {
65 dev_err(&client
->dev
, "SMBUS Word Data not Supported\n");
69 ts
= ad7879_probe(&client
->dev
, AD7879_DEVID
, client
->irq
,
74 i2c_set_clientdata(client
, ts
);
79 static int ad7879_i2c_remove(struct i2c_client
*client
)
81 struct ad7879
*ts
= i2c_get_clientdata(client
);
88 static const struct i2c_device_id ad7879_id
[] = {
93 MODULE_DEVICE_TABLE(i2c
, ad7879_id
);
96 static const struct of_device_id ad7879_i2c_dt_ids
[] = {
97 { .compatible
= "adi,ad7879-1", },
100 MODULE_DEVICE_TABLE(of
, ad7879_i2c_dt_ids
);
103 static struct i2c_driver ad7879_i2c_driver
= {
106 .pm
= &ad7879_pm_ops
,
107 .of_match_table
= of_match_ptr(ad7879_i2c_dt_ids
),
109 .probe
= ad7879_i2c_probe
,
110 .remove
= ad7879_i2c_remove
,
111 .id_table
= ad7879_id
,
114 module_i2c_driver(ad7879_i2c_driver
);
116 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
117 MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver");
118 MODULE_LICENSE("GPL");