Netdev Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH net-next v1 0/5] stmmac: cleanups for stmmac_mdio_reset
@ 2019-06-15 10:09 Martin Blumenstingl
  2019-06-15 10:09 ` [PATCH net-next v1 1/5] net: stmmac: drop redundant check in stmmac_mdio_reset Martin Blumenstingl
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Martin Blumenstingl @ 2019-06-15 10:09 UTC (permalink / raw)
  To: netdev, peppe.cavallaro, alexandre.torgue, joabreu, davem
  Cc: linus.walleij, andrew, linux-arm-kernel, linux-kernel,
	Martin Blumenstingl

This is a successor to my previous series "stmmac: honor the GPIO flags
for the PHY reset GPIO" from [0]. It contains only the "cleanup"
patches from that series plus some additional cleanups on top.

I broke out the actual GPIO flag handling into a separate patch which
is already part of net-next: "net: stmmac: use GPIO descriptors in
stmmac_mdio_reset" from [1]

I have build and runtime tested this on my ARM Meson8b Odroid-C1.


[0] https://patchwork.kernel.org/cover/10983801/
[1] https://patchwork.ozlabs.org/patch/1114798/


Martin Blumenstingl (5):
  net: stmmac: drop redundant check in stmmac_mdio_reset
  net: stmmac: use device_property_read_u32_array to read the reset
    delays
  net: stmmac: drop the reset GPIO from struct stmmac_mdio_bus_data
  net: stmmac: drop the reset delays from struct stmmac_mdio_bus_data
  net: stmmac: drop the phy_reset hook from struct stmmac_mdio_bus_data

 .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 52 ++++++-------------
 include/linux/stmmac.h                        |  5 --
 2 files changed, 16 insertions(+), 41 deletions(-)

-- 
2.22.0


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

* [PATCH net-next v1 1/5] net: stmmac: drop redundant check in stmmac_mdio_reset
  2019-06-15 10:09 [PATCH net-next v1 0/5] stmmac: cleanups for stmmac_mdio_reset Martin Blumenstingl
@ 2019-06-15 10:09 ` Martin Blumenstingl
  2019-06-15 10:09 ` [PATCH net-next v1 2/5] net: stmmac: use device_property_read_u32_array to read the reset delays Martin Blumenstingl
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Martin Blumenstingl @ 2019-06-15 10:09 UTC (permalink / raw)
  To: netdev, peppe.cavallaro, alexandre.torgue, joabreu, davem
  Cc: linus.walleij, andrew, linux-arm-kernel, linux-kernel,
	Martin Blumenstingl

A simplified version of the existing code looks like this:
  if (priv->device->of_node) {
      struct device_node *np = priv->device->of_node;
      if (!np)
          return 0;

The second "if" never evaluates to true because the first "if" checks
for exactly the opposite.
Drop the redundant check and early return to make the code easier to
understand.

No functional changes intended.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index f1c39dd048e7..21bbe3ba3e8e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -256,9 +256,6 @@ int stmmac_mdio_reset(struct mii_bus *bus)
 		if (data->reset_gpio < 0) {
 			struct device_node *np = priv->device->of_node;
 
-			if (!np)
-				return 0;
-
 			reset_gpio = devm_gpiod_get_optional(priv->device,
 							     "snps,reset",
 							     GPIOD_OUT_LOW);
-- 
2.22.0


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

* [PATCH net-next v1 2/5] net: stmmac: use device_property_read_u32_array to read the reset delays
  2019-06-15 10:09 [PATCH net-next v1 0/5] stmmac: cleanups for stmmac_mdio_reset Martin Blumenstingl
  2019-06-15 10:09 ` [PATCH net-next v1 1/5] net: stmmac: drop redundant check in stmmac_mdio_reset Martin Blumenstingl
@ 2019-06-15 10:09 ` Martin Blumenstingl
  2019-06-15 10:09 ` [PATCH net-next v1 3/5] net: stmmac: drop the reset GPIO from struct stmmac_mdio_bus_data Martin Blumenstingl
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Martin Blumenstingl @ 2019-06-15 10:09 UTC (permalink / raw)
  To: netdev, peppe.cavallaro, alexandre.torgue, joabreu, davem
  Cc: linus.walleij, andrew, linux-arm-kernel, linux-kernel,
	Martin Blumenstingl

Change stmmac_mdio_reset() to use device_property_read_u32_array()
instead of of_property_read_u32_array().

This is meant as a cleanup because we can drop the struct device_node
variable. Also it will make it easier to get rid of struct
stmmac_mdio_bus_data (or at least make it private) in the future because
non-OF platforms can now pass the reset delays as device properties.

No functional changes (neither for OF platforms nor for ones that are
not using OF, because the modified code is still contained in an "if
(priv->device->of_node)").

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 21bbe3ba3e8e..4614f1f2bffb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -24,9 +24,9 @@
 #include <linux/io.h>
 #include <linux/iopoll.h>
 #include <linux/mii.h>
-#include <linux/of.h>
 #include <linux/of_mdio.h>
 #include <linux/phy.h>
+#include <linux/property.h>
 #include <linux/slab.h>
 
 #include "dwxgmac2.h"
@@ -254,16 +254,15 @@ int stmmac_mdio_reset(struct mii_bus *bus)
 		struct gpio_desc *reset_gpio;
 
 		if (data->reset_gpio < 0) {
-			struct device_node *np = priv->device->of_node;
-
 			reset_gpio = devm_gpiod_get_optional(priv->device,
 							     "snps,reset",
 							     GPIOD_OUT_LOW);
 			if (IS_ERR(reset_gpio))
 				return PTR_ERR(reset_gpio);
 
-			of_property_read_u32_array(np,
-				"snps,reset-delays-us", data->delays, 3);
+			device_property_read_u32_array(priv->device,
+						       "snps,reset-delays-us",
+						       data->delays, 3);
 		} else {
 			reset_gpio = gpio_to_desc(data->reset_gpio);
 
-- 
2.22.0


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

* [PATCH net-next v1 3/5] net: stmmac: drop the reset GPIO from struct stmmac_mdio_bus_data
  2019-06-15 10:09 [PATCH net-next v1 0/5] stmmac: cleanups for stmmac_mdio_reset Martin Blumenstingl
  2019-06-15 10:09 ` [PATCH net-next v1 1/5] net: stmmac: drop redundant check in stmmac_mdio_reset Martin Blumenstingl
  2019-06-15 10:09 ` [PATCH net-next v1 2/5] net: stmmac: use device_property_read_u32_array to read the reset delays Martin Blumenstingl
@ 2019-06-15 10:09 ` Martin Blumenstingl
  2019-06-18 14:00   ` Linus Walleij
  2019-06-15 10:09 ` [PATCH net-next v1 4/5] net: stmmac: drop the reset delays " Martin Blumenstingl
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: Martin Blumenstingl @ 2019-06-15 10:09 UTC (permalink / raw)
  To: netdev, peppe.cavallaro, alexandre.torgue, joabreu, davem
  Cc: linus.walleij, andrew, linux-arm-kernel, linux-kernel,
	Martin Blumenstingl

No platform uses the "reset_gpio" field from stmmac_mdio_bus_data
anymore. Drop it so we don't get any new consumers either.

Plain GPIO numbers are being deprecated in favor of GPIO descriptors. If
needed any new non-OF platform can add a GPIO descriptor lookup table.
devm_gpiod_get_optional() will find the GPIO in that case.

Suggested-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 29 ++++++-------------
 include/linux/stmmac.h                        |  1 -
 2 files changed, 9 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 4614f1f2bffb..459ef8afe4fb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -253,21 +253,15 @@ int stmmac_mdio_reset(struct mii_bus *bus)
 	if (priv->device->of_node) {
 		struct gpio_desc *reset_gpio;
 
-		if (data->reset_gpio < 0) {
-			reset_gpio = devm_gpiod_get_optional(priv->device,
-							     "snps,reset",
-							     GPIOD_OUT_LOW);
-			if (IS_ERR(reset_gpio))
-				return PTR_ERR(reset_gpio);
-
-			device_property_read_u32_array(priv->device,
-						       "snps,reset-delays-us",
-						       data->delays, 3);
-		} else {
-			reset_gpio = gpio_to_desc(data->reset_gpio);
-
-			gpiod_direction_output(reset_gpio, 0);
-		}
+		reset_gpio = devm_gpiod_get_optional(priv->device,
+						     "snps,reset",
+						     GPIOD_OUT_LOW);
+		if (IS_ERR(reset_gpio))
+			return PTR_ERR(reset_gpio);
+
+		device_property_read_u32_array(priv->device,
+					       "snps,reset-delays-us",
+					       data->delays, 3);
 
 		if (data->delays[0])
 			msleep(DIV_ROUND_UP(data->delays[0], 1000));
@@ -323,11 +317,6 @@ int stmmac_mdio_register(struct net_device *ndev)
 	if (mdio_bus_data->irqs)
 		memcpy(new_bus->irq, mdio_bus_data->irqs, sizeof(new_bus->irq));
 
-#ifdef CONFIG_OF
-	if (priv->device->of_node)
-		mdio_bus_data->reset_gpio = -1;
-#endif
-
 	new_bus->name = "stmmac";
 
 	if (priv->plat->has_xgmac) {
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 816edb545592..fe865df82e48 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -97,7 +97,6 @@ struct stmmac_mdio_bus_data {
 	int *irqs;
 	int probed_phy_irq;
 #ifdef CONFIG_OF
-	int reset_gpio;
 	u32 delays[3];
 #endif
 };
-- 
2.22.0


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

* [PATCH net-next v1 4/5] net: stmmac: drop the reset delays from struct stmmac_mdio_bus_data
  2019-06-15 10:09 [PATCH net-next v1 0/5] stmmac: cleanups for stmmac_mdio_reset Martin Blumenstingl
                   ` (2 preceding siblings ...)
  2019-06-15 10:09 ` [PATCH net-next v1 3/5] net: stmmac: drop the reset GPIO from struct stmmac_mdio_bus_data Martin Blumenstingl
@ 2019-06-15 10:09 ` " Martin Blumenstingl
  2019-06-15 10:09 ` [PATCH net-next v1 5/5] net: stmmac: drop the phy_reset hook " Martin Blumenstingl
  2019-06-16 20:53 ` [PATCH net-next v1 0/5] stmmac: cleanups for stmmac_mdio_reset David Miller
  5 siblings, 0 replies; 8+ messages in thread
From: Martin Blumenstingl @ 2019-06-15 10:09 UTC (permalink / raw)
  To: netdev, peppe.cavallaro, alexandre.torgue, joabreu, davem
  Cc: linus.walleij, andrew, linux-arm-kernel, linux-kernel,
	Martin Blumenstingl

Only OF platforms use the reset delays and these delays are only read in
stmmac_mdio_reset(). Move them from struct stmmac_mdio_bus_data to a
stack variable inside stmmac_mdio_reset() because that's the only usage
of these delays.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 15 ++++++++-------
 include/linux/stmmac.h                            |  3 ---
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 459ef8afe4fb..c9454cf4f189 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -252,6 +252,7 @@ int stmmac_mdio_reset(struct mii_bus *bus)
 #ifdef CONFIG_OF
 	if (priv->device->of_node) {
 		struct gpio_desc *reset_gpio;
+		u32 delays[3];
 
 		reset_gpio = devm_gpiod_get_optional(priv->device,
 						     "snps,reset",
@@ -261,18 +262,18 @@ int stmmac_mdio_reset(struct mii_bus *bus)
 
 		device_property_read_u32_array(priv->device,
 					       "snps,reset-delays-us",
-					       data->delays, 3);
+					       delays, ARRAY_SIZE(delays));
 
-		if (data->delays[0])
-			msleep(DIV_ROUND_UP(data->delays[0], 1000));
+		if (delays[0])
+			msleep(DIV_ROUND_UP(delays[0], 1000));
 
 		gpiod_set_value_cansleep(reset_gpio, 1);
-		if (data->delays[1])
-			msleep(DIV_ROUND_UP(data->delays[1], 1000));
+		if (delays[1])
+			msleep(DIV_ROUND_UP(delays[1], 1000));
 
 		gpiod_set_value_cansleep(reset_gpio, 0);
-		if (data->delays[2])
-			msleep(DIV_ROUND_UP(data->delays[2], 1000));
+		if (delays[2])
+			msleep(DIV_ROUND_UP(delays[2], 1000));
 	}
 #endif
 
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index fe865df82e48..96d97c908595 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -96,9 +96,6 @@ struct stmmac_mdio_bus_data {
 	unsigned int phy_mask;
 	int *irqs;
 	int probed_phy_irq;
-#ifdef CONFIG_OF
-	u32 delays[3];
-#endif
 };
 
 struct stmmac_dma_cfg {
-- 
2.22.0


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

* [PATCH net-next v1 5/5] net: stmmac: drop the phy_reset hook from struct stmmac_mdio_bus_data
  2019-06-15 10:09 [PATCH net-next v1 0/5] stmmac: cleanups for stmmac_mdio_reset Martin Blumenstingl
                   ` (3 preceding siblings ...)
  2019-06-15 10:09 ` [PATCH net-next v1 4/5] net: stmmac: drop the reset delays " Martin Blumenstingl
@ 2019-06-15 10:09 ` " Martin Blumenstingl
  2019-06-16 20:53 ` [PATCH net-next v1 0/5] stmmac: cleanups for stmmac_mdio_reset David Miller
  5 siblings, 0 replies; 8+ messages in thread
From: Martin Blumenstingl @ 2019-06-15 10:09 UTC (permalink / raw)
  To: netdev, peppe.cavallaro, alexandre.torgue, joabreu, davem
  Cc: linus.walleij, andrew, linux-arm-kernel, linux-kernel,
	Martin Blumenstingl

The phy_reset hook is not set anywhere. Drop it to make
stmmac_mdio_reset() smaller.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 6 ------
 include/linux/stmmac.h                            | 1 -
 2 files changed, 7 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index c9454cf4f189..14aa3ee14082 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -247,7 +247,6 @@ int stmmac_mdio_reset(struct mii_bus *bus)
 	struct net_device *ndev = bus->priv;
 	struct stmmac_priv *priv = netdev_priv(ndev);
 	unsigned int mii_address = priv->hw->mii.addr;
-	struct stmmac_mdio_bus_data *data = priv->plat->mdio_bus_data;
 
 #ifdef CONFIG_OF
 	if (priv->device->of_node) {
@@ -277,11 +276,6 @@ int stmmac_mdio_reset(struct mii_bus *bus)
 	}
 #endif
 
-	if (data->phy_reset) {
-		netdev_dbg(ndev, "stmmac_mdio_reset: calling phy_reset\n");
-		data->phy_reset(priv->plat->bsp_priv);
-	}
-
 	/* This is a workaround for problems with the STE101P PHY.
 	 * It doesn't complete its reset until at least one clock cycle
 	 * on MDC, so perform a dummy mdio read. To be updated for GMAC4
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 96d97c908595..9aad16c379e7 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -92,7 +92,6 @@
 /* Platfrom data for platform device structure's platform_data field */
 
 struct stmmac_mdio_bus_data {
-	int (*phy_reset)(void *priv);
 	unsigned int phy_mask;
 	int *irqs;
 	int probed_phy_irq;
-- 
2.22.0


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

* Re: [PATCH net-next v1 0/5] stmmac: cleanups for stmmac_mdio_reset
  2019-06-15 10:09 [PATCH net-next v1 0/5] stmmac: cleanups for stmmac_mdio_reset Martin Blumenstingl
                   ` (4 preceding siblings ...)
  2019-06-15 10:09 ` [PATCH net-next v1 5/5] net: stmmac: drop the phy_reset hook " Martin Blumenstingl
@ 2019-06-16 20:53 ` David Miller
  5 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2019-06-16 20:53 UTC (permalink / raw)
  To: martin.blumenstingl
  Cc: netdev, peppe.cavallaro, alexandre.torgue, joabreu,
	linus.walleij, andrew, linux-arm-kernel, linux-kernel

From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Date: Sat, 15 Jun 2019 12:09:27 +0200

> This is a successor to my previous series "stmmac: honor the GPIO flags
> for the PHY reset GPIO" from [0]. It contains only the "cleanup"
> patches from that series plus some additional cleanups on top.
> 
> I broke out the actual GPIO flag handling into a separate patch which
> is already part of net-next: "net: stmmac: use GPIO descriptors in
> stmmac_mdio_reset" from [1]
> 
> I have build and runtime tested this on my ARM Meson8b Odroid-C1.
> 
> 
> [0] https://patchwork.kernel.org/cover/10983801/
> [1] https://patchwork.ozlabs.org/patch/1114798/

Looks good, series applied.

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

* Re: [PATCH net-next v1 3/5] net: stmmac: drop the reset GPIO from struct stmmac_mdio_bus_data
  2019-06-15 10:09 ` [PATCH net-next v1 3/5] net: stmmac: drop the reset GPIO from struct stmmac_mdio_bus_data Martin Blumenstingl
@ 2019-06-18 14:00   ` Linus Walleij
  0 siblings, 0 replies; 8+ messages in thread
From: Linus Walleij @ 2019-06-18 14:00 UTC (permalink / raw)
  To: Martin Blumenstingl
  Cc: netdev, Giuseppe CAVALLARO, Alexandre TORGUE, Jose Abreu,
	David S. Miller, Andrew Lunn, Linux ARM, linux-kernel

On Sat, Jun 15, 2019 at 12:09 PM Martin Blumenstingl
<martin.blumenstingl@googlemail.com> wrote:

> No platform uses the "reset_gpio" field from stmmac_mdio_bus_data
> anymore. Drop it so we don't get any new consumers either.
>
> Plain GPIO numbers are being deprecated in favor of GPIO descriptors. If
> needed any new non-OF platform can add a GPIO descriptor lookup table.
> devm_gpiod_get_optional() will find the GPIO in that case.
>
> Suggested-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

end of thread, back to index

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-15 10:09 [PATCH net-next v1 0/5] stmmac: cleanups for stmmac_mdio_reset Martin Blumenstingl
2019-06-15 10:09 ` [PATCH net-next v1 1/5] net: stmmac: drop redundant check in stmmac_mdio_reset Martin Blumenstingl
2019-06-15 10:09 ` [PATCH net-next v1 2/5] net: stmmac: use device_property_read_u32_array to read the reset delays Martin Blumenstingl
2019-06-15 10:09 ` [PATCH net-next v1 3/5] net: stmmac: drop the reset GPIO from struct stmmac_mdio_bus_data Martin Blumenstingl
2019-06-18 14:00   ` Linus Walleij
2019-06-15 10:09 ` [PATCH net-next v1 4/5] net: stmmac: drop the reset delays " Martin Blumenstingl
2019-06-15 10:09 ` [PATCH net-next v1 5/5] net: stmmac: drop the phy_reset hook " Martin Blumenstingl
2019-06-16 20:53 ` [PATCH net-next v1 0/5] stmmac: cleanups for stmmac_mdio_reset David Miller

Netdev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netdev/0 netdev/git/0.git
	git clone --mirror https://lore.kernel.org/netdev/1 netdev/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 netdev netdev/ https://lore.kernel.org/netdev \
		netdev@vger.kernel.org netdev@archiver.kernel.org
	public-inbox-index netdev


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netdev


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