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/pm.h>
14
15#include "ad7879.h"
16
17#define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
18
19/* All registers are word-sized.
20 * AD7879 uses a high-byte first convention.
21 */
22static int ad7879_i2c_read(struct device *dev, u8 reg)
23{
24 struct i2c_client *client = to_i2c_client(dev);
25
26 return i2c_smbus_read_word_swapped(client, reg);
27}
28
29static int ad7879_i2c_multi_read(struct device *dev,
30 u8 first_reg, u8 count, u16 *buf)
31{
32 struct i2c_client *client = to_i2c_client(dev);
33 u8 idx;
34
35 i2c_smbus_read_i2c_block_data(client, first_reg, count * 2, (u8 *)buf);
36
37 for (idx = 0; idx < count; ++idx)
38 buf[idx] = swab16(buf[idx]);
39
40 return 0;
41}
42
43static int ad7879_i2c_write(struct device *dev, u8 reg, u16 val)
44{
45 struct i2c_client *client = to_i2c_client(dev);
46
47 return i2c_smbus_write_word_swapped(client, reg, val);
48}
49
50static const struct ad7879_bus_ops ad7879_i2c_bus_ops = {
51 .bustype = BUS_I2C,
52 .read = ad7879_i2c_read,
53 .multi_read = ad7879_i2c_multi_read,
54 .write = ad7879_i2c_write,
55};
56
57static int ad7879_i2c_probe(struct i2c_client *client,
58 const struct i2c_device_id *id)
59{
60 struct ad7879 *ts;
61
62 if (!i2c_check_functionality(client->adapter,
63 I2C_FUNC_SMBUS_WORD_DATA)) {
64 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
65 return -EIO;
66 }
67
68 ts = ad7879_probe(&client->dev, AD7879_DEVID, client->irq,
69 &ad7879_i2c_bus_ops);
70 if (IS_ERR(ts))
71 return PTR_ERR(ts);
72
73 i2c_set_clientdata(client, ts);
74
75 return 0;
76}
77
78static int ad7879_i2c_remove(struct i2c_client *client)
79{
80 struct ad7879 *ts = i2c_get_clientdata(client);
81
82 ad7879_remove(ts);
83
84 return 0;
85}
86
87static const struct i2c_device_id ad7879_id[] = {
88 { "ad7879", 0 },
89 { "ad7889", 0 },
90 { }
91};
92MODULE_DEVICE_TABLE(i2c, ad7879_id);
93
94static struct i2c_driver ad7879_i2c_driver = {
95 .driver = {
96 .name = "ad7879",
97 .owner = THIS_MODULE,
98 .pm = &ad7879_pm_ops,
99 },
100 .probe = ad7879_i2c_probe,
101 .remove = ad7879_i2c_remove,
102 .id_table = ad7879_id,
103};
104
105module_i2c_driver(ad7879_i2c_driver);
106
107MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
108MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver");
109MODULE_LICENSE("GPL");
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * AD7879-1/AD7889-1 touchscreen (I2C bus)
4 *
5 * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
6 */
7
8#include <linux/input.h> /* BUS_I2C */
9#include <linux/i2c.h>
10#include <linux/module.h>
11#include <linux/types.h>
12#include <linux/of.h>
13#include <linux/pm.h>
14#include <linux/regmap.h>
15
16#include "ad7879.h"
17
18#define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
19
20static const struct regmap_config ad7879_i2c_regmap_config = {
21 .reg_bits = 8,
22 .val_bits = 16,
23 .max_register = 15,
24};
25
26static int ad7879_i2c_probe(struct i2c_client *client,
27 const struct i2c_device_id *id)
28{
29 struct regmap *regmap;
30
31 if (!i2c_check_functionality(client->adapter,
32 I2C_FUNC_SMBUS_WORD_DATA)) {
33 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
34 return -EIO;
35 }
36
37 regmap = devm_regmap_init_i2c(client, &ad7879_i2c_regmap_config);
38 if (IS_ERR(regmap))
39 return PTR_ERR(regmap);
40
41 return ad7879_probe(&client->dev, regmap, client->irq,
42 BUS_I2C, AD7879_DEVID);
43}
44
45static const struct i2c_device_id ad7879_id[] = {
46 { "ad7879", 0 },
47 { "ad7889", 0 },
48 { }
49};
50MODULE_DEVICE_TABLE(i2c, ad7879_id);
51
52#ifdef CONFIG_OF
53static const struct of_device_id ad7879_i2c_dt_ids[] = {
54 { .compatible = "adi,ad7879-1", },
55 { }
56};
57MODULE_DEVICE_TABLE(of, ad7879_i2c_dt_ids);
58#endif
59
60static struct i2c_driver ad7879_i2c_driver = {
61 .driver = {
62 .name = "ad7879",
63 .pm = &ad7879_pm_ops,
64 .of_match_table = of_match_ptr(ad7879_i2c_dt_ids),
65 },
66 .probe = ad7879_i2c_probe,
67 .id_table = ad7879_id,
68};
69
70module_i2c_driver(ad7879_i2c_driver);
71
72MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
73MODULE_DESCRIPTION("AD7879(-1) touchscreen I2C bus driver");
74MODULE_LICENSE("GPL");