mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
To: Petre Rodan <petre.rodan@subdimension.ro>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Andreas Klinger" <ak@it-klinger.de>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Jonathan Cameron" <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH 09/14] iio: pressure: mprls0025pa: mitigate SPI CS delay violation
Date: Mon, 22 Dec 2025 11:36:11 -0300	[thread overview]
Message-ID: <aUlXWwoqnG7llPwA@debian-BULLSEYE-live-builder-AMD64> (raw)
In-Reply-To: <aUZUwL2fHQ6Q4zOI@sunspire.home.arpa>

On 12/20, Petre Rodan wrote:
> 
> Hello Marcelo,
> 
> thank you for the pointers.
> 
> On Sat, Dec 20, 2025 at 01:51:42AM -0300, Marcelo Schmitt wrote:
> > On 12/18, Petre Rodan wrote:
> > > Based on the sensor datasheet in chapter 7.6 SPI timing, Table 20,
> > > during the SPI transfer there is a minimum time interval between the
> > > CS being asserted and the first clock edge (tHDSS).
> > > This minimum interval of 2.5us is being violated if two consecutive SPI
> > > transfers are queued up, at least on my SPI controller (omap2_mcspi) [1]
> > > As you can see in the first package that only contains a NOP the interval
> > > is 0.75us (half a 800kHz clock cycle).
> > > 
> > > This patch mitigates the problem by implementing a different measurement
> > > technique that does not involve checking for the EOC indicator before
> > > reading the conversion, thus making sure SPI transfers are not queued up.
> > The correct way of fixing that is with protocol specific delay. Generic delays
> > like fsleep won't guarantee any delay between CS drop and fist SCLK edge.
> 
> sorry for the lack of detail in the commit log, I forgot to add it.
> 
> this patch changes the measurement sequence and as a consequence it also mitigates a problem where protocol-specific delays are not implemented in the SPI controller (for the corner case when multiple SPI transfers are queued up).
> 
> as per the datasheet pages 36 and 41, the measurement sequence can follow one of these two scenarios, for both bus implementations:
> 
> a) send measurement command and wait for the status byte to lose the busy flag.
> this means that we would need to keep sending NOP commands and read the first (status) byte in a loop until the busy flag goes away. this is how the driver was designed before this series of patches.
> 
> b) send measurement command and wait for 5ms for the data conversion to occur.
> same as a, but instead of polling the sensor for the status byte there's just a 5ms+ delay after which only one NOP command is sent.
> the read that follows will get the conversion data plus the status byte.
> depending on the status byte flags, either error out or pass the conversion along.
> 
> my patch replaces the measurement sequence defined by scenario a with scenario b and it only affects users that did not define the EoC interrupt pin in the device tree overlay.
> the datasheet contains sample code (pages 38 and 43) and they also happen to use scenario b, so no polling.
> in my testing the sensor always performed as expected (the busy flag was never set after the 5ms fsleep()).
> 
> > For SPI, we unfortunately we don't have any interface to set a pre-SCLK delay
> > so I suggest to make an spi_message with a dummy transfer to cause the initial
> > 2.5 µs delay. E.g.
> 
> for normal (non-queued) SPI messages the delay that exist between the CS assert and the first clock is ~4us, well above the 2.5us minimum.
> the problem only appears when the SPI controller gets multiple xfers without any delays between them - which happens in scenario a when two transfers get queued up (NOP that reads the status byte and the NOP that reads the status + conversions).

Sure, as you say, the probable reason to have enough first SCLK delay was
because the SPI controller was not initially dealing with many transfers.
Though, can't the MPR read transfer lack enough first SCLK delay if a different
device on the same bus bursts SPI transfers during MPR device read?
fsleep() may fix it for single-device use case, but I don't think it is the
proper way of getting transfer timings correctly. To ensure that first SCLK
delay, you got to use protocol specific delays so that the controller will
be able to properly set that delay.

> 
> this is just a hunch but I think that the CS timing is directly controlled by hardware when the issue happens.
> see chapter 24.3.2.8 page 4903 in the AM335x technical reference manual [1].
> I'm measuring exactly 0.5 clock cycles CS lead times which is the default for the TCS bit of the register MCSPI_CH(i)CONF.
> 
> [1] https://www.ti.com/lit/ug/spruh73q/spruh73q.pdf?ts=1766215152875
> 
> > /* dummy transfer with no data, just cause the delay */
> > xfers[0].delay.value = 2500 * NSEC_PER_SEC;
> > xfers[0].delay.unit = SPI_DELAY_UNIT_NSECS;
> > 
> > /* normal data transfer  */
> > xfer[1].tx_buf = data->tx_buf;
> > xfer[1].rx_buf = data->rx_buf;
> > ...

See spi.h for documentation of the delays available for SPI transfers. As I
mentioned, we unfortunately don't have a first SCLK delay for SPI but I think
you may get something equivalent with a dummy transfer like the example above.

> > 
> > Also, I don't see how the proposed change is 'implementing a different
> > measurement technique'. Consider updating the commit description or providing
> > better explanation.
> 
> I feel that using scenario b defined above we cure the problem before it happens.
> my patch provides a less complex implementation, it's recommended by the manufacturer in their sample code and provides less code duplication (status byte parsing) with no downsides afaict.
> 
> > > see Option 2 in Table 19 SPI output measurement command.
> > > Note that Honeywell's example code also follows this technique for both i2c
> > > and SPI.
> > > 
> > > This change only affects users that do not define the EOC interrupt in the
> > > device tree.
> > > 
> > > Remove defines that are no longer used.
> > > 
> > > [1] https://pasteboard.co/66WN38MRI1wc.png
> > > 
> > > Datasheet: https://prod-edam.honeywell.com/content/dam/honeywell-edam/sps/siot/en-us/products/sensors/pressure-sensors/board-mount-pressure-sensors/micropressure-mpr-series/documents/sps-siot-mpr-series-datasheet-32332628-ciid-172626.pdf?download=false
> > > Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
> 
> best regards,
> peter
> 
> -- 
> petre rodan

  reply	other threads:[~2025-12-22 14:34 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-18 11:05 [PATCH 00/14] iio: pressure: mprls0025pa: driver code cleanup Petre Rodan
2025-12-18 11:05 ` [PATCH 01/14] iio: pressure: mprls0025pa: Kconfig allow bus selection Petre Rodan
2025-12-20  4:39   ` Marcelo Schmitt
2025-12-21 18:06     ` Jonathan Cameron
2025-12-18 11:05 ` [PATCH 02/14] iio: pressure: mprls0025pa: remove redundant mutex Petre Rodan
2025-12-20  4:45   ` Marcelo Schmitt
2025-12-21 18:13     ` Jonathan Cameron
2025-12-18 11:05 ` [PATCH 03/14] iio: pressure: mprls0025pa: rename buffer variable Petre Rodan
2025-12-18 11:05 ` [PATCH 04/14] iio: pressure: mprls0025pa: introduce tx buffer Petre Rodan
2025-12-20  4:46   ` Marcelo Schmitt
2025-12-18 11:05 ` [PATCH 05/14] iio: pressure: mprls0025pa: zero out spi_transfer struct Petre Rodan
2025-12-21 18:18   ` Jonathan Cameron
2025-12-18 11:05 ` [PATCH 06/14] iio: pressure: mprls0025pa: memset rx_buf before reading new data Petre Rodan
2025-12-20  4:47   ` Marcelo Schmitt
2025-12-20  8:25     ` Petre Rodan
2025-12-21 18:21       ` Jonathan Cameron
2025-12-22  5:57         ` Petre Rodan
2025-12-22 14:06           ` Marcelo Schmitt
2025-12-27 14:31             ` Jonathan Cameron
2026-01-03  8:00               ` Petre Rodan
2026-01-11 11:44                 ` Jonathan Cameron
2025-12-18 11:05 ` [PATCH 07/14] iio: pressure: mprls0025pa: make ops->write function consistent Petre Rodan
2025-12-20  4:49   ` Marcelo Schmitt
2025-12-20  9:59     ` Petre Rodan
2025-12-18 11:05 ` [PATCH 08/14] iio: pressure: mprls0025pa: stricter checks for the status byte Petre Rodan
2025-12-20  4:50   ` Marcelo Schmitt
2025-12-18 11:05 ` [PATCH 09/14] iio: pressure: mprls0025pa: mitigate SPI CS delay violation Petre Rodan
2025-12-20  4:51   ` Marcelo Schmitt
2025-12-20  7:48     ` Petre Rodan
2025-12-22 14:36       ` Marcelo Schmitt [this message]
2025-12-18 11:05 ` [PATCH 10/14] iio: pressure: mprls0025pa: cleanup pressure calculation Petre Rodan
2025-12-20  4:53   ` Marcelo Schmitt
2025-12-18 11:05 ` [PATCH 11/14] iio: pressure: mprls0025pa: fix scan_type struct Petre Rodan
2025-12-21 18:34   ` Jonathan Cameron
2025-12-18 11:05 ` [PATCH 12/14] iio: pressure: mprls0025pa: fix interrupt flag Petre Rodan
2025-12-21 18:38   ` Jonathan Cameron
2025-12-22  7:22     ` Petre Rodan
2025-12-27 16:40       ` Jonathan Cameron
2025-12-18 11:05 ` [PATCH 13/14] iio: pressure: mprls0025pa: cleanup includes and forward declarations Petre Rodan
2025-12-20  4:55   ` Marcelo Schmitt
2025-12-18 11:05 ` [PATCH 14/14] iio: pressure: mprls0025pa: add copyright line Petre Rodan

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=aUlXWwoqnG7llPwA@debian-BULLSEYE-live-builder-AMD64 \
    --to=marcelo.schmitt1@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=ak@it-klinger.de \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=petre.rodan@subdimension.ro \
    /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

all inboxes | Powered by JetHome®