Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp22662pxb; Fri, 15 Jan 2021 04:57:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJxIC/lKH0QqwLdDbto4f0PV73DjDv+qKa2gLFa4evzAsPqVrMIG3ZSuQLG0hsh+/w3NUp2S X-Received: by 2002:a17:906:1d1a:: with SMTP id n26mr1207735ejh.481.1610715456645; Fri, 15 Jan 2021 04:57:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610715456; cv=none; d=google.com; s=arc-20160816; b=zZo5D1okaID8kIpc/eVDaqvPl2RdaTvAIYsmCd+wV157lR2Sxttvgo0zXD3ftJtAVV jlREmru0sRRcHel2or4MfFpGKznvUV/JJ02EzXZi4ftzctISXtiN14iNntmsbLbaFwY2 tiZ09GF5otWUvLWcUb7d1g+MmQXSY5eQRKg89pzDNA+wRIHe50kiFB5R78hF2QSGnRrT a+E/qT5UcEQNcFGDC3cmuB3YgbdsMwztaiwJ9RLYmzVgnBrTXi1iS1V0zHICfJuU9M06 hqw2fpqqRrKRtVFSRLKplJMUxqL9n6d4afv1TMdfJmfG6GExR+cWLUzR+Wyj/Uf7BlST QX6g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rWlvhs1kQC7hcLOAMIUOCm6c1x9XsdqIJtbD3bcngvE=; b=fZ90TDVX7au4X7W5+jL7HSv83Q8+iMI1npNiDte0Md78L7v7xiuZhXjsmCdmeg3fuP jcA24wfccapADxCu2FPCvYKuRCZQ3L1yJraq+RglowTzhXp/PeneGH88E4QI8ijtw8+L MqRqMp0kwKNAEb1ZYoAcREd1V7V1aA34sNK/FDTspStxdZMJasjs6C+g+HSMm7kw/YUq 48NpRwSBd3Vb06zdb+dy9Ifo6HY+X1Z89RFUtE86NwWD4qCAMczTviQ9dSPkBGOWHBWH qxOB2GxAPnVpIeh3o1R0RXJd52P709WONQbm6jqz2ijqal0Fy7K44yUIvA+Izn+rA/0c pCIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gdtrrfHV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t16si4322434edi.560.2021.01.15.04.57.12; Fri, 15 Jan 2021 04:57:36 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gdtrrfHV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388109AbhAOM4r (ORCPT + 99 others); Fri, 15 Jan 2021 07:56:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:41400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387498AbhAOMed (ORCPT ); Fri, 15 Jan 2021 07:34:33 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 37F1D236FB; Fri, 15 Jan 2021 12:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610714032; bh=tKjmPvrJtGuMC86HPIICeVL3ZxQuL0r9JL3fIUc6SUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gdtrrfHVE0wnRmXLl2NBL60PAUX6GrYEdyBJ//umpHff1WeBNw7IALTrQX0o4YjOH P/9Jp95whzpY39JEPVq/VUsnZJUeTMuW6gSWsH+1VyXF5E+foQ0tdK6QtWswYPExaU Ui0WW6AY8srsiMmnT7V5w6/LL33nqIMLVgHJCDbg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Samuel Holland , "David S. Miller" Subject: [PATCH 5.4 07/62] net: stmmac: dwmac-sun8i: Balance internal PHY power Date: Fri, 15 Jan 2021 13:27:29 +0100 Message-Id: <20210115121958.751738424@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115121958.391610178@linuxfoundation.org> References: <20210115121958.391610178@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Samuel Holland [ Upstream commit b8239638853e3e37b287e4bd4d57b41f14c78550 ] sun8i_dwmac_exit calls sun8i_dwmac_unpower_internal_phy, but sun8i_dwmac_init did not call sun8i_dwmac_power_internal_phy. This caused PHY power to remain off after a suspend/resume cycle. Fix this by recording if PHY power should be restored, and if so, restoring it. Fixes: 634db83b8265 ("net: stmmac: dwmac-sun8i: Handle integrated/external MDIOs") Signed-off-by: Samuel Holland Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -64,6 +64,7 @@ struct emac_variant { * @variant: reference to the current board variant * @regmap: regmap for using the syscon * @internal_phy_powered: Does the internal PHY is enabled + * @use_internal_phy: Is the internal PHY selected for use * @mux_handle: Internal pointer used by mdio-mux lib */ struct sunxi_priv_data { @@ -74,6 +75,7 @@ struct sunxi_priv_data { const struct emac_variant *variant; struct regmap_field *regmap_field; bool internal_phy_powered; + bool use_internal_phy; void *mux_handle; }; @@ -523,8 +525,11 @@ static const struct stmmac_dma_ops sun8i .dma_interrupt = sun8i_dwmac_dma_interrupt, }; +static int sun8i_dwmac_power_internal_phy(struct stmmac_priv *priv); + static int sun8i_dwmac_init(struct platform_device *pdev, void *priv) { + struct net_device *ndev = platform_get_drvdata(pdev); struct sunxi_priv_data *gmac = priv; int ret; @@ -538,13 +543,25 @@ static int sun8i_dwmac_init(struct platf ret = clk_prepare_enable(gmac->tx_clk); if (ret) { - if (gmac->regulator) - regulator_disable(gmac->regulator); dev_err(&pdev->dev, "Could not enable AHB clock\n"); - return ret; + goto err_disable_regulator; + } + + if (gmac->use_internal_phy) { + ret = sun8i_dwmac_power_internal_phy(netdev_priv(ndev)); + if (ret) + goto err_disable_clk; } return 0; + +err_disable_clk: + clk_disable_unprepare(gmac->tx_clk); +err_disable_regulator: + if (gmac->regulator) + regulator_disable(gmac->regulator); + + return ret; } static void sun8i_dwmac_core_init(struct mac_device_info *hw, @@ -815,7 +832,6 @@ static int mdio_mux_syscon_switch_fn(int struct sunxi_priv_data *gmac = priv->plat->bsp_priv; u32 reg, val; int ret = 0; - bool need_power_ephy = false; if (current_child ^ desired_child) { regmap_field_read(gmac->regmap_field, ®); @@ -823,13 +839,12 @@ static int mdio_mux_syscon_switch_fn(int case DWMAC_SUN8I_MDIO_MUX_INTERNAL_ID: dev_info(priv->device, "Switch mux to internal PHY"); val = (reg & ~H3_EPHY_MUX_MASK) | H3_EPHY_SELECT; - - need_power_ephy = true; + gmac->use_internal_phy = true; break; case DWMAC_SUN8I_MDIO_MUX_EXTERNAL_ID: dev_info(priv->device, "Switch mux to external PHY"); val = (reg & ~H3_EPHY_MUX_MASK) | H3_EPHY_SHUTDOWN; - need_power_ephy = false; + gmac->use_internal_phy = false; break; default: dev_err(priv->device, "Invalid child ID %x\n", @@ -837,7 +852,7 @@ static int mdio_mux_syscon_switch_fn(int return -EINVAL; } regmap_field_write(gmac->regmap_field, val); - if (need_power_ephy) { + if (gmac->use_internal_phy) { ret = sun8i_dwmac_power_internal_phy(priv); if (ret) return ret;