summaryrefslogtreecommitdiff
path: root/drivers/input/misc/ad714x-i2c.c
diff options
context:
space:
mode:
authorMichael Hennerich <michael.hennerich@analog.com>2011-08-21 21:04:12 -0700
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2011-08-22 09:59:12 -0700
commit6337de2204be3b7b40825a1d30de30e514e8947b (patch)
treee76e4b6ba4460ed5e20d8ebdcfa91273f7c5cb5f /drivers/input/misc/ad714x-i2c.c
parent5b9063b19caaffe7135e1f9b8b22174ded0f586b (diff)
Input: ad714x - fix endianness issues
Allow driver to be used on Big Endian boxes. Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/misc/ad714x-i2c.c')
-rw-r--r--drivers/input/misc/ad714x-i2c.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/drivers/input/misc/ad714x-i2c.c b/drivers/input/misc/ad714x-i2c.c
index e21deb1baa8a..00a6a223212a 100644
--- a/drivers/input/misc/ad714x-i2c.c
+++ b/drivers/input/misc/ad714x-i2c.c
@@ -32,17 +32,12 @@ static int ad714x_i2c_write(struct device *dev, unsigned short reg,
{
struct i2c_client *client = to_i2c_client(dev);
int ret = 0;
- u8 *_reg = (u8 *)&reg;
- u8 *_data = (u8 *)&data;
-
- u8 tx[4] = {
- _reg[1],
- _reg[0],
- _data[1],
- _data[0]
+ unsigned short tx[2] = {
+ cpu_to_be16(reg),
+ cpu_to_be16(data)
};
- ret = i2c_master_send(client, tx, 4);
+ ret = i2c_master_send(client, (u8 *)tx, 4);
if (ret < 0)
dev_err(&client->dev, "I2C write error\n");
@@ -54,25 +49,16 @@ static int ad714x_i2c_read(struct device *dev, unsigned short reg,
{
struct i2c_client *client = to_i2c_client(dev);
int ret = 0;
- u8 *_reg = (u8 *)&reg;
- u8 *_data = (u8 *)data;
+ unsigned short tx = cpu_to_be16(reg);
- u8 tx[2] = {
- _reg[1],
- _reg[0]
- };
- u8 rx[2];
-
- ret = i2c_master_send(client, tx, 2);
+ ret = i2c_master_send(client, (u8 *)&tx, 2);
if (ret >= 0)
- ret = i2c_master_recv(client, rx, 2);
+ ret = i2c_master_recv(client, (u8 *)data, 2);
- if (unlikely(ret < 0)) {
+ if (unlikely(ret < 0))
dev_err(&client->dev, "I2C read error\n");
- } else {
- _data[0] = rx[1];
- _data[1] = rx[0];
- }
+ else
+ *data = be16_to_cpu(*data);
return ret;
}