From patchwork Mon Mar 18 06:36:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 13595053 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 94762C54E58 for ; Mon, 18 Mar 2024 06:53:43 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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=1Tng7KBhjb3iD0n0dd7VkT6wlE+KpdZ93TvCzW4WPdM=; b=DsbDM4uJooNLbw EqikXQ57Bhz6quiCQvcr3LMVZ4wl7acZniwlsNzQROuu+TptPM3RWeKEyrbEf4bI4j4J8Fu4vx0n2 rj+rWqw13RSgwSsIz7ha3j8Ad0IuaV2FjSNiUKwhEXsDKrm2A1hflCdY23ESzuAVJjYl5Oz6U8HVs tesFxGE90bfFkPkln2S3pK8LDA9A/F0BxvwKI+Ux+EvNM4WY0trbe2LJoriQ1pBUPVsKZmrIHLOla 6Us5/ziHmoJELuKpru1xOiBJH8ps2MMbIifNR2+mZEOuz30MmljPm96+MuMsoCStzzIAPuf7IrcIn q7w1RN7SSez5LVRw67cA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rm6sB-00000007WSp-2a0m; Mon, 18 Mar 2024 06:53:27 +0000 Received: from inva020.nxp.com ([92.121.34.13]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rm6s8-00000007WR0-0wre for linux-arm-kernel@lists.infradead.org; Mon, 18 Mar 2024 06:53:26 +0000 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 9589D1A0BA3; Mon, 18 Mar 2024 07:53:18 +0100 (CET) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 337111A0580; Mon, 18 Mar 2024 07:53:18 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 77ACD183AC0B; Mon, 18 Mar 2024 14:53:16 +0800 (+08) From: Shengjiu Wang To: abelvesa@kernel.org, peng.fan@nxp.com, mturquette@baylibre.com, sboyd@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, shengjiu.wang@gmail.com Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] clk: imx: imx8mp: Add pm_runtime support for power saving Date: Mon, 18 Mar 2024 14:36:51 +0800 Message-Id: <1710743811-1698-1-git-send-email-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240317_235324_559678_52E9F0EF X-CRM114-Status: GOOD ( 20.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add pm_runtime support for power saving. In pm runtime suspend state the registers will be reseted, so add registers save in pm runtime suspend and restore them in pm runtime resume. Signed-off-by: Shengjiu Wang Reviewed-by: Peng Fan --- drivers/clk/imx/clk-imx8mp-audiomix.c | 99 ++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 3 deletions(-) diff --git a/drivers/clk/imx/clk-imx8mp-audiomix.c b/drivers/clk/imx/clk-imx8mp-audiomix.c index 55ed211a5e0b..d2bf53e2aacf 100644 --- a/drivers/clk/imx/clk-imx8mp-audiomix.c +++ b/drivers/clk/imx/clk-imx8mp-audiomix.c @@ -7,10 +7,12 @@ #include #include +#include #include #include #include #include +#include #include @@ -18,6 +20,7 @@ #define CLKEN0 0x000 #define CLKEN1 0x004 +#define EARC 0x200 #define SAI1_MCLK_SEL 0x300 #define SAI2_MCLK_SEL 0x304 #define SAI3_MCLK_SEL 0x308 @@ -26,6 +29,12 @@ #define SAI7_MCLK_SEL 0x314 #define PDM_SEL 0x318 #define SAI_PLL_GNRL_CTL 0x400 +#define SAI_PLL_FDIVL_CTL0 0x404 +#define SAI_PLL_FDIVL_CTL1 0x408 +#define SAI_PLL_SSCG_CTL 0x40C +#define SAI_PLL_MNIT_CTL 0x410 +#define IPG_LP_CTRL 0x504 +#define REGS_NUM 16 #define SAIn_MCLK1_PARENT(n) \ static const struct clk_parent_data \ @@ -182,13 +191,65 @@ static struct clk_imx8mp_audiomix_sel sels[] = { CLK_SAIn(7) }; +struct clk_imx8mp_audiomix_regs { + u32 regs_num; + u32 regs_off[]; +}; + +static const struct clk_imx8mp_audiomix_regs audiomix_regs = { + .regs_num = REGS_NUM, + .regs_off = { + CLKEN0, + CLKEN1, + EARC, + SAI1_MCLK_SEL, + SAI2_MCLK_SEL, + SAI3_MCLK_SEL, + SAI5_MCLK_SEL, + SAI6_MCLK_SEL, + SAI7_MCLK_SEL, + PDM_SEL, + SAI_PLL_GNRL_CTL, + SAI_PLL_FDIVL_CTL0, + SAI_PLL_FDIVL_CTL1, + SAI_PLL_SSCG_CTL, + SAI_PLL_MNIT_CTL, + IPG_LP_CTRL + }, +}; + +struct clk_imx8mp_audiomix_drvdata { + void __iomem *base; + u32 regs_save[REGS_NUM]; +}; + +static void clk_imx8mp_audiomix_save_restore(struct device *dev, bool save) +{ + struct clk_imx8mp_audiomix_drvdata *drvdata = dev_get_drvdata(dev); + void __iomem *base = drvdata->base; + int i; + + if (save) { + for (i = 0; i < audiomix_regs.regs_num; i++) + drvdata->regs_save[i] = readl(base + audiomix_regs.regs_off[i]); + } else { + for (i = 0; i < audiomix_regs.regs_num; i++) + writel(drvdata->regs_save[i], base + audiomix_regs.regs_off[i]); + } +} + static int clk_imx8mp_audiomix_probe(struct platform_device *pdev) { + struct clk_imx8mp_audiomix_drvdata *drvdata; struct clk_hw_onecell_data *priv; struct device *dev = &pdev->dev; void __iomem *base; struct clk_hw *hw; - int i; + int i, ret; + + drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); + if (!drvdata) + return -ENOMEM; priv = devm_kzalloc(dev, struct_size(priv, hws, IMX8MP_CLK_AUDIOMIX_END), @@ -202,6 +263,9 @@ static int clk_imx8mp_audiomix_probe(struct platform_device *pdev) if (IS_ERR(base)) return PTR_ERR(base); + drvdata->base = base; + dev_set_drvdata(dev, drvdata); + for (i = 0; i < ARRAY_SIZE(sels); i++) { if (sels[i].num_parents == 1) { hw = devm_clk_hw_register_gate_parent_data(dev, @@ -257,10 +321,38 @@ static int clk_imx8mp_audiomix_probe(struct platform_device *pdev) if (IS_ERR(hw)) return PTR_ERR(hw); - return devm_of_clk_add_hw_provider(&pdev->dev, of_clk_hw_onecell_get, - priv); + ret = devm_of_clk_add_hw_provider(&pdev->dev, of_clk_hw_onecell_get, + priv); + if (ret) + return ret; + + pm_runtime_enable(&pdev->dev); + clk_imx8mp_audiomix_save_restore(&pdev->dev, true); + + return 0; } +static int clk_imx8mp_audiomix_runtime_suspend(struct device *dev) +{ + clk_imx8mp_audiomix_save_restore(dev, true); + + return 0; +} + +static int clk_imx8mp_audiomix_runtime_resume(struct device *dev) +{ + clk_imx8mp_audiomix_save_restore(dev, false); + + return 0; +} + +static const struct dev_pm_ops clk_imx8mp_audiomix_pm_ops = { + SET_RUNTIME_PM_OPS(clk_imx8mp_audiomix_runtime_suspend, + clk_imx8mp_audiomix_runtime_resume, NULL) + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) +}; + static const struct of_device_id clk_imx8mp_audiomix_of_match[] = { { .compatible = "fsl,imx8mp-audio-blk-ctrl" }, { /* sentinel */ } @@ -272,6 +364,7 @@ static struct platform_driver clk_imx8mp_audiomix_driver = { .driver = { .name = "imx8mp-audio-blk-ctrl", .of_match_table = clk_imx8mp_audiomix_of_match, + .pm = &clk_imx8mp_audiomix_pm_ops, }, };