Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4022020pxb; Mon, 8 Feb 2021 06:13:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJyiAf+1dywTRsecWli8n1kYzCMpSDHRhpjJJjCj0nOo2uFgliGVnZ2oKJyQVpTZRDOoPyIu X-Received: by 2002:a17:906:b351:: with SMTP id cd17mr17247775ejb.110.1612793623361; Mon, 08 Feb 2021 06:13:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612793623; cv=none; d=google.com; s=arc-20160816; b=Gm51PBCNicydU64ZioSFx4SWdzf6AiBtR+KiOs4nTboGgU81GjShau1nLHJ6U/Ng7u jh9SX5F+BPkYj2EXadktemUP2hKWOFG7lB/K4EANibDD9/21agTdu5n5/TaJKc/9h57J nrRYXUgGyk34GfdI4lzYsN2DbiEinYSRcj52kkIERTe1AOJKSyNC5b9HbCdDKhSS0voR sFIKnZeALLRsHXQdYLtMQ2UwLHeCPrk0PSmfYOMG1Lh6Xq3kmLmiQhDuozS0eXtHwxWE 3y3MkILfPhjDye6feqiuEFYzeN4IwoDOR8//VFP/DeoRnPT6vTPnOy+LBT4qkw8wsHrF Lhcw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lZXWR714IG1HVzaRcQfAKzUe/91HjAG265LxVW0PSDA=; b=rAJT0qC2oxNP767CvmxEF+NfjdZ3zkVjo4+L9h33KjXRCOS1xQ1Hkc/zmFSt1MyTZf QseBmW1sGjrA1iIGRI3juHktnPvaH/TmhG39J9yTXBlvt8uV8yBdleNK9npaZ9KfH9bX UizlUo247MqBNApD0emawy9ymNI9Tko2hGEBUA/lOqtBCKQHO6cJXRJ+soaxphs3XfX/ zznehDnj9ZUcL9j3doJd+qu2lAo836nw/CZEImmL7dJGfueYvZoslLzEYm7qHs+YUk+1 mPDZFKPTTm43m3WyeWeMn3E2i4GNLOv5WHUD7xh46L5qnkRj0lsDdwAvbXS7O5BULO/N MMsg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k11si9208911ejc.112.2021.02.08.06.13.19; Mon, 08 Feb 2021 06:13:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231538AbhBHOLw (ORCPT + 99 others); Mon, 8 Feb 2021 09:11:52 -0500 Received: from mail.baikalelectronics.com ([87.245.175.226]:57072 "EHLO mail.baikalelectronics.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231974AbhBHN6J (ORCPT ); Mon, 8 Feb 2021 08:58:09 -0500 From: Serge Semin To: Rob Herring , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Johan Hovold , Maxime Ripard , Joao Pinto , Lars Persson , Maxime Coquelin CC: Serge Semin , Serge Semin , Alexey Malahov , Pavel Parkhomenko , Vyacheslav Mitrofanov , , , , , Subject: [PATCH v2 15/24] net: stmmac: Use optional clock request method to get ptp_clk Date: Mon, 8 Feb 2021 16:55:59 +0300 Message-ID: <20210208135609.7685-16-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20210208135609.7685-1-Sergey.Semin@baikalelectronics.ru> References: <20210208135609.7685-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's replace the manual implementation of the optional ptp_clk functionality with method devm_clk_get_optional() provided by the common clock kernel framework. First of all it will be better from maintainability point of view. Secondly by doing so we'll also fix a potential problem, which will come out if the PTP clock has been actually specified, but the clock framework failed to request it. Note since we are switching the code to using the optional common clock API, then there is no need in checking the clk_ptp_ref pointer for being not NULL before calling the clk_prepare_enable() method. The later will correctly handle it. So just discard the conditional statement of priv->plat->clk_ptp_ref pointer value testing in the stmmac_resume() method. Signed-off-by: Serge Semin --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 +-- drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index b371842d9337..4f1bf8f6538b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5289,8 +5289,7 @@ int stmmac_resume(struct device *dev) /* enable the clk previously disabled */ clk_prepare_enable(priv->plat->stmmac_clk); clk_prepare_enable(priv->plat->pclk); - if (priv->plat->clk_ptp_ref) - clk_prepare_enable(priv->plat->clk_ptp_ref); + clk_prepare_enable(priv->plat->clk_ptp_ref); /* reset the phy so that it's ready */ if (priv->mii) stmmac_mdio_reset(priv->mii); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index a66467baf30a..9a7c94622c36 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -586,10 +586,13 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) clk_prepare_enable(plat->pclk); /* Fall-back to main clock in case of no PTP ref is passed */ - plat->clk_ptp_ref = devm_clk_get(&pdev->dev, "ptp_ref"); + plat->clk_ptp_ref = devm_clk_get_optional(&pdev->dev, "ptp_ref"); if (IS_ERR(plat->clk_ptp_ref)) { + rc = PTR_ERR(plat->clk_ptp_ref); + dev_err_probe(&pdev->dev, rc, "Cannot get PTP clock\n"); + goto error_hw_init; + } else if (!plat->clk_ptp_ref) { plat->clk_ptp_rate = clk_get_rate(plat->stmmac_clk); - plat->clk_ptp_ref = NULL; dev_info(&pdev->dev, "PTP uses main clock\n"); } else { plat->clk_ptp_rate = clk_get_rate(plat->clk_ptp_ref); -- 2.29.2