diff mbox

[PATCH/RFC,v2] gpio: rcar: Add Runtime PM handling for interrupts

Message ID 1455811590-15836-1-git-send-email-geert+renesas@glider.be
State New
Headers show

Commit Message

Geert Uytterhoeven Feb. 18, 2016, 4:06 p.m. UTC
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 <geert+renesas@glider.be>
---
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(+)

Comments

Linus Walleij Feb. 19, 2016, 9:18 a.m. UTC | #1
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
<geert+renesas@glider.be> 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 <geert+renesas@glider.be>
> ---
> 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
>
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marc Zyngier Feb. 19, 2016, 11:59 a.m. UTC | #2
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 <marc.zyngier@arm.com>

Thanks,

	M.
Linus Walleij Feb. 25, 2016, 9:07 a.m. UTC | #3
On Thu, Feb 18, 2016 at 5:06 PM, Geert Uytterhoeven
<geert+renesas@glider.be> 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 <geert+renesas@glider.be>

Patch applied with Marc's ACK.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Geert Uytterhoeven Feb. 25, 2016, 9:37 a.m. UTC | #4
Hi Linus,

On Thu, Feb 25, 2016 at 10:07 AM, Linus Walleij
<linus.walleij@linaro.org> wrote:
> On Thu, Feb 18, 2016 at 5:06 PM, Geert Uytterhoeven
> <geert+renesas@glider.be> 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 <geert+renesas@glider.be>
>
> 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 -- geert@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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij Feb. 25, 2016, 2:19 p.m. UTC | #5
On Thu, Feb 25, 2016 at 10:37 AM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> On Thu, Feb 25, 2016 at 10:07 AM, Linus Walleij
> <linus.walleij@linaro.org> wrote:
>> On Thu, Feb 18, 2016 at 5:06 PM, Geert Uytterhoeven
>> <geert+renesas@glider.be> 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 <geert+renesas@glider.be>
>>
>> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Geert Uytterhoeven Feb. 25, 2016, 2:26 p.m. UTC | #6
Hi Linus,

On Thu, Feb 25, 2016 at 3:19 PM, Linus Walleij <linus.walleij@linaro.org> wrote:
> On Thu, Feb 25, 2016 at 10:37 AM, Geert Uytterhoeven
> <geert@linux-m68k.org> wrote:
>> On Thu, Feb 25, 2016 at 10:07 AM, Linus Walleij
>> <linus.walleij@linaro.org> wrote:
>>> On Thu, Feb 18, 2016 at 5:06 PM, Geert Uytterhoeven
>>> <geert+renesas@glider.be> 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 <geert+renesas@glider.be>
>>>
>>> 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 -- geert@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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Laurent Pinchart April 11, 2016, 4:26 p.m. UTC | #7
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 <marc.zyngier@arm.com>

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)
[    6.265036] Backtrace: 
[    6.267535] [<c0014c98>] (dump_backtrace) from [<c0014fb0>] (show_stack+0x20/0x24)
[    6.275124]  r6:00000000 r5:00000000 r4:60000093 r3:00000000
[    6.280850] [<c0014f90>] (show_stack) from [<c01f614c>] (dump_stack+0x8c/0xac)
[    6.288105] [<c01f60c0>] (dump_stack) from [<c00510c8>] (___might_sleep+0x100/0x158)
[    6.295863]  r5:000003bb r4:c06ca340
[    6.299474] [<c0050fc8>] (___might_sleep) from [<c005118c>] (__might_sleep+0x6c/0xa8)
[    6.307317]  r4:c05b6a24
[    6.309880] [<c0051120>] (__might_sleep) from [<c02d971c>] (__pm_runtime_resume+0x98/0xa0)
[    6.318159]  r6:000000dc r5:00000004 r4:ea280010
[    6.322831] [<c02d9684>] (__pm_runtime_resume) from [<c02282c8>] (gpio_rcar_irq_request_resources+0x2c/0x34)
[    6.332674]  r7:00000000 r6:000000dc r5:e95b3c00 r4:e99f3c00
[    6.338397] [<c022829c>] (gpio_rcar_irq_request_resources) from [<c0077a88>] (__setup_irq+0x24c/0x5dc)
[    6.347724] [<c007783c>] (__setup_irq) from [<c0077ff4>] (request_threaded_irq+0xdc/0x180)
[    6.356004]  r10:bf0aabc8 r9:000000dc r8:e9bc3000 r7:c0075be8 r6:e99f3c00 r5:00002003
[    6.363905]  r4:e95b3c00
[    6.366466] [<c0077f18>] (request_threaded_irq) from [<c007a758>] (devm_request_threaded_irq+0x6c/0xac)
[    6.375874]  r10:ea2db810 r9:ea2db810 r8:00000000 r7:bf0aabc8 r6:000000dc r5:e9bc3000
[    6.383773]  r4:e95b3b50 r3:00002003
[    6.387410] [<c007a6ec>] (devm_request_threaded_irq) from [<bf0aab9c>] (mmc_gpiod_request_cd_irq+0xa4/0xd0 [mmc_core])
[    6.398121]  r10:ea2db800 r8:e9bc3000 r7:e9bed598 r6:000000dc r5:e9bed524 r4:e9bc3000
[    6.406065] [<bf0aaaf8>] (mmc_gpiod_request_cd_irq [mmc_core]) from [<bf09f3bc>] (mmc_start_host+0x70/0x90 [mmc_core])
[    6.416779]  r6:e9bc3300 r5:00000000 r4:e9bc3000
[    6.421476] [<bf09f34c>] (mmc_start_host [mmc_core]) from [<bf0a061c>] (mmc_add_host+0x54/0x78 [mmc_core])
[    6.431146]  r4:e9bc3000 r3:00000001
[    6.434782] [<bf0a05c8>] (mmc_add_host [mmc_core]) from [<bf134b3c>] (tmio_mmc_host_probe+0x3ac/0x450 [tmio_mmc_core])
[    6.445498]  r5:ffffffe0 r4:00000000
[    6.449119] [<bf134790>] (tmio_mmc_host_probe [tmio_mmc_core]) from [<bf1501e8>] (sh_mobile_sdhi_probe+0x198/0x414 [sh_mobile_sdhi])
[    6.461051]  r10:bf150d04 r9:e9bed598 r8:00000001 r7:ea2db810 r6:ea2db800 r5:e9bc3300
[    6.468958]  r4:e9bed590
[    6.471532] [<bf150050>] (sh_mobile_sdhi_probe [sh_mobile_sdhi]) from [<c02cf220>] (platform_drv_probe+0x60/0xc0)
[    6.481811]  r10:00000011 r9:00000000 r8:bf151464 r7:bf151464 r6:fffffdfb r5:ea2db810
[    6.489712]  r4:00000000
[    6.492271] [<c02cf1c0>] (platform_drv_probe) from [<c02ccf80>] (driver_probe_device+0x224/0x440)
[    6.501156]  r7:c06c45f8 r6:c08e2b44 r5:c08e2b3c r4:ea2db810
[    6.506878] [<c02ccd5c>] (driver_probe_device) from [<c02cd2a0>] (__driver_attach+0x104/0x128)
[    6.515508]  r10:00000000 r9:bf1514c0 r8:c06c4520 r7:00000000 r6:bf151464 r5:ea2db810
[    6.523411]  r4:ea2db844
[    6.525965] [<c02cd19c>] (__driver_attach) from [<c02cae04>] (bus_for_each_dev+0x64/0x98)
[    6.534156]  r6:c02cd19c r5:bf151464 r4:00000000 r3:00000000
[    6.539874] [<c02cada0>] (bus_for_each_dev) from [<c02cc5e4>] (driver_attach+0x2c/0x30)
[    6.547895]  r6:c06ace08 r5:ea294c80 r4:bf151464
[    6.552561] [<c02cc5b8>] (driver_attach) from [<c02cc264>] (bus_add_driver+0x18c/0x268)
[    6.560586] [<c02cc0d8>] (bus_add_driver) from [<c02cdf90>] (driver_register+0x88/0x104)
[    6.568691]  r8:bf153000 r7:00000001 r6:e9ba7a40 r5:c067cfc8 r4:bf151464
[    6.575464] [<c02cdf08>] (driver_register) from [<c02cef80>] (__platform_driver_register+0x50/0x54)
[    6.584523]  r5:c067cfc8 r4:c067cfc8
[    6.588141] [<c02cef30>] (__platform_driver_register) from [<bf153018>] (sh_mobile_sdhi_driver_init+0x18/0x24 [sh_mobile_sdhi])
[    6.599654] [<bf153000>] (sh_mobile_sdhi_driver_init [sh_mobile_sdhi]) from [<c000a884>] (do_one_initcall+0xc0/0x200)
[    6.610292] [<c000a7c4>] (do_one_initcall) from [<c00ccd28>] (do_init_module+0x70/0x1dc)
[    6.618398]  r10:000005fa r9:bf1514c0 r8:c00a1f28 r7:00000001 r6:e94f3fc0 r5:00000001
[    6.626299]  r4:bf1514c0
[    6.628860] [<c00cccb8>] (do_init_module) from [<c00a5368>] (load_module+0x19c8/0x2164)
[    6.636878]  r7:00000001 r6:e955ec00 r5:00000001 r4:e9b73f3c
[    6.642603] [<c00a39a0>] (load_module) from [<c00a5d38>] (SyS_finit_module+0xb0/0xe0)
[    6.650447]  r10:00000000 r9:e9b72000 r8:b6f75330 r7:00000009 r6:00000000 r5:00000000
[    6.658342]  r4:7fffffff
[    6.660901] [<c00a5c88>] (SyS_finit_module) from [<c0011940>] (ret_fast_syscall+0x0/0x34)
[    6.669093]  r8:c0011ae4 r7:0000017b r6:00000000 r5:00000000 r4:00020000

The .irq_request_resources() handler is called with a spinlock held, it thus
can't call the synchronous version of the PM runtime functions.
Marc Zyngier April 11, 2016, 4:55 p.m. UTC | #8
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 <marc.zyngier@arm.com>
> 
> 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.
Geert Uytterhoeven April 11, 2016, 5:18 p.m. UTC | #9
Hi Marc,

On Mon, Apr 11, 2016 at 6:55 PM, Marc Zyngier <marc.zyngier@arm.com> 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 <marc.zyngier@arm.com>
>>
>> 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 -- geert@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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij April 12, 2016, 8:06 a.m. UTC | #10
On Mon, Apr 11, 2016 at 7:18 PM, Geert Uytterhoeven
<geert@linux-m68k.org> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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);