Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1582014rdb; Sat, 2 Dec 2023 01:23:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGsU0NeCIaaQFSkAiGypFZLISxo9HYQULQxzzPOBLd/rfTaCHY5mMBAaqZ5XIS7NYUAw+mz X-Received: by 2002:a05:6a21:3409:b0:18f:97c:978d with SMTP id yn9-20020a056a21340900b0018f097c978dmr1192926pzb.117.1701509028782; Sat, 02 Dec 2023 01:23:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701509028; cv=none; d=google.com; s=arc-20160816; b=zZhTSiOR/dCjhY6qc2PYj10Fb3Oqv7ulhVEsaToei9kx20C7k/fE6qR6vEj+LZ6yUP z3puk7s7pA7HwEgtOIJfOIphFX7Hba3POKSCTywzZCEvtAf80GVp53wAVnF1lIWaUKza 0nGrZFxy2i14kf5l//xYSYeufytiGK6Z75ARTAnIAflvi5t2RfrBfZC7+gLCA3ZUWgnK IOFQe4midxAUAuwx8Q3SLlZX12TRZ21I1YxYEYQmPaz4+QdTa/UWw9uf17CzghtTUeg6 RRDolUuD+Oz94ylKxwDDLVyYTcd0w9KcRokhchkvb2ZjMljAkUWWDiaG5jWKP4e/hK5b VMRA== 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=vyX/lxSXq2Q5RNwAmsKFUuXJAonqdZmX1UmuleUYFkE=; fh=Coc04m6BP/xtf4N8fZzvbRXxYCV30lDt76Ep/wdDSVY=; b=JMys2TZd0f3gdU5i32iXm5Ll7HcXHGhogmCnBYPZZ3QJn++JFPMlWNQcV13EGPb9IY 55NbvYqlq3QQcmj98L6IoFstM+8NJ2cKEMuy1esXejADujQxs8Q3VbaOmcInJqfED2Bh bNYNPCvn4zIoo7u/1GbH51Px4iU37Np6lzeWjZBPh+TepcIbLixbHTc7VS45K+bfNY9L o84sjBmIPH5cZS8zCcyuSZIGnwSiy0hxGqBaUBIB8EYpyFpAg51zN8ujNuS8OTyEG9lp GfLphrep1zPpWc56xTwiVdQb54Q/C04fQoT4KlXCUjpiFbdllofxdKa8o0Ml2sBTLP+4 cXGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rock-chips.com header.s=default header.b="Th2v5iV/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=rock-chips.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id bq19-20020a056a02045300b005c6646565d2si428435pgb.629.2023.12.02.01.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 01:23:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@rock-chips.com header.s=default header.b="Th2v5iV/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=rock-chips.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id A02A180274B5; Sat, 2 Dec 2023 01:23:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231527AbjLBJX2 (ORCPT + 99 others); Sat, 2 Dec 2023 04:23:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230038AbjLBJX1 (ORCPT ); Sat, 2 Dec 2023 04:23:27 -0500 X-Greylist: delayed 314 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sat, 02 Dec 2023 01:23:31 PST Received: from mail-m92244.xmail.ntesmail.com (mail-m92244.xmail.ntesmail.com [103.126.92.244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1D689E; Sat, 2 Dec 2023 01:23:31 -0800 (PST) DKIM-Signature: a=rsa-sha256; b=Th2v5iV/l2L1wbN87SyMQIQyavtk6yH9CCgzrnj4JP6zyjT9Cr47YT2H0osyJzpzE+e2EQcy66wJfupbGmX62VqJxLyQscUwiG9SfnU9mp9YYYoZXw3NHuTTuJxsm/C6V5OQutvvdavOljHCIh0q2UowQNyqNd20SkvEugytRB8=; s=default; c=relaxed/relaxed; d=rock-chips.com; v=1; bh=vyX/lxSXq2Q5RNwAmsKFUuXJAonqdZmX1UmuleUYFkE=; h=date:mime-version:subject:message-id:from; Received: from localhost.localdomain (unknown [58.22.7.114]) by mail-m11876.qiye.163.com (Hmail) with ESMTPA id EE86B3C030D; Sat, 2 Dec 2023 17:18:07 +0800 (CST) From: David Wu To: netdev@vger.kernel.org, sebastian.reichel@collabora.com Cc: davem@davemloft.net, linux-kernel@vger.kernel.org, David Wu Subject: [PATCH] net: ethernet: stmmac: dwmac-rk: Repair the clock handling Date: Sat, 2 Dec 2023 17:18:06 +0800 Message-Id: <20231202091806.179512-1-david.wu@rock-chips.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZQ00aHlZMTkJDT09IHh4YShpVEwETFh oSFyQUDg9ZV1kYEgtZQVlOQ1VJSVVMVUpKT1lXWRYaDxIVHRRZQVlPS0hVSk1PSUxOVUpLS1VKQk tLWQY+ X-HM-Tid: 0a8c29d228ce2eb2kusnee86b3c030d X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6PjY6FRw6Ojw4NAsdQxpPMhIZ N0MKCjJVSlVKTEtKTktDTUNDQ09IVTMWGhIXVR8aDRIfVQwOOwkUGBBWGBMSCwhVGBQWRVlXWRIL WUFZTkNVSUlVTFVKSk9ZV1kIAVlBTE5CSTcG X-Spam-Status: No, score=0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Sat, 02 Dec 2023 01:23:45 -0800 (PST) It's clarier and simpler to replace devm_clk_bulk_get_optional via devm_clk_bulk_get_all. And it may be a different clocks combination for different Socs, so for the clk_mac_speed, it is more correct to obtain the clock directly by its name. Fixes: ea449f7fa0bf ("net: ethernet: stmmac: dwmac-rk: rework optional clock handling") Signed-off-by: David Wu --- .../net/ethernet/stmicro/stmmac/dwmac-rk.c | 83 ++++++++----------- 1 file changed, 33 insertions(+), 50 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c index 382e8de1255d..fff18037e68c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c @@ -39,24 +39,6 @@ struct rk_gmac_ops { u32 regs[]; }; -static const char * const rk_clocks[] = { - "aclk_mac", "pclk_mac", "mac_clk_tx", "clk_mac_speed", -}; - -static const char * const rk_rmii_clocks[] = { - "mac_clk_rx", "clk_mac_ref", "clk_mac_refout", -}; - -enum rk_clocks_index { - RK_ACLK_MAC = 0, - RK_PCLK_MAC, - RK_MAC_CLK_TX, - RK_CLK_MAC_SPEED, - RK_MAC_CLK_RX, - RK_CLK_MAC_REF, - RK_CLK_MAC_REFOUT, -}; - struct rk_priv_data { struct platform_device *pdev; phy_interface_t phy_iface; @@ -73,6 +55,7 @@ struct rk_priv_data { int num_clks; struct clk *clk_mac; struct clk *clk_phy; + struct clk *clk_mac_speed; struct reset_control *phy_reset; @@ -116,12 +99,11 @@ static void px30_set_to_rmii(struct rk_priv_data *bsp_priv) static void px30_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed) { - struct clk *clk_mac_speed = bsp_priv->clks[RK_CLK_MAC_SPEED].clk; struct device *dev = &bsp_priv->pdev->dev; int ret; - if (!clk_mac_speed) { - dev_err(dev, "%s: Missing clk_mac_speed clock\n", __func__); + if (!bsp_priv->clk_mac_speed) { + dev_err(dev, "Missing clk_mac_speed clock\n"); return; } @@ -129,7 +111,7 @@ static void px30_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed) regmap_write(bsp_priv->grf, PX30_GRF_GMAC_CON1, PX30_GMAC_SPEED_10M); - ret = clk_set_rate(clk_mac_speed, 2500000); + ret = clk_set_rate(bsp_priv->clk_mac_speed, 2500000); if (ret) dev_err(dev, "%s: set clk_mac_speed rate 2500000 failed: %d\n", __func__, ret); @@ -137,7 +119,7 @@ static void px30_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed) regmap_write(bsp_priv->grf, PX30_GRF_GMAC_CON1, PX30_GMAC_SPEED_100M); - ret = clk_set_rate(clk_mac_speed, 25000000); + ret = clk_set_rate(bsp_priv->clk_mac_speed, 25000000); if (ret) dev_err(dev, "%s: set clk_mac_speed rate 25000000 failed: %d\n", __func__, ret); @@ -1079,11 +1061,15 @@ static void rk3568_set_to_rmii(struct rk_priv_data *bsp_priv) static void rk3568_set_gmac_speed(struct rk_priv_data *bsp_priv, int speed) { - struct clk *clk_mac_speed = bsp_priv->clks[RK_CLK_MAC_SPEED].clk; struct device *dev = &bsp_priv->pdev->dev; unsigned long rate; int ret; + if (!bsp_priv->clk_mac_speed) { + dev_err(dev, "Missing clk_mac_speed clock\n"); + return; + } + switch (speed) { case 10: rate = 2500000; @@ -1099,7 +1085,7 @@ static void rk3568_set_gmac_speed(struct rk_priv_data *bsp_priv, int speed) return; } - ret = clk_set_rate(clk_mac_speed, rate); + ret = clk_set_rate(bsp_priv->clk_mac_speed, rate); if (ret) dev_err(dev, "%s: set clk_mac_speed rate %ld failed %d\n", __func__, rate, ret); @@ -1385,11 +1371,15 @@ static void rv1126_set_to_rmii(struct rk_priv_data *bsp_priv) static void rv1126_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed) { - struct clk *clk_mac_speed = bsp_priv->clks[RK_CLK_MAC_SPEED].clk; struct device *dev = &bsp_priv->pdev->dev; unsigned long rate; int ret; + if (!bsp_priv->clk_mac_speed) { + dev_err(dev, "Missing clk_mac_speed clock\n"); + return; + } + switch (speed) { case 10: rate = 2500000; @@ -1405,7 +1395,7 @@ static void rv1126_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed) return; } - ret = clk_set_rate(clk_mac_speed, rate); + ret = clk_set_rate(bsp_priv->clk_mac_speed, rate); if (ret) dev_err(dev, "%s: set clk_mac_speed rate %ld failed %d\n", __func__, rate, ret); @@ -1413,11 +1403,15 @@ static void rv1126_set_rgmii_speed(struct rk_priv_data *bsp_priv, int speed) static void rv1126_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed) { - struct clk *clk_mac_speed = bsp_priv->clks[RK_CLK_MAC_SPEED].clk; struct device *dev = &bsp_priv->pdev->dev; unsigned long rate; int ret; + if (!bsp_priv->clk_mac_speed) { + dev_err(dev, "Missing clk_mac_speed clock\n"); + return; + } + switch (speed) { case 10: rate = 2500000; @@ -1430,7 +1424,7 @@ static void rv1126_set_rmii_speed(struct rk_priv_data *bsp_priv, int speed) return; } - ret = clk_set_rate(clk_mac_speed, rate); + ret = clk_set_rate(bsp_priv->clk_mac_speed, rate); if (ret) dev_err(dev, "%s: set clk_mac_speed rate %ld failed %d\n", __func__, rate, ret); @@ -1492,31 +1486,14 @@ static int rk_gmac_clk_init(struct plat_stmmacenet_data *plat) struct rk_priv_data *bsp_priv = plat->bsp_priv; struct device *dev = &bsp_priv->pdev->dev; int phy_iface = bsp_priv->phy_iface; - int i, j, ret; + int ret; bsp_priv->clk_enabled = false; - bsp_priv->num_clks = ARRAY_SIZE(rk_clocks); - if (phy_iface == PHY_INTERFACE_MODE_RMII) - bsp_priv->num_clks += ARRAY_SIZE(rk_rmii_clocks); - - bsp_priv->clks = devm_kcalloc(dev, bsp_priv->num_clks, - sizeof(*bsp_priv->clks), GFP_KERNEL); - if (!bsp_priv->clks) - return -ENOMEM; - - for (i = 0; i < ARRAY_SIZE(rk_clocks); i++) - bsp_priv->clks[i].id = rk_clocks[i]; - - if (phy_iface == PHY_INTERFACE_MODE_RMII) { - for (j = 0; j < ARRAY_SIZE(rk_rmii_clocks); j++) - bsp_priv->clks[i++].id = rk_rmii_clocks[j]; - } - - ret = devm_clk_bulk_get_optional(dev, bsp_priv->num_clks, - bsp_priv->clks); - if (ret) + ret = devm_clk_bulk_get_all(dev, &bsp_priv->clks); + if (ret <= 0) return dev_err_probe(dev, ret, "Failed to get clocks\n"); + bsp_priv->num_clks = ret; /* "stmmaceth" will be enabled by the core */ bsp_priv->clk_mac = devm_clk_get(dev, "stmmaceth"); @@ -1538,6 +1515,12 @@ static int rk_gmac_clk_init(struct plat_stmmacenet_data *plat) clk_set_rate(bsp_priv->clk_phy, 50000000); } + /* get option clock */ + bsp_priv->clk_mac_speed = devm_clk_get(dev, "clk_mac_speed"); + ret = PTR_ERR_OR_ZERO(bsp_priv->clk_mac_speed); + if (ret) + bsp_priv->clk_mac_speed = NULL; + return 0; } -- 2.25.1