Skip to contentSkip to conversation

GPIO driver to turn power off

PATCH Superseded Andrew Lunn 7 participants 24 messages Nov 11, 2012 – Nov 21, 2012

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover GPIO driver to turn power off

A few of the Kirkwood systems use a GPIO line to turn the power off on shutdown. They request the GPIO line in the board setup code, optionally setting it as an output and driving it inactive. They then register a function for pm_power_off. At the end of the shutdown, this function is called. The GPIO line is configured as an output, if not already so, and then driven active. In order to cover the use case of edges rather then levels, triggering power off, the GPIO line is then toggled active and later inactive. This should allow the driver to be used by PXA which also has boards using the same scheme.

The driver code was initially developed by Jamie Lentin and extended to cover the PXA case by Andrew Lunn.

Andrew Lunn (2):
ARM: Kirkwood: Convert DNSKW to use gpio-poweroff.
ARM: Kirkwood: Convert IB62x0 to use gpio-poweroff.

Jamie Lentin (1):
gpio: Add simple poweroff-gpio driver

 .../devicetree/bindings/gpio/gpio-poweroff.txt     |   22 ++++
 arch/arm/boot/dts/kirkwood-dnskw.dtsi              |    5 +
 arch/arm/boot/dts/kirkwood-ib62x0.dts              |    6 +
 arch/arm/mach-kirkwood/Kconfig                     |    1 +
 arch/arm/mach-kirkwood/board-dnskw.c               |   12 --
 arch/arm/mach-kirkwood/board-ib62x0.c              |   13 --
 drivers/gpio/Kconfig                               |   10 ++
 drivers/gpio/Makefile                              |    2 +
 drivers/gpio/gpio-poweroff.c                       |  129 ++++++++++++++++++++
 9 files changed, 175 insertions(+), 25 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-poweroff.txt
 create mode 100644 drivers/gpio/gpio-poweroff.c
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

From: Jamie Lentin <[email protected]>

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

---
 .../devicetree/bindings/gpio/gpio-poweroff.txt     |   22 ++++
 drivers/gpio/Kconfig                               |   10 ++
 drivers/gpio/Makefile                              |    2 +
 drivers/gpio/gpio-poweroff.c                       |  129 ++++++++++++++++++++
 4 files changed, 163 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-poweroff.txt
 create mode 100644 drivers/gpio/gpio-poweroff.c
Documentation/devicetree/bindings/gpio/gpio-poweroff.txt new file +22 -0
new file mode 100644
index 0000000..558cdf3
@@ -0,0 +1,22 @@
+GPIO line that should be set high/low to power off a device
+
+Required properties:
+- compatible : should be "gpio-poweroff".
+- gpios : The GPIO to set high/low, see "gpios property" in
+  Documentation/devicetree/bindings/gpio/gpio.txt. If the pin should be
+  low to power down the board set it to "Active Low", otherwise set
+  gpio to "Active High".
+
+Optional properties:
+- input : Initially configure the GPIO line as an input. Only reconfigure
+  it to an output when the pm_power_off function is called. If this optional
+  property is not specified, the GPIO is initialized as an output in its
+  inactive state.
+
+
+Examples:
+
+gpio-poweroff {
+	compatible = "gpio-poweroff";
+	gpios = <&gpio 4 0>; /* GPIO 4 Active Low */
+};
drivers/gpio/Kconfig +10 -0
index d055cee..5ec1714 100644
@@ -75,6 +75,16 @@ config GPIO_SYSFS
 	  Kernel drivers may also request that a particular GPIO be
 	  exported to userspace; this can be useful when debugging.
 
+config GPIO_POWEROFF
+	tristate "GPIO power-off driver"
+	depends on OF_GPIO
+	help
+	  This driver supports turning off your device via a GPIO line.
+	  If your device needs a GPIO high/low to power down, say Y and
+	  create a binding in your devicetree.
+
+	  If unsure, say N
+
 config GPIO_GENERIC
 	tristate
 
drivers/gpio/Makefile +2 -0
index 9aeed67..a8efda3 100644
@@ -5,6 +5,8 @@ ccflags-$(CONFIG_DEBUG_GPIO)	+= -DDEBUG
 obj-$(CONFIG_GPIOLIB)		+= gpiolib.o devres.o
 obj-$(CONFIG_OF_GPIO)		+= gpiolib-of.o
 
+obj-$(CONFIG_GPIO_POWEROFF)	+= gpio-poweroff.o
+
 # Device drivers. Generally keep list sorted alphabetically
 obj-$(CONFIG_GPIO_GENERIC)	+= gpio-generic.o
 
drivers/gpio/gpio-poweroff.c new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Quoted 5 lines · Andrew Lunn

From: Jamie Lentin <[email protected]>

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

This feature will be useful for the Tegra TrimSlice board too.

Documentation/devicetree/bindings/gpio/gpio-poweroff.txt line 8

Quoted 8 lines
Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +6 -0
 
+Required properties:
+- compatible : should be "gpio-poweroff".
+- gpios : The GPIO to set high/low, see "gpios property" in
+  Documentation/devicetree/bindings/gpio/gpio.txt. If the pin should be
+  low to power down the board set it to "Active Low", otherwise set
+  gpio to "Active High".

Unfortunately, not all GPIO bindings support active high/low flags in the GPIO specifier. As such, the flags there are basically useless. Other bindings (e.g. IIRC the fixed-regulator binding) have added a separate active-high property to indicate the GPIO polarity. This binding should probably follow suite.

#3 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Quoted 8 lines · Stephen Warren
Quoted 5 lines · Andrew Lunn

From: Jamie Lentin <[email protected]>

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

This feature will be useful for the Tegra TrimSlice board too.

Hi Stephen

Great to hear its usable for others.

Quoted 9 lines

Documentation/devicetree/bindings/gpio/gpio-poweroff.txt line 8

Quoted 8 lines
Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +6 -0
 
+Required properties:
+- compatible : should be "gpio-poweroff".
+- gpios : The GPIO to set high/low, see "gpios property" in
+  Documentation/devicetree/bindings/gpio/gpio.txt. If the pin should be
+  low to power down the board set it to "Active Low", otherwise set
+  gpio to "Active High".
Quoted 5 lines

Unfortunately, not all GPIO bindings support active high/low flags in the GPIO specifier. As such, the flags there are basically useless. Other bindings (e.g. IIRC the fixed-regulator binding) have added a separate active-high property to indicate the GPIO polarity. This binding should probably follow suite.

Humm, so are you saying of_get_named_gpio_flags() is deprecated?

There is a lot of code using this to get the flag OF_GPIO_ACTIVE_LOW. Some of these users are very generic code:

drivers/leds/leds-gpio.c:
drivers/input/misc/rotary_encoder.c:
drivers/input/keyboard/gpio_keys.c:
drivers/input/keyboard/gpio_keys_polled.c:
drivers/hwmon/gpio-fan.c:

The only code using the "enable-active-high"
property is drivers/regulator/fixed.c although the binding documentation twl6040.txt talks about it, but the code does not implement it.

Could you point me towards some email discussion about this?

Thanks
Andrew

#4 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Quoted 17 lines · Andrew Lunn
Quoted 16 lines · Stephen Warren
Quoted 14 lines · Andrew Lunn

From: Jamie Lentin <[email protected]>

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +6 -0
 
+Required properties:
+- compatible : should be "gpio-poweroff".
+- gpios : The GPIO to set high/low, see "gpios property" in
+  Documentation/devicetree/bindings/gpio/gpio.txt. If the pin should be
+  low to power down the board set it to "Active Low", otherwise set
+  gpio to "Active High".
Quoted 7 lines
Quoted 5 lines

Unfortunately, not all GPIO bindings support active high/low flags in the GPIO specifier. As such, the flags there are basically useless. Other bindings (e.g. IIRC the fixed-regulator binding) have added a separate active-high property to indicate the GPIO polarity. This binding should probably follow suite.

Humm, so are you saying of_get_named_gpio_flags() is deprecated?

I don't know if it's deprecated, but it's certainly not useful in generic code.

Quoted 2 lines

There is a lot of code using this to get the flag OF_GPIO_ACTIVE_LOW. Some of these users are very generic code:

That's unfortunate...

Quoted 7 lines

drivers/leds/leds-gpio.c:
drivers/input/misc/rotary_encoder.c:
drivers/input/keyboard/gpio_keys.c:
drivers/input/keyboard/gpio_keys_polled.c:
drivers/hwmon/gpio-fan.c:

Quoted 6 lines

The only code using the "enable-active-high"
property is drivers/regulator/fixed.c although the binding documentation twl6040.txt talks about it, but the code does not implement it.

Could you point me towards some email discussion about this?

I don't have any good links. I imagine the discussion happened when the patched for regulator/fixed.c were submitted.

#5 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Quoted 24 lines · Stephen Warren
Quoted 23 lines · Andrew Lunn
Quoted 21 lines · Stephen Warren
Quoted 7 lines · Andrew Lunn

From: Jamie Lentin <[email protected]>

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

Documentation/devicetree/bindings/gpio/gpio-poweroff.txt line 8

Quoted 7 lines
Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +6 -0
 
+Required properties:
+- compatible : should be "gpio-poweroff".
+- gpios : The GPIO to set high/low, see "gpios property" in
+  Documentation/devicetree/bindings/gpio/gpio.txt. If the pin should be
+  low to power down the board set it to "Active Low", otherwise set
+  gpio to "Active High".

Unfortunately, not all GPIO bindings support active high/low flags in the GPIO specifier. As such, the flags there are basically useless. Other bindings (e.g. IIRC the fixed-regulator binding) have added a separate active-high property to indicate the GPIO polarity. This binding should probably follow suite.

Quoted 4 lines
Quoted 1 line

Humm, so are you saying of_get_named_gpio_flags() is deprecated?

I don't know if it's deprecated, but it's certainly not useful in generic code.

Hi Linus, Anton

How do you see this?

I'm happy to implement an enable-active-high property, but it seems to go against the purpose of of_get_named_gpio_flags(). Is that function deprecated?

Thanks
Andrew

#6 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

On Mon, Nov 12, 2012 at 07:19:47PM +0100, Andrew Lunn wrote:
[..]

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +6 -0
 
+Required properties:
+- compatible : should be "gpio-poweroff".
+- gpios : The GPIO to set high/low, see "gpios property" in
+  Documentation/devicetree/bindings/gpio/gpio.txt. If the pin should be
+  low to power down the board set it to "Active Low", otherwise set
+  gpio to "Active High".
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Unfortunately, not all GPIO bindings support active high/low flags in the GPIO specifier. As such, the flags there are basically useless. Other bindings (e.g. IIRC the fixed-regulator binding) have added a separate active-high property to indicate the GPIO polarity. This binding should probably follow suite.

Should the gpio driver fix its bindings then?.. Polarity is a quite generic concept of a GPIO, and flags are there for a reason. I'd rather prefer having

	stuff-gpios = <0 0
		       1 0
		       2 1
		       3 0>;

Rather than

	stuff-gpios = <0 1 2 3>;
	stuff-polarity-gpio-map = <0 0 1 0>;

The first scheme existed like for years already. Has it been discussed that it is no longer preferred?

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

Humm, so are you saying of_get_named_gpio_flags() is deprecated?

I don't know if it's deprecated, but it's certainly not useful in generic code.

Quoted 7 lines

Hi Linus, Anton

How do you see this?

I'm happy to implement an enable-active-high property, but it seems to go against the purpose of of_get_named_gpio_flags(). Is that function deprecated?

Never heard of any deprecation, and I disagree that it is "not useful in generic code". :)

Thanks,
Anton.

#7 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Quoted 21 lines · Anton Vorontsov

On Mon, Nov 12, 2012 at 07:19:47PM +0100, Andrew Lunn wrote:
[..]

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

Documentation/devicetree/bindings/gpio/gpio-poweroff.txt +6 -0
 
+Required properties:
+- compatible : should be "gpio-poweroff".
+- gpios : The GPIO to set high/low, see "gpios property" in
+  Documentation/devicetree/bindings/gpio/gpio.txt. If the pin should be
+  low to power down the board set it to "Active Low", otherwise set
+  gpio to "Active High".
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Unfortunately, not all GPIO bindings support active high/low flags in the GPIO specifier. As such, the flags there are basically useless. Other bindings (e.g. IIRC the fixed-regulator binding) have added a separate active-high property to indicate the GPIO polarity. This binding should probably follow suite.

Quoted 3 lines

Should the gpio driver fix its bindings then?.. Polarity is a quite generic concept of a GPIO, and flags are there for a reason. I'd rather prefer having

There is no "GPIO driver" to fix; each GPIO driver has its own bindings, and unfortunately, some of the GPIO binding authors chose not to include any flags cell in the GPIO specifier (e.g. Samsung ARM SoCs IIRC, but there are probably more).

Quoted 20 lines
	stuff-gpios = <0 0
		       1 0
		       2 1
		       3 0>;

Rather than

	stuff-gpios = <0 1 2 3>;
	stuff-polarity-gpio-map = <0 0 1 0>;

The first scheme existed like for years already. Has it been discussed that it is no longer preferred?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Humm, so are you saying of_get_named_gpio_flags() is deprecated?

I don't know if it's deprecated, but it's certainly not useful in generic code.

Hi Linus, Anton

Quoted 8 lines
Quoted 5 lines

How do you see this?

I'm happy to implement an enable-active-high property, but it seems to go against the purpose of of_get_named_gpio_flags(). Is that function deprecated?

Never heard of any deprecation, and I disagree that it is "not useful in generic code". :)

Put more specifically, I meant: It would be useful to have such a feature. However, since such a feature doesn't exist in all cases, it's not possible to rely on the feature, and hence trying to isn't useful.

#8 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

On Mon, Nov 12, 2012 at 11:58:47AM -0700, Stephen Warren wrote:
[...]

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Unfortunately, not all GPIO bindings support active high/low flags in the GPIO specifier. As such, the flags there are basically useless. Other bindings (e.g. IIRC the fixed-regulator binding) have added a separate active-high property to indicate the GPIO polarity. This binding should probably follow suite.

Quoted 8 lines
Quoted 3 lines

Should the gpio driver fix its bindings then?.. Polarity is a quite generic concept of a GPIO, and flags are there for a reason. I'd rather prefer having

There is no "GPIO driver" to fix; each GPIO driver has its own bindings, and unfortunately, some of the GPIO binding authors chose not to include any flags cell in the GPIO specifier (e.g. Samsung ARM SoCs IIRC, but there are probably more).

They didn't read this? :)

int of_gpio_simple_xlate(struct gpio_chip *gc,
const struct of_phandle_args *gpiospec, u32 *flags)

{
        /*
         * We're discouraging gpio_cells < 2, since that way you'll have to
         * write your own xlate function (that will have to retrive the GPIO
         * number and the flags from a single gpio cell -- this is possible,
         * but not recommended).
         */
        if (gc->of_gpio_n_cells < 2) {
                WARN_ON(1);
                return -EINVAL;
        }

They should have gotten the WARN_ON().

If not, if they do have the second cell, then they still can encode the flags. Just change the bindings in a backwards-compatible way.

And even if they have just one cell, just as the comment above says, they still can add the polarity flag -- add it into the gpio number specifier. 0x0001 -- GPIO 1, 0x1001 -- GPIO 1, polarity inverted. In the gpio driver they have to mask the flags (by implementing their own xlate), of course.

A few "broken" (but fixable) drivers/bindings is not the reason change the whole concept, or declare a long-standing API as 'not suitable for generic code'. At least it was meant exactly to be suitable for a generic code. :)

Thanks,
Anton.

#9 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

In reply to Stephen Warren
Quoted 10 lines · Stephen Warren
Quoted 3 lines · Anton Vorontsov

Should the gpio driver fix its bindings then?.. Polarity is a quite generic concept of a GPIO, and flags are there for a reason. I'd rather prefer having

There is no "GPIO driver" to fix; each GPIO driver has its own bindings, and unfortunately, some of the GPIO binding authors chose not to include any flags cell in the GPIO specifier (e.g. Samsung ARM SoCs IIRC, but there are probably more).

So can I read this something like we have been too liberal with the GPIO DT bindings and they are now a bit messy and need to be shaped up? I don't know how to achieve that :-(

Alerting Grant to see if he has something to add on this subject...

Yours,
Linus Walleij

#10 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Quoted 7 lines · Linus Walleij
Quoted 6 lines · Stephen Warren
Quoted 3 lines · Anton Vorontsov

Should the gpio driver fix its bindings then?.. Polarity is a quite generic concept of a GPIO, and flags are there for a reason. I'd rather prefer having

Quoted 8 lines
Quoted 4 lines

There is no "GPIO driver" to fix; each GPIO driver has its own bindings, and unfortunately, some of the GPIO binding authors chose not to include any flags cell in the GPIO specifier (e.g. Samsung ARM SoCs IIRC, but there are probably more).

So can I read this something like we have been too liberal with the GPIO DT bindings and they are now a bit messy and need to be shaped up? I don't know how to achieve that :-(

I guess there's really no reason to panic. :)

'git grep gpio-cells Documentation/' shows just mrvl-gpio.txt and twl6040.txt having the wrong gpio-cells (i.e. 1).

But even these can use one cells for both flags and pin number (unless you really have 4294967295 GPIOs per controller).

FWIW, current Samsung SOCs use 3 and even 4 cells for a GPIO specifier, which is absolutely fine. Plus, the Samsung bindings do specify the inversion flag. So, unless we have a lot of other [undocumented] bindings, I don't see a big mess. And everything I currently see is fixable.

Thanks,
Anton.

#11 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Quoted 22 lines · Anton Vorontsov
Quoted 7 lines · Linus Walleij
Quoted 6 lines · Stephen Warren
Quoted 3 lines · Anton Vorontsov

Should the gpio driver fix its bindings then?.. Polarity is a quite generic concept of a GPIO, and flags are there for a reason. I'd rather prefer having

Quoted 8 lines
Quoted 4 lines

There is no "GPIO driver" to fix; each GPIO driver has its own bindings, and unfortunately, some of the GPIO binding authors chose not to include any flags cell in the GPIO specifier (e.g. Samsung ARM SoCs IIRC, but there are probably more).

So can I read this something like we have been too liberal with the GPIO DT bindings and they are now a bit messy and need to be shaped up? I don't know how to achieve that :-(

I guess there's really no reason to panic. :)

'git grep gpio-cells Documentation/' shows just mrvl-gpio.txt and twl6040.txt having the wrong gpio-cells (i.e. 1).

Quoted 7 lines

But even these can use one cells for both flags and pin number (unless you really have 4294967295 GPIOs per controller).

FWIW, current Samsung SOCs use 3 and even 4 cells for a GPIO specifier, which is absolutely fine. Plus, the Samsung bindings do specify the inversion flag. So, unless we have a lot of other [undocumented] bindings, I don't see a big mess. And everything I currently see is fixable.

I agree it's not that big a mess...

I was more thinking about how to convince the people who can test this to fix it up.

Yours,
Linus Walleij

#12 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Quoted 32 lines · Linus Walleij
Quoted 22 lines · Anton Vorontsov
Quoted 7 lines · Linus Walleij
Quoted 6 lines · Stephen Warren
Quoted 3 lines · Anton Vorontsov

Should the gpio driver fix its bindings then?.. Polarity is a quite generic concept of a GPIO, and flags are there for a reason. I'd rather prefer having

Quoted 8 lines
Quoted 4 lines

There is no "GPIO driver" to fix; each GPIO driver has its own bindings, and unfortunately, some of the GPIO binding authors chose not to include any flags cell in the GPIO specifier (e.g. Samsung ARM SoCs IIRC, but there are probably more).

So can I read this something like we have been too liberal with the GPIO DT bindings and they are now a bit messy and need to be shaped up? I don't know how to achieve that :-(

I guess there's really no reason to panic. :)

'git grep gpio-cells Documentation/' shows just mrvl-gpio.txt and twl6040.txt having the wrong gpio-cells (i.e. 1).

Quoted 7 lines

But even these can use one cells for both flags and pin number (unless you really have 4294967295 GPIOs per controller).

FWIW, current Samsung SOCs use 3 and even 4 cells for a GPIO specifier, which is absolutely fine. Plus, the Samsung bindings do specify the inversion flag. So, unless we have a lot of other [undocumented] bindings, I don't see a big mess. And everything I currently see is fixable.

Quoted 4 lines

I agree it's not that big a mess...

I was more thinking about how to convince the people who can test this to fix it up.

+1. Most drivers use the same definitions for flags. New drivers should be pushed to do the same. And the few that don't can be fixed up individually.

g.

Signature · 2 lines
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.
#13 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

In reply to Anton Vorontsov
Quoted 13 lines · Anton Vorontsov
Quoted 12 lines · Linus Walleij
Quoted 10 lines · Stephen Warren
Quoted 3 lines · Anton Vorontsov

Should the gpio driver fix its bindings then?.. Polarity is a quite generic concept of a GPIO, and flags are there for a reason. I'd rather prefer having

There is no "GPIO driver" to fix; each GPIO driver has its own bindings, and unfortunately, some of the GPIO binding authors chose not to include any flags cell in the GPIO specifier (e.g. Samsung ARM SoCs IIRC, but there are probably more).

Quoted 8 lines
Quoted 3 lines

So can I read this something like we have been too liberal with the GPIO DT bindings and they are now a bit messy and need to be shaped up? I don't know how to achieve that :-(

I guess there's really no reason to panic. :)

'git grep gpio-cells Documentation/' shows just mrvl-gpio.txt and twl6040.txt having the wrong gpio-cells (i.e. 1).

If there are too-few cells, the binding and driver can always be expanded to support more cells in a backwards-compatible way.

Quoted 7 lines

But even these can use one cells for both flags and pin number (unless you really have 4294967295 GPIOs per controller).

FWIW, current Samsung SOCs use 3 and even 4 cells for a GPIO specifier, which is absolutely fine. Plus, the Samsung bindings do specify the inversion flag. So, unless we have a lot of other [undocumented] bindings, I don't see a big mess. And everything I currently see is fixable.

Oh, I always thought that the Samsung bindings were one of the major issues here, but you're right - they do have the inversion flag already.

So, perhaps there really isn't an issue, and we should revisit the GPIO-based regulator bindings and drivers, and allow them to (additionally) rely on the GPIO flags in the standard way.

#14 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

In reply to Andrew Lunn
Quoted 8 lines · Andrew Lunn

From: Jamie Lentin <[email protected]>

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

So this is just a GPIO client like any such thing right?

I mean this thing has nothing more to do with the GPIO subsystem than say, drivers/input/keyboard/gpio_keys.c?

So from the GPIO subsystem point of view controlling power is an alien concept.

But I suspect Anton may be ready to welcome a driver like this under drivers/power/* which I think is where it belongs.

Yours,
Linus Walleij

#15 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Quoted 13 lines · Linus Walleij
Quoted 8 lines · Andrew Lunn

From: Jamie Lentin <[email protected]>

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

So this is just a GPIO client like any such thing right?

Quoted 8 lines

I mean this thing has nothing more to do with the GPIO subsystem than say, drivers/input/keyboard/gpio_keys.c?

So from the GPIO subsystem point of view controlling power is an alien concept.

But I suspect Anton may be ready to welcome a driver like this under drivers/power/* which I think is where it belongs.

Yup. driver/power/reset/ seems appropriate.

Thanks,
Anton.

#16 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Quoted 17 lines · Anton Vorontsov
Quoted 16 lines · Linus Walleij
Quoted 8 lines · Andrew Lunn

From: Jamie Lentin <[email protected]>

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

So this is just a GPIO client like any such thing right?

I mean this thing has nothing more to do with the GPIO subsystem than say, drivers/input/keyboard/gpio_keys.c?

Quoted 7 lines
Quoted 5 lines

So from the GPIO subsystem point of view controlling power is an alien concept.

But I suspect Anton may be ready to welcome a driver like this under drivers/power/* which I think is where it belongs.

Yup. driver/power/reset/ seems appropriate.

Hi Anton

I was unsure where to put it. I will submit new patches with the move.

I'm not too sure about 'reset' though. Its not a reset operation, the power goes off and stays off. Would 'shutdown' or 'power_off' be better?

Andrew

#17 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Hi Andrew,

On Mon, Nov 12, 2012 at 07:07:40AM +0100, Andrew Lunn wrote:
[...]

Quoted 10 lines
Quoted 4 lines
Quoted 2 lines

But I suspect Anton may be ready to welcome a driver like this under drivers/power/* which I think is where it belongs.

Yup. driver/power/reset/ seems appropriate.

I was unsure where to put it. I will submit new patches with the move.

I'm not too sure about 'reset' though. Its not a reset operation, the power goes off and stays off. Would 'shutdown' or 'power_off' be better?

Other folks already wanted drivers/power/reset/ for board reset/poweroff drivers. But it makes little sense to make both reset and poweroff directories. So, let's just do 'reset', somebody might have already using it in their private trees.

Thanks,
Anton.

#18 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

In reply to Andrew Lunn
Quoted 6 lines · Andrew Lunn

From: Jamie Lentin <[email protected]>

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

Quoted 7 lines
---
 .../devicetree/bindings/gpio/gpio-poweroff.txt     |   22 ++++
 drivers/gpio/Kconfig                               |   10 ++
 drivers/gpio/Makefile                              |    2 +
 drivers/gpio/gpio-poweroff.c                       |  129 ++++++++++++++++++++

This isn't a gpio controller driver. Don't put it into drivers/gpio

g.

#19 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Quoted 15 lines · Grant Likely
Quoted 6 lines · Andrew Lunn

From: Jamie Lentin <[email protected]>

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

Quoted 7 lines
---
 .../devicetree/bindings/gpio/gpio-poweroff.txt     |   22 ++++
 drivers/gpio/Kconfig                               |   10 ++
 drivers/gpio/Makefile                              |    2 +
 drivers/gpio/gpio-poweroff.c                       |  129 ++++++++++++++++++++
Quoted 1 line

This isn't a gpio controller driver. Don't put it into drivers/gpio

There's a v2 which puts it in drivers/power/reset/gpio-poweroff.c

Quoted 4 lines

g.

Signature · 1 line
Jamie Lentin
#20 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Quoted 20 lines · Jamie Lentin
Quoted 18 lines · Grant Likely
Quoted 15 lines · Andrew Lunn

From: Jamie Lentin <[email protected]>

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

---
 .../devicetree/bindings/gpio/gpio-poweroff.txt     |   22 ++++
 drivers/gpio/Kconfig                               |   10 ++
 drivers/gpio/Makefile                              |    2 +
 drivers/gpio/gpio-poweroff.c                       |  129

++++++++++++++++++++

Quoted 4 lines
Quoted 1 line

This isn't a gpio controller driver. Don't put it into drivers/gpio

There's a v2 which puts it in drivers/power/reset/gpio-poweroff.c

Okay, thanks.

g.

#21 lore raw

PATCH 1/3 gpio: Add simple poweroff-gpio driver

Quoted 21 lines · Grant Likely
Quoted 20 lines · Jamie Lentin
Quoted 18 lines · Grant Likely
Quoted 15 lines · Andrew Lunn

From: Jamie Lentin <[email protected]>

Given appropriate devicetree bindings, this driver registers a pm_power_off function to set a GPIO line high/low to power down your board.

---
 .../devicetree/bindings/gpio/gpio-poweroff.txt     |   22 ++++
 drivers/gpio/Kconfig                               |   10 ++
 drivers/gpio/Makefile                              |    2 +
 drivers/gpio/gpio-poweroff.c                       |  129

++++++++++++++++++++

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

This isn't a gpio controller driver. Don't put it into drivers/gpio

There's a v2 which puts it in drivers/power/reset/gpio-poweroff.c

Okay, thanks.

g.

So... I just read the power sequence proposal patch series which is remarkably like a superset of what is needed here. Does it make sense to use a power sequence for doing generic power off instead of this interface?

g.

Signature · 2 lines
Grant Likely, B.Sc, P.Eng.
Secret Lab Technologies, Ltd.
#22 lore raw

PATCH 2/3 ARM: Kirkwood: Convert DNSKW to use gpio-poweroff.

In reply to Andrew Lunn

Also enable the gpio-poweroff driver when DT is used.

---
 arch/arm/boot/dts/kirkwood-dnskw.dtsi |    5 +++++
 arch/arm/mach-kirkwood/Kconfig        |    1 +
 arch/arm/mach-kirkwood/board-dnskw.c  |   12 ------------
 3 files changed, 6 insertions(+), 12 deletions(-)
arch/arm/boot/dts/kirkwood-dnskw.dtsi +5 -0
index 9b32d02..22aa07a 100644
@@ -35,6 +35,11 @@
 				      6000 2>;
 	};
 
+	gpio_poweroff {
+		compatible = "gpio-poweroff";
+		gpios = <&gpio1 4 0>;
+	};
+
 	ocp at f1000000 {
 		sata at 80000 {
 			status = "okay";
arch/arm/mach-kirkwood/Kconfig +1 -0
index 50bca50..a0f4f47 100644
@@ -47,6 +47,7 @@ config MACH_GURUPLUG
 config ARCH_KIRKWOOD_DT
 	bool "Marvell Kirkwood Flattened Device Tree"
 	select USE_OF
+	select GPIO_POWEROFF
 	help
 	  Say 'Y' here if you want your kernel to support the
 	  Marvell Kirkwood using flattened device tree.
arch/arm/mach-kirkwood/board-dnskw.c +0 -12
index 43d16d6..549369e 100644
@@ -57,11 +57,6 @@ static unsigned int dnskw_mpp_config[] __initdata = {
 	0
 };
 
-static void dnskw_power_off(void)
-{
-	gpio_set_value(36, 1);
-}
-
 /* Register any GPIO for output and set the value */
 static void __init dnskw_gpio_register(unsigned gpio, char *name, int def)
 {
@@ -81,13 +76,6 @@ void __init dnskw_init(void)
 	kirkwood_ehci_init();
 	kirkwood_ge00_init(&dnskw_ge00_data);
 
-	/* Register power-off GPIO. */
-	if (gpio_request(36, "dnskw:power:off") == 0
-	    && gpio_direction_output(36, 0) == 0)
-		pm_power_off = dnskw_power_off;
-	else
-		pr_err("dnskw: failed to configure power-off GPIO\n");
-
 	/* Ensure power is supplied to both HDDs */
 	dnskw_gpio_register(39, "dnskw:power:sata0", 1);
 	dnskw_gpio_register(40, "dnskw:power:sata1", 1);
Signature · 1 line
1.7.10.4
#23 lore raw

PATCH 3/3 ARM: Kirkwood: Convert IB62x0 to use gpio-poweroff.

In reply to Andrew Lunn
---
 arch/arm/boot/dts/kirkwood-ib62x0.dts |    6 ++++++
 arch/arm/mach-kirkwood/board-ib62x0.c |   13 -------------
 2 files changed, 6 insertions(+), 13 deletions(-)
arch/arm/boot/dts/kirkwood-ib62x0.dts +6 -0
index 66794ed..9b0e2e3 100644
@@ -79,4 +79,10 @@
 			gpios = <&gpio0 27 0>;
 		};
 	};
+	gpio_poweroff {
+		compatible = "gpio-poweroff";
+		gpios = <&gpio0 24 1>;
+	};
+
+
 };
arch/arm/mach-kirkwood/board-ib62x0.c +0 -13
index cfc47f8..7b8adf5 100644
@@ -17,7 +17,6 @@
 #include <linux/mtd/partitions.h>
 #include <linux/ata_platform.h>
 #include <linux/mv643xx_eth.h>
-#include <linux/gpio.h>
 #include <linux/input.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
@@ -25,8 +24,6 @@
 #include "common.h"
 #include "mpp.h"
 
-#define IB62X0_GPIO_POWER_OFF	24
-
 static struct mv643xx_eth_platform_data ib62x0_ge00_data = {
 	.phy_addr	= MV643XX_ETH_PHY_ADDR(8),
 };
@@ -49,11 +46,6 @@ static unsigned int ib62x0_mpp_config[] __initdata = {
 	0
 };
 
-static void ib62x0_power_off(void)
-{
-	gpio_set_value(IB62X0_GPIO_POWER_OFF, 1);
-}
-
 void __init ib62x0_init(void)
 {
 	/*
@@ -63,9 +55,4 @@ void __init ib62x0_init(void)
 
 	kirkwood_ehci_init();
 	kirkwood_ge00_init(&ib62x0_ge00_data);
-	if (gpio_request(IB62X0_GPIO_POWER_OFF, "ib62x0:power:off") == 0 &&
-	    gpio_direction_output(IB62X0_GPIO_POWER_OFF, 0) == 0)
-		pm_power_off = ib62x0_power_off;
-	else
-		pr_err("board-ib62x0: failed to configure power-off GPIO\n");
 }
Signature · 1 line
1.7.10.4