Skip to contentSkip to conversation

PowerPC: implement GPIO API

PATCH In review Anton Vorontsov 7 participants 21 messages Dec 21, 2007 – Dec 23, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover PowerPC: implement GPIO API

Hi all,

OF device tree GPIOs bindings are similar to IRQs:

pario0: gpio-controller@0 {
	#gpio-cells = <2>;
	num-ports = <7>;
};
device@0 {
	gpios = <bank pin bank pin bank pin>;
	gpio-parent = <&pario0>;
};

"bank pin" scheme is controller specific, so controllers that want to implement flat mappings or any other could do so.

So far I implemented GPIO API for QE and CPM2 chips. GPIO API for CPM1 implemented by Jochen Friedrich <[email protected]>, included in this patchset.

- QE GPIO API tested to work with FSL UPM NAND driver and MPC8360E-RDK (STMicro NAND512W3A2BN6E);
- CPM2 GPIO API tested to work with MPC8555E+Samsung HY27UF081G6 (LP);
- CPM1 GPIO API untested.

GPIO API is described in Documentation/gpio.txt, and these patches are tend to support most of it.

As an additional bonus, PowerPC now gets access to few pleasing drivers:

- drivers/leds/leds-gpio.c (we could use it to play with on-board LEDs);
- drivers/i2c/busses/i2c-gpio.c (generic I2C bit-banging driver);
- drivers/input/keyboard/gpio_keys.c - gpio keys (requires gpio_to_irq, so far not implemented);
- Could be more (I named the ones I knew about).

Also, in the upcoming kernels, there will be GPIOLIB[1] addition to the generic GPIO API, to support off-chip GPIO expanders (like MFDs on I2C/LBC). But so far we support on-chip GPIOs only, with single controller built-in.

Changes since RFC:
- Implemented #gpio-cells handling;
- Per-bank spinlocks removed;
- Added a patch which implements GPIO API for CPM1;
- Few minor fixes.

Thanks,

[1] http://www.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.24-rc4/2.6.24-rc4-mm1/broken-out/generic-gpio-gpio_chip-support.patch

Signature · 4 lines
Anton Vorontsov
email: [email protected]
backup email: [email protected]
irc://irc.freenode.net/bd2
#1 lore raw

PATCH 1/4 Implement GPIO API embryo

This patch implements GPIO API as described in Documentation/gpio.txt. Two calls unimplemented though: irq_to_gpio and gpio_to_irq.

This patch also provides OF helpers.

---
 arch/powerpc/Kconfig             |    3 ++
 arch/powerpc/kernel/prom_parse.c |   64 ++++++++++++++++++++++++++++++++++++++
 include/asm-powerpc/gpio.h       |   47 ++++++++++++++++++++++++++++
 include/asm-powerpc/prom.h       |   23 +++++++++++++
 4 files changed, 137 insertions(+), 0 deletions(-)
 create mode 100644 include/asm-powerpc/gpio.h
arch/powerpc/Kconfig +3 -0
index 232c298..a4fa173 100644
@@ -73,6 +73,9 @@ config GENERIC_FIND_NEXT_BIT
 	bool
 	default y
 
+config GENERIC_GPIO
+	bool
+
 config ARCH_NO_VIRT_TO_BUS
 	def_bool PPC64
 
arch/powerpc/kernel/prom_parse.c +64 -0

73 lines not on this page · raw message

include/asm-powerpc/gpio.h new file +47 -0

47 lines not on this page · raw message

include/asm-powerpc/prom.h +23 -0
index 78b7b0d..f882efc 100644
@@ -330,6 +330,29 @@ extern int of_irq_to_resource(struct device_node *dev, int index,
  */
 extern void __iomem *of_iomap(struct device_node *device, int index);
 
+/**
+ * __of_parse_gpio_bank_pin - Helper function to translate "bank pin" GPIOs
+ * @np:		device node to get GPIO from
+ * @index:	index of the GPIO
+ * @bank_width:	pins per bank
+ * @max_bank:	maximum value to represent a bank
+ *
+ * Returns GPIO number to use with Linux generic GPIO api, or
+ * one of the errno value on the error condition.
+ */
+extern int __of_parse_gpio_bank_pin(struct device_node *np, int index,
+				    int bank_width, int max_bank);
+
+/**
+ * of_get_gpio - Translate GPIO number given in the device tree
+ * @np:		device node to get GPIO from
+ * @index:	index of the GPIO
+ *
+ * Returns GPIO number to use with Linux generic GPIO API, or
+ * one of the errno value on the error condition.
+ */
+extern int of_get_gpio(struct device_node *np, int index);
+
 /*
  * NB:  This is here while we transition from using asm/prom.h
  * to linux/of.h
Signature · 1 line
1.5.2.2
#2 lore raw

Re: [PATCH 1/4] [POWERPC] Implement GPIO API embryo

Quoted 4 lines
arch/powerpc/kernel/prom_parse.c +4 -0
+int __of_parse_gpio_bank_pin(struct device_node *np, int index,
+			     int bank_width, int max_bank)
+{
+	int bank;

arch/powerpc/kernel/prom_parse.c void __iomem *of_iomap(struct device_node *np, int index) · line 1097

Quoted 10 lines
arch/powerpc/kernel/prom_parse.c +10 -0
+	int pin;
+	const u32 *gpios;
+
+	/*
+	 * We can get there only if of_get_gpio() succeeded, thus
+	 * no need checking for "gpios" existence.
+	 */
+	gpios = of_get_property(np, "gpios", NULL);
+	bank = gpios[index * 2];
+	pin = gpios[index * 2 + 1];

If you stick with the #gpio-cells plan, here is where you should use it.

Segher

#3 lore raw

Re: [PATCH 1/4] [POWERPC] Implement GPIO API embryo

Quoted 8 lines · Segher Boessenkool
Quoted 8 lines
arch/powerpc/kernel/prom_parse.c +8 -0
+int __of_parse_gpio_bank_pin(struct device_node *np, int index,
+			     int bank_width, int max_bank)
+{
+	int bank;
+	int pin;
+	const u32 *gpios;
+
+	/*
Quoted 8 lines

arch/powerpc/kernel/prom_parse.c void __iomem *of_iomap(struct device_node *np, int index) · line 1097

Quoted 6 lines
arch/powerpc/kernel/prom_parse.c +6 -0
+	 * We can get there only if of_get_gpio() succeeded, thus
+	 * no need checking for "gpios" existence.
+	 */
+	gpios = of_get_property(np, "gpios", NULL);
+	bank = gpios[index * 2];
+	pin = gpios[index * 2 + 1];

If you stick with the #gpio-cells plan, here is where you should use it.

I think part of what's happening here is due to the patch's history. The "bank pin" information was always of a format local to the controller, but originally the size wasn't explicitly stated in the tree - it was just implicit in the type of gpio controller. I suggested that #gpio-cells be added, which it has been, but it looks like the code hasn't been updated to use it everywhere. Obviously a driver for a particular gpio controller would generally need to assert that the controller's #gpio-cells has the correct value for this controller type, after which code like the above would be acceptable.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#4 lore raw

Re: [PATCH 1/4] [POWERPC] Implement GPIO API embryo

Quoted 1 line

I think part of what's happening here is due to the patch's history.

That doesn't make it right though ;-)

Quoted 4 lines

Obviously a
driver for a particular gpio controller would generally need to assert that the controller's #gpio-cells has the correct value for this controller type, after which code like the above would be acceptable.

Well to nitpick... _a_ correct value. But sure, if this is device- specific code, it is okay. OTOH, this really should be a helper function that each GPIO controller driver can use.

Segher

#5 lore raw

PATCH 2/4 QE: implement GPIO API

In reply to Anton Vorontsov
---
 arch/powerpc/platforms/Kconfig     |    1 +
 arch/powerpc/sysdev/qe_lib/qe_io.c |   82 +++++++++++++++++++++++++++++++++++-
 2 files changed, 81 insertions(+), 2 deletions(-)
arch/powerpc/platforms/Kconfig +1 -0
index ea22cad..3d9ff27 100644
@@ -265,6 +265,7 @@ config TAU_AVERAGE
 config QUICC_ENGINE
 	bool
 	select PPC_LIB_RHEAP
+	select GENERIC_GPIO
 	help
 	  The QUICC Engine (QE) is a new generation of communications
 	  coprocessors on Freescale embedded CPUs (akin to CPM in older chips).
arch/powerpc/sysdev/qe_lib/qe_io.c +80 -2

141 lines not on this page · raw message

Signature · 1 line
1.5.2.2
#6 lore raw

PATCH 3/4 CPM2: implement GPIO API

In reply to Anton Vorontsov
---
 arch/powerpc/platforms/Kconfig    |    1 +
 arch/powerpc/sysdev/cpm2_common.c |  121 +++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+), 0 deletions(-)
arch/powerpc/platforms/Kconfig +1 -0
index 3d9ff27..cc2d54e 100644
@@ -277,6 +277,7 @@ config CPM2
 	default n
 	select CPM
 	select PPC_LIB_RHEAP
+	select GENERIC_GPIO
 	help
 	  The CPM2 (Communications Processor Module) is a coprocessor on
 	  embedded CPUs made by Freescale.  Selecting this option means that
arch/powerpc/sysdev/cpm2_common.c +121 -0

150 lines not on this page · raw message

Signature · 1 line
1.5.2.2
#7 lore raw

Re: [PATCH 3/4] [POWERPC] CPM2: implement GPIO API

Quoted 2 lines · Anton Vorontsov

+static spinlock_t cpm2_port_lock = __SPIN_LOCK_UNLOCKED(cpm2_port_lock);

This needs to be

static DEFINE_SPINLOCK(cpm2_port_lock);

I think at least lockdep doesn't work the way you do it here.

Quoted 10 lines
arch/powerpc/sysdev/cpm2_common.c +10 -0
+int cpm2_init_par_io(void)
+{
+	struct device_node *np;
+	const u32 *num_ports;
+
+	np = of_find_compatible_node(NULL, NULL, "fsl,cpm2-pario");
+	if (!np)
+		return -ENOENT;
+
+	num_ports = of_get_property(np, "num-ports", NULL);

arch/powerpc/sysdev/cpm2_common.c cpm2_map_t __iomem *cpm2_immr; · line 97

Quoted 10 lines
arch/powerpc/sysdev/cpm2_common.c +10 -0
+	if (!num_ports) {
+		of_node_put(np);
+		return -ENOENT;
+	}
+	cpm2_num_ports = *num_ports;
+
+	np->data = &of_gpio_chip;
+
+	return 0;
+}

This function should also do the call to of_iomap, so you don't need to pull the address out of the cpm2_immr, which I believe we're trying to get rid of.

	Arnd <><
#8 lore raw

Re: [PATCH 3/4] [POWERPC] CPM2: implement GPIO API

Quoted 7 lines · Arnd Bergmann
Quoted 2 lines · Anton Vorontsov

+static spinlock_t cpm2_port_lock = __SPIN_LOCK_UNLOCKED(cpm2_port_lock);

This needs to be

static DEFINE_SPINLOCK(cpm2_port_lock);

These are equivalents.

#define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)

Quoted 1 line

I think at least lockdep doesn't work the way you do it here.

Is it anyhow special regarding what exact macro is used?..

spinlocks.txt says:

SPIN_LOCK_UNLOCKED and RW_LOCK_UNLOCKED defeat lockdep state tracking and are hence deprecated.

Please use DEFINE_SPINLOCK()/DEFINE_RWLOCK() or __SPIN_LOCK_UNLOCKED()/__RW_LOCK_UNLOCKED() as appropriate for static initialization.
-

..should be equivalent, though I prefer open-coded version, until it fits 80 column width. ;-)

Quoted 16 lines
Quoted 16 lines
arch/powerpc/sysdev/cpm2_common.c +16 -0
+int cpm2_init_par_io(void)
+{
+	struct device_node *np;
+	const u32 *num_ports;
+
+	np = of_find_compatible_node(NULL, NULL, "fsl,cpm2-pario");
+	if (!np)
+		return -ENOENT;
+
+	num_ports = of_get_property(np, "num-ports", NULL);
+	if (!num_ports) {
+		of_node_put(np);
+		return -ENOENT;
+	}
+	cpm2_num_ports = *num_ports;
+
Quoted 8 lines

arch/powerpc/sysdev/cpm2_common.c cpm2_map_t __iomem *cpm2_immr; · line 97

Quoted 4 lines
arch/powerpc/sysdev/cpm2_common.c +4 -0
+	np->data = &of_gpio_chip;
+
+	return 0;
+}

This function should also do the call to of_iomap, so you don't need to pull the address out of the cpm2_immr, which I believe we're trying to get rid of.

Yup, thanks!

Signature · 4 lines
Anton Vorontsov
email: [email protected]
backup email: [email protected]
irc://irc.freenode.net/bd2
#9 lore raw

PATCH 4/4 CPM1: implement GPIO API

In reply to Anton Vorontsov

From: Jochen Friedrich <[email protected]>

---

Jochen, I kept your Signed-off-by, though this isn't your original patch. Hope you're okay with it. I also hope you'll test it. ;-)

 arch/powerpc/platforms/8xx/Kconfig |    1 +
 arch/powerpc/sysdev/commproc.c     |  178 +++++++++++++++++++++++++++++++++++-
 2 files changed, 178 insertions(+), 1 deletions(-)
arch/powerpc/platforms/8xx/Kconfig +1 -0
index 91fbe42..6962914 100644
@@ -4,6 +4,7 @@ config FADS
 config CPM1
 	bool
 	select CPM
+	select GENERIC_GPIO
 
 choice
 	prompt "8xx Machine Type"
arch/powerpc/sysdev/commproc.c +177 -1

229 lines not on this page · raw message

Signature · 1 line
1.5.2.2
#10 lore raw

Re: [PATCH 4/4] [POWERPC] CPM1: implement GPIO API

Hi Anton,

Quoted 3 lines

Jochen, I kept your Signed-off-by, though this isn't your original patch. Hope you're okay with it. I also hope you'll test it. ;-)

that's OK.

Thanks,
Jochen

#11 lore raw

Re: [PATCH 4/4] [POWERPC] CPM1: implement GPIO API

Hi Anton,

Quoted 1 line

I also hope you'll test it. ;-)

yes.

arch/powerpc/sysdev/commproc.c static cpic8xx_t __iomem *cpic_reg; · line 81

Quoted 9 lines
arch/powerpc/sysdev/commproc.c +9 -0
+int cpm_init_par_io(void)
+{
+       struct device_node *np;
+       const u32 *num_ports;
+
+       np = of_find_node_by_name(NULL, "fsl,cpm1-pario");
+       if (!np)
+               return -ENOENT;
+

I guess this should be:

np = of_find_compatible_node(NULL, NULL, "fsl,cpm1-pario");

With this modification it works OK for me :)

Thanks,
Jochen

#12 lore raw

Re: [PATCH 4/4] [POWERPC] CPM1: implement GPIO API

Quoted 18 lines · Jochen Friedrich

Hi Anton,

Quoted 1 line

I also hope you'll test it. ;-)

yes.

arch/powerpc/sysdev/commproc.c static cpic8xx_t __iomem *cpic_reg; · line 81

Quoted 9 lines
arch/powerpc/sysdev/commproc.c +9 -0
+int cpm_init_par_io(void)
+{
+       struct device_node *np;
+       const u32 *num_ports;
+
+       np = of_find_node_by_name(NULL, "fsl,cpm1-pario");
+       if (!np)
+               return -ENOENT;
+

I guess this should be:

Quoted 3 lines

np = of_find_compatible_node(NULL, NULL, "fsl,cpm1-pario");

With this modification it works OK for me :)

Fixed, thanks!

Signature · 4 lines
Anton Vorontsov
email: [email protected]
backup email: [email protected]
irc://irc.freenode.net/bd2
#13 lore raw
In reply to Anton Vorontsov
Quoted 10 lines · Anton Vorontsov

Also, in the upcoming kernels, there will be GPIOLIB[1] addition to the generic GPIO API, to support off-chip GPIO expanders (like MFDs on I2C/LBC). But so far we support on-chip GPIOs only, with single controller built-in.

Changes since RFC:
- Implemented #gpio-cells handling;
- Per-bank spinlocks removed;
- Added a patch which implements GPIO API for CPM1;
- Few minor fixes.

Also need to add documentation to booting-without-of.txt.

In general this looks like a good direction, but I do not like the hard linking for QE and CPM gpios to the 'top level' gpio API. I think I'd prefer this stuff to stay out of mainline until the gpiolib stuff gets merged (which should be soon IIRC).

Cheers,
g.

Signature · 4 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
#14 lore raw
Quoted 12 lines · Grant Likely
Quoted 10 lines · Anton Vorontsov

Also, in the upcoming kernels, there will be GPIOLIB[1] addition to the generic GPIO API, to support off-chip GPIO expanders (like MFDs on I2C/LBC). But so far we support on-chip GPIOs only, with single controller built-in.

Changes since RFC:
- Implemented #gpio-cells handling;
- Per-bank spinlocks removed;
- Added a patch which implements GPIO API for CPM1;
- Few minor fixes.

Quoted 5 lines

Also need to add documentation to booting-without-of.txt.

In general this looks like a good direction, but I do not like the hard linking for QE and CPM gpios to the 'top level' gpio API. I think I'd prefer this stuff to stay out of mainline until the gpiolib

Well, generally I'm okay to wait for gpiolib. Though...

Quoted 1 line

stuff gets merged (which should be soon IIRC).

                                     ^^^^ I doubt about that. :-)

I'm looking after gpiolib development (and, well, I also partipiated in the discussion of earlier versions with former name "gpiodev") for almost a _year_.

And they're still arguing about fluffy details of implementation.. :-/

As I've probably said once already: if there are plans to build single kernel with QE+CPM1+CPM2 inside tomorrow -- then of course, I'd better wait.

But if these plans are distant enough, I see no reason why we can't enjoy of current API.

Thanks!

Signature · 4 lines
Anton Vorontsov
email: [email protected]
backup email: [email protected]
irc://irc.freenode.net/bd2
#15 lore raw
Quoted 6 lines · Anton Vorontsov

As I've probably said once already: if there are plans to build single kernel with QE+CPM1+CPM2 inside tomorrow -- then of course, I'd better wait.

But if these plans are distant enough, I see no reason why we can't enjoy of current API.

Oh, I'm not saying don't enjoy it. :-) I'm just saying keep it out of mainline. I've got a bunch of Virtex stuff that falls into that category. Those who are interested can pick the non mainlined patches out of my git tree.

I suggest doing the same with the GPIO support. Either that or do our own simple ppc specific GPIO multiplexer until the common stuff has its act together. :-) We can always migrate over later.

I don't want to see more barriers added to prevent all of 8xxx going multiplatform.

Cheers,
g.

Signature · 4 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
[email protected]
(403) 399-0195
#16 lore raw
Quoted 5 lines · Grant Likely
Quoted 4 lines · Anton Vorontsov

As I've probably said once already: if there are plans to build single kernel with QE+CPM1+CPM2 inside tomorrow -- then of course, I'd better wait.

Quoted 7 lines
Quoted 2 lines

But if these plans are distant enough, I see no reason why we can't enjoy of current API.

Oh, I'm not saying don't enjoy it. :-) I'm just saying keep it out of mainline. I've got a bunch of Virtex stuff that falls into that category. Those who are interested can pick the non mainlined patches out of my git tree.

Ok. I'm fine either way.

Here we go. For anyone interested in the GPIOs on PowerPC, you can keep an eye on this git tree:

git://git.infradead.org/users/cbou/powerpc-gpio.git

As time will permit, I'll start gpiolib work in the "gpiolib" branch in that repo, which will include gpiolib -mm patches + powerpc bits.

Note: I'm quite often rebasing my work, be aware. ;-)

Thanks!

Signature · 4 lines
Anton Vorontsov
email: [email protected]
backup email: [email protected]
irc://irc.freenode.net/bd2
#17 lore raw
In reply to Anton Vorontsov
Quoted 1 line

OF device tree GPIOs bindings are similar to IRQs:

But GPIOs are a very different thing. Most importantly, the "number" of a GPIO is completely local to the GPIO controller.

Quoted 2 lines
pario0: gpio-controller@0 {
	#gpio-cells = <2>;

Your Linux code doesn't actually use this. Why is it needed, anyway? You should be able to encode a GPIO identifier in a single 32-bit word, for any possible GPIO controller.

Quoted 1 line
	num-ports = <7>;

What is this? What is a "port"? This doesn't belong in a generic GPIO binding.

Quoted 3 lines
device@0 {
	gpios = <bank pin bank pin bank pin>;
	gpio-parent = <&pario0>;

Not every GPIO controller has banks. Not every device uses GPIOs on a single GPIO controller. It is inconvenient to force all bindings to use the same name ("gpios") for its property that shows the GPIOs (and for it to have only one such property).

So I recommend:

-- Advise (in the generic GPIO binding) people to use
< phandle-of-gpio-controller gpio-id-on-that-controller >
to refer to a GPIO from some device node;

-- And either:

	-- Define (in the generic GPIO binding) that a "gpio-id" is a single
	   32-bit cell;

or
-- Define (in the generic GPIO binding) that a "gpio-id" is a number
of 32-bit cells, and that that number of cells is encoded as a
32-bit
integer in the "#gpio-cells" property in the device node of the respective GPIO controller.

(I like the first option better, unless someone can think of some reasonable situation where some specific GPIO controller binding needs more than 32 bits to encode GPIO #).

Segher

#18 lore raw
Quoted 4 lines · Segher Boessenkool
Quoted 1 line

OF device tree GPIOs bindings are similar to IRQs:

But GPIOs are a very different thing. Most importantly, the "number" of a GPIO is completely local to the GPIO controller.

Yes... just as interrupt specifiers are local to their interrupt domain.

Quoted 9 lines
Quoted 2 lines
pario0: gpio-controller@0 {
	#gpio-cells = <2>;

Your Linux code doesn't actually use this. Why is it needed, anyway? You should be able to encode a GPIO identifier in a single 32-bit word, for any possible GPIO controller.

Quoted 1 line
	num-ports = <7>;
Quoted 8 lines

What is this? What is a "port"? This doesn't belong in a generic GPIO binding.

Quoted 3 lines
device@0 {
	gpios = <bank pin bank pin bank pin>;
	gpio-parent = <&pario0>;

Not every GPIO controller has banks.

That's just bad terminology in the example. "bank pin" means an arbitrary format gpio specifier.

Quoted 10 lines

Not every device uses GPIOs
on a single GPIO controller. It is inconvenient to force all bindings to use the same name ("gpios") for its property that shows the GPIOs (and for it to have only one such property).

So I recommend:

-- Advise (in the generic GPIO binding) people to use
< phandle-of-gpio-controller gpio-id-on-that-controller >
to refer to a GPIO from some device node;

Ah, yes, that's a good point. Given the ugly workarounds we need to deal with devices which have interrupts from multiple domains, we don't want to copy that limitation to the GPIO scheme.

Quoted 9 lines

-- And either:
-- Define (in the generic GPIO binding) that a "gpio-id" is a single
32-bit cell;
or
-- Define (in the generic GPIO binding) that a "gpio-id" is a number
of 32-bit cells, and that that number of cells is encoded as a
32-bit
integer in the "#gpio-cells" property in the device node of the respective GPIO controller.

This option was the idea; the "bank pin" information has a format local to the gpio controller. I agree the terminology needs to change to "gpio specifier" by analogy with the interrupt tree, though.

Quoted 5 lines

(I like the first option better, unless someone can think of some reasonable
situation where some specific GPIO controller binding needs more than 32 bits
to encode GPIO #).

I can't think of a situation where it would be strictly speaking necessary, but I can think of several where it would be more convenient. GPIO controllers that do have a bank/pin arrangement is one. GPIO controllers than have a pin number, plus some sort of direction or level information is another.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#19 lore raw
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

OF device tree GPIOs bindings are similar to IRQs:

But GPIOs are a very different thing. Most importantly, the "number" of a GPIO is completely local to the GPIO controller.

Yes... just as interrupt specifiers are local to their interrupt domain.

Sure, but an interrupt domain can be (and usually is) more than one device node. A GPIO controller is just one node.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
device@0 {
	gpios = <bank pin bank pin bank pin>;
	gpio-parent = <&pario0>;

Not every GPIO controller has banks.

That's just bad terminology in the example. "bank pin" means an arbitrary format gpio specifier.

Okay. Don't split it into two things then, just say "gpio-spec" or such.

Quoted 7 lines
Quoted 7 lines

Not every device uses GPIOs
on a single GPIO controller. It is inconvenient to force all bindings to use the same name ("gpios") for its property that shows the GPIOs (and for it to have only one such property).

So I recommend:

Quoted 7 lines
Quoted 3 lines

-- Advise (in the generic GPIO binding) people to use
< phandle-of-gpio-controller gpio-id-on-that-controller >
to refer to a GPIO from some device node;

Ah, yes, that's a good point. Given the ugly workarounds we need to deal with devices which have interrupts from multiple domains, we don't want to copy that limitation to the GPIO scheme.

Yeah, and we even know for a fact that devices exist that do GPIOs on multiple GPIO controllers. In the interrupt case, no one thought anyone would be crazy enough to route their IRQs like that :-)

Quoted 9 lines
Quoted 5 lines

-- Define (in the generic GPIO binding) that a "gpio-id" is a number
of 32-bit cells, and that that number of cells is encoded as a
32-bit
integer in the "#gpio-cells" property in the device node of the respective GPIO controller.

This option was the idea; the "bank pin" information has a format local to the gpio controller. I agree the terminology needs to change to "gpio specifier" by analogy with the interrupt tree, though.

Right, with that cleared up, and the binding doc expanded a bit, you won't hear complaints from me :-)

Quoted 11 lines
Quoted 5 lines

(I like the first option better, unless someone can think of some reasonable
situation where some specific GPIO controller binding needs more than 32 bits
to encode GPIO #).

I can't think of a situation where it would be strictly speaking necessary, but I can think of several where it would be more convenient. GPIO controllers that do have a bank/pin arrangement is one. GPIO controllers than have a pin number, plus some sort of direction or level information is another.

Ah yes, a second word for pin "type" information makes a lot of sense. #gpio-cells it is, then. Let's please make sure that we put that "type" thing in the documentation (as an example), and that the first controller bindings we put in use it.

Segher

#20 lore raw

On Sun, Dec 23, 2007 at 10:53:05AM +0100, Segher Boessenkool wrote:
[...]

Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
device@0 {
	gpios = <bank pin bank pin bank pin>;
	gpio-parent = <&pario0>;

Not every GPIO controller has banks.

That's just bad terminology in the example. "bank pin" means an arbitrary format gpio specifier.

Okay. Don't split it into two things then, just say "gpio-spec" or such.

Will do. "bank pin" was just an example of QE/CPMs gpio specifiers, they could be arbitrary in general.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

Not every device uses GPIOs
on a single GPIO controller. It is inconvenient to force all bindings to use the same name ("gpios") for its property that shows the GPIOs (and for it to have only one such property).

So I recommend:

-- Advise (in the generic GPIO binding) people to use
< phandle-of-gpio-controller gpio-id-on-that-controller >
to refer to a GPIO from some device node;

Quoted 7 lines
Quoted 3 lines

Ah, yes, that's a good point. Given the ugly workarounds we need to deal with devices which have interrupts from multiple domains, we don't want to copy that limitation to the GPIO scheme.

Yeah, and we even know for a fact that devices exist that do GPIOs on multiple GPIO controllers. In the interrupt case, no one thought anyone would be crazy enough to route their IRQs like that :-)

Oh, <&gpio-controller-phandle gpio-spec> is indeed better scheme. Well, parsing it would be a bit more complicated, as gpio-spec is variable length: next placement of phandle depends on previous gpio-specs... But this is doable of course.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

-- Define (in the generic GPIO binding) that a "gpio-id" is a number
of 32-bit cells, and that that number of cells is encoded as a
32-bit
integer in the "#gpio-cells" property in the device node of the respective GPIO controller.

Quoted 6 lines
Quoted 3 lines

This option was the idea; the "bank pin" information has a format local to the gpio controller. I agree the terminology needs to change to "gpio specifier" by analogy with the interrupt tree, though.

Right, with that cleared up, and the binding doc expanded a bit, you won't hear complaints from me :-)

Ok, I should write documentation indeed. ;-)

Quoted 12 lines
Quoted 11 lines
Quoted 5 lines

(I like the first option better, unless someone can think of some reasonable
situation where some specific GPIO controller binding needs more than 32 bits
to encode GPIO #).

I can't think of a situation where it would be strictly speaking necessary, but I can think of several where it would be more convenient. GPIO controllers that do have a bank/pin arrangement is one. GPIO controllers than have a pin number, plus some sort of direction or level information is another.

Quoted 5 lines

Ah yes, a second word for pin "type" information makes a lot of sense. #gpio-cells it is, then. Let's please make sure that we put that "type" thing in the documentation (as an example), and that the first controller
bindings we put in use it.

There is no limitation to define gpio direction in the gpio-spec, but the thing is: we're passing gpios to the drivers which are already know in what direction gpio should be set up, and we have an API to set up GPIOs.

Example: fsl_nand, we're passing gpio, and driver is doing gpio_direction_output() call on it. So we don't have to pass gpio direction information in the gpio specifier.

As for level, yes this is important information, and encoding it into gpio-spec seems reasonable (in fsl_nand example, ready-not-busy (rnb) gpio. GPIO could be wired to be !rnb or just rnb).

Thanks!

Signature · 4 lines
Anton Vorontsov
email: [email protected]
backup email: [email protected]
irc://irc.freenode.net/bd2