From: David Lechner <dlechner@baylibre.com>
To: "Mark Brown" <broonie@kernel.org>,
"Jonathan Cameron" <jic23@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Nuno Sá" <nuno.sa@analog.com>
Cc: "Uwe Kleine-König" <ukleinek@kernel.org>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"David Jander" <david@protonic.nl>,
"Martin Sperl" <kernel@martin.sperl.org>,
linux-spi@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH v8 14/17] iio: adc: ad4695: Add support for SPI offload
Date: Mon, 10 Feb 2025 10:01:57 -0600 [thread overview]
Message-ID: <8a8432e7-86b9-43dd-9aa0-75875747eedb@baylibre.com> (raw)
In-Reply-To: <20250207-dlech-mainline-spi-engine-offload-2-v8-14-e48a489be48c@baylibre.com>
On 2/7/25 2:09 PM, David Lechner wrote:
> Add support for SPI offload to the ad4695 driver. SPI offload allows
> sampling data at the max sample rate (500kSPS or 1MSPS).
>
> This is developed and tested against the ADI example FPGA design for
> this family of ADCs [1].
>
> [1]: http://analogdevicesinc.github.io/hdl/projects/ad469x_fmc/index.html
>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
>
...
> ---
> drivers/iio/adc/Kconfig | 1 +
> drivers/iio/adc/ad4695.c | 445 +++++++++++++++++++++++++++++++++++++++++++++--
> 2 files changed, 429 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index 995b9cacbaa964d26424346120c139858f93cdcd..ec60b64c46e187e2be18ab1f8ca9e6f4f03299f9 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -52,6 +52,7 @@ config AD4695
> tristate "Analog Device AD4695 ADC Driver"
> depends on SPI
> select IIO_BUFFER
> + select IIO_BUFFER_DMAENGINE
> select IIO_TRIGGERED_BUFFER
> select REGMAP
I missed adding
select SPI_OFFLOAD
Closes: https://lore.kernel.org/oe-kbuild-all/202502090910.ganYXEeF-lkp@intel.com/
> help
...
> +static int ad4695_offload_buffer_postenable(struct iio_dev *indio_dev)
> +{
> + struct ad4695_state *st = iio_priv(indio_dev);
> + struct spi_offload_trigger_config config = {
> + .type = SPI_OFFLOAD_TRIGGER_DATA_READY,
> + };
> + struct spi_transfer *xfer = &st->buf_read_xfer[0];
> + struct pwm_state state;
> + u8 temp_chan_bit = st->chip_info->num_voltage_inputs;
> + u8 num_slots = 0;
> + u8 temp_en = 0;
> + unsigned int bit;
> + int ret;
> +
> + iio_for_each_active_channel(indio_dev, bit) {
> + if (bit == temp_chan_bit) {
> + temp_en = 1;
> + continue;
> + }
> +
> + ret = regmap_write(st->regmap, AD4695_REG_AS_SLOT(num_slots),
> + FIELD_PREP(AD4695_REG_AS_SLOT_INX, bit));
> + if (ret)
> + return ret;
> +
> + num_slots++;
> + }
> +
> + /*
> + * For non-offload, we could discard data to work around this
> + * restriction, but with offload, that is not possible.
> + */
> + if (num_slots < 2) {
> + dev_err(&st->spi->dev,
> + "At least two voltage channels must be enabled.\n");
> + return -EINVAL;
> + }
> +
> + ret = regmap_update_bits(st->regmap, AD4695_REG_TEMP_CTRL,
> + AD4695_REG_TEMP_CTRL_TEMP_EN,
> + FIELD_PREP(AD4695_REG_TEMP_CTRL_TEMP_EN,
> + temp_en));
> + if (ret)
> + return ret;
> +
> + /* Each BUSY event means just one sample for one channel is ready. */
> + memset(xfer, 0, sizeof(*xfer));
> + xfer->offload_flags = SPI_OFFLOAD_XFER_RX_STREAM;
> + /* Using 19 bits per word to allow for possible oversampling */
> + xfer->bits_per_word = 19;
> + xfer->len = 4;
> +
> + spi_message_init_with_transfers(&st->buf_read_msg, xfer, 1);
> + st->buf_read_msg.offload = st->offload;
> +
> + ret = spi_optimize_message(st->spi, &st->buf_read_msg);
> + if (ret)
> + return ret;
> +
> + /*
> + * NB: technically, this is part the SPI offload trigger enable, but it
> + * doesn't work to call it from the offload trigger enable callback
> + * because it requires accessing the SPI bus. Calling it from the
> + * trigger enable callback could cause a deadlock.
> + */
> + ret = regmap_set_bits(st->regmap, AD4695_REG_GP_MODE,
> + AD4695_REG_GP_MODE_BUSY_GP_EN);
> + if (ret)
> + goto err_unoptimize_message;
> +
> + ret = spi_offload_trigger_enable(st->offload, st->offload_trigger,
> + &config);
> + if (ret)
> + goto err_disable_busy_output;
> +
> + ret = ad4695_enter_advanced_sequencer_mode(st, num_slots);
> + if (ret)
> + goto err_offload_trigger_disable;
> +
> + guard(mutex)(&st->cnv_pwm_lock);
Apparently clang doesn't like this guard() after goto, so I'll have to figure
out what to do about that. Probably need to add a helper function to avoid
goto below from jumping out of scoped_guard().
https://lore.kernel.org/oe-kbuild-all/202502090806.KxEvxCZC-lkp@intel.com/
> + pwm_get_state(st->cnv_pwm, &state);
> + /*
> + * PWM subsystem generally rounds down, so requesting 2x minimum high
> + * time ensures that we meet the minimum high time in any case.
> + */
> + state.duty_cycle = AD4695_T_CNVH_NS * 2;
> + ret = pwm_apply_might_sleep(st->cnv_pwm, &state);
> + if (ret)
> + goto err_offload_exit_conversion_mode;
> +
> + return 0;
> +
> +err_offload_exit_conversion_mode:
> + /*
> + * We have to unwind in a different order to avoid triggering offload.
> + * ad4695_exit_conversion_mode() triggers a conversion, so it has to be
> + * done after spi_offload_trigger_disable().
> + */
> + spi_offload_trigger_disable(st->offload, st->offload_trigger);
> + ad4695_exit_conversion_mode(st);
> + goto err_disable_busy_output;
> +
> +err_offload_trigger_disable:
> + spi_offload_trigger_disable(st->offload, st->offload_trigger);
> +
> +err_disable_busy_output:
> + regmap_clear_bits(st->regmap, AD4695_REG_GP_MODE,
> + AD4695_REG_GP_MODE_BUSY_GP_EN);
> +
> +err_unoptimize_message:
> + spi_unoptimize_message(&st->buf_read_msg);
> +
> + return ret;
> +}
next prev parent reply other threads:[~2025-02-10 16:02 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 20:08 [PATCH v8 00/17] spi: axi-spi-engine: add offload support David Lechner
2025-02-07 20:08 ` [PATCH v8 01/17] spi: add basic support for SPI offloading David Lechner
2025-02-10 16:45 ` Andy Shevchenko
2025-02-10 17:11 ` David Lechner
2025-02-10 17:48 ` Mark Brown
2025-02-10 20:33 ` Andy Shevchenko
2025-02-11 13:00 ` Mark Brown
2025-02-11 14:20 ` Andy Shevchenko
2025-02-11 14:29 ` Andy Shevchenko
2025-02-11 14:31 ` Andy Shevchenko
2025-02-11 14:35 ` Andy Shevchenko
2025-02-11 18:45 ` Uwe Kleine-König
2025-02-11 18:53 ` Mark Brown
2025-02-11 19:15 ` Andy Shevchenko
2025-02-11 19:12 ` Andy Shevchenko
2025-02-12 8:52 ` Uwe Kleine-König
2025-02-12 10:55 ` Andy Shevchenko
2025-02-12 10:58 ` Andy Shevchenko
2025-02-07 20:08 ` [PATCH v8 02/17] spi: offload: add support for hardware triggers David Lechner
2025-02-07 20:09 ` [PATCH v8 03/17] dt-bindings: trigger-source: add generic PWM trigger source David Lechner
2025-02-07 20:09 ` [PATCH v8 04/17] spi: offload-trigger: add PWM trigger driver David Lechner
2025-02-10 16:52 ` Andy Shevchenko
2025-02-07 20:09 ` [PATCH v8 05/17] spi: add offload TX/RX streaming APIs David Lechner
2025-02-07 20:09 ` [PATCH v8 06/17] spi: dt-bindings: axi-spi-engine: add SPI offload properties David Lechner
2025-02-07 20:09 ` [PATCH v8 07/17] spi: axi-spi-engine: implement offload support David Lechner
2025-02-07 20:09 ` [PATCH v8 08/17] iio: buffer-dmaengine: split requesting DMA channel from allocating buffer David Lechner
2025-02-07 20:09 ` [PATCH v8 09/17] iio: buffer-dmaengine: add devm_iio_dmaengine_buffer_setup_with_handle() David Lechner
2025-02-07 20:09 ` [PATCH v8 10/17] iio: adc: ad7944: don't use storagebits for sizing David Lechner
2025-02-07 20:09 ` [PATCH v8 11/17] iio: adc: ad7944: add support for SPI offload David Lechner
2025-02-10 19:09 ` David Lechner
2025-02-11 19:32 ` Jonathan Cameron
2025-02-07 20:09 ` [PATCH v8 12/17] doc: iio: ad7944: describe offload support David Lechner
2025-02-07 20:09 ` [PATCH v8 13/17] dt-bindings: iio: adc: adi,ad4695: add SPI offload properties David Lechner
2025-02-07 20:09 ` [PATCH v8 14/17] iio: adc: ad4695: Add support for SPI offload David Lechner
2025-02-07 20:20 ` Mark Brown
2025-02-08 13:11 ` Jonathan Cameron
2025-02-10 16:01 ` David Lechner [this message]
2025-02-10 18:54 ` Jonathan Cameron
2025-02-07 20:09 ` [PATCH v8 15/17] doc: iio: ad4695: add SPI offload support David Lechner
2025-02-07 20:09 ` [PATCH v8 16/17] iio: dac: ad5791: sort include directives David Lechner
2025-02-07 20:09 ` [PATCH v8 17/17] iio: dac: ad5791: Add offload support David Lechner
2025-02-10 14:36 ` [PATCH v8 00/17] spi: axi-spi-engine: add " Mark Brown
2025-02-10 18:59 ` Jonathan Cameron
2025-02-10 16:07 ` (subset) " 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=8a8432e7-86b9-43dd-9aa0-75875747eedb@baylibre.com \
--to=dlechner@baylibre.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=Michael.Hennerich@analog.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=david@protonic.nl \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=kernel@martin.sperl.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=ukleinek@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