Commit 6337de22 authored by Michael Hennerich's avatar Michael Hennerich Committed by Dmitry Torokhov

Input: ad714x - fix endianness issues

Allow driver to be used on Big Endian boxes.
Signed-off-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent 5b9063b1
...@@ -32,17 +32,12 @@ static int ad714x_i2c_write(struct device *dev, unsigned short reg, ...@@ -32,17 +32,12 @@ static int ad714x_i2c_write(struct device *dev, unsigned short reg,
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
int ret = 0; int ret = 0;
u8 *_reg = (u8 *)&reg; unsigned short tx[2] = {
u8 *_data = (u8 *)&data; cpu_to_be16(reg),
cpu_to_be16(data)
u8 tx[4] = {
_reg[1],
_reg[0],
_data[1],
_data[0]
}; };
ret = i2c_master_send(client, tx, 4); ret = i2c_master_send(client, (u8 *)tx, 4);
if (ret < 0) if (ret < 0)
dev_err(&client->dev, "I2C write error\n"); dev_err(&client->dev, "I2C write error\n");
...@@ -54,25 +49,16 @@ static int ad714x_i2c_read(struct device *dev, unsigned short reg, ...@@ -54,25 +49,16 @@ static int ad714x_i2c_read(struct device *dev, unsigned short reg,
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
int ret = 0; int ret = 0;
u8 *_reg = (u8 *)&reg; unsigned short tx = cpu_to_be16(reg);
u8 *_data = (u8 *)data;
u8 tx[2] = { ret = i2c_master_send(client, (u8 *)&tx, 2);
_reg[1],
_reg[0]
};
u8 rx[2];
ret = i2c_master_send(client, tx, 2);
if (ret >= 0) 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"); dev_err(&client->dev, "I2C read error\n");
} else { else
_data[0] = rx[1]; *data = be16_to_cpu(*data);
_data[1] = rx[0];
}
return ret; return ret;
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Licensed under the GPL-2 or later. * Licensed under the GPL-2 or later.
*/ */
#include <linux/input.h> /* BUS_I2C */ #include <linux/input.h> /* BUS_SPI */
#include <linux/module.h> #include <linux/module.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/pm.h> #include <linux/pm.h>
...@@ -30,22 +30,28 @@ static int ad714x_spi_resume(struct device *dev) ...@@ -30,22 +30,28 @@ static int ad714x_spi_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(ad714x_spi_pm, ad714x_spi_suspend, ad714x_spi_resume); static SIMPLE_DEV_PM_OPS(ad714x_spi_pm, ad714x_spi_suspend, ad714x_spi_resume);
static int ad714x_spi_read(struct device *dev, unsigned short reg, static int ad714x_spi_read(struct device *dev,
unsigned short *data) unsigned short reg, unsigned short *data)
{ {
struct spi_device *spi = to_spi_device(dev); struct spi_device *spi = to_spi_device(dev);
unsigned short tx = AD714x_SPI_CMD_PREFIX | AD714x_SPI_READ | reg; unsigned short tx = cpu_to_be16(AD714x_SPI_CMD_PREFIX |
AD714x_SPI_READ | reg);
int ret;
return spi_write_then_read(spi, (u8 *)&tx, 2, (u8 *)data, 2); ret = spi_write_then_read(spi, &tx, 2, data, 2);
*data = be16_to_cpup(data);
return ret;
} }
static int ad714x_spi_write(struct device *dev, unsigned short reg, static int ad714x_spi_write(struct device *dev,
unsigned short data) unsigned short reg, unsigned short data)
{ {
struct spi_device *spi = to_spi_device(dev); struct spi_device *spi = to_spi_device(dev);
unsigned short tx[2] = { unsigned short tx[2] = {
AD714x_SPI_CMD_PREFIX | reg, cpu_to_be16(AD714x_SPI_CMD_PREFIX | reg),
data cpu_to_be16(data)
}; };
return spi_write(spi, (u8 *)tx, 4); return spi_write(spi, (u8 *)tx, 4);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment