Commit 31f6a29a authored by Michael Hennerich's avatar Michael Hennerich Committed by Greg Kroah-Hartman

IIO: GYRO: ADXRS450: Don't issue two messages, use two transfers

Don't issue the same message twice, use two transfers and group them together
Signed-off-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Acked-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent bd5a793f
...@@ -40,29 +40,28 @@ static int adxrs450_spi_read_reg_16(struct device *dev, ...@@ -40,29 +40,28 @@ static int adxrs450_spi_read_reg_16(struct device *dev,
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adxrs450_state *st = iio_dev_get_devdata(indio_dev); struct adxrs450_state *st = iio_dev_get_devdata(indio_dev);
int ret; int ret;
struct spi_transfer xfers = { struct spi_transfer xfers[] = {
.tx_buf = st->tx, {
.rx_buf = st->rx, .tx_buf = st->tx,
.bits_per_word = 8, .bits_per_word = 8,
.len = 4, .len = 4,
.cs_change = 1,
}, {
.rx_buf = st->rx,
.bits_per_word = 8,
.len = 4,
},
}; };
/* Needs to send the command twice to get the wanted value */
mutex_lock(&st->buf_lock); mutex_lock(&st->buf_lock);
st->tx[0] = ADXRS450_READ_DATA | reg_address >> 7; st->tx[0] = ADXRS450_READ_DATA | (reg_address >> 7);
st->tx[1] = reg_address << 1; st->tx[1] = reg_address << 1;
st->tx[2] = 0; st->tx[2] = 0;
st->tx[3] = 0; st->tx[3] = 0;
spi_message_init(&msg);
spi_message_add_tail(&xfers, &msg);
ret = spi_sync(st->us, &msg);
if (ret) {
dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n",
reg_address);
goto error_ret;
}
spi_message_init(&msg); spi_message_init(&msg);
spi_message_add_tail(&xfers, &msg); spi_message_add_tail(&xfers[0], &msg);
spi_message_add_tail(&xfers[1], &msg);
ret = spi_sync(st->us, &msg); ret = spi_sync(st->us, &msg);
if (ret) { if (ret) {
dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n", dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n",
...@@ -125,11 +124,17 @@ static int adxrs450_spi_sensor_data(struct device *dev, u16 *val) ...@@ -125,11 +124,17 @@ static int adxrs450_spi_sensor_data(struct device *dev, u16 *val)
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adxrs450_state *st = iio_dev_get_devdata(indio_dev); struct adxrs450_state *st = iio_dev_get_devdata(indio_dev);
int ret; int ret;
struct spi_transfer xfers = { struct spi_transfer xfers[] = {
.tx_buf = st->tx, {
.rx_buf = st->rx, .tx_buf = st->tx,
.bits_per_word = 8, .bits_per_word = 8,
.len = 4, .len = 4,
.cs_change = 1,
}, {
.rx_buf = st->rx,
.bits_per_word = 8,
.len = 4,
},
}; };
mutex_lock(&st->buf_lock); mutex_lock(&st->buf_lock);
...@@ -139,15 +144,8 @@ static int adxrs450_spi_sensor_data(struct device *dev, u16 *val) ...@@ -139,15 +144,8 @@ static int adxrs450_spi_sensor_data(struct device *dev, u16 *val)
st->tx[3] = 0; st->tx[3] = 0;
spi_message_init(&msg); spi_message_init(&msg);
spi_message_add_tail(&xfers, &msg); spi_message_add_tail(&xfers[0], &msg);
ret = spi_sync(st->us, &msg); spi_message_add_tail(&xfers[1], &msg);
if (ret) {
dev_err(&st->us->dev, "Problem while reading sensor data\n");
goto error_ret;
}
spi_message_init(&msg);
spi_message_add_tail(&xfers, &msg);
ret = spi_sync(st->us, &msg); ret = spi_sync(st->us, &msg);
if (ret) { if (ret) {
dev_err(&st->us->dev, "Problem while reading sensor data\n"); dev_err(&st->us->dev, "Problem while reading sensor data\n");
......
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