All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yixun Lan <dlan@kernel.org>
To: E Shattow <e@freeshell.de>
Cc: u-boot@lists.u-boot-project.org, Tom Rini <trini@konsulko.com>,
	Raymond Mao <raymond.mao@riscstar.com>
Subject: Re: [PATCH] spi: fsl_qspi: Add optional clock support
Date: Sun, 22 Nov 2026 00:38:13 +0000	[thread overview]
Message-ID: <20261122003813-GKB203137@kernel.org> (raw)
In-Reply-To: <03d87c74-de4b-4335-85d2-869ad8d83a31@freeshell.de>

Hi E Shattow, 

On 14:14 Sat 21 Nov     , E Shattow wrote:
> Hi Yixun,
> 
> On 11/20/26 06:43, Yixun Lan wrote:
> > The clock required by QSPI controller may not be enabled by default,
> > So explicitly get and enable the clocks described by the DT node, due
> > to keep compatibility reason, keep the clock optional for platforms if
> > there is no clock framework support or no clocks property provided.
> > 
> > Signed-off-by: Yixun Lan <dlan@kernel.org>
> > ---
> > While testing in SpacemiT K3 Platform, we found the QSPI clock need to
> > be explicitly enabled if boot from USB fastboot mode. While there is no
> 
> I observe that BootROM SPL Loader "USB" mode allows an vendor SPL with
> SPI and clocks support enabled (and otherwise reduced options; as
> "bsp-spi"[1]) to then load (via UART) u-boot.itb where mainline u-boot
> main app "sf probe" is successful.
> 
> This same vendor SPL and mainline u-boot main app "sf probe" action does
> fail if it was instead loaded from BootROM SPL Loader "UART" mode. I
> regard the "UART" mode as a baseline for testing since it apparently is
> doing the least in terms of peripheral setup. The software must do this
> setup and not depend on features of any previous peripheral setup by
> BootROM SPL Loader.
> 
> Either mode "USB" or "UART" results in probe failure from mainline
> u-boot main app if the vendor SPL is build without SPI and clocks
> support (as "bsp-nospi"[1]). From this I conclude there is a difference
> in handling setup between BootROM SPL Loader "UART" and "USB" modes in
> this way that can be tested for.
> 
> I did not yet test "SPI" mode because I assume if BootROM SPL Loader can
> access the peripheral then it will also work for SPL software to access
> the same.
> 
> 1: Guide to build reduced SpacemiT K3 vendor BSP:
> https://lore.kernel.org/u-boot/20261029001555.1890775-1-e@freeshell.de/
> 
> To be clear my above reply remarks are while *not* applying this "spi:
> fls_qspi: Add optional clock support" patch to mainline u-boot. I think
> it is interesting that "USB" mode does allow successful "sf probe" in my
> testing and that in your description it was not successful.
> 
The test environment is different, I'm testing "USB" mode without vendor SPL

> > problem in booting from SPI nor flash mode which the clock already
> > enabled by BROM code.
Yes, that's right

> > 
> > In order to not break other platforms, try to set the clock optional,
> > so it won't abort if there is no clock framework support, or no clock
> > device tree property.
> 
> The compatible "spacemit,k1-spi" is in the SpacemiT K3 SoC dtsi include:
> 
It's spacemit,k1-qspi (s/spi/qspi/) which SPI NOR connect to..

> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/riscv/boot/dts/spacemit/k3.dtsi
> 
> Matched from driver wrapper:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/spi/spi-spacemit-k1.c
> 
> Where it then appears the clock setup is branched to from k1_spi_probe()
> function.
> 
> In all situations I have tested I do observe that Linux kernel probes
> SPI NOR flash on SpacemiT K3 Pico-ITX board properly with FSL SPI driver
> and the wrapper driver matching "spacemit,k1-spi" compatible. That seems
> to me properly vetted as being correct because it always works even if
> no setup was done by SPL or u-boot main app.
> 
..
> There are some updates to the FSL SPI driver itself that should be
> sync'd from the Linux FSL SPI driver, and then I observe one improvement
> to u-boot FSL SPI driver which should probably be sent upstream to Linux.
> 
I'm not aware of this, feel free to send patches or link?

> I guess that it is preferable to sync with the Linux driver(s) for less
> maintenance troubles. Does this patch break the DM model the way it is
> now? What do the other maintainers think?
> 
I don't think it break DM model..

> > ---
> >  drivers/spi/fsl_qspi.c | 25 +++++++++++++++++++++++++
> >  1 file changed, 25 insertions(+)
> > 
> > diff --git a/drivers/spi/fsl_qspi.c b/drivers/spi/fsl_qspi.c
> > index 5692510a558..454dfaf1814 100644
> > --- a/drivers/spi/fsl_qspi.c
> > +++ b/drivers/spi/fsl_qspi.c
> > @@ -23,6 +23,7 @@
> >   * Transition to spi-mem in spi-fsl-qspi.c
> >   */
> >  
> > +#include <clk.h>
> >  #include <dm.h>
> >  #include <dm/device_compat.h>
> >  #include <log.h>
> > @@ -716,6 +717,29 @@ static int fsl_qspi_adjust_op_size(struct spi_slave *slave,
> >  	return 0;
> >  }
> >  
> > +static int fsl_qspi_clock_setup(struct fsl_qspi *q)
> > +{
> > +	struct clk_bulk clks;
> > +	int ret;
> > +
> > +	ret = clk_get_bulk(q->dev, &clks);
> > +
> > +	/* Ignore if no DT clock property or no clock framework support */
> > +	if (ret == -ENOENT || ret == -ENOSYS)
> > +		return 0;
> > +
> > +	if (ret) {
> > +		dev_err(q->dev, "Failed to get clocks: %d\n", ret);
> > +		return ret;
> > +	}
> > +
> > +	ret = clk_enable_bulk(&clks);
> > +	if (ret)
> > +		dev_err(q->dev, "Failed to enable clocks: %d\n", ret);
> > +
> > +	return ret;
> > +}
> > +
> >  static int fsl_qspi_default_setup(struct fsl_qspi *q)
> >  {
> >  	void __iomem *base = q->iobase;
> > @@ -829,6 +853,7 @@ static int fsl_qspi_probe(struct udevice *bus)
> >  	dm_bus->max_hz = fdtdec_get_int(blob, node, "spi-max-frequency",
> >  					66000000);
> >  
> > +	fsl_qspi_clock_setup(q);
> >  	fsl_qspi_default_setup(q);
> >  
> >  	return 0;
> > 
> > ---
> > base-commit: c1958b5f6cce03956d309ce422b5d9f819955d4a
> > change-id: 20261120-05-fsl-qspi-clock-e3df6b72ab8a
> > 
> > Best regards,
> > --  
> > Yixun Lan <dlan@kernel.org>
> > 
> 
> With this patch on mainline u-boot main branch from today and the
> intermediary "bsp-spi"[1] or "bsp-nospi"[1] reduced vendor SPL
> previously mentioned, on Sipeed K3 Pico-ITX 32G board as BootROM SPL
> Loader "UART" mode:
> 
> => sf probe
> SF:    Detected w25q64dw with page size 256 Bytes, erase size 4 KiB,
> total 8 MiB
> 
> => sf erase 0 800000
> SF: 8388608 bytes @ 0x0 Erased: OK
> 
> It works as-is, but I think it probably should not work unless matching
> a compatible. Obviously there are valid concerns for SpacemiT K3 SPL
> environment being memory-constrained, but what I'm testing is S-mode
> u-boot main app and this does not seem like the correct approach. Do I
> not understand correctly the driver model?
> 
what do you mean by "not work unless matching a compatible", is
"spacemit,k1-qspi" of fsl_qspi.c the one?  I see no problem of
your testing, such like U-Boot S-mode and "sf" commands

-- 
Yixun Lan (dlan)

  reply	other threads:[~2026-11-22  0:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 14:43 [PATCH] spi: fsl_qspi: Add optional clock support Yixun Lan
2026-11-21 22:14 ` E Shattow
2026-11-22  0:38   ` Yixun Lan [this message]
2026-11-25 12:04     ` E Shattow

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=20261122003813-GKB203137@kernel.org \
    --to=dlan@kernel.org \
    --cc=e@freeshell.de \
    --cc=raymond.mao@riscstar.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.