drivers/gpio: Altera soft IP GPIO driver
Subsystems (3)
PATCH 1/1 drivers/gpio: Altera soft IP GPIO driver
From: Tien Hock Loh <[email protected]>
Add driver support for Altera GPIO soft IP, including interrupts and I/O. Tested on Altera CV SoC board.
--- .../devicetree/bindings/gpio/gpio-altera.txt | 36 ++ drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-altera.c | 405 +++++++++++++++++++++ 4 files changed, 449 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-altera.txt create mode 100644 drivers/gpio/gpio-altera.c
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +36 -0
@@ -0,0 +1,36 @@ +Altera GPIO controller bindings + +Required properties: +- compatible: + - "altr,pio-1.0" +- reg: Physical base address and length of the controller's registers. +- #gpio-cells : Should be 1 + - first cell is the gpio offset number +- gpio-controller : Marks the device node as a GPIO controller. +- #interrupt-cells : Should be 1. +- interrupts: Specify the interrupt. +- interrupt-controller: Mark the device node as an interrupt controller + The first cell is the GPIO number. + +Altera GPIO specific properties: +- width: Width of the GPIO bank, range from 1-32 +- level_trigger: Specifies whether the GPIO interrupt is level trigger (high). + This field is required if the Altera GPIO controller used has IRQ enabled. +- edge_type: Specifies edge type if the GPIO interrupt is edge trigger: + 0 = Rising edge + 1 = Falling edge + 2 = Both edge + +Example: + +gpio_altr: gpio_altr { + compatible = "altr,pio-1.0"; + reg = <0xff200000 0x10>; + interrupts = <0 45 4>; + width = <32>; + level_trigger = <0>; + #gpio-cells = <1>; + gpio-controller; + #interrupt-cells = <1>; + interrupt-controller; +};
drivers/gpio/Kconfig +7 -0
@@ -118,6 +118,13 @@ config GPIO_GENERIC_PLATFORM help Say yes here to support basic platform_device memory-mapped GPIO controllers. +config GPIO_ALTERA + tristate "Altera GPIO" + select IRQ_DOMAIN + depends on OF_GPIO + help + Say yes here to support the Altera PIO device. + config GPIO_IT8761E tristate "IT8761E GPIO support" depends on X86 # unconditional access to IO space.
drivers/gpio/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o +obj-$(CONFIG_GPIO_ALTERA) += gpio-altera.o obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o
drivers/gpio/gpio-altera.c new file +405 -0
405 lines not on this page · raw message
Signature · 1 line
1.7.11.GIT
Quoted 6 lines · On Thu, Jun 6, 2013 at 10:05 AM, <[email protected]> wrote:
From: Tien Hock Loh <[email protected]>
Add driver support for Altera GPIO soft IP, including interrupts and I/O. Tested on Altera CV SoC board.
Signed-off-by Tien Hock Loh <[email protected]>
(...)
This is looking much better, some remaining comments.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 5
Quoted 7 lines
+++
b/Documentation/devicetree/bindings/gpio/gpio-altera.txtDocumentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-0@@ -0,0 +1,36 @@ +Altera GPIO controller bindings + +Required properties: +- compatible: + - "altr,pio-1.0"
I asked you to add this prefix to Documentation/devicetree/bindings/vendor-prefixes.txt
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 13
Quoted 8 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +8
-0+- reg: Physical base address and length of the controller's registers. +- #gpio-cells : Should be 1 + - first cell is the gpio offset number +- gpio-controller : Marks the device node as a GPIO controller. +- #interrupt-cells : Should be 1. +- interrupts: Specify the interrupt. +- interrupt-controller: Mark the device node as an interrupt controller + The first cell is the GPIO number.
How can that cell be the "GPIO number"? Surely it is the local interrupt offset number on the GPIO controller?
(...)
drivers/gpio/gpio-altera.c line 120
Quoted 7 lines
drivers/gpio/gpio-altera.c new file +6
-0+++ b/drivers/gpio/gpio-altera.c +static int altera_gpio_get (struct gpio_chip *gc,unsigned offset) +{ +struct of_mm_gpio_chip *mm_gc =to_of_mm_gpio_chip (gc); + +return (readl (mm_gc->regs +ALTERA_GPIO_DATA ) >> offset) &1 ;
I usually would write that like this:
#include <linux/bitops.h>
return !!(readl(mm_gc->regs + ALTERA_GPIO_DATA) & BIT(offset));
But no big deal.
Quoted 1 line
+
gpio_ddr|= (1 << offset);
And with <linux/bitops.h> I would just:
gpio_ddr |= BIT(offset);
Quoted 28 lines
drivers/gpio/gpio-altera.c new file +28
-0+static void altera_gpio_irq_handler (unsigned int irq,struct irq_desc *desc) +{ +struct altera_gpio_chip *altera_gc =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +struct of_mm_gpio_chip *mm_gc = &altera_gc->mmchip; +unsigned long status; + +int base; + chip->irq_mask (&desc->irq_data); + +if (altera_gc->level_trigger) { + status =__raw_readl (mm_gc->regs +ALTERA_GPIO_DATA ); + status &=__raw_readl (mm_gc->regs +ALTERA_GPIO_IRQ_MASK ); + +for (base =0 ; base < mm_gc->gc.ngpio; base++) { +if ((1 << base) & status) { +generic_handle_irq (irq_linear_revmap ( + altera_gc->irq, base)); + } + } + }else { +while ((status = + (__raw_readl (mm_gc->regs +ALTERA_GPIO_EDGE_CAP ) & +__raw_readl (mm_gc->regs +ALTERA_GPIO_IRQ_MASK )))) { +__raw_writel (status, + mm_gc->regs +ALTERA_GPIO_EDGE_CAP ); +for (base =0 ; base < mm_gc->gc.ngpio; base++) { +if ((1 << base) & status) {
drivers/gpio/gpio-altera.c line 231
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+generic_handle_irq (irq_linear_revmap ( + altera_gc->irq, base)); + } + } + } + } + + chip->irq_eoi (irq_desc_get_irq_data (desc)); + chip->irq_unmask (&desc->irq_data); +}
Why is the above code using __raw_* accessors?
Atleast use readl_relaxed() instead of __raw.
drivers/gpio/gpio-altera.c line 294
Quoted 3 lines
drivers/gpio/gpio-altera.c new file +3
-0+if (of_get_property (node,"interrupts" , ®) ==NULL ) + goto skip_irq; + altera_gc->hwirq =irq_of_parse_and_map (node,0 );
But wait. How can a hardware IRQ be something coming out of irq_of_parse_and_map()???
The entire point of mapping an IRQ is to move it into some free Linux IRQ slot, it is as far away from a HW IRQ you ever get.
Either rename the variable or rethink what you're doing here.
Yours,
Linus Walleij
Quoted 12 lines · Linus Walleij
Quoted 6 lines · On Thu, Jun 6, 2013 at 10:05 AM, <[email protected]> wrote:
From: Tien Hock Loh <[email protected]>
Add driver support for Altera GPIO soft IP, including interrupts and I/O. Tested on Altera CV SoC board.
Signed-off-by Tien Hock Loh <[email protected]>(...)
This is looking much better, some remaining comments.
Quoted 11 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 5
Quoted 7 lines
+++
b/Documentation/devicetree/bindings/gpio/gpio-altera.txtDocumentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-0@@ -0,0 +1,36 @@ +Altera GPIO controller bindings + +Required properties: +- compatible: + - "altr,pio-1.0"I asked you to add this prefix to
Documentation/devicetree/bindings/vendor-prefixes.txt
Noted, missed that out.
Quoted 9 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 13
Quoted 8 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +8
-0+- reg: Physical base address and length of the controller's registers. +- #gpio-cells : Should be 1 + - first cell is the gpio offset number +- gpio-controller : Marks the device node as a GPIO controller. +- #interrupt-cells : Should be 1. +- interrupts: Specify the interrupt. +- interrupt-controller: Mark the device node as an interrupt controller + The first cell is the GPIO number.
Quoted 3 lines
How can that cell be the "GPIO number"? Surely it is the local interrupt offset number on the GPIO controller?
Yup, bad documentation. I'll update this.
Quoted 15 lines
(...)
drivers/gpio/gpio-altera.c line 120
Quoted 7 lines
+++
b/drivers/gpio/gpio-altera.cdrivers/gpio/gpio-altera.c new file +5
-0+static int altera_gpio_get (struct gpio_chip *gc,unsigned offset) +{ +struct of_mm_gpio_chip *mm_gc =to_of_mm_gpio_chip (gc); + +return (readl (mm_gc->regs +ALTERA_GPIO_DATA ) >> offset) &1 ;I usually would write that like this:
#include <
linux/bitops.h>return !!(readl(mm_gc->regs +
ALTERA_GPIO_DATA) & BIT(offset));
Quoted 7 lines
But no big deal.
Quoted 1 line
+
gpio_ddr|= (1 << offset);And with <
linux/bitops.h> I would just:
gpio_ddr|= BIT(offset);
Noted, that looks cleaner.
Noted.
A question regarding readl_relaxed(), is that because the endianess swapping? If that's the case, should codes in other functions use readl_relaxed()/writel_relaxed() as well?
Quoted 5 lines
drivers/gpio/gpio-altera.c line 294
Quoted 4 lines
drivers/gpio/gpio-altera.c new file +3
-0+if (of_get_property (node,"interrupts" , ®) ==NULL ) + goto skip_irq; + altera_gc->hwirq =irq_of_parse_and_map (node,0 );
Quoted 8 lines
But wait. How can a hardware IRQ be something coming out of
irq_of_parse_and_map()???The entire point of mapping an IRQ is to move it into some free Linux IRQ slot, it is as far away from a HW IRQ you ever get.
Either rename the variable or rethink what you're doing here.
The variable naming came from gpio-mpc8xxx.c, I'll update this to a better name.
Quoted 3 lines
Yours,
Linus Walleij
Quoted 116 lines · Linus Walleij
Quoted 6 lines · On Thu, Jun 6, 2013 at 10:05 AM, <[email protected]> wrote:
From: Tien Hock Loh <[email protected]>
Add driver support for Altera GPIO soft IP, including interrupts and I/O. Tested on Altera CV SoC board.
Signed-off-by Tien Hock Loh <[email protected]>(...)
This is looking much better, some remaining comments.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 5
Quoted 7 lines
+++
b/Documentation/devicetree/bindings/gpio/gpio-altera.txtDocumentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-0@@ -0,0 +1,36 @@ +Altera GPIO controller bindings + +Required properties: +- compatible: + - "altr,pio-1.0"I asked you to add this prefix to
Documentation/devicetree/bindings/vendor-prefixes.txtDocumentation/devicetree/bindings/gpio/gpio-altera.txt line 13
Quoted 8 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +8
-0+- reg: Physical base address and length of the controller's registers. +- #gpio-cells : Should be 1 + - first cell is the gpio offset number +- gpio-controller : Marks the device node as a GPIO controller. +- #interrupt-cells : Should be 1. +- interrupts: Specify the interrupt. +- interrupt-controller: Mark the device node as an interrupt controller + The first cell is the GPIO number.How can that cell be the "GPIO number"? Surely it is the local interrupt offset number on the GPIO controller?
(...)
drivers/gpio/gpio-altera.c line 120
Quoted 7 lines
drivers/gpio/gpio-altera.c new file +6
-0+++ b/drivers/gpio/gpio-altera.c +static int altera_gpio_get (struct gpio_chip *gc,unsigned offset) +{ +struct of_mm_gpio_chip *mm_gc =to_of_mm_gpio_chip (gc); + +return (readl (mm_gc->regs +ALTERA_GPIO_DATA ) >> offset) &1 ;I usually would write that like this:
#include <
linux/bitops.h>return !!(readl(mm_gc->regs +
ALTERA_GPIO_DATA) & BIT(offset));But no big deal.
Quoted 1 line
+
gpio_ddr|= (1 << offset);And with <
linux/bitops.h> I would just:
gpio_ddr|= BIT(offset);Quoted 28 lines
drivers/gpio/gpio-altera.c new file +28
-0+static void altera_gpio_irq_handler (unsigned int irq,struct irq_desc *desc) +{ +struct altera_gpio_chip *altera_gc =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +struct of_mm_gpio_chip *mm_gc = &altera_gc->mmchip; +unsigned long status; + +int base; + chip->irq_mask (&desc->irq_data); + +if (altera_gc->level_trigger) { + status =__raw_readl (mm_gc->regs +ALTERA_GPIO_DATA ); + status &=__raw_readl (mm_gc->regs +ALTERA_GPIO_IRQ_MASK ); + +for (base =0 ; base < mm_gc->gc.ngpio; base++) { +if ((1 << base) & status) { +generic_handle_irq (irq_linear_revmap ( + altera_gc->irq, base)); + } + } + }else { +while ((status = + (__raw_readl (mm_gc->regs +ALTERA_GPIO_EDGE_CAP ) & +__raw_readl (mm_gc->regs +ALTERA_GPIO_IRQ_MASK )))) { +__raw_writel (status, + mm_gc->regs +ALTERA_GPIO_EDGE_CAP ); +for (base =0 ; base < mm_gc->gc.ngpio; base++) { +if ((1 << base) & status) {drivers/gpio/gpio-altera.c line 231
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+generic_handle_irq (irq_linear_revmap ( + altera_gc->irq, base)); + } + } + } + } + + chip->irq_eoi (irq_desc_get_irq_data (desc)); + chip->irq_unmask (&desc->irq_data); +}Why is the above code using __raw_* accessors?
Atleast use
readl_relaxed()instead of__raw.drivers/gpio/gpio-altera.c line 294
Quoted 3 lines
drivers/gpio/gpio-altera.c new file +3
-0+if (of_get_property (node,"interrupts" , ®) ==NULL ) + goto skip_irq; + altera_gc->hwirq =irq_of_parse_and_map (node,0 );But wait. How can a hardware IRQ be something coming out of
irq_of_parse_and_map()???The entire point of mapping an IRQ is to move it into some free Linux IRQ slot, it is as far away from a HW IRQ you ever get.
Either rename the variable or rethink what you're doing here.
Yours,
Linus Walleij
Sorry for the spam, had a bad copy and paste in previous email.
Quoted 12 lines · Linus Walleij
Quoted 6 lines · On Thu, Jun 6, 2013 at 10:05 AM, <[email protected]> wrote:
From: Tien Hock Loh <[email protected]>
Add driver support for Altera GPIO soft IP, including interrupts and I/O. Tested on Altera CV SoC board.
Signed-off-by Tien Hock Loh <[email protected]>(...)
This is looking much better, some remaining comments.
Quoted 11 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 5
Quoted 7 lines
+++
b/Documentation/devicetree/bindings/gpio/gpio-altera.txtDocumentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-0@@ -0,0 +1,36 @@ +Altera GPIO controller bindings + +Required properties: +- compatible: + - "altr,pio-1.0"I asked you to add this prefix to
Documentation/devicetree/bindings/vendor-prefixes.txt
Noted, missed that out.
Quoted 9 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 13
Quoted 8 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +8
-0+- reg: Physical base address and length of the controller's registers. +- #gpio-cells : Should be 1 + - first cell is the gpio offset number +- gpio-controller : Marks the device node as a GPIO controller. +- #interrupt-cells : Should be 1. +- interrupts: Specify the interrupt. +- interrupt-controller: Mark the device node as an interrupt controller + The first cell is the GPIO number.
Quoted 3 lines
How can that cell be the "GPIO number"? Surely it is the local interrupt offset number on the GPIO controller?
Yup, bad documentation. I'll update this.
Quoted 15 lines
(...)
drivers/gpio/gpio-altera.c line 120
Quoted 7 lines
+++
b/drivers/gpio/gpio-altera.cdrivers/gpio/gpio-altera.c new file +5
-0+static int altera_gpio_get (struct gpio_chip *gc,unsigned offset) +{ +struct of_mm_gpio_chip *mm_gc =to_of_mm_gpio_chip (gc); + +return (readl (mm_gc->regs +ALTERA_GPIO_DATA ) >> offset) &1 ;I usually would write that like this:
#include <
linux/bitops.h>return !!(readl(mm_gc->regs +
ALTERA_GPIO_DATA) & BIT(offset));
Quoted 7 lines
But no big deal.
Quoted 1 line
+
gpio_ddr|= (1 << offset);And with <
linux/bitops.h> I would just:
gpio_ddr|= BIT(offset);
Noted, that looks cleaner.
Quoted 42 lines
Quoted 29 lines
drivers/gpio/gpio-altera.c new file +28
-0+static void altera_gpio_irq_handler (unsigned int irq,struct irq_desc *desc) +{ +struct altera_gpio_chip *altera_gc =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +struct of_mm_gpio_chip *mm_gc = &altera_gc->mmchip; +unsigned long status; + +int base; + chip->irq_mask (&desc->irq_data); + +if (altera_gc->level_trigger) { + status =__raw_readl (mm_gc->regs +ALTERA_GPIO_DATA ); + status &=__raw_readl (mm_gc->regs +ALTERA_GPIO_IRQ_MASK ); + +for (base =0 ; base < mm_gc->gc.ngpio; base++) { +if ((1 << base) & status) { +generic_handle_irq (irq_linear_revmap ( + altera_gc->irq, base)); + } + } + }else { +while ((status = + (__raw_readl (mm_gc->regs +ALTERA_GPIO_EDGE_CAP ) & +__raw_readl (mm_gc->regs +ALTERA_GPIO_IRQ_MASK )))) { +__raw_writel (status, + mm_gc->regs +ALTERA_GPIO_EDGE_CAP ); +for (base =0 ; base < mm_gc->gc.ngpio; base++) { +if ((1 << base) & status) {drivers/gpio/gpio-altera.c line 231
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+generic_handle_irq (irq_linear_revmap ( + altera_gc->irq, base)); + } + } + } + } + + chip->irq_eoi (irq_desc_get_irq_data (desc)); + chip->irq_unmask (&desc->irq_data); +}Why is the above code using __raw_* accessors?
Quoted 1 line
Atleast use
readl_relaxed()instead of__raw.
Noted.
A question regarding readl_relaxed(), is that because the endianess swapping? If that's the case, should codes in other functions use readl_relaxed()/writel_relaxed() as well?
Quoted 5 lines
drivers/gpio/gpio-altera.c line 294
Quoted 4 lines
drivers/gpio/gpio-altera.c new file +3
-0+if (of_get_property (node,"interrupts" , ®) ==NULL ) + goto skip_irq; + altera_gc->hwirq =irq_of_parse_and_map (node,0 );
Quoted 8 lines
But wait. How can a hardware IRQ be something coming out of
irq_of_parse_and_map()???The entire point of mapping an IRQ is to move it into some free Linux IRQ slot, it is as far away from a HW IRQ you ever get.
Either rename the variable or rethink what you're doing here.
The variable naming came from gpio-mpc8xxx.c, I'll update this to a better name.
Quoted 3 lines
Yours,
Linus Walleij
Quoted 43 lines · Loh Tien Hock
Quoted 42 lines · Linus Walleij
Quoted 28 lines · On Thu, Jun 6, 2013 at 10:05 AM, <[email protected]> wrote:
drivers/gpio/gpio-altera.c new file +28
-0+static void altera_gpio_irq_handler (unsigned int irq,struct irq_desc *desc) +{ +struct altera_gpio_chip *altera_gc =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +struct of_mm_gpio_chip *mm_gc = &altera_gc->mmchip; +unsigned long status; + +int base; + chip->irq_mask (&desc->irq_data); + +if (altera_gc->level_trigger) { + status =__raw_readl (mm_gc->regs +ALTERA_GPIO_DATA ); + status &=__raw_readl (mm_gc->regs +ALTERA_GPIO_IRQ_MASK ); + +for (base =0 ; base < mm_gc->gc.ngpio; base++) { +if ((1 << base) & status) { +generic_handle_irq (irq_linear_revmap ( + altera_gc->irq, base)); + } + } + }else { +while ((status = + (__raw_readl (mm_gc->regs +ALTERA_GPIO_EDGE_CAP ) & +__raw_readl (mm_gc->regs +ALTERA_GPIO_IRQ_MASK )))) { +__raw_writel (status, + mm_gc->regs +ALTERA_GPIO_EDGE_CAP ); +for (base =0 ; base < mm_gc->gc.ngpio; base++) { +if ((1 << base) & status) {drivers/gpio/gpio-altera.c line 231
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+generic_handle_irq (irq_linear_revmap ( + altera_gc->irq, base)); + } + } + } + } + + chip->irq_eoi (irq_desc_get_irq_data (desc)); + chip->irq_unmask (&desc->irq_data); +}Why is the above code using __raw_* accessors?
Quoted 7 lines
Quoted 1 line
Atleast use
readl_relaxed()instead of__raw.Noted.
A question regarding
readl_relaxed(), is that because the endianess swapping? If that's the case, should codes in other functions use readl_relaxed()/writel_relaxed() as well?
Basically I think of it like this:
__raw_* = will just poke the registers without really taking anything
into account, in native endianness.
readl/writel_relaxed() = same thing but always little-endian.
readl()/write() = always little-endian, and will go to lengths to also drain buffers etc so the write hits the target registers after the PC passed this instruction. To the extent possible, and may cause a performance problem due to all buffer draining.
Yours,
Linus Walleij