All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yao Zi <me@ziyao.cc>
To: Hiago De Franco <hfranco@baylibre.com>,
	u-boot@lists.u-boot-project.org, Yao Zi <me@ziyao.cc>
Cc: Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>,
	Alper Nebi Yasak <alpernebiyasak@gmail.com>,
	Marek Vasut <marex@nabladev.com>,
	Tim Ouyang <tim609@andestech.com>,
	Leo Liang <leo.liang@sifive.com>,
	Kongyang Liu <seashell11234455@gmail.com>,
	Neha Malcom Francis <n-francis@ti.com>, Bin Liu <b-liu@ti.com>,
	Quentin Schulz <quentin.schulz@cherry.de>,
	Andrei Lalaev <andrey.lalaev@gmail.com>,
	Zhuxu Ran <zhuxu_ran@zohomail.com>, Udit Kumar <u-kumar1@ti.com>
Subject: Re: [PATCH 5/8] board: sophgo: milkv_duo: initialize PLLs in SPL
Date: Wed, 4 Nov 2026 04:19:33 +0000	[thread overview]
Message-ID: <auqyVVLqnKxPadXk@pie> (raw)
In-Reply-To: <20261021-milkv-duo-spl-v1-5-ee7618860237@baylibre.com>

On Wed, Oct 21, 2026 at 09:54:21AM -0300, Hiago De Franco wrote:
> DDR training runs from the XTAL, before the PLLs are configured, so add
> PLL setup after it in board_init_f().
> 
> The sequence bypasses all clocks to the XTAL, reprograms the APLL,
> DISPPLL, CAM0PLL, CAM1PLL, MIPIMPLL, MPLL and TPLL synthesizers and
> their derived dividers, waits for lock, then switches every clock from
> the XTAL bypass to its PLL source. It is ported from the Sophgo FSBL
> (plat/cv180x/platform.c), https://github.com/sophgo/fsbl.

I'm worried about code duplication since we already have a driver with
more features under clk/sophgo.

I think this setup work doesn't have to be done in the SPL stage? If so,
I'll suggest delaying the work to proper U-Boot or even the kernel, with
assigned-clock-rates/assigned-clock-parents for re-using existing clock
driver.

> Signed-off-by: Hiago De Franco <hfranco@baylibre.com>
> ---
>  board/sophgo/milkv_duo/spl.c | 123 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 123 insertions(+)
> 
> diff --git a/board/sophgo/milkv_duo/spl.c b/board/sophgo/milkv_duo/spl.c
> index 3db50df0615..8b2dc2756ae 100644
> --- a/board/sophgo/milkv_duo/spl.c
> +++ b/board/sophgo/milkv_duo/spl.c

...

> +static void cv18xx_pll_init(void)
> +{
> +	int i;
> +
> +	/* Run everything from the XTAL while the PLLs are reprogrammed */
> +	writel(0xffffffff, clkgen_reg(CLK_BYP_0));
> +	writel(0x0000003f, clkgen_reg(CLK_BYP_1));
> +
> +	/* MIPIMPLL = 900 MHz */
> +	writel(0x05488101, clkgen_reg(MIPIMPLL_CSR));
> +
> +	writel(0x3f, clkgen_reg(PLL_G2_SSC_SYN_CTRL));
> +	for (i = 0; i < ARRAY_SIZE(cv18xx_pll_csr); i++) {
> +		writel(cv18xx_pll_syn_set[i],
> +		       clkgen_reg(APLL_SSC_SYN_SET + 0x10 * i));
> +		clrsetbits_le32(clkgen_reg(APLL_SSC_SYN_CTRL + 0x10 * i),
> +				SSC_SYN_CTRL_BYPASS, SSC_SYN_CTRL_SW_UP);
> +		writel(cv18xx_pll_csr[i], clkgen_reg(APLL0_CSR + 4 * i));
> +	}
> +
> +	/* Power up the PLLs */
> +	clrbits_le32(clkgen_reg(PLL_G2_CTRL), PLL_G2_CTRL_PD);
> +
> +	/* MPLL = TPLL = 850 MHz */
> +	writel(0x00448101, clkgen_reg(MPLL_CSR));
> +	writel(0x00448101, clkgen_reg(TPLL_CSR));
> +
> +	for (i = 0; i < ARRAY_SIZE(cv18xx_clk_divs); i++)
> +		writel(cv18xx_clk_divs[i].val,
> +		       clkgen_reg(cv18xx_clk_divs[i].off));
> +
> +	clrbits_le32(clkgen_reg(MIPIMPLL_D3_PD), MIPIMPLL_D3_PD_PD);
> +	clrbits_le32(clkgen_reg(CAM0PLL_D2_PD), CAM0PLL_D2_PD_PD);
> +
> +	/* Wait for the PLLs to lock */
> +	udelay(200);

If I read the datasheet correctly, the pll_g2_status register have bits
indicating PLL's locking status. We should probably poll for these bits
instead.

> +	/*
> +	 * C906 clocks from the *_0 dividers, then switch every clock from the
> +	 * XTAL to its PLL source.
> +	 */
> +	writel(CLK_SEL_0_C906_0 | CLK_SEL_0_C906_1, clkgen_reg(CLK_SEL_0));
> +	writel(0, clkgen_reg(CLK_BYP_0));
> +	writel(0, clkgen_reg(CLK_BYP_1));
> +}

Regards,
Yao Zi

  reply	other threads:[~2026-11-04  4:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 12:54 [PATCH 0/8] riscv: sophgo: add SPL support for the Milk-V Duo Hiago De Franco
2026-10-21 12:54 ` [PATCH 1/8] binman: add Sophgo CV18xx FIP entry type Hiago De Franco
2026-11-03 14:54   ` Simon Glass
2026-10-21 12:54 ` [PATCH 2/8] riscv: cv1800b: add SPL support Hiago De Franco
2026-11-03 13:53   ` Yao Zi
2026-10-21 12:54 ` [PATCH 3/8] ram: sophgo: add CV180x DDR2 driver Hiago De Franco
2026-10-21 12:54 ` [PATCH 4/8] board: sophgo: milkv_duo: add SPL support Hiago De Franco
2026-11-04  3:56   ` Yao Zi
2026-10-21 12:54 ` [PATCH 5/8] board: sophgo: milkv_duo: initialize PLLs in SPL Hiago De Franco
2026-11-04  4:19   ` Yao Zi [this message]
2026-10-21 12:54 ` [PATCH 6/8] board: sophgo: milkv_duo: enable RTC power and reset Hiago De Franco
2026-11-03 17:31   ` João Paulo Gonçalves
2026-11-04  3:59     ` Yao Zi
2026-10-21 12:54 ` [PATCH 7/8] doc: board: sophgo: milkv_duo: update documentation Hiago De Franco
2026-10-21 12:54 ` [PATCH 8/8] doc: board: sophgo: milkv_duo: document the SPL boot flow Hiago De Franco
2026-10-25 17:33 ` [PATCH 0/8] riscv: sophgo: add SPL support for the Milk-V Duo Andrei Lalaev

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=auqyVVLqnKxPadXk@pie \
    --to=me@ziyao.cc \
    --cc=alpernebiyasak@gmail.com \
    --cc=andrey.lalaev@gmail.com \
    --cc=b-liu@ti.com \
    --cc=hfranco@baylibre.com \
    --cc=leo.liang@sifive.com \
    --cc=marex@nabladev.com \
    --cc=n-francis@ti.com \
    --cc=quentin.schulz@cherry.de \
    --cc=seashell11234455@gmail.com \
    --cc=sjg@chromium.org \
    --cc=tim609@andestech.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    --cc=u-kumar1@ti.com \
    --cc=zhuxu_ran@zohomail.com \
    /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.