aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/misc/ad714x-i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/misc/ad714x-i2c.c')
-rw-r--r--drivers/input/misc/ad714x-i2c.c60
1 files changed, 33 insertions, 27 deletions
diff --git a/drivers/input/misc/ad714x-i2c.c b/drivers/input/misc/ad714x-i2c.c
index 00a6a223212a..6c6121865f0e 100644
--- a/drivers/input/misc/ad714x-i2c.c
+++ b/drivers/input/misc/ad714x-i2c.c
@@ -27,40 +27,46 @@ static int ad714x_i2c_resume(struct device *dev)
27 27
28static SIMPLE_DEV_PM_OPS(ad714x_i2c_pm, ad714x_i2c_suspend, ad714x_i2c_resume); 28static SIMPLE_DEV_PM_OPS(ad714x_i2c_pm, ad714x_i2c_suspend, ad714x_i2c_resume);
29 29
30static int ad714x_i2c_write(struct device *dev, unsigned short reg, 30static int ad714x_i2c_write(struct ad714x_chip *chip,
31 unsigned short data) 31 unsigned short reg, unsigned short data)
32{ 32{
33 struct i2c_client *client = to_i2c_client(dev); 33 struct i2c_client *client = to_i2c_client(chip->dev);
34 int ret = 0; 34 int error;
35 unsigned short tx[2] = { 35
36 cpu_to_be16(reg), 36 chip->xfer_buf[0] = cpu_to_be16(reg);
37 cpu_to_be16(data) 37 chip->xfer_buf[1] = cpu_to_be16(data);
38 }; 38
39 39 error = i2c_master_send(client, (u8 *)chip->xfer_buf,
40 ret = i2c_master_send(client, (u8 *)tx, 4); 40 2 * sizeof(*chip->xfer_buf));
41 if (ret < 0) 41 if (unlikely(error < 0)) {
42 dev_err(&client->dev, "I2C write error\n"); 42 dev_err(&client->dev, "I2C write error: %d\n", error);
43 43 return error;
44 return ret; 44 }
45
46 return 0;
45} 47}
46 48
47static int ad714x_i2c_read(struct device *dev, unsigned short reg, 49static int ad714x_i2c_read(struct ad714x_chip *chip,
48 unsigned short *data) 50 unsigned short reg, unsigned short *data)
49{ 51{
50 struct i2c_client *client = to_i2c_client(dev); 52 struct i2c_client *client = to_i2c_client(chip->dev);
51 int ret = 0; 53 int error;
52 unsigned short tx = cpu_to_be16(reg); 54
55 chip->xfer_buf[0] = cpu_to_be16(reg);
53 56
54 ret = i2c_master_send(client, (u8 *)&tx, 2); 57 error = i2c_master_send(client, (u8 *)chip->xfer_buf,
55 if (ret >= 0) 58 sizeof(*chip->xfer_buf));
56 ret = i2c_master_recv(client, (u8 *)data, 2); 59 if (error >= 0)
60 error = i2c_master_recv(client, (u8 *)chip->xfer_buf,
61 sizeof(*chip->xfer_buf));
57 62
58 if (unlikely(ret < 0)) 63 if (unlikely(error < 0)) {
59 dev_err(&client->dev, "I2C read error\n"); 64 dev_err(&client->dev, "I2C read error: %d\n", error);
60 else 65 return error;
61 *data = be16_to_cpu(*data); 66 }
62 67
63 return ret; 68 *data = be16_to_cpup(chip->xfer_buf);
69 return 0;
64} 70}
65 71
66static int __devinit ad714x_i2c_probe(struct i2c_client *client, 72static int __devinit ad714x_i2c_probe(struct i2c_client *client,