public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
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>
Subject: [PATCH 3/3] net: fec: Reset ethernet PHY whenever the enet_out clock is being enabled
Date: Mon, 30 Nov 2015 12:32:48 +0100	[thread overview]
Message-ID: <1448883168-30742-4-git-send-email-LW@KARO-electronics.de> (raw)
In-Reply-To: <1448883168-30742-3-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 | 46 ++++++++++++++++++++++++-------
 2 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index 99d33e2..8ab4f7f 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;
+	struct gpio_desc *phy_reset;
 
 	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 1a983fc..7ba2bbb 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -66,6 +66,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"
 
@@ -1861,6 +1862,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);
@@ -3231,13 +3234,32 @@ static int fec_enet_init(struct net_device *ndev)
 }
 
 #ifdef CONFIG_OF
-static void fec_reset_phy(struct platform_device *pdev)
+static struct gpio_desc *fec_get_reset_gpio(struct platform_device *pdev)
 {
 	struct gpio_desc *phy_reset;
-	int msec = 1;
 	struct device_node *np = pdev->dev.of_node;
 
 	if (!np)
+		return ERR_PTR(-ENODEV);
+
+	phy_reset = devm_gpiod_get_optional(&pdev->dev, "phy-reset",
+					    GPIOD_OUT_LOW);
+	if (IS_ERR(phy_reset))
+		dev_err(&pdev->dev, "failed to get phy-reset-gpios: %ld\n",
+			PTR_ERR(phy_reset));
+	return phy_reset;
+}
+
+static void fec_reset_phy(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct net_device *ndev = platform_get_drvdata(pdev);
+	struct fec_enet_private *fep = netdev_priv(ndev);
+	int msec = 1;
+
+	if (!fep->phy_reset)
+		return;
+	if (!np)
 		return;
 
 	of_property_read_u32(np, "phy-reset-duration", &msec);
@@ -3245,17 +3267,16 @@ static void fec_reset_phy(struct platform_device *pdev)
 	if (msec > 1000)
 		msec = 1;
 
-	phy_reset = devm_gpiod_get_optional(&pdev->dev, "phy-reset",
-					    GPIOD_OUT_LOW);
-	if (IS_ERR(phy_reset)) {
-		dev_err(&pdev->dev, "failed to get phy-reset-gpios: %ld\n",
-			PTR_ERR(phy_reset));
-		return;
-	}
+	gpiod_set_value_cansleep(fep->phy_reset, 0);
 	msleep(msec);
-	gpiod_set_value_cansleep(phy_reset, 1);
+	gpiod_set_value_cansleep(fep->phy_reset, 1);
 }
 #else /* CONFIG_OF */
+static void fec_get_reset_gpio(struct platform_device *pdev)
+{
+	return -EINVAL;
+}
+
 static void fec_reset_phy(struct platform_device *pdev)
 {
 	/*
@@ -3309,8 +3330,12 @@ fec_probe(struct platform_device *pdev)
 	struct device_node *np = pdev->dev.of_node, *phy_node;
 	int num_tx_qs;
 	int num_rx_qs;
+	struct gpio_desc *phy_reset;
 
 	fec_enet_get_queue_num(pdev, &num_tx_qs, &num_rx_qs);
+	phy_reset = fec_get_reset_gpio(pdev);
+	if (IS_ERR(phy_reset) && PTR_ERR(phy_reset) == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
 
 	/* Init network device */
 	ndev = alloc_etherdev_mqs(sizeof(struct fec_enet_private),
@@ -3331,6 +3356,7 @@ fec_probe(struct platform_device *pdev)
 	fep->netdev = ndev;
 	fep->num_rx_queues = num_rx_qs;
 	fep->num_tx_queues = num_tx_qs;
+	fep->phy_reset = phy_reset;
 
 #if !defined(CONFIG_M5272)
 	/* default enable pause frame auto negotiation */
-- 
2.1.4

  reply	other threads:[~2015-11-30 11:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-30 11:32 [PATCH 0/3] net: fec: Reset ethernet PHY whenever the enet_out clock Lothar Waßmann
2015-11-30 11:32 ` [PATCH 1/3] net: fec: Remove redundant checks for NULL clk pointer Lothar Waßmann
2015-11-30 11:32   ` [PATCH 2/3] net: fec: convert to using gpiod framework Lothar Waßmann
2015-11-30 11:32     ` Lothar Waßmann [this message]
2015-12-01  2:31       ` [PATCH 3/3] net: fec: Reset ethernet PHY whenever the enet_out clock is being enabled Duan Andy
2015-11-30 12:17     ` [PATCH 2/3] net: fec: convert to using gpiod framework Fabio Estevam
2015-12-01  2:17     ` Duan Andy
2015-12-01 10:29       ` Lothar Waßmann
2015-12-01  2:04   ` [PATCH 1/3] net: fec: Remove redundant checks for NULL clk pointer Duan Andy
2015-12-01  7:24     ` Lothar Waßmann
2015-12-01  1:52 ` [PATCH 0/3] net: fec: Reset ethernet PHY whenever the enet_out clock Duan Andy
2015-12-01  7:24   ` Lothar Waßmann
2015-12-01  7:33     ` Duan Andy

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=1448883168-30742-4-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=fabio.estevam@freescale.com \
    --cc=gerg@uclinux.org \
    --cc=haokexin@gmail.com \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=l.stach@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=s.hauer@pengutronix.de \
    --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