diff mbox

usb: dwc3: pci: make better use of gpiod API

Message ID 1434093019-14009-1-git-send-email-u.kleine-koenig@pengutronix.de (mailing list archive)
State New, archived
Headers show

Commit Message

Uwe Kleine-König June 12, 2015, 7:10 a.m. UTC
Since 39b2bbe3d715 (gpio: add flags argument to gpiod_get*() functions)
which appeared in v3.17-rc1, the gpiod_get* functions take an additional
parameter that allows to specify direction and initial value for output.

Furthermore there is devm_gpiod_get_optional which is designed to get
optional gpios. Also use devm_gpiod_get* because otherwise the gpio
might be grabbed by a different driver.

Simplify driver accordingly.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

This usage without flags was introduced by commit a89d977cc04c (usb:
dwc3: pci: add quirk for Baytrails) that is currently in next.

Note I plan to make the flags parameter mandatory for 4.3. So unless
this change gets into 4.2, would it be ok to let it go in via the gpio
tree?

Best regards
Uwe

 drivers/usb/dwc3/dwc3-pci.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

Comments

Linus Walleij June 16, 2015, 9:16 a.m. UTC | #1
On Fri, Jun 12, 2015 at 9:10 AM, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:

> Since 39b2bbe3d715 (gpio: add flags argument to gpiod_get*() functions)
> which appeared in v3.17-rc1, the gpiod_get* functions take an additional
> parameter that allows to specify direction and initial value for output.
>
> Furthermore there is devm_gpiod_get_optional which is designed to get
> optional gpios. Also use devm_gpiod_get* because otherwise the gpio
> might be grabbed by a different driver.
>
> Simplify driver accordingly.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

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

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Heikki Krogerus June 23, 2015, 10:01 a.m. UTC | #2
On Fri, Jun 12, 2015 at 09:10:19AM +0200, Uwe Kleine-König wrote:
> Since 39b2bbe3d715 (gpio: add flags argument to gpiod_get*() functions)
> which appeared in v3.17-rc1, the gpiod_get* functions take an additional
> parameter that allows to specify direction and initial value for output.
> 
> Furthermore there is devm_gpiod_get_optional which is designed to get
> optional gpios. Also use devm_gpiod_get* because otherwise the gpio
> might be grabbed by a different driver.

These gpios are later given to the phy driver. We handle them in this
quirk separately because otherwise the phy can not be probed as it
may still be in reset.

So we are just turning the phy "on" here, and then releasing the gpios
so the phy driver can take over.

> diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
> index 27e4fc896e9d..7e308730f955 100644
> --- a/drivers/usb/dwc3/dwc3-pci.c
> +++ b/drivers/usb/dwc3/dwc3-pci.c
> @@ -84,18 +84,19 @@ static int dwc3_pci_quirks(struct pci_dev *pdev)
>  					  acpi_dwc3_byt_gpios);
>  
>  		/* These GPIOs will turn on the USB2 PHY */
> -		gpio = gpiod_get(&pdev->dev, "cs");
> -		if (!IS_ERR(gpio)) {
> -			gpiod_direction_output(gpio, 0);
> -			gpiod_set_value_cansleep(gpio, 1);
> -			gpiod_put(gpio);
> -		}
> +		gpio = devm_gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW);
> +		if (IS_ERR(gpio))
> +			return PTR_ERR(gpio);
> +
> +		gpiod_set_value_cansleep(gpio, 1);
> +
> +		gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
> +					       GPIOD_OUT_LOW);
> +		if (IS_ERR(gpio))
> +			return PTR_ERR(gpio);
>  
> -		gpio = gpiod_get(&pdev->dev, "reset");
> -		if (!IS_ERR(gpio)) {
> -			gpiod_direction_output(gpio, 0);
> +		if (gpio) {
>  			gpiod_set_value_cansleep(gpio, 1);
> -			gpiod_put(gpio);

So we still need to release the gpio here, or we break the platforms
where we have these gpios.


Thanks,
diff mbox

Patch

diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 27e4fc896e9d..7e308730f955 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -84,18 +84,19 @@  static int dwc3_pci_quirks(struct pci_dev *pdev)
 					  acpi_dwc3_byt_gpios);
 
 		/* These GPIOs will turn on the USB2 PHY */
-		gpio = gpiod_get(&pdev->dev, "cs");
-		if (!IS_ERR(gpio)) {
-			gpiod_direction_output(gpio, 0);
-			gpiod_set_value_cansleep(gpio, 1);
-			gpiod_put(gpio);
-		}
+		gpio = devm_gpiod_get_optional(&pdev->dev, "cs", GPIOD_OUT_LOW);
+		if (IS_ERR(gpio))
+			return PTR_ERR(gpio);
+
+		gpiod_set_value_cansleep(gpio, 1);
+
+		gpio = devm_gpiod_get_optional(&pdev->dev, "reset",
+					       GPIOD_OUT_LOW);
+		if (IS_ERR(gpio))
+			return PTR_ERR(gpio);
 
-		gpio = gpiod_get(&pdev->dev, "reset");
-		if (!IS_ERR(gpio)) {
-			gpiod_direction_output(gpio, 0);
+		if (gpio) {
 			gpiod_set_value_cansleep(gpio, 1);
-			gpiod_put(gpio);
 			usleep_range(10000, 11000);
 		}
 	}