From patchwork Wed Apr 10 03:31:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xingyu Wu X-Patchwork-Id: 13623502 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 40532CD128A for ; Wed, 10 Apr 2024 03:32:24 +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:References:In-Reply-To: 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: List-Owner; bh=PnyWcOKRD+nXabyfPyAjJeEc0N0ddyOTWimtKGsZfPw=; b=3rUFI7SNE1o3Vs v+sOlvZCcRwOvrG+rbv4lcN+bbgKoMwO6aAMfV70U4hqMvC24uSche8rh+obUHwxFatTd5l26e3du EzwVmCT0npV1ZnAsoJ83NaHOU53rGhO1Q2Cydbq5wWC6R5vGBnNH15uRrGICodtJEuP0E8D7X+vD0 Oo67KY86siTks/CiOeAErtDdlFv6Vtf/YsTM/6JCbRh9WSC6qbb6AbUT4wB2M29CgZLTfY9oSS/0u kvEeF12NJxBWVXob5Jnjc/4gSwMP3edtARGvCsCsLcjnjsou8oXwUgvZHUJBYfw5JIdUdF4ldIveV XgAISe66FYP2ZmXqhQzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruOgz-00000004smA-0d9H; Wed, 10 Apr 2024 03:32:09 +0000 Received: from mail-sh0chn02on2071b.outbound.protection.partner.outlook.cn ([2406:e500:4420:2::71b] helo=CHN02-SH0-obe.outbound.protection.partner.outlook.cn) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1ruOgv-00000004skU-1qwx for linux-riscv@lists.infradead.org; Wed, 10 Apr 2024 03:32:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XYAjkpgZ8VxAvp0heh2KTKdSthCosc20xmJCzkSRTYtfNj4mH/bkkQuxE0LG9RIEN6LD4CADJ4VPo4q1jwJyGBU30ZbRCo0ZtdEcwTEWjoIOlc+oXnLClj6HblsdIJ72zhw3HAYmwmJrnkBLLYQMvP8/yceJ8diGHTP+Np3pWlD9zZ3YEk+fn6m3T+uzk1b8qrtj2LitAFLdHImQOS50bi7isZVM1BYqKPLBa1H2Apb8JGaz53lN0/hir8mguIYy363FiIkqy+5p4Xe/52nPLCj8lzQZrG4VFgHCP7L9Cvxlyn0VlZXEJo0yaj1/99S0VTv2OLw3isgTQpGTlW0KJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=M/5MChuanEqmbBcI5dd7l05/xpiV8Fdo3YJTMWDUkzk=; b=Qd/mGYJz0Cd0NjbCQ507uomNfB7mlU0PA/VWFrLbSsUWeyJwqku3XL5EUplCx1X1+maq9IzcxJL/BkAjmcm1f3VY2DF5t/ubZTvmgGa/b/dOo9dowzFFf186YzWndtxjvpZhc0W7WJ46AuOIp8r3oWy2VgiKYYrZRa70Cum3GaaRZpJ0CFyNl2yY9FE1cFjtuAMA1wF0duSBv99fWhGaGetQEn+MZVGqJGOHuFZyRby5nujY9+V0O1ggAp+W/YGs4XrRF207Iqp5e5z2w4G4BUG911Axzv82GTBokyaFCfc60rwXI33J/cBJ36u71/ITUIYiWqrpCIpW3Y5LXQSaQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=starfivetech.com; dmarc=pass action=none header.from=starfivetech.com; dkim=pass header.d=starfivetech.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=starfivetech.com; Received: from NTZPR01MB0956.CHNPR01.prod.partner.outlook.cn (2406:e500:c510:8::10) by NTZPR01MB1132.CHNPR01.prod.partner.outlook.cn (2406:e500:c510:8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Wed, 10 Apr 2024 03:31:56 +0000 Received: from NTZPR01MB0956.CHNPR01.prod.partner.outlook.cn ([fe80::6174:711d:d93:87c9]) by NTZPR01MB0956.CHNPR01.prod.partner.outlook.cn ([fe80::6174:711d:d93:87c9%4]) with mapi id 15.20.7409.053; Wed, 10 Apr 2024 03:31:56 +0000 From: Xingyu Wu To: Michael Turquette , Stephen Boyd , Conor Dooley , Emil Renner Berthing , Rob Herring , Krzysztof Kozlowski Cc: Emil Renner Berthing , Paul Walmsley , Palmer Dabbelt , Albert Ou , Hal Feng , Xingyu Wu , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org Subject: [PATCH v4 1/2] clk: starfive: jh7110-sys: Add notifier for PLL clock Date: Wed, 10 Apr 2024 11:31:47 +0800 Message-Id: <20240410033148.213991-2-xingyu.wu@starfivetech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240410033148.213991-1-xingyu.wu@starfivetech.com> References: <20240410033148.213991-1-xingyu.wu@starfivetech.com> X-ClientProxiedBy: NT0PR01CA0002.CHNPR01.prod.partner.outlook.cn (2406:e500:c510::23) To NTZPR01MB0956.CHNPR01.prod.partner.outlook.cn (2406:e500:c510:8::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: NTZPR01MB0956:EE_|NTZPR01MB1132:EE_ X-MS-Office365-Filtering-Correlation-Id: 5096103e-13fb-4616-a8f6-08dc590ec571 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: poY8uf4Bdt7w+S3yoDuXOgUVg7laUlIO3wKcGvq0XRLjLazPAadmmPtoaRYxaIxdK7rjVDZBH/RmboRlaeKPFPTsi/Yxb30Qt6gWwECdHYS6NaMcZB1SZOysDCwR6Kma/5lrfZtAO1KwBKdKpixnNEq4G1T591n/kgTvNY+d8pcem29pWLjl82A5ZgqjVHiaT1mF/khKB3J7+OntWDMg1YpwYJk9rq2/aqO5zY7x+W8BJ6rJOWKspdXypQqac+w5st2aCH8IwrAYBQ0G83imAS/130GwXgcUAihyNK8ib2zNy3CMCLO22qEzdvknbDl1OgkP5Rk+RQfphFjtBwXrUi2tJXDTzcEvHOoQx2hq62fRb0XuZB4kdrtTpGXEVUDruJzSUlgYp5iXblUBdoYOyFPwtZ3/F8e+kW8Eek00pky8Ph3MfvYRpHLw2CrPxpyXaYPME8Kk28wQL1O7H9aPfTr5eI7dZ8t9FaSSMFkBWXa8cbGsRHE8071kLyjJqDCVzvTSFm3bwV+165BdQr44SZgXtL8fQ7ptC9RDilRrIVimu1tVZTTcjKwLJjTtri6TQhMpDIDk+zxs08xoPHMJeb1VcroclKoobfaxtpdzo84BKqhe7mha7ZO2/juwYJfr X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:NTZPR01MB0956.CHNPR01.prod.partner.outlook.cn;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(52116005)(7416005)(41320700004)(366007)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam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sWGZH8hIwBwC0z2sZY3WziBfnP/Ch43TR0xLDDobTgTeS1Ta7qWp2y6che3qo/wBljkptTAjBPnYIzb+iygCYM540lcvZO4//OSlaGzL7o+VlDWggPFFI8ejK6nof9L1irx48YY3X1zRzFEMdPCMZNSOetyji8de4n25PctALEwqy1/WtUBdtAyNP77KjyUoDdlMgUQj74j59tlPCUa0msEzjxLWiJAPzBHsyg0vn3CkiZigrvcAouEiGe999ExMqVoZXRSlmJ0FBgu8VYXvAwmEmUiKw+qRVqsryFYBrspedGQUji8Iiyn/DH5uksoIv8y0ZAehvs45w1rgDb6UzjumcXxKW+BCdUnJwdCaVSHG8HxqEUYKFUGn10oLApLAkxslwhChGYmglfnwbXoA8V8/Cgy3OQfCvL0U5QISqjWwwiNAQoy3jVIOP6i7mjiUGV66kmb4w+2CAur07/+DoabI9c4Jwqy6LmlXoj7m+gRXe6yphE5Ku5qMrBM9Z766Kr/2k5TgHfu5TbxfF8WBgOpXSokfvJl/d0dSg== X-OriginatorOrg: starfivetech.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5096103e-13fb-4616-a8f6-08dc590ec571 X-MS-Exchange-CrossTenant-AuthSource: NTZPR01MB0956.CHNPR01.prod.partner.outlook.cn X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2024 03:31:55.8092 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 06fe3fa3-1221-43d3-861b-5a4ee687a85c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9GBMUxZ0L6iTmJEMhwPhqTd1AeqIQsN55hfdcecg9XELQWKVMzmsbOXIoMXCiX/lRFCrg6Ey61RrVsDNPOiOIlzvmfrDbl93X/+zJvzHQ6g= X-MS-Exchange-Transport-CrossTenantHeadersStamped: NTZPR01MB1132 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240409_203205_509638_0D642D2A X-CRM114-Status: GOOD ( 16.20 ) 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 Add notifier function for PLL clock. In the function, the cpu_root clock should be operated by saving its current parent and setting a new safe parent (osc clock) before setting the PLL clock rate. After setting PLL rate, it should be switched back to the original parent clock. Signed-off-by: Xingyu Wu --- .../clk/starfive/clk-starfive-jh7110-sys.c | 31 ++++++++++++++++++- drivers/clk/starfive/clk-starfive-jh71x0.h | 2 ++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/clk/starfive/clk-starfive-jh7110-sys.c b/drivers/clk/starfive/clk-starfive-jh7110-sys.c index 8f5e5abfa178..adf62e4d94e4 100644 --- a/drivers/clk/starfive/clk-starfive-jh7110-sys.c +++ b/drivers/clk/starfive/clk-starfive-jh7110-sys.c @@ -385,6 +385,32 @@ int jh7110_reset_controller_register(struct jh71x0_clk_priv *priv, } EXPORT_SYMBOL_GPL(jh7110_reset_controller_register); +/* + * This clock notifier is called when the rate of PLL0 clock is to be change, + * The cpu_root clock should save curent parent clock and swicth its parent + * clock to osc before PLL0 rate will be changed. And switch its parent clock + * back after PLL rate finished. + */ +static int jh7110_pll_clk_notifier_cb(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct jh71x0_clk_priv *priv = container_of(nb, struct jh71x0_clk_priv, pll_clk_nb); + struct clk *cpu_root = priv->reg[JH7110_SYSCLK_CPU_ROOT].hw.clk; + int ret = 0; + + if (action == PRE_RATE_CHANGE) { + struct clk *osc = clk_get(priv->dev, "osc"); + + priv->original_clk = clk_get_parent(cpu_root); + ret = clk_set_parent(cpu_root, osc); + clk_put(osc); + } else if (action == POST_RATE_CHANGE) { + ret = clk_set_parent(cpu_root, priv->original_clk); + } + + return notifier_from_errno(ret); +} + static int __init jh7110_syscrg_probe(struct platform_device *pdev) { struct jh71x0_clk_priv *priv; @@ -413,7 +439,10 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev) if (IS_ERR(priv->pll[0])) return PTR_ERR(priv->pll[0]); } else { - clk_put(pllclk); + priv->pll_clk_nb.notifier_call = jh7110_pll_clk_notifier_cb; + ret = clk_notifier_register(pllclk, &priv->pll_clk_nb); + if (ret) + return ret; priv->pll[0] = NULL; } diff --git a/drivers/clk/starfive/clk-starfive-jh71x0.h b/drivers/clk/starfive/clk-starfive-jh71x0.h index 23e052fc1549..e3f441393e48 100644 --- a/drivers/clk/starfive/clk-starfive-jh71x0.h +++ b/drivers/clk/starfive/clk-starfive-jh71x0.h @@ -114,6 +114,8 @@ struct jh71x0_clk_priv { spinlock_t rmw_lock; struct device *dev; void __iomem *base; + struct clk *original_clk; + struct notifier_block pll_clk_nb; struct clk_hw *pll[3]; struct jh71x0_clk reg[]; };