[U-Boot] [PATCH v2] dm: spi: prevent setting a speed of 0 Hz
Simon Goldschmidt
simon.k.r.goldschmidt at gmail.com
Wed Oct 31 06:42:03 UTC 2018
On Wed, Oct 31, 2018 at 7:22 AM Jagan Teki <jagan at amarulasolutions.com> wrote:
>
> On Wed, Oct 31, 2018 at 1:40 AM Simon Goldschmidt
> <simon.k.r.goldschmidt at gmail.com> wrote:
> >
> > When the device tree is missing a correct spi slave description below
> > the bus (compatible "spi-flash" or spi-max-frequency are missing),
> > the 'set_speed' callback can be called with 'speed' == 0 Hz.
> > At least with cadence qspi, this leads to a division by zero.
> >
> > Prevent this by initializing speed to 100 kHz in this case (same
> > fallback value as is done in 'dm_spi_claim_bus') and issue a warning
> > to console.
>
> Why can't driver plat->frequency in cadence driver initialize 100KH?
> plat->frequency = fdtdec_get_int(blob, node, "spi-max-frequency", 100000)
I'm not sure I understand.
The cadence driver initializes its 'plat->max_hz' from
"spi-max-frequency" property and defaults to 500 kHz. No problem
there.
However, the problem I want to solve is if someone puts a flash chip
below there which has compatible != "spi-flash", they will get a hard
fault which is hard to debug. This is because the node is not parsed
because of the wrong compatible string (even if there is an
"spi-max-frequency" property) and thus, "sf probe" tries to continue
with 0 Hz.
And this can happen easily when porting device trees from Linux as
there, the boards have compatible "n25q00" etc. instead of
"spi-flash", which is U-Boot specific (sadly).
This patch is not required to make valid U-Boot devicetrees work, it
is meant to get better error handling for devicetrees ported from
Linux.
An even better fix would be for U-Boot not to require the compatible =
"spi-flash" string but just work correctly with Linux device trees,
but that's not within my possibilities right now :-(
Simon
More information about the U-Boot
mailing list