From: Patrick DELAUNAY Date: Thu, 13 Dec 2018 16:04:34 +0000 Subject: [U-Boot] [PATCH v2 1/2] spl_spi: Read default speed and mode values from DT In-Reply-To: References: <1542648790-21362-1-git-send-email-patrick.delaunay@st.com> <1542648790-21362-2-git-send-email-patrick.delaunay@st.com> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Hi Adam, Thanks for the tests,=20 And sorry for the regression on your board. > From: Adam Ford > Sent: lundi 10 d=C3=A9cembre 2018 23:48 >=20 > On Mon, Nov 19, 2018 at 11:55 AM Patrick Delaunay > wrote: > > > > In case of DT boot, don't read default speed and mode for SPI from > > CONFIG_*, instead read from DT node. > > > > Signed-off-by: Christophe Kerello > > Signed-off-by: Patrick Delaunay > > --- > > > > Changes in v2: > > - use variables to avoid duplicated code > > > > common/spl/spl_spi.c | 10 ++++++++-- > > 1 file changed, 8 insertions(+), 2 deletions(-) > > > > diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c index > > 8cd4830..b348b45 100644 > > --- a/common/spl/spl_spi.c > > +++ b/common/spl/spl_spi.c > > @@ -74,15 +74,21 @@ static int spl_spi_load_image(struct spl_image_info > *spl_image, > > unsigned payload_offs =3D CONFIG_SYS_SPI_U_BOOT_OFFS; > > struct spi_flash *flash; > > struct image_header *header; > > + unsigned int max_hz =3D CONFIG_SF_DEFAULT_SPEED; > > + unsigned int spi_mode =3D CONFIG_SF_DEFAULT_MODE; > > >=20 > Instead of > > +#ifdef CONFIG_DM_SPI_FLASH >=20 > What about using: >=20 > #if CONFIG_IS_ENABLED(OF_CONTROL) && > !CONFIG_IS_ENABLED(OF_PLATDATA) >=20 > > + /* In DM mode defaults will be taken from DT */ > > + max_hz =3D 0, spi_mode =3D 0; > > +#endif >=20 > This one-line change 'should' give you what you want, the settings of > 0 for boards using the device tree. If board that uses OF_PLATDATA canno= t load > the device tree, it'll default back to the configs set above. You could = probably > combine all if statements into one, and I'd be fine with that too. >=20 > This one-line change made my board boot with this series. I haven't appl= ied the > follow-up series yet but if a v3 was posted with this change, I'd mark it= as > 'tested-by. >=20 > adam I am not familiar with platdata (my platform use only device tree). So I take some time to check and answer. I clearly no anticipate the issue for OF_PLATDATA, mainly caused by code in= drivers/spi/spi-uclass.c In function spi_get_bus_and_cs The parameter speed expect 0 to load parameter from device tree / with pare= nt platdata if (!speed) { speed =3D plat->max_hz; mode =3D plat->mode; } =3D> it should the default behavior when parent is correctly initialized fo= r ALL the user (SPL/ENV/Commands). But for some case, when driver is automatically created (no device tree nod= e or platform data) Speed is ALSO used as max_hz entry for platdata. It is a bad idea when speed =3D 0=20 Simon already make a patch to avoid the issue =3D> "dm: spi: prevent setting a speed of 0 Hz" SHA1 =3D 12bfb2e05fc29bfbec7eb76ea8cc02e130268801 But in your case , it is not enough ..... I don't known why, I try to understood how the platdata for parent (SPI_UCLASS) can be configu= rated... I need to go deeper. A solution can to change the code introduce by Simon : + if (speed) { + plat->max_hz =3D speed; + } else { + printf("Warning: SPI speed fallback to %u kHz\n", + SPI_DEFAULT_SPEED_HZ / 1000); + plat->max_hz =3D SPI_DEFAULT_SPEED_HZ; + } some update can work in your case if (speed) { plat->max_hz =3D speed;=20 } else { #ifdef CONFIG_SF_DEFAULT_SPEED plat->max_hz =3D CONFIG_SF_DEFAULT_SPEED;=20 #else printf("Warning: SPI speed fallback to %u kHz\n", SPI_DEFAULT_SPEED_HZ / 1000); plat->max_hz =3D SPI_DEFAULT_SPEED_HZ; #endif } If (mode) plat->mode =3D mode; else #ifdef CONFIG_SF_DEFAULT_MODE plat->mode =3D CONFIG_SF_DEFAULT_MODE #else plat->mode =3D SPI_MODE_3 #endif In thise case the CONFIG_DEFAULT value are defined, they are used.... So the 2 series are not enough mature today, we need some work. But I start my holiday today, I will come back only in 3 weeks.... I will check this point when I will come back. NB: for short term solution, for plaform with DT only flash descrition (as = my platform), we can use CONFIG_SF_DEFAULT_SPEED=3D0 CONFIG_SF_DEFAULT_MODE=3D0 That should be solved the current issue in my board without need to merge t= he 2 series (not yet tested). > > /* > > * Load U-Boot image from SPI flash into RAM > > */ > > > > flash =3D spi_flash_probe(CONFIG_SF_DEFAULT_BUS, > > CONFIG_SF_DEFAULT_CS, > > - CONFIG_SF_DEFAULT_SPEED, > > - CONFIG_SF_DEFAULT_MODE); > > + max_hz, > > + spi_mode); > > if (!flash) { > > puts("SPI probe failed.\n"); > > return -ENODEV; > > -- > > 2.7.4 > > > > _______________________________________________ > > U-Boot mailing list > > U-Boot at lists.denx.de > > https://lists.denx.de/listinfo/u-boot Regards=20 Patrick