summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Blumenstingl <martin.blumenstingl@googlemail.com>2019-06-12 15:31:15 -0400
committerDavid S. Miller <davem@davemloft.net>2019-06-14 22:08:40 -0400
commit7c86f20d15b7c1132e0c24358ce240ba4cb002b7 (patch)
tree237ef62fafa7912212c1434913ff069c2c58d355
parent4373a5e2606b4eda14fa096caf93dc2efc22689f (diff)
net: stmmac: use GPIO descriptors in stmmac_mdio_reset
Switch stmmac_mdio_reset to use GPIO descriptors. GPIO core handles the "snps,reset-gpio" for GPIO descriptors so we don't need to take care of it inside the driver anymore. The advantage of this is that we now preserve the GPIO flags which are passed via devicetree. This is required on some newer Amlogic boards which use an Open Drain pin for the reset GPIO. This pin can only output a LOW signal or switch to input mode but it cannot output a HIGH signal. There are already devicetree bindings for these special cases and GPIO core already takes care of them but only if we use GPIO descriptors instead of GPIO numbers. Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c27
-rw-r--r--include/linux/stmmac.h2
2 files changed, 14 insertions, 15 deletions
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 093a223fe408..f1c39dd048e7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -20,11 +20,11 @@
20 Maintainer: Giuseppe Cavallaro <peppe.cavallaro@st.com> 20 Maintainer: Giuseppe Cavallaro <peppe.cavallaro@st.com>
21*******************************************************************************/ 21*******************************************************************************/
22 22
23#include <linux/gpio/consumer.h>
23#include <linux/io.h> 24#include <linux/io.h>
24#include <linux/iopoll.h> 25#include <linux/iopoll.h>
25#include <linux/mii.h> 26#include <linux/mii.h>
26#include <linux/of.h> 27#include <linux/of.h>
27#include <linux/of_gpio.h>
28#include <linux/of_mdio.h> 28#include <linux/of_mdio.h>
29#include <linux/phy.h> 29#include <linux/phy.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
@@ -251,37 +251,36 @@ int stmmac_mdio_reset(struct mii_bus *bus)
251 251
252#ifdef CONFIG_OF 252#ifdef CONFIG_OF
253 if (priv->device->of_node) { 253 if (priv->device->of_node) {
254 struct gpio_desc *reset_gpio;
255
254 if (data->reset_gpio < 0) { 256 if (data->reset_gpio < 0) {
255 struct device_node *np = priv->device->of_node; 257 struct device_node *np = priv->device->of_node;
256 258
257 if (!np) 259 if (!np)
258 return 0; 260 return 0;
259 261
260 data->reset_gpio = of_get_named_gpio(np, 262 reset_gpio = devm_gpiod_get_optional(priv->device,
261 "snps,reset-gpio", 0); 263 "snps,reset",
262 if (data->reset_gpio < 0) 264 GPIOD_OUT_LOW);
263 return 0; 265 if (IS_ERR(reset_gpio))
266 return PTR_ERR(reset_gpio);
264 267
265 data->active_low = of_property_read_bool(np,
266 "snps,reset-active-low");
267 of_property_read_u32_array(np, 268 of_property_read_u32_array(np,
268 "snps,reset-delays-us", data->delays, 3); 269 "snps,reset-delays-us", data->delays, 3);
270 } else {
271 reset_gpio = gpio_to_desc(data->reset_gpio);
269 272
270 if (devm_gpio_request(priv->device, data->reset_gpio, 273 gpiod_direction_output(reset_gpio, 0);
271 "mdio-reset"))
272 return 0;
273 } 274 }
274 275
275 gpio_direction_output(data->reset_gpio,
276 data->active_low ? 1 : 0);
277 if (data->delays[0]) 276 if (data->delays[0])
278 msleep(DIV_ROUND_UP(data->delays[0], 1000)); 277 msleep(DIV_ROUND_UP(data->delays[0], 1000));
279 278
280 gpio_set_value(data->reset_gpio, data->active_low ? 0 : 1); 279 gpiod_set_value_cansleep(reset_gpio, 1);
281 if (data->delays[1]) 280 if (data->delays[1])
282 msleep(DIV_ROUND_UP(data->delays[1], 1000)); 281 msleep(DIV_ROUND_UP(data->delays[1], 1000));
283 282
284 gpio_set_value(data->reset_gpio, data->active_low ? 1 : 0); 283 gpiod_set_value_cansleep(reset_gpio, 0);
285 if (data->delays[2]) 284 if (data->delays[2])
286 msleep(DIV_ROUND_UP(data->delays[2], 1000)); 285 msleep(DIV_ROUND_UP(data->delays[2], 1000));
287 } 286 }
diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
index 4335bd771ce5..816edb545592 100644
--- a/include/linux/stmmac.h
+++ b/include/linux/stmmac.h
@@ -97,7 +97,7 @@ struct stmmac_mdio_bus_data {
97 int *irqs; 97 int *irqs;
98 int probed_phy_irq; 98 int probed_phy_irq;
99#ifdef CONFIG_OF 99#ifdef CONFIG_OF
100 int reset_gpio, active_low; 100 int reset_gpio;
101 u32 delays[3]; 101 u32 delays[3];
102#endif 102#endif
103}; 103};