diff mbox

[2/3] net: fec: convert to using gpiod framework

Message ID 1448883168-30742-3-git-send-email-LW@KARO-electronics.de
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Lothar Waßmann Nov. 30, 2015, 11:32 a.m. UTC
Use gpiod_get_optional() instead of checking for a valid GPIO number
and calling devm_gpio_request_one() conditionally.

Signed-off-by: Lothar Waßmann <LW@KARO-electronics.de>
---
 drivers/net/ethernet/freescale/fec_main.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

Comments

Fabio Estevam Nov. 30, 2015, 12:17 p.m. UTC | #1
On Mon, Nov 30, 2015 at 9:32 AM, Lothar Waßmann <LW@karo-electronics.de> wrote:

> -       gpio_set_value_cansleep(phy_reset, 1);
> +       gpiod_set_value_cansleep(phy_reset, 1);

This will break some existing DTBs.

Currently the fec driver does not care whether 'phy-reset-gpios' is
active low or active high. (Yes, it was a mistake to assume in the
driver that it is always active low.)

After this change the polarity will be taken into account and may
break some dtb's.

I suggest you to send a single patch with the minimum changes to fix
the regression caused by 8fff755e9f8d ("net: fec: Ensure clocks are
enabled while using mdio bus").
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Fugang Duan Dec. 1, 2015, 2:17 a.m. UTC | #2
From: Lothar Waßmann <LW@KARO-electronics.de> Sent: Monday, November 30, 2015 7:33 PM

> To: Andrew Lunn; David S. Miller; Estevam Fabio-R49496; Greg Ungerer;

> Kevin Hao; Lothar Waßmann; Lucas Stach; Duan Fugang-B38611; Philippe

> Reynes; Richard Cochran; Russell King; Sascha Hauer; Stefan Agner; linux-

> kernel@vger.kernel.org; netdev@vger.kernel.org; Jeff Kirsher; Uwe Kleine-

> König

> Subject: [PATCH 2/3] net: fec: convert to using gpiod framework

> 

> Use gpiod_get_optional() instead of checking for a valid GPIO number and

> calling devm_gpio_request_one() conditionally.

> 

> Signed-off-by: Lothar Waßmann <LW@KARO-electronics.de>

> ---

>  drivers/net/ethernet/freescale/fec_main.c | 17 +++++++----------

>  1 file changed, 7 insertions(+), 10 deletions(-)

> 

> diff --git a/drivers/net/ethernet/freescale/fec_main.c

> b/drivers/net/ethernet/freescale/fec_main.c

> index e17d74f..1a983fc 100644

> --- a/drivers/net/ethernet/freescale/fec_main.c

> +++ b/drivers/net/ethernet/freescale/fec_main.c

> @@ -3233,7 +3233,7 @@ static int fec_enet_init(struct net_device *ndev)

> #ifdef CONFIG_OF  static void fec_reset_phy(struct platform_device *pdev)

> {

> -	int err, phy_reset;

> +	struct gpio_desc *phy_reset;

>  	int msec = 1;

>  	struct device_node *np = pdev->dev.of_node;

> 

> @@ -3245,18 +3245,15 @@ static void fec_reset_phy(struct platform_device

> *pdev)

>  	if (msec > 1000)

>  		msec = 1;

> 

> -	phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);

> -	if (!gpio_is_valid(phy_reset))

> -		return;

> -

> -	err = devm_gpio_request_one(&pdev->dev, phy_reset,

> -				    GPIOF_OUT_INIT_LOW, "phy-reset");

> -	if (err) {

> -		dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n",

> err);

> +	phy_reset = devm_gpiod_get_optional(&pdev->dev, "phy-reset",

> +					    GPIOD_OUT_LOW);

> +	if (IS_ERR(phy_reset)) {

> +		dev_err(&pdev->dev, "failed to get phy-reset-gpios: %ld\n",

> +			PTR_ERR(phy_reset));

>  		return;

>  	}

>  	msleep(msec);

> -	gpio_set_value_cansleep(phy_reset, 1);

> +	gpiod_set_value_cansleep(phy_reset, 1);


This API will judge the GPIO active polarity, there many imx boards in dts files don't care the polarity.
So pls drop the patch.

Or use gpiod_set_raw_value_cansleep() instead of gpiod_set_value_cansleep().

>  }

>  #else /* CONFIG_OF */

>  static void fec_reset_phy(struct platform_device *pdev)

> --

> 2.1.4
Lothar Waßmann Dec. 1, 2015, 10:29 a.m. UTC | #3
Hi,

> From: Lothar Waßmann <LW@KARO-electronics.de> Sent: Monday, November 30, 2015 7:33 PM
> > To: Andrew Lunn; David S. Miller; Estevam Fabio-R49496; Greg Ungerer;
> > Kevin Hao; Lothar Waßmann; Lucas Stach; Duan Fugang-B38611; Philippe
> > Reynes; Richard Cochran; Russell King; Sascha Hauer; Stefan Agner; linux-
> > kernel@vger.kernel.org; netdev@vger.kernel.org; Jeff Kirsher; Uwe Kleine-
> > König
> > Subject: [PATCH 2/3] net: fec: convert to using gpiod framework
> > 
> > Use gpiod_get_optional() instead of checking for a valid GPIO number and
> > calling devm_gpio_request_one() conditionally.
> > 
> > Signed-off-by: Lothar Waßmann <LW@KARO-electronics.de>
> > ---
> >  drivers/net/ethernet/freescale/fec_main.c | 17 +++++++----------
> >  1 file changed, 7 insertions(+), 10 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/freescale/fec_main.c
> > b/drivers/net/ethernet/freescale/fec_main.c
> > index e17d74f..1a983fc 100644
> > --- a/drivers/net/ethernet/freescale/fec_main.c
> > +++ b/drivers/net/ethernet/freescale/fec_main.c
> > @@ -3233,7 +3233,7 @@ static int fec_enet_init(struct net_device *ndev)
> > #ifdef CONFIG_OF  static void fec_reset_phy(struct platform_device *pdev)
> > {
> > -	int err, phy_reset;
> > +	struct gpio_desc *phy_reset;
> >  	int msec = 1;
> >  	struct device_node *np = pdev->dev.of_node;
> > 
> > @@ -3245,18 +3245,15 @@ static void fec_reset_phy(struct platform_device
> > *pdev)
> >  	if (msec > 1000)
> >  		msec = 1;
> > 
> > -	phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
> > -	if (!gpio_is_valid(phy_reset))
> > -		return;
> > -
> > -	err = devm_gpio_request_one(&pdev->dev, phy_reset,
> > -				    GPIOF_OUT_INIT_LOW, "phy-reset");
> > -	if (err) {
> > -		dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n",
> > err);
> > +	phy_reset = devm_gpiod_get_optional(&pdev->dev, "phy-reset",
> > +					    GPIOD_OUT_LOW);
> > +	if (IS_ERR(phy_reset)) {
> > +		dev_err(&pdev->dev, "failed to get phy-reset-gpios: %ld\n",
> > +			PTR_ERR(phy_reset));
> >  		return;
> >  	}
> >  	msleep(msec);
> > -	gpio_set_value_cansleep(phy_reset, 1);
> > +	gpiod_set_value_cansleep(phy_reset, 1);
> 
> This API will judge the GPIO active polarity, there many imx boards in dts files don't care the polarity.
> So pls drop the patch.
> 
> Or use gpiod_set_raw_value_cansleep() instead of gpiod_set_value_cansleep().
> 
I could prepare a patch that temporarily uses the raw functions and add
a comment to convert these to the proper functions once all DTB files
have been corrected and some time has passed to account for boards using
old dtbs with newer kernels.

I could also send a patch to convert all in-tree dts files to use
GPIO_ACTIVE_LOW if that is desired.


Lothar Waßmann
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index e17d74f..1a983fc 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -3233,7 +3233,7 @@  static int fec_enet_init(struct net_device *ndev)
 #ifdef CONFIG_OF
 static void fec_reset_phy(struct platform_device *pdev)
 {
-	int err, phy_reset;
+	struct gpio_desc *phy_reset;
 	int msec = 1;
 	struct device_node *np = pdev->dev.of_node;
 
@@ -3245,18 +3245,15 @@  static void fec_reset_phy(struct platform_device *pdev)
 	if (msec > 1000)
 		msec = 1;
 
-	phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0);
-	if (!gpio_is_valid(phy_reset))
-		return;
-
-	err = devm_gpio_request_one(&pdev->dev, phy_reset,
-				    GPIOF_OUT_INIT_LOW, "phy-reset");
-	if (err) {
-		dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err);
+	phy_reset = devm_gpiod_get_optional(&pdev->dev, "phy-reset",
+					    GPIOD_OUT_LOW);
+	if (IS_ERR(phy_reset)) {
+		dev_err(&pdev->dev, "failed to get phy-reset-gpios: %ld\n",
+			PTR_ERR(phy_reset));
 		return;
 	}
 	msleep(msec);
-	gpio_set_value_cansleep(phy_reset, 1);
+	gpiod_set_value_cansleep(phy_reset, 1);
 }
 #else /* CONFIG_OF */
 static void fec_reset_phy(struct platform_device *pdev)