[PATCH/RFC v2] gpio: rcar: Add Runtime PM handling for interrupts
The R-Car GPIO driver handles Runtime PM for requested GPIOs only. When using a GPIO purely as an interrupt source, no Runtime PM handling is done, and the GPIO module's clock may not be enabled. To fix this: - Add .irq_request_resources() and .irq_release_resources() callbacks to handle Runtime PM when an interrupt is requested, - Add irq_bus_lock() and sync_unlock() callbacks to handle Runtime PM when e.g. disabling/enabling an interrupt, or configuring the interrupt type. Signed-off-by: Geert Uytterhoeven --- This fixes ravb Ethernet on r8a7795/Salvator-X, which was "broken" by commit d5c3d84657db57bd ("net: phy: Avoid polling PHY with PHY_IGNORE_INTERRUPTS"). Does it also fix the HDMI interrupt on r8a7791/Koelsch? v2: - Handle Runtime PM in .irq_bus_{lock,sync_unlock}() instead of .irq_{dis,en}able() and .irq_set_type(), - Drop WARN() checks, they were just for testing. In case of failures, please re-add WARN(pm_runtime_suspended(&p->pdev->dev), "%s: %s is runtime-suspended\n", __func__, dev_name(&p->pdev->dev)); to gpio_rcar_read() and gpio_rcar_write(). --- drivers/gpio/gpio-rcar.c | 42 ++ 1 file changed, 42 insertions(+) diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c index cf41440aff91971e..d9ab0cd1d2059635 100644 --- a/drivers/gpio/gpio-rcar.c +++ b/drivers/gpio/gpio-rcar.c @@ -196,6 +196,44 @@ static int gpio_rcar_irq_set_wake(struct irq_data *d, unsigned int on) return 0; } +static void gpio_rcar_irq_bus_lock(struct irq_data *d) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + struct gpio_rcar_priv *p = gpiochip_get_data(gc); + + pm_runtime_get_sync(&p->pdev->dev); +} + +static void gpio_rcar_irq_bus_sync_unlock(struct irq_data *d) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + struct gpio_rcar_priv *p = gpiochip_get_data(gc); + + pm_runtime_put(&p->pdev->dev); +} + + +static int gpio_rcar_irq_request_resources(struct irq_data *d) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + struct gpio_rcar_priv *p = gpiochip_get_data(gc); + int error; + + error = pm_runtime_get_sync(&p->pdev->dev); + if (error < 0) + return error; + + return 0; +} + +static void gpio_rcar_irq_release_resources(struct irq_data *d) +{ + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); + struct gpio_rcar_priv *p = gpiochip_get_data(gc); + + pm_runtime_put(&p->pdev->dev); +} + static irqreturn_t gpio_rcar_irq_handler(int irq, void *dev_id) { struct gpio_rcar_priv *p = dev_id; @@ -450,6 +488,10 @@ static int gpio_rcar_probe(struct platform_device *pdev) irq_chip->irq_unmask = gpio_rcar_irq_enable; irq_chip->irq_set_type = gpio_rcar_irq_set_type; irq_chip->irq_set_wake = gpio_rcar_irq_set_wake; + irq_chip->irq_bus_lock = gpio_rcar_irq_bus_lock; + irq_chip->irq_bus_sync_unlock = gpio_rcar_irq_bus_sync_unlock; + irq_chip->irq_request_resources = gpio_rcar_irq_request_resources; + irq_chip->irq_release_resources = gpio_rcar_irq_release_resources; irq_chip->flags = IRQCHIP_SET_TYPE_MASKED | IRQCHIP_MASK_ON_SUSPEND; ret = gpiochip_add_data(gpio_chip, p); -- 1.9.1
Re: [PATCH/RFC v2] gpio: rcar: Add Runtime PM handling for interrupts
Top-quoting so everyone on the new To:-line gets the context. I definately need an indication from an irqchip maintainer like tglx or Marc Z before I merge this. Also, as in reply to the previous letter, coordinate efforts with Jon Hunters similar problem space. Yours, Linus Walleij On Thu, Feb 18, 2016 at 5:06 PM, Geert Uytterhoeven wrote: > The R-Car GPIO driver handles Runtime PM for requested GPIOs only. > > When using a GPIO purely as an interrupt source, no Runtime PM handling > is done, and the GPIO module's clock may not be enabled. > > To fix this: > - Add .irq_request_resources() and .irq_release_resources() callbacks > to handle Runtime PM when an interrupt is requested, > - Add irq_bus_lock() and sync_unlock() callbacks to handle Runtime PM > when e.g. disabling/enabling an interrupt, or configuring the > interrupt type. > > Signed-off-by: Geert Uytterhoeven > --- > This fixes ravb Ethernet on r8a7795/Salvator-X, which was "broken" by > commit d5c3d84657db57bd ("net: phy: Avoid polling PHY with > PHY_IGNORE_INTERRUPTS"). > > Does it also fix the HDMI interrupt on r8a7791/Koelsch? > > v2: > - Handle Runtime PM in .irq_bus_{lock,sync_unlock}() instead of > .irq_{dis,en}able() and .irq_set_type(), > - Drop WARN() checks, they were just for testing. > In case of failures, please re-add > > WARN(pm_runtime_suspended(&p->pdev->dev), > "%s: %s is runtime-suspended\n", __func__, > dev_name(&p->pdev->dev)); > > to gpio_rcar_read() and gpio_rcar_write(). > --- > drivers/gpio/gpio-rcar.c | 42 ++ > 1 file changed, 42 insertions(+) > > diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c > index cf41440aff91971e..d9ab0cd1d2059635 100644 > --- a/drivers/gpio/gpio-rcar.c > +++ b/drivers/gpio/gpio-rcar.c > @@ -196,6 +196,44 @@ static int gpio_rcar_irq_set_wake(struct irq_data *d, > unsigned int on) > return 0; > } > > +static void gpio_rcar_irq_bus_lock(struct irq_data *d) > +{ > + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); > + struct gpio_rcar_priv *p = gpiochip_get_data(gc); > + > + pm_runtime_get_sync(&p->pdev->dev); > +} > + > +static void gpio_rcar_irq_bus_sync_unlock(struct irq_data *d) > +{ > + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); > + struct gpio_rcar_priv *p = gpiochip_get_data(gc); > + > + pm_runtime_put(&p->pdev->dev); > +} > + > + > +static int gpio_rcar_irq_request_resources(struct irq_data *d) > +{ > + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); > + struct gpio_rcar_priv *p = gpiochip_get_data(gc); > + int error; > + > + error = pm_runtime_get_sync(&p->pdev->dev); > + if (error < 0) > + return error; > + > + return 0; > +} > + > +static void gpio_rcar_irq_release_resources(struct irq_data *d) > +{ > + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); > + struct gpio_rcar_priv *p = gpiochip_get_data(gc); > + > + pm_runtime_put(&p->pdev->dev); > +} > + > static irqreturn_t gpio_rcar_irq_handler(int irq, void *dev_id) > { > struct gpio_rcar_priv *p = dev_id; > @@ -450,6 +488,10 @@ static int gpio_rcar_probe(struct platform_device *pdev) > irq_chip->irq_unmask = gpio_rcar_irq_enable; > irq_chip->irq_set_type = gpio_rcar_irq_set_type; > irq_chip->irq_set_wake = gpio_rcar_irq_set_wake; > + irq_chip->irq_bus_lock = gpio_rcar_irq_bus_lock; > + irq_chip->irq_bus_sync_unlock = gpio_rcar_irq_bus_sync_unlock; > + irq_chip->irq_request_resources = gpio_rcar_irq_request_resources; > + irq_chip->irq_release_resources = gpio_rcar_irq_release_resources; > irq_chip->flags = IRQCHIP_SET_TYPE_MASKED | IRQCHIP_MASK_ON_SUSPEND; > > ret = gpiochip_add_data(gpio_chip, p); > -- > 1.9.1 >
Re: [PATCH/RFC v2] gpio: rcar: Add Runtime PM handling for interrupts
Hi Linus, On 19/02/16 09:18, Linus Walleij wrote: > Top-quoting so everyone on the new To:-line gets the context. > > I definately need an indication from an irqchip maintainer like tglx or Marc Z > before I merge this. Also, as in reply to the previous letter, coordinate > efforts with Jon Hunters similar problem space. Seems pretty straightforward to me. Acked-by: Marc Zyngier Thanks, M. -- Jazz is not dead. It just smells funny...
Re: [PATCH/RFC v2] gpio: rcar: Add Runtime PM handling for interrupts
On Thu, Feb 18, 2016 at 5:06 PM, Geert Uytterhoeven wrote: > The R-Car GPIO driver handles Runtime PM for requested GPIOs only. > > When using a GPIO purely as an interrupt source, no Runtime PM handling > is done, and the GPIO module's clock may not be enabled. > > To fix this: > - Add .irq_request_resources() and .irq_release_resources() callbacks > to handle Runtime PM when an interrupt is requested, > - Add irq_bus_lock() and sync_unlock() callbacks to handle Runtime PM > when e.g. disabling/enabling an interrupt, or configuring the > interrupt type. > > Signed-off-by: Geert Uytterhoeven Patch applied with Marc's ACK. Yours, Linus Walleij
Re: [PATCH/RFC v2] gpio: rcar: Add Runtime PM handling for interrupts
Hi Linus, On Thu, Feb 25, 2016 at 10:07 AM, Linus Walleij wrote: > On Thu, Feb 18, 2016 at 5:06 PM, Geert Uytterhoeven > wrote: > >> The R-Car GPIO driver handles Runtime PM for requested GPIOs only. >> >> When using a GPIO purely as an interrupt source, no Runtime PM handling >> is done, and the GPIO module's clock may not be enabled. >> >> To fix this: >> - Add .irq_request_resources() and .irq_release_resources() callbacks >> to handle Runtime PM when an interrupt is requested, >> - Add irq_bus_lock() and sync_unlock() callbacks to handle Runtime PM >> when e.g. disabling/enabling an interrupt, or configuring the >> interrupt type. >> >> Signed-off-by: Geert Uytterhoeven > > Patch applied with Marc's ACK. Thanks! Can we have it in v4.5? Else Ethernet won't work on r8a7795/salvator-x. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH/RFC v2] gpio: rcar: Add Runtime PM handling for interrupts
On Thu, Feb 25, 2016 at 10:37 AM, Geert Uytterhoeven wrote: > On Thu, Feb 25, 2016 at 10:07 AM, Linus Walleij > wrote: >> On Thu, Feb 18, 2016 at 5:06 PM, Geert Uytterhoeven >> wrote: >> >>> The R-Car GPIO driver handles Runtime PM for requested GPIOs only. >>> >>> When using a GPIO purely as an interrupt source, no Runtime PM handling >>> is done, and the GPIO module's clock may not be enabled. >>> >>> To fix this: >>> - Add .irq_request_resources() and .irq_release_resources() callbacks >>> to handle Runtime PM when an interrupt is requested, >>> - Add irq_bus_lock() and sync_unlock() callbacks to handle Runtime PM >>> when e.g. disabling/enabling an interrupt, or configuring the >>> interrupt type. >>> >>> Signed-off-by: Geert Uytterhoeven >> >> Patch applied with Marc's ACK. > > Thanks! > > Can we have it in v4.5? Else Ethernet won't work on r8a7795/salvator-x. Argh that is late. But I'll move it over to the fixes branch... Yours, Linus Walleij
Re: [PATCH/RFC v2] gpio: rcar: Add Runtime PM handling for interrupts
Hi Linus, On Thu, Feb 25, 2016 at 3:19 PM, Linus Walleij wrote: > On Thu, Feb 25, 2016 at 10:37 AM, Geert Uytterhoeven > wrote: >> On Thu, Feb 25, 2016 at 10:07 AM, Linus Walleij >> wrote: >>> On Thu, Feb 18, 2016 at 5:06 PM, Geert Uytterhoeven >>> wrote: >>> The R-Car GPIO driver handles Runtime PM for requested GPIOs only. When using a GPIO purely as an interrupt source, no Runtime PM handling is done, and the GPIO module's clock may not be enabled. To fix this: - Add .irq_request_resources() and .irq_release_resources() callbacks to handle Runtime PM when an interrupt is requested, - Add irq_bus_lock() and sync_unlock() callbacks to handle Runtime PM when e.g. disabling/enabling an interrupt, or configuring the interrupt type. Signed-off-by: Geert Uytterhoeven >>> >>> Patch applied with Marc's ACK. >> >> Thanks! >> >> Can we have it in v4.5? Else Ethernet won't work on r8a7795/salvator-x. > > Argh that is late. But I'll move it over to the fixes branch... Thanks! The issue was exposed by commit d5c3d84657db57bd ("net: phy: Avoid polling PHY with PHY_IGNORE_INTERRUPTS"), which went upstream only in v4.5-rc3. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH/RFC v2] gpio: rcar: Add Runtime PM handling for interrupts
On Friday 19 Feb 2016 11:59:40 Marc Zyngier wrote: > On 19/02/16 09:18, Linus Walleij wrote: > > Top-quoting so everyone on the new To:-line gets the context. > > > > I definately need an indication from an irqchip maintainer like tglx or > > Marc Z before I merge this. Also, as in reply to the previous letter, > > coordinate efforts with Jon Hunters similar problem space. > > Seems pretty straightforward to me. > > Acked-by: Marc Zyngier Too straightforward to be correct :-/ [6.232681] BUG: sleeping function called from invalid context at /home/laurent/src/iob/renesas/linux/drivers/base/power/runtime.c:955 [6.244795] in_atomic(): 1, irqs_disabled(): 128, pid: 658, name: udevd [6.251429] CPU: 3 PID: 658 Comm: udevd Tainted: P4.6.0-rc3 #756 [6.258844] Hardware name: Generic R8A7790 (Flattened Device Tree) [6.265036] Backtrace: [6.267535] [] (dump_backtrace) from [] (show_stack+0x20/0x24) [6.275124] r6: r5: r4:6093 r3: [6.280850] [] (show_stack) from [] (dump_stack+0x8c/0xac) [6.288105] [] (dump_stack) from [] (___might_sleep+0x100/0x158) [6.295863] r5:03bb r4:c06ca340 [6.299474] [] (___might_sleep) from [] (__might_sleep+0x6c/0xa8) [6.307317] r4:c05b6a24 [6.309880] [] (__might_sleep) from [] (__pm_runtime_resume+0x98/0xa0) [6.318159] r6:00dc r5:0004 r4:ea280010 [6.322831] [] (__pm_runtime_resume) from [] (gpio_rcar_irq_request_resources+0x2c/0x34) [6.332674] r7: r6:00dc r5:e95b3c00 r4:e99f3c00 [6.338397] [] (gpio_rcar_irq_request_resources) from [] (__setup_irq+0x24c/0x5dc) [6.347724] [] (__setup_irq) from [] (request_threaded_irq+0xdc/0x180) [6.356004] r10:bf0aabc8 r9:00dc r8:e9bc3000 r7:c0075be8 r6:e99f3c00 r5:2003 [6.363905] r4:e95b3c00 [6.366466] [] (request_threaded_irq) from [] (devm_request_threaded_irq+0x6c/0xac) [6.375874] r10:ea2db810 r9:ea2db810 r8: r7:bf0aabc8 r6:00dc r5:e9bc3000 [6.383773] r4:e95b3b50 r3:2003 [6.387410] [] (devm_request_threaded_irq) from [] (mmc_gpiod_request_cd_irq+0xa4/0xd0 [mmc_core]) [6.398121] r10:ea2db800 r8:e9bc3000 r7:e9bed598 r6:00dc r5:e9bed524 r4:e9bc3000 [6.406065] [] (mmc_gpiod_request_cd_irq [mmc_core]) from [] (mmc_start_host+0x70/0x90 [mmc_core]) [6.416779] r6:e9bc3300 r5: r4:e9bc3000 [6.421476] [] (mmc_start_host [mmc_core]) from [] (mmc_add_host+0x54/0x78 [mmc_core]) [6.431146] r4:e9bc3000 r3:0001 [6.434782] [] (mmc_add_host [mmc_core]) from [] (tmio_mmc_host_probe+0x3ac/0x450 [tmio_mmc_core]) [6.445498] r5:ffe0 r4: [6.449119] [] (tmio_mmc_host_probe [tmio_mmc_core]) from [] (sh_mobile_sdhi_probe+0x198/0x414 [sh_mobile_sdhi]) [6.461051] r10:bf150d04 r9:e9bed598 r8:0001 r7:ea2db810 r6:ea2db800 r5:e9bc3300 [6.468958] r4:e9bed590 [6.471532] [] (sh_mobile_sdhi_probe [sh_mobile_sdhi]) from [] (platform_drv_probe+0x60/0xc0) [6.481811] r10:0011 r9: r8:bf151464 r7:bf151464 r6:fdfb r5:ea2db810 [6.489712] r4: [6.492271] [] (platform_drv_probe) from [] (driver_probe_device+0x224/0x440) [6.501156] r7:c06c45f8 r6:c08e2b44 r5:c08e2b3c r4:ea2db810 [6.506878] [] (driver_probe_device) from [] (__driver_attach+0x104/0x128) [6.515508] r10: r9:bf1514c0 r8:c06c4520 r7: r6:bf151464 r5:ea2db810 [6.523411] r4:ea2db844 [6.525965] [] (__driver_attach) from [] (bus_for_each_dev+0x64/0x98) [6.534156] r6:c02cd19c r5:bf151464 r4: r3: [6.539874] [] (bus_for_each_dev) from [] (driver_attach+0x2c/0x30) [6.547895] r6:c06ace08 r5:ea294c80 r4:bf151464 [6.552561] [] (driver_attach) from [] (bus_add_driver+0x18c/0x268) [6.560586] [] (bus_add_driver) from [] (driver_register+0x88/0x104) [6.568691] r8:bf153000 r7:0001 r6:e9ba7a40 r5:c067cfc8 r4:bf151464 [6.575464] [] (driver_register) from [] (__platform_driver_register+0x50/0x54) [6.584523] r5:c067cfc8 r4:c067cfc8 [6.588141] [] (__platform_driver_register) from [] (sh_mobile_sdhi_driver_init+0x18/0x24 [sh_mobile_sdhi]) [6.599654] [] (sh_mobile_sdhi_driver_init [sh_mobile_sdhi]) from [] (do_one_initcall+0xc0/0x200) [6.610292] [] (do_one_initcall) from [] (do_init_module+0x70/0x1dc) [6.618398] r10:05fa r9:bf1514c0 r8:c00a1f28 r7:0001 r6:e94f3fc0 r5:0001 [6.626299] r4:bf1514c0 [6.628860] [] (do_init_module) from [] (load_module+0x19c8/0x2164) [6.636878] r7:0001 r6:e955ec00 r5:0001 r4:e9b73f3c [6.642603] [] (load_module) from [] (SyS_finit_module+0xb0/0xe0) [6.650447] r10: r9:e9b72000 r8:b6f75330 r7:0009 r6: r5: [6.658342] r4:7fff [6.660901] [] (SyS_finit_module) from [] (ret_fast_syscall+0x0/0x34) [6.669093] r8:c0011ae4 r7:017b r6: r5: r4:0002 The .irq_request_resources() ha
Re: [PATCH/RFC v2] gpio: rcar: Add Runtime PM handling for interrupts
On 11/04/16 17:26, Laurent Pinchart wrote: > On Friday 19 Feb 2016 11:59:40 Marc Zyngier wrote: >> On 19/02/16 09:18, Linus Walleij wrote: >>> Top-quoting so everyone on the new To:-line gets the context. >>> >>> I definately need an indication from an irqchip maintainer like tglx or >>> Marc Z before I merge this. Also, as in reply to the previous letter, >>> coordinate efforts with Jon Hunters similar problem space. >> >> Seems pretty straightforward to me. >> >> Acked-by: Marc Zyngier > > Too straightforward to be correct :-/ > > [6.232681] BUG: sleeping function called from invalid context at > /home/laurent/src/iob/renesas/linux/drivers/base/power/runtime.c:955 > [6.244795] in_atomic(): 1, irqs_disabled(): 128, pid: 658, name: udevd > [6.251429] CPU: 3 PID: 658 Comm: udevd Tainted: P > 4.6.0-rc3 #756 > [6.258844] Hardware name: Generic R8A7790 (Flattened Device Tree) [...] Ah! That will teach me a lesson. > The .irq_request_resources() handler is called with a spinlock held, it thus > can't call the synchronous version of the PM runtime functions. OK, so we're back to square one. Is that just a matter of calling the non-synchronous version? My hunch is that it is not that simple... Geert? M. -- Jazz is not dead. It just smells funny...
Re: [PATCH/RFC v2] gpio: rcar: Add Runtime PM handling for interrupts
Hi Marc, On Mon, Apr 11, 2016 at 6:55 PM, Marc Zyngier wrote: > On 11/04/16 17:26, Laurent Pinchart wrote: >> On Friday 19 Feb 2016 11:59:40 Marc Zyngier wrote: >>> On 19/02/16 09:18, Linus Walleij wrote: Top-quoting so everyone on the new To:-line gets the context. I definately need an indication from an irqchip maintainer like tglx or Marc Z before I merge this. Also, as in reply to the previous letter, coordinate efforts with Jon Hunters similar problem space. >>> >>> Seems pretty straightforward to me. >>> >>> Acked-by: Marc Zyngier >> >> Too straightforward to be correct :-/ >> >> [6.232681] BUG: sleeping function called from invalid context at >> /home/laurent/src/iob/renesas/linux/drivers/base/power/runtime.c:955 >> [6.244795] in_atomic(): 1, irqs_disabled(): 128, pid: 658, name: udevd >> [6.251429] CPU: 3 PID: 658 Comm: udevd Tainted: P >> 4.6.0-rc3 #756 >> [6.258844] Hardware name: Generic R8A7790 (Flattened Device Tree) > > [...] > > Ah! That will teach me a lesson. > >> The .irq_request_resources() handler is called with a spinlock held, it thus >> can't call the synchronous version of the PM runtime functions. > > OK, so we're back to square one. Is that just a matter of calling the > non-synchronous version? My hunch is that it is not that simple... > > Geert? Unfortunately it's not that simple. The irqchip must be runtime-resumed before we can access its registers. I'm afraid we'll have to keep gpio-rcar runtime-resumed all the time, i.e. revert both of b26a719bdb ("gpio: rcar: Add Runtime PM handling for interrupts") 65194cb174 ("gpio: rcar: Fine-grained Runtime PM support") until Jon Hunter's "genirq: Add runtime power management support for IRQ chips" (and perhaps a few more patches from his series) is applied. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH/RFC v2] gpio: rcar: Add Runtime PM handling for interrupts
On Mon, Apr 11, 2016 at 7:18 PM, Geert Uytterhoeven wrote: > I'm afraid we'll have to keep gpio-rcar runtime-resumed all the time, > i.e. revert both of > b26a719bdb ("gpio: rcar: Add Runtime PM handling for interrupts") I have reverted this for fixes. > 65194cb174 ("gpio: rcar: Fine-grained Runtime PM support") I reverted this too, with some manual intervention. > until Jon Hunter's "genirq: Add runtime power management support for IRQ > chips" > (and perhaps a few more patches from his series) is applied. Yup let's try to solve the big picture problem with Jon. Yours, Linus Walleij