Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4036731pxb; Mon, 8 Feb 2021 06:31:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwINgS+1OJ01nkjAbCDRsFiiS9lxqn/Zv7Onfqjjd+MKWF2gSdHCvn2gF+bZbK0IMKdfuLb X-Received: by 2002:a50:c94b:: with SMTP id p11mr17425219edh.388.1612794716284; Mon, 08 Feb 2021 06:31:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612794716; cv=none; d=google.com; s=arc-20160816; b=ByqgL7B6iqDOylkJ1QmzczOgTmy9Ty/TDG3YFnCO45vOdLG/GU48H42/leT6OJf+Ga F783FllcLTEJ2hZMXJPx4kxKUSXaJxdiZX0+ObY47lRWIVEofzWsCtBltBgOLt4VG+Vu vJ6qRRXGPikJpJ/q3/iGoXZfpb9aYUeCdTk0Qe85JpNMZkKKEhXkbTglDWNezgbo+TZt YJcKhdFb6p3G/CTFoWbWe90f5S9KMyj+OAsAFwWHlzfey5Bbto8Ts73zP2kaemrTJUAy BMuTIVxc+yFi6bqPGhTPyHSPYi+xU9iQlwYJdchsKLH6TpwCL9y6d/nM4UOiVr8H78Rr n9Pg== 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=J8uFEFfIOv8Xl7M7Pk8ex5HjfQu2Q3c2Pn9QR5SyLus=; b=MCGnpgjr0dG3ahvRpjB6ZGU3xfxzJm9INA44Yt7g9YrVIqXk+mxlfeZyRdk5TIeacn Ar5GQFsgw+obF1I0Uq4wkTZi5wirZgqvh7v9msqo9NzdEHOJpeZLUS2WA0X06EF3P/9D qGSU9KpBL+zpVlE05/4o0zj6Coab3yXxBmWU2YVRKJ5TLOFA7sZdTwKkHIWBCnWDyTrN rV/WnnAsZcqrYBh/Aq/Sgf1N3A/u3muoRDbG8b1oCQo3FEc1kWreCEtFTsQYjhY3GAL1 ryLbUqG58iZXNmThTSRRgfz4iUwuKYrtqpWX0r3N+lp2O8UL19kuy04AY/JxdvoQw58n clYQ== 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 g17si11657049edb.473.2021.02.08.06.31.15; Mon, 08 Feb 2021 06:31:56 -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 S231221AbhBHOaL (ORCPT + 99 others); Mon, 8 Feb 2021 09:30:11 -0500 Received: from mail.baikalelectronics.com ([87.245.175.226]:57454 "EHLO mail.baikalelectronics.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232417AbhBHOIG (ORCPT ); Mon, 8 Feb 2021 09:08:06 -0500 From: Serge Semin To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Joao Pinto , Jose Abreu , Maxime Coquelin CC: Serge Semin , Serge Semin , Alexey Malahov , Pavel Parkhomenko , Vyacheslav Mitrofanov , Russell King , Andrew Lunn , Heiner Kallweit , , , , 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 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 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; } -- 2.29.2