[v2] clk: starfive: jh7110-sys: Fix lower rate of CPUfreq by setting PLL0 rate to 1.5GHz
Message ID | 20230821152915.208366-1-xingyu.wu@starfivetech.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp3122033vqi; Mon, 21 Aug 2023 09:31:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHLLdFa3K2hiWpghRFbZu7gdkFhDP3nptL3zz3/uKOqvcyMHeIDWSCqSBiR3vRpPDYYSiQS X-Received: by 2002:a05:6e02:924:b0:34b:50cd:e86d with SMTP id o4-20020a056e02092400b0034b50cde86dmr8355053ilt.8.1692635471175; Mon, 21 Aug 2023 09:31:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692635471; cv=none; d=google.com; s=arc-20160816; b=FsOYcLgFV/oxnUiiZMnoOvR1oxyj1OheTDiGxK2jarvUnYkXzNMeZbhc+k4/JERl7s xp4sp9uA9jCnKjXohyAZfGpLpwazYgMm4RwaUn5Xi0VUH22XVCfYGS2RkS0n7LOgAKd2 yKcqvIpH91gw+CiJR2FBCtHcwgXQ1f9DdsvWvAHy4zC/TJxtxbnJmwg5eA9ixGI/IdQc uRfgTTLdDKMUcPGh8pUAo39vwJdYPdP6odNymOi6IZY3k6vdfB+BObxYy8KfAb/SRR7I cV5e7MUq+6VVwmgdTN9futp5LxD3MkIeQ9nLVxMrEULpBdSOwnbfoteKAu7VtVB6jJBC SAvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=JEMunl5Zj2CE4mGWAtsIb6m9EPrtKWzXlZUNnn1uqHM=; fh=nOSKHTZN0YU28neYxTW9TZNbz7Vz9SZ3bWNRr6EDkNg=; b=uO/frBzAwLeM332v5npu+Ecwr7Mo8FvSp1/h6w/NQOToe8jXSV6ad2TUXt0Mi0X7R4 +WiqJIKA3mpnmUyh05q6xQW2RTcxf7qv19CuK+nPtZbmmGnwm7T6S1IgHUILFGi1bJVL SrC+/RfVb0o3+8qJdw3HrW3e9cN5QN9P7n8YuZTyMNewp3um424vE5OXFhsufXczSbxs 1EqoWpuXXgEqF99fD1laD3KwEEcW7UvizXbbMpChcipMvmo8/EQLRJwdUeMXIMwFCde/ 0J2TDpBFDLagwe0Z2VVdUSXLcF+thIOIJwXxpT6mH0aPpiWkkBgZxIYqEFJ5yu7b2N7t nzjQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n127-20020a632785000000b0056534e3aeeasi3215000pgn.474.2023.08.21.09.30.51; Mon, 21 Aug 2023 09:31:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233027AbjHUP3X convert rfc822-to-8bit (ORCPT <rfc822;chiang.bai@gmail.com> + 99 others); Mon, 21 Aug 2023 11:29:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233390AbjHUP3W (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 21 Aug 2023 11:29:22 -0400 Received: from ex01.ufhost.com (ex01.ufhost.com [61.152.239.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DFC0E2; Mon, 21 Aug 2023 08:29:20 -0700 (PDT) Received: from EXMBX166.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX166", Issuer "EXMBX166" (not verified)) by ex01.ufhost.com (Postfix) with ESMTP id E302A24E2AB; Mon, 21 Aug 2023 23:29:16 +0800 (CST) Received: from EXMBX061.cuchost.com (172.16.6.61) by EXMBX166.cuchost.com (172.16.6.76) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 21 Aug 2023 23:29:17 +0800 Received: from localhost.localdomain (113.72.145.205) by EXMBX061.cuchost.com (172.16.6.61) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 21 Aug 2023 23:29:16 +0800 From: Xingyu Wu <xingyu.wu@starfivetech.com> To: Michael Turquette <mturquette@baylibre.com>, Stephen Boyd <sboyd@kernel.org>, Conor Dooley <conor@kernel.org>, Emil Renner Berthing <emil.renner.berthing@canonical.com> CC: Hal Feng <hal.feng@starfivetech.com>, Xingyu Wu <xingyu.wu@starfivetech.com>, <linux-kernel@vger.kernel.org>, <linux-clk@vger.kernel.org> Subject: [PATCH v2] clk: starfive: jh7110-sys: Fix lower rate of CPUfreq by setting PLL0 rate to 1.5GHz Date: Mon, 21 Aug 2023 23:29:15 +0800 Message-ID: <20230821152915.208366-1-xingyu.wu@starfivetech.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [113.72.145.205] X-ClientProxiedBy: EXCAS066.cuchost.com (172.16.6.26) To EXMBX061.cuchost.com (172.16.6.61) X-YovoleRuleAgent: yovoleflag Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774856931895965292 X-GMAIL-MSGID: 1774856931895965292 |
Series |
[v2] clk: starfive: jh7110-sys: Fix lower rate of CPUfreq by setting PLL0 rate to 1.5GHz
|
|
Commit Message
Xingyu Wu
Aug. 21, 2023, 3:29 p.m. UTC
CPUfreq supports 4 cpu frequency loads on 375/500/750/1500MHz. But now PLL0 rate is 1GHz and the cpu frequency loads become 333/500/500/1000MHz in fact. So PLL0 rate should be set to 1.5GHz. Change the parent of cpu_root clock and the divider of cpu_core before the setting. Reviewed-by: Hal Feng <hal.feng@starfivetech.com> Fixes: e2c510d6d630 ("riscv: dts: starfive: Add cpu scaling for JH7110 SoC") Signed-off-by: Xingyu Wu <xingyu.wu@starfivetech.com> --- Hi Stephen and Emil, This patch fixes the issue about lower rate of CPUfreq[1] and sets PLL0 rate to 1.5GHz. In order not to affect the cpu operation, the cpu_root's parent clock should be changed first. And the divider of the cpu_core clock should be set to 2 so they won't crash when setting 1.5GHz without voltage regulation. [1]: https://github.com/starfive-tech/VisionFive2/issues/55 This patch is based on linux-next(20230818) which has merge PLL driver on the StarFive JH7110 SoC. Thanks, Xingyu Wu --- .../clk/starfive/clk-starfive-jh7110-sys.c | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
Comments
On 2023/8/21 23:38, Emil Renner Berthing wrote: > On Mon, 21 Aug 2023 at 17:29, Xingyu Wu <xingyu.wu@starfivetech.com> wrote: >> >> CPUfreq supports 4 cpu frequency loads on 375/500/750/1500MHz. >> But now PLL0 rate is 1GHz and the cpu frequency loads become >> 333/500/500/1000MHz in fact. >> >> So PLL0 rate should be set to 1.5GHz. Change the parent of cpu_root clock >> and the divider of cpu_core before the setting. >> >> Reviewed-by: Hal Feng <hal.feng@starfivetech.com> >> Fixes: e2c510d6d630 ("riscv: dts: starfive: Add cpu scaling for JH7110 SoC") >> Signed-off-by: Xingyu Wu <xingyu.wu@starfivetech.com> >> --- >> >> Hi Stephen and Emil, >> >> This patch fixes the issue about lower rate of CPUfreq[1] >> and sets PLL0 rate to 1.5GHz. In order not to affect the cpu >> operation, the cpu_root's parent clock should be changed first. >> And the divider of the cpu_core clock should be set to 2 so they >> won't crash when setting 1.5GHz without voltage regulation. > > Hi Xingyu, > > It sounds like this is something the driver should handle > automatically whenever clk_set_rate() is called on the PLL0 clock. > Then we should be able to use regular assigned-clocks / > assigned-clock-rates stanzas in the device tree instead of having this > 1.5GHz rate hard-coded in the driver. > > /Emil Hi Emil, The frequency of PLL0 is set according to this process to avoid crash: 1. The divider of the cpu_core clock should be set to 2 if PLL0 is set to 1.5GHz. 2. The parent of cpu_root is changed from pll0 to osc. 3. The PLL0 is set to 1.5GHz. 4. The parent of cpu_root is changed from osc to pll0 back. I don't think assigned-clock-rates/assigned-clock-parents can do such a complicated job. Best regards, Xingyu Wu > >> [1]: https://github.com/starfive-tech/VisionFive2/issues/55 >> >> This patch is based on linux-next(20230818) which has merge PLL driver >> on the StarFive JH7110 SoC. >> >> Thanks, >> Xingyu Wu >> >> --- >> .../clk/starfive/clk-starfive-jh7110-sys.c | 47 ++++++++++++++++++- >> 1 file changed, 46 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/clk/starfive/clk-starfive-jh7110-sys.c b/drivers/clk/starfive/clk-starfive-jh7110-sys.c >> index 3884eff9fe93..b6b9e967dfc7 100644 >> --- a/drivers/clk/starfive/clk-starfive-jh7110-sys.c >> +++ b/drivers/clk/starfive/clk-starfive-jh7110-sys.c >> @@ -501,7 +501,52 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev) >> if (ret) >> return ret; >> >> - return jh7110_reset_controller_register(priv, "rst-sys", 0); >> + ret = jh7110_reset_controller_register(priv, "rst-sys", 0); >> + if (ret) >> + return ret; >> + >> + /* >> + * Set PLL0 rate to 1.5GHz >> + * In order to not affect the cpu when the PLL0 rate is changing, >> + * we need to switch the parent of cpu_root clock to osc clock first, >> + * and then switch back after setting the PLL0 rate. >> + */ >> + pllclk = clk_get(priv->dev, "pll0_out"); >> + if (!IS_ERR(pllclk)) { >> + struct clk *osc = clk_get(&pdev->dev, "osc"); >> + struct clk *cpu_root = priv->reg[JH7110_SYSCLK_CPU_ROOT].hw.clk; >> + struct clk *cpu_core = priv->reg[JH7110_SYSCLK_CPU_CORE].hw.clk; >> + >> + if (IS_ERR(osc)) { >> + clk_put(pllclk); >> + return PTR_ERR(osc); >> + } >> + >> + /* >> + * CPU need voltage regulation by CPUfreq if set 1.5GHz. >> + * So in this driver, cpu_core need to be set the divider to be 2 first >> + * and will be 750M after setting parent. >> + */ >> + ret = clk_set_rate(cpu_core, clk_get_rate(cpu_core) / 2); >> + if (ret) >> + goto failed_set; >> + >> + ret = clk_set_parent(cpu_root, osc); >> + if (ret) >> + goto failed_set; >> + >> + ret = clk_set_rate(pllclk, 1500000000); >> + if (ret) >> + goto failed_set; >> + >> + ret = clk_set_parent(cpu_root, pllclk); >> + >> +failed_set: >> + clk_put(pllclk); >> + clk_put(osc); >> + } >> + >> + return ret; >> } >> >> static const struct of_device_id jh7110_syscrg_match[] = { >> -- >> 2.25.1 >>
On 2023/8/22 16:56, Emil Renner Berthing wrote: > On Tue, 22 Aug 2023 at 05:33, Xingyu Wu <xingyu.wu@starfivetech.com> wrote: >> On 2023/8/21 23:38, Emil Renner Berthing wrote: >> > On Mon, 21 Aug 2023 at 17:29, Xingyu Wu <xingyu.wu@starfivetech.com> wrote: >> >> >> >> CPUfreq supports 4 cpu frequency loads on 375/500/750/1500MHz. >> >> But now PLL0 rate is 1GHz and the cpu frequency loads become >> >> 333/500/500/1000MHz in fact. >> >> >> >> So PLL0 rate should be set to 1.5GHz. Change the parent of cpu_root clock >> >> and the divider of cpu_core before the setting. >> >> >> >> Reviewed-by: Hal Feng <hal.feng@starfivetech.com> >> >> Fixes: e2c510d6d630 ("riscv: dts: starfive: Add cpu scaling for JH7110 SoC") >> >> Signed-off-by: Xingyu Wu <xingyu.wu@starfivetech.com> >> >> --- >> >> >> >> Hi Stephen and Emil, >> >> >> >> This patch fixes the issue about lower rate of CPUfreq[1] >> >> and sets PLL0 rate to 1.5GHz. In order not to affect the cpu >> >> operation, the cpu_root's parent clock should be changed first. >> >> And the divider of the cpu_core clock should be set to 2 so they >> >> won't crash when setting 1.5GHz without voltage regulation. >> > >> > Hi Xingyu, >> > >> > It sounds like this is something the driver should handle >> > automatically whenever clk_set_rate() is called on the PLL0 clock. >> > Then we should be able to use regular assigned-clocks / >> > assigned-clock-rates stanzas in the device tree instead of having this >> > 1.5GHz rate hard-coded in the driver. >> > >> > /Emil >> >> Hi Emil, >> >> The frequency of PLL0 is set according to this process to avoid crash: >> 1. The divider of the cpu_core clock should be set to 2 if PLL0 is set to 1.5GHz. >> 2. The parent of cpu_root is changed from pll0 to osc. >> 3. The PLL0 is set to 1.5GHz. >> 4. The parent of cpu_root is changed from osc to pll0 back. >> I don't think assigned-clock-rates/assigned-clock-parents can do such a complicated job. > > Right, but what I'm saying is that if calling clk_set_rate() on the > PLL0 clock causes a crash, that sounds like a bug in the driver. If > you fix that bug, and make clk_set_rate() on the PLL0 clock do the > procedure above when changing the rate, then the PLL0 clock can work > just like any other clock and assigned-clock-rates would work. > > /Emil Yeah, if fix this bug, I should add there steps when setting rate in the PLL clock driver. But how to get and use the clocks of cpu_root and cpu_core in the PLL driver? It seem to be only two ways, clk_get() or ioremap(). If use clk_get(), the pll node should add syscrg clocks. It shows that the PLL driver depends on the SYSCRG driver, which seems confusing because normally the syscrg depends on the pll. Do you have a better suggestion? Thanks. Xingyu Wu > >> > >> >> [1]: https://github.com/starfive-tech/VisionFive2/issues/55 >> >> >> >> This patch is based on linux-next(20230818) which has merge PLL driver >> >> on the StarFive JH7110 SoC. >> >> >> >> Thanks, >> >> Xingyu Wu >> >> >> >> --- >> >> .../clk/starfive/clk-starfive-jh7110-sys.c | 47 ++++++++++++++++++- >> >> 1 file changed, 46 insertions(+), 1 deletion(-) >> >> >> >> diff --git a/drivers/clk/starfive/clk-starfive-jh7110-sys.c b/drivers/clk/starfive/clk-starfive-jh7110-sys.c >> >> index 3884eff9fe93..b6b9e967dfc7 100644 >> >> --- a/drivers/clk/starfive/clk-starfive-jh7110-sys.c >> >> +++ b/drivers/clk/starfive/clk-starfive-jh7110-sys.c >> >> @@ -501,7 +501,52 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev) >> >> if (ret) >> >> return ret; >> >> >> >> - return jh7110_reset_controller_register(priv, "rst-sys", 0); >> >> + ret = jh7110_reset_controller_register(priv, "rst-sys", 0); >> >> + if (ret) >> >> + return ret; >> >> + >> >> + /* >> >> + * Set PLL0 rate to 1.5GHz >> >> + * In order to not affect the cpu when the PLL0 rate is changing, >> >> + * we need to switch the parent of cpu_root clock to osc clock first, >> >> + * and then switch back after setting the PLL0 rate. >> >> + */ >> >> + pllclk = clk_get(priv->dev, "pll0_out"); >> >> + if (!IS_ERR(pllclk)) { >> >> + struct clk *osc = clk_get(&pdev->dev, "osc"); >> >> + struct clk *cpu_root = priv->reg[JH7110_SYSCLK_CPU_ROOT].hw.clk; >> >> + struct clk *cpu_core = priv->reg[JH7110_SYSCLK_CPU_CORE].hw.clk; >> >> + >> >> + if (IS_ERR(osc)) { >> >> + clk_put(pllclk); >> >> + return PTR_ERR(osc); >> >> + } >> >> + >> >> + /* >> >> + * CPU need voltage regulation by CPUfreq if set 1.5GHz. >> >> + * So in this driver, cpu_core need to be set the divider to be 2 first >> >> + * and will be 750M after setting parent. >> >> + */ >> >> + ret = clk_set_rate(cpu_core, clk_get_rate(cpu_core) / 2); >> >> + if (ret) >> >> + goto failed_set; >> >> + >> >> + ret = clk_set_parent(cpu_root, osc); >> >> + if (ret) >> >> + goto failed_set; >> >> + >> >> + ret = clk_set_rate(pllclk, 1500000000); >> >> + if (ret) >> >> + goto failed_set; >> >> + >> >> + ret = clk_set_parent(cpu_root, pllclk); >> >> + >> >> +failed_set: >> >> + clk_put(pllclk); >> >> + clk_put(osc); >> >> + } >> >> + >> >> + return ret; >> >> } >> >> >> >> static const struct of_device_id jh7110_syscrg_match[] = { >> >> -- >> >> 2.25.1 >> >> >>
diff --git a/drivers/clk/starfive/clk-starfive-jh7110-sys.c b/drivers/clk/starfive/clk-starfive-jh7110-sys.c index 3884eff9fe93..b6b9e967dfc7 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-sys.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-sys.c @@ -501,7 +501,52 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev) if (ret) return ret; - return jh7110_reset_controller_register(priv, "rst-sys", 0); + ret = jh7110_reset_controller_register(priv, "rst-sys", 0); + if (ret) + return ret; + + /* + * Set PLL0 rate to 1.5GHz + * In order to not affect the cpu when the PLL0 rate is changing, + * we need to switch the parent of cpu_root clock to osc clock first, + * and then switch back after setting the PLL0 rate. + */ + pllclk = clk_get(priv->dev, "pll0_out"); + if (!IS_ERR(pllclk)) { + struct clk *osc = clk_get(&pdev->dev, "osc"); + struct clk *cpu_root = priv->reg[JH7110_SYSCLK_CPU_ROOT].hw.clk; + struct clk *cpu_core = priv->reg[JH7110_SYSCLK_CPU_CORE].hw.clk; + + if (IS_ERR(osc)) { + clk_put(pllclk); + return PTR_ERR(osc); + } + + /* + * CPU need voltage regulation by CPUfreq if set 1.5GHz. + * So in this driver, cpu_core need to be set the divider to be 2 first + * and will be 750M after setting parent. + */ + ret = clk_set_rate(cpu_core, clk_get_rate(cpu_core) / 2); + if (ret) + goto failed_set; + + ret = clk_set_parent(cpu_root, osc); + if (ret) + goto failed_set; + + ret = clk_set_rate(pllclk, 1500000000); + if (ret) + goto failed_set; + + ret = clk_set_parent(cpu_root, pllclk); + +failed_set: + clk_put(pllclk); + clk_put(osc); + } + + return ret; } static const struct of_device_id jh7110_syscrg_match[] = {