linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: mediatek: Fix trigger type setting follow for unexpected interrupt
@ 2021-01-21  3:17 Hailong Fan
  0 siblings, 0 replies; 4+ messages in thread
From: Hailong Fan @ 2021-01-21  3:17 UTC (permalink / raw)
  To: Sean Wang, Linus Walleij, Matthias Brugger
  Cc: linux-mediatek, linux-gpio, linux-arm-kernel, linux-kernel,
	youlin.pei, Nicolas Boichat, srv_heupstream, chentsung,
	gtk_pangao, hanks.chen, Hailong Fan

When flipping the polarity will be generated interrupt under certain
circumstances, but GPIO external signal has not changed.
Then, mask the interrupt before polarity setting, and clear the
unexpected interrupt after trigger type setting completed.

Signed-off-by: Hailong Fan <hailong.fan@mediatek.com>

Version: 5.11-rc1

---
 drivers/pinctrl/mediatek/mtk-eint.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/mediatek/mtk-eint.c b/drivers/pinctrl/mediatek/mtk-eint.c
index 22736f60c16c..3acda6bb401e 100644
--- a/drivers/pinctrl/mediatek/mtk-eint.c
+++ b/drivers/pinctrl/mediatek/mtk-eint.c
@@ -157,6 +157,7 @@ static void mtk_eint_ack(struct irq_data *d)
 static int mtk_eint_set_type(struct irq_data *d, unsigned int type)
 {
 	struct mtk_eint *eint = irq_data_get_irq_chip_data(d);
+	unsigned int unmask;
 	u32 mask = BIT(d->hwirq & 0x1f);
 	void __iomem *reg;
 
@@ -173,6 +174,13 @@ static int mtk_eint_set_type(struct irq_data *d, unsigned int type)
 	else
 		eint->dual_edge[d->hwirq] = 0;
 
+	if (!mtk_eint_get_mask(eint, d->hwirq)) {
+		mtk_eint_mask(d);
+		unmask = 1;
+	} else {
+		unmask = 0;
+	}
+
 	if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_EDGE_FALLING)) {
 		reg = mtk_eint_get_offset(eint, d->hwirq, eint->regs->pol_clr);
 		writel(mask, reg);
@@ -189,8 +197,9 @@ static int mtk_eint_set_type(struct irq_data *d, unsigned int type)
 		writel(mask, reg);
 	}
 
-	if (eint->dual_edge[d->hwirq])
-		mtk_eint_flip_edge(eint, d->hwirq);
+	mtk_eint_ack(d);
+	if (unmask == 1)
+		mtk_eint_unmask(d);
 
 	return 0;
 }
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] pinctrl: mediatek: Fix trigger type setting follow for unexpected interrupt
  2021-01-25  3:24 ` Nicolas Boichat
@ 2021-01-25  4:18   ` mtk15103
  0 siblings, 0 replies; 4+ messages in thread
From: mtk15103 @ 2021-01-25  4:18 UTC (permalink / raw)
  To: Nicolas Boichat
  Cc: Sean Wang, Linus Walleij, Matthias Brugger,
	moderated list:ARM/Mediatek SoC support,
	open list:GPIO SUBSYSTEM, linux-arm Mailing List, lkml,
	youlin.pei, srv_heupstream, Chen-Tsung Hsieh, gtk_pangao,
	Hanks Chen, Yong Wu

On Mon, 2021-01-25 at 11:24 +0800, Nicolas Boichat wrote:
> On Mon, Jan 25, 2021 at 11:15 AM Hailong Fan <hailong.fan@mediatek.com> wrote:
> >
> > When flipping the polarity will be generated interrupt under certain
> > circumstances, but GPIO external signal has not changed.
> > Then, mask the interrupt before polarity setting, and clear the
> > unexpected interrupt after trigger type setting completed.
> 
> I'd add a short note about why you remove mtk_eint_flip_edge, that is,
> because mtk_eint_unmask already calls it.
Add it on V3, thx.
 
> >
> > Signed-off-by: Hailong Fan <hailong.fan@mediatek.com>
> > ---
> > [V2]
> > ---
> >  drivers/pinctrl/mediatek/mtk-eint.c | 13 +++++++++++--
> >  1 file changed, 11 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/pinctrl/mediatek/mtk-eint.c b/drivers/pinctrl/mediatek/mtk-eint.c
> > index 22736f60c16c..0042f32c7e7e 100644
> > --- a/drivers/pinctrl/mediatek/mtk-eint.c
> > +++ b/drivers/pinctrl/mediatek/mtk-eint.c
> > @@ -157,6 +157,7 @@ static void mtk_eint_ack(struct irq_data *d)
> >  static int mtk_eint_set_type(struct irq_data *d, unsigned int type)
> >  {
> >         struct mtk_eint *eint = irq_data_get_irq_chip_data(d);
> > +       bool unmasked;
> 
> Well, this is true if the interrupt has been masked (or, equivalently,
> if we need to unmask it later).
> 
> So I think either "masked" or "unmask" are better as variable names.
Yes, masked is better.
> 
> >         u32 mask = BIT(d->hwirq & 0x1f);
> >         void __iomem *reg;
> >
> > @@ -173,6 +174,13 @@ static int mtk_eint_set_type(struct irq_data *d, unsigned int type)
> >         else
> >                 eint->dual_edge[d->hwirq] = 0;
> >
> > +       if (!mtk_eint_get_mask(eint, d->hwirq)) {
> > +               mtk_eint_mask(d);
> > +               unmasked = true;
> > +       } else {
> > +               unmasked = false;
> > +       }
> > +
> >         if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_EDGE_FALLING)) {
> >                 reg = mtk_eint_get_offset(eint, d->hwirq, eint->regs->pol_clr);
> >                 writel(mask, reg);
> > @@ -189,8 +197,9 @@ static int mtk_eint_set_type(struct irq_data *d, unsigned int type)
> >                 writel(mask, reg);
> >         }
> >
> > -       if (eint->dual_edge[d->hwirq])
> > -               mtk_eint_flip_edge(eint, d->hwirq);
> > +       mtk_eint_ack(d);
> > +       if (unmasked)
> > +               mtk_eint_unmask(d);
> >
> >         return 0;
> >  }
> > --
> > 2.18.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pinctrl: mediatek: Fix trigger type setting follow for unexpected interrupt
  2021-01-25  3:15 Hailong Fan
@ 2021-01-25  3:24 ` Nicolas Boichat
  2021-01-25  4:18   ` mtk15103
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Boichat @ 2021-01-25  3:24 UTC (permalink / raw)
  To: Hailong Fan
  Cc: Sean Wang, Linus Walleij, Matthias Brugger,
	moderated list:ARM/Mediatek SoC support,
	open list:GPIO SUBSYSTEM, linux-arm Mailing List, lkml,
	youlin.pei, srv_heupstream, Chen-Tsung Hsieh, gtk_pangao,
	Hanks Chen, Yong Wu

On Mon, Jan 25, 2021 at 11:15 AM Hailong Fan <hailong.fan@mediatek.com> wrote:
>
> When flipping the polarity will be generated interrupt under certain
> circumstances, but GPIO external signal has not changed.
> Then, mask the interrupt before polarity setting, and clear the
> unexpected interrupt after trigger type setting completed.

I'd add a short note about why you remove mtk_eint_flip_edge, that is,
because mtk_eint_unmask already calls it.

>
> Signed-off-by: Hailong Fan <hailong.fan@mediatek.com>
> ---
> [V2]
> ---
>  drivers/pinctrl/mediatek/mtk-eint.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pinctrl/mediatek/mtk-eint.c b/drivers/pinctrl/mediatek/mtk-eint.c
> index 22736f60c16c..0042f32c7e7e 100644
> --- a/drivers/pinctrl/mediatek/mtk-eint.c
> +++ b/drivers/pinctrl/mediatek/mtk-eint.c
> @@ -157,6 +157,7 @@ static void mtk_eint_ack(struct irq_data *d)
>  static int mtk_eint_set_type(struct irq_data *d, unsigned int type)
>  {
>         struct mtk_eint *eint = irq_data_get_irq_chip_data(d);
> +       bool unmasked;

Well, this is true if the interrupt has been masked (or, equivalently,
if we need to unmask it later).

So I think either "masked" or "unmask" are better as variable names.

>         u32 mask = BIT(d->hwirq & 0x1f);
>         void __iomem *reg;
>
> @@ -173,6 +174,13 @@ static int mtk_eint_set_type(struct irq_data *d, unsigned int type)
>         else
>                 eint->dual_edge[d->hwirq] = 0;
>
> +       if (!mtk_eint_get_mask(eint, d->hwirq)) {
> +               mtk_eint_mask(d);
> +               unmasked = true;
> +       } else {
> +               unmasked = false;
> +       }
> +
>         if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_EDGE_FALLING)) {
>                 reg = mtk_eint_get_offset(eint, d->hwirq, eint->regs->pol_clr);
>                 writel(mask, reg);
> @@ -189,8 +197,9 @@ static int mtk_eint_set_type(struct irq_data *d, unsigned int type)
>                 writel(mask, reg);
>         }
>
> -       if (eint->dual_edge[d->hwirq])
> -               mtk_eint_flip_edge(eint, d->hwirq);
> +       mtk_eint_ack(d);
> +       if (unmasked)
> +               mtk_eint_unmask(d);
>
>         return 0;
>  }
> --
> 2.18.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] pinctrl: mediatek: Fix trigger type setting follow for unexpected interrupt
@ 2021-01-25  3:15 Hailong Fan
  2021-01-25  3:24 ` Nicolas Boichat
  0 siblings, 1 reply; 4+ messages in thread
From: Hailong Fan @ 2021-01-25  3:15 UTC (permalink / raw)
  To: Sean Wang, Linus Walleij, Matthias Brugger
  Cc: linux-mediatek, linux-gpio, linux-arm-kernel, linux-kernel,
	youlin.pei, Nicolas Boichat, srv_heupstream, chentsung,
	gtk_pangao, hanks.chen, yong.wu, Hailong Fan

When flipping the polarity will be generated interrupt under certain
circumstances, but GPIO external signal has not changed.
Then, mask the interrupt before polarity setting, and clear the
unexpected interrupt after trigger type setting completed.

Signed-off-by: Hailong Fan <hailong.fan@mediatek.com>
---
[V2]
---
 drivers/pinctrl/mediatek/mtk-eint.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/mediatek/mtk-eint.c b/drivers/pinctrl/mediatek/mtk-eint.c
index 22736f60c16c..0042f32c7e7e 100644
--- a/drivers/pinctrl/mediatek/mtk-eint.c
+++ b/drivers/pinctrl/mediatek/mtk-eint.c
@@ -157,6 +157,7 @@ static void mtk_eint_ack(struct irq_data *d)
 static int mtk_eint_set_type(struct irq_data *d, unsigned int type)
 {
 	struct mtk_eint *eint = irq_data_get_irq_chip_data(d);
+	bool unmasked;
 	u32 mask = BIT(d->hwirq & 0x1f);
 	void __iomem *reg;
 
@@ -173,6 +174,13 @@ static int mtk_eint_set_type(struct irq_data *d, unsigned int type)
 	else
 		eint->dual_edge[d->hwirq] = 0;
 
+	if (!mtk_eint_get_mask(eint, d->hwirq)) {
+		mtk_eint_mask(d);
+		unmasked = true;
+	} else {
+		unmasked = false;
+	}
+
 	if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_EDGE_FALLING)) {
 		reg = mtk_eint_get_offset(eint, d->hwirq, eint->regs->pol_clr);
 		writel(mask, reg);
@@ -189,8 +197,9 @@ static int mtk_eint_set_type(struct irq_data *d, unsigned int type)
 		writel(mask, reg);
 	}
 
-	if (eint->dual_edge[d->hwirq])
-		mtk_eint_flip_edge(eint, d->hwirq);
+	mtk_eint_ack(d);
+	if (unmasked)
+		mtk_eint_unmask(d);
 
 	return 0;
 }
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-25  4:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-21  3:17 [PATCH] pinctrl: mediatek: Fix trigger type setting follow for unexpected interrupt Hailong Fan
2021-01-25  3:15 Hailong Fan
2021-01-25  3:24 ` Nicolas Boichat
2021-01-25  4:18   ` mtk15103

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