gpio: driver for PrimeCell PL061 GPIO controller
PATCH v3 1/1 gpio: driver for PrimeCell PL061 GPIO controller
This is a driver for the ARM PrimeCell PL061 GPIO AMBA peripheral. The driver is implemented using the gpiolib framework.
This driver also includes support for the use of the PL061 as an interrupt controller (secondary).
---
Changes in v3:
- amba driver instead of a platform driver
- Move include/linux/gpio/pl061.h => include/linux/amba/pl061.h
Changes in v2:
- Address Andrew Morton's comments
- Pass checkpatch.pl
- Add changelog comment
drivers/gpio/Kconfig | 5 + drivers/gpio/Makefile | 1 + drivers/gpio/pl061.c | 346 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/amba/pl061.h | 18 +++ 4 files changed, 370 insertions(+), 0 deletions(-) create mode 100644 drivers/gpio/pl061.c create mode 100644 include/linux/amba/pl061.h
drivers/gpio/Kconfig +5 -0
@@ -67,6 +67,11 @@ config GPIO_SYSFS comment "Memory mapped GPIO expanders:" +config GPIO_PL061 + bool "PrimeCell PL061 GPIO support" + help + Say yes here to support the PrimeCell PL061 GPIO device + config GPIO_XILINX bool "Xilinx GPIO support" depends on PPC_OF
drivers/gpio/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_GPIO_MAX732X) += max732x.o obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o obj-$(CONFIG_GPIO_PCA953X) += pca953x.o obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o +obj-$(CONFIG_GPIO_PL061) += pl061.o obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o obj-$(CONFIG_GPIO_XILINX) += xilinx_gpio.o obj-$(CONFIG_GPIO_BT8XX) += bt8xxgpio.o
drivers/gpio/pl061.c new file +346 -0
346 lines not on this page · raw message
include/linux/amba/pl061.h new file +18 -0
@@ -0,0 +1,18 @@ +/* platform data for the PL061 GPIO driver */ + +#define GPIODIR 0x400 +#define GPIOIS 0x404 +#define GPIOIBE 0x408 +#define GPIOIEV 0x40C +#define GPIOIE 0x410 +#define GPIORIS 0x414 +#define GPIOMIS 0x418 +#define GPIOIC 0x41C + +struct pl061_platform_data { +/* number of the first GPIO */ +unsigned gpio_base; +u32 (*pending_irqs)(int irq); +u8 directions;/* startup directions, 1: out, 0: in */ +u8 values;/* startup values */ +};
Signature · 1 line
1.6.3.1
Quoted 2 lines · On Tue, 2 Jun 2009 23:48:10 +0300 Baruch Siach <[email protected]> wrote:
This is a driver for the ARM PrimeCell PL061 GPIO AMBA peripheral. The driver is implemented using the gpiolib framework.
x86_64 allmodconfig:
drivers/gpio/pl061.c: In function 'pl061_probe':drivers/gpio/pl061.c:254: error: 'SZ_4K' undeclared (first use in this function) drivers/gpio/pl061.c:254: error: (Each undeclared identifier is reported only once drivers/gpio/pl061.c:254: error: for each function it appears in.) drivers/gpio/pl061.c:306: error: implicit declaration of function 'set_irq_flags' drivers/gpio/pl061.c:306: error: 'IRQF_VALID' undeclared (first use in this function)
I'll put a depends-on-ARM in there...
Hi Andrew,
Quoted 8 lines · Andrew Morton
Quoted 2 lines · On Tue, 2 Jun 2009 23:48:10 +0300 Baruch Siach <[email protected]> wrote:
This is a driver for the ARM PrimeCell PL061 GPIO AMBA peripheral. The driver is implemented using the gpiolib framework.
x86_64allmodconfig:
Quoted 8 lines
drivers/gpio/pl061.c: In function 'pl061_probe':drivers/gpio/pl061.c:254: error: 'SZ_4K' undeclared (first use in this function)drivers/gpio/pl061.c:254: error: (Each undeclared identifier is reported only oncedrivers/gpio/pl061.c:254: error: for each function it appears in.)drivers/gpio/pl061.c:306: error: implicit declaration of function 'set_irq_flags'drivers/gpio/pl061.c:306: error: 'IRQF_VALID' undeclared (first use in this function)I'll put a depends-on-ARM in there...
I guess a depends-on-ARM_AMBA would be better.
baruch
Signature · 3 lines
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- [email protected] - tel: +972.2.679.5364, http://www.tkos.co.il -Quoted 1 line · Baruch Siach
+static u32 (*pl061_pending_irq)(int irq);
Hmm, not sure this is entirely a good idea, especially when some platforms may have more than one of these. It'll work provided they all point at the same function, but if they don't, it's bad news.
IRQs do have the ability to have chip specific data attached to them. See set_irq_chip_data() and get_irq_chip_data().
drivers/gpio/pl061.c line 150
Quoted 12 lines
drivers/gpio/pl061.c new file +12
-0+static unsigned int pl061_irq_startup (unsigned irq) +{ +int ret; + + ret =gpio_request (irq_to_gpio (irq),"IRQ" ); +if (ret <0 ) { +pr_warning ("%s: warning: gpio_request(%d) returned %d\n" , + __func__,irq_to_gpio (irq), ret); +return 0 ; + } + +gpio_direction_input (irq_to_gpio (irq));
I thought that it was not expected that claiming an interrupt would claim a GPIO automatically - in other words, it's the responsibility of the driver or platform itself to claim GPIOs for interrupts and ensure that they're properly configured.
drivers/gpio/pl061.c line 248
Quoted 9 lines
drivers/gpio/pl061.c new file +9
-0+static int __init pl061_probe (struct amba_device *dev,struct amba_id *id) +{ +struct pl061_platform_data *pdata; +struct pl061_gpio *chip; +int ret, irq, i; + + pdata = dev->dev.platform_data; +if (pdata ==NULL ) +return -ENODEV ;
-EINVAL would be better.
drivers/gpio/pl061.c line 254
Quoted 6 lines
drivers/gpio/pl061.c new file +6
-0+ + chip =kzalloc (sizeof (*chip),GFP_KERNEL ); +if (chip ==NULL ) +return -ENOMEM ; + +if (request_mem_region (dev->res.start,SZ_4K ,"pl061" ) ==NULL ) {
It would be better to keep SZ_* constants out of what are essentially generic drivers - or we move them into some generic kernel header (but I don't hold out that much hope of that happening.)
Quoted 6 lines
include/linux/amba/pl061.h new file +0
-0
include/linux/amba/pl061.h line 10
Quoted 10 lines
include/linux/amba/pl061.h new file +10
-0@@ -0,0 +1,18 @@ +/* platform data for the PL061 GPIO driver */ + +#define GPIODIR 0x400 +#define GPIOIS 0x404 +#define GPIOIBE 0x408 +#define GPIOIEV 0x40C +#define GPIOIE 0x410 +#define GPIORIS 0x414 +#define GPIOMIS 0x418 +#define GPIOIC 0x41C
I think it would make sense to have the above register definitions in the .c file.
Thanks.
Hi Russell,
Thank you very much for your review. See my comments below.
Quoted 9 lines · Russell King - ARM Linux
Quoted 1 line · Baruch Siach
+static u32 (*pl061_pending_irq)(int irq);
Hmm, not sure this is entirely a good idea, especially when some platforms may have more than one of these. It'll work provided they all point at the same function, but if they don't, it's bad news.
IRQs do have the ability to have chip specific data attached to them. See
set_irq_chip_data()andget_irq_chip_data().
The trouble is that my chip has two PL061 blocks that are both connected to the same IRQ on the VIC. The driver, then, has no way to know which PL061 has triggered the interrupt. That's why I moved this responsibility to the platform code.
A different approach would be to use a per-IRQ linked list containing all PL061s connected to this IRQ. Is this a reasonable solution?
Quoted 10 lines
Quoted 10 lines
drivers/gpio/pl061.c new file +9
-0+static unsigned int pl061_irq_startup (unsigned irq) +{ +int ret; + + ret =gpio_request (irq_to_gpio (irq),"IRQ" ); +if (ret <0 ) { +pr_warning ("%s: warning: gpio_request(%d) returned %d\n" , + __func__,irq_to_gpio (irq), ret); +return 0 ;
Quoted 8 lines
drivers/gpio/pl061.c line 150
Quoted 3 lines
drivers/gpio/pl061.c new file +3
-0+ } + +gpio_direction_input (irq_to_gpio (irq));I thought that it was not expected that claiming an interrupt would claim a GPIO automatically - in other words, it's the responsibility of the driver or platform itself to claim GPIOs for interrupts and ensure that they're properly configured.
OK. I guess that emitting a warning in the case of an un-claimed GPIO is OK, isn't it?
Quoted 4 lines
Quoted 4 lines
+static int
__initpl061_probe(struct amba_device *dev, struct amba_id *id)(quoted diff) +2
-0+{ + struct pl061_platform_data *pdata;
Quoted 8 lines
drivers/gpio/pl061.c line 248
Quoted 6 lines
drivers/gpio/pl061.c new file +6
-0+struct pl061_gpio *chip; +int ret, irq, i; + + pdata = dev->dev.platform_data; +if (pdata ==NULL ) +return -ENODEV ;
-EINVALwould be better.
OK.
Quoted 10 lines
drivers/gpio/pl061.c line 254
Quoted 6 lines
drivers/gpio/pl061.c new file +6
-0+ + chip =kzalloc (sizeof (*chip),GFP_KERNEL ); +if (chip ==NULL ) +return -ENOMEM ; + +if (request_mem_region (dev->res.start,SZ_4K ,"pl061" ) ==NULL ) {It would be better to keep SZ_* constants out of what are essentially generic drivers - or we move them into some generic kernel header (but I don't hold out that much hope of that happening.)
OK.
Quoted 11 lines
Quoted 11 lines
include/linux/amba/pl061.h new file +5
-0@@ -0,0 +1,18 @@ +/* platform data for the PL061 GPIO driver */ + +#define GPIODIR 0x400 +#define GPIOIS 0x404 +#define GPIOIBE 0x408
Quoted 8 lines
include/linux/amba/pl061.h line 10
Quoted 5 lines
include/linux/amba/pl061.h new file +5
-0+#define GPIOIEV 0x40C +#define GPIOIE 0x410 +#define GPIORIS 0x414 +#define GPIOMIS 0x418 +#define GPIOIC 0x41CI think it would make sense to have the above register definitions in the .c file.
I put the register definitions here for the platform code that needs access to those registers to determine IRQ sources.
baruch
Signature · 3 lines
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- [email protected] - tel: +972.2.679.5364, http://www.tkos.co.il -Quoted 9 lines · Russell King - ARM Linux
Quoted 9 lines
drivers/gpio/pl061.c new file +9
-0+static unsigned int pl061_irq_startup (unsigned irq) +{ + int ret; + + ret = gpio_request(irq_to_gpio(irq), "IRQ"); + if (ret < 0) { + pr_warning("%s: warning: gpio_request(%d) returned %d\n", + __func__, irq_to_gpio(irq), ret); + return 0;
Quoted 8 lines
Quoted 3 lines
+ }
+
+ gpio_direction_input(irq_to_gpio(irq));I thought that it was not expected that claiming an interrupt would claim a GPIO automatically - in other words, it's the responsibility of the driver or platform itself to claim GPIOs for interrupts and ensure that they're properly configured.
You're right about that.