gpio: driver for PrimeCell PL061 GPIO controller
PATCH v5 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 v5:
- Use resource_size() as suggested by Linus Walleij
- Add a comment about the list member of pl061_gpio
Changes in v4:
- Depend on CONFIG_ARM_AMBA
- Do not request the gpio for IRQ automatically, just warn if it's not requested
- Remove SZ_4K
- Iterate through a linked list find the source of interrupt when multiple PL061s are connected to the same IRQ trigger
- Move hardware register defines into the .c file
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 | 6 + drivers/gpio/Makefile | 1 + drivers/gpio/pl061.c | 346 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/amba/pl061.h | 17 ++ 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 +6 -0
@@ -67,6 +67,12 @@ config GPIO_SYSFS comment "Memory mapped GPIO expanders:" +config GPIO_PL061 + bool "PrimeCell PL061 GPIO support" + depends on ARM_AMBA + 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 +17 -0
@@ -0,0 +1,17 @@ +/* platform data for the PL061 GPIO driver */ + +struct pl061_platform_data { +/* number of the first GPIO */ +unsigned gpio_base; + +u8 directions;/* startup directions, 1: out, 0: in */ +u8 values;/* startup values */ + +/* This callback may be used when you have more than one PL061 +* connected to the same IRQ trigger. This callback must return 0 on +* the first time it is called for each irq, and 1 on any other call. +* In case you are not unfortunate enough to have this setup, this +* pointer must be set to NULL. +*/ +int (*is_irq_initialized)(int irq); +};
Signature · 1 line
1.6.3.1
drivers/gpio/pl061.c line 146
Quoted 5 lines · Baruch Siach
drivers/gpio/pl061.c new file +5
-0+static unsigned int pl061_irq_startup (unsigned irq) +{ + if (gpio_request(irq_to_gpio(irq), "IRQ") == 0) + pr_warning("%s: warning: GPIO%d has not been requested\n", + __func__, irq_to_gpio(irq));
No, that's the responsibility of whoever is setting this up.
Normally, platform setup code would request the GPIO since it's being dedicated to some task on the board ... and then pass the gpio_to_irq() value as a device resource, or maybe the GPIO itself (if the driver had to deal with GPIOs per se).
Also, irq_to_gpio() can be problematic in some systems; avoid it.
drivers/gpio/pl061.c line 151
Quoted 5 lines
drivers/gpio/pl061.c new file +5
-0+ + pl061_irq_enable(irq); + + return 0; +}
Remove that gpio_request(), and the irq_to_gpio(), and you get:
The driver is a trifle unusual in having only eight bits per bank, but that's just hardware. Software looks clean, thanks.
Hi David,
Thank you very much for your review.
Quoted 8 lines · David Brownell
drivers/gpio/pl061.c line 146
Quoted 5 lines · Baruch Siach
drivers/gpio/pl061.c new file +5
-0+static unsigned int pl061_irq_startup (unsigned irq) +{ + if (gpio_request(irq_to_gpio(irq), "IRQ") == 0) + pr_warning("%s: warning: GPIO%d has not been requested\n", + __func__, irq_to_gpio(irq));No, that's the responsibility of whoever is setting this up.
The gpio_request() here is only for warning. It is expected to fail. Should I remove it? Shouldn't there be an is_gpio_requested() as part of gpiolib?
Quoted 6 lines
Normally, platform setup code would request the GPIO since it's being dedicated to some task on the board ... and then pass the
gpio_to_irq()value as a device resource, or maybe the GPIO itself (if the driver had to deal with GPIOs per se).Also,
irq_to_gpio()can be problematic in some systems; avoid it.
I use irq_to_gpio() extensively to implement the enable/disable etc. methods of irq_chip. Is there a way to implement them without irq_to_gpio()?
Quoted 9 lines
drivers/gpio/pl061.c line 151
Quoted 5 lines
drivers/gpio/pl061.c new file +5
-0+ + pl061_irq_enable(irq); + + return 0; +}Remove that
gpio_request(), and theirq_to_gpio(), and you get:Acked-by David Brownell <[email protected]>
Thanks,
Baruch
Signature · 3 lines
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- [email protected] - tel: +972.2.679.5364, http://www.tkos.co.il -Quoted 11 lines · Baruch Siach
Quoted 8 lines
drivers/gpio/pl061.c line 146
Quoted 6 lines
drivers/gpio/pl061.c new file +5
-0+static unsigned int pl061_irq_startup (unsigned irq) +{ + if (gpio_request(irq_to_gpio(irq), "IRQ") == 0) + pr_warning("%s: warning: GPIO%d has not been requested\n", + __func__, irq_to_gpio(irq));No, that's the responsibility of whoever is setting this up.
The
gpio_request()here is only for warning. It is expected to fail. Should I remove it? Shouldn't there be anis_gpio_requested()as part of gpiolib?
As I said elsewhere: yes, remove it; and no, such a call would be pointless since it's conceptually broken in threaded environments, like inside the Linux kernel.
Quoted 9 lines
Quoted 6 lines
Normally, platform setup code would request the GPIO since it's being dedicated to some task on the board ... and then pass the
gpio_to_irq()value as a device resource, or maybe the GPIO itself (if the driver had to deal with GPIOs per se).Also,
irq_to_gpio()can be problematic in some systems; avoid it.I use
irq_to_gpio()extensively to implement the enable/disable etc. methods ofirq_chip. Is there a way to implement them withoutirq_to_gpio()?
If it works on your systems, so be it ... it's highly system-specific whether it works. But this driver is not supposed to be system-specific, and shouldn't use it. (And it doesn't need to use it, as noted.)
Quoted 20 lines
Quoted 9 lines
drivers/gpio/pl061.c line 151
Quoted 5 lines
drivers/gpio/pl061.c new file +5
-0+ + pl061_irq_enable(irq); + + return 0; +}Remove that
gpio_request(), and theirq_to_gpio(), and you get:Acked-by David Brownell <[email protected]>Thanks,
Baruch
Signature · 3 lines
~. .~ Tk Open Systems =}------------------------------------------------ooO--U--Ooo------------{= - [email protected] - tel: +972.2.679.5364, http://www.tkos.co.il -