On 2026-10-27T17:57:37+11:00, Igor Velkov via B4 Relay
<[email protected]> wrote:
> spi: sf: Probe a flash at the requested speed and mode
>
> 'sf probe <bus>:<cs> <speed> [<mode>]' ignores the speed and the mode
> for a flash that has a device tree node: the probe, and with it the
> JEDEC ID read, runs at spi-max-frequency and in the device tree mode.
> The requested values reach the controller only after the probe, through
> spi_set_speed_mode(), while slave->max_hz and slave->mode keep the
> device tree values. Without a mode, sf probe passes
> CONFIG_SF_DEFAULT_MODE, so after the probe the controller runs in that
> mode rather than in the device tree one. A mode given once also stays
> in the controller for later probes without one, since the bus still
> caches the device tree mode and the bus claim does not reprogram it.
>
> On ROCK Pi 4A the device tree sets spi-max-frequency = <108000000> and
> the flash does not answer at the resulting clock, at any requested
> speed:
>
>   => sf probe 1:0 1000000
>   jedec_spi_nor flash@0: unrecognized JEDEC id bytes: ff, ff, ff
>
> Add _spi_get_bus_and_cs_at() to the SPI uclass. It probes a slave that
> has platform data with the requested speed and mode and restores the
> platform data right after the probe, so the slave keeps the requested
> values and the platform data stays as the device tree set it. With
> dt_mode it keeps the device tree mode. Add spi_flash_probe_at() on top
> of it and use it in sf probe with an explicit speed; without a mode
> argument the device tree mode stays. A speed above spi-max-frequency is
> honoured, as it already is after the probe. The other callers of
> spi_flash_probe() and _spi_get_bus_and_cs() do not change.
>
> With this change:
>
>   => sf probe 1:0 1000000
>   SF: Detected xt25f32 with page size 256 Bytes, erase size 4 KiB, total 4 MiB
>
> Add a sandbox test for it.
>
> Signed-off-by: Igor Velkov <[email protected]>
>
>  cmd/sf.c                    |  2 +-
>  drivers/mtd/spi/sf-uclass.c | 33 +++++++++++++++++++++++++++++----
>  drivers/spi/spi-uclass.c    | 41 ++++++++++++++++++++++++++++++++++++++---
>  include/spi.h               | 23 +++++++++++++++++++++++
>  include/spi_flash.h         | 18 ++++++++++++++++++
>  test/dm/sf.c                | 42 ++++++++++++++++++++++++++++++++++++++++++
>  6 files changed, 151 insertions(+), 8 deletions(-)

Reviewed-by: Simon Glass <[email protected]>

Reply via email to