Skip to contentSkip to conversation

Teach phylib hard-resetting devices

PATCH In review Sergei Shtylyov 4 participants 10 messages Apr 28, 2016 – May 9, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover Teach phylib hard-resetting devices

Hello.

Here's the set of 2 patches against DaveM's 'net-next.git' repo. They add to
the 'phylib' support for resetting devices via GPIO and do some clean up after doing that...

[1/2] phylib: add device reset GPIO support
[2/2] macb: kill PHY reset code

MBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw

PATCH v2 2/2 macb: kill PHY reset code

With the 'phylib' now being aware of the "reset-gpios" PHY node property, there should be no need to frob the PHY reset in this driver anymore...

---
 drivers/net/ethernet/cadence/macb.c |   17 -----------------
 drivers/net/ethernet/cadence/macb.h |    1 -
 2 files changed, 18 deletions(-)
drivers/net/ethernet/cadence/macb.c +0 -17
Index: net-next/drivers/net/ethernet/cadence/macb.c
===================================================================
@@ -2884,7 +2884,6 @@ static int macb_probe(struct platform_de
 					      = macb_clk_init;
 	int (*init)(struct platform_device *) = macb_init;
 	struct device_node *np = pdev->dev.of_node;
-	struct device_node *phy_node;
 	const struct macb_config *macb_config = NULL;
 	struct clk *pclk, *hclk = NULL, *tx_clk = NULL;
 	unsigned int queue_mask, num_queues;
@@ -2977,18 +2976,6 @@ static int macb_probe(struct platform_de
 	else
 		macb_get_hwaddr(bp);
 
-	/* Power up the PHY if there is a GPIO reset */
-	phy_node =  of_get_next_available_child(np, NULL);
-	if (phy_node) {
-		int gpio = of_get_named_gpio(phy_node, "reset-gpios", 0);
-
-		if (gpio_is_valid(gpio)) {
-			bp->reset_gpio = gpio_to_desc(gpio);
-			gpiod_direction_output(bp->reset_gpio, 1);
-		}
-	}
-	of_node_put(phy_node);
-
 	err = of_get_phy_mode(np);
 	if (err < 0) {
 		pdata = dev_get_platdata(&pdev->dev);
@@ -3054,10 +3041,6 @@ static int macb_remove(struct platform_d
 		mdiobus_unregister(bp->mii_bus);
 		mdiobus_free(bp->mii_bus);
 
-		/* Shutdown the PHY if there is a GPIO reset */
-		if (bp->reset_gpio)
-			gpiod_set_value(bp->reset_gpio, 0);
-
 		unregister_netdev(dev);
 		clk_disable_unprepare(bp->tx_clk);
 		clk_disable_unprepare(bp->hclk);
drivers/net/ethernet/cadence/macb.h +0 -1
Index: net-next/drivers/net/ethernet/cadence/macb.h
===================================================================
@@ -832,7 +832,6 @@ struct macb {
 	unsigned int		dma_burst_length;
 
 	phy_interface_t		phy_interface;
-	struct gpio_desc	*reset_gpio;
 
 	/* AT91RM9200 transmit */
 	struct sk_buff *skb;			/* holds skb until xmit interrupt completes */
Acked-by on v2 2/2
#2 lore raw

Re: [PATCH RFT v2 2/2] macb: kill PHY reset code

Quoted 4 lines · Sergei Shtylyov

With the 'phylib' now being aware of the "reset-gpios" PHY node property, there should be no need to frob the PHY reset in this driver anymore...

So I queue my DT patch through arm-soc.

Thanks Sergei, bye.

Quoted 61 lines
---
 drivers/net/ethernet/cadence/macb.c |   17 -----------------
 drivers/net/ethernet/cadence/macb.h |    1 -
 2 files changed, 18 deletions(-)

Index: net-next/drivers/net/ethernet/cadence/macb.c
===================================================================

drivers/net/ethernet/cadence/macb.c +0 -17
@@ -2884,7 +2884,6 @@ static int macb_probe(struct platform_de
 					      = macb_clk_init;
 	int (*init)(struct platform_device *) = macb_init;
 	struct device_node *np = pdev->dev.of_node;
-	struct device_node *phy_node;
 	const struct macb_config *macb_config = NULL;
 	struct clk *pclk, *hclk = NULL, *tx_clk = NULL;
 	unsigned int queue_mask, num_queues;
@@ -2977,18 +2976,6 @@ static int macb_probe(struct platform_de
 	else
 		macb_get_hwaddr(bp);
 
-	/* Power up the PHY if there is a GPIO reset */
-	phy_node =  of_get_next_available_child(np, NULL);
-	if (phy_node) {
-		int gpio = of_get_named_gpio(phy_node, "reset-gpios", 0);
-
-		if (gpio_is_valid(gpio)) {
-			bp->reset_gpio = gpio_to_desc(gpio);
-			gpiod_direction_output(bp->reset_gpio, 1);
-		}
-	}
-	of_node_put(phy_node);
-
 	err = of_get_phy_mode(np);
 	if (err < 0) {
 		pdata = dev_get_platdata(&pdev->dev);
@@ -3054,10 +3041,6 @@ static int macb_remove(struct platform_d
 		mdiobus_unregister(bp->mii_bus);
 		mdiobus_free(bp->mii_bus);
 
-		/* Shutdown the PHY if there is a GPIO reset */
-		if (bp->reset_gpio)
-			gpiod_set_value(bp->reset_gpio, 0);
-
 		unregister_netdev(dev);
 		clk_disable_unprepare(bp->tx_clk);
 		clk_disable_unprepare(bp->hclk);

Index: net-next/drivers/net/ethernet/cadence/macb.h
===================================================================

drivers/net/ethernet/cadence/macb.h +0 -1
@@ -832,7 +832,6 @@ struct macb {
 	unsigned int		dma_burst_length;
 
 	phy_interface_t		phy_interface;
-	struct gpio_desc	*reset_gpio;
 
 	/* AT91RM9200 transmit */
 	struct sk_buff *skb;			/* holds skb until xmit interrupt completes */
Signature · 1 line
Nicolas Ferre
#3 lore raw

PATCH 1/1 pxa168_eth: fix mdiobus_scan() error check

In reply to Sergei Shtylyov

Since mdiobus_scan() returns either an error code or NULL on error, the driver should check for both, not only for NULL, otherwise a crash is imminent...

---
The patch is against DaveM's 'net.git' repo.

 drivers/net/ethernet/marvell/pxa168_eth.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/pxa168_eth.c +2 -0
Index: net/drivers/net/ethernet/marvell/pxa168_eth.c
===================================================================
@@ -979,6 +979,8 @@ static int pxa168_init_phy(struct net_de
 		return 0;
 
 	pep->phy = mdiobus_scan(pep->smi_bus, pep->phy_addr);
+	if (IS_ERR(pep->phy))
+		return PTR_ERR(pep->phy);
 	if (!pep->phy)
 		return -ENODEV;
 
#4 lore raw

Re: [PATCH] pxa168_eth: fix mdiobus_scan() error check

Quoted 18 lines · Sergei Shtylyov

Since mdiobus_scan() returns either an error code or NULL on error, the driver should check for both, not only for NULL, otherwise a crash is imminent...

---
The patch is against DaveM's 'net.git' repo.

 drivers/net/ethernet/marvell/pxa168_eth.c |    2 ++
 1 file changed, 2 insertions(+)

Index: net/drivers/net/ethernet/marvell/pxa168_eth.c
===================================================================

drivers/net/ethernet/marvell/pxa168_eth.c static int pxa168_init_phy(struct net_de · line 985

Quoted 7 lines
drivers/net/ethernet/marvell/pxa168_eth.c +2 -0
@@ -979,6 +979,8 @@ static int pxa168_init_phy(struct net_de
 		return 0;
 
 	pep->phy = mdiobus_scan(pep->smi_bus, pep->phy_addr);
+	if (IS_ERR(pep->phy))
+		return PTR_ERR(pep->phy);
 	if (!pep->phy)
 		return -ENODEV;

Should not this check be removed too and converted to a PTR_ERR(pep->phy) != -ENODEV?

Signature · 1 line
Florian
#5 lore raw

Re: [PATCH] pxa168_eth: fix mdiobus_scan() error check

Hello.

Quoted 20 lines · Florian Fainelli
Quoted 20 lines

Since mdiobus_scan() returns either an error code or NULL on error, the driver should check for both, not only for NULL, otherwise a crash is imminent...

---
The patch is against DaveM's 'net.git' repo.

  drivers/net/ethernet/marvell/pxa168_eth.c |    2 ++
  1 file changed, 2 insertions(+)

Index: net/drivers/net/ethernet/marvell/pxa168_eth.c
===================================================================

drivers/net/ethernet/marvell/pxa168_eth.c +0 -0
@@ -979,6 +979,8 @@ static int pxa168_init_phy(struct net_de
  		return 0;
 
Quoted 7 lines

drivers/net/ethernet/marvell/pxa168_eth.c static int pxa168_init_phy(struct net_de · line 985

Quoted 5 lines
drivers/net/ethernet/marvell/pxa168_eth.c +2 -0
  	pep->phy = mdiobus_scan(pep->smi_bus, pep->phy_addr);
+	if (IS_ERR(pep->phy))
+		return PTR_ERR(pep->phy);
  	if (!pep->phy)
  		return -ENODEV;

Should not this check be removed too and

That's my next move -- for now I'm fixing the existing bug in this driver
only.

Quoted 1 line

converted to a PTR_ERR(pep->phy) != -ENODEV?

I don't see what that would achieve, IMO it's enough to just drop this
*if* altogether.

MBR, Sergei

#6 lore raw

Re: [PATCH] pxa168_eth: fix mdiobus_scan() error check

Quoted 28 lines · Sergei Shtylyov
Quoted 20 lines
Quoted 20 lines

Since mdiobus_scan() returns either an error code or NULL on error, the driver should check for both, not only for NULL, otherwise a crash is imminent...

---
The patch is against DaveM's 'net.git' repo.

  drivers/net/ethernet/marvell/pxa168_eth.c |    2 ++
  1 file changed, 2 insertions(+)

Index: net/drivers/net/ethernet/marvell/pxa168_eth.c
===================================================================

drivers/net/ethernet/marvell/pxa168_eth.c +0 -0
@@ -979,6 +979,8 @@ static int pxa168_init_phy(struct net_de
          return 0;
 
Quoted 7 lines

drivers/net/ethernet/marvell/pxa168_eth.c static int pxa168_init_phy(struct net_de · line 985

Quoted 5 lines
drivers/net/ethernet/marvell/pxa168_eth.c +2 -0
      pep->phy = mdiobus_scan(pep->smi_bus, pep->phy_addr);
+    if (IS_ERR(pep->phy))
+        return PTR_ERR(pep->phy);
      if (!pep->phy)
          return -ENODEV;

Should not this check be removed too and

Quoted 2 lines

That's my next move -- for now I'm fixing the existing bug in this driver
only.

In fact, it can't be removed yet as mdiobus_scan() may return NULL on
other error path. There's certainly a space for improvements yet... [...]

MBR, Sergei

#8 lore raw

PATCH 1/1 pxa168_eth: mdiobus_scan() doesn't return NULL anymore

In reply to Sergei Shtylyov

Now that mdiobus_scan() doesn't return NULL on failure anymore, this driver no longer needs to check for it...

---
The patch is against DaveM's 'net-next.git' repo.

 drivers/net/ethernet/marvell/pxa168_eth.c |    2 --
 1 file changed, 2 deletions(-)
drivers/net/ethernet/marvell/pxa168_eth.c +0 -2
Index: net-next/drivers/net/ethernet/marvell/pxa168_eth.c
===================================================================
@@ -981,8 +981,6 @@ static int pxa168_init_phy(struct net_de
 	pep->phy = mdiobus_scan(pep->smi_bus, pep->phy_addr);
 	if (IS_ERR(pep->phy))
 		return PTR_ERR(pep->phy);
-	if (!pep->phy)
-		return -ENODEV;
 
 	err = phy_connect_direct(dev, pep->phy, pxa168_eth_adjust_link,
 				 pep->phy_intf);
maintainer Applied
#9 lore raw

Re: [PATCH] pxa168_eth: mdiobus_scan() doesn't return NULL anymore

From: Sergei Shtylyov <[email protected]>
Date: Sat, 07 May 2016 22:53:40 +0300

Quoted 4 lines

Now that mdiobus_scan() doesn't return NULL on failure anymore, this driver no longer needs to check for it...

Applied.