From: "Lothar Waßmann" <LW@KARO-electronics.de>
To: "Andrew Lunn" <andrew@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Fabio Estevam" <fabio.estevam@freescale.com>,
"Greg Ungerer" <gerg@uclinux.org>,
"Kevin Hao" <haokexin@gmail.com>,
"Lothar Waßmann" <LW@KARO-electronics.de>,
"Lucas Stach" <l.stach@pengutronix.de>,
"Nimrod Andy" <B38611@freescale.com>,
"Philippe Reynes" <tremyfr@gmail.com>,
"Richard Cochran" <richardcochran@gmail.com>,
"Russell King" <rmk+kernel@arm.linux.org.uk>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Stefan Agner" <stefan@agner.ch>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
"Jeff Kirsher" <jeffrey.t.kirsher@intel.com>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Ian Campbell" <ijc+devicetree@hellion.org.uk>,
"Kumar Gala" <galak@codeaurora.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Pawel Moll" <pawel.moll@arm.com>,
"Rob Herring" <robh+dt@kernel.org>,
"Russell King" <linux@arm.linux.org.uk>,
"Sascha Hauer" <kernel@pengutronix.de>,
"Shawn Guo" <shawnguo@kernel.org>,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: [PATCHv2 2/2] net: fec: Reset ethernet PHY whenever the enet_out clock is being enabled
Date: Tue, 12 Jan 2016 16:17:56 +0100 [thread overview]
Message-ID: <1452611876-451-3-git-send-email-LW@KARO-electronics.de> (raw)
In-Reply-To: <1452611876-451-2-git-send-email-LW@KARO-electronics.de>
If a PHY uses ENET_OUT as reference clock, it may need a RESET to get
functional after the clock had been disabled.
Failure to do this results in the link state constantly toggling
between up and down:
fec 02188000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
fec 02188000.ethernet eth0: Link is Down
fec 02188000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
fec 02188000.ethernet eth0: Link is Down
[...]
Signed-off-by: Lothar Waßmann <LW@KARO-electronics.de>
---
drivers/net/ethernet/freescale/fec.h | 1 +
drivers/net/ethernet/freescale/fec_main.c | 38 +++++++++++++++++++++++++------
2 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index 99d33e2..33228df 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -519,6 +519,7 @@ struct fec_enet_private {
int pause_flag;
int wol_flag;
u32 quirks;
+ int phy_reset_gpio;
struct napi_struct napi;
int csum_flags;
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 592a7a4..fb0b0eb 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -67,6 +67,7 @@
static void set_multicast_list(struct net_device *ndev);
static void fec_enet_itr_coal_init(struct net_device *ndev);
+static void fec_reset_phy(struct platform_device *pdev);
#define DRIVER_NAME "fec"
@@ -1862,6 +1863,8 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
ret = clk_prepare_enable(fep->clk_enet_out);
if (ret)
goto failed_clk_enet_out;
+
+ fec_reset_phy(fep->pdev);
}
if (fep->clk_ptp) {
mutex_lock(&fep->ptp_clk_mutex);
@@ -3216,11 +3219,12 @@ static int fec_enet_init(struct net_device *ndev)
#ifdef CONFIG_OF
static void fec_reset_phy(struct platform_device *pdev)
{
- int err, phy_reset;
- int msec = 1;
+ struct net_device *ndev = platform_get_drvdata(pdev);
+ struct fec_enet_private *fep = netdev_priv(ndev);
struct device_node *np = pdev->dev.of_node;
+ int msec = 1;
- if (!np)
+ if (!gpio_is_valid(fep->phy_reset_gpio))
return;
of_property_read_u32(np, "phy-reset-duration", &msec);
@@ -3228,18 +3232,27 @@ static void fec_reset_phy(struct platform_device *pdev)
if (msec > 1000)
msec = 1;
+ gpio_set_value_cansleep(fep->phy_reset_gpio, 0);
+ msleep(msec);
+ gpio_set_value_cansleep(fep->phy_reset_gpio, 1);
+}
+
+static int fec_get_reset_gpio(struct platform_device *pdev)
+{
+ int err, phy_reset;
+ struct device_node *np = pdev->dev.of_node;
+
phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
if (!gpio_is_valid(phy_reset))
- return;
+ return phy_reset;
err = devm_gpio_request_one(&pdev->dev, phy_reset,
GPIOF_OUT_INIT_LOW, "phy-reset");
if (err) {
dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err);
- return;
+ return err;
}
- msleep(msec);
- gpio_set_value_cansleep(phy_reset, 1);
+ return phy_reset;
}
#else /* CONFIG_OF */
static void fec_reset_phy(struct platform_device *pdev)
@@ -3249,6 +3262,11 @@ static void fec_reset_phy(struct platform_device *pdev)
* by machine code.
*/
}
+
+static inline int fec_get_reset_gpio(struct platform_device *pdev)
+{
+ return -EINVAL;
+}
#endif /* CONFIG_OF */
static void
@@ -3339,6 +3357,11 @@ fec_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, ndev);
+ ret = fec_get_reset_gpio(pdev);
+ if (ret == -EPROBE_DEFER)
+ goto gpio_defer;
+ fep->phy_reset_gpio = ret;
+
if (of_get_property(np, "fsl,magic-packet", NULL))
fep->wol_flag |= FEC_WOL_HAS_MAGIC_PACKET;
@@ -3493,6 +3516,7 @@ failed_clk_ipg:
failed_clk:
failed_phy:
of_node_put(phy_node);
+gpio_defer:
failed_ioremap:
free_netdev(ndev);
--
2.1.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2016-01-12 15:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-12 15:17 [PATCHv2 0/2] net: fec: Reset ethernet PHY whenever the enet_out clock is being enabled Lothar Waßmann
[not found] ` <1452611876-451-1-git-send-email-LW-bxm8fMRDkQLDiMYJYoSAnRvVK+yQ3ZXh@public.gmane.org>
2016-01-12 15:17 ` [PATCHv2 1/2] remove redundant struct clk NULL checks Lothar Waßmann
2016-01-12 15:17 ` Lothar Waßmann
2016-01-12 15:17 ` Lothar Waßmann [this message]
2016-01-12 15:28 ` [PATCHv2 2/2] net: fec: Reset ethernet PHY whenever the enet_out clock is being enabled Lucas Stach
[not found] ` <1452611876-451-2-git-send-email-LW-bxm8fMRDkQLDiMYJYoSAnRvVK+yQ3ZXh@public.gmane.org>
2016-01-12 15:17 ` Lothar Waßmann
2016-01-12 15:25 ` [PATCHv2 1/2] remove redundant struct clk NULL checks Lucas Stach
2016-01-12 15:24 ` [PATCHv2 0/2] net: fec: Reset ethernet PHY whenever the enet_out clock is being enabled Russell King - ARM Linux
2016-01-12 16:04 ` Lothar Waßmann
2016-01-12 20:30 ` Uwe Kleine-König
2016-09-26 15:37 ` Jörg Krause
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1452611876-451-3-git-send-email-LW@KARO-electronics.de \
--to=lw@karo-electronics.de \
--cc=B38611@freescale.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=fabio.estevam@freescale.com \
--cc=galak@codeaurora.org \
--cc=gerg@uclinux.org \
--cc=haokexin@gmail.com \
--cc=ijc+devicetree@hellion.org.uk \
--cc=jeffrey.t.kirsher@intel.com \
--cc=kernel@pengutronix.de \
--cc=l.stach@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=mark.rutland@arm.com \
--cc=netdev@vger.kernel.org \
--cc=pawel.moll@arm.com \
--cc=richardcochran@gmail.com \
--cc=rmk+kernel@arm.linux.org.uk \
--cc=robh+dt@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=stefan@agner.ch \
--cc=tremyfr@gmail.com \
--cc=u.kleine-koenig@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).