netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] fec driver updates
@ 2012-06-27 13:45 Shawn Guo
  2012-06-27 13:45 ` [PATCH v2 1/5] net: fec: reset phy after pinctrl setup Shawn Guo
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Shawn Guo @ 2012-06-27 13:45 UTC (permalink / raw)
  To: David S. Miller
  Cc: Lothar Waßmann, Florian Fainelli, netdev, linux-arm-kernel,
	devicetree-discuss, Shawn Guo

Changes since v1:
* Add one patch to use devm_gpio_request_one
* Have a separate patch to fix phy-reset-gpios property in binding
  document
* Change phy-reset-interval to phy-reset-duration
* Add a sanity check on phy-reset-duration value

Shawn Guo (5):
  net: fec: reset phy after pinctrl setup
  net: fec: enable regulator for fec phy
  net: fec: use managed function devm_gpio_request_one
  net: fec: phy-reset-gpios is optional
  net: fec: add phy-reset-duration for device tree probe

 Documentation/devicetree/bindings/net/fsl-fec.txt |    6 +++-
 drivers/net/ethernet/freescale/fec.c              |   28 ++++++++++++++++++---
 2 files changed, 29 insertions(+), 5 deletions(-)

-- 
1.7.5.4

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/5] net: fec: reset phy after pinctrl setup
  2012-06-27 13:45 [PATCH v2 0/5] fec driver updates Shawn Guo
@ 2012-06-27 13:45 ` Shawn Guo
  2012-06-27 13:45 ` [PATCH v2 2/5] net: fec: enable regulator for fec phy Shawn Guo
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Shawn Guo @ 2012-06-27 13:45 UTC (permalink / raw)
  To: David S. Miller
  Cc: Lothar Waßmann, Florian Fainelli, netdev, linux-arm-kernel,
	devicetree-discuss, Shawn Guo

In case that bootloader or platform initialization does not set up
fec pins, the fec_reset_phy will not be able to succeed, because
fec_reset_phy is currently called before devm_pinctrl_get_select_default.
Move fec_reset_phy call to the place between devm_pinctrl_get_select_default
and fec_enet_init to have above case be taken care.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
 drivers/net/ethernet/freescale/fec.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec.c b/drivers/net/ethernet/freescale/fec.c
index ff7f4c5..e868a37 100644
--- a/drivers/net/ethernet/freescale/fec.c
+++ b/drivers/net/ethernet/freescale/fec.c
@@ -1593,8 +1593,6 @@ fec_probe(struct platform_device *pdev)
 		fep->phy_interface = ret;
 	}
 
-	fec_reset_phy(pdev);
-
 	for (i = 0; i < FEC_IRQ_NUM; i++) {
 		irq = platform_get_irq(pdev, i);
 		if (irq < 0) {
@@ -1634,6 +1632,8 @@ fec_probe(struct platform_device *pdev)
 	clk_prepare_enable(fep->clk_ahb);
 	clk_prepare_enable(fep->clk_ipg);
 
+	fec_reset_phy(pdev);
+
 	ret = fec_enet_init(ndev);
 	if (ret)
 		goto failed_init;
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/5] net: fec: enable regulator for fec phy
  2012-06-27 13:45 [PATCH v2 0/5] fec driver updates Shawn Guo
  2012-06-27 13:45 ` [PATCH v2 1/5] net: fec: reset phy after pinctrl setup Shawn Guo
@ 2012-06-27 13:45 ` Shawn Guo
  2012-06-27 13:45 ` [PATCH v2 3/5] net: fec: use managed function devm_gpio_request_one Shawn Guo
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Shawn Guo @ 2012-06-27 13:45 UTC (permalink / raw)
  To: David S. Miller
  Cc: Lothar Waßmann, Florian Fainelli, netdev, linux-arm-kernel,
	devicetree-discuss, Shawn Guo

If bootloader or platform initialization code does not enable the
power supply to fec phy, we need to do it in fec driver before calling
fec_reset_phy to have the phy powered on.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
 drivers/net/ethernet/freescale/fec.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec.c b/drivers/net/ethernet/freescale/fec.c
index e868a37..4dce9e3 100644
--- a/drivers/net/ethernet/freescale/fec.c
+++ b/drivers/net/ethernet/freescale/fec.c
@@ -49,6 +49,7 @@
 #include <linux/of_gpio.h>
 #include <linux/of_net.h>
 #include <linux/pinctrl/consumer.h>
+#include <linux/regulator/consumer.h>
 
 #include <asm/cacheflush.h>
 
@@ -1546,6 +1547,7 @@ fec_probe(struct platform_device *pdev)
 	const struct of_device_id *of_id;
 	static int dev_id;
 	struct pinctrl *pinctrl;
+	struct regulator *reg_phy;
 
 	of_id = of_match_device(fec_dt_ids, &pdev->dev);
 	if (of_id)
@@ -1632,6 +1634,16 @@ fec_probe(struct platform_device *pdev)
 	clk_prepare_enable(fep->clk_ahb);
 	clk_prepare_enable(fep->clk_ipg);
 
+	reg_phy = devm_regulator_get(&pdev->dev, "phy");
+	if (!IS_ERR(reg_phy)) {
+		ret = regulator_enable(reg_phy);
+		if (ret) {
+			dev_err(&pdev->dev,
+				"Failed to enable phy regulator: %d\n", ret);
+			goto failed_regulator;
+		}
+	}
+
 	fec_reset_phy(pdev);
 
 	ret = fec_enet_init(ndev);
@@ -1655,6 +1667,7 @@ failed_register:
 	fec_enet_mii_remove(fep);
 failed_mii_init:
 failed_init:
+failed_regulator:
 	clk_disable_unprepare(fep->clk_ahb);
 	clk_disable_unprepare(fep->clk_ipg);
 failed_pin:
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/5] net: fec: use managed function devm_gpio_request_one
  2012-06-27 13:45 [PATCH v2 0/5] fec driver updates Shawn Guo
  2012-06-27 13:45 ` [PATCH v2 1/5] net: fec: reset phy after pinctrl setup Shawn Guo
  2012-06-27 13:45 ` [PATCH v2 2/5] net: fec: enable regulator for fec phy Shawn Guo
@ 2012-06-27 13:45 ` Shawn Guo
  2012-06-27 13:45 ` [PATCH v2 4/5] net: fec: phy-reset-gpios is optional Shawn Guo
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Shawn Guo @ 2012-06-27 13:45 UTC (permalink / raw)
  To: David S. Miller
  Cc: Lothar Waßmann, Florian Fainelli, netdev, linux-arm-kernel,
	devicetree-discuss, Shawn Guo

Using gpio_request_one will require the probe fail-out call gpio_free,
which is missing currently.  Change to use devm_gpio_request_one to
fix the problem.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
 drivers/net/ethernet/freescale/fec.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec.c b/drivers/net/ethernet/freescale/fec.c
index 4dce9e3..f174070 100644
--- a/drivers/net/ethernet/freescale/fec.c
+++ b/drivers/net/ethernet/freescale/fec.c
@@ -1513,7 +1513,8 @@ static void __devinit fec_reset_phy(struct platform_device *pdev)
 		return;
 
 	phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
-	err = gpio_request_one(phy_reset, GPIOF_OUT_INIT_LOW, "phy-reset");
+	err = devm_gpio_request_one(&pdev->dev, phy_reset,
+				    GPIOF_OUT_INIT_LOW, "phy-reset");
 	if (err) {
 		pr_debug("FEC: failed to get gpio phy-reset: %d\n", err);
 		return;
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 4/5] net: fec: phy-reset-gpios is optional
  2012-06-27 13:45 [PATCH v2 0/5] fec driver updates Shawn Guo
                   ` (2 preceding siblings ...)
  2012-06-27 13:45 ` [PATCH v2 3/5] net: fec: use managed function devm_gpio_request_one Shawn Guo
@ 2012-06-27 13:45 ` Shawn Guo
  2012-06-27 13:45 ` [PATCH v2 5/5] net: fec: add phy-reset-duration for device tree probe Shawn Guo
  2012-06-28  4:30 ` [PATCH v2 0/5] fec driver updates David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: Shawn Guo @ 2012-06-27 13:45 UTC (permalink / raw)
  To: David S. Miller
  Cc: Lothar Waßmann, Florian Fainelli, netdev, linux-arm-kernel,
	devicetree-discuss, Shawn Guo

The phy-reset-gpios is an optional property for fec device tree boot.
Change the binding document to match the driver code.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
 Documentation/devicetree/bindings/net/fsl-fec.txt |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/fsl-fec.txt b/Documentation/devicetree/bindings/net/fsl-fec.txt
index 7ab9e1a..0428920 100644
--- a/Documentation/devicetree/bindings/net/fsl-fec.txt
+++ b/Documentation/devicetree/bindings/net/fsl-fec.txt
@@ -7,10 +7,10 @@ Required properties:
 - phy-mode : String, operation mode of the PHY interface.
   Supported values are: "mii", "gmii", "sgmii", "tbi", "rmii",
   "rgmii", "rgmii-id", "rgmii-rxid", "rgmii-txid", "rtbi", "smii".
-- phy-reset-gpios : Should specify the gpio for phy reset
 
 Optional properties:
 - local-mac-address : 6 bytes, mac address
+- phy-reset-gpios : Should specify the gpio for phy reset
 
 Example:
 
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 5/5] net: fec: add phy-reset-duration for device tree probe
  2012-06-27 13:45 [PATCH v2 0/5] fec driver updates Shawn Guo
                   ` (3 preceding siblings ...)
  2012-06-27 13:45 ` [PATCH v2 4/5] net: fec: phy-reset-gpios is optional Shawn Guo
@ 2012-06-27 13:45 ` Shawn Guo
  2012-06-28  4:30 ` [PATCH v2 0/5] fec driver updates David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: Shawn Guo @ 2012-06-27 13:45 UTC (permalink / raw)
  To: David S. Miller
  Cc: Lothar Waßmann, Florian Fainelli, netdev, linux-arm-kernel,
	devicetree-discuss, Shawn Guo

Different boards may require different phy reset duration.  Add property
phy-reset-duration for device tree probe, so that the boards that need
a longer reset duration can specify it in their device tree.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
 Documentation/devicetree/bindings/net/fsl-fec.txt |    4 ++++
 drivers/net/ethernet/freescale/fec.c              |    8 +++++++-
 2 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/fsl-fec.txt b/Documentation/devicetree/bindings/net/fsl-fec.txt
index 0428920..f7a2fef 100644
--- a/Documentation/devicetree/bindings/net/fsl-fec.txt
+++ b/Documentation/devicetree/bindings/net/fsl-fec.txt
@@ -11,6 +11,10 @@ Required properties:
 Optional properties:
 - local-mac-address : 6 bytes, mac address
 - phy-reset-gpios : Should specify the gpio for phy reset
+- phy-reset-duration : Reset duration in milliseconds.  Should present
+  only if property "phy-reset-gpios" is available.  Missing the property
+  will have the duration be 1 millisecond.  Numbers greater than 1000 are
+  invalid and 1 millisecond will be used instead.
 
 Example:
 
diff --git a/drivers/net/ethernet/freescale/fec.c b/drivers/net/ethernet/freescale/fec.c
index f174070..dafd797 100644
--- a/drivers/net/ethernet/freescale/fec.c
+++ b/drivers/net/ethernet/freescale/fec.c
@@ -1507,11 +1507,17 @@ static int __devinit fec_get_phy_mode_dt(struct platform_device *pdev)
 static void __devinit fec_reset_phy(struct platform_device *pdev)
 {
 	int err, phy_reset;
+	int msec = 1;
 	struct device_node *np = pdev->dev.of_node;
 
 	if (!np)
 		return;
 
+	of_property_read_u32(np, "phy-reset-duration", &msec);
+	/* A sane reset duration should not be longer than 1s */
+	if (msec > 1000)
+		msec = 1;
+
 	phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
 	err = devm_gpio_request_one(&pdev->dev, phy_reset,
 				    GPIOF_OUT_INIT_LOW, "phy-reset");
@@ -1519,7 +1525,7 @@ static void __devinit fec_reset_phy(struct platform_device *pdev)
 		pr_debug("FEC: failed to get gpio phy-reset: %d\n", err);
 		return;
 	}
-	msleep(1);
+	msleep(msec);
 	gpio_set_value(phy_reset, 1);
 }
 #else /* CONFIG_OF */
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 0/5] fec driver updates
  2012-06-27 13:45 [PATCH v2 0/5] fec driver updates Shawn Guo
                   ` (4 preceding siblings ...)
  2012-06-27 13:45 ` [PATCH v2 5/5] net: fec: add phy-reset-duration for device tree probe Shawn Guo
@ 2012-06-28  4:30 ` David Miller
  5 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2012-06-28  4:30 UTC (permalink / raw)
  To: shawn.guo; +Cc: LW, florian, netdev, linux-arm-kernel, devicetree-discuss

From: Shawn Guo <shawn.guo@linaro.org>
Date: Wed, 27 Jun 2012 21:45:19 +0800

> Changes since v1:
> * Add one patch to use devm_gpio_request_one
> * Have a separate patch to fix phy-reset-gpios property in binding
>   document
> * Change phy-reset-interval to phy-reset-duration
> * Add a sanity check on phy-reset-duration value

All applied.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-06-28  4:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-27 13:45 [PATCH v2 0/5] fec driver updates Shawn Guo
2012-06-27 13:45 ` [PATCH v2 1/5] net: fec: reset phy after pinctrl setup Shawn Guo
2012-06-27 13:45 ` [PATCH v2 2/5] net: fec: enable regulator for fec phy Shawn Guo
2012-06-27 13:45 ` [PATCH v2 3/5] net: fec: use managed function devm_gpio_request_one Shawn Guo
2012-06-27 13:45 ` [PATCH v2 4/5] net: fec: phy-reset-gpios is optional Shawn Guo
2012-06-27 13:45 ` [PATCH v2 5/5] net: fec: add phy-reset-duration for device tree probe Shawn Guo
2012-06-28  4:30 ` [PATCH v2 0/5] fec driver updates David Miller

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).