From patchwork Mon Mar 1 10:25:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joakim Zhang X-Patchwork-Id: 389030 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 5C5BDC433E0 for ; Mon, 1 Mar 2021 10:27:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0909C600CC for ; Mon, 1 Mar 2021 10:27:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234356AbhCAK1H (ORCPT ); Mon, 1 Mar 2021 05:27:07 -0500 Received: from mail-vi1eur05on2057.outbound.protection.outlook.com ([40.107.21.57]:24961 "EHLO EUR05-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234280AbhCAK0m (ORCPT ); Mon, 1 Mar 2021 05:26:42 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VDHMxEgMx5HWXaHix+I7vbbIaGVcAWPw4MPDwHdHYBYdepbVp3xsNI6kUKpkcTUVLAGmZz35tpFPci16rKMhUD5Rl/rfHq4BIQg5WMyVuHAB6Jko/ZG2rE7etxPdsVnlgLjT63ZvftwbZS8sC4iaqim8CjOIMAhpixXX2+A6zMkZrQWKFVFJdd2Ai6FHK2DcAbaKHpJ8/4vTfxF5VJr9217VkHdx006XmkokbikNiDZVnBH6YZLkYJR+KzQ8GMhSPkeR+hlmn9QjBD3ydGh8U5Jy52ZVVYFNMdL6wkp/TGHQddYDgiXRazt29jLSLzaFHkSMeoyZiXD0Fb39Zx/PBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v3X6/J8WhEgmLeMzc8V9xRYMsQ18+O53uzRfM49YCnE=; b=eyKp6YYpBoZEuhuAb8iVB7yJrAWfryrlFkrc/wdMybRSNwAnzuSUwfzhi+Nwr0w2tgS6Y7GPyKjvHigyR4u0CUW2zrcS3/qK/fKcLifxoV6tknZRexyqFvSo3tz/mpvPlulnxlTHa7e0s4zvykUxR4cSIjC3eyb5NCenWZBX3Rf/aUNNfCQaheMvtfVTAHSiQ4CuQBkZfD1JG2NkmgH+Z8rkXooJgDdQaI05NMMyw76ikXz0XldlyQQfDdNBwAiMBSEZ5hB10xXhy7ZjFTV+4SukV8ctghahsM1mSZubSO45huiP8efJ12ODf1fmCzmvNCzwGbaDJO783koIfe42Mw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v3X6/J8WhEgmLeMzc8V9xRYMsQ18+O53uzRfM49YCnE=; b=VoWKgWDRqHYlUSEL3ZDiIRB0b5oeFVtD9TuImwgwGaWerrf27GVSegeQr/ycrxSNao8Rt84Mup/hQa59GwY35G2+3xwof2lWZvZhBejpG23I8y7X080lzbyoBS7X2xwONqc0eDJjTb65CoZE7OqG5dgMuhWlcbjvTc9SklX303g= Authentication-Results: st.com; dkim=none (message not signed) header.d=none;st.com; dmarc=none action=none header.from=nxp.com; Received: from DB8PR04MB6795.eurprd04.prod.outlook.com (2603:10a6:10:fa::15) by DB7PR04MB4953.eurprd04.prod.outlook.com (2603:10a6:10:13::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.28; Mon, 1 Mar 2021 10:25:17 +0000 Received: from DB8PR04MB6795.eurprd04.prod.outlook.com ([fe80::7d13:2d65:d6f7:b978]) by DB8PR04MB6795.eurprd04.prod.outlook.com ([fe80::7d13:2d65:d6f7:b978%4]) with mapi id 15.20.3890.028; Mon, 1 Mar 2021 10:25:17 +0000 From: Joakim Zhang To: peppe.cavallaro@st.com, alexandre.torgue@st.com, joabreu@synopsys.com, davem@davemloft.net, kuba@kernel.org, f.fainelli@gmail.com, andrew@lunn.ch Cc: linux-imx@nxp.com, netdev@vger.kernel.org Subject: [RFC V2 resend net-next 1/3] net: stmmac: add clocks management for gmac driver Date: Mon, 1 Mar 2021 18:25:27 +0800 Message-Id: <20210301102529.18573-2-qiangqing.zhang@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210301102529.18573-1-qiangqing.zhang@nxp.com> References: <20210301102529.18573-1-qiangqing.zhang@nxp.com> X-Originating-IP: [119.31.174.71] X-ClientProxiedBy: HK2PR04CA0045.apcprd04.prod.outlook.com (2603:1096:202:14::13) To DB8PR04MB6795.eurprd04.prod.outlook.com (2603:10a6:10:fa::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (119.31.174.71) by HK2PR04CA0045.apcprd04.prod.outlook.com (2603:1096:202:14::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19 via Frontend Transport; Mon, 1 Mar 2021 10:25:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: fcb1585b-5367-4fe9-1019-08d8dc9c4ec8 X-MS-TrafficTypeDiagnostic: DB7PR04MB4953: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2276; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HD7n5z1ZYOKwUv+3Lgg2NO2NKfa2kkfj5mEdf+7k6icRUi046z6GThzFhLTmJK9CRpVtjsOchu5ZaqGDiMTZszku8xHFscfKy5AqoFfB37ENmIEkrAIr1OJujr03+C7BLTdxGNsLQeE04uVpyfOTNCVlrPKb2hHyu+hrD/gD0muip5VnVGV4rC+5arzdNSd5MzAu7vIkJxCO4iAnjx0fo2fPiA42TfMWnHOtYns+5a5lWCbdRAf5H2GTNhg7h5kIJ6ROBLxIxUXNRyT/avnirZAm5ta1oJoDZDrNPEM/x4z37TLW3RthuK0EtWydBiezFWiAZR+En5xTzvXfhJgb8DUw73nyjO2Tf4pzTFO4Lq0q6s2cWFBsfesG6HqSSIEOt5GRU+cXtzNtopmPZD3VWJzGEA5jYh/Rf99zdNdePa1dDtx4QezlZ7Dw2FZ8SsuM2mNvEmjxbolIqCC29suullCbnm94aYzjNdibMK1BpHph31WKSIhrpo5hEr/1BZk8BOm6uXeE7ODqm8uDWhuK/JUyO4zPwNk05n8k9G5H5rWTINufFuDuR9geigPDKgdo8SwzNQdGo7V3HKLrI8MeIw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB8PR04MB6795.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(39860400002)(136003)(376002)(366004)(346002)(5660300002)(6666004)(6512007)(30864003)(2906002)(1076003)(86362001)(52116002)(6506007)(36756003)(478600001)(6486002)(26005)(69590400012)(186003)(66476007)(8676002)(316002)(16526019)(4326008)(2616005)(956004)(83380400001)(8936002)(66556008)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: QrgKILqgt0QmhDV4OIvBBoQrzeVweLD7fH5i6O0q3OV/mn957HxzrCqDFQXcVK1hI1Jj7sNiPsL4E1SMZnbljd+l5n4dOEp1bP2c2HJ/hBeBMugmw+hk7oUZHDItIsfsTjhIVGrf7ZpWRUAvdkkGXSOfoiBX+ptVTWpfCrWT3pUVZdgvWIwggx6tWIEPqJD5fT63uV6MWT6puz5D6C+U7S48SzGas0O5qMDgn0YcsGiSr6c/zonU+tyKxj0T5z0CrcNIzpZ297GQejkUEqLpg624z0jWKjVEG6BPCSCQllGEUoytRaloUluK1hQNzpFlEfI39+pydjp7WEVd8zx2ApHE4gVE+bl9QSvzsm0AgNDa4TbihJ1/9ihllNj9EcPf+8s6QQ+hTZqmZIbp6wpw78XaFlNQ4nb91UexxXw/2kvoMhSfH0UEijSfM4cctw6t1onB3fB7J+vPQbsEzhtnFomb2M5aDnMK6y7hnYXT+HWnq0iIOrofg2zUG2EhMgrW4d9WpkiBIHKg87Y8voyMK/X1BXRTE0SLP/73ZnFyN7xXY3f38C1MkT3pazSC6GqT28sdw3v9TMOcZ3vcukrCXAcGphyZ6qcotln5EBnm7sMdNnmzGRln4xHHyX+Xxr7v3lOGgfa+epcTgrX/Ce0cmFDte5kFU114cXRHmRnpMSvMS88ly+iKTS6m3RgcACaocKW2gi1wlwX1PIzSKza3/l4RyDMLjwkfcFa7dUXVmiWl2MHwkV61mYNcplMVgTIJuGS+7a1q9Euv05bTPD4aw3fgRLb+maDrxt7cWqmA2nL80wodu0FibwoEM97172FCUO42sb4nmhxTRXCgDiNQBACH7YWkt8ksB2Ka3uWi9KG0l2tkGEJB51lbOoCHbmecOcrINIEabjb5pWh4nBoiLTv7iPQOjM/dxTKEL9Y7yQJn76YbGIupmeWE0JzZZfG28JvfMxgDlo5Ee7+gQZNTCjobfj7tsGV2KbQiP+YrHnyviAiQ4ZlcdpjWXZ5koCjmdNd3gBNVkN6qV7MNrrhaUMDOx3J5Jf1ZYFXjRwh9oq/tHuxfAh96eMKtYEQPpbsdj7O0bOsSQjb43zEe4K/3t3ZUo8xn25JkWLgTCL54P3I/P4DvX9t3DQ5U4gh9RQjY4VVsFsoAsnzR+8bMiDYFcNSn2EcC5py9Pwa9M9TdWi5TtqLDDSeI6aPawO8zV2YSmeHtlBaPC5AhBaYTX8EgGBlgH2wmW2s438blXpgFaM3tC6wkKpUAuOceptFkkA/VnKvst6WwnsvAGQcDB2d9ftRarWrxy023vKcB7nkkBKpA/u1x5Kuxv098ilRRddzB X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fcb1585b-5367-4fe9-1019-08d8dc9c4ec8 X-MS-Exchange-CrossTenant-AuthSource: DB8PR04MB6795.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2021 10:25:16.9739 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZlUsOqhFBG5xKXbNfZ1Qpl2MZaoXZfg6LKyQSIaqptnPg9OLzqhFgF2oYgqy2FABCC96l8WJUcI7FlKp3CK/kw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4953 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch intends to add clocks management for stmmac driver: If CONFIG_PM enabled: 1. Keep clocks disabled after driver probed. 2. Enable clocks when up the net device, and disable clocks when down the net device. If CONFIG_PM disabled: Keep clocks always enabled after driver probed. Note: 1. It is fine for ethtool, since the way of implementing ethtool_ops::begin in stmmac is only can be accessed when interface is enabled, so the clocks are ticked. 2. The MDIO bus has a different life cycle to the MAC, need ensure clocks are enabled when _mdio_read/write() need clocks, because these functions can be called while the interface it not opened. Signed-off-by: Joakim Zhang Reviewed-by: Andrew Lunn --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 + .../net/ethernet/stmicro/stmmac/stmmac_main.c | 75 +++++++++-- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 123 ++++++++++++++---- .../ethernet/stmicro/stmmac/stmmac_platform.c | 24 +++- 4 files changed, 184 insertions(+), 39 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index e553b9a1f785..10e8ae8e2d58 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -272,6 +272,7 @@ void stmmac_disable_eee_mode(struct stmmac_priv *priv); bool stmmac_eee_init(struct stmmac_priv *priv); int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt); int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size); +int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled); #if IS_ENABLED(CONFIG_STMMAC_SELFTESTS) void stmmac_selftest_run(struct net_device *dev, diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 26b971cd4da5..b4bc1c2104df 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #ifdef CONFIG_DEBUG_FS @@ -113,6 +114,28 @@ static void stmmac_exit_fs(struct net_device *dev); #define STMMAC_COAL_TIMER(x) (ns_to_ktime((x) * NSEC_PER_USEC)) +int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled) +{ + int ret = 0; + + if (enabled) { + ret = clk_prepare_enable(priv->plat->stmmac_clk); + if (ret) + return ret; + ret = clk_prepare_enable(priv->plat->pclk); + if (ret) { + clk_disable_unprepare(priv->plat->stmmac_clk); + return ret; + } + } else { + clk_disable_unprepare(priv->plat->stmmac_clk); + clk_disable_unprepare(priv->plat->pclk); + } + + return ret; +} +EXPORT_SYMBOL_GPL(stmmac_bus_clks_config); + /** * stmmac_verify_args - verify the driver parameters. * Description: it checks the driver parameters and set a default in case of @@ -2800,6 +2823,12 @@ static int stmmac_open(struct net_device *dev) u32 chan; int ret; + ret = pm_runtime_get_sync(priv->device); + if (ret < 0) { + pm_runtime_put_noidle(priv->device); + return ret; + } + if (priv->hw->pcs != STMMAC_PCS_TBI && priv->hw->pcs != STMMAC_PCS_RTBI && priv->hw->xpcs == NULL) { @@ -2808,7 +2837,7 @@ static int stmmac_open(struct net_device *dev) netdev_err(priv->dev, "%s: Cannot attach to PHY (error: %d)\n", __func__, ret); - return ret; + goto init_phy_error; } } @@ -2924,6 +2953,8 @@ static int stmmac_open(struct net_device *dev) free_dma_desc_resources(priv); dma_desc_error: phylink_disconnect_phy(priv->phylink); +init_phy_error: + pm_runtime_put(priv->device); return ret; } @@ -2974,6 +3005,8 @@ static int stmmac_release(struct net_device *dev) stmmac_release_ptp(priv); + pm_runtime_put(priv->device); + return 0; } @@ -4624,6 +4657,12 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vi bool is_double = false; int ret; + ret = pm_runtime_get_sync(priv->device); + if (ret < 0) { + pm_runtime_put_noidle(priv->device); + return ret; + } + if (be16_to_cpu(proto) == ETH_P_8021AD) is_double = true; @@ -4632,10 +4671,15 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vi if (priv->hw->num_vlan) { ret = stmmac_del_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, vid); if (ret) - return ret; + goto del_vlan_error; } - return stmmac_vlan_update(priv, is_double); + ret = stmmac_vlan_update(priv, is_double); + +del_vlan_error: + pm_runtime_put(priv->device); + + return ret; } static const struct net_device_ops stmmac_netdev_ops = { @@ -5074,6 +5118,10 @@ int stmmac_dvr_probe(struct device *device, stmmac_check_pcs_mode(priv); + pm_runtime_get_noresume(device); + pm_runtime_set_active(device); + pm_runtime_enable(device); + if (priv->hw->pcs != STMMAC_PCS_TBI && priv->hw->pcs != STMMAC_PCS_RTBI) { /* MDIO bus Registration */ @@ -5111,6 +5159,11 @@ int stmmac_dvr_probe(struct device *device, stmmac_init_fs(ndev); #endif + /* Let pm_runtime_put() disable the clocks. + * If CONFIG_PM is not enabled, the clocks will stay powered. + */ + pm_runtime_put(device); + return ret; error_serdes_powerup: @@ -5125,6 +5178,7 @@ int stmmac_dvr_probe(struct device *device, stmmac_napi_del(ndev); error_hw_init: destroy_workqueue(priv->wq); + stmmac_bus_clks_config(priv, false); return ret; } @@ -5157,8 +5211,8 @@ int stmmac_dvr_remove(struct device *dev) phylink_destroy(priv->phylink); if (priv->plat->stmmac_rst) reset_control_assert(priv->plat->stmmac_rst); - clk_disable_unprepare(priv->plat->pclk); - clk_disable_unprepare(priv->plat->stmmac_clk); + pm_runtime_put(dev); + pm_runtime_disable(dev); if (priv->hw->pcs != STMMAC_PCS_TBI && priv->hw->pcs != STMMAC_PCS_RTBI) stmmac_mdio_unregister(ndev); @@ -5181,6 +5235,7 @@ int stmmac_suspend(struct device *dev) struct net_device *ndev = dev_get_drvdata(dev); struct stmmac_priv *priv = netdev_priv(ndev); u32 chan; + int ret; if (!ndev || !netif_running(ndev)) return 0; @@ -5224,8 +5279,9 @@ int stmmac_suspend(struct device *dev) pinctrl_pm_select_sleep_state(priv->device); /* Disable clock in case of PWM is off */ clk_disable_unprepare(priv->plat->clk_ptp_ref); - clk_disable_unprepare(priv->plat->pclk); - clk_disable_unprepare(priv->plat->stmmac_clk); + ret = pm_runtime_force_suspend(dev); + if (ret) + return ret; } mutex_unlock(&priv->lock); @@ -5289,8 +5345,9 @@ int stmmac_resume(struct device *dev) } else { pinctrl_pm_select_default_state(priv->device); /* enable the clk previously disabled */ - clk_prepare_enable(priv->plat->stmmac_clk); - clk_prepare_enable(priv->plat->pclk); + ret = pm_runtime_force_resume(dev); + if (ret) + return ret; if (priv->plat->clk_ptp_ref) clk_prepare_enable(priv->plat->clk_ptp_ref); /* reset the phy so that it's ready */ diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c index d64116e0543e..4950e7ba3716 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -85,23 +86,31 @@ static int stmmac_xgmac2_mdio_read(struct mii_bus *bus, int phyaddr, int phyreg) unsigned int mii_address = priv->hw->mii.addr; unsigned int mii_data = priv->hw->mii.data; u32 tmp, addr, value = MII_XGMAC_BUSY; - int ret; + int ret, data = 0; + + ret = pm_runtime_get_sync(priv->device); + if (ret < 0) { + pm_runtime_put_noidle(priv->device); + return ret; + } /* Wait until any existing MII operation is complete */ if (readl_poll_timeout(priv->ioaddr + mii_data, tmp, - !(tmp & MII_XGMAC_BUSY), 100, 10000)) - return -EBUSY; + !(tmp & MII_XGMAC_BUSY), 100, 10000)) { + ret = -EBUSY; + goto err_disable_clks; + } if (phyreg & MII_ADDR_C45) { phyreg &= ~MII_ADDR_C45; ret = stmmac_xgmac2_c45_format(priv, phyaddr, phyreg, &addr); if (ret) - return ret; + goto err_disable_clks; } else { ret = stmmac_xgmac2_c22_format(priv, phyaddr, phyreg, &addr); if (ret) - return ret; + goto err_disable_clks; value |= MII_XGMAC_SADDR; } @@ -112,8 +121,10 @@ static int stmmac_xgmac2_mdio_read(struct mii_bus *bus, int phyaddr, int phyreg) /* Wait until any existing MII operation is complete */ if (readl_poll_timeout(priv->ioaddr + mii_data, tmp, - !(tmp & MII_XGMAC_BUSY), 100, 10000)) - return -EBUSY; + !(tmp & MII_XGMAC_BUSY), 100, 10000)) { + ret = -EBUSY; + goto err_disable_clks; + } /* Set the MII address register to read */ writel(addr, priv->ioaddr + mii_address); @@ -121,11 +132,22 @@ static int stmmac_xgmac2_mdio_read(struct mii_bus *bus, int phyaddr, int phyreg) /* Wait until any existing MII operation is complete */ if (readl_poll_timeout(priv->ioaddr + mii_data, tmp, - !(tmp & MII_XGMAC_BUSY), 100, 10000)) - return -EBUSY; + !(tmp & MII_XGMAC_BUSY), 100, 10000)) { + ret = -EBUSY; + goto err_disable_clks; + } /* Read the data from the MII data register */ - return readl(priv->ioaddr + mii_data) & GENMASK(15, 0); + data = (int)readl(priv->ioaddr + mii_data) & GENMASK(15, 0); + + pm_runtime_put(priv->device); + + return data; + +err_disable_clks: + pm_runtime_put(priv->device); + + return ret; } static int stmmac_xgmac2_mdio_write(struct mii_bus *bus, int phyaddr, @@ -138,21 +160,29 @@ static int stmmac_xgmac2_mdio_write(struct mii_bus *bus, int phyaddr, u32 addr, tmp, value = MII_XGMAC_BUSY; int ret; + ret = pm_runtime_get_sync(priv->device); + if (ret < 0) { + pm_runtime_put_noidle(priv->device); + return ret; + } + /* Wait until any existing MII operation is complete */ if (readl_poll_timeout(priv->ioaddr + mii_data, tmp, - !(tmp & MII_XGMAC_BUSY), 100, 10000)) - return -EBUSY; + !(tmp & MII_XGMAC_BUSY), 100, 10000)) { + ret = -EBUSY; + goto err_disable_clks; + } if (phyreg & MII_ADDR_C45) { phyreg &= ~MII_ADDR_C45; ret = stmmac_xgmac2_c45_format(priv, phyaddr, phyreg, &addr); if (ret) - return ret; + goto err_disable_clks; } else { ret = stmmac_xgmac2_c22_format(priv, phyaddr, phyreg, &addr); if (ret) - return ret; + goto err_disable_clks; value |= MII_XGMAC_SADDR; } @@ -164,16 +194,23 @@ static int stmmac_xgmac2_mdio_write(struct mii_bus *bus, int phyaddr, /* Wait until any existing MII operation is complete */ if (readl_poll_timeout(priv->ioaddr + mii_data, tmp, - !(tmp & MII_XGMAC_BUSY), 100, 10000)) - return -EBUSY; + !(tmp & MII_XGMAC_BUSY), 100, 10000)) { + ret = -EBUSY; + goto err_disable_clks; + } /* Set the MII address register to write */ writel(addr, priv->ioaddr + mii_address); writel(value, priv->ioaddr + mii_data); /* Wait until any existing MII operation is complete */ - return readl_poll_timeout(priv->ioaddr + mii_data, tmp, - !(tmp & MII_XGMAC_BUSY), 100, 10000); + ret = readl_poll_timeout(priv->ioaddr + mii_data, tmp, + !(tmp & MII_XGMAC_BUSY), 100, 10000); + +err_disable_clks: + pm_runtime_put(priv->device); + + return ret; } /** @@ -193,9 +230,15 @@ static int stmmac_mdio_read(struct mii_bus *bus, int phyaddr, int phyreg) unsigned int mii_address = priv->hw->mii.addr; unsigned int mii_data = priv->hw->mii.data; u32 value = MII_BUSY; - int data = 0; + int ret, data = 0; u32 v; + ret = pm_runtime_get_sync(priv->device); + if (ret < 0) { + pm_runtime_put_noidle(priv->device); + return ret; + } + value |= (phyaddr << priv->hw->mii.addr_shift) & priv->hw->mii.addr_mask; value |= (phyreg << priv->hw->mii.reg_shift) & priv->hw->mii.reg_mask; @@ -216,20 +259,31 @@ static int stmmac_mdio_read(struct mii_bus *bus, int phyaddr, int phyreg) } if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY), - 100, 10000)) - return -EBUSY; + 100, 10000)) { + ret = -EBUSY; + goto err_disable_clks; + } writel(data, priv->ioaddr + mii_data); writel(value, priv->ioaddr + mii_address); if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY), - 100, 10000)) - return -EBUSY; + 100, 10000)) { + ret = -EBUSY; + goto err_disable_clks; + } /* Read the data from the MII data register */ data = (int)readl(priv->ioaddr + mii_data) & MII_DATA_MASK; + pm_runtime_put(priv->device); + return data; + +err_disable_clks: + pm_runtime_put(priv->device); + + return ret; } /** @@ -247,10 +301,16 @@ static int stmmac_mdio_write(struct mii_bus *bus, int phyaddr, int phyreg, struct stmmac_priv *priv = netdev_priv(ndev); unsigned int mii_address = priv->hw->mii.addr; unsigned int mii_data = priv->hw->mii.data; + int ret, data = phydata; u32 value = MII_BUSY; - int data = phydata; u32 v; + ret = pm_runtime_get_sync(priv->device); + if (ret < 0) { + pm_runtime_put_noidle(priv->device); + return ret; + } + value |= (phyaddr << priv->hw->mii.addr_shift) & priv->hw->mii.addr_mask; value |= (phyreg << priv->hw->mii.reg_shift) & priv->hw->mii.reg_mask; @@ -275,16 +335,23 @@ static int stmmac_mdio_write(struct mii_bus *bus, int phyaddr, int phyreg, /* Wait until any existing MII operation is complete */ if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY), - 100, 10000)) - return -EBUSY; + 100, 10000)) { + ret = -EBUSY; + goto err_disable_clks; + } /* Set the MII address register to write */ writel(data, priv->ioaddr + mii_data); writel(value, priv->ioaddr + mii_address); /* Wait until any existing MII operation is complete */ - return readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY), - 100, 10000); + ret = readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY), + 100, 10000); + +err_disable_clks: + pm_runtime_put(priv->device); + + return ret; } /** diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index 6dc9f10414e4..a70b0bc84b2a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -744,10 +744,30 @@ static int stmmac_pltfr_resume(struct device *dev) return stmmac_resume(dev); } + +static int stmmac_runtime_suspend(struct device *dev) +{ + struct net_device *ndev = dev_get_drvdata(dev); + struct stmmac_priv *priv = netdev_priv(ndev); + + stmmac_bus_clks_config(priv, false); + + return 0; +} + +static int stmmac_runtime_resume(struct device *dev) +{ + struct net_device *ndev = dev_get_drvdata(dev); + struct stmmac_priv *priv = netdev_priv(ndev); + + return stmmac_bus_clks_config(priv, true); +} #endif /* CONFIG_PM_SLEEP */ -SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops, stmmac_pltfr_suspend, - stmmac_pltfr_resume); +const struct dev_pm_ops stmmac_pltfr_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(stmmac_pltfr_suspend, stmmac_pltfr_resume) + SET_RUNTIME_PM_OPS(stmmac_runtime_suspend, stmmac_runtime_resume, NULL) +}; EXPORT_SYMBOL_GPL(stmmac_pltfr_pm_ops); MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet platform support"); From patchwork Mon Mar 1 10:25:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joakim Zhang X-Patchwork-Id: 389029 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 1EC30C433DB for ; Mon, 1 Mar 2021 10:28:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA72560232 for ; Mon, 1 Mar 2021 10:28:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234366AbhCAK2U (ORCPT ); Mon, 1 Mar 2021 05:28:20 -0500 Received: from mail-am6eur05on2075.outbound.protection.outlook.com ([40.107.22.75]:45056 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234359AbhCAK1K (ORCPT ); Mon, 1 Mar 2021 05:27:10 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BvltnSwUE0ZzyS3Pnrs0E2Uu5As8AHFso1gVru/XNA3tyh10QYJ+3NBnBdpghisOvn4oedYVRBwXGuNByCsx1Q6tvOjEaXJltnl2kQMJUJer5GGnfJ+xyhvmpXvNPJan8LyU6uPly3yuWKzNMHXgrtBNScJBIyojv1VvgP+LwzykFH2ok8Q7sFaRWuQ225GYETRU0b4MKtU1/13Z7zpy9nCvu5ybky8pGVQSeCaJhq3+1Vryz4jCGBuhPKdzwj425Q7YAnTXrVyDxyJQ07kSgdgkPxPG4/+DZtDnJdofbUOFmkSqYpDleNijfjNmJMuFPWDNxZBVtE4Kl6Kv9QC5dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MRYrrDDiGe4l9VJ3X+XpaO71UTe9l69v2sCjPWw2Jew=; b=Str7UynqwvpIO7Ch55zxZOmsMUIBc1F3Z7aRaluTVgmDrJY/qyK2JkaLJmo1w4ECD3HH2GJdLPHx/QzjVLJNSwwaDKu0fSpKb9bDCGzMzWjdr++adArjXjHumwz8tZMYcl8+wk3ALW/2mw4JyRzUjkj5J1vaKlrTop1I0h22Gxc/PGFCqLG+fnm+0/cA0CxUAUHS8ENUUh7ODcts4ZqIMUT5EJprj8OlacK6K236U9HL2jY14CSTkEQIYtfL6pQI2+4fPNcX7XgphlVlqstTTLFthL1p18tOXqYrUvQxtE//UamUjISXF+ITB4R3kNHLSgkqRB0t21rXMTZSmYc7+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MRYrrDDiGe4l9VJ3X+XpaO71UTe9l69v2sCjPWw2Jew=; b=dR/5vyu/EQ0hyCAcy0tzWZTkAgKs1dSFvmXp/RLMi8GS/WusooCSibQxQ32zzVoRcLsYERINz6LFVC63QZ6/50U/YXFoXzbvUE+6sR0/QzwkGDAyXfYU6pmTvd8NYaz0jjTIlsLujP8TB04nPQ8wWdwI/c0vL3lZFftm0gacwuk= Authentication-Results: st.com; dkim=none (message not signed) header.d=none;st.com; dmarc=none action=none header.from=nxp.com; Received: from DB8PR04MB6795.eurprd04.prod.outlook.com (2603:10a6:10:fa::15) by DB7PR04MB4953.eurprd04.prod.outlook.com (2603:10a6:10:13::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.28; Mon, 1 Mar 2021 10:25:20 +0000 Received: from DB8PR04MB6795.eurprd04.prod.outlook.com ([fe80::7d13:2d65:d6f7:b978]) by DB8PR04MB6795.eurprd04.prod.outlook.com ([fe80::7d13:2d65:d6f7:b978%4]) with mapi id 15.20.3890.028; Mon, 1 Mar 2021 10:25:20 +0000 From: Joakim Zhang To: peppe.cavallaro@st.com, alexandre.torgue@st.com, joabreu@synopsys.com, davem@davemloft.net, kuba@kernel.org, f.fainelli@gmail.com, andrew@lunn.ch Cc: linux-imx@nxp.com, netdev@vger.kernel.org Subject: [RFC V2 resend net-next 2/3] net: stmmac: add platform level clocks management Date: Mon, 1 Mar 2021 18:25:28 +0800 Message-Id: <20210301102529.18573-3-qiangqing.zhang@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210301102529.18573-1-qiangqing.zhang@nxp.com> References: <20210301102529.18573-1-qiangqing.zhang@nxp.com> X-Originating-IP: [119.31.174.71] X-ClientProxiedBy: HK2PR04CA0045.apcprd04.prod.outlook.com (2603:1096:202:14::13) To DB8PR04MB6795.eurprd04.prod.outlook.com (2603:10a6:10:fa::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (119.31.174.71) by HK2PR04CA0045.apcprd04.prod.outlook.com (2603:1096:202:14::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19 via Frontend Transport; Mon, 1 Mar 2021 10:25:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e5614f12-6281-4daa-10f6-08d8dc9c50a7 X-MS-TrafficTypeDiagnostic: DB7PR04MB4953: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1265; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 28phTNNN2LXGOze28pjgJ+sIuimlg5rPSRiIv2defedyQ66rpzzu0TnO+aV+m3fz7cDQci6eICFVeKjFBtjuVcl/0NkRNe59yieabWtbvZf1IYutKZ5xQWwADnFayN/wI85FaCoxyzye5hwt5gCYZr3jx9VQKX+DqxsLn8x0be0m2AwnFfgvHbOpf4HScUef6kcZGfTq9x4avWvhZTmvm5ix98LNyPjEiSkAvXyVpUCjUEE2nCuiCShok5M8ts5hMjXHKZoI37UznfCgz7n+SnrpnLIOIBGQhPOHmAYbbLfwRr2orYVx4ZJLYGn87BBtgL/1sjnCxt/hUggd9U3l8L69wUV5ngGEqK9ebh6Yn5FsFzw0sHTxmO+f6XBYEPXh08vHiYkuMyeLiUrV5pC4WTiwDvXASbcnpFCp0GjVc17HuOHuhOtEmIEphsKULQvvBkmoYizUrivHqJCMBHryQ2ryk+OjY3oV30bfS5NsyftJ0658JbdC/Ni4nYC86Oj/xSBVZTbSVXm4xGNLOQf5TmU/CTwyONVlzZf/iPhl2BTyQvyQMN43387UpikGgSgdoGRYhzcGQxtjyZ0zaJj6fA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB8PR04MB6795.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(39860400002)(136003)(376002)(366004)(346002)(5660300002)(6666004)(6512007)(2906002)(1076003)(86362001)(52116002)(6506007)(36756003)(478600001)(6486002)(26005)(69590400012)(186003)(66476007)(8676002)(316002)(16526019)(4326008)(2616005)(956004)(83380400001)(8936002)(66556008)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 7l7mJHB/4lEWJO3KMQCNNaC91uiZ9be2RlUcJS9XG2KFFG7MgQAcNqclMOtX57tLvUY7Vj7j+dOhlyagooWq6s2b//HnKz275xDTvBR1OEmKUan3+qpbhNYE+4qigEK83IMNwzVCWIMoKSuf0jbXrUGjAgzS8bLUvTHzwD4p8fgS3Do9GoVHV8TGixBe30er+QGdM3QRc2061WW5x54KejLcalPfqgOU3SmBgJsLhAbEQZRBGzizF3bKQ+s9nw22Iy7zcbNAPWMqDbFA3rN5triS1dTFK3bNA7ZD78c1l551WkzcgWx/BcOZ66A5G+QuZ9E27A325keZglEFFqkYtxbX2atPoNZAtgQvweVjU3SSik1gTUG5nX1dIpfWukc3L5BhzffsB8yhD10J4DQKwSI15vbHrM5j85lji2eif1+I8Ta09oLakoh71Y0ka8QmkxtI7raL1pXNxsf5pA+KDomFLjs/LrNe5YbHIZrhSyTqG6/wxHU5t1LY84dJT3RHqs8t+DlRmF/FrPe+V20DSdBKs01RV3FKkYQeauO2W4eKsOz2w1oPvm0saZT47+ju6B4MDuEL1BHsfPjgk++2Tkb69lBAuKHWVrU4fE4yBVoRf5oc33e8s9tiYlf7NalPm+pQONOtlWYRBqlOFVNwpbVeCFVmKlXx6FpiK4iPC27qkaVpM/f5gsf2HgSEViPlzkW0CQWIa1ym7u/6vR3ogeBhn0D/E7Y1yv14SwecXkDBRAh9mqXy+O0H4eRqOXsvYNdn5pWPaU2QDVFwNsJY0QPZxsxgIaPVLwCIAiF/tjFXfuDvi0KdZEJg9sMczufkGLzZvtCrAWFWNKPIE725Y13ZTCvoKyp5PcHxkeEGWygUzS/J6Ql8PT+Fv4+b2p9A/kElCBTQ1iBKv3H5SZVTrVJXcYIBEu9ur5KM2T9xLJNIe7rHMmsI1uwC0jg2AFi4/8e4iCOZP0mTYoRUWr/44mZWMJ1nk7GQbbfqs/Xs/gYJkDdqVSztu4aRcBoDcEuoQmezYQRpIHnwrUEqcLG8lp9Ysc6gsqZBHqJBSAdLe9DUxyLd905tX9Ky9q3HYJBbNkjS3opI1C8jP5+bFCj2IN7HJ+Q2l7DMU/hNvhWNzlN7EzudWugNQE/iCXB2xqVsyCYQLbU5vBwV3lkVQRVO8n3biAJ60Nvy7MqDcghTQYskPPI/Hv1OSku9lgnwmxkl3c/Uj+doJ7R01ACDatrdK5KTYrGPo9TTr6x854CnDZNHbqvepyDwfPvhjEpluP/OJKgX/pH6Q7/an1BPBGEV+5ykKZCQ6qE+o3lTg8k7siaPx1FCfvqaBihqEG2Ie3wv X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e5614f12-6281-4daa-10f6-08d8dc9c50a7 X-MS-Exchange-CrossTenant-AuthSource: DB8PR04MB6795.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2021 10:25:20.2664 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /qey6Bxn60DsPfohwqy2iQk6wCAXPP2bGMOrP7frmltz62onzHpOJB2BtOLyLDQb8o3ebBjuOQmE9KxPd0sOTQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4953 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch intends to add platform level clocks management. Some platforms may have their own special clocks, they also need to be managed dynamically. If you want to manage such clocks, please implement clks_config callback. Signed-off-by: Joakim Zhang Reviewed-by: Andrew Lunn --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 10 ++++++++++ include/linux/stmmac.h | 1 + 2 files changed, 11 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index b4bc1c2104df..33b0783de270 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -127,9 +127,19 @@ int stmmac_bus_clks_config(struct stmmac_priv *priv, bool enabled) clk_disable_unprepare(priv->plat->stmmac_clk); return ret; } + if (priv->plat->clks_config) { + ret = priv->plat->clks_config(priv->plat->bsp_priv, enabled); + if (ret) { + clk_disable_unprepare(priv->plat->stmmac_clk); + clk_disable_unprepare(priv->plat->pclk); + return ret; + } + } } else { clk_disable_unprepare(priv->plat->stmmac_clk); clk_disable_unprepare(priv->plat->pclk); + if (priv->plat->clks_config) + priv->plat->clks_config(priv->plat->bsp_priv, enabled); } return ret; diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h index a302982de2d7..5ab2a8138149 100644 --- a/include/linux/stmmac.h +++ b/include/linux/stmmac.h @@ -183,6 +183,7 @@ struct plat_stmmacenet_data { int (*init)(struct platform_device *pdev, void *priv); void (*exit)(struct platform_device *pdev, void *priv); struct mac_device_info *(*setup)(void *priv); + int (*clks_config)(void *priv, bool enabled); void *bsp_priv; struct clk *stmmac_clk; struct clk *pclk; From patchwork Mon Mar 1 10:25:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joakim Zhang X-Patchwork-Id: 390781 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT 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 B169EC433E0 for ; Mon, 1 Mar 2021 10:28:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 678EC600CC for ; Mon, 1 Mar 2021 10:28:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234396AbhCAK1Y (ORCPT ); Mon, 1 Mar 2021 05:27:24 -0500 Received: from mail-am6eur05on2077.outbound.protection.outlook.com ([40.107.22.77]:2529 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233707AbhCAK0r (ORCPT ); Mon, 1 Mar 2021 05:26:47 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lGw9lH4w6dk/c/Y05eBgiuPff5VvqXkwD5BnZwL/GwO8HGveNcOYdnKbwQ9YS5yRLJepM6IHkidS/MqPuAb5YSwfEfvMHaMmcPnZzV9klEjPwoEG2l5mCRYvUntJBJI2t6/iSKY+CwPpyicMC0CBcAQoYrhb8rFPE20dGWZ+0NfHkg3NXeFTIoHoKsH7HOgUeAg2B5AOojVj2anaf+jDM0nXqvzcHUl0pHsT4FsrkeqqCEmknc9RS2y3ovrjMVvzeY8aufV9MlfK7T/UQexY9hJNRQ5bq7nLzZoZc/sARjU02j3Jj3fZfn1qx2o4ToVZzmwpbyVBHtjQZ0UgODMxOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YwlpXMc9HeU0HUozihgQ9MCQZSvHXQlYtz+rjy0O8LU=; b=X0nctaX+wnYA8k3c9ObJA2HuT+t0C+jaaf6jbDloAFIyw1F5cNKz6iFI2qMj3bVghI7fk/LEC0EDmkkOKXCZID/42/aPffmtWaJCm8+FFR2loBOL5fYyA2Fp2ukuIewejKozMv0/bnjCmOe9owytTCLbZ1YkSulHqyM3ywGv7+rZHgPTfwz3q55sG7mnItS0OGc0e9CEG2am2GWba3XV+MYqr30sSM0lL/lFadaUjcDOMWhIxOaFlpDhm48GtAmz/bN98X6DCe296vuHBzBzMFhgwNfByWcEP0gMJxrn1mebAh1XLVlNY5yUcpxxjooR5oqiIxM32bQZdBqwdyUrBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YwlpXMc9HeU0HUozihgQ9MCQZSvHXQlYtz+rjy0O8LU=; b=jrEMYMldh1O+xLPXWPBbm72Tza3tLPBgHhJFMnjrQ+H303+/oW6DDeheYRVhhgOgXRY9T48SCdpwa/L7ttdV3pZC25QGMLItC/C2ot4PsrF1oPt8jd+EHiuVIzUKXfsPEyjG1m4yRbS0Oc94E5+lGZepM5PGxk+/eTogC5Byvzw= Authentication-Results: st.com; dkim=none (message not signed) header.d=none;st.com; dmarc=none action=none header.from=nxp.com; Received: from DB8PR04MB6795.eurprd04.prod.outlook.com (2603:10a6:10:fa::15) by DB7PR04MB4953.eurprd04.prod.outlook.com (2603:10a6:10:13::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.28; Mon, 1 Mar 2021 10:25:23 +0000 Received: from DB8PR04MB6795.eurprd04.prod.outlook.com ([fe80::7d13:2d65:d6f7:b978]) by DB8PR04MB6795.eurprd04.prod.outlook.com ([fe80::7d13:2d65:d6f7:b978%4]) with mapi id 15.20.3890.028; Mon, 1 Mar 2021 10:25:23 +0000 From: Joakim Zhang To: peppe.cavallaro@st.com, alexandre.torgue@st.com, joabreu@synopsys.com, davem@davemloft.net, kuba@kernel.org, f.fainelli@gmail.com, andrew@lunn.ch Cc: linux-imx@nxp.com, netdev@vger.kernel.org Subject: [RFC V2 resend net-next 3/3] net: stmmac: dwmac-imx: add platform level clocks management for i.MX Date: Mon, 1 Mar 2021 18:25:29 +0800 Message-Id: <20210301102529.18573-4-qiangqing.zhang@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210301102529.18573-1-qiangqing.zhang@nxp.com> References: <20210301102529.18573-1-qiangqing.zhang@nxp.com> X-Originating-IP: [119.31.174.71] X-ClientProxiedBy: HK2PR04CA0045.apcprd04.prod.outlook.com (2603:1096:202:14::13) To DB8PR04MB6795.eurprd04.prod.outlook.com (2603:10a6:10:fa::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (119.31.174.71) by HK2PR04CA0045.apcprd04.prod.outlook.com (2603:1096:202:14::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19 via Frontend Transport; Mon, 1 Mar 2021 10:25:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 74665ae6-c36e-4d12-c4e5-08d8dc9c529d X-MS-TrafficTypeDiagnostic: DB7PR04MB4953: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:632; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qXFFKJtpQxRtfPQKyNllPwlpeX/uPjSTyqqTBXtmYl8kTEL6ZJHsuVWxviQrRu3KlaAZ9PSSgUjZX93U67lYI+gp9iujaF5jhG6RS4H731SOIKJcMvSCcZloW9DdmavWcfk+TzogReCwdbE4JiKdTmxSUmqd6npjPFqyb3kQqeKdxRZsqMFeiW85MpNjcgzRd3IT76jRU0fwYVRwuTXnAfXL3zaTdyQ5Pcdj/kzRxjlyDTgqYOvn32TJhxHSRxwiwZSdLQzun6uVwuvdufepP8UxxWnHg50VuaSzt63oJKC/9811h8/xAfKZTMJgH7CTFUiu0VBSdS5JVcvE5Dulf0YeiZWHuS8WIPVouE9JnSks5K/nZgypo+d/3wHNGINKPW4AsRVPeBWVc/rlMXwr+MM7Uno4YSAxH99ghdi48O7i0xo6SdHHq5jTAEMv5wIPCT/JCQyd5AIyGyyt70wuII+yQBP1r/V6MIQrR1P4pi3CXPQzKVOSr329AXGKkMyPGlL1RZti2rQkBfoLrSF6B0G08fT3JrqEHAOZM59R23UsQEGG+Ga93A2Lm8E9JmDBy6X0G+Z1ycxTqbby95aazA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB8PR04MB6795.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(39860400002)(136003)(376002)(366004)(346002)(5660300002)(6512007)(2906002)(1076003)(86362001)(52116002)(6506007)(36756003)(478600001)(6486002)(26005)(69590400012)(186003)(66476007)(8676002)(316002)(16526019)(4326008)(2616005)(956004)(83380400001)(8936002)(66556008)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 51bHvEaMYatVrPR3o0frJ2nQQmULmBABBmzmyJ7lMYC64ujm1PrEJG7NEIaEbBgfkpzcTv/+x42do1WhJt2rYzBskPJ6uKHfPwg9k1pdz12g4ApBA80qIg+cEsHXI0H3ZlVKE3zEHG81Pg+45n/pnmGh9sIcGTqxpogLxf2r1XMqd8TbS3w1+jWSnDbmxlUEKBddRf4LNeGX65oqfcRJIB6q/8YuDN667exbqQUakcTOCENXHozNJGo8j2sboCbucXB0uldQC/WzWKNI6SgGENO6310OhE7/Nvsd0UOCG9sQ1Q2sIYqMBBUq1D7vCmH7x8IF1XnofNGQdNtaRzKPl/5XzjvXTBNZCYU8TTFPevh2ztBQ77FlX2uxnNVq0zhhtJa1w09VVLTqkBr/EgLO3YcEB6YThqIghDk1elFbueJ5DLozzm8lIcUpmKylmwOS3pL+HyD5gfK0W1ZdUmekTFHjbNfHgCWvkEULYgudpzAS8DXVMLwtqan506XpUoHb2VD77a25YV6q+sVtGkYwstCTJFXfzv4h+myccv2T4NfLG4OVBaBiy1sigCyBexHTy/rvExjz7/d2VhA56+IiFecWzvrIPbY6w7FAjaKKEo5kk8o3HVLIgkTUGKrDxOlGSxiJEKst9dSnS66aAqEOlSj3MWGfbDJwgYz6WPdYqxwWLcz8ODWXhr67lPqRUf+Kr2a6hQVP1USe4wsnBssunbB2teS16kBUndP/4fVWQ1bzzCI/aDvNggEHmCb+N4EjDvUwIzh6sBfWeHxD6npLOvJJoBCBbGu4PBrj71HvoaGqYLLzolADWVJAnmTqqoU8la7mKLEEtPAgJ3zLhamIwESVvj8R0EVWpKgZiUaJGmeNEWa9btL4b2xaHQaLEjQoUlRAxhYoHVTEwzRmA8UIES7EnlT3YVkCoeZ6U5TEQsYOUwVJTfrpAh5+GOhzPbMY6VEkrxzsJRcwAvhNQq7Nfpj+LGZdhYvYSVV+re4poj5mBqekNsZh99Q8UEZScod+Lyfi/M+4Cs9iJgKWWY/BkGIPQ1vkW50Nje3z2ZlW/Qe88hHvs2qhJFOryMvG3b4o0PCgLeaBWWg8+F7TvQyO1w1sYQJTY5+k02lc8RYRq1yYbTPwBpABwl/u85r4t3WSpd7IHbxd6f5VYFvofFYphzoyWacNXNgaOUURAt/4+Toekm4F6n5NJEwM4gKCiyWtUpziJ2RAbmjftw+sKdjLFvgIOYJhFAgSmxJtJJuOwdKMMVoAyTFX21Bz6y0CURfz5LnkLtkWBomNr1lBuz517QU+J05aAb82xUR6epfCxn4XPoL5STk3c2HgkJHRj6VN X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74665ae6-c36e-4d12-c4e5-08d8dc9c529d X-MS-Exchange-CrossTenant-AuthSource: DB8PR04MB6795.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2021 10:25:23.3498 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: z6NofUVgeAFB40HExdmiAAxHLqia8gtBcLpR8sAPnehAjax4bdpogWpVrGA3y8UvZKTbl/OfE3T3h7ymEE4VNg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4953 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Split clocks settings from init callback into clks_config callback, which could support platform level clocks management. Signed-off-by: Joakim Zhang Reviewed-by: Andrew Lunn --- .../net/ethernet/stmicro/stmmac/dwmac-imx.c | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c index 223f69da7e95..c1a361305a5a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c @@ -90,6 +90,32 @@ imx8dxl_set_intf_mode(struct plat_stmmacenet_data *plat_dat) return ret; } +static int imx_dwmac_clks_config(void *priv, bool enabled) +{ + struct imx_priv_data *dwmac = priv; + int ret = 0; + + if (enabled) { + ret = clk_prepare_enable(dwmac->clk_mem); + if (ret) { + dev_err(dwmac->dev, "mem clock enable failed\n"); + return ret; + } + + ret = clk_prepare_enable(dwmac->clk_tx); + if (ret) { + dev_err(dwmac->dev, "tx clock enable failed\n"); + clk_disable_unprepare(dwmac->clk_mem); + return ret; + } + } else { + clk_disable_unprepare(dwmac->clk_tx); + clk_disable_unprepare(dwmac->clk_mem); + } + + return ret; +} + static int imx_dwmac_init(struct platform_device *pdev, void *priv) { struct plat_stmmacenet_data *plat_dat; @@ -98,39 +124,18 @@ static int imx_dwmac_init(struct platform_device *pdev, void *priv) plat_dat = dwmac->plat_dat; - ret = clk_prepare_enable(dwmac->clk_mem); - if (ret) { - dev_err(&pdev->dev, "mem clock enable failed\n"); - return ret; - } - - ret = clk_prepare_enable(dwmac->clk_tx); - if (ret) { - dev_err(&pdev->dev, "tx clock enable failed\n"); - goto clk_tx_en_failed; - } - if (dwmac->ops->set_intf_mode) { ret = dwmac->ops->set_intf_mode(plat_dat); if (ret) - goto intf_mode_failed; + return ret; } return 0; - -intf_mode_failed: - clk_disable_unprepare(dwmac->clk_tx); -clk_tx_en_failed: - clk_disable_unprepare(dwmac->clk_mem); - return ret; } static void imx_dwmac_exit(struct platform_device *pdev, void *priv) { - struct imx_priv_data *dwmac = priv; - - clk_disable_unprepare(dwmac->clk_tx); - clk_disable_unprepare(dwmac->clk_mem); + /* nothing to do now */ } static void imx_dwmac_fix_speed(void *priv, unsigned int speed) @@ -249,10 +254,15 @@ static int imx_dwmac_probe(struct platform_device *pdev) plat_dat->addr64 = dwmac->ops->addr_width; plat_dat->init = imx_dwmac_init; plat_dat->exit = imx_dwmac_exit; + plat_dat->clks_config = imx_dwmac_clks_config; plat_dat->fix_mac_speed = imx_dwmac_fix_speed; plat_dat->bsp_priv = dwmac; dwmac->plat_dat = plat_dat; + ret = imx_dwmac_clks_config(dwmac, true); + if (ret) + goto err_clks_config; + ret = imx_dwmac_init(pdev, dwmac); if (ret) goto err_dwmac_init; @@ -263,9 +273,11 @@ static int imx_dwmac_probe(struct platform_device *pdev) return 0; -err_dwmac_init: err_drv_probe: imx_dwmac_exit(pdev, plat_dat->bsp_priv); +err_dwmac_init: + imx_dwmac_clks_config(dwmac, false); +err_clks_config: err_parse_dt: err_match_data: stmmac_remove_config_dt(pdev, plat_dat);