diff options
author | Michael Hennerich <michael.hennerich@analog.com> | 2011-08-22 00:04:12 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2011-08-22 12:59:12 -0400 |
commit | 6337de2204be3b7b40825a1d30de30e514e8947b (patch) | |
tree | e76e4b6ba4460ed5e20d8ebdcfa91273f7c5cb5f /drivers/input | |
parent | 5b9063b19caaffe7135e1f9b8b22174ded0f586b (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')
-rw-r--r-- | drivers/input/misc/ad714x-i2c.c | 34 | ||||
-rw-r--r-- | drivers/input/misc/ad714x-spi.c | 24 |
2 files changed, 25 insertions, 33 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, | |||
32 | { | 32 | { |
33 | struct i2c_client *client = to_i2c_client(dev); | 33 | struct i2c_client *client = to_i2c_client(dev); |
34 | int ret = 0; | 34 | int ret = 0; |
35 | u8 *_reg = (u8 *)® | 35 | unsigned short tx[2] = { |
36 | u8 *_data = (u8 *)&data; | 36 | cpu_to_be16(reg), |
37 | 37 | cpu_to_be16(data) | |
38 | u8 tx[4] = { | ||
39 | _reg[1], | ||
40 | _reg[0], | ||
41 | _data[1], | ||
42 | _data[0] | ||
43 | }; | 38 | }; |
44 | 39 | ||
45 | ret = i2c_master_send(client, tx, 4); | 40 | ret = i2c_master_send(client, (u8 *)tx, 4); |
46 | if (ret < 0) | 41 | if (ret < 0) |
47 | dev_err(&client->dev, "I2C write error\n"); | 42 | dev_err(&client->dev, "I2C write error\n"); |
48 | 43 | ||
@@ -54,25 +49,16 @@ static int ad714x_i2c_read(struct device *dev, unsigned short reg, | |||
54 | { | 49 | { |
55 | struct i2c_client *client = to_i2c_client(dev); | 50 | struct i2c_client *client = to_i2c_client(dev); |
56 | int ret = 0; | 51 | int ret = 0; |
57 | u8 *_reg = (u8 *)® | 52 | unsigned short tx = cpu_to_be16(reg); |
58 | u8 *_data = (u8 *)data; | ||
59 | 53 | ||
60 | u8 tx[2] = { | 54 | ret = i2c_master_send(client, (u8 *)&tx, 2); |
61 | _reg[1], | ||
62 | _reg[0] | ||
63 | }; | ||
64 | u8 rx[2]; | ||
65 | |||
66 | ret = i2c_master_send(client, tx, 2); | ||
67 | if (ret >= 0) | 55 | if (ret >= 0) |
68 | ret = i2c_master_recv(client, rx, 2); | 56 | ret = i2c_master_recv(client, (u8 *)data, 2); |
69 | 57 | ||
70 | if (unlikely(ret < 0)) { | 58 | if (unlikely(ret < 0)) |
71 | dev_err(&client->dev, "I2C read error\n"); | 59 | dev_err(&client->dev, "I2C read error\n"); |
72 | } else { | 60 | else |
73 | _data[0] = rx[1]; | 61 | *data = be16_to_cpu(*data); |
74 | _data[1] = rx[0]; | ||
75 | } | ||
76 | 62 | ||
77 | return ret; | 63 | return ret; |
78 | } | 64 | } |
diff --git a/drivers/input/misc/ad714x-spi.c b/drivers/input/misc/ad714x-spi.c index da83ac9bed7e..0c7f9488f5cb 100644 --- a/drivers/input/misc/ad714x-spi.c +++ b/drivers/input/misc/ad714x-spi.c | |||
@@ -6,7 +6,7 @@ | |||
6 | * Licensed under the GPL-2 or later. | 6 | * Licensed under the GPL-2 or later. |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/input.h> /* BUS_I2C */ | 9 | #include <linux/input.h> /* BUS_SPI */ |
10 | #include <linux/module.h> | 10 | #include <linux/module.h> |
11 | #include <linux/spi/spi.h> | 11 | #include <linux/spi/spi.h> |
12 | #include <linux/pm.h> | 12 | #include <linux/pm.h> |
@@ -30,22 +30,28 @@ static int ad714x_spi_resume(struct device *dev) | |||
30 | 30 | ||
31 | static SIMPLE_DEV_PM_OPS(ad714x_spi_pm, ad714x_spi_suspend, ad714x_spi_resume); | 31 | static SIMPLE_DEV_PM_OPS(ad714x_spi_pm, ad714x_spi_suspend, ad714x_spi_resume); |
32 | 32 | ||
33 | static int ad714x_spi_read(struct device *dev, unsigned short reg, | 33 | static int ad714x_spi_read(struct device *dev, |
34 | unsigned short *data) | 34 | unsigned short reg, unsigned short *data) |
35 | { | 35 | { |
36 | struct spi_device *spi = to_spi_device(dev); | 36 | struct spi_device *spi = to_spi_device(dev); |
37 | unsigned short tx = AD714x_SPI_CMD_PREFIX | AD714x_SPI_READ | reg; | 37 | unsigned short tx = cpu_to_be16(AD714x_SPI_CMD_PREFIX | |
38 | AD714x_SPI_READ | reg); | ||
39 | int ret; | ||
38 | 40 | ||
39 | return spi_write_then_read(spi, (u8 *)&tx, 2, (u8 *)data, 2); | 41 | ret = spi_write_then_read(spi, &tx, 2, data, 2); |
42 | |||
43 | *data = be16_to_cpup(data); | ||
44 | |||
45 | return ret; | ||
40 | } | 46 | } |
41 | 47 | ||
42 | static int ad714x_spi_write(struct device *dev, unsigned short reg, | 48 | static int ad714x_spi_write(struct device *dev, |
43 | unsigned short data) | 49 | unsigned short reg, unsigned short data) |
44 | { | 50 | { |
45 | struct spi_device *spi = to_spi_device(dev); | 51 | struct spi_device *spi = to_spi_device(dev); |
46 | unsigned short tx[2] = { | 52 | unsigned short tx[2] = { |
47 | AD714x_SPI_CMD_PREFIX | reg, | 53 | cpu_to_be16(AD714x_SPI_CMD_PREFIX | reg), |
48 | data | 54 | cpu_to_be16(data) |
49 | }; | 55 | }; |
50 | 56 | ||
51 | return spi_write(spi, (u8 *)tx, 4); | 57 | return spi_write(spi, (u8 *)tx, 4); |