From patchwork Mon Oct 9 14:59:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Wolsieffer X-Patchwork-Id: 150134 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1927015vqo; Mon, 9 Oct 2023 07:59:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF62yprR1SAROqXKmqYTQZovDFxZpcoyXlIhD3CX+1RWjHhn4eacwpHXF3su1msTIbPlGQ4 X-Received: by 2002:a17:90a:a090:b0:25d:eca9:1621 with SMTP id r16-20020a17090aa09000b0025deca91621mr12281003pjp.6.1696863584317; Mon, 09 Oct 2023 07:59:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696863584; cv=none; d=google.com; s=arc-20160816; b=uv8DnxaVUSEkrWsz4RRRhIGvmXD7PsDSPo0t9Jl30LBVm9AdEPlbgDbmR7GddL8bgL 31UAu5Kd1F/21XvOS2meddGoAOvMHpeF/sIK6hjCPsrGOqVK9gcwIsSGenepk93H9yxE 6YA16Ln+TmYn7hGIaShrig2Yz/8rb4UHRBE8VzUk4DCcEgHhKFFU5u16hGXaFQgNseaN 2WNTAD/9aG+ottQPa1vLdIt7hcnZy+YNZAaWbLk11P3RRc/wW2m7VsLRj6ehIz6W4qXF mt9xIIAb/xrFNx+RemlalgZq3I7FP8W3hTBtF3zczv7c5oKuGZ9VSyDgKy4tNAb81q3K Q5lQ== 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:dkim-signature; bh=gremNSB3d9SyFHcL1LlmJRtVUMpoQGmg6IJzbQmBl54=; fh=f9safSkw/SQVr0kEtPvUiqQf5kZ6gbwV4tr+WhykmK8=; b=KGOgvc7JZurzwgTGQXP703qUhUzoTxUZMi46DDjgwO/rL5to+zrL5GriZlWFGcXmhc 1gaUPKDAXBk6lw0YcTMQJMMacCB+CO66nG/m9o7qfh9FoVohlBmmhqSwiI90iyFMpPQV eMl0oTY3jGYlbGw5majTIzZOUxC6HKF2zc1XxY3EsK8DG38Bpz2Qoa/tQZMGzAVi1wpg 2voMYyqp8oFMuPGImv6tOcrbarSj4obaAB7EqpAFicRKJjAbNNLnkzQnSasTvI6yIx+N iSb5Lbf/2H7zrPu6SO2oMc1d7scqNn837sIUvC4+O5k61AcSRohwfWEAEvZNXj6Um0Gb XGnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hefring-com.20230601.gappssmtp.com header.s=20230601 header.b=seHY4i9K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id l16-20020a17090b079000b002776794a75csi9899756pjz.171.2023.10.09.07.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 07:59:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@hefring-com.20230601.gappssmtp.com header.s=20230601 header.b=seHY4i9K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id BCE3B8046BEF; Mon, 9 Oct 2023 07:59:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344471AbjJIO7a (ORCPT + 18 others); Mon, 9 Oct 2023 10:59:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346549AbjJIO72 (ORCPT ); Mon, 9 Oct 2023 10:59:28 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CCB7C5 for ; Mon, 9 Oct 2023 07:59:26 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3af65455e7cso3390660b6e.1 for ; Mon, 09 Oct 2023 07:59:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hefring-com.20230601.gappssmtp.com; s=20230601; t=1696863565; x=1697468365; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=gremNSB3d9SyFHcL1LlmJRtVUMpoQGmg6IJzbQmBl54=; b=seHY4i9KKfpCxSJAJK2e50XT3NwsxB8C0ZuF2/PNl5C1zlFaT/P4iHgHMr+Bwto22Y 10Tlr3f0XShEtQgRU5QXvFau9Hw6+zPztCM+YfOvR+kPzpLmzcs8ZTwl3Ms/cgoILfRc b2KGkxLeV7lyhFSDasuGB1S9pxeOyr8bYG1kcbLRoWfQCNlM9THRloaSZhkSpaJ3Q4Br HL5R+NXlsSt3mElioyu2OCdW36k9f/zFdw5xg8IPPXuBR3ExewySSTTLVxkPaLqgF7Y7 c7yx5h4gPINSAnqMtCgpppHy0fgHIX3ZEMfgjnsmdxzNYgE28ss70iAXsWbmW4+AW7OH VUmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696863565; x=1697468365; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gremNSB3d9SyFHcL1LlmJRtVUMpoQGmg6IJzbQmBl54=; b=jswaM1ySDCd56eyPrs8vGlSSA9gyG/Ub0BjnnLm3eDrRTLwfD+7tjPPLFV0bbl/bCK gr8HuMVZ0uDmN2FnAoXANvthJ++aWVMoCeOWN79aqUkRuOQGAUmhjARY4iEseFmn/hcf aXP5kj0S+05LtiZtIDKIKURDKAdVGLWAJud/85FkwBVpgC6WkcgxluTHNbXPqO0aA6ZK /fjZNCYudgBg5h3vCLzoZ74gmDMXc9GbZamYI1U8mSdeG5ZKBInn/Fn7DaXihdPtwjY2 WzU04/LAOQ9RRvhCQP1hnjRqHD7ZTgLJxwV6txvxZwRk54YvfgFQTTZkuWE0nvkBPCrt Jkxw== X-Gm-Message-State: AOJu0Yxhrfl9B8pLA1yWlqL0oz9A0jTBWB1YPg2V22LZ/mxunf/MLIsR we+i6r6OTPFIanodK3DnPBHLJw== X-Received: by 2002:a05:6870:d187:b0:1b0:60ff:b73f with SMTP id a7-20020a056870d18700b001b060ffb73fmr19038396oac.8.1696863565494; Mon, 09 Oct 2023 07:59:25 -0700 (PDT) Received: from localhost.localdomain ([50.212.55.89]) by smtp.gmail.com with ESMTPSA id u21-20020ae9c015000000b0076ef29f3429sm3559275qkk.120.2023.10.09.07.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 07:59:25 -0700 (PDT) From: Ben Wolsieffer To: linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Christophe Roullier , Ben Wolsieffer Subject: [PATCH net-next] net: stmmac: dwmac-stm32: refactor clock config Date: Mon, 9 Oct 2023 10:59:04 -0400 Message-ID: <20231009145904.3776703-1-ben.wolsieffer@hefring.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=2.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 09 Oct 2023 07:59:41 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779290430235614429 X-GMAIL-MSGID: 1779290430235614429 Currently, clock configuration is spread throughout the driver and partially duplicated for the STM32MP1 and STM32 MCU variants. This makes it difficult to keep track of which clocks need to be enabled or disabled in various scenarios. This patch adds symmetric stm32_dwmac_clk_enable/disable() functions that handle all clock configuration, including quirks required while suspending or resuming. syscfg_clk and clk_eth_ck are not present on STM32 MCUs, but it is fine to try to configure them anyway since NULL clocks are ignored. Signed-off-by: Ben Wolsieffer --- This is a followup to my recent STM32 ethernet resume bug fix [1] that tries to address the underlying issues that led to that bug. [1] https://lore.kernel.org/all/20230927175749.1419774-1-ben.wolsieffer@hefring.com/ .../net/ethernet/stmicro/stmmac/dwmac-stm32.c | 113 +++++++----------- 1 file changed, 45 insertions(+), 68 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c index d8d3c729f219..c92dfc4ecf57 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-stm32.c @@ -98,7 +98,6 @@ struct stm32_dwmac { struct stm32_ops { int (*set_mode)(struct plat_stmmacenet_data *plat_dat); - int (*clk_prepare)(struct stm32_dwmac *dwmac, bool prepare); int (*suspend)(struct stm32_dwmac *dwmac); void (*resume)(struct stm32_dwmac *dwmac); int (*parse_data)(struct stm32_dwmac *dwmac, @@ -107,62 +106,55 @@ struct stm32_ops { bool clk_rx_enable_in_suspend; }; -static int stm32_dwmac_init(struct plat_stmmacenet_data *plat_dat) +static int stm32_dwmac_clk_enable(struct stm32_dwmac *dwmac, bool resume) { - struct stm32_dwmac *dwmac = plat_dat->bsp_priv; int ret; - if (dwmac->ops->set_mode) { - ret = dwmac->ops->set_mode(plat_dat); - if (ret) - return ret; - } - ret = clk_prepare_enable(dwmac->clk_tx); if (ret) - return ret; + goto err_clk_tx; - if (!dwmac->ops->clk_rx_enable_in_suspend || - !dwmac->dev->power.is_suspended) { + if (!dwmac->ops->clk_rx_enable_in_suspend || !resume) { ret = clk_prepare_enable(dwmac->clk_rx); - if (ret) { - clk_disable_unprepare(dwmac->clk_tx); - return ret; - } + if (ret) + goto err_clk_rx; } - if (dwmac->ops->clk_prepare) { - ret = dwmac->ops->clk_prepare(dwmac, true); - if (ret) { - clk_disable_unprepare(dwmac->clk_rx); - clk_disable_unprepare(dwmac->clk_tx); - } + ret = clk_prepare_enable(dwmac->syscfg_clk); + if (ret) + goto err_syscfg_clk; + + if (dwmac->enable_eth_ck) { + ret = clk_prepare_enable(dwmac->clk_eth_ck); + if (ret) + goto err_clk_eth_ck; } return ret; + +err_clk_eth_ck: + clk_disable_unprepare(dwmac->syscfg_clk); +err_syscfg_clk: + if (!dwmac->ops->clk_rx_enable_in_suspend || !resume) + clk_disable_unprepare(dwmac->clk_rx); +err_clk_rx: + clk_disable_unprepare(dwmac->clk_tx); +err_clk_tx: + return ret; } -static int stm32mp1_clk_prepare(struct stm32_dwmac *dwmac, bool prepare) +static int stm32_dwmac_init(struct plat_stmmacenet_data *plat_dat, bool resume) { - int ret = 0; + struct stm32_dwmac *dwmac = plat_dat->bsp_priv; + int ret; - if (prepare) { - ret = clk_prepare_enable(dwmac->syscfg_clk); + if (dwmac->ops->set_mode) { + ret = dwmac->ops->set_mode(plat_dat); if (ret) return ret; - if (dwmac->enable_eth_ck) { - ret = clk_prepare_enable(dwmac->clk_eth_ck); - if (ret) { - clk_disable_unprepare(dwmac->syscfg_clk); - return ret; - } - } - } else { - clk_disable_unprepare(dwmac->syscfg_clk); - if (dwmac->enable_eth_ck) - clk_disable_unprepare(dwmac->clk_eth_ck); } - return ret; + + return stm32_dwmac_clk_enable(dwmac, resume); } static int stm32mp1_set_mode(struct plat_stmmacenet_data *plat_dat) @@ -252,13 +244,15 @@ static int stm32mcu_set_mode(struct plat_stmmacenet_data *plat_dat) dwmac->ops->syscfg_eth_mask, val << 23); } -static void stm32_dwmac_clk_disable(struct stm32_dwmac *dwmac) +static void stm32_dwmac_clk_disable(struct stm32_dwmac *dwmac, bool suspend) { clk_disable_unprepare(dwmac->clk_tx); - clk_disable_unprepare(dwmac->clk_rx); + if (!dwmac->ops->clk_rx_enable_in_suspend || !suspend) + clk_disable_unprepare(dwmac->clk_rx); - if (dwmac->ops->clk_prepare) - dwmac->ops->clk_prepare(dwmac, false); + clk_disable_unprepare(dwmac->syscfg_clk); + if (dwmac->enable_eth_ck) + clk_disable_unprepare(dwmac->clk_eth_ck); } static int stm32_dwmac_parse_data(struct stm32_dwmac *dwmac, @@ -397,7 +391,7 @@ static int stm32_dwmac_probe(struct platform_device *pdev) plat_dat->bsp_priv = dwmac; - ret = stm32_dwmac_init(plat_dat); + ret = stm32_dwmac_init(plat_dat, false); if (ret) return ret; @@ -408,7 +402,7 @@ static int stm32_dwmac_probe(struct platform_device *pdev) return 0; err_clk_disable: - stm32_dwmac_clk_disable(dwmac); + stm32_dwmac_clk_disable(dwmac, false); return ret; } @@ -421,7 +415,7 @@ static void stm32_dwmac_remove(struct platform_device *pdev) stmmac_dvr_remove(&pdev->dev); - stm32_dwmac_clk_disable(priv->plat->bsp_priv); + stm32_dwmac_clk_disable(dwmac, false); if (dwmac->irq_pwr_wakeup >= 0) { dev_pm_clear_wake_irq(&pdev->dev); @@ -431,18 +425,7 @@ static void stm32_dwmac_remove(struct platform_device *pdev) static int stm32mp1_suspend(struct stm32_dwmac *dwmac) { - int ret = 0; - - ret = clk_prepare_enable(dwmac->clk_ethstp); - if (ret) - return ret; - - clk_disable_unprepare(dwmac->clk_tx); - clk_disable_unprepare(dwmac->syscfg_clk); - if (dwmac->enable_eth_ck) - clk_disable_unprepare(dwmac->clk_eth_ck); - - return ret; + return clk_prepare_enable(dwmac->clk_ethstp); } static void stm32mp1_resume(struct stm32_dwmac *dwmac) @@ -450,14 +433,6 @@ static void stm32mp1_resume(struct stm32_dwmac *dwmac) clk_disable_unprepare(dwmac->clk_ethstp); } -static int stm32mcu_suspend(struct stm32_dwmac *dwmac) -{ - clk_disable_unprepare(dwmac->clk_tx); - clk_disable_unprepare(dwmac->clk_rx); - - return 0; -} - #ifdef CONFIG_PM_SLEEP static int stm32_dwmac_suspend(struct device *dev) { @@ -468,6 +443,10 @@ static int stm32_dwmac_suspend(struct device *dev) int ret; ret = stmmac_suspend(dev); + if (ret) + return ret; + + stm32_dwmac_clk_disable(dwmac, true); if (dwmac->ops->suspend) ret = dwmac->ops->suspend(dwmac); @@ -485,7 +464,7 @@ static int stm32_dwmac_resume(struct device *dev) if (dwmac->ops->resume) dwmac->ops->resume(dwmac); - ret = stm32_dwmac_init(priv->plat); + ret = stm32_dwmac_init(priv->plat, true); if (ret) return ret; @@ -500,13 +479,11 @@ static SIMPLE_DEV_PM_OPS(stm32_dwmac_pm_ops, static struct stm32_ops stm32mcu_dwmac_data = { .set_mode = stm32mcu_set_mode, - .suspend = stm32mcu_suspend, .syscfg_eth_mask = SYSCFG_MCU_ETH_MASK }; static struct stm32_ops stm32mp1_dwmac_data = { .set_mode = stm32mp1_set_mode, - .clk_prepare = stm32mp1_clk_prepare, .suspend = stm32mp1_suspend, .resume = stm32mp1_resume, .parse_data = stm32mp1_parse_data,