From patchwork Mon Feb 8 14:03:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 12075585 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBE3FC433DB for ; Mon, 8 Feb 2021 14:09:46 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 67BDF64D9F for ; Mon, 8 Feb 2021 14:09:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 67BDF64D9F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baikalelectronics.ru Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EO4/laA9PoL7y/qgPMIcvewk0GWHCPRBJBGuFQ8DOmU=; b=ynWgYCmmupjbem+kwM/yuv6ET un31hPzfMkNlJAii5yUP8aMLdo5pQRqR4icPdAHb1yxK3oJY0w8DUgzCTXxcX+hkj+6ritalK10U6 69jq/jFXfHir9YDOXkraOGhHrGHMToghCGcgxs+zReLCrBPG+/7o9oK07v09KLR2g0ORh4BMSfext 3QTRVrgSbnIvDhuAMG3l6Nr2dllPLslpslqvY0I2x2nUgQc+qDAlOC1gbspOm/Q2vtLfJ1h13Fd85 fwemoY2GtobG3kbsxHpE1RY9xzgwdhAN9QaINdgAP6mDAxKNjbhBVxm2ZRG85VKuZvBeBGuIj/IoN yC94d7HAA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l97Cj-0004wD-Uf; Mon, 08 Feb 2021 14:07:53 +0000 Received: from mail.baikalelectronics.com ([87.245.175.226] helo=mail.baikalelectronics.ru) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l978w-00036M-BO for linux-arm-kernel@lists.infradead.org; Mon, 08 Feb 2021 14:04:08 +0000 From: Serge Semin To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Joao Pinto , Jose Abreu , Maxime Coquelin Subject: [PATCH 18/20] net: stmmac: Move PTP clock enabling to PTP-init method Date: Mon, 8 Feb 2021 17:03:39 +0300 Message-ID: <20210208140341.9271-19-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20210208140341.9271-1-Sergey.Semin@baikalelectronics.ru> References: <20210208140341.9271-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210208_090358_735286_60CFA8D9 X-CRM114-Status: GOOD ( 16.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Lunn , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Russell King , Serge Semin , Alexey Malahov , Serge Semin , Vyacheslav Mitrofanov , Pavel Parkhomenko , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Heiner Kallweit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org That clock is purely dedicated for the PTP feature of DW *MAC. From the driver readability and maintainability point of the view it's better to have it enabled/disable in the PTP interface init/release methods. Let's do that by moving the clock prepare/enable procedure invocation to the stmmac_init_ptp() method and adding the clock disable/unprepare function call to stmmac_release_ptp(). Since the clock is now handled in the framework of the PTP-interface related initializers/de-initializers we need to call the stmmac_release_ptp() method in the HW-setup antagonist - stmmac_hw_teardown(). Thus call the later one when the network device is closed to clean the PTP-interface too. Signed-off-by: Serge Semin --- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index f3ced94b3f4e..d6446aa712e1 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -761,10 +761,18 @@ static int stmmac_hwtstamp_get(struct net_device *dev, struct ifreq *ifr) static int stmmac_init_ptp(struct stmmac_priv *priv) { bool xmac = priv->plat->has_gmac4 || priv->plat->has_xgmac; + int ret; if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) return -EOPNOTSUPP; + ret = clk_prepare_enable(priv->plat->clk_ptp_ref); + if (ret) { + netdev_warn(priv->dev, "failed to enable PTP ref-clock: %d\n", + ret); + return ret; + } + priv->adv_ts = 0; /* Check if adv_ts can be enabled for dwmac 4.x / xgmac core */ if (xmac && priv->dma_cap.atime_stamp) @@ -790,8 +798,12 @@ static int stmmac_init_ptp(struct stmmac_priv *priv) static void stmmac_release_ptp(struct stmmac_priv *priv) { - clk_disable_unprepare(priv->plat->clk_ptp_ref); + if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) + return; + stmmac_ptp_unregister(priv); + + clk_disable_unprepare(priv->plat->clk_ptp_ref); } /** @@ -2716,10 +2728,6 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) stmmac_mmc_setup(priv); if (init_ptp) { - ret = clk_prepare_enable(priv->plat->clk_ptp_ref); - if (ret < 0) - netdev_warn(priv->dev, "failed to enable PTP reference clock: %d\n", ret); - ret = stmmac_init_ptp(priv); if (ret == -EOPNOTSUPP) netdev_warn(priv->dev, "PTP not supported by HW\n"); @@ -2784,7 +2792,7 @@ static void stmmac_hw_teardown(struct net_device *dev) { struct stmmac_priv *priv = netdev_priv(dev); - clk_disable_unprepare(priv->plat->clk_ptp_ref); + stmmac_release_ptp(priv); } /** @@ -2965,6 +2973,9 @@ static int stmmac_release(struct net_device *dev) /* Stop TX/RX DMA and clear the descriptors */ stmmac_stop_all_dma(priv); + /* Cleanup HW setup */ + stmmac_hw_teardown(dev); + /* Release and free the Rx/Tx resources */ free_dma_desc_resources(priv); @@ -2973,8 +2984,6 @@ static int stmmac_release(struct net_device *dev) netif_carrier_off(dev); - stmmac_release_ptp(priv); - return 0; }