drivers/gpio: Altera soft IP GPIO driver
Subsystems (3)
PATCH v6 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 | 42 +++ drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-altera.c | 420 +++++++++++++++++++++ 4 files changed, 470 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 +42 -0
@@ -0,0 +1,42 @@ +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 + - The first cell is the gpio offset number +- gpio-controller : Marks the device node as a GPIO controller. +- #interrupt-cells : Should be 1. + - The first cell is the GPIO offset number within the GPIO controller. +- interrupts: Specify the interrupt. +- interrupt-controller: Mark the device node as an interrupt 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. Optional and defaults to 32 is not + specified. +- 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. Required if GPIO is used as an interrupt + controller. The value is defined in <dt-bindings/interrupt-controller/irq.h> + Only the following flags are supported: + IRQ_TYPE_EDGE_RISING + IRQ_TYPE_EDGE_FALLING + IRQ_TYPE_EDGE_BOTH + IRQ_TYPE_LEVEL_HIGH + +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 = <IRQ_TYPE_EDGE_RISING>; + #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 +420 -0
420 lines not on this page · raw message
Signature · 1 line
1.7.11.GIT
Quoted 7 lines · On Wed, Jan 22, 2014 at 10:54 +0800, [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]>
Quoted 8 lines
--- .../devicetree/bindings/gpio/gpio-altera.txt | 42 +++ drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-altera.c | 420 +++++++++++++++++++++ 4 files changed, 470 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-altera.txt create mode 100644 drivers/gpio/gpio-altera.c
Since you not only introduce the driver, but do introduce the binding as well, I'd suggest to reflect this in the commit message. And put 'binding' into the subject line such that DT people can be aware they should have a look.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 9
Quoted 12 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +9
-0@@ -0,0 +1,42 @@ +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 + - The first cell is the gpio offset number +- gpio-controller : Marks the device node as a GPIO controller.
Learning about required data types when reading the binding would be nice. So that DTS authors can tell whether a property is boolean, takes integers or strings, etc
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. + - The first cell is the GPIO offset number within the GPIO controller. +- interrupts: Specify the interrupt. +- interrupt-controller: Mark the device node as an interrupt controller
Are these really 'required'? I'd expect those to be optional.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 18
Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-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. Optional and defaults to 32 is not + specified.
In addition to being specific to the Altera GPIO implementation, aren't these optional, too?
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 28
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +10
-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. Required if GPIO is used as an interrupt + controller. The value is defined in <dt-bindings/interrupt-controller/irq.h> + Only the following flags are supported: + IRQ_TYPE_EDGE_RISING + IRQ_TYPE_EDGE_FALLING + IRQ_TYPE_EDGE_BOTH + IRQ_TYPE_LEVEL_HIGH
This text suggests that using the GPIO bank as an interrupt controller indeed is optional. As one would expect.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 32
Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +4
-0+ +Example: + +gpio_altr: gpio_altr {
Should node names not be generic, i.e. "gpio"? While aliases do have specific names since they identify a specific node, to later reference it from other sites.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 42
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +10
-0+ compatible = "altr,pio-1.0"; + reg = <0xff200000 0x10>; + interrupts = <0 45 4>; + altr,gpio-bank-width = <32>; + altr,interrupt_trigger = <IRQ_TYPE_EDGE_RISING>; + #gpio-cells = <1>; + gpio-controller; + #interrupt-cells = <1>; + interrupt-controller; +};
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]
Hi Tien Hock,
Quoted 15 lines · Gerhard Sittig
Quoted 6 lines · On Wed, Jan 22, 2014 at 10:54 +0800, [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]>Quoted 8 lines
--- .../devicetree/bindings/gpio/gpio-altera.txt | 42 +++ drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-altera.c | 420 +++++++++++++++++++++ 4 files changed, 470 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-altera.txt create mode 100644 drivers/gpio/gpio-altera.c
Quoted 4 lines
Since you not only introduce the driver, but do introduce the binding as well, I'd suggest to reflect this in the commit message. And put 'binding' into the subject line such that DT people can be aware they should have a look.
Yes, and you also do not have the correct DT email address too. Please look at the updated MAINTAINERS file for the correct DT BINDINGS address.
Dinh
Quoted 66 lines
Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 9
Quoted 9 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +9
-0@@ -0,0 +1,42 @@ +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 + - The first cell is the gpio offset number +- gpio-controller : Marks the device node as a GPIO controller.Learning about required data types when reading the binding would be nice. So that DTS authors can tell whether a property is boolean, takes integers or strings, etc
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. + - The first cell is the GPIO offset number within the GPIO controller. +- interrupts: Specify the interrupt. +- interrupt-controller: Mark the device node as an interrupt controllerAre these really 'required'? I'd expect those to be optional.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 18
Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-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. Optional and defaults to 32 is not + specified.In addition to being specific to the Altera GPIO implementation, aren't these optional, too?
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 28
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +10
-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. Required if GPIO is used as an interrupt + controller. The value is defined in <dt-bindings/interrupt-controller/irq.h> + Only the following flags are supported: + IRQ_TYPE_EDGE_RISING + IRQ_TYPE_EDGE_FALLING + IRQ_TYPE_EDGE_BOTH + IRQ_TYPE_LEVEL_HIGHThis text suggests that using the GPIO bank as an interrupt controller indeed is optional. As one would expect.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 32
Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +4
-0+ +Example: + +gpio_altr: gpio_altr {Should node names not be generic, i.e. "gpio"? While aliases do have specific names since they identify a specific node, to later reference it from other sites.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 42
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +10
-0+ compatible = "altr,pio-1.0"; + reg = <0xff200000 0x10>; + interrupts = <0 45 4>; + altr,gpio-bank-width = <32>; + altr,interrupt_trigger = <IRQ_TYPE_EDGE_RISING>; + #gpio-cells = <1>; + gpio-controller; + #interrupt-cells = <1>; + interrupt-controller; +};virtually yours
Gerhard Sittig
Quoted 23 lines · Dinh Nguyen
Hi Tien Hock,
Quoted 15 lines · Gerhard Sittig
Quoted 6 lines · On Wed, Jan 22, 2014 at 10:54 +0800, [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]>Quoted 8 lines
--- .../devicetree/bindings/gpio/gpio-altera.txt | 42 +++ drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-altera.c | 420 +++++++++++++++++++++ 4 files changed, 470 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-altera.txt create mode 100644 drivers/gpio/gpio-altera.cQuoted 4 lines
Since you not only introduce the driver, but do introduce the binding as well, I'd suggest to reflect this in the commit message. And put 'binding' into the subject line such that DT people can be aware they should have a look.
Quoted 5 lines
Yes, and you also do not have the correct DT email address too. Please look at the updated
MAINTAINERSfile for the correct DT BINDINGS address.Dinh
Yeah, it seems like Rob's email had changed since my last post. However, he should be getting the email from [email protected] mailing list as well.
Quoted 67 lines
Quoted 66 lines
Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 9
Quoted 9 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +9
-0@@ -0,0 +1,42 @@ +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 + - The first cell is the gpio offset number +- gpio-controller : Marks the device node as a GPIO controller.Learning about required data types when reading the binding would be nice. So that DTS authors can tell whether a property is boolean, takes integers or strings, etc
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. + - The first cell is the GPIO offset number within the GPIO controller. +- interrupts: Specify the interrupt. +- interrupt-controller: Mark the device node as an interrupt controllerAre these really 'required'? I'd expect those to be optional.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 18
Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-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. Optional and defaults to 32 is not + specified.In addition to being specific to the Altera GPIO implementation, aren't these optional, too?
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 28
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +10
-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. Required if GPIO is used as an interrupt + controller. The value is defined in <dt-bindings/interrupt-controller/irq.h> + Only the following flags are supported: + IRQ_TYPE_EDGE_RISING + IRQ_TYPE_EDGE_FALLING + IRQ_TYPE_EDGE_BOTH + IRQ_TYPE_LEVEL_HIGHThis text suggests that using the GPIO bank as an interrupt controller indeed is optional. As one would expect.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 32
Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +4
-0+ +Example: + +gpio_altr: gpio_altr {Should node names not be generic, i.e. "gpio"? While aliases do have specific names since they identify a specific node, to later reference it from other sites.
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 42
Quoted 10 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +10
-0+ compatible = "altr,pio-1.0"; + reg = <0xff200000 0x10>; + interrupts = <0 45 4>; + altr,gpio-bank-width = <32>; + altr,interrupt_trigger = <IRQ_TYPE_EDGE_RISING>; + #gpio-cells = <1>; + gpio-controller; + #interrupt-cells = <1>; + interrupt-controller; +};virtually yours
Gerhard Sittig
Quoted 17 lines · Gerhard Sittig
Quoted 7 lines · On Wed, Jan 22, 2014 at 10:54 +0800, [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]>Quoted 8 lines
--- .../devicetree/bindings/gpio/gpio-altera.txt | 42 +++ drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-altera.c | 420 +++++++++++++++++++++ 4 files changed, 470 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-altera.txt create mode 100644 drivers/gpio/gpio-altera.c
Quoted 4 lines
Since you not only introduce the driver, but do introduce the binding as well, I'd suggest to reflect this in the commit message. And put 'binding' into the subject line such that DT people can be aware they should have a look.
OK noted. Putting v7 up by in a few days so people get to review v6.
Quoted 18 lines
Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 9
Quoted 9 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +9
-0@@ -0,0 +1,42 @@ +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 + - The first cell is the gpio offset number +- gpio-controller : Marks the device node as a GPIO controller.Learning about required data types when reading the binding would be nice. So that DTS authors can tell whether a property is boolean, takes integers or strings, etc
Hmm, I don't quite understand your statement. I'm referring to other gpio device tree binding documentation when creating this. Do you mind to elaborate what you're expecting?
Quoted 7 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 13
Quoted 5 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +4
-0+- #interrupt-cells : Should be 1. + - The first cell is the GPIO offset number within the GPIO controller. +- interrupts: Specify the interrupt. +- interrupt-controller: Mark the device node as an interrupt controllerAre these really 'required'? I'd expect those to be optional.
Yeah, I'll move this to optional section.
Quoted 9 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 18
Quoted 6 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +5
-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. Optional and defaults to 32 is not + specified.In addition to being specific to the Altera GPIO implementation, aren't these optional, too?
Ditto. Moving this to optional section.
Quoted 12 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 28
Quoted 11 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +10
-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. Required if GPIO is used as an interrupt + controller. The value is defined in <dt-bindings/interrupt-controller/irq.h> + Only the following flags are supported: + IRQ_TYPE_EDGE_RISING + IRQ_TYPE_EDGE_FALLING + IRQ_TYPE_EDGE_BOTH + IRQ_TYPE_LEVEL_HIGH
Quoted 3 lines
This text suggests that using the GPIO bank as an interrupt controller indeed is optional. As one would expect.
Ditto.
Quoted 8 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 32
Quoted 4 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +4
-0+ +Example: + +gpio_altr: gpio_altr {Should node names not be generic, i.e. "gpio"? While aliases do have specific names since they identify a specific node, to later reference it from other sites.
Okay, I'll update the node name.
Quoted 19 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 42
Quoted 11 lines
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +10
-0+ compatible = "altr,pio-1.0"; + reg = <0xff200000 0x10>; + interrupts = <0 45 4>; + altr,gpio-bank-width = <32>; + altr,interrupt_trigger = <IRQ_TYPE_EDGE_RISING>; + #gpio-cells = <1>; + gpio-controller; + #interrupt-cells = <1>; + interrupt-controller; +};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]
Quoted 21 lines · Tien Hock Loh
Quoted 18 lines · Gerhard Sittig
Documentation/devicetree/bindings/gpio/gpio-altera.txt line 9
Quoted 13 lines · On Wed, Jan 22, 2014 at 10:54 +0800, [email protected] wrote:
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +9
-0@@ -0,0 +1,42 @@ +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 + - The first cell is the gpio offset number +- gpio-controller : Marks the device node as a GPIO controller.Learning about required data types when reading the binding would be nice. So that DTS authors can tell whether a property is boolean, takes integers or strings, etc
Quoted 3 lines
Hmm, I don't quite understand your statement. I'm referring to other gpio device tree binding documentation when creating this. Do you mind to elaborate what you're expecting?
Do you mean you have been citing, or copying from other bindings? Got inspiration from them, did what they do? This I'd understand.
But you don't _reference_ other bindings or a common binding. The above quotation is complete from the start of the file, and one cannot learn from this specific binding what the data types of the properties are, nor are other bindings referred to.
It's easy to fix. No problem there.
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]
[ this reply is related to the Linux driver source code,
I kept device tree and doc concerns in the other reply ]
you introduce a Linux driver, yet I don't see any Linux development ML in the Cc: list (only the GPIO maintainer and doc/DT related lists) -- am I missing something?
Quoted 20 lines · On Wed, Jan 22, 2014 at 10:54 +0800, [email protected] wrote:
drivers/gpio/gpio-altera.c new file +16
-0+ +static int altera_gpio_irq_set_type (struct irq_data *d, +unsigned int type) +{ +struct altera_gpio_chip *altera_gc =irq_data_get_irq_chip_data (d); + +if (type ==IRQ_TYPE_NONE ) +return 0 ; + +if (type ==IRQ_TYPE_LEVEL_HIGH && + altera_gc->interrupt_trigger ==IRQ_TYPE_LEVEL_HIGH ) { +return 0 ; + }else { +if (type ==IRQ_TYPE_EDGE_RISING && + altera_gc->interrupt_trigger ==IRQ_TYPE_EDGE_RISING ) +return 0 ;
drivers/gpio/gpio-altera.c line 114
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+else if (type ==IRQ_TYPE_EDGE_FALLING && + altera_gc->interrupt_trigger ==IRQ_TYPE_EDGE_FALLING ) +return 0 ; +else if (type ==IRQ_TYPE_EDGE_BOTH && + altera_gc->interrupt_trigger ==IRQ_TYPE_EDGE_BOTH ) +return 0 ; + } + +return -EINVAL ; +}
This style of indentation makes readers miss the fact that the condition is multi-line and the body is just a single line. From a quick look one might assume broken code due to missing braces. Please adjust the alignment.
Quoted 7 lines
drivers/gpio/gpio-altera.c new file +7
-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; +
drivers/gpio/gpio-altera.c line 237
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+int i; + +chained_irq_enter (chip, desc); +/* Handling for level trigger and edge trigger is different */ +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) {
this looks like "Yoda programming" :) checking the constant value against a variable, making readers stop and wonder
Quoted 37 lines
drivers/gpio/gpio-altera.c new file +36
-0+generic_handle_irq (irq_find_mapping ( + altera_gc->domain, i)); + } + } + }else { +while ((status = + (readl_relaxed (mm_gc->regs +ALTERA_GPIO_EDGE_CAP ) & +readl_relaxed (mm_gc->regs +ALTERA_GPIO_IRQ_MASK )))) { +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_find_mapping ( + altera_gc->domain, i)); + } + } + } + } + +chained_irq_exit (chip, desc); +} +int altera_gpio_probe (struct platform_device *pdev) +{ +struct device_node *node = pdev->dev.of_node; +int i, 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->domain =0 ; + +spin_lock_init (&altera_gc->gpio_lock); + + id = pdev->id;
drivers/gpio/gpio-altera.c line 299
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-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; + +if (altera_gc->mmchip.gc.ngpio >32 ) { +pr_warn ("%s: ngpio is greater than 32, defaulting to 32\n" , + node->full_name);
use dev_warn() so users can better identify the instance? hand-rolling this with pr_warn() and node->full_name is unexpected
Quoted 13 lines
drivers/gpio/gpio-altera.c new file +13
-0+ 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",
drivers/gpio/gpio-altera.c line 322
Quoted 10 lines
drivers/gpio/gpio-altera.c 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;
interrupt controller support is optional in the code, too -- good
drivers/gpio/gpio-altera.c line 333
Quoted 11 lines
drivers/gpio/gpio-altera.c new file +11
-0+ + altera_gc->domain =irq_domain_add_linear (node, + altera_gc->mmchip.gc.ngpio, &altera_gpio_irq_ops, altera_gc); + +for (i =0 ; i < altera_gc->mmchip.gc.ngpio; i++) +irq_create_mapping (altera_gc->domain, i); + +if (!altera_gc->domain) { + ret = -ENODEV ; + goto dispose_irq; + }
do you reference the domain already between allocation and the check for successful allocation?
Quoted 17 lines
drivers/gpio/gpio-altera.c new file +17
-0+ +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; + +irq_set_handler_data (altera_gc->mapped_irq, altera_gc); +irq_set_chained_handler (altera_gc->mapped_irq, altera_gpio_irq_handler); + +return 0 ; + +teardown: +irq_domain_remove (altera_gc->domain); +dispose_irq:
drivers/gpio/gpio-altera.c line 360
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 6 lines · Gerhard Sittig
[ this reply is related to the Linux driver source code,
I kept device tree and doc concerns in the other reply ]you introduce a Linux driver, yet I don't see any Linux development ML in the Cc: list (only the GPIO maintainer and doc/DT related lists) -- am I missing something?
Totally my fault. Do I add them in now or do I create a v7 patch in this case?
Quoted 29 lines · On Wed, Jan 22, 2014 at 10:54 +0800, [email protected] wrote:
Quoted 27 lines
drivers/gpio/gpio-altera.c new file +23
-0+ +static int altera_gpio_irq_set_type (struct irq_data *d, +unsigned int type) +{ +struct altera_gpio_chip *altera_gc =irq_data_get_irq_chip_data (d); + +if (type ==IRQ_TYPE_NONE ) +return 0 ; + +if (type ==IRQ_TYPE_LEVEL_HIGH && + altera_gc->interrupt_trigger ==IRQ_TYPE_LEVEL_HIGH ) { +return 0 ; + }else { +if (type ==IRQ_TYPE_EDGE_RISING && + altera_gc->interrupt_trigger ==IRQ_TYPE_EDGE_RISING ) +return 0 ; +else if (type ==IRQ_TYPE_EDGE_FALLING && + altera_gc->interrupt_trigger ==IRQ_TYPE_EDGE_FALLING ) +return 0 ; +else if (type ==IRQ_TYPE_EDGE_BOTH && + altera_gc->interrupt_trigger ==IRQ_TYPE_EDGE_BOTH ) +return 0 ; + }
Quoted 8 lines
drivers/gpio/gpio-altera.c line 114
Quoted 3 lines
drivers/gpio/gpio-altera.c new file +3
-0+ +return -EINVAL ; +}This style of indentation makes readers miss the fact that the condition is multi-line and the body is just a single line. From a quick look one might assume broken code due to missing braces. Please adjust the alignment.
Okay, will fix the alignment.
Quoted 13 lines
Quoted 13 lines
drivers/gpio/gpio-altera.c new file +12
-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; + +chained_irq_enter (chip, desc); +/* Handling for level trigger and edge trigger is different */ +if (altera_gc->interrupt_trigger ==IRQ_TYPE_LEVEL_HIGH ) {
Quoted 8 lines
drivers/gpio/gpio-altera.c line 237
Quoted 5 lines
drivers/gpio/gpio-altera.c new file +5
-0+ 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) {this looks like "Yoda programming" :) checking the constant value against a variable, making readers stop and wonder
Fix this I will.
Quoted 44 lines
Quoted 44 lines
drivers/gpio/gpio-altera.c new file +42
-0+generic_handle_irq (irq_find_mapping ( + altera_gc->domain, i)); + } + } + }else { +while ((status = + (readl_relaxed (mm_gc->regs +ALTERA_GPIO_EDGE_CAP ) & +readl_relaxed (mm_gc->regs +ALTERA_GPIO_IRQ_MASK )))) { +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_find_mapping ( + altera_gc->domain, i)); + } + } + } + } + +chained_irq_exit (chip, desc); +} +int altera_gpio_probe (struct platform_device *pdev) +{ +struct device_node *node = pdev->dev.of_node; +int i, 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->domain =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;
Quoted 8 lines
drivers/gpio/gpio-altera.c line 299
Quoted 4 lines
drivers/gpio/gpio-altera.c new file +4
-0+ +if (altera_gc->mmchip.gc.ngpio >32 ) { +pr_warn ("%s: ngpio is greater than 32, defaulting to 32\n" , + node->full_name);use
dev_warn()so users can better identify the instance? hand-rolling this withpr_warn()andnode->full_nameis unexpected
Yeah makes sense. I'll update this.
Quoted 27 lines
Quoted 14 lines
drivers/gpio/gpio-altera.c new file +13
-0+ 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",drivers/gpio/gpio-altera.c line 322
Quoted 10 lines
drivers/gpio/gpio-altera.c 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;interrupt controller support is optional in the code, too -- good
Quoted 14 lines
drivers/gpio/gpio-altera.c line 333
Quoted 11 lines
drivers/gpio/gpio-altera.c new file +11
-0+ + altera_gc->domain =irq_domain_add_linear (node, + altera_gc->mmchip.gc.ngpio, &altera_gpio_irq_ops, altera_gc); + +for (i =0 ; i < altera_gc->mmchip.gc.ngpio; i++) +irq_create_mapping (altera_gc->domain, i); + +if (!altera_gc->domain) { + ret = -ENODEV ; + goto dispose_irq; + }do you reference the domain already between allocation and the check for successful allocation?
Good catch. The irq_create_mapping was added from the last patch and I totally overlooked this.
Quoted 30 lines
Quoted 18 lines
drivers/gpio/gpio-altera.c new file +17
-0+ +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; + +irq_set_handler_data (altera_gc->mapped_irq, altera_gc); +irq_set_chained_handler (altera_gc->mapped_irq, altera_gpio_irq_handler); + +return 0 ; + +teardown: +irq_domain_remove (altera_gc->domain); +dispose_irq:drivers/gpio/gpio-altera.c line 360
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]
Tien Hock Loh