From: Brian Norris <briannorris@chromium.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Chen Jeffy <jeffy.chen@rock-chips.com>,
Doug Anderson <dianders@chromium.org>,
Heiko Stuebner <heiko@sntech.de>,
"open list:ARM/Rockchip SoC..."
<linux-rockchip@lists.infradead.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
LKML <linux-kernel@vger.kernel.org>,
"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
Linux ARM <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH 2/2] gpio/rockchip: Toggle edge trigger mode after acking
Date: Mon, 29 Aug 2022 16:26:20 -0700 [thread overview]
Message-ID: <Yw1LHPKumlKRtGTR@google.com> (raw)
In-Reply-To: <CACRpkdY1jQH+-o6y84w0WtJT1erRnJzCcg0jjgRHVDUw4q97QQ@mail.gmail.com>
Hi Linus,
On Fri, Aug 26, 2022 at 10:54:08AM +0200, Linus Walleij wrote:
> On Tue, Aug 23, 2022 at 4:50 AM Chen Jeffy <jeffy.chen@rock-chips.com> wrote:
>
> > The thing is, we are currently toggling the trigger mode to make sure it
> > matches the current GPIO level (e.g. level low -> rising edge mode),
> > than ack it in gpio IRQ handler.
>
> Yes this is an old trick, I don't know if I invented it again for Linux in
> commit cc890cd78acd7ab03442907d354b6af34e973cb3
> in 2011, surely the trick must be well known.
>
> Back then I did it like this:
>
> + val = readl(U300_PIN_REG(offset, icr));
> + /* Set mode depending on state */
> + if (u300_gpio_get(&gpio->chip, offset)) {
> + /* High now, let's trigger on falling edge next then */
> + writel(val & ~U300_PIN_BIT(offset), U300_PIN_REG(offset, icr));
This looks pretty close to the right solution, but you still have a
race: a falling edge may happen right between the get() and the
writel(), and you'll miss it. You're in a little better shape than any
of the rockchip proposals so far, because at least you do the ACK before
this step (Rockchip doesn't). But you do still have a narrow race
window.
I think you need to iterate on this, and check the status again
afterward, looping until you are sure you either got it right, or are
leaving an edge still latched.
And at that point, I think you have the solution I recommended in my
other email :)
> + dev_dbg(gpio->dev, "next IRQ on falling edge on pin %d\n",
> + offset);
> + } else {
> + /* Low now, let's trigger on rising edge next then */
> + writel(val | U300_PIN_BIT(offset), U300_PIN_REG(offset, icr));
> + dev_dbg(gpio->dev, "next IRQ on rising edge on pin %d\n",
> + offset);
> + }
>
> Notice that I read the current level of the raw input to decide what the next
> trigger should be. The Rockchip driver does not do this, maybe that works
> better?
Actually, it does; that's what the 'ext_port' register is doing. The
question is when exactly to do this toggling -- before or after the ACK,
and with what sort of ordering to ensure you don't end up at the wrong
polarity when exiting.
Brian
prev parent reply other threads:[~2022-08-29 23:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-20 9:59 [PATCH 1/2] gpio/rockchip: Convert to generic_handle_domain_irq() Jeffy Chen
2022-08-20 9:59 ` [PATCH 2/2] gpio/rockchip: Toggle edge trigger mode after acking Jeffy Chen
2022-08-22 17:08 ` Doug Anderson
2022-08-23 2:50 ` Chen Jeffy
2022-08-23 18:50 ` Brian Norris
2022-08-26 8:54 ` Linus Walleij
2022-08-29 23:26 ` Brian Norris [this message]
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=Yw1LHPKumlKRtGTR@google.com \
--to=briannorris@chromium.org \
--cc=brgl@bgdev.pl \
--cc=dianders@chromium.org \
--cc=heiko@sntech.de \
--cc=jeffy.chen@rock-chips.com \
--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-rockchip@lists.infradead.org \
/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).