From: David Lechner <dlechner@baylibre.com>
To: Mark Brown <broonie@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
"Martin Sperl" <kernel@martin.sperl.org>,
"David Jander" <david@protonic.nl>,
"Jonathan Cameron" <jic23@kernel.org>,
"Michael Hennerich" <michael.hennerich@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Alain Volmat" <alain.volmat@foss.st.com>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org, linux-iio@vger.kernel.org,
"Julien Stephan" <jstephan@baylibre.com>
Subject: [PATCH v2 5/5] iio: adc: ad7380: use spi_optimize_message()
Date: Mon, 19 Feb 2024 16:33:22 -0600 [thread overview]
Message-ID: <20240219-mainline-spi-precook-message-v2-5-4a762c6701b9@baylibre.com> (raw)
In-Reply-To: <20240219-mainline-spi-precook-message-v2-0-4a762c6701b9@baylibre.com>
This modifies the ad7380 ADC driver to use spi_optimize_message() to
optimize the SPI message for the buffered read operation. Since buffered
reads reuse the same SPI message for each read, this can improve
performance by reducing the overhead of setting up some parts the SPI
message in each spi_sync() call.
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
v2 changes:
- Removed dynamic allocation of spi xfer/msg
- Moved spi message optimization to probe function
- Dropped buffer pre/post callbacks
drivers/iio/adc/ad7380.c | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c
index abd746aef868..6b3fd20c8f1f 100644
--- a/drivers/iio/adc/ad7380.c
+++ b/drivers/iio/adc/ad7380.c
@@ -133,6 +133,9 @@ struct ad7380_state {
struct spi_device *spi;
struct regulator *vref;
struct regmap *regmap;
+ /* xfer and msg for buffer reads */
+ struct spi_transfer xfer;
+ struct spi_message msg;
/*
* DMA (thus cache coherency maintenance) requires the
* transfer buffers to live in their own cache lines.
@@ -236,14 +239,9 @@ static irqreturn_t ad7380_trigger_handler(int irq, void *p)
struct iio_poll_func *pf = p;
struct iio_dev *indio_dev = pf->indio_dev;
struct ad7380_state *st = iio_priv(indio_dev);
- struct spi_transfer xfer = {
- .bits_per_word = st->chip_info->channels[0].scan_type.realbits,
- .len = 4,
- .rx_buf = st->scan_data.raw,
- };
int ret;
- ret = spi_sync_transfer(st->spi, &xfer, 1);
+ ret = spi_sync(st->spi, &st->msg);
if (ret)
goto out;
@@ -335,6 +333,28 @@ static const struct iio_info ad7380_info = {
.debugfs_reg_access = &ad7380_debugfs_reg_access,
};
+static void ad7380_unoptimize_spi_msg(void *msg)
+{
+ spi_unoptimize_message(msg);
+}
+
+static int devm_ad7380_setup_spi_msg(struct device *dev, struct ad7380_state *st)
+{
+ int ret;
+
+ st->xfer.bits_per_word = st->chip_info->channels[0].scan_type.realbits;
+ st->xfer.len = 4;
+ st->xfer.rx_buf = st->scan_data.raw;
+
+ spi_message_init_with_transfers(&st->msg, &st->xfer, 1);
+
+ ret = spi_optimize_message(st->spi, &st->msg);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to optimize message\n");
+
+ return devm_add_action_or_reset(dev, ad7380_unoptimize_spi_msg, &st->msg);
+}
+
static int ad7380_init(struct ad7380_state *st)
{
int ret;
@@ -411,6 +431,10 @@ static int ad7380_probe(struct spi_device *spi)
return dev_err_probe(&spi->dev, PTR_ERR(st->regmap),
"failed to allocate register map\n");
+ ret = devm_ad7380_setup_spi_msg(&spi->dev, st);
+ if (ret)
+ return ret;
+
indio_dev->channels = st->chip_info->channels;
indio_dev->num_channels = st->chip_info->num_channels;
indio_dev->name = st->chip_info->name;
--
2.43.2
next prev parent reply other threads:[~2024-02-19 22:35 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-19 22:33 [PATCH v2 0/5] spi: add support for pre-cooking messages David Lechner
2024-02-19 22:33 ` [PATCH v2 1/5] spi: add spi_optimize_message() APIs David Lechner
2024-02-20 10:50 ` Nuno Sá
2024-02-24 16:36 ` Jonathan Cameron
2024-02-24 18:15 ` Markus Elfring
2024-02-24 20:09 ` Markus Elfring
2024-02-26 13:48 ` Mark Brown
2024-02-19 22:33 ` [PATCH v2 2/5] spi: move splitting transfers to spi_optimize_message() David Lechner
2024-02-20 10:52 ` Nuno Sá
2024-02-19 22:33 ` [PATCH v2 3/5] spi: stm32: move splitting transfers to optimize_message David Lechner
2024-02-24 16:45 ` Jonathan Cameron
2024-02-19 22:33 ` [PATCH v2 4/5] spi: axi-spi-engine: move message compile " David Lechner
2024-02-20 10:45 ` Nuno Sá
2024-02-24 16:51 ` Jonathan Cameron
2024-02-19 22:33 ` David Lechner [this message]
2024-02-20 10:41 ` [PATCH v2 5/5] iio: adc: ad7380: use spi_optimize_message() Nuno Sá
2024-02-24 16:57 ` Jonathan Cameron
2024-02-27 16:36 ` David Lechner
2024-02-26 19:16 ` (subset) [PATCH v2 0/5] spi: add support for pre-cooking messages Mark Brown
2024-06-28 9:49 ` Oleksij Rempel
2024-06-28 10:16 ` Marc Kleine-Budde
2024-06-28 15:27 ` David Lechner
2024-06-28 17:47 ` Oleksij Rempel
2024-07-01 6:55 ` Oleksij Rempel
2024-06-28 12:17 ` Mark Brown
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=20240219-mainline-spi-precook-message-v2-5-4a762c6701b9@baylibre.com \
--to=dlechner@baylibre.com \
--cc=alain.volmat@foss.st.com \
--cc=alexandre.torgue@foss.st.com \
--cc=broonie@kernel.org \
--cc=david@protonic.nl \
--cc=jic23@kernel.org \
--cc=jstephan@baylibre.com \
--cc=kernel@martin.sperl.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=michael.hennerich@analog.com \
--cc=nuno.sa@analog.com \
/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).