GPIO LIB API support for OF and PowerPC
Subsystems (3)
cover GPIO LIB API support for OF and PowerPC
Hi all,
Here are few patches needed to support GPIO LIB API on PowerPC. It would be great to see these applied for the 2.6.26...
For now we use static gpio base allocation, later we'll switch to the dynamic bases. The patch below shows the idea of what needs to be done when dynamic gpio base allocation patch[1] will hit the mainline.
[1] http://lkml.org/lkml/2008/3/11/261
- - - -
Subject: of/gpio: use dynamic base allocation
---
depends on http://lkml.org/lkml/2008/3/11/261
drivers/of/gpio.c | 38 +------------------------------------- 1 files changed, 1 insertions(+), 37 deletions(-)
drivers/of/gpio.c +1 -37
@@ -118,38 +118,6 @@ static int of_gpio_simple_xlate(struct of_gpio_chip *of_gc,return *gpio; } -/* Should be sufficient for now, later we'll use dynamic bases. */ -#if defined(CONFIG_PPC32 ) || defined(CONFIG_SPARC32 ) -#define GPIOS_PER_CHIP 32 -#else -#define GPIOS_PER_CHIP 64 -#endif - -static int of_get_gpiochip_base (struct device_node *np) -{ -struct device_node *gc =NULL ; -int gpiochip_base =0 ; - -while ((gc =of_find_all_nodes (gc))) { -if (!of_get_property (gc,"gpio-controller" ,NULL )) -continue ; - -if (gc != np) { - gpiochip_base +=GPIOS_PER_CHIP ; -continue ; - } - -of_node_put (gc); - -if (gpiochip_base >=ARCH_NR_GPIOS ) -return -ENOSPC ; - -return gpiochip_base; - } - -return -ENOENT ; -} -int of_mm_gpiochip_add (struct device_node *np,struct of_mm_gpio_chip *mm_gc) {
@@ -165,11 +133,7 @@ int of_mm_gpiochip_add(struct device_node *np,if (!mm_gc->regs) goto err1; - gc->base =of_get_gpiochip_base (np); -if (gc->base <0 ) { - ret = gc->base; - goto err1; - } + gc->base =-1 ;if (!of_gc->xlate) of_gc->xlate = of_gpio_simple_xlate;
Signature · 1 line
1.5.2.2
PATCH 1/4 OF helpers for the GPIO API
This patch implements various helpers to support OF bindings for the GPIO LIB API.
Previously this was PowerPC specific, but it seems this code isn't arch-dependent anyhow, so let's place it into of/.
SPARC will not see this addition yet, real hardware seem to not use GPIOs at all. But this might change:
http://www.leox.org/docs/faq_MLleon.html
"16-bit I/O port" sounds promising. :-)
--- drivers/of/Kconfig | 6 ++ drivers/of/Makefile | 1 + drivers/of/gpio.c | 202 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_gpio.h | 96 ++++++++++++++++++++++ 4 files changed, 305 insertions(+), 0 deletions(-) create mode 100644 drivers/of/gpio.c create mode 100644 include/linux/of_gpio.h
drivers/of/Kconfig +6 -0
@@ -1,3 +1,9 @@ config OF_DEVICE def_bool y depends on OF && (SPARC || PPC_OF) + +config OF_GPIO + def_bool y + depends on OF && PPC_OF && HAVE_GPIO_LIB + help + OpenFirmware GPIO accessors
drivers/of/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-y = base.o obj-$(CONFIG_OF_DEVICE) += device.o platform.o +obj-$(CONFIG_OF_GPIO) += gpio.o
drivers/of/gpio.c new file +202 -0
202 lines not on this page · raw message
include/linux/of_gpio.h new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
1.5.2.2
PATCH 2/4 Implement support for the GPIO LIB API
In reply to Anton VorontsovThis patch implements support for the GPIO LIB API. Two calls unimplemented though: irq_to_gpio and gpio_to_irq.
--- Documentation/powerpc/booting-without-of.txt | 52 ++++++++++++++++++++++++ arch/powerpc/Kconfig | 5 ++ include/asm-powerpc/gpio.h | 55 ++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 0 deletions(-) create mode 100644 include/asm-powerpc/gpio.h
Documentation/powerpc/booting-without-of.txt +52 -0
@@ -66,6 +66,10 @@ Table of Contents 3) OpenPIC Interrupt Controllers 4) ISA Interrupt Controllers + VIII - Specifying GPIO information for devices + 1) gpios property + 2) gpio-controller nodes + Appendix A - Sample SOC node for MPC8540
@@ -2925,6 +2929,54 @@ encodings listed below: 2 = high to low edge sensitive type enabled 3 = low to high edge sensitive type enabled +VIII - Specifying GPIO information for devices +============================================== + +1) gpios property +----------------- + +Nodes that makes use of GPIOs should define them using `gpios' property, +format of which is: <&gpio-controller1-phandle gpio1-specifier + &gpio-controller2-phandle gpio2-specifier + 0 /* holes are permitted, means no GPIO 3 */ + &gpio-controller4-phandle gpio4-specifier + ...>; + +Note that gpio-specifier length is controller dependent. + +gpio-specifier may encode: bank, pin position inside the bank, +whether pin is open-drain and whether pin is logically inverted. + +Example of the node using GPIOs: + + node { + gpios = <&qe_pio_e 18 0>; + }; + +In this example gpio-specifier is "18 0" and encodes GPIO pin number, +and empty GPIO flags as accepted by the "qe_pio_e" gpio-controller. + +2) gpio-controller nodes +------------------------ + +Every GPIO controller node must have #gpio-cells property defined, +this information will be used to translate gpio-specifiers. + +Example of two SOC GPIO banks defined as gpio-controller nodes: + + qe_pio_a: gpio-controller@1400 { + #gpio-cells = <2>; + compatible = "fsl,qe-pario-bank-a", "fsl,qe-pario-bank"; + reg = <0x1400 0x18>; + gpio-controller; + }; + + qe_pio_e: gpio-controller@1460 { + #gpio-cells = <2>; + compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank"; + reg = <0x1460 0x18>; + gpio-controller; + }; Appendix A - Sample SOC node for MPC8540 ========================================
arch/powerpc/Kconfig +5 -0
@@ -81,6 +81,11 @@ config GENERIC_FIND_NEXT_BIT bool default y +config GENERIC_GPIO + bool + help + Generic GPIO API support + config ARCH_NO_VIRT_TO_BUS def_bool PPC64
include/asm-powerpc/gpio.h new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
1.5.2.2
Re: [PATCH 2/4] [POWERPC] Implement support for the GPIO LIB API
Hi Anton,
Quoted 10 lines · Anton Vorontsov
This patch implements support for the GPIO LIB API. Two calls unimplemented though:
irq_to_gpioandgpio_to_irq.Signed-off-by Anton Vorontsov <[email protected]>--- Documentation/powerpc/booting-without-of.txt | 52 ++++++++++++++++++++++++ arch/powerpc/Kconfig | 5 ++ include/asm-powerpc/gpio.h | 55 ++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 0 deletions(-) create mode 100644 include/asm-powerpc/gpio.h
[snip]
Quoted 47 lines
include/asm-powerpc/gpio.h new file +41
-0@@ -0,0 +1,55 @@ +/* +* Generic GPIO API implementation for PowerPC. +* +* Copyright (c) 2007-2008 MontaVista Software, Inc. +* +* Author: Anton Vorontsov <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#ifndef __ASM_POWERPC_GPIO_H +#define __ASM_POWERPC_GPIO_H + +#include <asm-generic/gpio.h> + +#ifdef CONFIG_HAVE_GPIO_LIB + +/* +* We don't (yet) implement inlined/rapid versions for on-chip gpios. +* Just call gpiolib. +*/ +static inline int gpio_get_value (unsigned int gpio) +{ +return __gpio_get_value (gpio); +} + +static inline void gpio_set_value (unsigned int gpio,int value) +{ +__gpio_set_value (gpio, value); +} + +static inline int gpio_cansleep (unsigned int gpio) +{ +return __gpio_cansleep (gpio); +} + +/* +* Not implemented, yet.
include/asm-powerpc/gpio.h line 51
Quoted 10 lines
include/asm-powerpc/gpio.h new file +10
-0+*/ +static inline int gpio_to_irq (unsigned int gpio) +{ +return -ENOSYS ; +} + +static inline int irq_to_gpio (unsigned int irq) +{ +return -EINVAL ; +}
You should include <linux/errno.h>.
include/asm-powerpc/gpio.h line 55
Quoted 3 lines
include/asm-powerpc/gpio.h new file +3
-0+#endif /* CONFIG_HAVE_GPIO_LIB */ + +#endif /* __ASM_POWERPC_GPIO_H */
Best regards,
Signature · 9 lines
Laurent Pinchart CSE Semaphore Belgium Chaussée de Bruxelles, 732A B-1410 Waterloo Belgium T +32 (2) 387 42 59 F +32 (2) 387 42 75
Re: [PATCH 2/4] [POWERPC] Implement support for the GPIO LIB API
Quoted 67 lines · Laurent Pinchart
Hi Anton,
Quoted 10 lines · Anton Vorontsov
This patch implements support for the GPIO LIB API. Two calls unimplemented though:
irq_to_gpioandgpio_to_irq.Signed-off-by Anton Vorontsov <[email protected]>--- Documentation/powerpc/booting-without-of.txt | 52 ++++++++++++++++++++++++ arch/powerpc/Kconfig | 5 ++ include/asm-powerpc/gpio.h | 55 ++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 0 deletions(-) create mode 100644 include/asm-powerpc/gpio.h[snip]
Quoted 51 lines
include/asm-powerpc/gpio.h new file +45
-0@@ -0,0 +1,55 @@ +/* +* Generic GPIO API implementation for PowerPC. +* +* Copyright (c) 2007-2008 MontaVista Software, Inc. +* +* Author: Anton Vorontsov <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#ifndef __ASM_POWERPC_GPIO_H +#define __ASM_POWERPC_GPIO_H + +#include <asm-generic/gpio.h> + +#ifdef CONFIG_HAVE_GPIO_LIB + +/* + * We don't (yet) implement inlined/rapid versions for on-chip gpios. + * Just call gpiolib. + */ +static inline int gpio_get_value(unsigned int gpio) +{ + return __gpio_get_value(gpio); +} + +static inline void gpio_set_value(unsigned int gpio, int value) +{ + __gpio_set_value(gpio, value); +} + +static inline int gpio_cansleep(unsigned int gpio) +{ + return __gpio_cansleep(gpio); +} + +/* + * Not implemented, yet. + */ +static inline int gpio_to_irq(unsigned int gpio) +{ + return -ENOSYS;
Quoted 8 lines
include/asm-powerpc/gpio.h line 51
Quoted 6 lines
include/asm-powerpc/gpio.h new file +6
-0+} + +static inline int irq_to_gpio (unsigned int irq) +{ +return -EINVAL ; +}You should include <
linux/errno.h>.
Yeah, much thanks for catching this!
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
PATCH 3/4 QE: split par_io_config_pin()
In reply to Anton VorontsovThis patch splits par_io_config_pin so we can use it with GPIO LIB API.
Also add a comment regarding #ifdef CONFIG_PPC_85xx being legacy.
--- arch/powerpc/sysdev/qe_lib/qe_io.c | 60 +++++++++++++++++++++++------------ 1 files changed, 39 insertions(+), 21 deletions(-)
arch/powerpc/sysdev/qe_lib/qe_io.c +39 -21
@@ -38,6 +38,10 @@ struct port_regs {__be32 cppar1;/* Pin assignment register */ __be32 cppar2;/* Pin assignment register */ #ifdef CONFIG_PPC_85xx +/* +* This is needed for legacy support only, should go away, +* because we started using per-bank gpio chips. +*/ u8 pad[8 ];#endif };
@@ -64,28 +68,29 @@ int par_io_init(struct device_node *np)return 0 ; } -int par_io_config_pin (u8 port,u8 pin,int dir,int open_drain, -int assignment,int has_irq) +static void __par_io_config_pin (struct port_regs __iomem *par_io, +u8 pin,int dir,int open_drain, +int assignment,int has_irq) { -u32 pin_mask1bit, pin_mask2bits, new_mask2bits, tmp_val; - -if (!par_io) -return -1 ; +u32 pin_mask1bit; +u32 pin_mask2bits; +u32 new_mask2bits; +u32 tmp_val;/* calculate pin location for single and 2 bits information */ pin_mask1bit = (u32) (1 << (NUM_OF_PINS - (pin +1 )));/* Set open drain, if required */ - tmp_val =in_be32 (&par_io[port].cpodr); + tmp_val =in_be32 (&par_io->cpodr);if (open_drain) -out_be32 (&par_io[port].cpodr, pin_mask1bit | tmp_val); +out_be32 (&par_io->cpodr, pin_mask1bit | tmp_val);else -out_be32 (&par_io[port].cpodr, ~pin_mask1bit & tmp_val); +out_be32 (&par_io->cpodr, ~pin_mask1bit & tmp_val);/* define direction */ tmp_val = (pin > (NUM_OF_PINS /2 ) -1 ) ? -in_be32 (&par_io[port].cpdir2) : -in_be32 (&par_io[port].cpdir1); +in_be32 (&par_io->cpdir2) : +in_be32 (&par_io->cpdir1);/* get all bits mask for 2 bit per port */ pin_mask2bits = (u32) (0x3 << (NUM_OF_PINS -
@@ -97,36 +102,49 @@ int par_io_config_pin(u8 port, u8 pin, int dir, int open_drain,/* clear and set 2 bits mask */ if (pin > (NUM_OF_PINS /2 ) -1 ) { -out_be32 (&par_io[port].cpdir2, +out_be32 (&par_io->cpdir2, ~pin_mask2bits & tmp_val); tmp_val &= ~pin_mask2bits; -out_be32 (&par_io[port].cpdir2, new_mask2bits | tmp_val); +out_be32 (&par_io->cpdir2, new_mask2bits | tmp_val); }else { -out_be32 (&par_io[port].cpdir1, +out_be32 (&par_io->cpdir1, ~pin_mask2bits & tmp_val); tmp_val &= ~pin_mask2bits; -out_be32 (&par_io[port].cpdir1, new_mask2bits | tmp_val); +out_be32 (&par_io->cpdir1, new_mask2bits | tmp_val); }/* define pin assignment */ tmp_val = (pin > (NUM_OF_PINS /2 ) -1 ) ? -in_be32 (&par_io[port].cppar2) : -in_be32 (&par_io[port].cppar1); +in_be32 (&par_io->cppar2) : +in_be32 (&par_io->cppar1); new_mask2bits = (u32) (assignment << (NUM_OF_PINS - (pin % (NUM_OF_PINS /2 ) +1 ) *2 ));/* clear and set 2 bits mask */ if (pin > (NUM_OF_PINS /2 ) -1 ) { -out_be32 (&par_io[port].cppar2, +out_be32 (&par_io->cppar2, ~pin_mask2bits & tmp_val); tmp_val &= ~pin_mask2bits; -out_be32 (&par_io[port].cppar2, new_mask2bits | tmp_val); +out_be32 (&par_io->cppar2, new_mask2bits | tmp_val); }else { -out_be32 (&par_io[port].cppar1, +out_be32 (&par_io->cppar1, ~pin_mask2bits & tmp_val); tmp_val &= ~pin_mask2bits; -out_be32 (&par_io[port].cppar1, new_mask2bits | tmp_val); +out_be32 (&par_io->cppar1, new_mask2bits | tmp_val); } +} + +/* +* This is "legacy" function that takes port number as an argument +* instead of pointer to the appropriate bank. +*/ +int par_io_config_pin (u8 port,u8 pin,int dir,int open_drain, +int assignment,int has_irq) +{ +if (!par_io || port >= num_par_io_ports) +return -EINVAL ; +__par_io_config_pin (&par_io[port], pin, dir, open_drain, assignment, + has_irq);return 0 ; }EXPORT_SYMBOL (par_io_config_pin);
Signature · 1 line
1.5.2.2
PATCH 4/4 QE: implement support for the GPIO LIB API
In reply to Anton Vorontsov--- Documentation/powerpc/booting-without-of.txt | 32 ++++--- arch/powerpc/platforms/Kconfig | 2 + arch/powerpc/sysdev/qe_lib/qe_io.c | 137 +++++++++++++++++++++++++- 3 files changed, 158 insertions(+), 13 deletions(-)
Documentation/powerpc/booting-without-of.txt +20 -12
@@ -1703,24 +1703,32 @@ platforms are moved over to use the flattened-device-tree model. information. Required properties: - - device_type : should be "par_io". + - #gpio-cells : should be "2". + - compatible : should be "fsl,qe-pario-bank-<bank>", "fsl,qe-pario-bank" - reg : offset to the register set and its length. - - num-ports : number of Parallel I/O ports + - gpio-controller : node to identify gpio controllers. - Example: - par_io@1400 { - reg = <1400 100>; - #address-cells = <1>; - #size-cells = <0>; - device_type = "par_io"; - num-ports = <7>; - ucc_pin@01 { - ...... - }; + For example, two QE Par I/O banks: + qe_pio_a: gpio-controller@1400 { + #gpio-cells = <2>; + compatible = "fsl,qe-pario-bank-a", "fsl,qe-pario-bank"; + reg = <0x1400 0x18>; + gpio-controller; + }; + qe_pio_e: gpio-controller@1460 { + #gpio-cells = <2>; + compatible = "fsl,qe-pario-bank-e", "fsl,qe-pario-bank"; + reg = <0x1460 0x18>; + gpio-controller; + }; vi) Pin configuration nodes + NOTE: pin configuration nodes are obsolete. Usually, their existance + is an evidence of the firmware shortcomings. Such fixups are + better handled by the Linux board file, not the device tree. + Required properties: - linux,phandle : phandle of this node; likely referenced by a QE device.
arch/powerpc/platforms/Kconfig +2 -0
@@ -271,6 +271,8 @@ config QUICC_ENGINE bool select PPC_LIB_RHEAP select CRC32 + select GENERIC_GPIO + select HAVE_GPIO_LIB 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 +136 -1
149 lines not on this page · raw message
Signature · 1 line
1.5.2.2