gpio / pinctrl: cherryview: Fix missing events from EC
Subsystems (4)
Mika Westerberg
maintainerv3 cover gpio / pinctrl: cherryview: Fix missing events from EC
Hi,
Up until now systems having Intel Cherryview/Braswell might lose GPEs (General Purpose Events) from EC (Embedded Controller) because the pinctrl driver masks all interrupt sources at probe time. I tried to fix this already in bcb48cca23ec ("pinctrl: cherryview: Do not mask all interrupts in probe") but it resulted that the irq core masked all the interrupts because now we pass handle_bad_irq() as default handler for the irqchip.
After reading again the hardware spec, I think I finally understand the problem correctly. In summary for southwest and north communities only the first 8 (or 16) wires can be used to generate interrupts. Rest are reserved for GPEs.
We fix this by excluding these only GPE capable wires from the IRQ domain of the gpiochip.
This first follows what LinusW suggested and adds irq_valid_mask for each gpiochip and then converts pinctrl-cherryview to use it.
Previous version of the patches and the discussion around this issue can be found here:
v2: http://www.spinics.net/lists/linux-gpio/msg16760.html
v1: https://lkml.org/lkml/2015/5/22/111
Changes from v2:
- Add irq_need_valid_mask flag that if set will make gpiochip_add_data() allocate irq_valid_mask for the chip.
- Drop gpiochip_irqchip_exclude_irq() in favor of directly using set_/clear_bit() in drivers.
- Use likely() annotation in gpiochip_irqchip_irq_valid().
- Changed ordering of last two patches because there is no dependency anymore.
Changes from v1:
- Only allocate irq_valid_mask when needed
- Provide gpiochip_irqchip_exclude_irq() helper which allows drivers to select which GPIOs to exclude.
- Use ->nrirqs in chv_gpio_irq_handler()
- Added patch to convert the driver to use devm_gpiochip_add_data() so we can just return if gpiochip_irqchip_exclude_irq() fails (and also this simplifies the driver).
Mika Westerberg (3):
gpiolib: Make it possible to exclude GPIOs from IRQ domain
pinctrl: cherryview: Do not add all southwest and north GPIOs to IRQ domain
pinctrl: cherryview: Convert to use devm_gpiochip_add_data()
Documentation/gpio/driver.txt | 6 +++ drivers/gpio/gpiolib.c | 66 ++++++++++++++++++++++++++++-- drivers/pinctrl/intel/pinctrl-cherryview.c | 55 ++++++++++++++++--------- include/linux/gpio/driver.h | 6 +++ 4 files changed, 111 insertions(+), 22 deletions(-)
Signature · 1 line
2.9.3
Mika Westerberg
maintainerPATCH v3 1/3 gpiolib: Make it possible to exclude GPIOs from IRQ domain
When using GPIO irqchip helpers to setup irqchip for a gpiolib based driver, it is not possible to select which GPIOs to add to the IRQ domain. Instead it just adds all GPIOs which is not always desired. For example there might be GPIOs that for some reason cannot generated normal interrupts at all.
To support this we add a flag irq_need_valid_mask to struct gpio_chip. When this flag is set the core allocates irq_valid_mask that holds one bit for each GPIO the chip has. By default all bits are set but drivers can manipulate this using set_bit() and clear_bit() accordingly.
Then when gpiochip_irqchip_add() is called, this mask is checked and all GPIOs with bit is set are added to the IRQ domain created for the GPIO chip.
--- Documentation/gpio/driver.txt | 6 ++++ drivers/gpio/gpiolib.c | 66 +++++++++++++++++++++++++++++++++++++++++-- include/linux/gpio/driver.h | 6 ++++ 3 files changed, 75 insertions(+), 3 deletions(-)
Documentation/gpio/driver.txt +6 -0
@@ -262,6 +262,12 @@ symbol: to the container using container_of(). (See Documentation/driver-model/design-patterns.txt) + If there is a need to exclude certain GPIOs from the IRQ domain, one can + set .irq_need_valid_mask of the gpiochip before gpiochip_add_data() is + called. This allocates .irq_valid_mask with as many bits set as there are + GPIOs in the chip. Drivers can exclude GPIOs by clearing bits from this + mask. The mask must be filled in before gpiochip_irqchip_add() is called. + * gpiochip_set_chained_irqchip(): sets up a chained irq handler for a gpio_chip from a parent IRQ and passes the struct gpio_chip* as handler data. (Notice handler data, since the irqchip data is likely used by the
drivers/gpio/gpiolib.c +63 -3
136 lines not on this page · raw message
include/linux/gpio/driver.h +6 -0
@@ -112,6 +112,10 @@ enum single_ended_mode {* initialization, provided by GPIO driver * @irq_parent: GPIO IRQ chip parent/bank linux irq number, * provided by GPIO driver +* @irq_need_valid_mask: If set core allocates @irq_valid_mask with all +* bits set to one +* @irq_valid_mask: If not %NULL holds bitmask of GPIOs which are valid to +* be included in IRQ domain of the chip * @lock_key: per GPIO IRQ chip lockdep class * * A gpio_chip can help platforms abstract various sources of GPIOs so
@@ -190,6 +194,8 @@ struct gpio_chip {irq_flow_handler_t irq_handler;unsigned int irq_default_type;int irq_parent; +bool irq_need_valid_mask; +unsigned long *irq_valid_mask;struct lock_class_key *lock_key;#endif
Signature · 1 line
2.9.3
Re: [PATCH v3 1/3] gpiolib: Make it possible to exclude GPIOs from IRQ domain
Quoted 11 lines · Mika Westerberg
When using GPIO irqchip helpers to setup irqchip for a gpiolib based driver, it is not possible to select which GPIOs to add to the IRQ domain. Instead it just adds all GPIOs which is not always desired. For example there might be GPIOs that for some reason cannot generated normal interrupts at all.
To support this we add a flag
irq_need_valid_maskto structgpio_chip. When this flag is set the core allocatesirq_valid_maskthat holds one bit for each GPIO the chip has. By default all bits are set but drivers can manipulate this usingset_bit()andclear_bit()accordingly.
Quoted 6 lines
Then when
gpiochip_irqchip_add()is called, this mask is checked and all GPIOs with bit is set are added to the IRQ domain created for the GPIO chip.Suggested-by Linus Walleij <[email protected]>Signed-off-by Mika Westerberg <[email protected]>
Yeps, exactly like this!
Patch applied.
Yours,
Linus Walleij
Mika Westerberg
maintainerPATCH v3 2/3 pinctrl: cherryview: Do not add all southwest and north GPIOs to IRQ domain
In reply to Mika WesterbergIt turns out that for north and southwest communities, they can only generate GPIO interrupts for lower 8 interrupts (IntSel value). The upper part (8-15) can only generate GPEs (General Purpose Events).
Now the reason why EC events such as pressing hotkeys does not work if we mask all the interrupts is that in order to generate either interrupts or GPEs the INTMASK register must have that particular interrupt unmasked. In case of GPEs the CPU does not trigger normal interrupt (and thus the GPIO driver does not see it) but instead it causes SCI (System Control Interrupt) to be triggered with the GPE in question set.
To make this all work as expected we only add those GPIOs to the IRQ domain that can actually generate interrupts (IntSel value 0-7) and skip others.
--- drivers/pinctrl/intel/pinctrl-cherryview.c | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
drivers/pinctrl/intel/pinctrl-cherryview.c +33 -1
@@ -134,6 +134,7 @@ struct chv_gpio_pinrange {* @gpio_ranges: An array of GPIO ranges in this community * @ngpio_ranges: Number of GPIO ranges * @ngpios: Total number of GPIOs in this community +* @nirqs: Total number of IRQs this community can generate */ struct chv_community {const char *uid;
@@ -146,6 +147,7 @@ struct chv_community {const struct chv_gpio_pinrange *gpio_ranges;size_t ngpio_ranges;size_t ngpios; +size_t nirqs; };struct chv_pin_context {
@@ -396,6 +398,12 @@ static const struct chv_community southwest_community = { .gpio_ranges = southwest_gpio_ranges, .ngpio_ranges = ARRAY_SIZE(southwest_gpio_ranges), .ngpios = ARRAY_SIZE(southwest_pins), +/* +* Southwest community can benerate GPIO interrupts only for the +* first 8 interrupts. The upper half (8-15) can only be used to +* trigger GPEs. +*/ + .nirqs = 8, };static const struct pinctrl_pin_desc north_pins[] = {
@@ -479,6 +487,12 @@ static const struct chv_community north_community = { .gpio_ranges = north_gpio_ranges, .ngpio_ranges = ARRAY_SIZE(north_gpio_ranges), .ngpios = ARRAY_SIZE(north_pins), +/* +* North community can benerate GPIO interrupts only for the first +* 8 interrupts. The upper half (8-15) can only be used to trigger +* GPEs. +*/ + .nirqs = 8, };static const struct pinctrl_pin_desc east_pins[] = {
@@ -521,6 +535,7 @@ static const struct chv_community east_community = { .gpio_ranges = east_gpio_ranges, .ngpio_ranges = ARRAY_SIZE(east_gpio_ranges), .ngpios = ARRAY_SIZE(east_pins), + .nirqs = 16, };static const struct pinctrl_pin_desc southeast_pins[] = {
@@ -646,6 +661,7 @@ static const struct chv_community southeast_community = { .gpio_ranges = southeast_gpio_ranges, .ngpio_ranges = ARRAY_SIZE(southeast_gpio_ranges), .ngpios = ARRAY_SIZE(southeast_pins), + .nirqs = 16, };static const struct chv_community *chv_communities[] = {
@@ -1497,7 +1513,7 @@ static void chv_gpio_irq_handler(struct irq_desc *desc)chained_irq_enter (chip, desc); pending =readl (pctrl->regs +CHV_INTSTAT ); -for_each_set_bit (intr_line, &pending,16 ) { +for_each_set_bit (intr_line, &pending, pctrl->community->nirqs) {unsigned irq, offset; offset = pctrl->intr_lines[intr_line];
@@ -1520,6 +1536,7 @@ static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq) chip->label =dev_name (pctrl->dev); chip->parent = pctrl->dev; chip->base =-1 ; + chip->irq_need_valid_mask = true; ret =gpiochip_add_data (chip, pctrl);if (ret) {
@@ -1539,6 +1556,21 @@ static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq) offset += range->npins; } +/* Do not add GPIOs that can only generate GPEs to the IRQ domain */ +for (i =0 ; i < pctrl->community->npins; i++) { +const struct pinctrl_pin_desc *desc; +u32 intsel; + + desc = &pctrl->community->pins[i]; + + intsel =readl (chv_padreg (pctrl, desc->number,CHV_PADCTRL0 )); + intsel &=CHV_PADCTRL0_INTSEL_MASK ; + intsel >>=CHV_PADCTRL0_INTSEL_SHIFT ; + +if (intsel >= pctrl->community->nirqs) +clear_bit (i, chip->irq_valid_mask); + } +/* Clear all interrupts */ chv_writel (0xffff , pctrl->regs +CHV_INTSTAT );
Signature · 1 line
2.9.3
Re: [PATCH v3 2/3] pinctrl: cherryview: Do not add all southwest and north GPIOs to IRQ domain
Quoted 11 lines · Mika Westerberg
It turns out that for north and southwest communities, they can only generate GPIO interrupts for lower 8 interrupts (IntSel value). The upper part (8-15) can only generate GPEs (General Purpose Events).
Now the reason why EC events such as pressing hotkeys does not work if we mask all the interrupts is that in order to generate either interrupts or GPEs the INTMASK register must have that particular interrupt unmasked. In case of GPEs the CPU does not trigger normal interrupt (and thus the GPIO driver does not see it) but instead it causes SCI (System Control Interrupt) to be triggered with the GPE in question set.
Quoted 4 lines
To make this all work as expected we only add those GPIOs to the IRQ domain that can actually generate interrupts (IntSel value 0-7) and skip others.
Signed-off-by Mika Westerberg <[email protected]>
Patch applied, had to merge in the recent fix from -rc6 first but after that it applied cleanly. Check the result please!
Yours,
Linus Walleij
Mika Westerberg
maintainerRe: [PATCH v3 2/3] pinctrl: cherryview: Do not add all southwest and north GPIOs to IRQ domain
Quoted 14 lines · Linus Walleij
Quoted 11 lines · Mika Westerberg
It turns out that for north and southwest communities, they can only generate GPIO interrupts for lower 8 interrupts (IntSel value). The upper part (8-15) can only generate GPEs (General Purpose Events).
Now the reason why EC events such as pressing hotkeys does not work if we mask all the interrupts is that in order to generate either interrupts or GPEs the INTMASK register must have that particular interrupt unmasked. In case of GPEs the CPU does not trigger normal interrupt (and thus the GPIO driver does not see it) but instead it causes SCI (System Control Interrupt) to be triggered with the GPE in question set.
Quoted 7 lines
Quoted 4 lines
To make this all work as expected we only add those GPIOs to the IRQ domain that can actually generate interrupts (IntSel value 0-7) and skip others.
Signed-off-by Mika Westerberg <[email protected]>Patch applied, had to merge in the recent fix from -rc6 first but after that it applied cleanly. Check the result please!
Looks good, thanks.
Mika Westerberg
maintainerPATCH v3 3/3 pinctrl: cherryview: Convert to use devm_gpiochip_add_data()
In reply to Mika WesterbergThis simplifies the error handling and allows us to drop the whole chv_pinctrl_remove() function.
--- drivers/pinctrl/intel/pinctrl-cherryview.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-)
drivers/pinctrl/intel/pinctrl-cherryview.c +3 -18
@@ -1538,7 +1538,7 @@ static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq) chip->base =-1 ; chip->irq_need_valid_mask = true; - ret =gpiochip_add_data (chip, pctrl); + ret =devm_gpiochip_add_data (pctrl->dev, chip, pctrl);if (ret) {dev_err (pctrl->dev,"Failed to register gpiochip\n" );return ret;
@@ -1550,7 +1550,7 @@ static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq) range->base, range->npins);if (ret) {dev_err (pctrl->dev,"failed to add GPIO pin range\n" ); - goto fail; +return ret; } offset += range->npins;
@@ -1578,17 +1578,12 @@ static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq) handle_bad_irq, IRQ_TYPE_NONE);if (ret) {dev_err (pctrl->dev,"failed to add IRQ chip\n" ); - goto fail; +return ret; }gpiochip_set_chained_irqchip (chip, &chv_gpio_irqchip, irq, chv_gpio_irq_handler);return 0 ; - -fail: -gpiochip_remove (chip); - -return ret; }static int chv_pinctrl_probe (struct platform_device *pdev)
@@ -1656,15 +1651,6 @@ static int chv_pinctrl_probe(struct platform_device *pdev)return 0 ; } -static int chv_pinctrl_remove (struct platform_device *pdev) -{ -struct chv_pinctrl *pctrl =platform_get_drvdata (pdev); - -gpiochip_remove (&pctrl->chip); - -return 0 ; -} -#ifdef CONFIG_PM_SLEEP static int chv_pinctrl_suspend (struct device *dev) {
@@ -1761,7 +1747,6 @@ MODULE_DEVICE_TABLE(acpi, chv_pinctrl_acpi_match);static struct platform_driver chv_pinctrl_driver = { .probe = chv_pinctrl_probe, - .remove = chv_pinctrl_remove, .driver = { .name ="cherryview-pinctrl" , .pm = &chv_pinctrl_pm_ops,
Signature · 1 line
2.9.3
Re: [PATCH v3 3/3] pinctrl: cherryview: Convert to use devm_gpiochip_add_data()
Quoted 4 lines · Mika Westerberg
This simplifies the error handling and allows us to drop the whole
chv_pinctrl_remove()function.Signed-off-by Mika Westerberg <[email protected]>
Patch applied!
Yours,
Linus Walleij
Sorry for late response, the fix works like a charm :), thank you very much!