ad7879-i2c.c (27fd38c5226ed0f1712d071880fa8e739eb78650) ad7879-i2c.c (404a24c35db8c44dce91010023f12b73f2f44441)
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>
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>
15
16#include "ad7879.h"
17
18#define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
19
16
17#include "ad7879.h"
18
19#define AD7879_DEVID 0x79 /* AD7879-1/AD7889-1 */
20
20/* 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
27 return i2c_smbus_read_word_swapped(client, reg);
28}
29
30static int ad7879_i2c_multi_read(struct device *dev,
31 u8 first_reg, u8 count, u16 *buf)
32{
33 struct i2c_client *client = to_i2c_client(dev);
34 u8 idx;
35
36 i2c_smbus_read_i2c_block_data(client, first_reg, count * 2, (u8 *)buf);
37
38 for (idx = 0; idx < count; ++idx)
39 buf[idx] = swab16(buf[idx]);
40
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
48 return i2c_smbus_write_word_swapped(client, reg, val);
49}
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,
21static const struct regmap_config ad7879_i2c_regmap_config = {
22 .reg_bits = 8,
23 .val_bits = 16,
24 .max_register = 15,
56};
57
58static int ad7879_i2c_probe(struct i2c_client *client,
59 const struct i2c_device_id *id)
60{
61 struct ad7879 *ts;
25};
26
27static int ad7879_i2c_probe(struct i2c_client *client,
28 const struct i2c_device_id *id)
29{
30 struct ad7879 *ts;
31 struct regmap *regmap;
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
32
33 if (!i2c_check_functionality(client->adapter,
34 I2C_FUNC_SMBUS_WORD_DATA)) {
35 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
36 return -EIO;
37 }
38
69 ts = ad7879_probe(&client->dev, AD7879_DEVID, client->irq,
70 &ad7879_i2c_bus_ops);
39 regmap = devm_regmap_init_i2c(client, &ad7879_i2c_regmap_config);
40 if (IS_ERR(regmap))
41 return PTR_ERR(regmap);
42
43 ts = ad7879_probe(&client->dev, regmap, client->irq,
44 BUS_I2C, AD7879_DEVID);
71 if (IS_ERR(ts))
72 return PTR_ERR(ts);
73
74 i2c_set_clientdata(client, ts);
75
76 return 0;
77}
78

--- 40 unchanged lines hidden ---
45 if (IS_ERR(ts))
46 return PTR_ERR(ts);
47
48 i2c_set_clientdata(client, ts);
49
50 return 0;
51}
52

--- 40 unchanged lines hidden ---