Loading...
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#include <linux/of.h>
14#include <linux/pm.h>
15#include <linux/regmap.h>
16
17#include "ad7879.h"
18
19#define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
20
21static const struct regmap_config ad7879_i2c_regmap_config = {
22 .reg_bits = 8,
23 .val_bits = 16,
24 .max_register = 15,
25};
26
27static int ad7879_i2c_probe(struct i2c_client *client,
28 const struct i2c_device_id *id)
29{
30 struct regmap *regmap;
31
32 if (!i2c_check_functionality(client->adapter,
33 I2C_FUNC_SMBUS_WORD_DATA)) {
34 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
35 return -EIO;
36 }
37
38 regmap = devm_regmap_init_i2c(client, &ad7879_i2c_regmap_config);
39 if (IS_ERR(regmap))
40 return PTR_ERR(regmap);
41
42 return ad7879_probe(&client->dev, regmap, client->irq,
43 BUS_I2C, AD7879_DEVID);
44}
45
46static const struct i2c_device_id ad7879_id[] = {
47 { "ad7879", 0 },
48 { "ad7889", 0 },
49 { }
50};
51MODULE_DEVICE_TABLE(i2c, ad7879_id);
52
53#ifdef CONFIG_OF
54static const struct of_device_id ad7879_i2c_dt_ids[] = {
55 { .compatible = "adi,ad7879-1", },
56 { }
57};
58MODULE_DEVICE_TABLE(of, ad7879_i2c_dt_ids);
59#endif
60
61static struct i2c_driver ad7879_i2c_driver = {
62 .driver = {
63 .name = "ad7879",
64 .pm = &ad7879_pm_ops,
65 .of_match_table = of_match_ptr(ad7879_i2c_dt_ids),
66 },
67 .probe = ad7879_i2c_probe,
68 .id_table = ad7879_id,
69};
70
71module_i2c_driver(ad7879_i2c_driver);
72
73MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
74MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver");
75MODULE_LICENSE("GPL");
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#include <linux/pm.h>
14
15#include "ad7879.h"
16
17#define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
18
19#ifdef CONFIG_PM
20static int ad7879_i2c_suspend(struct device *dev)
21{
22 struct i2c_client *client = to_i2c_client(dev);
23 struct ad7879 *ts = i2c_get_clientdata(client);
24
25 ad7879_suspend(ts);
26
27 return 0;
28}
29
30static int ad7879_i2c_resume(struct device *dev)
31{
32 struct i2c_client *client = to_i2c_client(dev);
33 struct ad7879 *ts = i2c_get_clientdata(client);
34
35 ad7879_resume(ts);
36
37 return 0;
38}
39
40static SIMPLE_DEV_PM_OPS(ad7879_i2c_pm, ad7879_i2c_suspend, ad7879_i2c_resume);
41#endif
42
43/* All registers are word-sized.
44 * AD7879 uses a high-byte first convention.
45 */
46static int ad7879_i2c_read(struct device *dev, u8 reg)
47{
48 struct i2c_client *client = to_i2c_client(dev);
49
50 return swab16(i2c_smbus_read_word_data(client, reg));
51}
52
53static int ad7879_i2c_multi_read(struct device *dev,
54 u8 first_reg, u8 count, u16 *buf)
55{
56 struct i2c_client *client = to_i2c_client(dev);
57 u8 idx;
58
59 i2c_smbus_read_i2c_block_data(client, first_reg, count * 2, (u8 *)buf);
60
61 for (idx = 0; idx < count; ++idx)
62 buf[idx] = swab16(buf[idx]);
63
64 return 0;
65}
66
67static int ad7879_i2c_write(struct device *dev, u8 reg, u16 val)
68{
69 struct i2c_client *client = to_i2c_client(dev);
70
71 return i2c_smbus_write_word_data(client, reg, swab16(val));
72}
73
74static const struct ad7879_bus_ops ad7879_i2c_bus_ops = {
75 .bustype = BUS_I2C,
76 .read = ad7879_i2c_read,
77 .multi_read = ad7879_i2c_multi_read,
78 .write = ad7879_i2c_write,
79};
80
81static int __devinit ad7879_i2c_probe(struct i2c_client *client,
82 const struct i2c_device_id *id)
83{
84 struct ad7879 *ts;
85
86 if (!i2c_check_functionality(client->adapter,
87 I2C_FUNC_SMBUS_WORD_DATA)) {
88 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
89 return -EIO;
90 }
91
92 ts = ad7879_probe(&client->dev, AD7879_DEVID, client->irq,
93 &ad7879_i2c_bus_ops);
94 if (IS_ERR(ts))
95 return PTR_ERR(ts);
96
97 i2c_set_clientdata(client, ts);
98
99 return 0;
100}
101
102static int __devexit ad7879_i2c_remove(struct i2c_client *client)
103{
104 struct ad7879 *ts = i2c_get_clientdata(client);
105
106 ad7879_remove(ts);
107
108 return 0;
109}
110
111static const struct i2c_device_id ad7879_id[] = {
112 { "ad7879", 0 },
113 { "ad7889", 0 },
114 { }
115};
116MODULE_DEVICE_TABLE(i2c, ad7879_id);
117
118static struct i2c_driver ad7879_i2c_driver = {
119 .driver = {
120 .name = "ad7879",
121 .owner = THIS_MODULE,
122#ifdef CONFIG_PM
123 .pm = &ad7879_i2c_pm,
124#endif
125 },
126 .probe = ad7879_i2c_probe,
127 .remove = __devexit_p(ad7879_i2c_remove),
128 .id_table = ad7879_id,
129};
130
131static int __init ad7879_i2c_init(void)
132{
133 return i2c_add_driver(&ad7879_i2c_driver);
134}
135module_init(ad7879_i2c_init);
136
137static void __exit ad7879_i2c_exit(void)
138{
139 i2c_del_driver(&ad7879_i2c_driver);
140}
141module_exit(ad7879_i2c_exit);
142
143MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
144MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver");
145MODULE_LICENSE("GPL");
146MODULE_ALIAS("i2c:ad7879");