From: Stephen Boyd <swboyd@chromium.org>
To: Evan Green <evgreen@chromium.org>,
Nicolas Boichat <drinkcat@chromium.org>
Cc: "moderated list:ARM/Mediatek SoC support"
<linux-mediatek@lists.infradead.org>,
Sean Wang <sean.wang@kernel.org>,
Linus Walleij <linus.walleij@linaro.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
linux-gpio@vger.kernel.org,
linux-arm Mailing List <linux-arm-kernel@lists.infradead.org>,
lkml <linux-kernel@vger.kernel.org>,
Chuanjia Liu <Chuanjia.Liu@mediatek.com>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH 2/2] pinctrl: mediatek: Update cur_mask in mask/mask ops
Date: Mon, 10 Jun 2019 15:25:53 -0700 [thread overview]
Message-ID: <5cfed8f2.1c69fb81.1dcd3.27c1@mx.google.com> (raw)
In-Reply-To: <CAE=gft6jxR9Lt7tLwm6VKy9_shMVW7wf3g6rBGEqtB7oNH0hUA@mail.gmail.com>
Quoting Evan Green (2019-05-30 10:12:03)
> On Wed, May 15, 2019 at 1:05 AM Nicolas Boichat <drinkcat@chromium.org> wrote:
> >
> > On Wed, May 15, 2019 at 4:14 AM Stephen Boyd <swboyd@chromium.org> wrote:
> >
> > > We could immediately unmask those lines in the hardware when the
> > > set_wake() callback is called. That way the genirq layer can use the
> > > driver to do what it wants with the hardware and the driver can make
> > > sure that set_wake() will always cause the wakeup interrupt to be
> > > delivered to genirq even when software has disabled it.
> > >
> > > But I think that there might be a problem with how genirq understands
> > > the masked state of a line when the wakeup implementation conflates
> > > masked state with wakeup armed state. Consider this call-flow:
> > >
> > > irq masked in hardware, IRQD_IRQ_MASKED is set
> > > enable_irq_wake()
> > > unmask_irq in hardware
> > > IRQD_WAKEUP_ARMED is set
> > > <suspend and wakeup from irq>
> > > handle_level_irq()
> > > mask_ack_irq()
> > > mask_irq()
> > > if (irqd_irq_masked()) -> returns true and skips masking!
> > > if (desc->irq_data.chip->irq_ack)
> > > ...
> > > irq_may_run()
> > > irq_pm_check_wakeup()
> > > irq_disable()
> > > mask_irq() -> does nothing again
> > >
> > > In the above flow, we never mask the irq because we thought it was
> > > already masked when it was disabled, but the irqchip implementation
> > > unmasked it to make wakeup work. Maybe we should always mask the irq if
> > > wakeup is armed and we're trying to call mask_irq()? Looks hacky.
> > >
> > > diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c
> > > index 51128bea3846..20257d528880 100644
> > > --- a/kernel/irq/chip.c
> > > +++ b/kernel/irq/chip.c
> > > @@ -411,7 +411,7 @@ static inline void mask_ack_irq(struct irq_desc *desc)
> > >
> > > void mask_irq(struct irq_desc *desc)
> > > {
> > > - if (irqd_irq_masked(&desc->irq_data))
> > > + if (!irqd_is_wakeup_armed(&desc->irq_data) && irqd_irq_masked(&desc->irq_data))
> > > return;
> > >
> > > if (desc->irq_data.chip->irq_mask) {
> >
> > I'm... really not sure what's the best approach here. But basically,
> > yes, if we can find a way to properly handle wake and interrupt
> > behaviour for drivers with a single mask, that'd be good.
> > IRQCHIP_MASK_ON_SUSPEND only seems to be doing half of the work, since
> > it does not cover the disable+wake source case.
> >
> > Thanks,
>
> I finally got around to studying this patch. This series seems okay to
> me. The underlying problem is really that the hardware IRQ enabled
> state is out of sync with what Linux thinks. This happens during
> suspend because Linux thinks the irq is disabled, but due to the
> hardware constraints on this platform, the interrupt has to be enabled
> for it to be a wake source. So the mtk driver re-enables the
> interrupt, and then has to find a way to get back in sync with Linux's
> IRQ mask state.
>
> One possible approach is mentioned above by Stephen: stop calling
> disable_irq in the cros EC driver. Then both linux and mtk agree the
> interrupt is enabled at suspend time. I think this ran into other
> problems though, where the EC gets its interrupt but is unable to
> silence it because the underlying SPI bus is still suspended.
Does this happen? I thought the interrupt would only be delivered once
all drivers have resumed from the noirq resume phase. Maybe the SPI
controller needs to resume there instead of in the normal resume path
and then this isn't a problem.
>
> The other approach, taken here, is to mask the interrupt when it first
> comes in, getting Linux and mtk back in agreement that yes, the
> interrupt is masked. Outside of enlightening the generic IRQ core
> about these types of interrupts that need to get re-enabled to be wake
> sources, this seems like a reasonable approach.
I prefer we teach the genirq layer about these types of irqchips. That
way the solution is common and not a one-off fix for Mediatek chips. I'm
sure that this same problem will come up again for another SoC vendor
out there so having a chip flag that does the other half of
IRQCHIP_MASK_ON_SUSPEND would be appropriate.
next prev parent reply other threads:[~2019-06-10 22:25 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-29 3:55 [PATCH 0/2] pinctrl: mediatek: Fix 2 issues related to resume from wake sources Nicolas Boichat
2019-04-29 3:55 ` [PATCH 1/2] pinctrl: mediatek: Ignore interrupts that are wake only during resume Nicolas Boichat
2019-06-21 4:47 ` Sean Wang
2019-06-25 13:50 ` Linus Walleij
2019-04-29 3:55 ` [PATCH 2/2] pinctrl: mediatek: Update cur_mask in mask/mask ops Nicolas Boichat
2019-05-13 22:29 ` Stephen Boyd
2019-05-14 1:37 ` Nicolas Boichat
2019-05-14 20:14 ` Stephen Boyd
2019-05-15 8:04 ` Nicolas Boichat
2019-05-30 17:12 ` Evan Green
2019-05-31 8:05 ` Chuanjia Liu
2019-05-31 17:17 ` Evan Green
2019-06-03 8:01 ` Chuanjia Liu
2019-06-04 0:57 ` Nicolas Boichat
2019-06-05 7:11 ` Chuanjia Liu
2019-06-10 22:25 ` Stephen Boyd [this message]
2019-06-21 4:20 ` Sean Wang
2019-06-25 13:52 ` Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5cfed8f2.1c69fb81.1dcd3.27c1@mx.google.com \
--to=swboyd@chromium.org \
--cc=Chuanjia.Liu@mediatek.com \
--cc=drinkcat@chromium.org \
--cc=evgreen@chromium.org \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=sean.wang@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).