From patchwork Wed Mar 20 11:24:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 13597790 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C937C54E58 for ; Wed, 20 Mar 2024 11:24:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=6aPp9d/+5hBrrAPkVd+mKoVZHqvFpVXosdzEzhVRQ3A=; b=hnPrnVZyzvG/DQ r8lzXBTSd9YP/lhJAqGE448wxeV48n6bMa3IBFIPIBhWyjFWUcy85yRAnOteF0cVCcN67ukgDbpGZ WUKf7/Rn3tA7tbBtMlrc026wfx4VkBKknailBs4sp9+cqaCtKixTUkdpnQ2v71i3kwVAJpzDJ00Mx ub5539oo1BxiJdGPsYjKK1+V2ppNthkxvE2HA0iXjWnDyJW+S+Fn9Nl65gG7OKylnYJl7dlAFm8VF Q15tbbnD2L6EHQuidKqJzTLv8NVX2rRWe5+dDzjQgNx9dWIiWmidwF7x6bw2Xo7pvYKVdM3hEa6pv yWLckzYlPQ3jxPX98Nlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmu3i-0000000Gx37-2rbm; Wed, 20 Mar 2024 11:24:38 +0000 Received: from xavier.telenet-ops.be ([2a02:1800:120:4::f00:14]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmu3f-0000000Gx1q-0myl for linux-riscv@lists.infradead.org; Wed, 20 Mar 2024 11:24:37 +0000 Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed80:76d0:2bff:fec8:549]) by xavier.telenet-ops.be with bizsmtp id 0zQL2C00F0SSLxL01zQLkm; Wed, 20 Mar 2024 12:24:30 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1rmu36-004BPL-BP; Wed, 20 Mar 2024 12:24:20 +0100 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1rmu3Q-000xvc-4T; Wed, 20 Mar 2024 12:24:20 +0100 From: Geert Uytterhoeven To: Emil Renner Berthing , Hal Feng , Michael Turquette , Stephen Boyd , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Krzysztof Kozlowski , Andy Shevchenko Cc: linux-clk@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2] clk: starfive: jh7100: Use clk_hw for external input clocks Date: Wed, 20 Mar 2024 12:24:15 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240320_042435_396736_5C2A7917 X-CRM114-Status: GOOD ( 17.65 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The Starfive JH7100 clock driver does not use the DT "clocks" property to find the external main input clock, but instead relies on the name of the actual clock provider ("osc_sys"). This is fragile, and caused breakage when sanitizing clock node names in DTS. Fix this by obtaining the external main input clock using devm_clk_get(), and passing the returned clk_hw object to devm_clk_hw_register_fixed_factor_parent_hw(). While name-based look-up of the other external input clocks works as-is, convert them to a similar clk_hw-based scheme to increase uniformity, and to decrease the number of name-based look-ups. Fixes: f03606470886 ("riscv: dts: starfive: replace underscores in node names") Fixes: 4210be668a09ee20 ("clk: starfive: Add JH7100 clock generator driver") Signed-off-by: Geert Uytterhoeven Reviewed-by: Samuel Holland --- After this is applied, the workaround in commit 7921e231f85a349d ("riscv: dts: starfive: jh7100: fix root clock names") can be reverted. This is v2 of "[PATCH] clk: starfive: jh7100: Use provided clocks instead of hardcoded names" https://lore.kernel.org/r/898aa0925a9598d44721d00145015b215434cb3b.1710414195.git.geert@linux-m68k.org/ v2: - Use devm_clk_hw_register_fixed_factor_parent_hw(), - Drop no longer needed local osc_sys name. --- drivers/clk/starfive/clk-starfive-jh7100.c | 48 ++++++++++++++-------- drivers/clk/starfive/clk-starfive-jh71x0.h | 1 + 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/drivers/clk/starfive/clk-starfive-jh7100.c b/drivers/clk/starfive/clk-starfive-jh7100.c index 0342db24c27e10df..ead5a7b14bab9045 100644 --- a/drivers/clk/starfive/clk-starfive-jh7100.c +++ b/drivers/clk/starfive/clk-starfive-jh7100.c @@ -7,6 +7,7 @@ * Copyright (C) 2021 Emil Renner Berthing */ +#include #include #include #include @@ -18,10 +19,18 @@ #include "clk-starfive-jh71x0.h" /* external clocks */ -#define JH7100_CLK_OSC_SYS (JH7100_CLK_END + 0) -#define JH7100_CLK_OSC_AUD (JH7100_CLK_END + 1) -#define JH7100_CLK_GMAC_RMII_REF (JH7100_CLK_END + 2) -#define JH7100_CLK_GMAC_GR_MII_RX (JH7100_CLK_END + 3) +enum { + EXT_CLK_OSC_SYS, + EXT_CLK_OSC_AUD, + EXT_CLK_GMAC_RMII_REF, + EXT_CLK_GMAC_GR_MII_RX, + EXT_NUM_CLKS +}; + +#define JH7100_CLK_OSC_SYS (JH7100_CLK_END + EXT_CLK_OSC_SYS) +#define JH7100_CLK_OSC_AUD (JH7100_CLK_END + EXT_CLK_OSC_AUD) +#define JH7100_CLK_GMAC_RMII_REF (JH7100_CLK_END + EXT_CLK_GMAC_RMII_REF) +#define JH7100_CLK_GMAC_GR_MII_RX (JH7100_CLK_END + EXT_CLK_GMAC_GR_MII_RX) static const struct jh71x0_clk_data jh7100_clk_data[] __initconst = { JH71X0__MUX(JH7100_CLK_CPUNDBUS_ROOT, "cpundbus_root", 0, 4, @@ -284,8 +293,11 @@ static struct clk_hw *jh7100_clk_get(struct of_phandle_args *clkspec, void *data static int __init clk_starfive_jh7100_probe(struct platform_device *pdev) { + static const char *jh7100_ext_clk[EXT_NUM_CLKS] = + { "osc_sys", "osc_aud", "gmac_rmii_ref", "gmac_gr_mii_rxclk" }; struct jh71x0_clk_priv *priv; unsigned int idx; + struct clk *clk; int ret; priv = devm_kzalloc(&pdev->dev, struct_size(priv, reg, JH7100_CLK_PLL0_OUT), GFP_KERNEL); @@ -298,13 +310,21 @@ static int __init clk_starfive_jh7100_probe(struct platform_device *pdev) if (IS_ERR(priv->base)) return PTR_ERR(priv->base); - priv->pll[0] = devm_clk_hw_register_fixed_factor(priv->dev, "pll0_out", - "osc_sys", 0, 40, 1); + for (idx = 0; idx < EXT_NUM_CLKS; idx++) { + clk = devm_clk_get(&pdev->dev, jh7100_ext_clk[idx]); + if (IS_ERR(clk)) + return PTR_ERR(clk); + + priv->ext[idx] = __clk_get_hw(clk); + } + + priv->pll[0] = devm_clk_hw_register_fixed_factor_parent_hw(priv->dev, + "pll0_out", priv->ext[EXT_CLK_OSC_SYS], 0, 40, 1); if (IS_ERR(priv->pll[0])) return PTR_ERR(priv->pll[0]); - priv->pll[1] = devm_clk_hw_register_fixed_factor(priv->dev, "pll1_out", - "osc_sys", 0, 64, 1); + priv->pll[1] = devm_clk_hw_register_fixed_factor_parent_hw(priv->dev, + "pll1_out", priv->ext[EXT_CLK_OSC_SYS], 0, 64, 1); if (IS_ERR(priv->pll[1])) return PTR_ERR(priv->pll[1]); @@ -331,16 +351,10 @@ static int __init clk_starfive_jh7100_probe(struct platform_device *pdev) if (pidx < JH7100_CLK_PLL0_OUT) parents[i].hw = &priv->reg[pidx].hw; - else if (pidx < JH7100_CLK_END) + else if (pidx < JH7100_CLK_OSC_SYS) parents[i].hw = priv->pll[pidx - JH7100_CLK_PLL0_OUT]; - else if (pidx == JH7100_CLK_OSC_SYS) - parents[i].fw_name = "osc_sys"; - else if (pidx == JH7100_CLK_OSC_AUD) - parents[i].fw_name = "osc_aud"; - else if (pidx == JH7100_CLK_GMAC_RMII_REF) - parents[i].fw_name = "gmac_rmii_ref"; - else if (pidx == JH7100_CLK_GMAC_GR_MII_RX) - parents[i].fw_name = "gmac_gr_mii_rxclk"; + else if (pidx <= JH7100_CLK_GMAC_GR_MII_RX) + parents[i].hw = priv->ext[pidx - JH7100_CLK_OSC_SYS]; } clk->hw.init = &init; diff --git a/drivers/clk/starfive/clk-starfive-jh71x0.h b/drivers/clk/starfive/clk-starfive-jh71x0.h index 23e052fc15495c41..4f46939179cd7418 100644 --- a/drivers/clk/starfive/clk-starfive-jh71x0.h +++ b/drivers/clk/starfive/clk-starfive-jh71x0.h @@ -115,6 +115,7 @@ struct jh71x0_clk_priv { struct device *dev; void __iomem *base; struct clk_hw *pll[3]; + struct clk_hw *ext[4]; struct jh71x0_clk reg[]; };