Commit 14543a00 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Jonathan Cameron

iio: Use spi_sync_transfer()

Use the new spi_sync_transfer() helper function instead of open-coding it.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 6d9eecd4
...@@ -94,7 +94,6 @@ static int kxsd9_write_scale(struct iio_dev *indio_dev, int micro) ...@@ -94,7 +94,6 @@ static int kxsd9_write_scale(struct iio_dev *indio_dev, int micro)
static int kxsd9_read(struct iio_dev *indio_dev, u8 address) static int kxsd9_read(struct iio_dev *indio_dev, u8 address)
{ {
struct spi_message msg;
int ret; int ret;
struct kxsd9_state *st = iio_priv(indio_dev); struct kxsd9_state *st = iio_priv(indio_dev);
struct spi_transfer xfers[] = { struct spi_transfer xfers[] = {
...@@ -112,10 +111,7 @@ static int kxsd9_read(struct iio_dev *indio_dev, u8 address) ...@@ -112,10 +111,7 @@ static int kxsd9_read(struct iio_dev *indio_dev, u8 address)
mutex_lock(&st->buf_lock); mutex_lock(&st->buf_lock);
st->tx[0] = KXSD9_READ(address); st->tx[0] = KXSD9_READ(address);
spi_message_init(&msg); ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
spi_message_add_tail(&xfers[0], &msg);
spi_message_add_tail(&xfers[1], &msg);
ret = spi_sync(st->us, &msg);
if (ret) if (ret)
return ret; return ret;
return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0); return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);
......
...@@ -213,7 +213,6 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type, ...@@ -213,7 +213,6 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
unsigned int addr) unsigned int addr)
{ {
struct ad5360_state *st = iio_priv(indio_dev); struct ad5360_state *st = iio_priv(indio_dev);
struct spi_message m;
int ret; int ret;
struct spi_transfer t[] = { struct spi_transfer t[] = {
{ {
...@@ -226,10 +225,6 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type, ...@@ -226,10 +225,6 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
}, },
}; };
spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);
mutex_lock(&indio_dev->mlock); mutex_lock(&indio_dev->mlock);
st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) | st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) |
...@@ -237,7 +232,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type, ...@@ -237,7 +232,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
AD5360_READBACK_TYPE(type) | AD5360_READBACK_TYPE(type) |
AD5360_READBACK_ADDR(addr)); AD5360_READBACK_ADDR(addr));
ret = spi_sync(st->spi, &m); ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
if (ret >= 0) if (ret >= 0)
ret = be32_to_cpu(st->data[1].d32) & 0xffff; ret = be32_to_cpu(st->data[1].d32) & 0xffff;
......
...@@ -127,7 +127,6 @@ static int ad5421_write(struct iio_dev *indio_dev, unsigned int reg, ...@@ -127,7 +127,6 @@ static int ad5421_write(struct iio_dev *indio_dev, unsigned int reg,
static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg) static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg)
{ {
struct ad5421_state *st = iio_priv(indio_dev); struct ad5421_state *st = iio_priv(indio_dev);
struct spi_message m;
int ret; int ret;
struct spi_transfer t[] = { struct spi_transfer t[] = {
{ {
...@@ -140,15 +139,11 @@ static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg) ...@@ -140,15 +139,11 @@ static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg)
}, },
}; };
spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);
mutex_lock(&indio_dev->mlock); mutex_lock(&indio_dev->mlock);
st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16)); st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));
ret = spi_sync(st->spi, &m); ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
if (ret >= 0) if (ret >= 0)
ret = be32_to_cpu(st->data[1].d32) & 0xffff; ret = be32_to_cpu(st->data[1].d32) & 0xffff;
......
...@@ -85,11 +85,7 @@ static int ad5504_spi_read(struct spi_device *spi, u8 addr) ...@@ -85,11 +85,7 @@ static int ad5504_spi_read(struct spi_device *spi, u8 addr)
.rx_buf = &val, .rx_buf = &val,
.len = 2, .len = 2,
}; };
struct spi_message m; ret = spi_sync_transfer(spi, &t, 1);
spi_message_init(&m);
spi_message_add_tail(&t, &m);
ret = spi_sync(spi, &m);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -117,18 +117,13 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 addr) ...@@ -117,18 +117,13 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 addr)
.len = 3, .len = 3,
}, },
}; };
struct spi_message m;
int ret; int ret;
spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);
st->data[0].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_READBACK_ENABLE) | st->data[0].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_READBACK_ENABLE) |
AD5686_ADDR(addr)); AD5686_ADDR(addr));
st->data[1].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_NOOP)); st->data[1].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_NOOP));
ret = spi_sync(st->spi, &m); ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -153,7 +153,6 @@ static int ad5755_write_ctrl(struct iio_dev *indio_dev, unsigned int channel, ...@@ -153,7 +153,6 @@ static int ad5755_write_ctrl(struct iio_dev *indio_dev, unsigned int channel,
static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr) static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr)
{ {
struct ad5755_state *st = iio_priv(indio_dev); struct ad5755_state *st = iio_priv(indio_dev);
struct spi_message m;
int ret; int ret;
struct spi_transfer t[] = { struct spi_transfer t[] = {
{ {
...@@ -167,16 +166,12 @@ static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr) ...@@ -167,16 +166,12 @@ static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr)
}, },
}; };
spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);
mutex_lock(&indio_dev->mlock); mutex_lock(&indio_dev->mlock);
st->data[0].d32 = cpu_to_be32(AD5755_READ_FLAG | (addr << 16)); st->data[0].d32 = cpu_to_be32(AD5755_READ_FLAG | (addr << 16));
st->data[1].d32 = cpu_to_be32(AD5755_NOOP); st->data[1].d32 = cpu_to_be32(AD5755_NOOP);
ret = spi_sync(st->spi, &m); ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
if (ret >= 0) if (ret >= 0)
ret = be32_to_cpu(st->data[1].d32) & 0xffff; ret = be32_to_cpu(st->data[1].d32) & 0xffff;
......
...@@ -135,7 +135,6 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg, ...@@ -135,7 +135,6 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg,
unsigned int *val) unsigned int *val)
{ {
struct ad5764_state *st = iio_priv(indio_dev); struct ad5764_state *st = iio_priv(indio_dev);
struct spi_message m;
int ret; int ret;
struct spi_transfer t[] = { struct spi_transfer t[] = {
{ {
...@@ -148,15 +147,11 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg, ...@@ -148,15 +147,11 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg,
}, },
}; };
spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);
mutex_lock(&indio_dev->mlock); mutex_lock(&indio_dev->mlock);
st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16)); st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));
ret = spi_sync(st->spi, &m); ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
if (ret >= 0) if (ret >= 0)
*val = be32_to_cpu(st->data[1].d32) & 0xffff; *val = be32_to_cpu(st->data[1].d32) & 0xffff;
......
...@@ -125,7 +125,6 @@ static int ad5791_spi_read(struct spi_device *spi, u8 addr, u32 *val) ...@@ -125,7 +125,6 @@ static int ad5791_spi_read(struct spi_device *spi, u8 addr, u32 *val)
u8 d8[4]; u8 d8[4];
} data[3]; } data[3];
int ret; int ret;
struct spi_message msg;
struct spi_transfer xfers[] = { struct spi_transfer xfers[] = {
{ {
.tx_buf = &data[0].d8[1], .tx_buf = &data[0].d8[1],
...@@ -144,10 +143,7 @@ static int ad5791_spi_read(struct spi_device *spi, u8 addr, u32 *val) ...@@ -144,10 +143,7 @@ static int ad5791_spi_read(struct spi_device *spi, u8 addr, u32 *val)
AD5791_ADDR(addr)); AD5791_ADDR(addr));
data[1].d32 = cpu_to_be32(AD5791_ADDR(AD5791_ADDR_NOOP)); data[1].d32 = cpu_to_be32(AD5791_ADDR(AD5791_ADDR_NOOP));
spi_message_init(&msg); ret = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers));
spi_message_add_tail(&xfers[0], &msg);
spi_message_add_tail(&xfers[1], &msg);
ret = spi_sync(spi, &msg);
*val = be32_to_cpu(data[2].d32); *val = be32_to_cpu(data[2].d32);
......
...@@ -287,7 +287,6 @@ struct ad9523_state { ...@@ -287,7 +287,6 @@ struct ad9523_state {
static int ad9523_read(struct iio_dev *indio_dev, unsigned addr) static int ad9523_read(struct iio_dev *indio_dev, unsigned addr)
{ {
struct ad9523_state *st = iio_priv(indio_dev); struct ad9523_state *st = iio_priv(indio_dev);
struct spi_message m;
int ret; int ret;
/* We encode the register size 1..3 bytes into the register address. /* We encode the register size 1..3 bytes into the register address.
...@@ -305,15 +304,11 @@ static int ad9523_read(struct iio_dev *indio_dev, unsigned addr) ...@@ -305,15 +304,11 @@ static int ad9523_read(struct iio_dev *indio_dev, unsigned addr)
}, },
}; };
spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);
st->data[0].d32 = cpu_to_be32(AD9523_READ | st->data[0].d32 = cpu_to_be32(AD9523_READ |
AD9523_CNT(AD9523_TRANSF_LEN(addr)) | AD9523_CNT(AD9523_TRANSF_LEN(addr)) |
AD9523_ADDR(addr)); AD9523_ADDR(addr));
ret = spi_sync(st->spi, &m); ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
if (ret < 0) if (ret < 0)
dev_err(&indio_dev->dev, "read failed (%d)", ret); dev_err(&indio_dev->dev, "read failed (%d)", ret);
else else
...@@ -326,7 +321,6 @@ static int ad9523_read(struct iio_dev *indio_dev, unsigned addr) ...@@ -326,7 +321,6 @@ static int ad9523_read(struct iio_dev *indio_dev, unsigned addr)
static int ad9523_write(struct iio_dev *indio_dev, unsigned addr, unsigned val) static int ad9523_write(struct iio_dev *indio_dev, unsigned addr, unsigned val)
{ {
struct ad9523_state *st = iio_priv(indio_dev); struct ad9523_state *st = iio_priv(indio_dev);
struct spi_message m;
int ret; int ret;
struct spi_transfer t[] = { struct spi_transfer t[] = {
{ {
...@@ -338,16 +332,12 @@ static int ad9523_write(struct iio_dev *indio_dev, unsigned addr, unsigned val) ...@@ -338,16 +332,12 @@ static int ad9523_write(struct iio_dev *indio_dev, unsigned addr, unsigned val)
}, },
}; };
spi_message_init(&m);
spi_message_add_tail(&t[0], &m);
spi_message_add_tail(&t[1], &m);
st->data[0].d32 = cpu_to_be32(AD9523_WRITE | st->data[0].d32 = cpu_to_be32(AD9523_WRITE |
AD9523_CNT(AD9523_TRANSF_LEN(addr)) | AD9523_CNT(AD9523_TRANSF_LEN(addr)) |
AD9523_ADDR(addr)); AD9523_ADDR(addr));
st->data[1].d32 = cpu_to_be32(val); st->data[1].d32 = cpu_to_be32(val);
ret = spi_sync(st->spi, &m); ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
if (ret < 0) if (ret < 0)
dev_err(&indio_dev->dev, "write failed (%d)", ret); dev_err(&indio_dev->dev, "write failed (%d)", ret);
......
...@@ -213,7 +213,6 @@ static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val) ...@@ -213,7 +213,6 @@ static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val)
static int adxrs450_spi_initial(struct adxrs450_state *st, static int adxrs450_spi_initial(struct adxrs450_state *st,
u32 *val, char chk) u32 *val, char chk)
{ {
struct spi_message msg;
int ret; int ret;
u32 tx; u32 tx;
struct spi_transfer xfers = { struct spi_transfer xfers = {
...@@ -228,9 +227,7 @@ static int adxrs450_spi_initial(struct adxrs450_state *st, ...@@ -228,9 +227,7 @@ static int adxrs450_spi_initial(struct adxrs450_state *st,
if (chk) if (chk)
tx |= (ADXRS450_CHK | ADXRS450_P); tx |= (ADXRS450_CHK | ADXRS450_P);
st->tx = cpu_to_be32(tx); st->tx = cpu_to_be32(tx);
spi_message_init(&msg); ret = spi_sync_transfer(st->us, &xfers, 1);
spi_message_add_tail(&xfers, &msg);
ret = spi_sync(st->us, &msg);
if (ret) { if (ret) {
dev_err(&st->us->dev, "Problem while reading initializing data\n"); dev_err(&st->us->dev, "Problem while reading initializing data\n");
goto error_ret; goto error_ret;
......
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