Altera soft IP GPIO driver
Subsystems (3)
v9 cover Altera soft IP GPIO driver
From: Tien Hock Loh <[email protected]>
Adds a new device tree binding and driver for Altera soft GPIO IP. The driver is able to do read/write and allows GPIO to be a interrupt controller.
Tested on Altera GHRD on interrupt handling and IO.
v9:
Removed duplicated initialization on set_type
using temporals to improve code readability in calling generic_handle_irq Using ?: ternary to reduce code size
v8:
Using for_each_set_bit
added const for struct definition
removed naggy pr_err
sort alpha header
remove unused macros
use fixed width data types instead of unsigned long whitespace issue fixes
removed _relaxed function for better compatibility across different CPU changed irq_create_mapping to platform_get_irq
updated implementation to use gpiochip_irqchip_add
reserve interrupt-cells number 2 in device tree binding for future use remove confusing sections on devicetree bindings
Added tristate Kconfig help text
v7:
used dev_warn instead of pr_warn
clean up unnecesarry if else indentation
v6:
Added irq_startup and irq_shutdown
changed bitwise clamping style
cleanup bitwise operation to improve readability change naming of mapped irqs from virq to mapped_irq
v5:
dispose irq_domain mapping correctly
update optional binding description in binding docs
v4:
added vendor prefix to devicetree binding for IP specific properties using MMIO GPIO helper library instead of manually map PIO to memory altera_gpio_chip inline struct documentation to kerneldoc using dev_ print to print a better failure message
v2, v3:
Do not reference NO_IRQ
Updated irq_set_type to only allow the hardware configured irq type
Tien Hock Loh (2):
drivers/gpio: Altera soft IP GPIO driver device tree binding drivers/gpio: Altera soft IP GPIO driver
.../devicetree/bindings/gpio/gpio-altera.txt | 43 +++ MAINTAINERS | 6 + drivers/gpio/Kconfig | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-altera.c | 405 +++++++++++++++++++++ 5 files changed, 463 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-altera.txt create mode 100644 drivers/gpio/gpio-altera.c
Signature · 1 line
1.7.11.GIT
PATCH v9 1/2 drivers/gpio: Altera soft IP GPIO driver device tree binding
From: Tien Hock Loh <[email protected]>
Adds a new driver device tree binding for Altera soft GPIO IP
--- .../devicetree/bindings/gpio/gpio-altera.txt | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-altera.txt
Documentation/devicetree/bindings/gpio/gpio-altera.txt new file +43 -0
@@ -0,0 +1,43 @@ +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 2 + - The first cell is the gpio offset number. + - The second cell is reserved and is currently unused. +- gpio-controller : Marks the device node as a GPIO controller. +- interrupt-controller: Mark the device node as an interrupt controller +- #interrupt-cells : Should be 1. The interrupt type is fixed in the hardware. + - The first cell is the GPIO offset number within the GPIO controller. +- interrupts: Specify the interrupt. +- 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 + +Optional properties: +- altr,ngpio: Width of the GPIO bank. This defines how many pins the + GPIO device has. Ranges between 1-32. Optional and defaults to 32 if not + specified. + +Example: + +gpio_altr: gpio@0xff200000 { + compatible = "altr,pio-1.0"; + reg = <0xff200000 0x10>; + interrupts = <0 45 4>; + altr,ngpio = <32>; + altr,interrupt-trigger = <IRQ_TYPE_EDGE_RISING>; + #gpio-cells = <1>; + gpio-controller; + #interrupt-cells = <1>; + interrupt-controller; +};
Signature · 1 line
1.7.11.GIT
PATCH v9 2/2 drivers/gpio: Altera soft IP GPIO driver
In reply to [email protected]From: Tien Hock Loh <[email protected]>
Adds a new driver for Altera soft GPIO IP. The driver is able to do read/write and allows GPIO to be a interrupt controller.
Tested on Altera GHRD on interrupt handling and IO.
--- MAINTAINERS | 6 + drivers/gpio/Kconfig | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-altera.c | 405 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 420 insertions(+) create mode 100644 drivers/gpio/gpio-altera.c
MAINTAINERS +6 -0
@@ -563,6 +563,12 @@ S: Odd Fixes L: [email protected] F: arch/alpha/ +ALTERA PIO DRIVER +M: Tien Hock Loh <[email protected]> +L: [email protected] +S: Maintained +F: drivers/gpio/gpio-altera.c + ALTERA TRIPLE SPEED ETHERNET DRIVER M: Vince Bridgers <[email protected]> L: [email protected]
drivers/gpio/Kconfig +8 -0
@@ -156,6 +156,14 @@ config GPIO_DWAPB Say Y or M here to build support for the Synopsys DesignWare APB GPIO block. +config GPIO_ALTERA + tristate "Altera GPIO" + depends on OF_GPIO + help + Say Y or M here to build support for the Altera PIO device. + + If driver is built as a module it will be called gpio-altera. + config GPIO_IT8761E tristate "IT8761E GPIO support" depends on X86 # unconditional access to IO space.
drivers/gpio/Makefile +1 -0
@@ -17,6 +17,7 @@ obj-$(CONFIG_GPIO_74XX_MMIO) += gpio-74xx-mmio.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 +405 -0
405 lines not on this page · raw message
Signature · 1 line
1.7.11.GIT
Re: [PATCH v9 2/2] drivers/gpio: Altera soft IP GPIO driver
On 2015-01-06 at 03:19:33 +0100, [email protected] <[email protected]> wrote:
[...]
Quoted 5 lines
drivers/gpio/Kconfig +0
-0
drivers/gpio/Kconfig config GPIO_DWAPB · line 165
Quoted 10 lines
drivers/gpio/Kconfig +7
-0@@ -156,6 +156,14 @@ config GPIO_DWAPB Say Y or M here to build support for the Synopsys DesignWare APB GPIO block. +config GPIO_ALTERA + tristate "Altera GPIO" + depends on OF_GPIO + help + Say Y or M here to build support for the Altera PIO device. + + If driver is built as a module it will be called gpio-altera.
Indentation looks odd. The tristate, depends and help lines should be indented by a tab and the help text should be indented by a tab followed by two spaces.
Quoted 6 lines
drivers/gpio/Kconfig +1
-0+ config GPIO_IT8761E tristate "IT8761E GPIO support" depends on X86 # unconditional access to IO space.drivers/gpio/Makefile +0
-0
[...]
Quoted 5 lines
drivers/gpio/gpio-altera.c new file +0
-0
[...]
drivers/gpio/gpio-altera.c line 297
Quoted 13 lines
drivers/gpio/gpio-altera.c new file +13
-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; + + altera_gc =devm_kzalloc (&pdev->dev,sizeof (*altera_gc),GFP_KERNEL ); +if (!altera_gc) +return -ENOMEM ; + +spin_lock_init (&altera_gc->gpio_lock); + + id = pdev->id;
id is assigned but never used.
drivers/gpio/gpio-altera.c line 300
Quoted 3 lines
drivers/gpio/gpio-altera.c new file +3
-0+ +if (of_property_read_u32 (node,"altr,ngpio" , ®)) +/*By default assume full GPIO controller*/
Spaces missing after /* and before */
drivers/gpio/gpio-altera.c line 305
Quoted 5 lines
drivers/gpio/gpio-altera.c new file +5
-0+ altera_gc->mmchip.gc.ngpio =ALTERA_GPIO_MAX_NGPIO ; + else + altera_gc->mmchip.gc.ngpio = reg; + +if (altera_gc->mmchip.gc.ngpio >32 ) {
Why the magic number 32 here? Better use ALTERA_GPIO_MAX_NGPIO as well.
Quoted 69 lines
drivers/gpio/gpio-altera.c new file +69
-0+dev_warn (&pdev->dev, +"ngpio is greater than %d, defaulting to %d\n" , +ALTERA_GPIO_MAX_NGPIO ,ALTERA_GPIO_MAX_NGPIO ); + altera_gc->mmchip.gc.ngpio =ALTERA_GPIO_MAX_NGPIO ; + } + + 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.owner =THIS_MODULE ; + altera_gc->mmchip.gc.dev = &pdev->dev; + + ret =of_mm_gpiochip_add (node, &altera_gc->mmchip); +if (ret) { +dev_err (&pdev->dev,"Failed adding memory mapped gpiochip\n" ); +return ret; + } + +platform_set_drvdata (pdev, altera_gc); + + altera_gc->mapped_irq =platform_get_irq (pdev,0 ); + +if (altera_gc->mapped_irq <0 ) + goto skip_irq; + +if (of_property_read_u32 (node,"altr,interrupt-type" , ®)) { + ret = -EINVAL ; +dev_err (&pdev->dev, +"altr,interrupt-type value not set in device tree\n" ); + goto teardown; + } + altera_gc->interrupt_trigger = reg; + + ret =gpiochip_irqchip_add (&altera_gc->mmchip.gc, &altera_irq_chip,0 , + handle_simple_irq,IRQ_TYPE_NONE ); + +if (ret) { +dev_info (&pdev->dev,"could not add irqchip\n" ); +return ret; + } + +gpiochip_set_chained_irqchip (&altera_gc->mmchip.gc, + &altera_irq_chip, + altera_gc->mapped_irq, + altera_gc->interrupt_trigger ==IRQ_TYPE_LEVEL_HIGH ? + altera_gpio_irq_leveL_high_handler : + altera_gpio_irq_edge_handler); + +skip_irq: +return 0 ; +teardown: +pr_err ("%s: registration failed with status %d\n" , + node->full_name, ret); + +return ret; +} + +static int altera_gpio_remove (struct platform_device *pdev) +{ +struct altera_gpio_chip *altera_gc =platform_get_drvdata (pdev); + +gpiochip_remove (&altera_gc->mmchip.gc); + +irq_set_handler_data (altera_gc->mapped_irq,NULL ); +irq_set_chained_handler (altera_gc->mapped_irq,NULL ); +return -EIO ; +} +
drivers/gpio/gpio-altera.c line 384
Quoted 10 lines
drivers/gpio/gpio-altera.c new file +10
-0+static const struct of_device_id altera_gpio_of_match[] = { + { .compatible ="altr,pio-1.0" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, altera_gpio_of_match); + +static struct platform_driver altera_gpio_driver = { + .driver = { + .name ="altera_gpio" , + .owner =THIS_MODULE ,
No need to set this here, platform_driver_register will take care of it.
Quoted 30 lines
drivers/gpio/gpio-altera.c new file +21
-0+ .of_match_table = of_match_ptr(altera_gpio_of_match), + }, + .probe = altera_gpio_probe, + .remove = altera_gpio_remove, +}; + +static int __init altera_gpio_init (void ) +{ +return platform_driver_register (&altera_gpio_driver); +} +subsys_initcall (altera_gpio_init); + +static void __exit altera_gpio_exit(void) +{ +platform_driver_unregister (&altera_gpio_driver); +} +module_exit (altera_gpio_exit); + +MODULE_AUTHOR ("Tien Hock Loh <[email protected]>" ); +MODULE_DESCRIPTION ("Altera GPIO driver" ); +MODULE_LICENSE ("GPL" );Signature · 7 lines
1.7.11.GIT -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v9 2/2] drivers/gpio: Altera soft IP GPIO driver
Quoted 10 lines · Tobias Klauser
On 2015-01-06 at 03:19:33 +0100, [email protected] <[email protected]> wrote:
[...]Quoted 8 lines
drivers/gpio/Kconfig +0
-0@@ -156,6 +156,14 @@ config GPIO_DWAPB Say Y or M here to build support for the Synopsys DesignWare APB GPIO block.
Quoted 12 lines
drivers/gpio/Kconfig config GPIO_DWAPB · line 165
Quoted 7 lines
drivers/gpio/Kconfig +7
-0+config GPIO_ALTERA + tristate "Altera GPIO" + depends on OF_GPIO + help + Say Y or M here to build support for the Altera PIO device. + + If driver is built as a module it will be called gpio-altera.Indentation looks odd. The tristate, depends and help lines should be indented by a tab and the help text should be indented by a tab followed by two spaces.
Yeah I didn't notice this. I'll fix it.
Quoted 13 lines
Quoted 6 lines
drivers/gpio/Kconfig +1
-0+ config GPIO_IT8761E tristate "IT8761E GPIO support" depends on X86 # unconditional access to IO space.drivers/gpio/Makefile +0
-0[...]
Quoted 5 lines
drivers/gpio/gpio-altera.c new file +0
-0[...]
Quoted 15 lines
drivers/gpio/gpio-altera.c line 297
Quoted 13 lines
drivers/gpio/gpio-altera.c new file +13
-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; + + altera_gc =devm_kzalloc (&pdev->dev,sizeof (*altera_gc),GFP_KERNEL ); +if (!altera_gc) +return -ENOMEM ; + +spin_lock_init (&altera_gc->gpio_lock); + + id = pdev->id;id is assigned but never used.
I'll remove this.
Quoted 7 lines
drivers/gpio/gpio-altera.c line 300
Quoted 4 lines
drivers/gpio/gpio-altera.c new file +3
-0+ +if (of_property_read_u32 (node,"altr,ngpio" , ®)) +/*By default assume full GPIO controller*/ Spaces missing after /* and before */
Quoted 7 lines
drivers/gpio/gpio-altera.c line 305
Quoted 5 lines
drivers/gpio/gpio-altera.c new file +5
-0+ altera_gc->mmchip.gc.ngpio =ALTERA_GPIO_MAX_NGPIO ; + else + altera_gc->mmchip.gc.ngpio = reg; + +if (altera_gc->mmchip.gc.ngpio >32 ) {Why the magic number 32 here? Better use
ALTERA_GPIO_MAX_NGPIOas well.
Noted.
Quoted 74 lines
Quoted 74 lines
drivers/gpio/gpio-altera.c new file +73
-0+dev_warn (&pdev->dev, +"ngpio is greater than %d, defaulting to %d\n" , +ALTERA_GPIO_MAX_NGPIO ,ALTERA_GPIO_MAX_NGPIO ); + altera_gc->mmchip.gc.ngpio =ALTERA_GPIO_MAX_NGPIO ; + } + + 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.owner =THIS_MODULE ; + altera_gc->mmchip.gc.dev = &pdev->dev; + + ret =of_mm_gpiochip_add (node, &altera_gc->mmchip); +if (ret) { +dev_err (&pdev->dev,"Failed adding memory mapped gpiochip\n" ); +return ret; + } + +platform_set_drvdata (pdev, altera_gc); + + altera_gc->mapped_irq =platform_get_irq (pdev,0 ); + +if (altera_gc->mapped_irq <0 ) + goto skip_irq; + +if (of_property_read_u32 (node,"altr,interrupt-type" , ®)) { + ret = -EINVAL ; +dev_err (&pdev->dev, +"altr,interrupt-type value not set in device tree\n" ); + goto teardown; + } + altera_gc->interrupt_trigger = reg; + + ret =gpiochip_irqchip_add (&altera_gc->mmchip.gc, &altera_irq_chip,0 , + handle_simple_irq,IRQ_TYPE_NONE ); + +if (ret) { +dev_info (&pdev->dev,"could not add irqchip\n" ); +return ret; + } + +gpiochip_set_chained_irqchip (&altera_gc->mmchip.gc, + &altera_irq_chip, + altera_gc->mapped_irq, + altera_gc->interrupt_trigger ==IRQ_TYPE_LEVEL_HIGH ? + altera_gpio_irq_leveL_high_handler : + altera_gpio_irq_edge_handler); + +skip_irq: +return 0 ; +teardown: +pr_err ("%s: registration failed with status %d\n" , + node->full_name, ret); + +return ret; +} + +static int altera_gpio_remove (struct platform_device *pdev) +{ +struct altera_gpio_chip *altera_gc =platform_get_drvdata (pdev); + +gpiochip_remove (&altera_gc->mmchip.gc); + +irq_set_handler_data (altera_gc->mapped_irq,NULL ); +irq_set_chained_handler (altera_gc->mapped_irq,NULL ); +return -EIO ; +} + +static const struct of_device_id altera_gpio_of_match[] = { + { .compatible ="altr,pio-1.0" , }, + {}, +};
Quoted 9 lines
drivers/gpio/gpio-altera.c line 384
Quoted 6 lines
drivers/gpio/gpio-altera.c new file +6
-0+MODULE_DEVICE_TABLE (of, altera_gpio_of_match); + +static struct platform_driver altera_gpio_driver = { + .driver = { + .name ="altera_gpio" , + .owner =THIS_MODULE ,No need to set this here,
platform_driver_registerwill take care of it.
Noted.
Quoted 24 lines
Quoted 24 lines
drivers/gpio/gpio-altera.c new file +21
-1+ .of_match_table = of_match_ptr(altera_gpio_of_match), + }, + .probe = altera_gpio_probe, + .remove = altera_gpio_remove, +}; + +static int __init altera_gpio_init (void ) +{ +return platform_driver_register (&altera_gpio_driver); +} +subsys_initcall (altera_gpio_init); + +static void __exit altera_gpio_exit(void) +{ +platform_driver_unregister (&altera_gpio_driver); +} +module_exit (altera_gpio_exit); + +MODULE_AUTHOR ("Tien Hock Loh <[email protected]>" ); +MODULE_DESCRIPTION ("Altera GPIO driver" ); +MODULE_LICENSE ("GPL" ); --1.7.11.GIT
Quoted 6 lines
Quoted 6 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Regards,
Tien Hock Loh
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html