From: Jerome Brunet <jbrunet@baylibre.com>
To: Miquel Raynal <miquel.raynal@bootlin.com>,
Jacky Huang <ychuang3@nuvoton.com>,
Shan-Chun Hung <schung@nuvoton.com>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
Richard Cochran <richardcochran@gmail.com>,
Arnd Bergmann <arnd@arndb.de>,
Brian Masney <bmasney+clk@redhat.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
Steam Lin <STLin2@winbond.com>,
linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
linux-kernel@vger.kernel.org,
Krzysztof Kozlowski <krzk@kernel.org>,
devicetree@vger.kernel.org,
Miquel Raynal <miquel.raynal@bootlin.com>,
stable@vger.kernel.org
Subject: Re: [PATCH v6 08/12] clk: nuvoton: ma35d1: Retrieve HXT/LXT from DT
Date: Thu, 01 Oct 2026 11:36:33 +0200 [thread overview]
Message-ID: <1j7bk13gpq.fsf@starbuckisacylon.baylibre.com> (raw)
In-Reply-To: <20260930-perso-ma35d1-upstream-clk-v6-8-48937ee6c9bb@bootlin.com>
On mer. 30 sept. 2026 at 19:24, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> HXT and LXT are crystal oscillator inputs of the clock controller, they
> are described in the DT, so retrieve them, in order, and store them in
> their respective HXT/LXT hw table entries.
>
> Since old DTs reference the HXT fixed-clock without naming it and do not
> describe LXT at all, we assume that HXT must be present, and fallback to
> creating a fixed clock for LXT if it is not described (for backward
> compatibility purposes).
>
> The downstream gate clocks can directly use the hw clocks as parents,
> instead of relying on string matching.
>
> Fixes: 691521a367cf ("clk: nuvoton: Add clock driver for ma35d1 clock controller")
> Cc: stable@vger.kernel.org
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
> drivers/clk/nuvoton/clk-ma35d1.c | 43 ++++++++++++++++++++++++++++++++--------
> 1 file changed, 35 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/clk/nuvoton/clk-ma35d1.c b/drivers/clk/nuvoton/clk-ma35d1.c
> index ceebcbd8c18b..d955d79abdd2 100644
> --- a/drivers/clk/nuvoton/clk-ma35d1.c
> +++ b/drivers/clk/nuvoton/clk-ma35d1.c
> @@ -4,6 +4,7 @@
> * Author: Chi-Fang Li <cfli0@nuvoton.com>
> */
>
> +#include <linux/clk.h>
> #include <linux/clk-provider.h>
> #include <linux/mfd/syscon.h>
> #include <linux/module.h>
> @@ -191,6 +192,15 @@ static struct clk_hw *ma35d1_clk_gate(struct device *dev, const char *name, cons
> reg, shift, 0, &ma35d1_lock);
> }
>
> +static struct clk_hw *ma35d1_clk_gate_parent(struct device *dev, const char *name,
> + struct clk_hw *parent,
> + void __iomem *reg, u8 shift)
> +{
> + return devm_clk_hw_register_gate_parent_hw(dev, name, parent,
> + CLK_SET_RATE_PARENT,
> + reg, shift, 0, &ma35d1_lock);
> +}
> +
> static int ma35d1_get_pll_setting(struct device_node *clk_node, u32 *pllmode)
> {
> const char *of_str;
> @@ -215,10 +225,12 @@ static int ma35d1_clocks_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> struct device_node *clk_node = pdev->dev.of_node;
> + struct clk_bulk_data *clks;
> void __iomem *clk_base;
> static struct clk_hw **hws;
> static struct clk_hw_onecell_data *ma35d1_hw_data;
> u32 pllmode[PLL_MAX_NUM];
> + int num_clks;
> int ret;
>
> ma35d1_hw_data = devm_kzalloc(dev,
> @@ -240,12 +252,27 @@ static int ma35d1_clocks_probe(struct platform_device *pdev)
> return -EINVAL;
> }
>
> - hws[HXT] = ma35d1_clk_fixed("hxt", 24000000);
> - hws[HXT_GATE] = ma35d1_clk_gate(dev, "hxt_gate", "hxt",
> - clk_base + REG_CLK_PWRCTL, 0);
> - hws[LXT] = ma35d1_clk_fixed("lxt", 32768);
> - hws[LXT_GATE] = ma35d1_clk_gate(dev, "lxt_gate", "lxt",
> - clk_base + REG_CLK_PWRCTL, 1);
> + num_clks = devm_clk_bulk_get_all(dev, &clks);
> + if (num_clks < 0)
> + return num_clks;
> +
> + if (!num_clks) {
> + dev_err(dev, "missing crystal input clocks\n");
> + return -ENODEV;
> + }
> +
> + hws[HXT] = __clk_get_hw(clks[0].clk);
Don't open code it. use .fw_name
> +
> + if (num_clks > 1)
> + hws[LXT] = __clk_get_hw(clks[1].clk);
> + else
> + /* Old DTs do not describe the low-speed crystal */
> + hws[LXT] = ma35d1_clk_fixed("lxt", 32768);
I'd give it another name so you can clearly see the difference between the
DT one and the manually registered one.
> +
Don't need to open code this either.
provide both .fw_name and .name - CCF will fallback to the name.
When you want to conditionally register the fixed is up to you.
> + hws[HXT_GATE] = ma35d1_clk_gate_parent(dev, "hxt_gate", hws[HXT],
> + clk_base + REG_CLK_PWRCTL, 0);
> + hws[LXT_GATE] = ma35d1_clk_gate_parent(dev, "lxt_gate", hws[LXT],
> + clk_base + REG_CLK_PWRCTL, 1);
> hws[HIRC] = ma35d1_clk_fixed("hirc", 12000000);
> hws[HIRC_GATE] = ma35d1_clk_gate(dev, "hirc_gate", "hirc",
> clk_base + REG_CLK_PWRCTL, 2);
> @@ -632,8 +659,8 @@ static int ma35d1_clocks_probe(struct platform_device *pdev)
> hws[UART16_GATE] = ma35d1_clk_gate(dev, "uart16_gate", "uart16_div",
> clk_base + REG_CLK_APBCLK0, 28);
>
> - hws[RTC_GATE] = ma35d1_clk_gate(dev, "rtc_gate", "lxt",
> - clk_base + REG_CLK_APBCLK0, 29);
> + hws[RTC_GATE] = ma35d1_clk_gate_parent(dev, "rtc_gate", hws[LXT],
> + clk_base + REG_CLK_APBCLK0, 29);
> hws[DDR_GATE] = ma35d1_clk_gate(dev, "ddr_gate", "ddrpll",
> clk_base + REG_CLK_APBCLK0, 30);
>
>
> --
> 2.55.0
>
--
Jerome
next prev parent reply other threads:[~2026-10-01 9:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 17:24 [PATCH v6 00/12] clk: nuvoton: ma35d1: Fix mux parenting and peripheral clock rates Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 01/12] clk: nuvoton: ma35d1: Keep the clock count in the driver Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 02/12] dt-bindings: clock: ma35d1: Document the missing crystal inputs Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 03/12] dt-bindings: clock: ma35d1: Drop CLK_MAX_IDX define Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 04/12] dt-bindings: clock: ma35d1: Add missing WDT/WWDT parent clocks Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 05/12] clk: nuvoton: " Miquel Raynal
2026-10-01 9:44 ` Jerome Brunet
2026-10-01 10:28 ` Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 06/12] clk: nuvoton: ma35d1: Use clk_hw pointers as mux parents Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 07/12] clk: nuvoton: ma35d1: Avoid possible error pointer dereferencing Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 08/12] clk: nuvoton: ma35d1: Retrieve HXT/LXT from DT Miquel Raynal
2026-10-01 9:36 ` Jerome Brunet [this message]
2026-10-01 16:12 ` Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 09/12] clk: nuvoton: ma35d1: Reparent the gates correctly Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 10/12] clk: nuvoton: ma35d1: Reparent SYSPLL correctly Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 11/12] arm64: dts: nuvoton: ma35d1: Drop HXT clock output name Miquel Raynal
2026-09-30 17:24 ` [PATCH v6 12/12] arm64: dts: nuvoton: ma35d1: Add LXT crystal and clock-names Miquel Raynal
2026-10-01 9:53 ` (subset) [PATCH v6 00/12] clk: nuvoton: ma35d1: Fix mux parenting and peripheral clock rates Jerome Brunet
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=1j7bk13gpq.fsf@starbuckisacylon.baylibre.com \
--to=jbrunet@baylibre.com \
--cc=STLin2@winbond.com \
--cc=arnd@arndb.de \
--cc=bmasney+clk@redhat.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jbrunet+clk@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=mturquette@baylibre.com \
--cc=richardcochran@gmail.com \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=schung@nuvoton.com \
--cc=stable@vger.kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=ychuang3@nuvoton.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®