blob: 58f72e0246ab7a5ab24c56436084b1306e383fcc [file] [log] [blame]
Mike Frysinger4397c982010-06-30 01:40:52 -07001/*
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>
Stefan Agnerfa6e3ca2016-03-08 10:35:24 -080013#include <linux/of.h>
Mark Brownd5dc9ac2011-01-06 23:01:02 -080014#include <linux/pm.h>
Mike Frysinger4397c982010-06-30 01:40:52 -070015
16#include "ad7879.h"
17
18#define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
19
Mike Frysinger4397c982010-06-30 01:40:52 -070020/* All registers are word-sized.
21 * AD7879 uses a high-byte first convention.
22 */
23static int ad7879_i2c_read(struct device *dev, u8 reg)
24{
25 struct i2c_client *client = to_i2c_client(dev);
26
Jonathan Cameron75255b22011-11-29 11:23:27 -080027 return i2c_smbus_read_word_swapped(client, reg);
Mike Frysinger4397c982010-06-30 01:40:52 -070028}
29
30static int ad7879_i2c_multi_read(struct device *dev,
31 u8 first_reg, u8 count, u16 *buf)
32{
Michael Hennerich16ea10a2010-06-30 14:51:09 -070033 struct i2c_client *client = to_i2c_client(dev);
Mike Frysinger4397c982010-06-30 01:40:52 -070034 u8 idx;
35
Michael Hennerich16ea10a2010-06-30 14:51:09 -070036 i2c_smbus_read_i2c_block_data(client, first_reg, count * 2, (u8 *)buf);
37
Mike Frysinger4397c982010-06-30 01:40:52 -070038 for (idx = 0; idx < count; ++idx)
Michael Hennerich16ea10a2010-06-30 14:51:09 -070039 buf[idx] = swab16(buf[idx]);
Mike Frysinger4397c982010-06-30 01:40:52 -070040
41 return 0;
42}
43
44static int ad7879_i2c_write(struct device *dev, u8 reg, u16 val)
45{
46 struct i2c_client *client = to_i2c_client(dev);
47
Jonathan Cameron75255b22011-11-29 11:23:27 -080048 return i2c_smbus_write_word_swapped(client, reg, val);
Mike Frysinger4397c982010-06-30 01:40:52 -070049}
50
51static const struct ad7879_bus_ops ad7879_i2c_bus_ops = {
52 .bustype = BUS_I2C,
53 .read = ad7879_i2c_read,
54 .multi_read = ad7879_i2c_multi_read,
55 .write = ad7879_i2c_write,
56};
57
Bill Pemberton5298cc42012-11-23 21:38:25 -080058static int ad7879_i2c_probe(struct i2c_client *client,
Mike Frysinger4397c982010-06-30 01:40:52 -070059 const struct i2c_device_id *id)
60{
61 struct ad7879 *ts;
62
63 if (!i2c_check_functionality(client->adapter,
64 I2C_FUNC_SMBUS_WORD_DATA)) {
65 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
66 return -EIO;
67 }
68
69 ts = ad7879_probe(&client->dev, AD7879_DEVID, client->irq,
70 &ad7879_i2c_bus_ops);
71 if (IS_ERR(ts))
72 return PTR_ERR(ts);
73
74 i2c_set_clientdata(client, ts);
75
76 return 0;
77}
78
Bill Pembertone2619cf2012-11-23 21:50:47 -080079static int ad7879_i2c_remove(struct i2c_client *client)
Mike Frysinger4397c982010-06-30 01:40:52 -070080{
81 struct ad7879 *ts = i2c_get_clientdata(client);
82
83 ad7879_remove(ts);
84
85 return 0;
86}
87
88static const struct i2c_device_id ad7879_id[] = {
89 { "ad7879", 0 },
90 { "ad7889", 0 },
91 { }
92};
93MODULE_DEVICE_TABLE(i2c, ad7879_id);
94
Stefan Agnerfa6e3ca2016-03-08 10:35:24 -080095#ifdef CONFIG_OF
96static const struct of_device_id ad7879_i2c_dt_ids[] = {
97 { .compatible = "adi,ad7879-1", },
98 { }
99};
100MODULE_DEVICE_TABLE(of, ad7879_i2c_dt_ids);
101#endif
102
Mike Frysinger4397c982010-06-30 01:40:52 -0700103static struct i2c_driver ad7879_i2c_driver = {
104 .driver = {
105 .name = "ad7879",
Dmitry Torokhov8672bd92011-11-14 00:32:09 -0800106 .pm = &ad7879_pm_ops,
Stefan Agnerfa6e3ca2016-03-08 10:35:24 -0800107 .of_match_table = of_match_ptr(ad7879_i2c_dt_ids),
Mike Frysinger4397c982010-06-30 01:40:52 -0700108 },
109 .probe = ad7879_i2c_probe,
Bill Pemberton1cb0aa82012-11-23 21:27:39 -0800110 .remove = ad7879_i2c_remove,
Mike Frysinger4397c982010-06-30 01:40:52 -0700111 .id_table = ad7879_id,
112};
113
Axel Lin1b92c1c2012-03-16 23:05:41 -0700114module_i2c_driver(ad7879_i2c_driver);
Mike Frysinger4397c982010-06-30 01:40:52 -0700115
116MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
117MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver");
118MODULE_LICENSE("GPL");