diff mbox

[8/8] gpio: stmpe: configure GPIO as output by default

Message ID 1461068317-28016-9-git-send-email-patrice.chotard@st.com (mailing list archive)
State New, archived
Headers show

Commit Message

Patrice CHOTARD April 19, 2016, 12:18 p.m. UTC
From: Patrice Chotard <patrice.chotard@st.com>

Configures all GPIOs as output, in order to minimize power
consumption when GPIOs are unused.

Signed-off-by: Amelie DELAUNAY <amelie.delaunay@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---
 drivers/gpio/gpio-stmpe.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Linus Walleij April 20, 2016, 2:56 p.m. UTC | #1
On Tue, Apr 19, 2016 at 2:18 PM,  <patrice.chotard@st.com> wrote:

> From: Patrice Chotard <patrice.chotard@st.com>
>
> Configures all GPIOs as output, in order to minimize power
> consumption when GPIOs are unused.
>
> Signed-off-by: Amelie DELAUNAY <amelie.delaunay@st.com>
> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>

Not only do you set them all to outout but also:

> +       /* To minimize power consumption, configure unused GPIOs as outputs */
> +       for (i = 0; i < stmpe_gpio->chip.ngpio; i++)
> +               stmpe_gpio_direction_output(&stmpe_gpio->chip, i, 0);

You are driving them all low.

Now GPIO is general purpose: what if they are connected to a
line with a pull-up resistor?

That is not saving power, instead consuming more than if you
were setting them all to 1.

I am afraid this is wrong.

What you need is to be able to define in the DT (or similar)
a set of initial values for the GPIO lines, and set them to
0 for this design.

Such bindings have been discussed but no conclusion
or merged patch has emerged. Please help out in driving
a standard for this!

Yours,
Linus Walleij
diff mbox

Patch

diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
index 45e5b92..80c6ae6 100644
--- a/drivers/gpio/gpio-stmpe.c
+++ b/drivers/gpio/gpio-stmpe.c
@@ -410,7 +410,7 @@  static int stmpe_gpio_probe(struct platform_device *pdev)
 	struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
 	struct device_node *np = pdev->dev.of_node;
 	struct stmpe_gpio *stmpe_gpio;
-	int ret;
+	int ret, i;
 	int irq = 0;
 
 	irq = platform_get_irq(pdev, 0);
@@ -475,6 +475,10 @@  static int stmpe_gpio_probe(struct platform_device *pdev)
 					     NULL);
 	}
 
+	/* To minimize power consumption, configure unused GPIOs as outputs */
+	for (i = 0; i < stmpe_gpio->chip.ngpio; i++)
+		stmpe_gpio_direction_output(&stmpe_gpio->chip, i, 0);
+
 	platform_set_drvdata(pdev, stmpe_gpio);
 
 	return 0;