From nobody Sun Dec 28 00:52:37 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFAAEC4332F for ; Thu, 14 Dec 2023 11:47:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1444192AbjLNLq4 (ORCPT ); Thu, 14 Dec 2023 06:46:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1444181AbjLNLqa (ORCPT ); Thu, 14 Dec 2023 06:46:30 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4508E197 for ; Thu, 14 Dec 2023 03:46:30 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-54c5ed26cf6so10160414a12.3 for ; Thu, 14 Dec 2023 03:46:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1702554389; x=1703159189; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=urXQcBC1I2HSJadX/7B8vUlbLmboqpTqecwWwz/bPS4=; b=ZuGXB+eSIGZ4T0x03M35t+rn/f90z0mV8KJz/OtKj2skFSxpKG6woHKXRvYr257RXf O4D9wFhs9dTFtsakOMBIu4aYV3ZFq6BHhYzP/qRalWr7KeeI7tuHsJdFatmnrex6RWHw kq5rlD+8q8DdLJgx6fzPk0Sh9Xq3jCCxuSDqiBOJDhHalVt+tvZE/mp5DoUyYbrKYVMj KVw+FX2WMBxogAbAO5WRRTK+COsfQxYC0ab/fI65/Yz1IYsLsnjVkR3sox3PdS6Mmq6s Hcl9VHghyTr9PgAMEDfVZFYgedOHQz7db+B3xdeAozAXhl8bCeh/hkZoOpjzYmALnLRv kFCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702554389; x=1703159189; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=urXQcBC1I2HSJadX/7B8vUlbLmboqpTqecwWwz/bPS4=; b=Su1gEz+IQyuzX9WG+ZsyNoK0CgSY+7WKs+GdbKM0dUpgdF5gqINIsRPVe0ZCSnUIzt YbYqWmXaUCdToi4QGLetqoGNAE/Un+ZASHOX4W21mprFsDGu7ATIa6BLMyAyAdNxKbJJ SCtjyVGsjf5OvH4anmMeyXnKpwb8X/wVqmI2CDk0igEUGIBcRPKBGNp4qHQ/F04x4pvc GOlU3ZLzbuXDo1dNWGRq5JAPaicOyjxhJyl9G5R1I3AmuSAr3dRsv4CyqqO3mvj5ovGk FiS0Zgzl46F1+oI3Ck7xoekvavHiRjHICss+Cdb+GC4k18FAjYHcYf95/YIsqPefzDLS P94Q== X-Gm-Message-State: AOJu0Yzrr2039+70OhLZod4G3ULJU9OfcqipAcmm9gy0P6NwiHeOnOqJ JdMXP+S76RkE7CkA/8ytJcJhmg== X-Google-Smtp-Source: AGHT+IEqGQoFBiFfzfK3jqMrNe9KA/tUQ/OOWSMGUcII2taRF+pt0OygGdcB8qR+fZU+qYveelsr+w== X-Received: by 2002:a17:906:5a49:b0:a1e:86c2:dccd with SMTP id my9-20020a1709065a4900b00a1e86c2dccdmr4714486ejc.14.1702554389543; Thu, 14 Dec 2023 03:46:29 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.103]) by smtp.gmail.com with ESMTPSA id ll9-20020a170907190900b00a1da2f7c1d8sm9240877ejc.77.2023.12.14.03.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 03:46:29 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: s.shtylyov@omp.ru, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, richardcochran@gmail.com, p.zabel@pengutronix.de, yoshihiro.shimoda.uh@renesas.com, wsa+renesas@sang-engineering.com, geert+renesas@glider.be Cc: netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Claudiu Beznea Subject: [PATCH net-next v2 07/21] net: ravb: Move reference clock enable/disable on runtime PM APIs Date: Thu, 14 Dec 2023 13:45:46 +0200 Message-Id: <20231214114600.2451162-8-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214114600.2451162-1-claudiu.beznea.uj@bp.renesas.com> References: <20231214114600.2451162-1-claudiu.beznea.uj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Reference clock could be or not part of the power domain. If it is part of the power domain, the power domain takes care of propertly setting it. In case it is not part of the power domain and full runtime PM support is available in driver the clock will not be propertly disabled/enabled at runtime. For this, keep the prepare/unprepare operations in the driver's probe()/remove() functions and move the enable/disable in runtime PM functions. Signed-off-by: Claudiu Beznea Reviewed-by: Sergey Shtylyov --- Changes in v2: - this patch is new and follows the recommendations proposed in the discussion of patch 08/13 ("net: ravb: Rely on PM domain to enable refclk= ") from v2 drivers/net/ethernet/renesas/ravb_main.c | 88 +++++++++++++----------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/etherne= t/renesas/ravb_main.c index 9a618d8dbfcd..83691a0f0cc2 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -2664,11 +2664,6 @@ static int ravb_probe(struct platform_device *pdev) if (error) goto out_free_netdev; =20 - pm_runtime_enable(&pdev->dev); - error =3D pm_runtime_resume_and_get(&pdev->dev); - if (error < 0) - goto out_rpm_disable; - if (info->multi_irqs) { if (info->err_mgmt_irqs) irq =3D platform_get_irq_byname(pdev, "dia"); @@ -2679,7 +2674,7 @@ static int ravb_probe(struct platform_device *pdev) } if (irq < 0) { error =3D irq; - goto out_release; + goto out_reset_assert; } ndev->irq =3D irq; =20 @@ -2697,10 +2692,23 @@ static int ravb_probe(struct platform_device *pdev) priv->num_rx_ring[RAVB_NC] =3D NC_RX_RING_SIZE; } =20 + priv->refclk =3D devm_clk_get_optional(&pdev->dev, "refclk"); + if (IS_ERR(priv->refclk)) { + error =3D PTR_ERR(priv->refclk); + goto out_reset_assert; + } + clk_prepare(priv->refclk); + + platform_set_drvdata(pdev, ndev); + pm_runtime_enable(&pdev->dev); + error =3D pm_runtime_resume_and_get(&pdev->dev); + if (error < 0) + goto out_rpm_disable; + priv->addr =3D devm_platform_get_and_ioremap_resource(pdev, 0, &res); if (IS_ERR(priv->addr)) { error =3D PTR_ERR(priv->addr); - goto out_release; + goto out_rpm_put; } =20 /* The Ether-specific entries in the device structure. */ @@ -2711,7 +2719,7 @@ static int ravb_probe(struct platform_device *pdev) =20 error =3D of_get_phy_mode(np, &priv->phy_interface); if (error && error !=3D -ENODEV) - goto out_release; + goto out_rpm_put; =20 priv->no_avb_link =3D of_property_read_bool(np, "renesas,no-ether-link"); priv->avb_link_active_low =3D @@ -2724,14 +2732,14 @@ static int ravb_probe(struct platform_device *pdev) irq =3D platform_get_irq_byname(pdev, "ch24"); if (irq < 0) { error =3D irq; - goto out_release; + goto out_rpm_put; } priv->emac_irq =3D irq; for (i =3D 0; i < NUM_RX_QUEUE; i++) { irq =3D platform_get_irq_byname(pdev, ravb_rx_irqs[i]); if (irq < 0) { error =3D irq; - goto out_release; + goto out_rpm_put; } priv->rx_irqs[i] =3D irq; } @@ -2739,7 +2747,7 @@ static int ravb_probe(struct platform_device *pdev) irq =3D platform_get_irq_byname(pdev, ravb_tx_irqs[i]); if (irq < 0) { error =3D irq; - goto out_release; + goto out_rpm_put; } priv->tx_irqs[i] =3D irq; } @@ -2748,14 +2756,14 @@ static int ravb_probe(struct platform_device *pdev) irq =3D platform_get_irq_byname(pdev, "err_a"); if (irq < 0) { error =3D irq; - goto out_release; + goto out_rpm_put; } priv->erra_irq =3D irq; =20 irq =3D platform_get_irq_byname(pdev, "mgmt_a"); if (irq < 0) { error =3D irq; - goto out_release; + goto out_rpm_put; } priv->mgmta_irq =3D irq; } @@ -2764,21 +2772,14 @@ static int ravb_probe(struct platform_device *pdev) priv->clk =3D devm_clk_get(&pdev->dev, NULL); if (IS_ERR(priv->clk)) { error =3D PTR_ERR(priv->clk); - goto out_release; + goto out_rpm_put; } =20 - priv->refclk =3D devm_clk_get_optional(&pdev->dev, "refclk"); - if (IS_ERR(priv->refclk)) { - error =3D PTR_ERR(priv->refclk); - goto out_release; - } - clk_prepare_enable(priv->refclk); - if (info->gptp_ref_clk) { priv->gptp_clk =3D devm_clk_get(&pdev->dev, "gptp"); if (IS_ERR(priv->gptp_clk)) { error =3D PTR_ERR(priv->gptp_clk); - goto out_disable_refclk; + goto out_rpm_put; } } =20 @@ -2799,20 +2800,20 @@ static int ravb_probe(struct platform_device *pdev) /* Set AVB config mode */ error =3D ravb_set_config_mode(ndev); if (error) - goto out_disable_refclk; + goto out_rpm_put; =20 if (info->gptp || info->ccc_gac) { /* Set GTI value */ error =3D ravb_set_gti(ndev); if (error) - goto out_disable_refclk; + goto out_rpm_put; =20 /* Request GTI loading */ ravb_modify(ndev, GCCR, GCCR_LTI, GCCR_LTI); /* Check completion status. */ error =3D ravb_wait(ndev, GCCR, GCCR_LTI, 0); if (error) - goto out_disable_refclk; + goto out_rpm_put; } =20 if (info->internal_delay) { @@ -2829,7 +2830,7 @@ static int ravb_probe(struct platform_device *pdev) "Cannot allocate desc base address table (size %d bytes)\n", priv->desc_bat_size); error =3D -ENOMEM; - goto out_disable_refclk; + goto out_rpm_put; } for (q =3D RAVB_BE; q < DBAT_ENTRY_NUM; q++) priv->desc_bat[q].die_dt =3D DT_EOS; @@ -2875,8 +2876,6 @@ static int ravb_probe(struct platform_device *pdev) netdev_info(ndev, "Base address at %#x, %pM, IRQ %d.\n", (u32)ndev->base_addr, ndev->dev_addr, ndev->irq); =20 - platform_set_drvdata(pdev, ndev); - return 0; =20 out_napi_del: @@ -2892,12 +2891,12 @@ static int ravb_probe(struct platform_device *pdev) /* Stop PTP Clock driver */ if (info->ccc_gac) ravb_ptp_stop(ndev); -out_disable_refclk: - clk_disable_unprepare(priv->refclk); -out_release: +out_rpm_put: pm_runtime_put(&pdev->dev); out_rpm_disable: pm_runtime_disable(&pdev->dev); + clk_unprepare(priv->refclk); +out_reset_assert: reset_control_assert(rstc); out_free_netdev: free_netdev(ndev); @@ -2929,10 +2928,9 @@ static void ravb_remove(struct platform_device *pdev) if (error) netdev_err(ndev, "Failed to reset ndev\n"); =20 - clk_disable_unprepare(priv->refclk); - pm_runtime_put_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); + clk_unprepare(priv->refclk); reset_control_assert(priv->rstc); free_netdev(ndev); platform_set_drvdata(pdev, NULL); @@ -3071,21 +3069,27 @@ static int ravb_resume(struct device *dev) return ret; } =20 -static int ravb_runtime_nop(struct device *dev) +static int ravb_runtime_suspend(struct device *dev) { - /* Runtime PM callback shared between ->runtime_suspend() - * and ->runtime_resume(). Simply returns success. - * - * This driver re-initializes all registers after - * pm_runtime_get_sync() anyway so there is no need - * to save and restore registers here. - */ + struct net_device *ndev =3D dev_get_drvdata(dev); + struct ravb_private *priv =3D netdev_priv(ndev); + + clk_disable(priv->refclk); + return 0; } =20 +static int ravb_runtime_resume(struct device *dev) +{ + struct net_device *ndev =3D dev_get_drvdata(dev); + struct ravb_private *priv =3D netdev_priv(ndev); + + return clk_enable(priv->refclk); +} + static const struct dev_pm_ops ravb_dev_pm_ops =3D { SYSTEM_SLEEP_PM_OPS(ravb_suspend, ravb_resume) - RUNTIME_PM_OPS(ravb_runtime_nop, ravb_runtime_nop, NULL) + RUNTIME_PM_OPS(ravb_runtime_suspend, ravb_runtime_resume, NULL) }; =20 static struct platform_driver ravb_driver =3D { --=20 2.39.2