Return-Path: Received: from mail-bn3nam01on0090.outbound.protection.outlook.com ([104.47.33.90]:43384 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933860AbeCCWfn (ORCPT ); Sat, 3 Mar 2018 17:35:43 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Fugang Duan , Fugang Duan , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 152/219] net: fec: add phy-reset-gpios PROBE_DEFER check Date: Sat, 3 Mar 2018 22:29:24 +0000 Message-ID: <20180303222716.26640-152-alexander.levin@microsoft.com> References: <20180303222716.26640-1-alexander.levin@microsoft.com> In-Reply-To: <20180303222716.26640-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Fugang Duan [ Upstream commit 9269e5560b261eb9ee157497890dc0948db76cf8 ] Many boards use i2c/spi expander gpio as phy-reset-gpios and these gpios maybe registered after fec port, driver should check the return value of .of_get_named_gpio(). Signed-off-by: Fugang Duan Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/freescale/fec_main.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethern= et/freescale/fec_main.c index 917091871259..dd6e07c748f5 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -3209,7 +3209,7 @@ static int fec_enet_init(struct net_device *ndev) } =20 #ifdef CONFIG_OF -static void fec_reset_phy(struct platform_device *pdev) +static int fec_reset_phy(struct platform_device *pdev) { int err, phy_reset; bool active_high =3D false; @@ -3217,7 +3217,7 @@ static void fec_reset_phy(struct platform_device *pde= v) struct device_node *np =3D pdev->dev.of_node; =20 if (!np) - return; + return 0; =20 of_property_read_u32(np, "phy-reset-duration", &msec); /* A sane reset duration should not be longer than 1s */ @@ -3225,8 +3225,10 @@ static void fec_reset_phy(struct platform_device *pd= ev) msec =3D 1; =20 phy_reset =3D of_get_named_gpio(np, "phy-reset-gpios", 0); - if (!gpio_is_valid(phy_reset)) - return; + if (phy_reset =3D=3D -EPROBE_DEFER) + return phy_reset; + else if (!gpio_is_valid(phy_reset)) + return 0; =20 active_high =3D of_property_read_bool(np, "phy-reset-active-high"); =20 @@ -3235,7 +3237,7 @@ static void fec_reset_phy(struct platform_device *pde= v) "phy-reset"); if (err) { dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err); - return; + return err; } =20 if (msec > 20) @@ -3244,14 +3246,17 @@ static void fec_reset_phy(struct platform_device *p= dev) usleep_range(msec * 1000, msec * 1000 + 1000); =20 gpio_set_value_cansleep(phy_reset, !active_high); + + return 0; } #else /* CONFIG_OF */ -static void fec_reset_phy(struct platform_device *pdev) +static int fec_reset_phy(struct platform_device *pdev) { /* * In case of platform probe, the reset has been done * by machine code. */ + return 0; } #endif /* CONFIG_OF */ =20 @@ -3422,6 +3427,7 @@ fec_probe(struct platform_device *pdev) if (ret) { dev_err(&pdev->dev, "Failed to enable phy regulator: %d\n", ret); + clk_disable_unprepare(fep->clk_ipg); goto failed_regulator; } } else { @@ -3434,7 +3440,9 @@ fec_probe(struct platform_device *pdev) pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); =20 - fec_reset_phy(pdev); + ret =3D fec_reset_phy(pdev); + if (ret) + goto failed_reset; =20 if (fep->bufdesc_ex) fec_ptp_init(pdev); @@ -3495,8 +3503,10 @@ failed_init: fec_ptp_stop(pdev); if (fep->reg_phy) regulator_disable(fep->reg_phy); +failed_reset: + pm_runtime_put(&pdev->dev); + pm_runtime_disable(&pdev->dev); failed_regulator: - clk_disable_unprepare(fep->clk_ipg); failed_clk_ipg: fec_enet_clk_enable(ndev, false); failed_clk: --=20 2.14.1