drivers/gpio: Altera soft IP GPIO driver
Subsystems (3)
PATCH v4 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 using dipsw and LED using LED framework.
--- .../devicetree/bindings/gpio/gpio-altera.txt | 35 ++ drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-altera.c | 395 +++++++++++++++++++++ 4 files changed, 438 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 +35 -0
@@ -0,0 +1,35 @@ +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 local interrupt offset number to the GPIO controller. + +Altera GPIO specific properties: +- altr,gpio-bank-width: Width of the GPIO bank. This defines how many pins the + GPIO device has. Ranges between 1-32. +- altr,interrupt_trigger: Specifies the interrupt trigger type the GPIO + hardware is synthesized. This field is required if the Altera GPIO controller + used has IRQ enabled as the interrupt type is not software controlled, + but hardware synthesized. + +Example: + +gpio_altr: gpio_altr { + compatible = "altr,pio-1.0"; + reg = <0xff200000 0x10>; + interrupts = <0 45 4>; + altr,gpio-bank-width = <32>; + altr,interrupt_trigger = <0>; + #gpio-cells = <1>; + gpio-controller; + #interrupt-cells = <1>; + interrupt-controller; +};
drivers/gpio/Kconfig +7 -0
@@ -121,6 +121,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_BCM_KONA) += gpio-bcm-kona.o
drivers/gpio/gpio-altera.c new file +395 -0
395 lines not on this page · raw message
Signature · 1 line
1.7.11.GIT
Hi,
Quoted 24 lines · On Wed, Nov 27, 2013 at 03:49:52AM +0000, [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 using dipsw and LED using LED framework.
Signed-off-by Tien Hock Loh <[email protected]>--- .../devicetree/bindings/gpio/gpio-altera.txt | 35 ++ drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-altera.c | 395 +++++++++++++++++++++ 4 files changed, 438 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-altera.txt create mode 100644 drivers/gpio/gpio-altera.cDocumentation/devicetree/bindings/gpio/gpio-altera.txt new file +3
-0@@ -0,0 +1,35 @@ +Altera GPIO controller bindings + +Required properties:
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 13
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +10
-0+- 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 local interrupt offset number to the GPIO controller.
Huh? This line doesn't make much sense immediately after the description of interrupt-controller. Presumably this is associated iwth #interrupt-cells?
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 17
Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +4
-0+ +Altera GPIO specific properties: +- altr,gpio-bank-width: Width of the GPIO bank. This defines how many pins the + GPIO device has. Ranges between 1-32.
The code appears to handle this as an optional property, such that this proeprty is only required if the GPIO controller does not have 32 GPIOs. It would be worth notign that this is optional, and describing when this is expected in the binding.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 21
Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +4
-0+- altr,interrupt_trigger: Specifies the interrupt trigger type the GPIO + hardware is synthesized. This field is required if the Altera GPIO controller + used has IRQ enabled as the interrupt type is not software controlled, + but hardware synthesized.
s/_/-/
What type is this, and what values are expected?
The description implies that this is an optional property, but the code seems to require it.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 30
Quoted 9 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +9
-0+ +Example: + +gpio_altr: gpio_altr { + compatible = "altr,pio-1.0"; + reg = <0xff200000 0x10>; + interrupts = <0 45 4>; + altr,gpio-bank-width = <32>; + altr,interrupt_trigger = <0>;
The description doesn't tell me what this porperty in the example means...
Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-0+ #gpio-cells = <1>; + gpio-controller; + #interrupt-cells = <1>; + interrupt-controller; +};
[...]
Quoted 11 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +11
-0+int altera_gpio_probe(struct platform_device *pdev) +{ + struct device_node *node = pdev->dev.of_node; + int id, reg, ret; + struct altera_gpio_chip *altera_gc = devm_kzalloc(&pdev->dev, + sizeof(*altera_gc), GFP_KERNEL); + if (altera_gc == NULL) { + pr_err("%s: out of memory\n", node->full_name); + return -ENOMEM; + } + altera_gc->irq = 0;
Documentation/devicetree/bindings/gpio/gpio-altera.txt
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +10
-0+ + spin_lock_init(&altera_gc->gpio_lock); + + id = pdev->id; + + if (of_property_read_u32(node, "altr,gpio-bank-width", ®)) + /*By default assume full GPIO controller*/ + altera_gc->mmchip.gc.ngpio = 32; + else + altera_gc->mmchip.gc.ngpio = reg;
As mentioned above, the binding doesn't describe this as optional, yet it's treated as such.
Quoted 17 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +17
-0+ + if (altera_gc->mmchip.gc.ngpio > 32) { + pr_warn("%s: ngpio is greater than 32, defaulting to 32\n", + node->full_name); + altera_gc->mmchip.gc.ngpio = 32; + } + + altera_gc->mmchip.gc.direction_input = altera_gpio_direction_input; + altera_gc->mmchip.gc.direction_output = altera_gpio_direction_output; + altera_gc->mmchip.gc.get = altera_gpio_get; + altera_gc->mmchip.gc.set = altera_gpio_set; + altera_gc->mmchip.gc.to_irq = altera_gpio_to_irq; + altera_gc->mmchip.gc.owner = THIS_MODULE; + + ret = of_mm_gpiochip_add(node, &altera_gc->mmchip); + if (ret) { + pr_err("%s: Failed adding memory mapped gpiochip\n",
Documentation/devicetree/bindings/gpio/gpio-altera.txt
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +10
-0+ node->full_name); + return ret; + } + + platform_set_drvdata(pdev, altera_gc); + + altera_gc->mapped_irq = irq_of_parse_and_map(node, 0); + + if (!altera_gc->mapped_irq) + goto skip_irq;
It seems odd to jump directly to a return 0. Why not just return 0 here (or initialise ret to 0 and combine the two return cases)?
Thanks,
Mark.
Hi Mark
Quoted 33 lines · Mark Rutland
Hi,
Quoted 30 lines · On Wed, Nov 27, 2013 at 03:49:52AM +0000, [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 using dipsw and LED using LED framework.
Signed-off-by Tien Hock Loh <[email protected]>--- .../devicetree/bindings/gpio/gpio-altera.txt | 35 ++ drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-altera.c | 395 +++++++++++++++++++++ 4 files changed, 438 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-altera.txt create mode 100644 drivers/gpio/gpio-altera.cDocumentation/devicetree/bindings/gpio/gpio-altera.txt new file +9
-0@@ -0,0 +1,35 @@ +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.
Quoted 8 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 13
Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +4
-0+- #interrupt-cells : Should be 1. +- interrupts: Specify the interrupt. +- interrupt-controller: Mark the device node as an interrupt controller + The first cell is the local interrupt offset number to the GPIO controller.Huh? This line doesn't make much sense immediately after the description of interrupt-controller. Presumably this is associated iwth #interrupt-cells?
Yes, it must have got displaced when I was editing the text. I'll get this fixed.
Quoted 11 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 17
Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +4
-0+ +Altera GPIO specific properties: +- altr,gpio-bank-width: Width of the GPIO bank. This defines how many pins the + GPIO device has. Ranges between 1-32.The code appears to handle this as an optional property, such that this proeprty is only required if the GPIO controller does not have 32 GPIOs. It would be worth notign that this is optional, and describing when this is expected in the binding.
Noted. Will add a note on required and optional parameters.
Quoted 11 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 21
Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +4
-0+- altr,interrupt_trigger: Specifies the interrupt trigger type the GPIO + hardware is synthesized. This field is required if the Altera GPIO controller + used has IRQ enabled as the interrupt type is not software controlled, + but hardware synthesized.s/_/-/
What type is this, and what values are expected?
The description implies that this is an optional property, but the code seems to require it.
This isn't always required, but only required when the controller is used as an interrupt controller. I'll specify that this is a required field if GPIO is used as an interrupt controller. I'll add in the expected values as well.
Quoted 13 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 30
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +9
-0+ +Example: + +gpio_altr: gpio_altr { + compatible = "altr,pio-1.0"; + reg = <0xff200000 0x10>; + interrupts = <0 45 4>; + altr,gpio-bank-width = <32>; + altr,interrupt_trigger = <0>;The description doesn't tell me what this porperty in the example means...
Noted, I'll put the supported interrupt trigger to the description above. This is the value of interrupt trigger as defined in <dt-bindings/interrupt-controller/irq.h>.
Quoted 25 lines
Quoted 6 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-0+ #gpio-cells = <1>; + gpio-controller; + #interrupt-cells = <1>; + interrupt-controller; +};[...]
Quoted 16 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +16
-0+int altera_gpio_probe(struct platform_device *pdev) +{ + struct device_node *node = pdev->dev.of_node; + int id, reg, ret; + struct altera_gpio_chip *altera_gc = devm_kzalloc(&pdev->dev, + sizeof(*altera_gc), GFP_KERNEL); + if (altera_gc == NULL) { + pr_err("%s: out of memory\n", node->full_name); + return -ENOMEM; + } + altera_gc->irq = 0; + + spin_lock_init(&altera_gc->gpio_lock); + + id = pdev->id; +
Quoted 8 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt
Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-0+ if (of_property_read_u32(node, "altr,gpio-bank-width", ®)) + /*By default assume full GPIO controller*/ + altera_gc->mmchip.gc.ngpio = 32; + else + altera_gc->mmchip.gc.ngpio = reg;As mentioned above, the binding doesn't describe this as optional, yet it's treated as such.
I'll get this fixed in the documentation.
Quoted 23 lines
Quoted 23 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +22
-0+ + if (altera_gc->mmchip.gc.ngpio > 32) { + pr_warn("%s: ngpio is greater than 32, defaulting to 32\n", + node->full_name); + altera_gc->mmchip.gc.ngpio = 32; + } + + altera_gc->mmchip.gc.direction_input = altera_gpio_direction_input; + altera_gc->mmchip.gc.direction_output = altera_gpio_direction_output; + altera_gc->mmchip.gc.get = altera_gpio_get; + altera_gc->mmchip.gc.set = altera_gpio_set; + altera_gc->mmchip.gc.to_irq = altera_gpio_to_irq; + altera_gc->mmchip.gc.owner = THIS_MODULE; + + ret = of_mm_gpiochip_add(node, &altera_gc->mmchip); + if (ret) { + pr_err("%s: Failed adding memory mapped gpiochip\n", + node->full_name); + return ret; + } + + platform_set_drvdata(pdev, altera_gc);
Quoted 8 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt
Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-0+ + altera_gc->mapped_irq = irq_of_parse_and_map(node, 0); + + if (!altera_gc->mapped_irq) + goto skip_irq;It seems odd to jump directly to a return 0. Why not just return 0 here (or initialise ret to 0 and combine the two return cases)?
Noted. I'll return 0 here.
Quoted 3 lines
Thanks,
Mark.
Thanks for the comments. I'll post a patch v5.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 7
Quoted 11 lines · On Wed, Nov 27, 2013 at 11:49 +0800, [email protected] wrote:
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +7
-0@@ -0,0 +1,35 @@ +[ ... ] + +Example: + +gpio_altr: gpio_altr { + compatible = "altr,pio-1.0"; + reg = <0xff200000 0x10>;
This length appears to be less than what the code defines (the latter has offsets beyond 0x10).
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 30
Quoted 3 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +3
-0+ interrupts = <0 45 4>; + altr,gpio-bank-width = <32>; + altr,interrupt_trigger = <0>;
The numerical value of zero is not one of the valid options. Strictly speaking, "none" is zero -- but if the GPIO chip is an IRQ controller, the value should be _some_ trigger type, I guess.
Is it useful to drop numerical specs and use symbolic names, when you already refer to dt-bindings header files in your reply? And/or reference common GPIO and IRQ related documentation.
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-0+ #gpio-cells = <1>; + gpio-controller; + #interrupt-cells = <1>; + interrupt-controller; +};
drivers/gpio/gpio-altera.c line 8
Quoted 8 lines
drivers/gpio/gpio-altera.c new file +8
-0@@ -0,0 +1,395 @@ +[ ... ] + +#define ALTERA_GPIO_DATA 0x0 +#define ALTERA_GPIO_DIR 0x4 +#define ALTERA_GPIO_IRQ_MASK 0x8 +#define ALTERA_GPIO_EDGE_CAP 0xc +#define ALTERA_GPIO_OUTSET 0x10 +#define ALTERA_GPIO_OUTCLEAR 0x14
See above. These aren't used in the code, but they suggest that the register window is larger than 0x10.
Quoted 11 lines
drivers/gpio/gpio-altera.c new file +11
-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 i; + chip->irq_mask (&desc->irq_data); + +/* Handling for level trigger and edge trigger is different */
drivers/gpio/gpio-altera.c line 218
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+if (altera_gc->interrupt_trigger ==IRQ_TYPE_LEVEL_HIGH ) { + status =readl_relaxed (mm_gc->regs +ALTERA_GPIO_DATA ); + status &=readl_relaxed (mm_gc->regs +ALTERA_GPIO_IRQ_MASK ); + +for (i =0 ; i < mm_gc->gc.ngpio; i++) { +if (BIT (i) & status) { +generic_handle_irq (irq_linear_revmap ( + altera_gc->irq, i)); + } + }
for_each_set_bit()
Quoted 4 lines
drivers/gpio/gpio-altera.c new file +4
-0+ }else { +while ((status = + (readl_relaxed (mm_gc->regs +ALTERA_GPIO_EDGE_CAP ) & +readl_relaxed (mm_gc->regs +ALTERA_GPIO_IRQ_MASK )))) {
drivers/gpio/gpio-altera.c line 232
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+writel_relaxed (status, + mm_gc->regs +ALTERA_GPIO_EDGE_CAP ); +for (i =0 ; i < mm_gc->gc.ngpio; i++) { +if (BIT (i) & status) { +generic_handle_irq (irq_linear_revmap ( + altera_gc->irq, i)); + } + } + } + }
Is the "level low" trigger missing? Or is it not supported (in the hardware) and is this worth documenting? OTOH later versions of the IP block may support all types of triggers, so the main concern is that the driver's setup and handling are consistent, which they are from a quick glance.
Quoted 4 lines
drivers/gpio/gpio-altera.c new file +4
-0+ + chip->irq_eoi (irq_desc_get_irq_data (desc)); + chip->irq_unmask (&desc->irq_data); +}
drivers/gpio/gpio-altera.c line 300
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +8
-0+int altera_gpio_probe (struct platform_device *pdev) +{ +[ ... ] + + altera_gc->mapped_irq =irq_of_parse_and_map (node,0 ); + +if (!altera_gc->mapped_irq) + goto skip_irq;
Personally I would not eliminate this goto instruction, but would put the skip_irq label into the regular probe() path. After all it's a shortcut when an option does not apply, it's not an error path.
Quoted 11 lines
drivers/gpio/gpio-altera.c new file +11
-0+ + altera_gc->irq =irq_domain_add_linear (node, altera_gc->mmchip.gc.ngpio, + &altera_gpio_irq_ops, altera_gc); + +if (!altera_gc->irq) { + ret = -ENODEV ; + goto dispose_irq; + } + +if (of_property_read_u32 (node,"altr,interrupt_trigger" , ®)) { + ret = -EINVAL ;
drivers/gpio/gpio-altera.c line 321
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+pr_err ("%s: interrupt_trigger value not set in device tree\n" , + node->full_name); + goto teardown; + } + altera_gc->interrupt_trigger = reg; + +irq_set_handler_data (altera_gc->mapped_irq, altera_gc); +irq_set_chained_handler (altera_gc->mapped_irq, altera_gpio_irq_handler); + +return 0 ;
I'd put skip_irq here, right before the return (as other GPIO drivers do). The remaining lines of this routine all can be considered "exceptions" and "bail out" paths.
Quoted 4 lines
drivers/gpio/gpio-altera.c new file +4
-0+ +teardown: +irq_domain_remove (altera_gc->irq); +dispose_irq:
drivers/gpio/gpio-altera.c line 335
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+irq_dispose_mapping (altera_gc->mapped_irq); +WARN_ON (gpiochip_remove (&altera_gc->mmchip.gc) <0 ); + +pr_err ("%s: registration failed with status %d\n" , + node->full_name, ret); + +return ret; +skip_irq: +return 0 ; +}
virtually yours
Gerhard Sittig
Signature · 3 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr. 5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: [email protected]
Quoted 15 lines · Gerhard Sittig
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 7
Quoted 11 lines · On Wed, Nov 27, 2013 at 11:49 +0800, [email protected] wrote:
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +7
-0@@ -0,0 +1,35 @@ +[ ... ] + +Example: + +gpio_altr: gpio_altr { + compatible = "altr,pio-1.0"; + reg = <0xff200000 0x10>;This length appears to be less than what the code defines (the latter has offsets beyond
0x10).
The higher registers (0x10 and 0x14) are only available if the controller is configured as GPIO output. Thus, there are two configuration - one that has the length 0x10 (GPIO without output ports), and one with the length 0x20 (GPIO with output ports). Is there anything I need to handle for cases like this?
Quoted 9 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 30
Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +3
-0+ interrupts = <0 45 4>; + altr,gpio-bank-width = <32>; + altr,interrupt_trigger = <0>;The numerical value of zero is not one of the valid options. Strictly speaking, "none" is zero -- but if the GPIO chip is an IRQ controller, the value should be _some_ trigger type, I guess.
Yes, you're right, I'll get it fixed.
Quoted 4 lines
Is it useful to drop numerical specs and use symbolic names, when you already refer to dt-bindings header files in your reply? And/or reference common GPIO and IRQ related documentation.
Noted. I'll update the documentation on using dt-binding macros instead of values.
Quoted 7 lines
Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-0+ #gpio-cells = <1>; + gpio-controller; + #interrupt-cells = <1>; + interrupt-controller; +};
Quoted 14 lines
drivers/gpio/gpio-altera.c line 8
Quoted 11 lines
drivers/gpio/gpio-altera.c new file +8
-0@@ -0,0 +1,395 @@ +[ ... ] + +#define ALTERA_GPIO_DATA 0x0 +#define ALTERA_GPIO_DIR 0x4 +#define ALTERA_GPIO_IRQ_MASK 0x8 +#define ALTERA_GPIO_EDGE_CAP 0xc +#define ALTERA_GPIO_OUTSET 0x10 +#define ALTERA_GPIO_OUTCLEAR 0x14See above. These aren't used in the code, but they suggest that the register window is larger than
0x10.
See my explanation above.
Quoted 40 lines
Quoted 12 lines
drivers/gpio/gpio-altera.c new file +11
-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 i; + chip->irq_mask (&desc->irq_data); + +/* Handling for level trigger and edge trigger is different */ drivers/gpio/gpio-altera.c line 218
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+if (altera_gc->interrupt_trigger ==IRQ_TYPE_LEVEL_HIGH ) { + status =readl_relaxed (mm_gc->regs +ALTERA_GPIO_DATA ); + status &=readl_relaxed (mm_gc->regs +ALTERA_GPIO_IRQ_MASK ); + +for (i =0 ; i < mm_gc->gc.ngpio; i++) { +if (BIT (i) & status) { +generic_handle_irq (irq_linear_revmap ( + altera_gc->irq, i)); + } + }
for_each_set_bit()Quoted 4 lines
drivers/gpio/gpio-altera.c new file +4
-0+ }else { +while ((status = + (readl_relaxed (mm_gc->regs +ALTERA_GPIO_EDGE_CAP ) & +readl_relaxed (mm_gc->regs +ALTERA_GPIO_IRQ_MASK )))) {drivers/gpio/gpio-altera.c line 232
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+writel_relaxed (status, + mm_gc->regs +ALTERA_GPIO_EDGE_CAP ); +for (i =0 ; i < mm_gc->gc.ngpio; i++) { +if (BIT (i) & status) { +generic_handle_irq (irq_linear_revmap ( + altera_gc->irq, i)); + } + } + } + }
Quoted 5 lines
Is the "level low" trigger missing? Or is it not supported (in the hardware) and is this worth documenting? OTOH later versions of the IP block may support all types of triggers, so the main concern is that the driver's setup and handling are consistent, which they are from a quick glance.
Yes, the Altera GPIO IP doesn't support level low trigger. Patch V5 has the supported interrupt triggers in the documentation.
Quoted 7 lines
Quoted 5 lines
drivers/gpio/gpio-altera.c new file +4
-0+ + chip->irq_eoi (irq_desc_get_irq_data (desc)); + chip->irq_unmask (&desc->irq_data); +}
Quoted 13 lines
drivers/gpio/gpio-altera.c line 300
Quoted 8 lines
drivers/gpio/gpio-altera.c new file +8
-0+int altera_gpio_probe (struct platform_device *pdev) +{ +[ ... ] + + altera_gc->mapped_irq =irq_of_parse_and_map (node,0 ); + +if (!altera_gc->mapped_irq) + goto skip_irq;Personally I would not eliminate this goto instruction, but would put the
skip_irqlabel into the regularprobe()path. After all it's a shortcut when an option does not apply, it's not an error path.
Right. I'll get this fixed.
Quoted 18 lines
Quoted 18 lines
drivers/gpio/gpio-altera.c new file +17
-0+ + altera_gc->irq =irq_domain_add_linear (node, altera_gc->mmchip.gc.ngpio, + &altera_gpio_irq_ops, altera_gc); + +if (!altera_gc->irq) { + ret = -ENODEV ; + goto dispose_irq; + } + +if (of_property_read_u32 (node,"altr,interrupt_trigger" , ®)) { + ret = -EINVAL ; +pr_err ("%s: interrupt_trigger value not set in device tree\n" , + node->full_name); + goto teardown; + } + altera_gc->interrupt_trigger = reg; +
Quoted 8 lines
drivers/gpio/gpio-altera.c line 321
Quoted 4 lines
drivers/gpio/gpio-altera.c new file +4
-0+irq_set_handler_data (altera_gc->mapped_irq, altera_gc); +irq_set_chained_handler (altera_gc->mapped_irq, altera_gpio_irq_handler); + +return 0 ;I'd put
skip_irqhere, right before the return (as other GPIO drivers do). The remaining lines of this routine all can be considered "exceptions" and "bail out" paths.
Noted. Thanks.
Quoted 17 lines
Quoted 5 lines
drivers/gpio/gpio-altera.c new file +4
-0+ +teardown: +irq_domain_remove (altera_gc->irq); +dispose_irq:drivers/gpio/gpio-altera.c line 335
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+irq_dispose_mapping (altera_gc->mapped_irq); +WARN_ON (gpiochip_remove (&altera_gc->mmchip.gc) <0 ); + +pr_err ("%s: registration failed with status %d\n" , + node->full_name, ret); + +return ret; +skip_irq: +return 0 ; +}
Quoted 6 lines
virtually yours
Gerhard Sittig
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr. 5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: [email protected]
Thanks for the comments. I'll get these fixed.
Quoted 18 lines · Tien Hock Loh
Quoted 15 lines · Gerhard Sittig
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 7
Quoted 11 lines · On Wed, Nov 27, 2013 at 11:49 +0800, [email protected] wrote:
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +7
-0@@ -0,0 +1,35 @@ +[ ... ] + +Example: + +gpio_altr: gpio_altr { + compatible = "altr,pio-1.0"; + reg = <0xff200000 0x10>;This length appears to be less than what the code defines (the latter has offsets beyond
0x10).
Quoted 5 lines
The higher registers (
0x10and0x14) are only available if the controller is configured as GPIO output. Thus, there are two configuration - one that has the length0x10(GPIO without output ports), and one with the length0x20(GPIO with output ports). Is there anything I need to handle for cases like this?
Hmm. I cannot tell whether there is a preference in mainline or whether there is prior art of IP blocks having different sizes depending on their "being compatible" to something or their configuration and feature set. Others may know more.
With your explanation in mind, writing "specify an address and size that fits your component" may be considered "stating the obvious".
So I don't have strong feelings about it, I was just wondering. This need not mean that something was wrong. :)
virtually yours
Gerhard Sittig
Signature · 3 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr. 5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: [email protected]
Quoted 25 lines · Gerhard Sittig
Quoted 18 lines · Tien Hock Loh
Quoted 15 lines · Gerhard Sittig
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 7
Quoted 11 lines · On Wed, Nov 27, 2013 at 11:49 +0800, [email protected] wrote:
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +7
-0@@ -0,0 +1,35 @@ +[ ... ] + +Example: + +gpio_altr: gpio_altr { + compatible = "altr,pio-1.0"; + reg = <0xff200000 0x10>;This length appears to be less than what the code defines (the latter has offsets beyond
0x10).Quoted 5 lines
The higher registers (
0x10and0x14) are only available if the controller is configured as GPIO output. Thus, there are two configuration - one that has the length0x10(GPIO without output ports), and one with the length0x20(GPIO with output ports). Is there anything I need to handle for cases like this?
Quoted 4 lines
Hmm. I cannot tell whether there is a preference in mainline or whether there is prior art of IP blocks having different sizes depending on their "being compatible" to something or their configuration and feature set. Others may know more.
More of a question to the DT people but having the actual size of this very variant seems to fit the DT paradigm of "describing hardware" precisely.
In worst case, what happens? Code dealing with an 0x10 sized controller writes into register 0x14, and instead of silently ignoring a write to the unused memory (unless it causes a bus stall!) you get a nice crash, which in this case is a feature as it helps you debug the code.
So I'd say, stick the actual size in the DTS.
Yours,
Linus Walleij