linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/1] pinctrl: intel: Fix a glitch when updating IRQ flags on a preconfigured line
@ 2022-01-19 18:19 Andy Shevchenko
  2022-01-20  7:44 ` Mika Westerberg
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2022-01-19 18:19 UTC (permalink / raw)
  To: Andy Shevchenko, linux-gpio, linux-kernel
  Cc: Mika Westerberg, Andy Shevchenko, Linus Walleij, Kane Chen

The commit af7e3eeb84e2 ("pinctrl: intel: Disable input and output buffer
when switching to GPIO") hadn't taken into account an update of the IRQ
flags scenario.

When updating the IRQ flags on the preconfigured line the ->irq_set_type()
is called again. In such case the sequential Rx buffer configuration
changes may trigger a falling or rising edge interrupt that may lead,
on some platforms, to an undesired event.

This may happen because each of intel_gpio_set_gpio_mode() and
__intel_gpio_set_direction() updates the pad configuration with a different
value of the GPIORXDIS bit. Notable, that the intel_gpio_set_gpio_mode() is
called only for the pads that are configured as an input. Due to this fact,
integrate the logic of __intel_gpio_set_direction() call into the
intel_gpio_set_gpio_mode() so that the Rx buffer won't be disabled and
immediately re-enabled.

Fixes: af7e3eeb84e2 ("pinctrl: intel: Disable input and output buffer when switching to GPIO")
Reported-by: Kane Chen <kane.chen@intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/intel/pinctrl-intel.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
index 7d8a7e7b0aef..4d718a928288 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.c
+++ b/drivers/pinctrl/intel/pinctrl-intel.c
@@ -451,8 +451,8 @@ static void intel_gpio_set_gpio_mode(void __iomem *padcfg0)
 	value &= ~PADCFG0_PMODE_MASK;
 	value |= PADCFG0_PMODE_GPIO;
 
-	/* Disable input and output buffers */
-	value |= PADCFG0_GPIORXDIS;
+	/* Disable TX buffer and enable RX (this will be input) */
+	value &= ~PADCFG0_GPIORXDIS;
 	value |= PADCFG0_GPIOTXDIS;
 
 	/* Disable SCI/SMI/NMI generation */
@@ -497,9 +497,6 @@ static int intel_gpio_request_enable(struct pinctrl_dev *pctldev,
 
 	intel_gpio_set_gpio_mode(padcfg0);
 
-	/* Disable TX buffer and enable RX (this will be input) */
-	__intel_gpio_set_direction(padcfg0, true);
-
 	raw_spin_unlock_irqrestore(&pctrl->lock, flags);
 
 	return 0;
@@ -1115,9 +1112,6 @@ static int intel_gpio_irq_type(struct irq_data *d, unsigned int type)
 
 	intel_gpio_set_gpio_mode(reg);
 
-	/* Disable TX buffer and enable RX (this will be input) */
-	__intel_gpio_set_direction(reg, true);
-
 	value = readl(reg);
 
 	value &= ~(PADCFG0_RXEVCFG_MASK | PADCFG0_RXINV);
-- 
2.34.1


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

* Re: [PATCH v1 1/1] pinctrl: intel: Fix a glitch when updating IRQ flags on a preconfigured line
  2022-01-19 18:19 [PATCH v1 1/1] pinctrl: intel: Fix a glitch when updating IRQ flags on a preconfigured line Andy Shevchenko
@ 2022-01-20  7:44 ` Mika Westerberg
  2022-01-24 13:36   ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Mika Westerberg @ 2022-01-20  7:44 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-gpio, linux-kernel, Andy Shevchenko, Linus Walleij,
	Kane Chen

On Wed, Jan 19, 2022 at 08:19:15PM +0200, Andy Shevchenko wrote:
> The commit af7e3eeb84e2 ("pinctrl: intel: Disable input and output buffer
> when switching to GPIO") hadn't taken into account an update of the IRQ
> flags scenario.
> 
> When updating the IRQ flags on the preconfigured line the ->irq_set_type()
> is called again. In such case the sequential Rx buffer configuration
> changes may trigger a falling or rising edge interrupt that may lead,
> on some platforms, to an undesired event.
> 
> This may happen because each of intel_gpio_set_gpio_mode() and
> __intel_gpio_set_direction() updates the pad configuration with a different
> value of the GPIORXDIS bit. Notable, that the intel_gpio_set_gpio_mode() is
> called only for the pads that are configured as an input. Due to this fact,
> integrate the logic of __intel_gpio_set_direction() call into the
> intel_gpio_set_gpio_mode() so that the Rx buffer won't be disabled and
> immediately re-enabled.
> 
> Fixes: af7e3eeb84e2 ("pinctrl: intel: Disable input and output buffer when switching to GPIO")
> Reported-by: Kane Chen <kane.chen@intel.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

Please mark this for stable too.

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

* Re: [PATCH v1 1/1] pinctrl: intel: Fix a glitch when updating IRQ flags on a preconfigured line
  2022-01-20  7:44 ` Mika Westerberg
@ 2022-01-24 13:36   ` Andy Shevchenko
  0 siblings, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2022-01-24 13:36 UTC (permalink / raw)
  To: Mika Westerberg
  Cc: linux-gpio, linux-kernel, Andy Shevchenko, Linus Walleij,
	Kane Chen

On Thu, Jan 20, 2022 at 09:44:52AM +0200, Mika Westerberg wrote:
> On Wed, Jan 19, 2022 at 08:19:15PM +0200, Andy Shevchenko wrote:
> > The commit af7e3eeb84e2 ("pinctrl: intel: Disable input and output buffer
> > when switching to GPIO") hadn't taken into account an update of the IRQ
> > flags scenario.
> > 
> > When updating the IRQ flags on the preconfigured line the ->irq_set_type()
> > is called again. In such case the sequential Rx buffer configuration
> > changes may trigger a falling or rising edge interrupt that may lead,
> > on some platforms, to an undesired event.
> > 
> > This may happen because each of intel_gpio_set_gpio_mode() and
> > __intel_gpio_set_direction() updates the pad configuration with a different
> > value of the GPIORXDIS bit. Notable, that the intel_gpio_set_gpio_mode() is
> > called only for the pads that are configured as an input. Due to this fact,
> > integrate the logic of __intel_gpio_set_direction() call into the
> > intel_gpio_set_gpio_mode() so that the Rx buffer won't be disabled and
> > immediately re-enabled.
> > 
> > Fixes: af7e3eeb84e2 ("pinctrl: intel: Disable input and output buffer when switching to GPIO")
> > Reported-by: Kane Chen <kane.chen@intel.com>
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> 
> Please mark this for stable too.

Pushed to my review and testing queue with the Grace Kao's tag, thanks!

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2022-01-24 13:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-19 18:19 [PATCH v1 1/1] pinctrl: intel: Fix a glitch when updating IRQ flags on a preconfigured line Andy Shevchenko
2022-01-20  7:44 ` Mika Westerberg
2022-01-24 13:36   ` Andy Shevchenko

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