pinctrl: meson: add support for GPIO IRQs
Subsystems (5)
v7 cover pinctrl: meson: add support for GPIO IRQs
This patch series is partially based on a series Jerome Brunet submitted about half a year ago. Due to open questions this series never made it to mainline, see https://patchwork.kernel.org/patch/9384431/
This new attempt uses GPIOLIB_IRQCHIP resulting in less needed code.
The series was successfully tested on a Odroid-C2.
Changes in v2:
- separate the GPIO IRQ controller from the pinctrl driver
- minor improvements to the GPIO IRQ controller
Changes in v3:
- replace the request_irq based allocation of parent irq's with chained irq handling, this also fixes the spurious interrupts issue and allows to remove the workaround code.
Last but not least the parent irq's are no longer visible in /proc/interrupts.
- minor improvements to the GPIO IRQ controller
Changes in v4:
- separate the gpio-independent interrupt controller part and make it a driver under drivers/irqchip
Changes in v5:
- smaller changes based on review comments
- split DT patches per ARM / ARM64
Changes in v6:
- based on suggestion by Rob Herring: rename DT property parent-interrupts to interrupts
Changes in v7:
- remove patch 1 as it was applied to the pinctrl tree already
- add patch 5 as prerequisite for reworked patch 6
- remove IRQ_TYPE_EDGE_BOTH support from patch 6
Heiner Kallweit (7):
irqchip: add Amlogic Meson GPIO irqchip driver
dt-bindings: add Amlogic Meson GPIO interrupt-controller DT binding documentation
ARM: dts: meson: add GPIO interrupt-controller support
ARM64: dts: meson: add GPIO interrupt-controller support
gpiolib: export gpiochip_irq_reqres and gpiochip_irq_relres
pinctrl: meson: add support for GPIO interrupts
pinctrl: meson: update DT binding documentation
ARM: dts: meson: mark gpio controllers as interrupt controllers
ARM64: dts: meson: mark gpio controllers as interrupt controllers
.../amlogic,meson-gpio-intc.txt | 26 ++
.../devicetree/bindings/pinctrl/meson,pinctrl.txt | 4 + arch/arm/boot/dts/meson8.dtsi | 12 + arch/arm/boot/dts/meson8b.dtsi | 12 + arch/arm64/boot/dts/amlogic/meson-gx.dtsi | 8 + arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 4 + arch/arm64/boot/dts/amlogic/meson-gxl.dtsi | 4 + drivers/gpio/gpiolib.c | 6 +- drivers/irqchip/Kconfig | 5 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-meson-gpio.c | 295 +++++++++++++++++++++ drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/meson/pinctrl-meson.c | 176 +++++++++++- include/linux/gpio/driver.h | 3 + 14 files changed, 554 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txt create mode 100644 drivers/irqchip/irq-meson-gpio.c
Signature · 1 line
2.13.1
PATCH v7 1/9 irqchip: add Amlogic Meson GPIO irqchip driver
Add a driver supporting the GPIO interrupt controller on certain Amlogic meson SoC's.
---
v5:
- changed Kconfig entry based on Neil's suggestion
- added authors
- extended explanation why 2 * n hwirqs are used v6:
- change DT property parent-interrupts to interrupts v7:
- no changes
--- drivers/irqchip/Kconfig | 5 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-meson-gpio.c | 295 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 drivers/irqchip/irq-meson-gpio.c
drivers/irqchip/Kconfig +5 -0
@@ -301,3 +301,8 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config MESON_GPIO_INTC + bool + depends on ARCH_MESON + default y
drivers/irqchip/Makefile +1 -0
@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_MESON_GPIO_INTC) += irq-meson-gpio.o
drivers/irqchip/irq-meson-gpio.c new file +295 -0
295 lines not on this page · raw message
Signature · 1 line
2.13.1
Jerome Brunet
reviewerPATCH v7 1/9 irqchip: add Amlogic Meson GPIO irqchip driver
Quoted 77 lines · Heiner Kallweit
Add a driver supporting the GPIO interrupt controller on certain Amlogic meson SoC's.
Signed-off-by Heiner Kallweit <[email protected]>---
v5:
- changedKconfigentry based on Neil's suggestion
- added authors
- extended explanation why 2 * n hwirqs are used v6:
- change DT property parent-interrupts to interrupts v7:
- no changes
---?drivers/irqchip/Kconfig??????????|???5 + ?drivers/irqchip/Makefile?????????|???1 + ?drivers/irqchip/irq-meson-gpio.c | 295+++++++++++++++++++++++++++++++++++++++
?3 files changed, 301 insertions(+)
?create mode 100644drivers/irqchip/irq-meson-gpio.cdrivers/irqchip/Kconfig +0
-0@@ -301,3 +301,8 @@ config QCOM_IRQ_COMBINER? help
? ??Say yes here to add support for the IRQ combiner devices embedded
? ??in Qualcomm Technologies chips.drivers/irqchip/Kconfig +5
-0+ +config MESON_GPIO_INTC + bool + depends on ARCH_MESON + default ydrivers/irqchip/Makefile +0
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o
?obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o
?obj-$(CONFIG_STM32_EXTI)? += irq-stm32-exti.o
?obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.odrivers/irqchip/Makefile +1
-0+obj-$(CONFIG_MESON_GPIO_INTC) += irq-meson-gpio.odrivers/irqchip/irq-meson- renamed from drivers/irqchip/irq-meson-gpio.c +0
-0
gpio.c
new file mode 100644
index 00000000..925d00c2drivers/irqchip/irq-meson-gpio.c new file +26
-0@@ -0,0 +1,295 @@ +/* +* Amlogic Meson GPIO IRQ chip driver +* +* Copyright (c) 2015 Endless Mobile, Inc. +* Author: Carlo Caione <[email protected]> +* Copyright (c) 2016 BayLibre, SAS. +* Author: Jerome Brunet <[email protected]> +* Copyright (c) 2017 Heiner Kallweit <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +*/ + +#include <linux/device.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/regmap.h> + +#define REG_EDGE_POL 0x00 +#define REG_PIN_03_SEL 0x04 +#define REG_PIN_47_SEL 0x08
drivers/irqchip/irq-meson-gpio.c line 36
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+#define REG_FILTER_SEL 0x0c + +#define REG_EDGE_POL_MASK (x) (BIT(x) | BIT(16 + (x))) +#define REG_EDGE_POL_EDGE (x) BIT(x) +#define REG_EDGE_POL_LOW (x) BIT(16 + (x)) + +#define MAX_PARENT_IRQ_NUM 8 + +/* maximum number of GPIO IRQs on supported platforms */ +#define MAX_NUM_GPIO_IRQ 133
Comment on V6 still applies here. 133 being the max on gxbb does not make it the max on the other supported chipset.
Review from october suggested to put this value in DT.
drivers/irqchip/irq-meson-gpio.c line 45
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c new file +9
-0+ +/* +* In case of IRQ_TYPE_EDGE_BOTH we need two parent interrupts, one for each +* edge. That's due to HW constraints. +* We use format 2 * GPIO_HWIRQ +(0|1) for the hwirq, so we can have one +* GPIO_HWIRQ twice and derive the GPIO_HWIRQ from hwirq by shifting hwirq +* one bit to the right. +*/ +#define NUM_GPIO_HWIRQ (2 * MAX_NUM_GPIO_IRQ)
????
Quoted 108 lines
drivers/irqchip/irq-meson-gpio.c new file +61
-0+ +struct meson_irq_slot { +unsigned int irq; +unsigned int owner; +}; + +struct meson_data { +struct regmap *regmap; +struct meson_irq_slot slots[MAX_PARENT_IRQ_NUM ]; +unsigned int num_slots; +struct mutex lock; +}; + +static int meson_alloc_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i, slot = -ENOSPC ; + +mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots && slot <0 ; i++) +if (!md->slots[i].owner) { + md->slots[i].owner = virq; + slot = i; + } + +mutex_unlock (&md->lock); + +return slot; +} + +static void meson_free_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i; + +mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots; i++) +if (md->slots[i].owner == virq) { + md->slots[i].owner =0 ; +break ; + } + +mutex_unlock (&md->lock); +} + +static int meson_find_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i, slot = -EINVAL ; + +mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots && slot <0 ; i++) +if (md->slots[i].owner == virq) + slot = i; + +mutex_unlock (&md->lock); + +return slot; +} + +static void meson_set_hwirq(struct meson_data *md, int idx, unsigned inthwirq)
drivers/irqchip/irq-meson-gpio.c new file +46
-0+{ +int reg = idx >3 ?REG_PIN_47_SEL :REG_PIN_03_SEL ; +int shift =8 * (idx %4 ); + +regmap_update_bits (md->regmap, reg,0xff << shift, + ???hwirq << shift); +} + +static void meson_irq_set_hwirq (struct irq_data *data,unsigned int hwirq) +{ +struct meson_data *md = data->domain->host_data; +int slot =meson_find_irq_slot (md, data->irq); + +if (slot >=0 ) +meson_set_hwirq (md, slot, hwirq); +} + +static int meson_irq_set_type (struct irq_data *data,unsigned int type) +{ +struct meson_data *md = data->domain->host_data; +int slot; +unsigned int val =0 ; + +if (type ==IRQ_TYPE_EDGE_BOTH ) +return -EINVAL ; + + slot =meson_find_irq_slot (md, data->irq); +if (slot <0 ) +return slot; + +if (type &IRQ_TYPE_EDGE_BOTH ) + val |=REG_EDGE_POL_EDGE (slot); + +if (type & (IRQ_TYPE_LEVEL_LOW |IRQ_TYPE_EDGE_FALLING )) + val |=REG_EDGE_POL_LOW (slot); + +regmap_update_bits (md->regmap,REG_EDGE_POL , + ???REG_EDGE_POL_MASK(slot), val); + +if (type &IRQ_TYPE_EDGE_BOTH ) + val =IRQ_TYPE_EDGE_RISING ; +else + val =IRQ_TYPE_LEVEL_HIGH ; + +return irq_chip_set_type_parent (data, val); +}
drivers/irqchip/irq-meson-gpio.c line 162
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+ +static unsigned int meson_irq_startup (struct irq_data *data) +{ +irq_chip_unmask_parent (data); +/* +?* An extra bit was added to allow having the same gpio hwirq twice +?* for handling IRQ_TYPE_EDGE_BOTH. Remove this bit to get the +?* gpio hwirq. +?*/ +meson_irq_set_hwirq (data, data->hwirq >>1 );
Comments from v6 still applies here, and this has nothing to do with the so- called percentage of niceness - whatever this means.
This is an interrupt controller, a critical part of the system. It has be correct.
Multiplying the number of IRQ lines and so changing the interface is not correct.
DT is OS independent, property should not be os-specific, let alone driver- hacked specific.
Interfaces, including DT, are important. These are supposed to be stable. We don't to change the irq numbers in every dts because "yeahhh we found another way!"
So yes, the corner cases should be covered, what drives you is not the matter here. If you have a critical need for this, then feel free to apply the patch to your kernel, no one is stopping you. If it goes upstream, people should be able to understand it and trust it, identified corner cases should be covered.
Quoted 135 lines
drivers/irqchip/irq-meson-gpio.c new file +71
-0+ +return 0 ; +} + +static void meson_irq_shutdown (struct irq_data *data) +{ +meson_irq_set_hwirq (data,0xff ); +irq_chip_mask_parent (data); +} + +static struct irq_chip meson_irq_chip = { + .name ="meson_gpio_intc" , + .irq_set_type = meson_irq_set_type, + .irq_eoi = irq_chip_eoi_parent, + .irq_mask = irq_chip_mask_parent, + .irq_unmask = irq_chip_unmask_parent, + .irq_startup = meson_irq_startup, + .irq_shutdown = meson_irq_shutdown, + .irq_set_affinity = irq_chip_set_affinity_parent, +}; + +static int meson_irq_alloc (struct irq_domain *d,unsigned int virq, + ???unsigned int nr_irqs, void *data) +{ +struct irq_fwspec parent_fwspec, *fwspec = data; +struct meson_data *md = d->host_data; +irq_hw_number_t hwirq; +int ret, slot; + + slot =meson_alloc_irq_slot (md, virq); +if (slot <0 ) +return slot; + + hwirq = fwspec->param[0 ]; +irq_domain_set_hwirq_and_chip (d, virq, hwirq, &meson_irq_chip,NULL ); + + parent_fwspec.fwnode = d->parent->fwnode; + parent_fwspec.param_count =3 ; + parent_fwspec.param[0 ] =0 ;/* SPI */ + parent_fwspec.param[1 ] = md->slots[slot].irq; + parent_fwspec.param[2 ] =IRQ_TYPE_NONE ; + + ret =irq_domain_alloc_irqs_parent (d, virq, nr_irqs, &parent_fwspec); +if (ret) +meson_free_irq_slot (md, virq); + +return ret; +} + +static void meson_irq_free (struct irq_domain *d,unsigned int virq, + ???unsigned int nr_irqs) +{ +struct meson_data *md = d->host_data; + +irq_domain_free_irqs_common (d, virq, nr_irqs); +meson_free_irq_slot (md, virq); +} + +static const struct irq_domain_ops meson_irq_ops = { + .alloc = meson_irq_alloc, + .free = meson_irq_free, + .xlate = irq_domain_xlate_twocell, +}; + +static int meson_get_irqs (struct meson_data *md,struct device_node *node) +{ +int ret, i; +u32 irq; + +for (i =0 ; i <MAX_PARENT_IRQ_NUM ; i++) { + ret = of_property_read_u32_index(node, "interrupts", i,&irq);
drivers/irqchip/irq-meson-gpio.c new file +62
-0+if (ret) +break ; + md->slots[i].irq = irq; + } + + md->num_slots = i; + +return i ?0 : -EINVAL ; +} + +static const struct regmap_config meson_regmap_config = { + .reg_bits???????= 32, + .reg_stride?????= 4, + .val_bits???????= 32, + .max_register =REG_FILTER_SEL , +}; + +static int __init meson_gpio_irq_init (struct device_node *node, + ??????struct device_node *parent) +{ +struct irq_domain *meson_irq_domain, *parent_domain; +struct meson_data *md; +void __iomem *io_base; +int ret; + + md =kzalloc (sizeof (*md),GFP_KERNEL ); +if (!md) +return -ENOMEM ; + +mutex_init (&md->lock); + + io_base =of_iomap (node,0 ); +if (!io_base) +return -EINVAL ; + + md->regmap =regmap_init_mmio (NULL , io_base, &meson_regmap_config); +if (IS_ERR (md->regmap)) +return PTR_ERR (md->regmap); + +/* initialize to IRQ_TYPE_LEVEL_HIGH */ +regmap_write (md->regmap,REG_EDGE_POL ,0 ); +/* disable all GPIO interrupt sources */ +regmap_write (md->regmap,REG_PIN_03_SEL ,0xffffffff ); +regmap_write (md->regmap,REG_PIN_47_SEL ,0xffffffff ); +/* disable filtering */ +regmap_write (md->regmap,REG_FILTER_SEL ,0 ); + + ret =meson_get_irqs (md, node); +if (ret) +return ret; + + parent_domain =irq_find_host (parent); +if (!parent_domain) +return -ENXIO ; + + meson_irq_domain =irq_domain_add_hierarchy (parent_domain,0 , + ????NUM_GPIO_HWIRQ, node, + ????&meson_irq_ops, md); +return meson_irq_domain ?0 : -EINVAL ; +} + +IRQCHIP_DECLARE(meson_gpio_irq, "amlogic,meson-gpio-intc",
meson_gpio_irq_init);
PATCH v7 1/9 irqchip: add Amlogic Meson GPIO irqchip driver
Am 12.06.2017 um 10:54 schrieb Jerome Brunet:
Quoted 83 lines · Heiner Kallweit
Quoted 82 lines
Add a driver supporting the GPIO interrupt controller on certain Amlogic meson SoC's.
Signed-off-by Heiner Kallweit <[email protected]>---
v5:
- changedKconfigentry based on Neil's suggestion
- added authors
- extended explanation why 2 * n hwirqs are used v6:
- change DT property parent-interrupts to interrupts v7:
- no changes--- drivers/irqchip/Kconfig | 5 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-meson-gpio.c | 295 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 drivers/irqchip/irq-meson-gpio.cdrivers/irqchip/Kconfig +5
-0@@ -301,3 +301,8 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config MESON_GPIO_INTC + bool + depends on ARCH_MESON + default ydrivers/irqchip/Makefile +0
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o
obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o
obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o
obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.odrivers/irqchip/Makefile +1
-0+obj-$(CONFIG_MESON_GPIO_INTC) += irq-meson-gpio.odrivers/irqchip/irq-meson- renamed from drivers/irqchip/irq-meson-gpio.c +0
-0
gpio.c
new file mode 100644
index 00000000..925d00c2drivers/irqchip/irq-meson-gpio.c new file +31
-0@@ -0,0 +1,295 @@ +/* +* Amlogic Meson GPIO IRQ chip driver +* +* Copyright (c) 2015 Endless Mobile, Inc. +* Author: Carlo Caione <[email protected]> +* Copyright (c) 2016 BayLibre, SAS. +* Author: Jerome Brunet <[email protected]> +* Copyright (c) 2017 Heiner Kallweit <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +*/ + +#include <linux/device.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/regmap.h> + +#define REG_EDGE_POL 0x00 +#define REG_PIN_03_SEL 0x04 +#define REG_PIN_47_SEL 0x08 +#define REG_FILTER_SEL 0x0c + +#define REG_EDGE_POL_MASK (x) (BIT(x) | BIT(16 + (x))) +#define REG_EDGE_POL_EDGE (x) BIT(x) +#define REG_EDGE_POL_LOW (x) BIT(16 + (x))
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 36
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ +#define MAX_PARENT_IRQ_NUM 8 + +/* maximum number of GPIO IRQs on supported platforms */ +#define MAX_NUM_GPIO_IRQ 133Comment on V6 still applies here. 133 being the max on gxbb does not make it the max on the other supported chipset.
133 is the highest number occurring on any supported chip.
Quoted 2 lines
Review from october suggested to put this value in DT.
I checked few irqchip drivers and none of them gets the number of hwirqs from DT. Most of the time the number of hwirq's is a #define in the driver. Also I don't see which benefit this would provide.
This value is used only to determine the size of the irq mapping array in the irq domain. By using chip-specific values we could save a few bytes in this array. But I think that's not worth the effort of introducing an extra dt parameter.
And using a hwirq greater than the max on the specific chips (if any driver should ever try this) results in: nothing.
Last but not least the dt binding was acked by Rob and if the number of hwirq's should be in the DT I think he would have mentioned this.
Quoted 134 lines
drivers/irqchip/irq-meson-gpio.c line 45
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c new file +9
-0+ +/* +* In case of IRQ_TYPE_EDGE_BOTH we need two parent interrupts, one for each +* edge. That's due to HW constraints. +* We use format 2 * GPIO_HWIRQ +(0|1) for the hwirq, so we can have one +* GPIO_HWIRQ twice and derive the GPIO_HWIRQ from hwirq by shifting hwirq +* one bit to the right. +*/ +#define NUM_GPIO_HWIRQ (2 * MAX_NUM_GPIO_IRQ)????
Quoted 108 lines
drivers/irqchip/irq-meson-gpio.c new file +61
-0+ +struct meson_irq_slot { +unsigned int irq; +unsigned int owner; +}; + +struct meson_data { +struct regmap *regmap; +struct meson_irq_slot slots[MAX_PARENT_IRQ_NUM ]; +unsigned int num_slots; +struct mutex lock; +}; + +static int meson_alloc_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i, slot = -ENOSPC ; + +mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots && slot <0 ; i++) +if (!md->slots[i].owner) { + md->slots[i].owner = virq; + slot = i; + } + +mutex_unlock (&md->lock); + +return slot; +} + +static void meson_free_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i; + +mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots; i++) +if (md->slots[i].owner == virq) { + md->slots[i].owner =0 ; +break ; + } + +mutex_unlock (&md->lock); +} + +static int meson_find_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i, slot = -EINVAL ; + +mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots && slot <0 ; i++) +if (md->slots[i].owner == virq) + slot = i; + +mutex_unlock (&md->lock); + +return slot; +} + +static void meson_set_hwirq(struct meson_data *md, int idx, unsigned inthwirq)
drivers/irqchip/irq-meson-gpio.c new file +46
-0+{ +int reg = idx >3 ?REG_PIN_47_SEL :REG_PIN_03_SEL ; +int shift =8 * (idx %4 ); + +regmap_update_bits (md->regmap, reg,0xff << shift, + hwirq << shift); +} + +static void meson_irq_set_hwirq (struct irq_data *data,unsigned int hwirq) +{ +struct meson_data *md = data->domain->host_data; +int slot =meson_find_irq_slot (md, data->irq); + +if (slot >=0 ) +meson_set_hwirq (md, slot, hwirq); +} + +static int meson_irq_set_type (struct irq_data *data,unsigned int type) +{ +struct meson_data *md = data->domain->host_data; +int slot; +unsigned int val =0 ; + +if (type ==IRQ_TYPE_EDGE_BOTH ) +return -EINVAL ; + + slot =meson_find_irq_slot (md, data->irq); +if (slot <0 ) +return slot; + +if (type &IRQ_TYPE_EDGE_BOTH ) + val |=REG_EDGE_POL_EDGE (slot); + +if (type & (IRQ_TYPE_LEVEL_LOW |IRQ_TYPE_EDGE_FALLING )) + val |=REG_EDGE_POL_LOW (slot); + +regmap_update_bits (md->regmap,REG_EDGE_POL , +REG_EDGE_POL_MASK (slot), val); + +if (type &IRQ_TYPE_EDGE_BOTH ) + val =IRQ_TYPE_EDGE_RISING ; +else + val =IRQ_TYPE_LEVEL_HIGH ; + +return irq_chip_set_type_parent (data, val); +}drivers/irqchip/irq-meson-gpio.c line 162
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+ +static unsigned int meson_irq_startup (struct irq_data *data) +{ +irq_chip_unmask_parent (data); +/* +* An extra bit was added to allow having the same gpio hwirq twice +* for handling IRQ_TYPE_EDGE_BOTH. Remove this bit to get the +* gpio hwirq. +*/ +meson_irq_set_hwirq (data, data->hwirq >>1 );Comments from v6 still applies here, and this has nothing to do with the so- called percentage of niceness - whatever this means.
Quoted 5 lines
This is an interrupt controller, a critical part of the system. It has be correct.
Multiplying the number of IRQ lines and so changing the interface is not correct.
Why changing the interface? Using gpio_hwirq << 1 as irq domain hwirq is the interface. A hwirq in a irq domain is a number, not more and not less. AFAIK there's no pre-defined semantics.
Of course it should be clear what the number means and the interface should not change later.
Quoted 7 lines
DT is OS independent, property should not be os-specific, let alone driver- hacked specific.
Interfaces, including DT, are important. These are supposed to be stable. We don't to change the irq numbers in every dts because "yeahhh we found another way!"
Which DT property are you referring to? There is no irq number in the DT.
Quoted 142 lines
So yes, the corner cases should be covered, what drives you is not the matter here. If you have a critical need for this, then feel free to apply the patch to your kernel, no one is stopping you. If it goes upstream, people should be able to understand it and trust it, identified corner cases should be covered.
Quoted 135 lines
drivers/irqchip/irq-meson-gpio.c new file +71
-0+ +return 0 ; +} + +static void meson_irq_shutdown (struct irq_data *data) +{ +meson_irq_set_hwirq (data,0xff ); +irq_chip_mask_parent (data); +} + +static struct irq_chip meson_irq_chip = { + .name ="meson_gpio_intc" , + .irq_set_type = meson_irq_set_type, + .irq_eoi = irq_chip_eoi_parent, + .irq_mask = irq_chip_mask_parent, + .irq_unmask = irq_chip_unmask_parent, + .irq_startup = meson_irq_startup, + .irq_shutdown = meson_irq_shutdown, + .irq_set_affinity = irq_chip_set_affinity_parent, +}; + +static int meson_irq_alloc (struct irq_domain *d,unsigned int virq, +unsigned int nr_irqs,void *data) +{ +struct irq_fwspec parent_fwspec, *fwspec = data; +struct meson_data *md = d->host_data; +irq_hw_number_t hwirq; +int ret, slot; + + slot =meson_alloc_irq_slot (md, virq); +if (slot <0 ) +return slot; + + hwirq = fwspec->param[0 ]; +irq_domain_set_hwirq_and_chip (d, virq, hwirq, &meson_irq_chip,NULL ); + + parent_fwspec.fwnode = d->parent->fwnode; + parent_fwspec.param_count =3 ; + parent_fwspec.param[0 ] =0 ;/* SPI */ + parent_fwspec.param[1 ] = md->slots[slot].irq; + parent_fwspec.param[2 ] =IRQ_TYPE_NONE ; + + ret =irq_domain_alloc_irqs_parent (d, virq, nr_irqs, &parent_fwspec); +if (ret) +meson_free_irq_slot (md, virq); + +return ret; +} + +static void meson_irq_free (struct irq_domain *d,unsigned int virq, +unsigned int nr_irqs) +{ +struct meson_data *md = d->host_data; + +irq_domain_free_irqs_common (d, virq, nr_irqs); +meson_free_irq_slot (md, virq); +} + +static const struct irq_domain_ops meson_irq_ops = { + .alloc = meson_irq_alloc, + .free = meson_irq_free, + .xlate = irq_domain_xlate_twocell, +}; + +static int meson_get_irqs (struct meson_data *md,struct device_node *node) +{ +int ret, i; +u32 irq; + +for (i =0 ; i <MAX_PARENT_IRQ_NUM ; i++) { + ret = of_property_read_u32_index(node, "interrupts", i,&irq);
drivers/irqchip/irq-meson-gpio.c new file +62
-0+if (ret) +break ; + md->slots[i].irq = irq; + } + + md->num_slots = i; + +return i ?0 : -EINVAL ; +} + +static const struct regmap_config meson_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .max_register =REG_FILTER_SEL , +}; + +static int __init meson_gpio_irq_init (struct device_node *node, +struct device_node *parent) +{ +struct irq_domain *meson_irq_domain, *parent_domain; +struct meson_data *md; +void __iomem *io_base; +int ret; + + md =kzalloc (sizeof (*md),GFP_KERNEL ); +if (!md) +return -ENOMEM ; + +mutex_init (&md->lock); + + io_base =of_iomap (node,0 ); +if (!io_base) +return -EINVAL ; + + md->regmap =regmap_init_mmio (NULL , io_base, &meson_regmap_config); +if (IS_ERR (md->regmap)) +return PTR_ERR (md->regmap); + +/* initialize to IRQ_TYPE_LEVEL_HIGH */ +regmap_write (md->regmap,REG_EDGE_POL ,0 ); +/* disable all GPIO interrupt sources */ +regmap_write (md->regmap,REG_PIN_03_SEL ,0xffffffff ); +regmap_write (md->regmap,REG_PIN_47_SEL ,0xffffffff ); +/* disable filtering */ +regmap_write (md->regmap,REG_FILTER_SEL ,0 ); + + ret =meson_get_irqs (md, node); +if (ret) +return ret; + + parent_domain =irq_find_host (parent); +if (!parent_domain) +return -ENXIO ; + + meson_irq_domain =irq_domain_add_hierarchy (parent_domain,0 , +NUM_GPIO_HWIRQ , node, + &meson_irq_ops, md); +return meson_irq_domain ?0 : -EINVAL ; +} + +IRQCHIP_DECLARE(meson_gpio_irq, "amlogic,meson-gpio-intc",
meson_gpio_irq_init);
PATCH v7 1/9 irqchip: add Amlogic Meson GPIO irqchip driver
In reply to Heiner KallweitQuoted 74 lines · Heiner Kallweit
Add a driver supporting the GPIO interrupt controller on certain Amlogic meson SoC's.
Signed-off-by Heiner Kallweit <[email protected]>---
v5:
- changedKconfigentry based on Neil's suggestion
- added authors
- extended explanation why 2 * n hwirqs are used v6:
- change DT property parent-interrupts to interrupts v7:
- no changes--- drivers/irqchip/Kconfig | 5 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-meson-gpio.c | 295 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 drivers/irqchip/irq-meson-gpio.cdrivers/irqchip/Kconfig +5
-0@@ -301,3 +301,8 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config MESON_GPIO_INTC + bool + depends on ARCH_MESON + default ydrivers/irqchip/Makefile +1
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_MESON_GPIO_INTC) += irq-meson-gpio.odrivers/irqchip/irq-meson-gpio.c new file +26
-0@@ -0,0 +1,295 @@ +/* +* Amlogic Meson GPIO IRQ chip driver +* +* Copyright (c) 2015 Endless Mobile, Inc. +* Author: Carlo Caione <[email protected]> +* Copyright (c) 2016 BayLibre, SAS. +* Author: Jerome Brunet <[email protected]> +* Copyright (c) 2017 Heiner Kallweit <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +*/ + +#include <linux/device.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/regmap.h> + +#define REG_EDGE_POL 0x00 +#define REG_PIN_03_SEL 0x04 +#define REG_PIN_47_SEL 0x08
drivers/irqchip/irq-meson-gpio.c line 36
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+#define REG_FILTER_SEL 0x0c + +#define REG_EDGE_POL_MASK (x) (BIT(x) | BIT(16 + (x))) +#define REG_EDGE_POL_EDGE (x) BIT(x) +#define REG_EDGE_POL_LOW (x) BIT(16 + (x)) + +#define MAX_PARENT_IRQ_NUM 8 + +/* maximum number of GPIO IRQs on supported platforms */ +#define MAX_NUM_GPIO_IRQ 133
Why aren't these values coming from DT? I bet that a future revision of the same HW will double these. Or at least, you could match it on the compatible string.
drivers/irqchip/irq-meson-gpio.c line 43
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +/* +* In case of IRQ_TYPE_EDGE_BOTH we need two parent interrupts, one for each +* edge. That's due to HW constraints. +* We use format 2 * GPIO_HWIRQ +(0|1) for the hwirq, so we can have one +* GPIO_HWIRQ twice and derive the GPIO_HWIRQ from hwirq by shifting hwirq +* one bit to the right.
Please expand on how you expect this to work, specially when a random driver expects a single interrupt.
Quoted 14 lines
drivers/irqchip/irq-meson-gpio.c new file +14
-0+*/ +#define NUM_GPIO_HWIRQ (2 * MAX_NUM_GPIO_IRQ) + +struct meson_irq_slot { +unsigned int irq; +unsigned int owner; +}; + +struct meson_data { +struct regmap *regmap; +struct meson_irq_slot slots[MAX_PARENT_IRQ_NUM ]; +unsigned int num_slots; +struct mutex lock; +};
drivers/irqchip/irq-meson-gpio.c line 67
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+ +static int meson_alloc_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i, slot = -ENOSPC ; + +mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots && slot <0 ; i++) +if (!md->slots[i].owner) { + md->slots[i].owner = virq;
Why do you have to deal with the virq? It'd be more logical to deal with the hwirq. The usual mechanism to reserve a "slot" is to use a bitmap indexed by the hwirq. Why is that not working for you?
Quoted 12 lines
drivers/irqchip/irq-meson-gpio.c new file +12
-0+ slot = i; + } + +mutex_unlock (&md->lock); + +return slot; +} + +static void meson_free_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i; +
drivers/irqchip/irq-meson-gpio.c line 89
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots; i++) +if (md->slots[i].owner == virq) { + md->slots[i].owner =0 ; +break ; + } + +mutex_unlock (&md->lock); +}
These two functions are basically the same...
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ +static int meson_find_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i, slot = -EINVAL ; +
drivers/irqchip/irq-meson-gpio.c line 104
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots && slot <0 ; i++) +if (md->slots[i].owner == virq) + slot = i; + +mutex_unlock (&md->lock); + +return slot; +}
... and could be expressed in terms of this one.
drivers/irqchip/irq-meson-gpio.c line 109
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ +static void meson_set_hwirq (struct meson_data *md,int idx,unsigned int hwirq) +{ +int reg = idx >3 ?REG_PIN_47_SEL :REG_PIN_03_SEL ; +int shift =8 * (idx %4 );
What's this?
Quoted 12 lines
drivers/irqchip/irq-meson-gpio.c new file +12
-0+ +regmap_update_bits (md->regmap, reg,0xff << shift, + hwirq << shift); +} + +static void meson_irq_set_hwirq (struct irq_data *data,unsigned int hwirq) +{ +struct meson_data *md = data->domain->host_data; +int slot =meson_find_irq_slot (md, data->irq); + +if (slot >=0 ) +meson_set_hwirq (md, slot, hwirq);
drivers/irqchip/irq-meson-gpio.c line 131
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+} + +static int meson_irq_set_type (struct irq_data *data,unsigned int type) +{ +struct meson_data *md = data->domain->host_data; +int slot; +unsigned int val =0 ; + +if (type ==IRQ_TYPE_EDGE_BOTH ) +return -EINVAL ;
So you reject EDGE_BOTH? So what's the deal with the beginning of the patch?
drivers/irqchip/irq-meson-gpio.c line 135
Quoted 4 lines
drivers/irqchip/irq-meson-gpio.c new file +4
-0+ + slot =meson_find_irq_slot (md, data->irq); +if (slot <0 ) +return slot;
How can this happen?
Quoted 4 lines
drivers/irqchip/irq-meson-gpio.c new file +4
-0+ +if (type &IRQ_TYPE_EDGE_BOTH ) + val |=REG_EDGE_POL_EDGE (slot); +
drivers/irqchip/irq-meson-gpio.c line 149
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+if (type & (IRQ_TYPE_LEVEL_LOW |IRQ_TYPE_EDGE_FALLING )) + val |=REG_EDGE_POL_LOW (slot); + +regmap_update_bits (md->regmap,REG_EDGE_POL , +REG_EDGE_POL_MASK (slot), val); + +if (type &IRQ_TYPE_EDGE_BOTH ) + val =IRQ_TYPE_EDGE_RISING ; +else + val =IRQ_TYPE_LEVEL_HIGH ;
How does this work? Does this HW have some magic falling->rising and low->high conversion feature? If it doesn't, I cannot see how this can work.
drivers/irqchip/irq-meson-gpio.c line 162
Quoted 13 lines
drivers/irqchip/irq-meson-gpio.c new file +13
-0+ +return irq_chip_set_type_parent (data, val); +} + +static unsigned int meson_irq_startup (struct irq_data *data) +{ +irq_chip_unmask_parent (data); +/* +* An extra bit was added to allow having the same gpio hwirq twice +* for handling IRQ_TYPE_EDGE_BOTH. Remove this bit to get the +* gpio hwirq. +*/ +meson_irq_set_hwirq (data, data->hwirq >>1 );
Again. Do you support EDGE_BOTH or not?
drivers/irqchip/irq-meson-gpio.c line 169
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +return 0 ; +} + +static void meson_irq_shutdown (struct irq_data *data) +{ +meson_irq_set_hwirq (data,0xff );
What's special about 0xff?
Quoted 24 lines
drivers/irqchip/irq-meson-gpio.c new file +24
-0+irq_chip_mask_parent (data); +} + +static struct irq_chip meson_irq_chip = { + .name ="meson_gpio_intc" , + .irq_set_type = meson_irq_set_type, + .irq_eoi = irq_chip_eoi_parent, + .irq_mask = irq_chip_mask_parent, + .irq_unmask = irq_chip_unmask_parent, + .irq_startup = meson_irq_startup, + .irq_shutdown = meson_irq_shutdown, + .irq_set_affinity = irq_chip_set_affinity_parent, +}; + +static int meson_irq_alloc (struct irq_domain *d,unsigned int virq, +unsigned int nr_irqs,void *data) +{ +struct irq_fwspec parent_fwspec, *fwspec = data; +struct meson_data *md = d->host_data; +irq_hw_number_t hwirq; +int ret, slot; + + slot =meson_alloc_irq_slot (md, virq); +if (slot <0 )
drivers/irqchip/irq-meson-gpio.c line 203
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+return slot; + + hwirq = fwspec->param[0 ]; +irq_domain_set_hwirq_and_chip (d, virq, hwirq, &meson_irq_chip,NULL ); + + parent_fwspec.fwnode = d->parent->fwnode; + parent_fwspec.param_count =3 ; + parent_fwspec.param[0 ] =0 ;/* SPI */ + parent_fwspec.param[1 ] = md->slots[slot].irq; + parent_fwspec.param[2 ] =IRQ_TYPE_NONE ;
Hell no. Look at the GIC DT binding: there is no NONE. It is either HIGH, or RISING.
Quoted 74 lines
drivers/irqchip/irq-meson-gpio.c new file +74
-0+ + ret =irq_domain_alloc_irqs_parent (d, virq, nr_irqs, &parent_fwspec); +if (ret) +meson_free_irq_slot (md, virq); + +return ret; +} + +static void meson_irq_free (struct irq_domain *d,unsigned int virq, +unsigned int nr_irqs) +{ +struct meson_data *md = d->host_data; + +irq_domain_free_irqs_common (d, virq, nr_irqs); +meson_free_irq_slot (md, virq); +} + +static const struct irq_domain_ops meson_irq_ops = { + .alloc = meson_irq_alloc, + .free = meson_irq_free, + .xlate = irq_domain_xlate_twocell, +}; + +static int meson_get_irqs (struct meson_data *md,struct device_node *node) +{ +int ret, i; +u32 irq; + +for (i =0 ; i <MAX_PARENT_IRQ_NUM ; i++) { + ret =of_property_read_u32_index (node,"interrupts" , i, &irq); +if (ret) +break ; + md->slots[i].irq = irq; + } + + md->num_slots = i; + +return i ?0 : -EINVAL ; +} + +static const struct regmap_config meson_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .max_register =REG_FILTER_SEL , +}; + +static int __init meson_gpio_irq_init (struct device_node *node, +struct device_node *parent) +{ +struct irq_domain *meson_irq_domain, *parent_domain; +struct meson_data *md; +void __iomem *io_base; +int ret; + + md =kzalloc (sizeof (*md),GFP_KERNEL ); +if (!md) +return -ENOMEM ; + +mutex_init (&md->lock); + + io_base =of_iomap (node,0 ); +if (!io_base) +return -EINVAL ; + + md->regmap =regmap_init_mmio (NULL , io_base, &meson_regmap_config); +if (IS_ERR (md->regmap)) +return PTR_ERR (md->regmap); + +/* initialize to IRQ_TYPE_LEVEL_HIGH */ +regmap_write (md->regmap,REG_EDGE_POL ,0 ); +/* disable all GPIO interrupt sources */ +regmap_write (md->regmap,REG_PIN_03_SEL ,0xffffffff ); +regmap_write (md->regmap,REG_PIN_47_SEL ,0xffffffff );
drivers/irqchip/irq-meson-gpio.c line 287
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+/* disable filtering */ +regmap_write (md->regmap,REG_FILTER_SEL ,0 ); + + ret =meson_get_irqs (md, node); +if (ret) +return ret; + + parent_domain =irq_find_host (parent); +if (!parent_domain) +return -ENXIO ;
Memory leak on all the return paths.
drivers/irqchip/irq-meson-gpio.c line 295
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c new file +8
-0+ + meson_irq_domain =irq_domain_add_hierarchy (parent_domain,0 , +NUM_GPIO_HWIRQ , node, + &meson_irq_ops, md); +return meson_irq_domain ?0 : -EINVAL ; +} + +IRQCHIP_DECLARE (meson_gpio_irq,"amlogic,meson-gpio-intc" , meson_gpio_irq_init);
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH v7 1/9 irqchip: add Amlogic Meson GPIO irqchip driver
Am 13.06.2017 um 10:31 schrieb Marc Zyngier:
Quoted 81 lines · Heiner Kallweit
Quoted 80 lines
Add a driver supporting the GPIO interrupt controller on certain Amlogic meson SoC's.
Signed-off-by Heiner Kallweit <[email protected]>---
v5:
- changedKconfigentry based on Neil's suggestion
- added authors
- extended explanation why 2 * n hwirqs are used v6:
- change DT property parent-interrupts to interrupts v7:
- no changes--- drivers/irqchip/Kconfig | 5 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-meson-gpio.c | 295 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 drivers/irqchip/irq-meson-gpio.cdrivers/irqchip/Kconfig +5
-0@@ -301,3 +301,8 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config MESON_GPIO_INTC + bool + depends on ARCH_MESON + default ydrivers/irqchip/Makefile +1
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_MESON_GPIO_INTC) += irq-meson-gpio.odrivers/irqchip/irq-meson-gpio.c new file +32
-0@@ -0,0 +1,295 @@ +/* +* Amlogic Meson GPIO IRQ chip driver +* +* Copyright (c) 2015 Endless Mobile, Inc. +* Author: Carlo Caione <[email protected]> +* Copyright (c) 2016 BayLibre, SAS. +* Author: Jerome Brunet <[email protected]> +* Copyright (c) 2017 Heiner Kallweit <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +*/ + +#include <linux/device.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/regmap.h> + +#define REG_EDGE_POL 0x00 +#define REG_PIN_03_SEL 0x04 +#define REG_PIN_47_SEL 0x08 +#define REG_FILTER_SEL 0x0c + +#define REG_EDGE_POL_MASK (x) (BIT(x) | BIT(16 + (x))) +#define REG_EDGE_POL_EDGE (x) BIT(x) +#define REG_EDGE_POL_LOW (x) BIT(16 + (x)) +
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 36
Quoted 4 lines
drivers/irqchip/irq-meson-gpio.c new file +4
-0+#define MAX_PARENT_IRQ_NUM 8 + +/* maximum number of GPIO IRQs on supported platforms */ +#define MAX_NUM_GPIO_IRQ 133Why aren't these values coming from DT? I bet that a future revision of the same HW will double these. Or at least, you could match it on the compatible string.
Alternatively this value can be set to 255. The GPIO source is an 8 bit value with 255 being reserved for "no interrupt source assigned". This way we cover all chips based on the same IP.
I think what we could gain by introducing an additional DT property (saving a few bytes in the irqdomain mapping table) isn't worth the effort.
Quoted 11 lines
drivers/irqchip/irq-meson-gpio.c line 43
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +/* +* In case of IRQ_TYPE_EDGE_BOTH we need two parent interrupts, one for each +* edge. That's due to HW constraints. +* We use format 2 * GPIO_HWIRQ +(0|1) for the hwirq, so we can have one +* GPIO_HWIRQ twice and derive the GPIO_HWIRQ from hwirq by shifting hwirq +* one bit to the right. Please expand on how you expect this to work, specially when a random driver expects a single interrupt.
The gpio interrupt controller in this chip doesn't have native support for IRQ_TYPE_EDGE_BOTH. As a workaround we would need to assign the same gpio to two parent interrupts, one for each edge.
There's still no solution to achieve this in a way everybody is happy with. Therefore this feature isn't part of this patch set.
However, to be prepared to include this feature later, the interface between pinctrl/gpio and irqchip driver should (IMHO) cater for it already. Else we may have to touch the irqchip driver later and change the interface what I would like to avoid.
If a driver just needs one (parent) interrupt, it can request hwirq (2 * GPIO_HWIRQ) only. There's no issue with that.
Quoted 20 lines
Quoted 20 lines
drivers/irqchip/irq-meson-gpio.c new file +20
-0+*/ +#define NUM_GPIO_HWIRQ (2 * MAX_NUM_GPIO_IRQ) + +struct meson_irq_slot { +unsigned int irq; +unsigned int owner; +}; + +struct meson_data { +struct regmap *regmap; +struct meson_irq_slot slots[MAX_PARENT_IRQ_NUM ]; +unsigned int num_slots; +struct mutex lock; +}; + +static int meson_alloc_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i, slot = -ENOSPC ; + +mutex_lock (&md->lock);
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 67
Quoted 4 lines
drivers/irqchip/irq-meson-gpio.c new file +4
-0+ +for (i =0 ; i < md->num_slots && slot <0 ; i++) +if (!md->slots[i].owner) { + md->slots[i].owner = virq;Why do you have to deal with the virq? It'd be more logical to deal with the hwirq. The usual mechanism to reserve a "slot" is to use a bitmap indexed by the hwirq. Why is that not working for you?
Using the hwirq as owner should also be possible. Will consider this.
A slot has two members, the owner and a the associated parent irq number. Of course we could split this into a slot bitmap + an array with parent irq's indexed by slot number. Would you prefer this?
Quoted 43 lines
Quoted 12 lines
drivers/irqchip/irq-meson-gpio.c new file +12
-0+ slot = i; + } + +mutex_unlock (&md->lock); + +return slot; +} + +static void meson_free_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i; +drivers/irqchip/irq-meson-gpio.c line 89
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots; i++) +if (md->slots[i].owner == virq) { + md->slots[i].owner =0 ; +break ; + } + +mutex_unlock (&md->lock); +}These two functions are basically the same...
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ +static int meson_find_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i, slot = -EINVAL ; +drivers/irqchip/irq-meson-gpio.c line 104
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots && slot <0 ; i++) +if (md->slots[i].owner == virq) + slot = i; + +mutex_unlock (&md->lock); + +return slot; +}... and could be expressed in terms of this one.
Quoted 8 lines
drivers/irqchip/irq-meson-gpio.c line 109
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ +static void meson_set_hwirq (struct meson_data *md,int idx,unsigned int hwirq) +{ +int reg = idx >3 ?REG_PIN_47_SEL :REG_PIN_03_SEL ; +int shift =8 * (idx %4 );What's this?
GPIO source for the eight parent irq's can be configured using two 32-bit registers with four 8-bit fields each.
Quoted 16 lines
Quoted 16 lines
drivers/irqchip/irq-meson-gpio.c new file +16
-0+ +regmap_update_bits (md->regmap, reg,0xff << shift, + hwirq << shift); +} + +static void meson_irq_set_hwirq (struct irq_data *data,unsigned int hwirq) +{ +struct meson_data *md = data->domain->host_data; +int slot =meson_find_irq_slot (md, data->irq); + +if (slot >=0 ) +meson_set_hwirq (md, slot, hwirq); +} + +static int meson_irq_set_type (struct irq_data *data,unsigned int type) +{
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 131
Quoted 6 lines
drivers/irqchip/irq-meson-gpio.c new file +6
-0+struct meson_data *md = data->domain->host_data; +int slot; +unsigned int val =0 ; + +if (type ==IRQ_TYPE_EDGE_BOTH ) +return -EINVAL ;So you reject
EDGE_BOTH? So what's the deal with the beginning of the patch?
We reject it in the initial version of the patch set as there's no consensus yet on some details of the workaround needed for EDGE_BOTH support.
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c line 135
Quoted 4 lines
drivers/irqchip/irq-meson-gpio.c new file +4
-0+ + slot =meson_find_irq_slot (md, data->irq); +if (slot <0 ) +return slot;How can this happen?
I see no way how this can happen. It was basically added to be on the safe side and fail nicely in case I miss a scenario which could cause this to fail. I can remove the check.
Quoted 9 lines
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c new file +9
-0+ +if (type &IRQ_TYPE_EDGE_BOTH ) + val |=REG_EDGE_POL_EDGE (slot); + +if (type & (IRQ_TYPE_LEVEL_LOW |IRQ_TYPE_EDGE_FALLING )) + val |=REG_EDGE_POL_LOW (slot); + +regmap_update_bits (md->regmap,REG_EDGE_POL , +REG_EDGE_POL_MASK (slot), val);
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 149
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ +if (type &IRQ_TYPE_EDGE_BOTH ) + val =IRQ_TYPE_EDGE_RISING ; +else + val =IRQ_TYPE_LEVEL_HIGH ;How does this work? Does this HW have some magic
falling->risingandlow->highconversion feature? If it doesn't, I cannot see how this can work.
Exactly, HW has a programmable polarity inverter.
Quoted 7 lines
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +return irq_chip_set_type_parent (data, val); +} + +static unsigned int meson_irq_startup (struct irq_data *data) +{ +irq_chip_unmask_parent (data);
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 162
Quoted 6 lines
drivers/irqchip/irq-meson-gpio.c new file +6
-0+/* +* An extra bit was added to allow having the same gpio hwirq twice +* for handling IRQ_TYPE_EDGE_BOTH. Remove this bit to get the +* gpio hwirq. +*/ +meson_irq_set_hwirq (data, data->hwirq >>1 );Again. Do you support
EDGE_BOTHor not?
Not yet ..
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c line 169
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +return 0 ; +} + +static void meson_irq_shutdown (struct irq_data *data) +{ +meson_irq_set_hwirq (data,0xff );What's special about
0xff?
0xff is the reserved value indicating the no GPIO source is assigned to the parent irq.
Quoted 29 lines
Quoted 29 lines
drivers/irqchip/irq-meson-gpio.c new file +29
-0+irq_chip_mask_parent (data); +} + +static struct irq_chip meson_irq_chip = { + .name ="meson_gpio_intc" , + .irq_set_type = meson_irq_set_type, + .irq_eoi = irq_chip_eoi_parent, + .irq_mask = irq_chip_mask_parent, + .irq_unmask = irq_chip_unmask_parent, + .irq_startup = meson_irq_startup, + .irq_shutdown = meson_irq_shutdown, + .irq_set_affinity = irq_chip_set_affinity_parent, +}; + +static int meson_irq_alloc (struct irq_domain *d,unsigned int virq, +unsigned int nr_irqs,void *data) +{ +struct irq_fwspec parent_fwspec, *fwspec = data; +struct meson_data *md = d->host_data; +irq_hw_number_t hwirq; +int ret, slot; + + slot =meson_alloc_irq_slot (md, virq); +if (slot <0 ) +return slot; + + hwirq = fwspec->param[0 ]; +irq_domain_set_hwirq_and_chip (d, virq, hwirq, &meson_irq_chip,NULL ); +
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 203
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ parent_fwspec.fwnode = d->parent->fwnode; + parent_fwspec.param_count =3 ; + parent_fwspec.param[0 ] =0 ;/* SPI */ + parent_fwspec.param[1 ] = md->slots[slot].irq; + parent_fwspec.param[2 ] =IRQ_TYPE_NONE ;Hell no. Look at the GIC DT binding: there is no NONE. It is either HIGH, or RISING.
OK, will be changed.
Quoted 78 lines
Quoted 78 lines
drivers/irqchip/irq-meson-gpio.c new file +78
-0+ + ret =irq_domain_alloc_irqs_parent (d, virq, nr_irqs, &parent_fwspec); +if (ret) +meson_free_irq_slot (md, virq); + +return ret; +} + +static void meson_irq_free (struct irq_domain *d,unsigned int virq, +unsigned int nr_irqs) +{ +struct meson_data *md = d->host_data; + +irq_domain_free_irqs_common (d, virq, nr_irqs); +meson_free_irq_slot (md, virq); +} + +static const struct irq_domain_ops meson_irq_ops = { + .alloc = meson_irq_alloc, + .free = meson_irq_free, + .xlate = irq_domain_xlate_twocell, +}; + +static int meson_get_irqs (struct meson_data *md,struct device_node *node) +{ +int ret, i; +u32 irq; + +for (i =0 ; i <MAX_PARENT_IRQ_NUM ; i++) { + ret =of_property_read_u32_index (node,"interrupts" , i, &irq); +if (ret) +break ; + md->slots[i].irq = irq; + } + + md->num_slots = i; + +return i ?0 : -EINVAL ; +} + +static const struct regmap_config meson_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .max_register =REG_FILTER_SEL , +}; + +static int __init meson_gpio_irq_init (struct device_node *node, +struct device_node *parent) +{ +struct irq_domain *meson_irq_domain, *parent_domain; +struct meson_data *md; +void __iomem *io_base; +int ret; + + md =kzalloc (sizeof (*md),GFP_KERNEL ); +if (!md) +return -ENOMEM ; + +mutex_init (&md->lock); + + io_base =of_iomap (node,0 ); +if (!io_base) +return -EINVAL ; + + md->regmap =regmap_init_mmio (NULL , io_base, &meson_regmap_config); +if (IS_ERR (md->regmap)) +return PTR_ERR (md->regmap); + +/* initialize to IRQ_TYPE_LEVEL_HIGH */ +regmap_write (md->regmap,REG_EDGE_POL ,0 ); +/* disable all GPIO interrupt sources */ +regmap_write (md->regmap,REG_PIN_03_SEL ,0xffffffff ); +regmap_write (md->regmap,REG_PIN_47_SEL ,0xffffffff ); +/* disable filtering */ +regmap_write (md->regmap,REG_FILTER_SEL ,0 ); + + ret =meson_get_irqs (md, node);
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 287
Quoted 6 lines
drivers/irqchip/irq-meson-gpio.c new file +6
-0+if (ret) +return ret; + + parent_domain =irq_find_host (parent); +if (!parent_domain) +return -ENXIO ;Memory leak on all the return paths.
Indeed. Most likely copy & paste error when I used other irqchip drivers as inspiration. E.g. irq-crossbar faces the same issue, it allocates memory in crossbar_of_init which isn't free'd if irq_domain_add_hierarchy fails.
Quoted 14 lines
drivers/irqchip/irq-meson-gpio.c line 295
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c new file +8
-0+ + meson_irq_domain =irq_domain_add_hierarchy (parent_domain,0 , +NUM_GPIO_HWIRQ , node, + &meson_irq_ops, md); +return meson_irq_domain ?0 : -EINVAL ; +} + +IRQCHIP_DECLARE (meson_gpio_irq,"amlogic,meson-gpio-intc" , meson_gpio_irq_init);Thanks,
M.
PATCH v7 1/9 irqchip: add Amlogic Meson GPIO irqchip driver
Quoted 91 lines · Heiner Kallweit
Am 13.06.2017 um 10:31 schrieb Marc Zyngier:
Quoted 81 lines · Heiner Kallweit
Quoted 80 lines
Add a driver supporting the GPIO interrupt controller on certain Amlogic meson SoC's.
Signed-off-by Heiner Kallweit <[email protected]>---
v5:
- changedKconfigentry based on Neil's suggestion
- added authors
- extended explanation why 2 * n hwirqs are used v6:
- change DT property parent-interrupts to interrupts v7:
- no changes--- drivers/irqchip/Kconfig | 5 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-meson-gpio.c | 295 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 drivers/irqchip/irq-meson-gpio.cdrivers/irqchip/Kconfig +5
-0@@ -301,3 +301,8 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config MESON_GPIO_INTC + bool + depends on ARCH_MESON + default ydrivers/irqchip/Makefile +1
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_MESON_GPIO_INTC) += irq-meson-gpio.odrivers/irqchip/irq-meson-gpio.c new file +32
-0@@ -0,0 +1,295 @@ +/* +* Amlogic Meson GPIO IRQ chip driver +* +* Copyright (c) 2015 Endless Mobile, Inc. +* Author: Carlo Caione <[email protected]> +* Copyright (c) 2016 BayLibre, SAS. +* Author: Jerome Brunet <[email protected]> +* Copyright (c) 2017 Heiner Kallweit <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +*/ + +#include <linux/device.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/regmap.h> + +#define REG_EDGE_POL 0x00 +#define REG_PIN_03_SEL 0x04 +#define REG_PIN_47_SEL 0x08 +#define REG_FILTER_SEL 0x0c + +#define REG_EDGE_POL_MASK (x) (BIT(x) | BIT(16 + (x))) +#define REG_EDGE_POL_EDGE (x) BIT(x) +#define REG_EDGE_POL_LOW (x) BIT(16 + (x)) +Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 36
Quoted 4 lines
drivers/irqchip/irq-meson-gpio.c new file +4
-0+#define MAX_PARENT_IRQ_NUM 8 + +/* maximum number of GPIO IRQs on supported platforms */ +#define MAX_NUM_GPIO_IRQ 133Why aren't these values coming from DT? I bet that a future revision of the same HW will double these. Or at least, you could match it on the compatible string.
Quoted 2 lines
Alternatively this value can be set to 255. The GPIO source is an 8 bit value with 255 being reserved for "no interrupt source assigned".
Who is reserving it? The HW? Or is that your own defined convention?
Quoted 1 line
This way we cover all chips based on the same IP.
Why? Where is that 8bit limit coming from?
Quoted 2 lines
I think what we could gain by introducing an additional DT property (saving a few bytes in the irqdomain mapping table) isn't worth the effort.
It is not about saving or wasting memory. It is about making the driver and its binding able to span multiple generation of the HW without too much churn. Which is why I'm suggesting that you either define these properties in DT *or* match the compatible string to obtain these values.
Quoted 11 lines
Quoted 11 lines
drivers/irqchip/irq-meson-gpio.c line 43
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +/* +* In case of IRQ_TYPE_EDGE_BOTH we need two parent interrupts, one for each +* edge. That's due to HW constraints. +* We use format 2 * GPIO_HWIRQ +(0|1) for the hwirq, so we can have one +* GPIO_HWIRQ twice and derive the GPIO_HWIRQ from hwirq by shifting hwirq +* one bit to the right. Please expand on how you expect this to work, specially when a random driver expects a single interrupt.
Quoted 3 lines
The gpio interrupt controller in this chip doesn't have native support for
IRQ_TYPE_EDGE_BOTH. As a workaround we would need to assign the same gpio to two parent interrupts, one for each edge.
No, that's horrible, racy, and impractical. It has been proposed in the past (for the same HW), and we're not going there again.
Quoted 7 lines
There's still no solution to achieve this in a way everybody is happy with. Therefore this feature isn't part of this patch set.
However, to be prepared to include this feature later, the interface between pinctrl/gpio and irqchip driver should (IMHO) cater for it already. Else we may have to touch the irqchip driver later and change the interface what I would like to avoid.
Don't even think of it, and considered it pre-NAKed.
Quoted 3 lines
If a driver just needs one (parent) interrupt, it can request hwirq (2 *
GPIO_HWIRQ) only. There's no issue with that.
Other than being utterly useless and confusing?
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/irqchip/irq-meson-gpio.c new file +20
-0+*/ +#define NUM_GPIO_HWIRQ (2 * MAX_NUM_GPIO_IRQ) + +struct meson_irq_slot { +unsigned int irq; +unsigned int owner; +}; + +struct meson_data { +struct regmap *regmap; +struct meson_irq_slot slots[MAX_PARENT_IRQ_NUM ]; +unsigned int num_slots; +struct mutex lock; +}; + +static int meson_alloc_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i, slot = -ENOSPC ; + +mutex_lock (&md->lock);Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 67
Quoted 4 lines
drivers/irqchip/irq-meson-gpio.c new file +4
-0+ +for (i =0 ; i < md->num_slots && slot <0 ; i++) +if (!md->slots[i].owner) { + md->slots[i].owner = virq;Why do you have to deal with the virq? It'd be more logical to deal with the hwirq. The usual mechanism to reserve a "slot" is to use a bitmap indexed by the hwirq. Why is that not working for you?
Quoted 5 lines
Using the hwirq as owner should also be possible. Will consider this.
A slot has two members, the owner and a the associated parent irq number. Of course we could split this into a slot bitmap + an array with parent irq's indexed by slot number. Would you prefer this?
Again, why do you need to consider the Linux irq number? All you need to track is whether a hwirq has been allocated or not, since all the irqchip function are called with an irq_data as a parameter, which contains both the irq and hwirq values.
Quoted 51 lines
Quoted 43 lines
Quoted 12 lines
drivers/irqchip/irq-meson-gpio.c new file +12
-0+ slot = i; + } + +mutex_unlock (&md->lock); + +return slot; +} + +static void meson_free_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i; +drivers/irqchip/irq-meson-gpio.c line 89
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots; i++) +if (md->slots[i].owner == virq) { + md->slots[i].owner =0 ; +break ; + } + +mutex_unlock (&md->lock); +}These two functions are basically the same...
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ +static int meson_find_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i, slot = -EINVAL ; +drivers/irqchip/irq-meson-gpio.c line 104
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots && slot <0 ; i++) +if (md->slots[i].owner == virq) + slot = i; + +mutex_unlock (&md->lock); + +return slot; +}... and could be expressed in terms of this one.
Quoted 8 lines
drivers/irqchip/irq-meson-gpio.c line 109
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ +static void meson_set_hwirq (struct meson_data *md,int idx,unsigned int hwirq) +{ +int reg = idx >3 ?REG_PIN_47_SEL :REG_PIN_03_SEL ; +int shift =8 * (idx %4 );What's this?
Quoted 2 lines
GPIO source for the eight parent irq's can be configured using two 32-bit registers with four 8-bit fields each.
Consider moving it to an accessor and document the mapping of the hwirqs in these registers.
Quoted 25 lines
Quoted 16 lines
Quoted 16 lines
drivers/irqchip/irq-meson-gpio.c new file +16
-0+ +regmap_update_bits (md->regmap, reg,0xff << shift, + hwirq << shift); +} + +static void meson_irq_set_hwirq (struct irq_data *data,unsigned int hwirq) +{ +struct meson_data *md = data->domain->host_data; +int slot =meson_find_irq_slot (md, data->irq); + +if (slot >=0 ) +meson_set_hwirq (md, slot, hwirq); +} + +static int meson_irq_set_type (struct irq_data *data,unsigned int type) +{Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 131
Quoted 6 lines
drivers/irqchip/irq-meson-gpio.c new file +6
-0+struct meson_data *md = data->domain->host_data; +int slot; +unsigned int val =0 ; + +if (type ==IRQ_TYPE_EDGE_BOTH ) +return -EINVAL ;So you reject
EDGE_BOTH? So what's the deal with the beginning of the patch?
Quoted 2 lines
We reject it in the initial version of the patch set as there's no consensus yet on some details of the workaround needed for
EDGE_BOTHsupport.
There is a consensus: The HW doesn't support this feature.
Quoted 60 lines
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c line 135
Quoted 4 lines
drivers/irqchip/irq-meson-gpio.c new file +4
-0+ + slot =meson_find_irq_slot (md, data->irq); +if (slot <0 ) +return slot;How can this happen?
I see no way how this can happen. It was basically added to be on the safe side and fail nicely in case I miss a scenario which could cause this to fail. I can remove the check.
Quoted 9 lines
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c new file +9
-0+ +if (type &IRQ_TYPE_EDGE_BOTH ) + val |=REG_EDGE_POL_EDGE (slot); + +if (type & (IRQ_TYPE_LEVEL_LOW |IRQ_TYPE_EDGE_FALLING )) + val |=REG_EDGE_POL_LOW (slot); + +regmap_update_bits (md->regmap,REG_EDGE_POL , +REG_EDGE_POL_MASK (slot), val);Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 149
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ +if (type &IRQ_TYPE_EDGE_BOTH ) + val =IRQ_TYPE_EDGE_RISING ; +else + val =IRQ_TYPE_LEVEL_HIGH ;How does this work? Does this HW have some magic
falling->risingandlow->highconversion feature? If it doesn't, I cannot see how this can work.Exactly, HW has a programmable polarity inverter.
Quoted 7 lines
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +return irq_chip_set_type_parent (data, val); +} + +static unsigned int meson_irq_startup (struct irq_data *data) +{ +irq_chip_unmask_parent (data);Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 162
Quoted 6 lines
drivers/irqchip/irq-meson-gpio.c new file +6
-0+/* +* An extra bit was added to allow having the same gpio hwirq twice +* for handling IRQ_TYPE_EDGE_BOTH. Remove this bit to get the +* gpio hwirq. +*/ +meson_irq_set_hwirq (data, data->hwirq >>1 );Again. Do you support
EDGE_BOTHor not?Not yet ..
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c line 169
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +return 0 ; +} + +static void meson_irq_shutdown (struct irq_data *data) +{ +meson_irq_set_hwirq (data,0xff );What's special about
0xff?
Quoted 2 lines
0xffis the reserved value indicating the no GPIO source is assigned to the parent irq.
Then document it, add a #define for this.
Quoted 127 lines
Quoted 29 lines
Quoted 29 lines
drivers/irqchip/irq-meson-gpio.c new file +29
-0+irq_chip_mask_parent (data); +} + +static struct irq_chip meson_irq_chip = { + .name ="meson_gpio_intc" , + .irq_set_type = meson_irq_set_type, + .irq_eoi = irq_chip_eoi_parent, + .irq_mask = irq_chip_mask_parent, + .irq_unmask = irq_chip_unmask_parent, + .irq_startup = meson_irq_startup, + .irq_shutdown = meson_irq_shutdown, + .irq_set_affinity = irq_chip_set_affinity_parent, +}; + +static int meson_irq_alloc (struct irq_domain *d,unsigned int virq, +unsigned int nr_irqs,void *data) +{ +struct irq_fwspec parent_fwspec, *fwspec = data; +struct meson_data *md = d->host_data; +irq_hw_number_t hwirq; +int ret, slot; + + slot =meson_alloc_irq_slot (md, virq); +if (slot <0 ) +return slot; + + hwirq = fwspec->param[0 ]; +irq_domain_set_hwirq_and_chip (d, virq, hwirq, &meson_irq_chip,NULL ); +Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 203
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ parent_fwspec.fwnode = d->parent->fwnode; + parent_fwspec.param_count =3 ; + parent_fwspec.param[0 ] =0 ;/* SPI */ + parent_fwspec.param[1 ] = md->slots[slot].irq; + parent_fwspec.param[2 ] =IRQ_TYPE_NONE ;Hell no. Look at the GIC DT binding: there is no NONE. It is either HIGH, or RISING.
OK, will be changed.
Quoted 78 lines
Quoted 78 lines
drivers/irqchip/irq-meson-gpio.c new file +78
-0+ + ret =irq_domain_alloc_irqs_parent (d, virq, nr_irqs, &parent_fwspec); +if (ret) +meson_free_irq_slot (md, virq); + +return ret; +} + +static void meson_irq_free (struct irq_domain *d,unsigned int virq, +unsigned int nr_irqs) +{ +struct meson_data *md = d->host_data; + +irq_domain_free_irqs_common (d, virq, nr_irqs); +meson_free_irq_slot (md, virq); +} + +static const struct irq_domain_ops meson_irq_ops = { + .alloc = meson_irq_alloc, + .free = meson_irq_free, + .xlate = irq_domain_xlate_twocell, +}; + +static int meson_get_irqs (struct meson_data *md,struct device_node *node) +{ +int ret, i; +u32 irq; + +for (i =0 ; i <MAX_PARENT_IRQ_NUM ; i++) { + ret =of_property_read_u32_index (node,"interrupts" , i, &irq); +if (ret) +break ; + md->slots[i].irq = irq; + } + + md->num_slots = i; + +return i ?0 : -EINVAL ; +} + +static const struct regmap_config meson_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .max_register =REG_FILTER_SEL , +}; + +static int __init meson_gpio_irq_init (struct device_node *node, +struct device_node *parent) +{ +struct irq_domain *meson_irq_domain, *parent_domain; +struct meson_data *md; +void __iomem *io_base; +int ret; + + md =kzalloc (sizeof (*md),GFP_KERNEL ); +if (!md) +return -ENOMEM ; + +mutex_init (&md->lock); + + io_base =of_iomap (node,0 ); +if (!io_base) +return -EINVAL ; + + md->regmap =regmap_init_mmio (NULL , io_base, &meson_regmap_config); +if (IS_ERR (md->regmap)) +return PTR_ERR (md->regmap); + +/* initialize to IRQ_TYPE_LEVEL_HIGH */ +regmap_write (md->regmap,REG_EDGE_POL ,0 ); +/* disable all GPIO interrupt sources */ +regmap_write (md->regmap,REG_PIN_03_SEL ,0xffffffff ); +regmap_write (md->regmap,REG_PIN_47_SEL ,0xffffffff ); +/* disable filtering */ +regmap_write (md->regmap,REG_FILTER_SEL ,0 ); + + ret =meson_get_irqs (md, node);Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 287
Quoted 6 lines
drivers/irqchip/irq-meson-gpio.c new file +6
-0+if (ret) +return ret; + + parent_domain =irq_find_host (parent); +if (!parent_domain) +return -ENXIO ;Memory leak on all the return paths.
Quoted 3 lines
Indeed. Most likely copy & paste error when I used other irqchip drivers as inspiration. E.g. irq-crossbar faces the same issue, it allocates memory in
crossbar_of_initwhich isn't free'd ifirq_domain_add_hierarchyfails.
Then please submit a patch addressing the defect.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH v7 1/9 irqchip: add Amlogic Meson GPIO irqchip driver
Am 15.06.2017 um 15:27 schrieb Marc Zyngier:
Quoted 92 lines · Heiner Kallweit
Quoted 91 lines
Am 13.06.2017 um 10:31 schrieb Marc Zyngier:
Quoted 90 lines · Heiner Kallweit
Quoted 74 lines
Add a driver supporting the GPIO interrupt controller on certain Amlogic meson SoC's.
Signed-off-by Heiner Kallweit <[email protected]>---
v5:
- changedKconfigentry based on Neil's suggestion
- added authors
- extended explanation why 2 * n hwirqs are used v6:
- change DT property parent-interrupts to interrupts v7:
- no changes--- drivers/irqchip/Kconfig | 5 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-meson-gpio.c | 295 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 drivers/irqchip/irq-meson-gpio.cdrivers/irqchip/Kconfig +5
-0@@ -301,3 +301,8 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config MESON_GPIO_INTC + bool + depends on ARCH_MESON + default ydrivers/irqchip/Makefile +1
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_MESON_GPIO_INTC) += irq-meson-gpio.odrivers/irqchip/irq-meson-gpio.c new file +26
-0@@ -0,0 +1,295 @@ +/* +* Amlogic Meson GPIO IRQ chip driver +* +* Copyright (c) 2015 Endless Mobile, Inc. +* Author: Carlo Caione <[email protected]> +* Copyright (c) 2016 BayLibre, SAS. +* Author: Jerome Brunet <[email protected]> +* Copyright (c) 2017 Heiner Kallweit <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +*/ + +#include <linux/device.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/regmap.h> + +#define REG_EDGE_POL 0x00 +#define REG_PIN_03_SEL 0x04 +#define REG_PIN_47_SEL 0x08drivers/irqchip/irq-meson-gpio.c line 36
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+#define REG_FILTER_SEL 0x0c + +#define REG_EDGE_POL_MASK (x) (BIT(x) | BIT(16 + (x))) +#define REG_EDGE_POL_EDGE (x) BIT(x) +#define REG_EDGE_POL_LOW (x) BIT(16 + (x)) + +#define MAX_PARENT_IRQ_NUM 8 + +/* maximum number of GPIO IRQs on supported platforms */ +#define MAX_NUM_GPIO_IRQ 133Why aren't these values coming from DT? I bet that a future revision of the same HW will double these. Or at least, you could match it on the compatible string.
Quoted 9 lines
Quoted 2 lines
Alternatively this value can be set to 255. The GPIO source is an 8 bit value with 255 being reserved for "no interrupt source assigned".
Who is reserving it? The HW? Or is that your own defined convention?
Quoted 1 line
This way we cover all chips based on the same IP.
Why? Where is that 8bit limit coming from?
The 8 bit limit is in the HW.
Quoted 19 lines
Quoted 2 lines
I think what we could gain by introducing an additional DT property (saving a few bytes in the irqdomain mapping table) isn't worth the effort.
It is not about saving or wasting memory. It is about making the driver and its binding able to span multiple generation of the HW without too much churn. Which is why I'm suggesting that you either define these properties in DT *or* match the compatible string to obtain these values.
Quoted 11 lines
Quoted 11 lines
drivers/irqchip/irq-meson-gpio.c line 43
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +/* +* In case of IRQ_TYPE_EDGE_BOTH we need two parent interrupts, one for each +* edge. That's due to HW constraints. +* We use format 2 * GPIO_HWIRQ +(0|1) for the hwirq, so we can have one +* GPIO_HWIRQ twice and derive the GPIO_HWIRQ from hwirq by shifting hwirq +* one bit to the right. Please expand on how you expect this to work, specially when a random driver expects a single interrupt.
Quoted 7 lines
Quoted 3 lines
The gpio interrupt controller in this chip doesn't have native support for
IRQ_TYPE_EDGE_BOTH. As a workaround we would need to assign the same gpio to two parent interrupts, one for each edge.No, that's horrible, racy, and impractical. It has been proposed in the past (for the same HW), and we're not going there again.
IIRC what has been proposed before is to re-program the polarity of edge detection withing the ISR. This would match your concern that it is racy.
Here it's about using two parent irq's, one programmed to react on the rising edge whilst the other is triggered in case of falling edge. Would you consider this to be racy too?
Quoted 138 lines
Quoted 7 lines
There's still no solution to achieve this in a way everybody is happy with. Therefore this feature isn't part of this patch set.
However, to be prepared to include this feature later, the interface between pinctrl/gpio and irqchip driver should (IMHO) cater for it already. Else we may have to touch the irqchip driver later and change the interface what I would like to avoid.
Don't even think of it, and considered it pre-NAKed.
Quoted 3 lines
If a driver just needs one (parent) interrupt, it can request hwirq (2 *
GPIO_HWIRQ) only. There's no issue with that.Other than being utterly useless and confusing?
Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
drivers/irqchip/irq-meson-gpio.c new file +20
-0+*/ +#define NUM_GPIO_HWIRQ (2 * MAX_NUM_GPIO_IRQ) + +struct meson_irq_slot { +unsigned int irq; +unsigned int owner; +}; + +struct meson_data { +struct regmap *regmap; +struct meson_irq_slot slots[MAX_PARENT_IRQ_NUM ]; +unsigned int num_slots; +struct mutex lock; +}; + +static int meson_alloc_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i, slot = -ENOSPC ; + +mutex_lock (&md->lock);Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 67
Quoted 4 lines
drivers/irqchip/irq-meson-gpio.c new file +4
-0+ +for (i =0 ; i < md->num_slots && slot <0 ; i++) +if (!md->slots[i].owner) { + md->slots[i].owner = virq;Why do you have to deal with the virq? It'd be more logical to deal with the hwirq. The usual mechanism to reserve a "slot" is to use a bitmap indexed by the hwirq. Why is that not working for you?
Quoted 5 lines
Using the hwirq as owner should also be possible. Will consider this.
A slot has two members, the owner and a the associated parent irq number. Of course we could split this into a slot bitmap + an array with parent irq's indexed by slot number. Would you prefer this?
Again, why do you need to consider the Linux irq number? All you need to track is whether a hwirq has been allocated or not, since all the irqchip function are called with an
irq_dataas a parameter, which contains both the irq and hwirq values.Quoted 51 lines
Quoted 43 lines
Quoted 12 lines
drivers/irqchip/irq-meson-gpio.c new file +12
-0+ slot = i; + } + +mutex_unlock (&md->lock); + +return slot; +} + +static void meson_free_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i; +drivers/irqchip/irq-meson-gpio.c line 89
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots; i++) +if (md->slots[i].owner == virq) { + md->slots[i].owner =0 ; +break ; + } + +mutex_unlock (&md->lock); +}These two functions are basically the same...
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ +static int meson_find_irq_slot (struct meson_data *md,unsigned int virq) +{ +int i, slot = -EINVAL ; +drivers/irqchip/irq-meson-gpio.c line 104
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+mutex_lock (&md->lock); + +for (i =0 ; i < md->num_slots && slot <0 ; i++) +if (md->slots[i].owner == virq) + slot = i; + +mutex_unlock (&md->lock); + +return slot; +}... and could be expressed in terms of this one.
Quoted 8 lines
drivers/irqchip/irq-meson-gpio.c line 109
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ +static void meson_set_hwirq (struct meson_data *md,int idx,unsigned int hwirq) +{ +int reg = idx >3 ?REG_PIN_47_SEL :REG_PIN_03_SEL ; +int shift =8 * (idx %4 );What's this?
Quoted 2 lines
GPIO source for the eight parent irq's can be configured using two 32-bit registers with four 8-bit fields each.
Consider moving it to an accessor and document the mapping of the hwirqs in these registers.
Quoted 25 lines
Quoted 25 lines
Quoted 12 lines
drivers/irqchip/irq-meson-gpio.c new file +12
-0+ +regmap_update_bits (md->regmap, reg,0xff << shift, + hwirq << shift); +} + +static void meson_irq_set_hwirq (struct irq_data *data,unsigned int hwirq) +{ +struct meson_data *md = data->domain->host_data; +int slot =meson_find_irq_slot (md, data->irq); + +if (slot >=0 ) +meson_set_hwirq (md, slot, hwirq);drivers/irqchip/irq-meson-gpio.c line 131
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+} + +static int meson_irq_set_type (struct irq_data *data,unsigned int type) +{ +struct meson_data *md = data->domain->host_data; +int slot; +unsigned int val =0 ; + +if (type ==IRQ_TYPE_EDGE_BOTH ) +return -EINVAL ;So you reject
EDGE_BOTH? So what's the deal with the beginning of the patch?
Quoted 5 lines
Quoted 2 lines
We reject it in the initial version of the patch set as there's no consensus yet on some details of the workaround needed for
EDGE_BOTHsupport.There is a consensus: The HW doesn't support this feature.
Means what? There is no acceptable way to support EDGE_BOTH on this HW? In this case I could stop here as for me this feature is important.
Would be somewhat a pity as there is a working solution. If it doesn't fit into the current irq(chip) framework, shouldn't this be considered a gap in the framework?
Quoted 202 lines
Quoted 60 lines
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c line 135
Quoted 4 lines
drivers/irqchip/irq-meson-gpio.c new file +4
-0+ + slot =meson_find_irq_slot (md, data->irq); +if (slot <0 ) +return slot;How can this happen?
I see no way how this can happen. It was basically added to be on the safe side and fail nicely in case I miss a scenario which could cause this to fail. I can remove the check.
Quoted 9 lines
Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c new file +9
-0+ +if (type &IRQ_TYPE_EDGE_BOTH ) + val |=REG_EDGE_POL_EDGE (slot); + +if (type & (IRQ_TYPE_LEVEL_LOW |IRQ_TYPE_EDGE_FALLING )) + val |=REG_EDGE_POL_LOW (slot); + +regmap_update_bits (md->regmap,REG_EDGE_POL , +REG_EDGE_POL_MASK (slot), val);Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 149
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ +if (type &IRQ_TYPE_EDGE_BOTH ) + val =IRQ_TYPE_EDGE_RISING ; +else + val =IRQ_TYPE_LEVEL_HIGH ;How does this work? Does this HW have some magic
falling->risingandlow->highconversion feature? If it doesn't, I cannot see how this can work.Exactly, HW has a programmable polarity inverter.
Quoted 7 lines
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +return irq_chip_set_type_parent (data, val); +} + +static unsigned int meson_irq_startup (struct irq_data *data) +{ +irq_chip_unmask_parent (data);Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 162
Quoted 6 lines
drivers/irqchip/irq-meson-gpio.c new file +6
-0+/* +* An extra bit was added to allow having the same gpio hwirq twice +* for handling IRQ_TYPE_EDGE_BOTH. Remove this bit to get the +* gpio hwirq. +*/ +meson_irq_set_hwirq (data, data->hwirq >>1 );Again. Do you support
EDGE_BOTHor not?Not yet ..
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c line 169
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +return 0 ; +} + +static void meson_irq_shutdown (struct irq_data *data) +{ +meson_irq_set_hwirq (data,0xff );What's special about
0xff?Quoted 2 lines
0xffis the reserved value indicating the no GPIO source is assigned to the parent irq.Then document it, add a #define for this.
Quoted 127 lines
Quoted 29 lines
Quoted 29 lines
drivers/irqchip/irq-meson-gpio.c new file +29
-0+irq_chip_mask_parent (data); +} + +static struct irq_chip meson_irq_chip = { + .name ="meson_gpio_intc" , + .irq_set_type = meson_irq_set_type, + .irq_eoi = irq_chip_eoi_parent, + .irq_mask = irq_chip_mask_parent, + .irq_unmask = irq_chip_unmask_parent, + .irq_startup = meson_irq_startup, + .irq_shutdown = meson_irq_shutdown, + .irq_set_affinity = irq_chip_set_affinity_parent, +}; + +static int meson_irq_alloc (struct irq_domain *d,unsigned int virq, +unsigned int nr_irqs,void *data) +{ +struct irq_fwspec parent_fwspec, *fwspec = data; +struct meson_data *md = d->host_data; +irq_hw_number_t hwirq; +int ret, slot; + + slot =meson_alloc_irq_slot (md, virq); +if (slot <0 ) +return slot; + + hwirq = fwspec->param[0 ]; +irq_domain_set_hwirq_and_chip (d, virq, hwirq, &meson_irq_chip,NULL ); +Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 203
Quoted 5 lines
drivers/irqchip/irq-meson-gpio.c new file +5
-0+ parent_fwspec.fwnode = d->parent->fwnode; + parent_fwspec.param_count =3 ; + parent_fwspec.param[0 ] =0 ;/* SPI */ + parent_fwspec.param[1 ] = md->slots[slot].irq; + parent_fwspec.param[2 ] =IRQ_TYPE_NONE ;Hell no. Look at the GIC DT binding: there is no NONE. It is either HIGH, or RISING.
OK, will be changed.
Quoted 78 lines
Quoted 78 lines
drivers/irqchip/irq-meson-gpio.c new file +78
-0+ + ret =irq_domain_alloc_irqs_parent (d, virq, nr_irqs, &parent_fwspec); +if (ret) +meson_free_irq_slot (md, virq); + +return ret; +} + +static void meson_irq_free (struct irq_domain *d,unsigned int virq, +unsigned int nr_irqs) +{ +struct meson_data *md = d->host_data; + +irq_domain_free_irqs_common (d, virq, nr_irqs); +meson_free_irq_slot (md, virq); +} + +static const struct irq_domain_ops meson_irq_ops = { + .alloc = meson_irq_alloc, + .free = meson_irq_free, + .xlate = irq_domain_xlate_twocell, +}; + +static int meson_get_irqs (struct meson_data *md,struct device_node *node) +{ +int ret, i; +u32 irq; + +for (i =0 ; i <MAX_PARENT_IRQ_NUM ; i++) { + ret =of_property_read_u32_index (node,"interrupts" , i, &irq); +if (ret) +break ; + md->slots[i].irq = irq; + } + + md->num_slots = i; + +return i ?0 : -EINVAL ; +} + +static const struct regmap_config meson_regmap_config = { + .reg_bits =32 , + .reg_stride =4 , + .val_bits =32 , + .max_register =REG_FILTER_SEL , +}; + +static int __init meson_gpio_irq_init (struct device_node *node, +struct device_node *parent) +{ +struct irq_domain *meson_irq_domain, *parent_domain; +struct meson_data *md; +void __iomem *io_base; +int ret; + + md =kzalloc (sizeof (*md),GFP_KERNEL ); +if (!md) +return -ENOMEM ; + +mutex_init (&md->lock); + + io_base =of_iomap (node,0 ); +if (!io_base) +return -EINVAL ; + + md->regmap =regmap_init_mmio (NULL , io_base, &meson_regmap_config); +if (IS_ERR (md->regmap)) +return PTR_ERR (md->regmap); + +/* initialize to IRQ_TYPE_LEVEL_HIGH */ +regmap_write (md->regmap,REG_EDGE_POL ,0 ); +/* disable all GPIO interrupt sources */ +regmap_write (md->regmap,REG_PIN_03_SEL ,0xffffffff ); +regmap_write (md->regmap,REG_PIN_47_SEL ,0xffffffff ); +/* disable filtering */ +regmap_write (md->regmap,REG_FILTER_SEL ,0 ); + + ret =meson_get_irqs (md, node);Quoted 9 lines
drivers/irqchip/irq-meson-gpio.c line 287
Quoted 6 lines
drivers/irqchip/irq-meson-gpio.c new file +6
-0+if (ret) +return ret; + + parent_domain =irq_find_host (parent); +if (!parent_domain) +return -ENXIO ;Memory leak on all the return paths.
Quoted 3 lines
Indeed. Most likely copy & paste error when I used other irqchip drivers as inspiration. E.g. irq-crossbar faces the same issue, it allocates memory in
crossbar_of_initwhich isn't free'd ifirq_domain_add_hierarchyfails.Then please submit a patch addressing the defect.
Thanks,
M.
PATCH v7 1/9 irqchip: add Amlogic Meson GPIO irqchip driver
Quoted 130 lines · Heiner Kallweit
Am 15.06.2017 um 15:27 schrieb Marc Zyngier:
Quoted 92 lines · Heiner Kallweit
Quoted 91 lines
Am 13.06.2017 um 10:31 schrieb Marc Zyngier:
Quoted 90 lines · Heiner Kallweit
Quoted 74 lines
Add a driver supporting the GPIO interrupt controller on certain Amlogic meson SoC's.
Signed-off-by Heiner Kallweit <[email protected]>---
v5:
- changedKconfigentry based on Neil's suggestion
- added authors
- extended explanation why 2 * n hwirqs are used v6:
- change DT property parent-interrupts to interrupts v7:
- no changes--- drivers/irqchip/Kconfig | 5 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-meson-gpio.c | 295 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 drivers/irqchip/irq-meson-gpio.cdrivers/irqchip/Kconfig +5
-0@@ -301,3 +301,8 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config MESON_GPIO_INTC + bool + depends on ARCH_MESON + default ydrivers/irqchip/Makefile +1
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_MESON_GPIO_INTC) += irq-meson-gpio.odrivers/irqchip/irq-meson-gpio.c new file +26
-0@@ -0,0 +1,295 @@ +/* +* Amlogic Meson GPIO IRQ chip driver +* +* Copyright (c) 2015 Endless Mobile, Inc. +* Author: Carlo Caione <[email protected]> +* Copyright (c) 2016 BayLibre, SAS. +* Author: Jerome Brunet <[email protected]> +* Copyright (c) 2017 Heiner Kallweit <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +*/ + +#include <linux/device.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/regmap.h> + +#define REG_EDGE_POL 0x00 +#define REG_PIN_03_SEL 0x04 +#define REG_PIN_47_SEL 0x08drivers/irqchip/irq-meson-gpio.c line 36
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+#define REG_FILTER_SEL 0x0c + +#define REG_EDGE_POL_MASK (x) (BIT(x) | BIT(16 + (x))) +#define REG_EDGE_POL_EDGE (x) BIT(x) +#define REG_EDGE_POL_LOW (x) BIT(16 + (x)) + +#define MAX_PARENT_IRQ_NUM 8 + +/* maximum number of GPIO IRQs on supported platforms */ +#define MAX_NUM_GPIO_IRQ 133Why aren't these values coming from DT? I bet that a future revision of the same HW will double these. Or at least, you could match it on the compatible string.
Quoted 9 lines
Quoted 2 lines
Alternatively this value can be set to 255. The GPIO source is an 8 bit value with 255 being reserved for "no interrupt source assigned".
Who is reserving it? The HW? Or is that your own defined convention?
Quoted 1 line
This way we cover all chips based on the same IP.
Why? Where is that 8bit limit coming from?
The 8 bit limit is in the HW.
Quoted 19 lines
Quoted 2 lines
I think what we could gain by introducing an additional DT property (saving a few bytes in the irqdomain mapping table) isn't worth the effort.
It is not about saving or wasting memory. It is about making the driver and its binding able to span multiple generation of the HW without too much churn. Which is why I'm suggesting that you either define these properties in DT *or* match the compatible string to obtain these values.
Quoted 11 lines
Quoted 11 lines
drivers/irqchip/irq-meson-gpio.c line 43
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +/* +* In case of IRQ_TYPE_EDGE_BOTH we need two parent interrupts, one for each +* edge. That's due to HW constraints. +* We use format 2 * GPIO_HWIRQ +(0|1) for the hwirq, so we can have one +* GPIO_HWIRQ twice and derive the GPIO_HWIRQ from hwirq by shifting hwirq +* one bit to the right. Please expand on how you expect this to work, specially when a random driver expects a single interrupt.
Quoted 7 lines
Quoted 3 lines
The gpio interrupt controller in this chip doesn't have native support for
IRQ_TYPE_EDGE_BOTH. As a workaround we would need to assign the same gpio to two parent interrupts, one for each edge.No, that's horrible, racy, and impractical. It has been proposed in the past (for the same HW), and we're not going there again.
Quoted 6 lines
IIRC what has been proposed before is to re-program the polarity of edge detection withing the ISR. This would match your concern that it is racy.
Here it's about using two parent irq's, one programmed to react on the rising edge whilst the other is triggered in case of falling edge. Would you consider this to be racy too?
How do you reconcile two interrupts to make look like a single one for a random, pre-existing driver?
[...]
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
So you reject
EDGE_BOTH? So what's the deal with the beginning of the patch?We reject it in the initial version of the patch set as there's no consensus yet on some details of the workaround needed for
EDGE_BOTHsupport.There is a consensus: The HW doesn't support this feature.
Means what? There is no acceptable way to support
EDGE_BOTHon this HW? In this case I could stop here as for me this feature is important.
Answer my question above, which I asked in my initial review: How do you make two interrupts appear as one for a driver that wants to get signaled on each edge, using the existing API.
Quoted 4 lines
Would be somewhat a pity as there is a working solution. If it doesn't fit into the current irq(chip) framework, shouldn't this be considered a gap in the framework?
Again, this is not about the framework, which we can almost twist as we see fit. It is about the API that a driver expects. At the moment, you haven't proposed anything.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH v7 1/9 irqchip: add Amlogic Meson GPIO irqchip driver
Am 15.06.2017 um 18:04 schrieb Marc Zyngier:
Quoted 148 lines · Heiner Kallweit
Quoted 130 lines
Am 15.06.2017 um 15:27 schrieb Marc Zyngier:
Quoted 92 lines · Heiner Kallweit
Quoted 91 lines
Am 13.06.2017 um 10:31 schrieb Marc Zyngier:
Quoted 90 lines · Heiner Kallweit
Quoted 74 lines
Add a driver supporting the GPIO interrupt controller on certain Amlogic meson SoC's.
Signed-off-by Heiner Kallweit <[email protected]>---
v5:
- changedKconfigentry based on Neil's suggestion
- added authors
- extended explanation why 2 * n hwirqs are used v6:
- change DT property parent-interrupts to interrupts v7:
- no changes--- drivers/irqchip/Kconfig | 5 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-meson-gpio.c | 295 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 drivers/irqchip/irq-meson-gpio.cdrivers/irqchip/Kconfig +5
-0@@ -301,3 +301,8 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config MESON_GPIO_INTC + bool + depends on ARCH_MESON + default ydrivers/irqchip/Makefile +1
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_MESON_GPIO_INTC) += irq-meson-gpio.odrivers/irqchip/irq-meson-gpio.c new file +26
-0@@ -0,0 +1,295 @@ +/* +* Amlogic Meson GPIO IRQ chip driver +* +* Copyright (c) 2015 Endless Mobile, Inc. +* Author: Carlo Caione <[email protected]> +* Copyright (c) 2016 BayLibre, SAS. +* Author: Jerome Brunet <[email protected]> +* Copyright (c) 2017 Heiner Kallweit <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +*/ + +#include <linux/device.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/regmap.h> + +#define REG_EDGE_POL 0x00 +#define REG_PIN_03_SEL 0x04 +#define REG_PIN_47_SEL 0x08drivers/irqchip/irq-meson-gpio.c line 36
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+#define REG_FILTER_SEL 0x0c + +#define REG_EDGE_POL_MASK (x) (BIT(x) | BIT(16 + (x))) +#define REG_EDGE_POL_EDGE (x) BIT(x) +#define REG_EDGE_POL_LOW (x) BIT(16 + (x)) + +#define MAX_PARENT_IRQ_NUM 8 + +/* maximum number of GPIO IRQs on supported platforms */ +#define MAX_NUM_GPIO_IRQ 133Why aren't these values coming from DT? I bet that a future revision of the same HW will double these. Or at least, you could match it on the compatible string.
Quoted 9 lines
Quoted 2 lines
Alternatively this value can be set to 255. The GPIO source is an 8 bit value with 255 being reserved for "no interrupt source assigned".
Who is reserving it? The HW? Or is that your own defined convention?
Quoted 1 line
This way we cover all chips based on the same IP.
Why? Where is that 8bit limit coming from?
The 8 bit limit is in the HW.
Quoted 19 lines
Quoted 2 lines
I think what we could gain by introducing an additional DT property (saving a few bytes in the irqdomain mapping table) isn't worth the effort.
It is not about saving or wasting memory. It is about making the driver and its binding able to span multiple generation of the HW without too much churn. Which is why I'm suggesting that you either define these properties in DT *or* match the compatible string to obtain these values.
Quoted 11 lines
Quoted 11 lines
drivers/irqchip/irq-meson-gpio.c line 43
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +/* +* In case of IRQ_TYPE_EDGE_BOTH we need two parent interrupts, one for each +* edge. That's due to HW constraints. +* We use format 2 * GPIO_HWIRQ +(0|1) for the hwirq, so we can have one +* GPIO_HWIRQ twice and derive the GPIO_HWIRQ from hwirq by shifting hwirq +* one bit to the right. Please expand on how you expect this to work, specially when a random driver expects a single interrupt.
Quoted 7 lines
Quoted 3 lines
The gpio interrupt controller in this chip doesn't have native support for
IRQ_TYPE_EDGE_BOTH. As a workaround we would need to assign the same gpio to two parent interrupts, one for each edge.No, that's horrible, racy, and impractical. It has been proposed in the past (for the same HW), and we're not going there again.
Quoted 6 lines
IIRC what has been proposed before is to re-program the polarity of edge detection withing the ISR. This would match your concern that it is racy.
Here it's about using two parent irq's, one programmed to react on the rising edge whilst the other is triggered in case of falling edge. Would you consider this to be racy too?
How do you reconcile two interrupts to make look like a single one for a random, pre-existing driver?
[...]
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
So you reject
EDGE_BOTH? So what's the deal with the beginning of the patch?We reject it in the initial version of the patch set as there's no consensus yet on some details of the workaround needed for
EDGE_BOTHsupport.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
There is a consensus: The HW doesn't support this feature.
Means what? There is no acceptable way to support
EDGE_BOTHon this HW? In this case I could stop here as for me this feature is important.Answer my question above, which I asked in my initial review: How do you make two interrupts appear as one for a driver that wants to get signaled on each edge, using the existing API.
Please see the pinctrl/gpio part of the patch set.
The GPIO controller has an own IRQ domain. When requesting an interrupt in request_resources if needed two parent irq's are allocated, (was removed in the current initial version of the patch set) both calling the same ISR via a chained interrupt.
Works perfectly fine here.
Quoted 13 lines
Quoted 4 lines
Would be somewhat a pity as there is a working solution. If it doesn't fit into the current irq(chip) framework, shouldn't this be considered a gap in the framework?
Again, this is not about the framework, which we can almost twist as we see fit. It is about the API that a driver expects. At the moment, you haven't proposed anything.
Thanks,
M.
PATCH v7 1/9 irqchip: add Amlogic Meson GPIO irqchip driver
Quoted 158 lines · Heiner Kallweit
Am 15.06.2017 um 18:04 schrieb Marc Zyngier:
Quoted 148 lines · Heiner Kallweit
Quoted 130 lines
Am 15.06.2017 um 15:27 schrieb Marc Zyngier:
Quoted 92 lines · Heiner Kallweit
Quoted 91 lines
Am 13.06.2017 um 10:31 schrieb Marc Zyngier:
Quoted 90 lines · Heiner Kallweit
Quoted 74 lines
Add a driver supporting the GPIO interrupt controller on certain Amlogic meson SoC's.
Signed-off-by Heiner Kallweit <[email protected]>---
v5:
- changedKconfigentry based on Neil's suggestion
- added authors
- extended explanation why 2 * n hwirqs are used v6:
- change DT property parent-interrupts to interrupts v7:
- no changes--- drivers/irqchip/Kconfig | 5 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-meson-gpio.c | 295 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 drivers/irqchip/irq-meson-gpio.cdrivers/irqchip/Kconfig +5
-0@@ -301,3 +301,8 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config MESON_GPIO_INTC + bool + depends on ARCH_MESON + default ydrivers/irqchip/Makefile +1
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_MESON_GPIO_INTC) += irq-meson-gpio.odrivers/irqchip/irq-meson-gpio.c new file +26
-0@@ -0,0 +1,295 @@ +/* +* Amlogic Meson GPIO IRQ chip driver +* +* Copyright (c) 2015 Endless Mobile, Inc. +* Author: Carlo Caione <[email protected]> +* Copyright (c) 2016 BayLibre, SAS. +* Author: Jerome Brunet <[email protected]> +* Copyright (c) 2017 Heiner Kallweit <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +*/ + +#include <linux/device.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/regmap.h> + +#define REG_EDGE_POL 0x00 +#define REG_PIN_03_SEL 0x04 +#define REG_PIN_47_SEL 0x08drivers/irqchip/irq-meson-gpio.c line 36
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+#define REG_FILTER_SEL 0x0c + +#define REG_EDGE_POL_MASK (x) (BIT(x) | BIT(16 + (x))) +#define REG_EDGE_POL_EDGE (x) BIT(x) +#define REG_EDGE_POL_LOW (x) BIT(16 + (x)) + +#define MAX_PARENT_IRQ_NUM 8 + +/* maximum number of GPIO IRQs on supported platforms */ +#define MAX_NUM_GPIO_IRQ 133Why aren't these values coming from DT? I bet that a future revision of the same HW will double these. Or at least, you could match it on the compatible string.
Quoted 9 lines
Quoted 2 lines
Alternatively this value can be set to 255. The GPIO source is an 8 bit value with 255 being reserved for "no interrupt source assigned".
Who is reserving it? The HW? Or is that your own defined convention?
Quoted 1 line
This way we cover all chips based on the same IP.
Why? Where is that 8bit limit coming from?
The 8 bit limit is in the HW.
Quoted 19 lines
Quoted 2 lines
I think what we could gain by introducing an additional DT property (saving a few bytes in the irqdomain mapping table) isn't worth the effort.
It is not about saving or wasting memory. It is about making the driver and its binding able to span multiple generation of the HW without too much churn. Which is why I'm suggesting that you either define these properties in DT *or* match the compatible string to obtain these values.
Quoted 11 lines
Quoted 11 lines
drivers/irqchip/irq-meson-gpio.c line 43
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +/* +* In case of IRQ_TYPE_EDGE_BOTH we need two parent interrupts, one for each +* edge. That's due to HW constraints. +* We use format 2 * GPIO_HWIRQ +(0|1) for the hwirq, so we can have one +* GPIO_HWIRQ twice and derive the GPIO_HWIRQ from hwirq by shifting hwirq +* one bit to the right. Please expand on how you expect this to work, specially when a random driver expects a single interrupt.
Quoted 7 lines
Quoted 3 lines
The gpio interrupt controller in this chip doesn't have native support for
IRQ_TYPE_EDGE_BOTH. As a workaround we would need to assign the same gpio to two parent interrupts, one for each edge.No, that's horrible, racy, and impractical. It has been proposed in the past (for the same HW), and we're not going there again.
Quoted 6 lines
IIRC what has been proposed before is to re-program the polarity of edge detection withing the ISR. This would match your concern that it is racy.
Here it's about using two parent irq's, one programmed to react on the rising edge whilst the other is triggered in case of falling edge. Would you consider this to be racy too?
How do you reconcile two interrupts to make look like a single one for a random, pre-existing driver?
[...]
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
So you reject
EDGE_BOTH? So what's the deal with the beginning of the patch?We reject it in the initial version of the patch set as there's no consensus yet on some details of the workaround needed for
EDGE_BOTHsupport.Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
There is a consensus: The HW doesn't support this feature.
Means what? There is no acceptable way to support
EDGE_BOTHon this HW? In this case I could stop here as for me this feature is important.Answer my question above, which I asked in my initial review: How do you make two interrupts appear as one for a driver that wants to get signaled on each edge, using the existing API.
Quoted 8 lines
Please see the pinctrl/gpio part of the patch set.
The GPIO controller has an own IRQ domain. When requesting an interrupt in
request_resourcesif needed two parent irq's are allocated, (was removed in the current initial version of the patch set) both calling the same ISR via a chained interrupt.Works perfectly fine here.
Are you referring to the horror that performs interrupt allocations from within the irq_set_type callback? No way. That's beyond disgusting. And potentially broken, as the locks that are being taken were never designed to nest that way.
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH v7 1/9 irqchip: add Amlogic Meson GPIO irqchip driver
Am 15.06.2017 um 18:58 schrieb Marc Zyngier:
Quoted 166 lines · Heiner Kallweit
Quoted 165 lines
Am 15.06.2017 um 18:04 schrieb Marc Zyngier:
Quoted 148 lines · Heiner Kallweit
Quoted 130 lines
Am 15.06.2017 um 15:27 schrieb Marc Zyngier:
Quoted 92 lines · Heiner Kallweit
Quoted 91 lines
Am 13.06.2017 um 10:31 schrieb Marc Zyngier:
Quoted 90 lines · Heiner Kallweit
Quoted 74 lines
Add a driver supporting the GPIO interrupt controller on certain Amlogic meson SoC's.
Signed-off-by Heiner Kallweit <[email protected]>---
v5:
- changedKconfigentry based on Neil's suggestion
- added authors
- extended explanation why 2 * n hwirqs are used v6:
- change DT property parent-interrupts to interrupts v7:
- no changes--- drivers/irqchip/Kconfig | 5 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-meson-gpio.c | 295 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 drivers/irqchip/irq-meson-gpio.cdrivers/irqchip/Kconfig +5
-0@@ -301,3 +301,8 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config MESON_GPIO_INTC + bool + depends on ARCH_MESON + default ydrivers/irqchip/Makefile +1
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_MESON_GPIO_INTC) += irq-meson-gpio.odrivers/irqchip/irq-meson-gpio.c new file +26
-0@@ -0,0 +1,295 @@ +/* +* Amlogic Meson GPIO IRQ chip driver +* +* Copyright (c) 2015 Endless Mobile, Inc. +* Author: Carlo Caione <[email protected]> +* Copyright (c) 2016 BayLibre, SAS. +* Author: Jerome Brunet <[email protected]> +* Copyright (c) 2017 Heiner Kallweit <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +*/ + +#include <linux/device.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/regmap.h> + +#define REG_EDGE_POL 0x00 +#define REG_PIN_03_SEL 0x04 +#define REG_PIN_47_SEL 0x08drivers/irqchip/irq-meson-gpio.c line 36
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+#define REG_FILTER_SEL 0x0c + +#define REG_EDGE_POL_MASK (x) (BIT(x) | BIT(16 + (x))) +#define REG_EDGE_POL_EDGE (x) BIT(x) +#define REG_EDGE_POL_LOW (x) BIT(16 + (x)) + +#define MAX_PARENT_IRQ_NUM 8 + +/* maximum number of GPIO IRQs on supported platforms */ +#define MAX_NUM_GPIO_IRQ 133Why aren't these values coming from DT? I bet that a future revision of the same HW will double these. Or at least, you could match it on the compatible string.
Quoted 9 lines
Quoted 2 lines
Alternatively this value can be set to 255. The GPIO source is an 8 bit value with 255 being reserved for "no interrupt source assigned".
Who is reserving it? The HW? Or is that your own defined convention?
Quoted 1 line
This way we cover all chips based on the same IP.
Why? Where is that 8bit limit coming from?
The 8 bit limit is in the HW.
Quoted 19 lines
Quoted 2 lines
I think what we could gain by introducing an additional DT property (saving a few bytes in the irqdomain mapping table) isn't worth the effort.
It is not about saving or wasting memory. It is about making the driver and its binding able to span multiple generation of the HW without too much churn. Which is why I'm suggesting that you either define these properties in DT *or* match the compatible string to obtain these values.
Quoted 11 lines
Quoted 11 lines
drivers/irqchip/irq-meson-gpio.c line 43
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +/* +* In case of IRQ_TYPE_EDGE_BOTH we need two parent interrupts, one for each +* edge. That's due to HW constraints. +* We use format 2 * GPIO_HWIRQ +(0|1) for the hwirq, so we can have one +* GPIO_HWIRQ twice and derive the GPIO_HWIRQ from hwirq by shifting hwirq +* one bit to the right. Please expand on how you expect this to work, specially when a random driver expects a single interrupt.
Quoted 7 lines
Quoted 3 lines
The gpio interrupt controller in this chip doesn't have native support for
IRQ_TYPE_EDGE_BOTH. As a workaround we would need to assign the same gpio to two parent interrupts, one for each edge.No, that's horrible, racy, and impractical. It has been proposed in the past (for the same HW), and we're not going there again.
Quoted 6 lines
IIRC what has been proposed before is to re-program the polarity of edge detection withing the ISR. This would match your concern that it is racy.
Here it's about using two parent irq's, one programmed to react on the rising edge whilst the other is triggered in case of falling edge. Would you consider this to be racy too?
How do you reconcile two interrupts to make look like a single one for a random, pre-existing driver?
[...]
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
So you reject
EDGE_BOTH? So what's the deal with the beginning of the patch?We reject it in the initial version of the patch set as there's no consensus yet on some details of the workaround needed for
EDGE_BOTHsupport.Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
There is a consensus: The HW doesn't support this feature.
Means what? There is no acceptable way to support
EDGE_BOTHon this HW? In this case I could stop here as for me this feature is important.Answer my question above, which I asked in my initial review: How do you make two interrupts appear as one for a driver that wants to get signaled on each edge, using the existing API.
Please see the pinctrl/gpio part of the patch set.
The GPIO controller has an own IRQ domain. When requesting an interrupt in
request_resourcesif needed two parent irq's are allocated, (was removed in the current initial version of the patch set) both calling the same ISR via a chained interrupt.
Quoted 7 lines
Quoted 1 line
Works perfectly fine here.
Are you referring to the horror that performs interrupt allocations from within the
irq_set_typecallback? No way. That's beyond disgusting. And potentially broken, as the locks that are being taken were never designed to nest that way.
No, this horror was the first attempt. In v7 of the patch set this is done from the request_resources callback.
Rgds, Heiner
Quoted 2 lines
M.
PATCH v7 1/9 irqchip: add Amlogic Meson GPIO irqchip driver
Quoted 169 lines · Heiner Kallweit
Am 15.06.2017 um 18:58 schrieb Marc Zyngier:
Quoted 168 lines · Heiner Kallweit
Quoted 166 lines
Am 15.06.2017 um 18:04 schrieb Marc Zyngier:
Quoted 148 lines · Heiner Kallweit
Quoted 130 lines
Am 15.06.2017 um 15:27 schrieb Marc Zyngier:
Quoted 92 lines · Heiner Kallweit
Quoted 91 lines
Am 13.06.2017 um 10:31 schrieb Marc Zyngier:
Quoted 90 lines · Heiner Kallweit
Quoted 74 lines
Add a driver supporting the GPIO interrupt controller on certain Amlogic meson SoC's.
Signed-off-by Heiner Kallweit <[email protected]>---
v5:
- changedKconfigentry based on Neil's suggestion
- added authors
- extended explanation why 2 * n hwirqs are used v6:
- change DT property parent-interrupts to interrupts v7:
- no changes--- drivers/irqchip/Kconfig | 5 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-meson-gpio.c | 295 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 drivers/irqchip/irq-meson-gpio.cdrivers/irqchip/Kconfig +5
-0@@ -301,3 +301,8 @@ config QCOM_IRQ_COMBINER help Say yes here to add support for the IRQ combiner devices embedded in Qualcomm Technologies chips. + +config MESON_GPIO_INTC + bool + depends on ARCH_MESON + default ydrivers/irqchip/Makefile +1
-0@@ -76,3 +76,4 @@ obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o +obj-$(CONFIG_MESON_GPIO_INTC) += irq-meson-gpio.odrivers/irqchip/irq-meson-gpio.c new file +26
-0@@ -0,0 +1,295 @@ +/* +* Amlogic Meson GPIO IRQ chip driver +* +* Copyright (c) 2015 Endless Mobile, Inc. +* Author: Carlo Caione <[email protected]> +* Copyright (c) 2016 BayLibre, SAS. +* Author: Jerome Brunet <[email protected]> +* Copyright (c) 2017 Heiner Kallweit <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2. +*/ + +#include <linux/device.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/irqchip.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_address.h> +#include <linux/regmap.h> + +#define REG_EDGE_POL 0x00 +#define REG_PIN_03_SEL 0x04 +#define REG_PIN_47_SEL 0x08drivers/irqchip/irq-meson-gpio.c line 36
Quoted 10 lines
drivers/irqchip/irq-meson-gpio.c new file +10
-0+#define REG_FILTER_SEL 0x0c + +#define REG_EDGE_POL_MASK (x) (BIT(x) | BIT(16 + (x))) +#define REG_EDGE_POL_EDGE (x) BIT(x) +#define REG_EDGE_POL_LOW (x) BIT(16 + (x)) + +#define MAX_PARENT_IRQ_NUM 8 + +/* maximum number of GPIO IRQs on supported platforms */ +#define MAX_NUM_GPIO_IRQ 133Why aren't these values coming from DT? I bet that a future revision of the same HW will double these. Or at least, you could match it on the compatible string.
Quoted 9 lines
Quoted 2 lines
Alternatively this value can be set to 255. The GPIO source is an 8 bit value with 255 being reserved for "no interrupt source assigned".
Who is reserving it? The HW? Or is that your own defined convention?
Quoted 1 line
This way we cover all chips based on the same IP.
Why? Where is that 8bit limit coming from?
The 8 bit limit is in the HW.
Quoted 19 lines
Quoted 2 lines
I think what we could gain by introducing an additional DT property (saving a few bytes in the irqdomain mapping table) isn't worth the effort.
It is not about saving or wasting memory. It is about making the driver and its binding able to span multiple generation of the HW without too much churn. Which is why I'm suggesting that you either define these properties in DT *or* match the compatible string to obtain these values.
Quoted 11 lines
Quoted 11 lines
drivers/irqchip/irq-meson-gpio.c line 43
Quoted 7 lines
drivers/irqchip/irq-meson-gpio.c new file +7
-0+ +/* +* In case of IRQ_TYPE_EDGE_BOTH we need two parent interrupts, one for each +* edge. That's due to HW constraints. +* We use format 2 * GPIO_HWIRQ +(0|1) for the hwirq, so we can have one +* GPIO_HWIRQ twice and derive the GPIO_HWIRQ from hwirq by shifting hwirq +* one bit to the right. Please expand on how you expect this to work, specially when a random driver expects a single interrupt.
Quoted 7 lines
Quoted 3 lines
The gpio interrupt controller in this chip doesn't have native support for
IRQ_TYPE_EDGE_BOTH. As a workaround we would need to assign the same gpio to two parent interrupts, one for each edge.No, that's horrible, racy, and impractical. It has been proposed in the past (for the same HW), and we're not going there again.
Quoted 6 lines
IIRC what has been proposed before is to re-program the polarity of edge detection withing the ISR. This would match your concern that it is racy.
Here it's about using two parent irq's, one programmed to react on the rising edge whilst the other is triggered in case of falling edge. Would you consider this to be racy too?
How do you reconcile two interrupts to make look like a single one for a random, pre-existing driver?
[...]
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
So you reject
EDGE_BOTH? So what's the deal with the beginning of the patch?We reject it in the initial version of the patch set as there's no consensus yet on some details of the workaround needed for
EDGE_BOTHsupport.Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
There is a consensus: The HW doesn't support this feature.
Means what? There is no acceptable way to support
EDGE_BOTHon this HW? In this case I could stop here as for me this feature is important.Answer my question above, which I asked in my initial review: How do you make two interrupts appear as one for a driver that wants to get signaled on each edge, using the existing API.
Please see the pinctrl/gpio part of the patch set.
The GPIO controller has an own IRQ domain. When requesting an interrupt in
request_resourcesif needed two parent irq's are allocated, (was removed in the current initial version of the patch set) both calling the same ISR via a chained interrupt.Works perfectly fine here.
Quoted 7 lines
Quoted 5 lines
Are you referring to the horror that performs interrupt allocations from within the
irq_set_typecallback? No way. That's beyond disgusting. And potentially broken, as the locks that are being taken were never designed to nest that way.No, this horror was the first attempt. In v7 of the patch set this is done from the
request_resourcescallback.
Which makes a lot more sense, thanks.
It remains that none of that code supports EDGE_BOTH, so please remove all traces of it in your next submission. With the right level of abstraction, you'll be able to add it as a subsequent series, and it will be easier to review once the basics are out of the way.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH v7 2/9 dt-bindings: add Amlogic Meson GPIO interrupt-controller DT binding documentation
In reply to Heiner KallweitAdd dt binding documentation for Amlogic meson GPIO interrupt controller.
---
v5:
- added Reviewed-by
v6:
- rename parent-interrupts to interrupts
v7:
- no changes
--- .../amlogic,meson-gpio-intc.txt | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txt
Documentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txt new file +26 -0
@@ -0,0 +1,26 @@ +Amlogic meson GPIO interrupt controller + +Meson SoCs contains an interrupt controller which is able watch the SoC pads +and generate an interrupt on edges or level. The controller is essentially a +256 pads to 8 GIC interrupt multiplexer, with a filter block to select edge +or level and polarity. The actual number of interrupt exposed depends on the +SoC. + +Required properties: + +- compatible : should be "amlogic,meson-gpio-intc". +- reg : Specifies base physical address and size of the registers. +- interrupt-controller : Identifies the node as an interrupt controller. +- #interrupt-cells : should be 2. +- interrupts : list of GIC interrupts which can be used with the + GPIO IRQ multiplexer + +Example: + +gpio_intc: interrupt-controller at 9880 { + compatible = "amlogic,meson-gpio-intc"; + reg = <0x0 0x09880 0x0 0x10>; + interrupt-controller; + #interrupt-cells = <2>; + interrupts = <64 65 66 67 68 69 70 71>; +};
Signature · 1 line
2.13.1
PATCH v7 2/9 dt-bindings: add Amlogic Meson GPIO interrupt-controller DT binding documentation
Quoted 38 lines · Heiner Kallweit
Add dt binding documentation for Amlogic meson GPIO interrupt controller.
Signed-off-by Heiner Kallweit <[email protected]>Reviewed-by Neil Armstrong <[email protected]>Acked-by Rob Herring <[email protected]>---
v5:
- added Reviewed-by
v6:
- rename parent-interrupts to interrupts
v7:
- no changes--- .../amlogic,meson-gpio-intc.txt | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txtDocumentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txt new file +15
-0@@ -0,0 +1,26 @@ +Amlogic meson GPIO interrupt controller + +Meson SoCs contains an interrupt controller which is able watch the SoC pads +and generate an interrupt on edges or level. The controller is essentially a +256 pads to 8 GIC interrupt multiplexer, with a filter block to select edge +or level and polarity. The actual number of interrupt exposed depends on the +SoC. + +Required properties: + +- compatible : should be "amlogic,meson-gpio-intc". +- reg : Specifies base physical address and size of the registers. +- interrupt-controller : Identifies the node as an interrupt controller. +- #interrupt-cells : should be 2. +- interrupts : list of GIC interrupts which can be used with the
Documentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txt line 25
Quoted 10 lines
Documentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txt new file +10
-0+ GPIO IRQ multiplexer + +Example: + +gpio_intc: interrupt-controller at 9880 { + compatible = "amlogic,meson-gpio-intc"; + reg = <0x0 0x09880 0x0 0x10>; + interrupt-controller; + #interrupt-cells = <2>; + interrupts = <64 65 66 67 68 69 70 71>;
What does it mean to have single-cell interrupt specifiers like this, when the interrupt-parent is a GIC, which has #interrupt-cells set to 3? Either you use actual interrupt specifiers, or you use another identifier.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH v7 2/9 dt-bindings: add Amlogic Meson GPIO interrupt-controller DT binding documentation
Am 13.06.2017 um 10:53 schrieb Marc Zyngier:
Quoted 45 lines · Heiner Kallweit
Quoted 44 lines
Add dt binding documentation for Amlogic meson GPIO interrupt controller.
Signed-off-by Heiner Kallweit <[email protected]>Reviewed-by Neil Armstrong <[email protected]>Acked-by Rob Herring <[email protected]>---
v5:
- added Reviewed-by
v6:
- rename parent-interrupts to interrupts
v7:
- no changes--- .../amlogic,meson-gpio-intc.txt | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txtDocumentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txt new file +21
-0@@ -0,0 +1,26 @@ +Amlogic meson GPIO interrupt controller + +Meson SoCs contains an interrupt controller which is able watch the SoC pads +and generate an interrupt on edges or level. The controller is essentially a +256 pads to 8 GIC interrupt multiplexer, with a filter block to select edge +or level and polarity. The actual number of interrupt exposed depends on the +SoC. + +Required properties: + +- compatible : should be "amlogic,meson-gpio-intc". +- reg : Specifies base physical address and size of the registers. +- interrupt-controller : Identifies the node as an interrupt controller. +- #interrupt-cells : should be 2. +- interrupts : list of GIC interrupts which can be used with the + GPIO IRQ multiplexer + +Example: + +gpio_intc: interrupt-controller at 9880 { + compatible = "amlogic,meson-gpio-intc";
Quoted 9 lines
Documentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txt line 25
Quoted 4 lines
Documentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txt new file +4
-0+ reg = <0x0 0x09880 0x0 0x10>; + interrupt-controller; + #interrupt-cells = <2>; + interrupts = <64 65 66 67 68 69 70 71>;What does it mean to have single-cell interrupt specifiers like this, when the interrupt-parent is a GIC, which has #interrupt-cells set to 3? Either you use actual interrupt specifiers, or you use another identifier.
The following approaches have been used already:
- standard interrupts property (3-cell): was rejected because the chip doesn't actually generate the interrupts but just provides a programmable IRQ routing
- property "parent-interrupts" (1-cell): Rob suggested to use "interrupts" instead
I'd appreciate if you could come to an agreement with Rob, whatever the outcome is is fine with me.
Rgds, Heiner
Quoted 4 lines
Thanks,
M.
Rob Herring
maintainerPATCH v7 2/9 dt-bindings: add Amlogic Meson GPIO interrupt-controller DT binding documentation
Quoted 55 lines · Heiner Kallweit
Am 13.06.2017 um 10:53 schrieb Marc Zyngier:
Quoted 45 lines · Heiner Kallweit
Quoted 44 lines
Add dt binding documentation for Amlogic meson GPIO interrupt controller.
Signed-off-by Heiner Kallweit <[email protected]>Reviewed-by Neil Armstrong <[email protected]>Acked-by Rob Herring <[email protected]>---
v5:
- added Reviewed-by
v6:
- rename parent-interrupts to interrupts
v7:
- no changes--- .../amlogic,meson-gpio-intc.txt | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txtDocumentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txt new file +21
-0@@ -0,0 +1,26 @@ +Amlogic meson GPIO interrupt controller + +Meson SoCs contains an interrupt controller which is able watch the SoC pads +and generate an interrupt on edges or level. The controller is essentially a +256 pads to 8 GIC interrupt multiplexer, with a filter block to select edge +or level and polarity. The actual number of interrupt exposed depends on the +SoC. + +Required properties: + +- compatible : should be "amlogic,meson-gpio-intc". +- reg : Specifies base physical address and size of the registers. +- interrupt-controller : Identifies the node as an interrupt controller. +- #interrupt-cells : should be 2. +- interrupts : list of GIC interrupts which can be used with the + GPIO IRQ multiplexer + +Example: + +gpio_intc: interrupt-controller at 9880 { + compatible = "amlogic,meson-gpio-intc";Quoted 9 lines
Documentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txt line 25
Quoted 4 lines
Documentation/devicetree/bindings/interrupt-controller/amlogic,meson-gpio-intc.txt new file +4
-0+ reg = <0x0 0x09880 0x0 0x10>; + interrupt-controller; + #interrupt-cells = <2>; + interrupts = <64 65 66 67 68 69 70 71>;What does it mean to have single-cell interrupt specifiers like this, when the interrupt-parent is a GIC, which has #interrupt-cells set to 3? Either you use actual interrupt specifiers, or you use another identifier.
Quoted 4 lines
The following approaches have been used already:
- standard interrupts property (3-cell): was rejected because the chip doesn't actually generate the interrupts but just provides a programmable IRQ routing
So what? That is describing any chained interrupt controller. The interrupts binding describes interrupt connections, not just interrupt source endpoints.
Quoted 4 lines
- property "parent-interrupts" (1-cell): Rob suggested to use "interrupts" instead
I'd appreciate if you could come to an agreement with Rob, whatever the outcome is is fine with me.
If Marc said not to use standard interrupt binding I can't find it.
Rob
PATCH v7 3/9 ARM: dts: meson: add GPIO interrupt-controller support
In reply to Heiner KallweitAdd support for the GPIO interupt controller of certain Amlogic Meson Soc's.
---
v5:
- split ARM and ARM64 into separate patches
- added Reviewed-by
v6:
- change parent-interrupts to interrupts
v7:
- no changes
--- arch/arm/boot/dts/meson8.dtsi | 8 ++++++++ arch/arm/boot/dts/meson8b.dtsi | 8 ++++++++ 2 files changed, 16 insertions(+)
arch/arm/boot/dts/meson8.dtsi +8 -0
@@ -126,6 +126,14 @@ }; &cbus { + gpio_intc: interrupt-controller at 9880 { + compatible = "amlogic,meson-gpio-intc"; + reg = <0x9880 0x10>; + interrupt-controller; + #interrupt-cells = <2>; + interrupts = <64 65 66 67 68 79 70 71>; + }; + pinctrl_cbus: pinctrl at 9880 { compatible = "amlogic,meson8-cbus-pinctrl"; reg = <0x9880 0x10>;
arch/arm/boot/dts/meson8b.dtsi +8 -0
@@ -112,6 +112,14 @@ }; &cbus { + gpio_intc: interrupt-controller at 9880 { + compatible = "amlogic,meson-gpio-intc"; + reg = <0x9880 0x10>; + interrupt-controller; + #interrupt-cells = <2>; + interrupts = <64 65 66 67 68 79 70 71>; + }; + clkc: clock-controller at 4000 { #clock-cells = <1>; compatible = "amlogic,meson8b-clkc";
Signature · 1 line
2.13.1
PATCH v7 4/9 ARM64: dts: meson: add GPIO interrupt-controller support
In reply to Heiner KallweitAdd support for the GPIO interupt controller of certain Amlogic Meson Soc's.
---
v5:
- split ARM and ARM64 into separate patches
- added Reviewed-by
v6:
- change parent-interrupts to interrupts
v7:
- no changes
--- arch/arm64/boot/dts/amlogic/meson-gx.dtsi | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm64/boot/dts/amlogic/meson-gx.dtsi +8 -0
@@ -312,6 +312,14 @@ status = "disabled"; }; + gpio_intc: interrupt-controller at 9880 { + compatible = "amlogic,meson-gpio-intc"; + reg = <0x0 0x09880 0x0 0x10>; + interrupt-controller; + #interrupt-cells = <2>; + interrupts = <64 65 66 67 68 79 70 71>; + }; + watchdog at 98d0 { compatible = "amlogic,meson-gx-wdt", "amlogic,meson-gxbb-wdt"; reg = <0x0 0x098d0 0x0 0x10>;
Signature · 1 line
2.13.1
PATCH v7 5/9 gpiolib: export gpiochip_irq_reqres and gpiochip_irq_relres
In reply to Heiner KallweitCustomized versions of the request_resources and release_resources callbacks usually just extend what is available in gpiochip_irq_reqres and gpiochip_irq_relres. Therefore export them to make them available to gpio drivers.
--- drivers/gpio/gpiolib.c | 6 ++++-- include/linux/gpio/driver.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib.c +4 -2
@@ -1643,7 +1643,7 @@ static const struct irq_domain_ops gpiochip_domain_ops = { .xlate = irq_domain_xlate_twocell, }; -static int gpiochip_irq_reqres (struct irq_data *d) +int gpiochip_irq_reqres (struct irq_data *d) {struct gpio_chip *chip =irq_data_get_irq_chip_data (d);
@@ -1659,14 +1659,16 @@ static int gpiochip_irq_reqres(struct irq_data *d) }return 0 ; } +EXPORT_SYMBOL_GPL (gpiochip_irq_reqres); -static void gpiochip_irq_relres (struct irq_data *d) +void gpiochip_irq_relres (struct irq_data *d) {struct gpio_chip *chip =irq_data_get_irq_chip_data (d);gpiochip_unlock_as_irq (chip, d->hwirq);module_put (chip->gpiodev->owner); } +EXPORT_SYMBOL_GPL (gpiochip_irq_relres);static int gpiochip_to_irq (struct gpio_chip *chip,unsigned offset) {
include/linux/gpio/driver.h +3 -0
@@ -262,6 +262,9 @@ int gpiochip_irqchip_add_key(struct gpio_chip *gpiochip,bool nested, struct lock_class_key *lock_key); +int gpiochip_irq_reqres (struct irq_data *d); +void gpiochip_irq_relres (struct irq_data *d); +#ifdef CONFIG_LOCKDEP /*
Signature · 1 line
2.13.1
PATCH v7 5/9 gpiolib: export gpiochip_irq_reqres and gpiochip_irq_relres
Quoted 6 lines · Heiner Kallweit
Customized versions of the
request_resourcesandrelease_resourcescallbacks usually just extend what is available ingpiochip_irq_reqresandgpiochip_irq_relres. Therefore export them to make them available to gpio drivers.Signed-off-by Heiner Kallweit <[email protected]>
I'm not happy with this patch.
The gpiolib IRQchip abstraction was created to pull common code into the gpiolib library so I get less mess of GPIO IRQ drivers spread out all over the place.
This does the reverse and start to spread it all over the place again.
Can you think about a way to try to centralize what you are trying to do into the gpiolib with a flag or special registration call or similar?
I guess I don't understand the context, I guess this is part of the problem Jerome is discussing with me in another thread.
Yours,
Linus Walleij
PATCH v7 6/9 pinctrl: meson: add support for GPIO interrupts
In reply to Heiner KallweitAdd support for GPIO interrupts and make use of the just introduced irqchip driver handling the GPIO interrupt-controller.
---
v5:
- changed Kconfig entry based on Neil's suggestion
- extended comments
- fixed indentation
v6:
- no changes
v7:
- remove IRQ_TYPE_EDGE_BOTH support for now as it requires a somehwat hacky workaround
- smaller refactorings
--- drivers/pinctrl/Kconfig | 1 + drivers/pinctrl/meson/pinctrl-meson.c | 176 +++++++++++++++++++++++++++++++++- 2 files changed, 176 insertions(+), 1 deletion(-)
drivers/pinctrl/Kconfig +1 -0
@@ -167,6 +167,7 @@ config PINCTRL_MESON select PINCONF select GENERIC_PINCONF select GPIOLIB + select GPIOLIB_IRQCHIP select OF_GPIO select REGMAP_MMIO
drivers/pinctrl/meson/pinctrl-meson.c +175 -1
200 lines not on this page · raw message
Signature · 1 line
2.13.1
PATCH v7 7/9 pinctrl: meson: update DT binding documentation
In reply to Heiner KallweitThe GPIO controllers act as interrupt controllers now, therefore update the related DT binding documentation.
---
v5:
- separate documentation update from actual DT update
- add Reviewed-by
v6:
- add Acked-by
v7:
- no changes
--- Documentation/devicetree/bindings/pinctrl/meson,pinctrl.txt | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/pinctrl/meson,pinctrl.txt +4 -0
@@ -24,6 +24,8 @@ Required properties for sub-nodes are: when it is missing the "pull" registers are used instead - gpio-controller: identifies the node as a gpio controller - #gpio-cells: must be 2 + - interrupt-controller: identifies the node as interrupt controller + - #interrupt-cells: must be 2 === Other sub-nodes ===
@@ -62,6 +64,8 @@ pinctrl-bindings.txt reg-names = "mux", "pull", "pull-enable", "gpio"; gpio-controller; #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; }; nand {
Signature · 1 line
2.13.1
PATCH v7 8/9 ARM: dts: meson: mark gpio controllers as interrupt controllers
In reply to Heiner KallweitMake the GPIO controllers act as interrupt controllers.
---
v5:
- separate ARM / ARM64 DT changes
- add Reviewed-by
v6:
- no changes
v7:
- no changes
--- arch/arm/boot/dts/meson8.dtsi | 4 ++++ arch/arm/boot/dts/meson8b.dtsi | 4 ++++ 2 files changed, 8 insertions(+)
arch/arm/boot/dts/meson8.dtsi +4 -0
@@ -106,6 +106,8 @@ reg-names = "mux", "pull", "gpio"; gpio-controller; #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; gpio-ranges = <&pinctrl_aobus 0 120 16>; };
@@ -149,6 +151,8 @@ reg-names = "mux", "pull", "pull-enable", "gpio"; gpio-controller; #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; gpio-ranges = <&pinctrl_cbus 0 0 120>; };
arch/arm/boot/dts/meson8b.dtsi +4 -0
@@ -99,6 +99,8 @@ reg-names = "mux", "pull", "gpio"; gpio-controller; #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; gpio-ranges = <&pinctrl_aobus 0 130 16>; };
@@ -174,6 +176,8 @@ reg-names = "mux", "pull", "pull-enable", "gpio"; gpio-controller; #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; gpio-ranges = <&pinctrl_cbus 0 0 130>; }; };
Signature · 1 line
2.13.1
PATCH v7 9/9 ARM64: dts: meson: mark gpio controllers as interrupt controllers
In reply to Heiner KallweitMake the GPIO controllers act as interrupt controllers.
---
v5:
- separate ARM / ARM64 DT changes
- add Reviewed-by
v6:
- no changes
v7:
- no changes
--- arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 4 ++++ arch/arm64/boot/dts/amlogic/meson-gxl.dtsi | 4 ++++ 2 files changed, 8 insertions(+)
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +4 -0
@@ -111,6 +111,8 @@ reg-names = "mux", "pull", "gpio"; gpio-controller; #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; gpio-ranges = <&pinctrl_aobus 0 0 14>; };
@@ -370,6 +372,8 @@ reg-names = "mux", "pull", "pull-enable", "gpio"; gpio-controller; #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; gpio-ranges = <&pinctrl_periphs 0 14 120>; };
arch/arm64/boot/dts/amlogic/meson-gxl.dtsi +4 -0
@@ -80,6 +80,8 @@ reg-names = "mux", "pull", "gpio"; gpio-controller; #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; gpio-ranges = <&pinctrl_aobus 0 0 14>; };
@@ -258,6 +260,8 @@ reg-names = "mux", "pull", "pull-enable", "gpio"; gpio-controller; #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; gpio-ranges = <&pinctrl_periphs 0 10 101>; };
Signature · 1 line
2.13.1