From: David Lechner <dlechner@baylibre.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "Mark Brown" <broonie@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>,
"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,
linux-pwm@vger.kernel.org
Subject: Re: [PATCH RFC v4 15/15] iio: adc: ad4695: Add support for SPI offload
Date: Sun, 27 Oct 2024 14:52:17 -0500 [thread overview]
Message-ID: <2679570d-6255-467b-8312-117e553a52b4@baylibre.com> (raw)
In-Reply-To: <20241027091244.2fe3c0ad@jic23-huawei>
On 10/27/24 4:12 AM, Jonathan Cameron wrote:
> On Sat, 26 Oct 2024 19:01:53 -0500
> David Lechner <dlechner@baylibre.com> wrote:
>
>> On 10/26/24 11:00 AM, Jonathan Cameron wrote:
>>> On Wed, 23 Oct 2024 15:59:22 -0500
>>> David Lechner <dlechner@baylibre.com> wrote:
>>>
...
>>>
>>>> static int ad4695_probe(struct spi_device *spi)
>>>> {
>>>> struct device *dev = &spi->dev;
>>>> struct ad4695_state *st;
>>>> struct iio_dev *indio_dev;
>>>> - struct gpio_desc *cnv_gpio;
>>>> bool use_internal_ldo_supply;
>>>> bool use_internal_ref_buffer;
>>>> int ret;
>>>>
>>>> - cnv_gpio = devm_gpiod_get_optional(dev, "cnv", GPIOD_OUT_LOW);
>>>> - if (IS_ERR(cnv_gpio))
>>>> - return dev_err_probe(dev, PTR_ERR(cnv_gpio),
>>>> - "Failed to get CNV GPIO\n");
>>>> -
>>>> - /* Driver currently requires CNV pin to be connected to SPI CS */
>>>> - if (cnv_gpio)
>>>> - return dev_err_probe(dev, -ENODEV,
>>>> - "CNV GPIO is not supported\n");
>>>> -
>>>> indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
>>>> if (!indio_dev)
>>>> return -ENOMEM;
>>>> @@ -1002,8 +1374,13 @@ static int ad4695_probe(struct spi_device *spi)
>>>> return -EINVAL;
>>>>
>>>> /* Registers cannot be read at the max allowable speed */
>>>> + st->spi_max_speed_hz = spi->max_speed_hz;
>>>> spi->max_speed_hz = AD4695_REG_ACCESS_SCLK_HZ;
>>>>
>>>> + ret = devm_add_action_or_reset(dev, ad4695_restore_spi_max_speed_hz, st);
>>>
>>> Why do you need to put it back in devm? What happens after this but without
>>> a driver restart that uses that faster rate?
>>>
>> I should have added a comment here as this was a weird bug to trace.
>>
>> The core SPI framework sets the initial value of spi->max_speed_hz
>> to the minimum of the controller max rate and the max rate specified
>> by the devicetree.
>>
>> The SPI device lives beyond this driver, so if we bind the driver
>> and set spi->max_speed_hz to something other than what the SPI core
>> set it, then the next time we bind the driver, we don't get the
>> the max rate from the SPI core, but rather we changed it to when
>> the driver unbound.
>>
>> So on the second bind, the max rate would be the slow register
>> read rate instead of the actual max allowable rate.
>>
>> So we need to reset spi->max_speed_hz to what it was originally
>> on driver unbind so that everything works as expected on the
>> next bind.
>>
>> (Or we call this a SPI core bug and fix it there instead).
> Definitely a question to ask. Directly accessing spi_max_speed_hz may
> be the fundamental issue as I don't think the driver is generally
> expected to touch that in a dynamic fashion. Should we be instead setting it
> per transfer for the ones that need it controlled?
>
> Jonathan
>
The problem is that we are using regmap and that doesn't have
a way to specify the max frequency for register reads that is
different from other uses of the SPI bus (i.e. reading sample
data). So we could fix it in the generic SPI regmap (not exactly
trivial) or we could write our own regmap read/write callbacks
in this driver that properly sets the per-transfer max speed.
next prev parent reply other threads:[~2024-10-27 19:52 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 20:59 [PATCH RFC v4 00/15] spi: axi-spi-engine: add offload support David Lechner
2024-10-23 20:59 ` [PATCH RFC v4 01/15] pwm: core: export pwm_get_state_hw() David Lechner
2024-10-29 8:05 ` Uwe Kleine-König
2024-10-29 15:30 ` David Lechner
2024-10-23 20:59 ` [PATCH RFC v4 02/15] spi: add basic support for SPI offloading David Lechner
2024-10-24 13:27 ` Nuno Sá
2024-10-24 14:49 ` David Lechner
2024-10-25 12:59 ` Nuno Sá
2024-10-25 16:39 ` Nuno Sá
2024-10-26 15:05 ` Jonathan Cameron
2024-11-11 17:14 ` David Lechner
2024-11-11 19:02 ` David Lechner
2024-10-30 15:55 ` Mark Brown
2024-10-23 20:59 ` [PATCH RFC v4 03/15] spi: offload: add support for hardware triggers David Lechner
2024-10-24 14:04 ` Nuno Sá
2024-10-24 15:02 ` David Lechner
2024-10-25 6:29 ` Nuno Sá
2024-10-26 15:14 ` Jonathan Cameron
2024-10-28 13:53 ` Nuno Sá
2024-10-23 20:59 ` [PATCH RFC v4 04/15] spi: dt-bindings: add trigger-source.yaml David Lechner
2024-10-23 20:59 ` [PATCH RFC v4 05/15] spi: dt-bindings: add PWM SPI offload trigger David Lechner
2024-10-26 15:18 ` Jonathan Cameron
2024-10-27 0:20 ` David Lechner
2024-10-27 20:24 ` Conor Dooley
2024-10-31 18:16 ` Conor Dooley
2024-11-11 17:31 ` David Lechner
2024-10-23 20:59 ` [PATCH RFC v4 06/15] spi: offload-trigger: add PWM trigger driver David Lechner
2024-10-25 12:07 ` Nuno Sá
2024-10-25 16:28 ` David Lechner
2024-10-28 13:47 ` Nuno Sá
2024-10-23 20:59 ` [PATCH RFC v4 07/15] spi: add offload TX/RX streaming APIs David Lechner
2024-10-25 12:24 ` Nuno Sá
2024-10-23 20:59 ` [PATCH RFC v4 08/15] spi: dt-bindings: axi-spi-engine: add SPI offload properties David Lechner
2024-10-25 12:26 ` Nuno Sá
2024-10-23 20:59 ` [PATCH RFC v4 09/15] spi: axi-spi-engine: implement offload support David Lechner
2024-10-25 13:09 ` Nuno Sá
2024-10-25 16:35 ` David Lechner
2024-10-23 20:59 ` [PATCH RFC v4 10/15] iio: buffer-dmaengine: document iio_dmaengine_buffer_setup_ext David Lechner
2024-10-26 15:29 ` Jonathan Cameron
2024-10-23 20:59 ` [PATCH RFC v4 11/15] iio: buffer-dmaengine: add devm_iio_dmaengine_buffer_setup_ext2() David Lechner
2024-10-25 13:24 ` Nuno Sá
2024-10-25 16:42 ` David Lechner
2024-10-23 20:59 ` [PATCH RFC v4 12/15] iio: adc: ad7944: don't use storagebits for sizing David Lechner
2024-10-23 20:59 ` [PATCH RFC v4 13/15] iio: adc: ad7944: add support for SPI offload David Lechner
2024-10-26 15:51 ` Jonathan Cameron
2024-10-23 20:59 ` [PATCH RFC v4 14/15] dt-bindings: iio: adc: adi,ad4695: add SPI offload properties David Lechner
2024-10-23 20:59 ` [PATCH RFC v4 15/15] iio: adc: ad4695: Add support for SPI offload David Lechner
2024-10-26 16:00 ` Jonathan Cameron
2024-10-27 0:01 ` David Lechner
2024-10-27 9:12 ` Jonathan Cameron
2024-10-27 19:52 ` David Lechner [this message]
2024-10-28 16:39 ` Jonathan Cameron
2024-10-27 0:05 ` David Lechner
2024-10-27 9:15 ` Jonathan Cameron
2024-10-24 14:12 ` [PATCH RFC v4 00/15] spi: axi-spi-engine: add offload support Nuno Sá
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=2679570d-6255-467b-8312-117e553a52b4@baylibre.com \
--to=dlechner@baylibre.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-pwm@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