Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH 1/2] power: reset: gpio-poweroff: let devm_gpiod_get set direction of gpio
@ 2015-05-18 20:45 Uwe Kleine-König
  2015-05-18 20:45 ` [PATCH 2/2] power: reset: ltc2952: use _optional variant of devm_gpiod_get Uwe Kleine-König
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2015-05-18 20:45 UTC (permalink / raw)
  To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse
  Cc: kernel, Linus Walleij, Alexandre Courbot, linux-pm

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.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/power/reset/gpio-poweroff.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/drivers/power/reset/gpio-poweroff.c b/drivers/power/reset/gpio-poweroff.c
index e5332f1db8a7..be3d81ff51cc 100644
--- a/drivers/power/reset/gpio-poweroff.c
+++ b/drivers/power/reset/gpio-poweroff.c
@@ -48,6 +48,7 @@ static void gpio_poweroff_do_poweroff(void)
 static int gpio_poweroff_probe(struct platform_device *pdev)
 {
 	bool input = false;
+	enum gpiod_flags flags;
 
 	/* If a pm_power_off function has already been added, leave it alone */
 	if (pm_power_off != NULL) {
@@ -57,25 +58,15 @@ static int gpio_poweroff_probe(struct platform_device *pdev)
 		return -EBUSY;
 	}
 
-	reset_gpio = devm_gpiod_get(&pdev->dev, NULL);
-	if (IS_ERR(reset_gpio))
-		return PTR_ERR(reset_gpio);
-
 	input = of_property_read_bool(pdev->dev.of_node, "input");
+	if (input)
+		flags = GPIOD_IN;
+	else
+		flags = GPIOD_OUT_LOW;
 
-	if (input) {
-		if (gpiod_direction_input(reset_gpio)) {
-			dev_err(&pdev->dev,
-				"Could not set direction of reset GPIO to input\n");
-			return -ENODEV;
-		}
-	} else {
-		if (gpiod_direction_output(reset_gpio, 0)) {
-			dev_err(&pdev->dev,
-				"Could not set direction of reset GPIO\n");
-			return -ENODEV;
-		}
-	}
+	reset_gpio = devm_gpiod_get(&pdev->dev, NULL, flags);
+	if (IS_ERR(reset_gpio))
+		return PTR_ERR(reset_gpio);
 
 	pm_power_off = &gpio_poweroff_do_poweroff;
 	return 0;
-- 
2.1.4


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

* [PATCH 2/2] power: reset: ltc2952: use _optional variant of devm_gpiod_get
  2015-05-18 20:45 [PATCH 1/2] power: reset: gpio-poweroff: let devm_gpiod_get set direction of gpio Uwe Kleine-König
@ 2015-05-18 20:45 ` Uwe Kleine-König
  2015-05-24 19:46   ` Sebastian Reichel
  2015-05-19 13:48 ` [PATCH 1/2] power: reset: gpio-poweroff: let devm_gpiod_get set direction of gpio Linus Walleij
  2015-05-24 19:44 ` Sebastian Reichel
  2 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2015-05-18 20:45 UTC (permalink / raw)
  To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse
  Cc: kernel, Linus Walleij, Alexandre Courbot, linux-pm

devm_gpiod_get_optional returns NULL if devm_gpiod_get would return an
ENOENT error pointer.

There is no semantic change intended.

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

probably you could argue if the other errors returned by
devm_gpiod_get_optional should be ignored or not. I'd say it would be cleaner
to forward the error but as the driver explictly claims it should be ok, I
kept this behaviour.

For forwarding the error replace "data->gpio_trigger = NULL" by
"return PTR_ERR(data->gpio_trigger)".

Best regards
Uwe

 drivers/power/reset/ltc2952-poweroff.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/power/reset/ltc2952-poweroff.c b/drivers/power/reset/ltc2952-poweroff.c
index 1e08195551fe..62c91acd6584 100644
--- a/drivers/power/reset/ltc2952-poweroff.c
+++ b/drivers/power/reset/ltc2952-poweroff.c
@@ -202,16 +202,15 @@ static int ltc2952_poweroff_init(struct platform_device *pdev)
 		return ret;
 	}
 
-	data->gpio_trigger = devm_gpiod_get(&pdev->dev, "trigger", GPIOD_IN);
+	data->gpio_trigger = devm_gpiod_get_optional(&pdev->dev, "trigger",
+						     GPIOD_IN);
 	if (IS_ERR(data->gpio_trigger)) {
 		/*
 		 * It's not a problem if the trigger gpio isn't available, but
 		 * it is worth a warning if its use was defined in the device
 		 * tree.
 		 */
-		if (PTR_ERR(data->gpio_trigger) != -ENOENT)
-			dev_err(&pdev->dev,
-				"unable to claim gpio \"trigger\"\n");
+		dev_err(&pdev->dev, "unable to claim gpio \"trigger\"\n");
 		data->gpio_trigger = NULL;
 	}
 
-- 
2.1.4


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

* Re: [PATCH 1/2] power: reset: gpio-poweroff: let devm_gpiod_get set direction of gpio
  2015-05-18 20:45 [PATCH 1/2] power: reset: gpio-poweroff: let devm_gpiod_get set direction of gpio Uwe Kleine-König
  2015-05-18 20:45 ` [PATCH 2/2] power: reset: ltc2952: use _optional variant of devm_gpiod_get Uwe Kleine-König
@ 2015-05-19 13:48 ` Linus Walleij
  2015-05-24 19:44 ` Sebastian Reichel
  2 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2015-05-19 13:48 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse,
	Sascha Hauer, Alexandre Courbot, linux-pm@vger.kernel.org

On Mon, May 18, 2015 at 10:45 PM, 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.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

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

Yours,
Linus Walleij

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

* Re: [PATCH 1/2] power: reset: gpio-poweroff: let devm_gpiod_get set direction of gpio
  2015-05-18 20:45 [PATCH 1/2] power: reset: gpio-poweroff: let devm_gpiod_get set direction of gpio Uwe Kleine-König
  2015-05-18 20:45 ` [PATCH 2/2] power: reset: ltc2952: use _optional variant of devm_gpiod_get Uwe Kleine-König
  2015-05-19 13:48 ` [PATCH 1/2] power: reset: gpio-poweroff: let devm_gpiod_get set direction of gpio Linus Walleij
@ 2015-05-24 19:44 ` Sebastian Reichel
  2 siblings, 0 replies; 5+ messages in thread
From: Sebastian Reichel @ 2015-05-24 19:44 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Dmitry Eremin-Solenikov, David Woodhouse, kernel, Linus Walleij,
	Alexandre Courbot, linux-pm

[-- Attachment #1: Type: text/plain, Size: 336 bytes --]

Hi,

On Mon, May 18, 2015 at 10:45:06PM +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.

Thanks, queued.

-- Sebastian

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 2/2] power: reset: ltc2952: use _optional variant of devm_gpiod_get
  2015-05-18 20:45 ` [PATCH 2/2] power: reset: ltc2952: use _optional variant of devm_gpiod_get Uwe Kleine-König
@ 2015-05-24 19:46   ` Sebastian Reichel
  0 siblings, 0 replies; 5+ messages in thread
From: Sebastian Reichel @ 2015-05-24 19:46 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Dmitry Eremin-Solenikov, David Woodhouse, kernel, Linus Walleij,
	Alexandre Courbot, linux-pm

[-- Attachment #1: Type: text/plain, Size: 888 bytes --]

Hi,

On Mon, May 18, 2015 at 10:45:07PM +0200, Uwe Kleine-König wrote:
> devm_gpiod_get_optional returns NULL if devm_gpiod_get would return an
> ENOENT error pointer.
> 
> There is no semantic change intended.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks, queued.

> probably you could argue if the other errors returned by
> devm_gpiod_get_optional should be ignored or not. I'd say it would be cleaner
> to forward the error but as the driver explictly claims it should be ok, I
> kept this behaviour.
> 
> For forwarding the error replace "data->gpio_trigger = NULL" by
> "return PTR_ERR(data->gpio_trigger)".

Looks sensible, but I took the patch as is for now, since I can't
test the changes (I don't have any ltc2952 including devices). Also
it should be a second patch, so that it can be reverted if needed.

-- Sebastian

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2015-05-24 19:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-18 20:45 [PATCH 1/2] power: reset: gpio-poweroff: let devm_gpiod_get set direction of gpio Uwe Kleine-König
2015-05-18 20:45 ` [PATCH 2/2] power: reset: ltc2952: use _optional variant of devm_gpiod_get Uwe Kleine-König
2015-05-24 19:46   ` Sebastian Reichel
2015-05-19 13:48 ` [PATCH 1/2] power: reset: gpio-poweroff: let devm_gpiod_get set direction of gpio Linus Walleij
2015-05-24 19:44 ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox