* [PATCH] Revert "i2c: pxa: move to generic GPIO recovery"
@ 2023-11-10 9:30 Robert Marko
2023-11-10 9:44 ` Russell King (Oracle)
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Robert Marko @ 2023-11-10 9:30 UTC (permalink / raw)
To: andi.shyti, linux-i2c, linux-kernel, linux, linus.walleij, wsa,
codrin.ciubotariu
Cc: Robert Marko, stable
This reverts commit 0b01392c18b9993a584f36ace1d61118772ad0ca.
Conversion of PXA to generic I2C recovery, makes the I2C bus completely
lock up if recovery pinctrl is present in the DT and I2C recovery is
enabled.
So, until the generic I2C recovery can also work with PXA lets revert
to have working I2C and I2C recovery again.
Signed-off-by: Robert Marko <robert.marko@sartura.hr>
Cc: stable@vger.kernel.org # 5.11+
---
drivers/i2c/busses/i2c-pxa.c | 76 ++++++++++++++++++++++++++++++++----
1 file changed, 68 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 1d7648242749..76f79b68cef8 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -265,6 +265,9 @@ struct pxa_i2c {
u32 hs_mask;
struct i2c_bus_recovery_info recovery;
+ struct pinctrl *pinctrl;
+ struct pinctrl_state *pinctrl_default;
+ struct pinctrl_state *pinctrl_recovery;
};
#define _IBMR(i2c) ((i2c)->reg_ibmr)
@@ -1299,12 +1302,13 @@ static void i2c_pxa_prepare_recovery(struct i2c_adapter *adap)
*/
gpiod_set_value(i2c->recovery.scl_gpiod, ibmr & IBMR_SCLS);
gpiod_set_value(i2c->recovery.sda_gpiod, ibmr & IBMR_SDAS);
+
+ WARN_ON(pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_recovery));
}
static void i2c_pxa_unprepare_recovery(struct i2c_adapter *adap)
{
struct pxa_i2c *i2c = adap->algo_data;
- struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
u32 isr;
/*
@@ -1318,7 +1322,7 @@ static void i2c_pxa_unprepare_recovery(struct i2c_adapter *adap)
i2c_pxa_do_reset(i2c);
}
- WARN_ON(pinctrl_select_state(bri->pinctrl, bri->pins_default));
+ WARN_ON(pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_default));
dev_dbg(&i2c->adap.dev, "recovery: IBMR 0x%08x ISR 0x%08x\n",
readl(_IBMR(i2c)), readl(_ISR(i2c)));
@@ -1340,20 +1344,76 @@ static int i2c_pxa_init_recovery(struct pxa_i2c *i2c)
if (IS_ENABLED(CONFIG_I2C_PXA_SLAVE))
return 0;
- bri->pinctrl = devm_pinctrl_get(dev);
- if (PTR_ERR(bri->pinctrl) == -ENODEV) {
- bri->pinctrl = NULL;
+ i2c->pinctrl = devm_pinctrl_get(dev);
+ if (PTR_ERR(i2c->pinctrl) == -ENODEV)
+ i2c->pinctrl = NULL;
+ if (IS_ERR(i2c->pinctrl))
+ return PTR_ERR(i2c->pinctrl);
+
+ if (!i2c->pinctrl)
+ return 0;
+
+ i2c->pinctrl_default = pinctrl_lookup_state(i2c->pinctrl,
+ PINCTRL_STATE_DEFAULT);
+ i2c->pinctrl_recovery = pinctrl_lookup_state(i2c->pinctrl, "recovery");
+
+ if (IS_ERR(i2c->pinctrl_default) || IS_ERR(i2c->pinctrl_recovery)) {
+ dev_info(dev, "missing pinmux recovery information: %ld %ld\n",
+ PTR_ERR(i2c->pinctrl_default),
+ PTR_ERR(i2c->pinctrl_recovery));
+ return 0;
+ }
+
+ /*
+ * Claiming GPIOs can influence the pinmux state, and may glitch the
+ * I2C bus. Do this carefully.
+ */
+ bri->scl_gpiod = devm_gpiod_get(dev, "scl", GPIOD_OUT_HIGH_OPEN_DRAIN);
+ if (bri->scl_gpiod == ERR_PTR(-EPROBE_DEFER))
+ return -EPROBE_DEFER;
+ if (IS_ERR(bri->scl_gpiod)) {
+ dev_info(dev, "missing scl gpio recovery information: %pe\n",
+ bri->scl_gpiod);
+ return 0;
+ }
+
+ /*
+ * We have SCL. Pull SCL low and wait a bit so that SDA glitches
+ * have no effect.
+ */
+ gpiod_direction_output(bri->scl_gpiod, 0);
+ udelay(10);
+ bri->sda_gpiod = devm_gpiod_get(dev, "sda", GPIOD_OUT_HIGH_OPEN_DRAIN);
+
+ /* Wait a bit in case of a SDA glitch, and then release SCL. */
+ udelay(10);
+ gpiod_direction_output(bri->scl_gpiod, 1);
+
+ if (bri->sda_gpiod == ERR_PTR(-EPROBE_DEFER))
+ return -EPROBE_DEFER;
+
+ if (IS_ERR(bri->sda_gpiod)) {
+ dev_info(dev, "missing sda gpio recovery information: %pe\n",
+ bri->sda_gpiod);
return 0;
}
- if (IS_ERR(bri->pinctrl))
- return PTR_ERR(bri->pinctrl);
bri->prepare_recovery = i2c_pxa_prepare_recovery;
bri->unprepare_recovery = i2c_pxa_unprepare_recovery;
+ bri->recover_bus = i2c_generic_scl_recovery;
i2c->adap.bus_recovery_info = bri;
- return 0;
+ /*
+ * Claiming GPIOs can change the pinmux state, which confuses the
+ * pinctrl since pinctrl's idea of the current setting is unaffected
+ * by the pinmux change caused by claiming the GPIO. Work around that
+ * by switching pinctrl to the GPIO state here. We do it this way to
+ * avoid glitching the I2C bus.
+ */
+ pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_recovery);
+
+ return pinctrl_select_state(i2c->pinctrl, i2c->pinctrl_default);
}
static int i2c_pxa_probe(struct platform_device *dev)
--
2.41.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Revert "i2c: pxa: move to generic GPIO recovery"
2023-11-10 9:30 [PATCH] Revert "i2c: pxa: move to generic GPIO recovery" Robert Marko
@ 2023-11-10 9:44 ` Russell King (Oracle)
2023-11-10 11:30 ` Andi Shyti
2023-11-10 15:03 ` Linus Walleij
2023-11-13 1:53 ` Wolfram Sang
2 siblings, 1 reply; 5+ messages in thread
From: Russell King (Oracle) @ 2023-11-10 9:44 UTC (permalink / raw)
To: Robert Marko
Cc: andi.shyti, linux-i2c, linux-kernel, linus.walleij, wsa,
codrin.ciubotariu, stable
On Fri, Nov 10, 2023 at 10:30:11AM +0100, Robert Marko wrote:
> This reverts commit 0b01392c18b9993a584f36ace1d61118772ad0ca.
>
> Conversion of PXA to generic I2C recovery, makes the I2C bus completely
> lock up if recovery pinctrl is present in the DT and I2C recovery is
> enabled.
>
> So, until the generic I2C recovery can also work with PXA lets revert
> to have working I2C and I2C recovery again.
>
> Signed-off-by: Robert Marko <robert.marko@sartura.hr>
> Cc: stable@vger.kernel.org # 5.11+
My feels were that this should not have been converted to the generic
recovery as pointed out at the time, so thanks for confirming that it
broke as a result of that conversion, it did indeed break.
Acked-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Thanks!
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Revert "i2c: pxa: move to generic GPIO recovery"
2023-11-10 9:44 ` Russell King (Oracle)
@ 2023-11-10 11:30 ` Andi Shyti
0 siblings, 0 replies; 5+ messages in thread
From: Andi Shyti @ 2023-11-10 11:30 UTC (permalink / raw)
To: Russell King (Oracle)
Cc: Robert Marko, linux-i2c, linux-kernel, linus.walleij, wsa,
codrin.ciubotariu, stable
Hi Marko,
On Fri, Nov 10, 2023 at 09:44:08AM +0000, Russell King (Oracle) wrote:
> On Fri, Nov 10, 2023 at 10:30:11AM +0100, Robert Marko wrote:
> > This reverts commit 0b01392c18b9993a584f36ace1d61118772ad0ca.
> >
> > Conversion of PXA to generic I2C recovery, makes the I2C bus completely
> > lock up if recovery pinctrl is present in the DT and I2C recovery is
> > enabled.
> >
> > So, until the generic I2C recovery can also work with PXA lets revert
> > to have working I2C and I2C recovery again.
Reverts are never nice, but if you are confirming this doesn't
work I can't do anything else than acking and bringing the driver
back to a working status.
Acked-by: Andi Shyti <andi.shyti@kernel.org>
I would have preferred a different fix, directly in the generic
i2c recovery, but this goes beyond the scope of the patch.
> > Signed-off-by: Robert Marko <robert.marko@sartura.hr>
> > Cc: stable@vger.kernel.org # 5.11+
>
> My feels were that this should not have been converted to the generic
> recovery as pointed out at the time, so thanks for confirming that it
> broke as a result of that conversion, it did indeed break.
>
> Acked-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Thanks Russel!
Andi
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Revert "i2c: pxa: move to generic GPIO recovery"
2023-11-10 9:30 [PATCH] Revert "i2c: pxa: move to generic GPIO recovery" Robert Marko
2023-11-10 9:44 ` Russell King (Oracle)
@ 2023-11-10 15:03 ` Linus Walleij
2023-11-13 1:53 ` Wolfram Sang
2 siblings, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2023-11-10 15:03 UTC (permalink / raw)
To: Robert Marko
Cc: andi.shyti, linux-i2c, linux-kernel, linux, wsa,
codrin.ciubotariu, stable
On Fri, Nov 10, 2023 at 10:30 AM Robert Marko <robert.marko@sartura.hr> wrote:
> This reverts commit 0b01392c18b9993a584f36ace1d61118772ad0ca.
>
> Conversion of PXA to generic I2C recovery, makes the I2C bus completely
> lock up if recovery pinctrl is present in the DT and I2C recovery is
> enabled.
>
> So, until the generic I2C recovery can also work with PXA lets revert
> to have working I2C and I2C recovery again.
>
> Signed-off-by: Robert Marko <robert.marko@sartura.hr>
> Cc: stable@vger.kernel.org # 5.11+
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Revert "i2c: pxa: move to generic GPIO recovery"
2023-11-10 9:30 [PATCH] Revert "i2c: pxa: move to generic GPIO recovery" Robert Marko
2023-11-10 9:44 ` Russell King (Oracle)
2023-11-10 15:03 ` Linus Walleij
@ 2023-11-13 1:53 ` Wolfram Sang
2 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2023-11-13 1:53 UTC (permalink / raw)
To: Robert Marko
Cc: andi.shyti, linux-i2c, linux-kernel, linux, linus.walleij,
codrin.ciubotariu, stable
[-- Attachment #1: Type: text/plain, Size: 551 bytes --]
On Fri, Nov 10, 2023 at 10:30:11AM +0100, Robert Marko wrote:
> This reverts commit 0b01392c18b9993a584f36ace1d61118772ad0ca.
>
> Conversion of PXA to generic I2C recovery, makes the I2C bus completely
> lock up if recovery pinctrl is present in the DT and I2C recovery is
> enabled.
>
> So, until the generic I2C recovery can also work with PXA lets revert
> to have working I2C and I2C recovery again.
>
> Signed-off-by: Robert Marko <robert.marko@sartura.hr>
> Cc: stable@vger.kernel.org # 5.11+
Applied to for-current, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-11-13 1:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-10 9:30 [PATCH] Revert "i2c: pxa: move to generic GPIO recovery" Robert Marko
2023-11-10 9:44 ` Russell King (Oracle)
2023-11-10 11:30 ` Andi Shyti
2023-11-10 15:03 ` Linus Walleij
2023-11-13 1:53 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox