Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] net: stmmac: move reset gpio parse & request to stmmac_mdio_register
@ 2019-05-22 10:06 Jisheng Zhang
  2019-05-23  0:29 ` David Miller
  2019-05-23  0:30 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Jisheng Zhang @ 2019-05-22 10:06 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, David S. Miller
  Cc: netdev, linux-kernel, linux-arm-kernel

Move the reset gpio dt parse and request to stmmac_mdio_register(),
thus makes the mdio code straightforward.

This patch also replace stack var mdio_bus_data with data to simplify
the code.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 58 ++++++++-----------
 1 file changed, 25 insertions(+), 33 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 093a223fe408..7d1562ec1149 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -250,28 +250,7 @@ int stmmac_mdio_reset(struct mii_bus *bus)
 	struct stmmac_mdio_bus_data *data = priv->plat->mdio_bus_data;
 
 #ifdef CONFIG_OF
-	if (priv->device->of_node) {
-		if (data->reset_gpio < 0) {
-			struct device_node *np = priv->device->of_node;
-
-			if (!np)
-				return 0;
-
-			data->reset_gpio = of_get_named_gpio(np,
-						"snps,reset-gpio", 0);
-			if (data->reset_gpio < 0)
-				return 0;
-
-			data->active_low = of_property_read_bool(np,
-						"snps,reset-active-low");
-			of_property_read_u32_array(np,
-				"snps,reset-delays-us", data->delays, 3);
-
-			if (devm_gpio_request(priv->device, data->reset_gpio,
-					      "mdio-reset"))
-				return 0;
-		}
-
+	if (gpio_is_valid(data->reset_gpio)) {
 		gpio_direction_output(data->reset_gpio,
 				      data->active_low ? 1 : 0);
 		if (data->delays[0])
@@ -313,24 +292,38 @@ int stmmac_mdio_register(struct net_device *ndev)
 	int err = 0;
 	struct mii_bus *new_bus;
 	struct stmmac_priv *priv = netdev_priv(ndev);
-	struct stmmac_mdio_bus_data *mdio_bus_data = priv->plat->mdio_bus_data;
+	struct stmmac_mdio_bus_data *data = priv->plat->mdio_bus_data;
 	struct device_node *mdio_node = priv->plat->mdio_node;
 	struct device *dev = ndev->dev.parent;
 	int addr, found, max_addr;
 
-	if (!mdio_bus_data)
+	if (!data)
 		return 0;
 
 	new_bus = mdiobus_alloc();
 	if (!new_bus)
 		return -ENOMEM;
 
-	if (mdio_bus_data->irqs)
-		memcpy(new_bus->irq, mdio_bus_data->irqs, sizeof(new_bus->irq));
+	if (data->irqs)
+		memcpy(new_bus->irq, data->irqs, sizeof(new_bus->irq));
 
 #ifdef CONFIG_OF
-	if (priv->device->of_node)
-		mdio_bus_data->reset_gpio = -1;
+	if (priv->device->of_node) {
+		struct device_node *np = priv->device->of_node;
+
+		data->reset_gpio = of_get_named_gpio(np, "snps,reset-gpio", 0);
+		if (gpio_is_valid(data->reset_gpio)) {
+			data->active_low = of_property_read_bool(np,
+						"snps,reset-active-low");
+			of_property_read_u32_array(np,
+				"snps,reset-delays-us", data->delays, 3);
+
+			devm_gpio_request(priv->device, data->reset_gpio,
+					  "mdio-reset");
+		}
+	} else {
+		data->reset_gpio = -1;
+	}
 #endif
 
 	new_bus->name = "stmmac";
@@ -356,7 +349,7 @@ int stmmac_mdio_register(struct net_device *ndev)
 	snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s-%x",
 		 new_bus->name, priv->plat->bus_id);
 	new_bus->priv = ndev;
-	new_bus->phy_mask = mdio_bus_data->phy_mask;
+	new_bus->phy_mask = data->phy_mask;
 	new_bus->parent = priv->device;
 
 	err = of_mdiobus_register(new_bus, mdio_node);
@@ -379,10 +372,9 @@ int stmmac_mdio_register(struct net_device *ndev)
 		 * If an IRQ was provided to be assigned after
 		 * the bus probe, do it here.
 		 */
-		if (!mdio_bus_data->irqs &&
-		    (mdio_bus_data->probed_phy_irq > 0)) {
-			new_bus->irq[addr] = mdio_bus_data->probed_phy_irq;
-			phydev->irq = mdio_bus_data->probed_phy_irq;
+		if (!data->irqs && (data->probed_phy_irq > 0)) {
+			new_bus->irq[addr] = data->probed_phy_irq;
+			phydev->irq = data->probed_phy_irq;
 		}
 
 		/*
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] net: stmmac: move reset gpio parse & request to stmmac_mdio_register
  2019-05-22 10:06 [PATCH] net: stmmac: move reset gpio parse & request to stmmac_mdio_register Jisheng Zhang
@ 2019-05-23  0:29 ` David Miller
  2019-05-23  0:30 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-05-23  0:29 UTC (permalink / raw)
  To: Jisheng.Zhang
  Cc: alexandre.torgue, netdev, linux-kernel, joabreu, peppe.cavallaro,
	linux-arm-kernel


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] net: stmmac: move reset gpio parse & request to stmmac_mdio_register
  2019-05-22 10:06 [PATCH] net: stmmac: move reset gpio parse & request to stmmac_mdio_register Jisheng Zhang
  2019-05-23  0:29 ` David Miller
@ 2019-05-23  0:30 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-05-23  0:30 UTC (permalink / raw)
  To: Jisheng.Zhang
  Cc: alexandre.torgue, netdev, linux-kernel, joabreu, peppe.cavallaro,
	linux-arm-kernel

From: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
Date: Wed, 22 May 2019 10:06:56 +0000

> Move the reset gpio dt parse and request to stmmac_mdio_register(),
> thus makes the mdio code straightforward.
> 
> This patch also replace stack var mdio_bus_data with data to simplify
> the code.
> 
> Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>

Please rebase this on net-next when I next merge net into net-next as
this is a cleanup and therefore not appropriate for net.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-22 10:06 [PATCH] net: stmmac: move reset gpio parse & request to stmmac_mdio_register Jisheng Zhang
2019-05-23  0:29 ` David Miller
2019-05-23  0:30 ` David Miller

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org infradead-linux-arm-kernel@archiver.kernel.org
	public-inbox-index linux-arm-kernel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox