From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH 07/15] iio:ad5791: Do not store transfer buffers on the stack
Date: Sat, 30 Nov 2013 11:09:45 +0000 [thread overview]
Message-ID: <5299C779.3070601@kernel.org> (raw)
In-Reply-To: <1385383327-28181-7-git-send-email-lars@metafoo.de>
On 11/25/13 12:41, Lars-Peter Clausen wrote:
> Some SPI controllers may not be able to handle transfer buffers that are placed
> on the stack.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Applied to the togreg branch of iio.git
Thanks
> ---
> drivers/iio/dac/ad5791.c | 46 +++++++++++++++++++++-------------------------
> 1 file changed, 21 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/iio/dac/ad5791.c b/drivers/iio/dac/ad5791.c
> index 1e7f4cd..79bf199 100644
> --- a/drivers/iio/dac/ad5791.c
> +++ b/drivers/iio/dac/ad5791.c
> @@ -91,6 +91,11 @@ struct ad5791_state {
> unsigned ctrl;
> unsigned pwr_down_mode;
> bool pwr_down;
> +
> + union {
> + __be32 d32;
> + u8 d8[4];
> + } data[3] ____cacheline_aligned;
> };
>
> /**
> @@ -104,48 +109,39 @@ enum ad5791_supported_device_ids {
> ID_AD5791,
> };
>
> -static int ad5791_spi_write(struct spi_device *spi, u8 addr, u32 val)
> +static int ad5791_spi_write(struct ad5791_state *st, u8 addr, u32 val)
> {
> - union {
> - __be32 d32;
> - u8 d8[4];
> - } data;
> -
> - data.d32 = cpu_to_be32(AD5791_CMD_WRITE |
> + st->data[0].d32 = cpu_to_be32(AD5791_CMD_WRITE |
> AD5791_ADDR(addr) |
> (val & AD5791_DAC_MASK));
>
> - return spi_write(spi, &data.d8[1], 3);
> + return spi_write(st->spi, &st->data[0].d8[1], 3);
> }
>
> -static int ad5791_spi_read(struct spi_device *spi, u8 addr, u32 *val)
> +static int ad5791_spi_read(struct ad5791_state *st, u8 addr, u32 *val)
> {
> - union {
> - __be32 d32;
> - u8 d8[4];
> - } data[3];
> int ret;
> struct spi_transfer xfers[] = {
> {
> - .tx_buf = &data[0].d8[1],
> + .tx_buf = &st->data[0].d8[1],
> .bits_per_word = 8,
> .len = 3,
> .cs_change = 1,
> }, {
> - .tx_buf = &data[1].d8[1],
> - .rx_buf = &data[2].d8[1],
> + .tx_buf = &st->data[1].d8[1],
> + .rx_buf = &st->data[2].d8[1],
> .bits_per_word = 8,
> .len = 3,
> },
> };
>
> - data[0].d32 = cpu_to_be32(AD5791_CMD_READ |
> + st->data[0].d32 = cpu_to_be32(AD5791_CMD_READ |
> AD5791_ADDR(addr));
> - data[1].d32 = cpu_to_be32(AD5791_ADDR(AD5791_ADDR_NOOP));
> + st->data[1].d32 = cpu_to_be32(AD5791_ADDR(AD5791_ADDR_NOOP));
>
> - ret = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers));
> + ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
>
> - *val = be32_to_cpu(data[2].d32);
> + *val = be32_to_cpu(st->data[2].d32);
>
> return ret;
> }
> @@ -210,7 +206,7 @@ static ssize_t ad5791_write_dac_powerdown(struct iio_dev *indio_dev,
> }
> st->pwr_down = pwr_down;
>
> - ret = ad5791_spi_write(st->spi, AD5791_ADDR_CTRL, st->ctrl);
> + ret = ad5791_spi_write(st, AD5791_ADDR_CTRL, st->ctrl);
>
> return ret ? ret : len;
> }
> @@ -263,7 +259,7 @@ static int ad5791_read_raw(struct iio_dev *indio_dev,
>
> switch (m) {
> case IIO_CHAN_INFO_RAW:
> - ret = ad5791_spi_read(st->spi, chan->address, val);
> + ret = ad5791_spi_read(st, chan->address, val);
> if (ret)
> return ret;
> *val &= AD5791_DAC_MASK;
> @@ -330,7 +326,7 @@ static int ad5791_write_raw(struct iio_dev *indio_dev,
> val &= AD5791_RES_MASK(chan->scan_type.realbits);
> val <<= chan->scan_type.shift;
>
> - return ad5791_spi_write(st->spi, chan->address, val);
> + return ad5791_spi_write(st, chan->address, val);
>
> default:
> return -EINVAL;
> @@ -393,7 +389,7 @@ static int ad5791_probe(struct spi_device *spi)
> dev_warn(&spi->dev, "reference voltage unspecified\n");
> }
>
> - ret = ad5791_spi_write(spi, AD5791_ADDR_SW_CTRL, AD5791_SWCTRL_RESET);
> + ret = ad5791_spi_write(st, AD5791_ADDR_SW_CTRL, AD5791_SWCTRL_RESET);
> if (ret)
> goto error_disable_reg_neg;
>
> @@ -405,7 +401,7 @@ static int ad5791_probe(struct spi_device *spi)
> | ((pdata && pdata->use_rbuf_gain2) ? 0 : AD5791_CTRL_RBUF) |
> AD5791_CTRL_BIN2SC;
>
> - ret = ad5791_spi_write(spi, AD5791_ADDR_CTRL, st->ctrl |
> + ret = ad5791_spi_write(st, AD5791_ADDR_CTRL, st->ctrl |
> AD5791_CTRL_OPGND | AD5791_CTRL_DACTRI);
> if (ret)
> goto error_disable_reg_neg;
>
next prev parent reply other threads:[~2013-11-30 11:09 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-25 12:41 [PATCH 01/15] iio:ad5504: Mark transfer buffers as __be16 Lars-Peter Clausen
2013-11-25 12:41 ` [PATCH 02/15] iio:ad5504: Do not store transfer buffers on the stack Lars-Peter Clausen
2013-11-30 11:07 ` Jonathan Cameron
2013-11-25 12:41 ` [PATCH 03/15] iio:ad5421: Mark transfer buffer as __be32 Lars-Peter Clausen
2013-11-30 11:07 ` Jonathan Cameron
2013-11-25 12:41 ` [PATCH 04/15] iio:ad5686: " Lars-Peter Clausen
2013-11-30 11:07 ` Jonathan Cameron
2013-11-25 12:41 ` [PATCH 05/15] iio:ad5755: " Lars-Peter Clausen
2013-11-30 11:08 ` Jonathan Cameron
2013-11-25 12:41 ` [PATCH 06/15] iio:ad5791: Mark transfer buffers " Lars-Peter Clausen
2013-11-30 11:08 ` Jonathan Cameron
2013-11-25 12:41 ` [PATCH 07/15] iio:ad5791: Do not store transfer buffers on the stack Lars-Peter Clausen
2013-11-30 11:09 ` Jonathan Cameron [this message]
2013-12-22 17:36 ` Jonathan Cameron
2013-12-22 17:40 ` Lars-Peter Clausen
2013-12-22 17:43 ` Jonathan Cameron
2013-11-25 12:42 ` [PATCH 08/15] iio:ad7266: Mark transfer buffer as __be16 Lars-Peter Clausen
2013-11-30 11:10 ` Jonathan Cameron
2013-11-25 12:42 ` [PATCH 09/15] iio:vcnl4000: " Lars-Peter Clausen
2013-11-30 11:11 ` Jonathan Cameron
2013-11-25 12:42 ` [PATCH 10/15] staging:iio:ad7280a: Mark transfer buffer as __be32 Lars-Peter Clausen
2013-11-30 11:12 ` Jonathan Cameron
2013-11-25 12:42 ` [PATCH 11/15] staging:iio:ad7280a: Do not store transfer buffer on the stack Lars-Peter Clausen
2013-11-30 11:12 ` Jonathan Cameron
2013-11-25 12:42 ` [PATCH 12/15] staging:iio:ad7746: Mark transfer buffer as __be32 Lars-Peter Clausen
2013-11-30 11:13 ` Jonathan Cameron
2013-11-25 12:42 ` [PATCH 13/15] staging:iio:ad7746: Do not store the transfer buffer on the stack Lars-Peter Clausen
2013-11-30 11:13 ` Jonathan Cameron
2013-12-22 17:22 ` Jonathan Cameron
2013-11-25 12:42 ` [PATCH 14/15] staging:iio:ad9832: Mark transfer buffers as __be16 Lars-Peter Clausen
2013-11-30 11:14 ` Jonathan Cameron
2013-12-03 10:27 ` Lars-Peter Clausen
2013-12-03 14:56 ` Jonathan Cameron
2013-12-03 20:09 ` Jonathan Cameron
2013-12-03 20:11 ` Lars-Peter Clausen
2013-11-25 12:42 ` [PATCH 15/15] staging:iio:ad9834: Mark transfer buffers as __b16 Lars-Peter Clausen
2013-11-30 11:14 ` Jonathan Cameron
2013-11-30 11:03 ` [PATCH 01/15] iio:ad5504: Mark transfer buffers as __be16 Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5299C779.3070601@kernel.org \
--to=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).