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)
static SIMPLE_DEV_PM_OPS(ad714x_i2c_pm, ad714x_i2c_suspend, ad714x_i2c_resume);
-static int ad714x_i2c_write(struct device *dev, unsigned short reg,
- unsigned short data)
+static int ad714x_i2c_write(struct ad714x_chip *chip,
+ unsigned short reg, unsigned short data)
{
- struct i2c_client *client = to_i2c_client(dev);
- int ret = 0;
- unsigned short tx[2] = {
- cpu_to_be16(reg),
- cpu_to_be16(data)
- };
-
- ret = i2c_master_send(client, (u8 *)tx, 4);
- if (ret < 0)
- dev_err(&client->dev, "I2C write error\n");
-
- return ret;
+ struct i2c_client *client = to_i2c_client(chip->dev);
+ int error;
+
+ chip->xfer_buf[0] = cpu_to_be16(reg);
+ chip->xfer_buf[1] = cpu_to_be16(data);
+
+ error = i2c_master_send(client, (u8 *)chip->xfer_buf,
+ 2 * sizeof(*chip->xfer_buf));
+ if (unlikely(error < 0)) {
+ dev_err(&client->dev, "I2C write error: %d\n", error);
+ return error;
+ }
+
+ return 0;
}
-static int ad714x_i2c_read(struct device *dev, unsigned short reg,
- unsigned short *data)
+static int ad714x_i2c_read(struct ad714x_chip *chip,
+ unsigned short reg, unsigned short *data)
{
- struct i2c_client *client = to_i2c_client(dev);
- int ret = 0;
- unsigned short tx = cpu_to_be16(reg);
+ struct i2c_client *client = to_i2c_client(chip->dev);
+ int error;
+
+ chip->xfer_buf[0] = cpu_to_be16(reg);
- ret = i2c_master_send(client, (u8 *)&tx, 2);
- if (ret >= 0)
- ret = i2c_master_recv(client, (u8 *)data, 2);
+ error = i2c_master_send(client, (u8 *)chip->xfer_buf,
+ sizeof(*chip->xfer_buf));
+ if (error >= 0)
+ error = i2c_master_recv(client, (u8 *)chip->xfer_buf,
+ sizeof(*chip->xfer_buf));
- if (unlikely(ret < 0))
- dev_err(&client->dev, "I2C read error\n");
- else
- *data = be16_to_cpu(*data);
+ if (unlikely(error < 0)) {
+ dev_err(&client->dev, "I2C read error: %d\n", error);
+ return error;
+ }
- return ret;
+ *data = be16_to_cpup(chip->xfer_buf);
+ return 0;
}
static int __devinit ad714x_i2c_probe(struct i2c_client *client,