Commit 0dbe59c7 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Jonathan Cameron

iio:ad5504: Do not store transfer buffers on the stack

Some SPI controllers may not be able to handle transfer buffers that are placed
on the stack.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 61c358e3
...@@ -47,14 +47,16 @@ ...@@ -47,14 +47,16 @@
* @vref_mv: actual reference voltage used * @vref_mv: actual reference voltage used
* @pwr_down_mask power down mask * @pwr_down_mask power down mask
* @pwr_down_mode current power down mode * @pwr_down_mode current power down mode
* @data: transfer buffer
*/ */
struct ad5504_state { struct ad5504_state {
struct spi_device *spi; struct spi_device *spi;
struct regulator *reg; struct regulator *reg;
unsigned short vref_mv; unsigned short vref_mv;
unsigned pwr_down_mask; unsigned pwr_down_mask;
unsigned pwr_down_mode; unsigned pwr_down_mode;
__be16 data[2] ____cacheline_aligned;
}; };
/** /**
...@@ -66,31 +68,29 @@ enum ad5504_supported_device_ids { ...@@ -66,31 +68,29 @@ enum ad5504_supported_device_ids {
ID_AD5501, ID_AD5501,
}; };
static int ad5504_spi_write(struct spi_device *spi, u8 addr, u16 val) static int ad5504_spi_write(struct ad5504_state *st, u8 addr, u16 val)
{ {
__be16 tmp = cpu_to_be16(AD5504_CMD_WRITE | st->data[0] = cpu_to_be16(AD5504_CMD_WRITE | AD5504_ADDR(addr) |
AD5504_ADDR(addr) |
(val & AD5504_RES_MASK)); (val & AD5504_RES_MASK));
return spi_write(spi, (u8 *)&tmp, 2); return spi_write(st->spi, &st->data[0], 2);
} }
static int ad5504_spi_read(struct spi_device *spi, u8 addr) static int ad5504_spi_read(struct ad5504_state *st, u8 addr)
{ {
__be16 tmp = cpu_to_be16(AD5504_CMD_READ | AD5504_ADDR(addr));
__be16 val;
int ret; int ret;
struct spi_transfer t = { struct spi_transfer t = {
.tx_buf = &tmp, .tx_buf = &st->data[0],
.rx_buf = &val, .rx_buf = &st->data[1],
.len = 2, .len = 2,
}; };
ret = spi_sync_transfer(spi, &t, 1);
st->data[0] = cpu_to_be16(AD5504_CMD_READ | AD5504_ADDR(addr));
ret = spi_sync_transfer(st->spi, &t, 1);
if (ret < 0) if (ret < 0)
return ret; return ret;
return be16_to_cpu(val) & AD5504_RES_MASK; return be16_to_cpu(st->data[1]) & AD5504_RES_MASK;
} }
static int ad5504_read_raw(struct iio_dev *indio_dev, static int ad5504_read_raw(struct iio_dev *indio_dev,
...@@ -104,7 +104,7 @@ static int ad5504_read_raw(struct iio_dev *indio_dev, ...@@ -104,7 +104,7 @@ static int ad5504_read_raw(struct iio_dev *indio_dev,
switch (m) { switch (m) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
ret = ad5504_spi_read(st->spi, chan->address); ret = ad5504_spi_read(st, chan->address);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -133,7 +133,7 @@ static int ad5504_write_raw(struct iio_dev *indio_dev, ...@@ -133,7 +133,7 @@ static int ad5504_write_raw(struct iio_dev *indio_dev,
if (val >= (1 << chan->scan_type.realbits) || val < 0) if (val >= (1 << chan->scan_type.realbits) || val < 0)
return -EINVAL; return -EINVAL;
return ad5504_spi_write(st->spi, chan->address, val); return ad5504_spi_write(st, chan->address, val);
default: default:
ret = -EINVAL; ret = -EINVAL;
} }
...@@ -197,12 +197,12 @@ static ssize_t ad5504_write_dac_powerdown(struct iio_dev *indio_dev, ...@@ -197,12 +197,12 @@ static ssize_t ad5504_write_dac_powerdown(struct iio_dev *indio_dev,
else else
st->pwr_down_mask &= ~(1 << chan->channel); st->pwr_down_mask &= ~(1 << chan->channel);
ret = ad5504_spi_write(st->spi, AD5504_ADDR_CTRL, ret = ad5504_spi_write(st, AD5504_ADDR_CTRL,
AD5504_DAC_PWRDWN_MODE(st->pwr_down_mode) | AD5504_DAC_PWRDWN_MODE(st->pwr_down_mode) |
AD5504_DAC_PWR(st->pwr_down_mask)); AD5504_DAC_PWR(st->pwr_down_mask));
/* writes to the CTRL register must be followed by a NOOP */ /* writes to the CTRL register must be followed by a NOOP */
ad5504_spi_write(st->spi, AD5504_ADDR_NOOP, 0); ad5504_spi_write(st, AD5504_ADDR_NOOP, 0);
return ret ? ret : len; return ret ? ret : len;
} }
......
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