Subject: pinctrl states vs pinmux vs gpio (i2c bus recovery)

From: Russell King - ARM Linux admin <[email-masked]>
Date: Fri, 6 Dec 2019 17:33:43 +0000

Hi Linus,

There seems to be a problem in pinctrl land when pinctrls interact with
GPIOs.

If, for example, an I2C driver wants to attempt bus recovery, and needs
to use GPIO mode to control the I2C bus pins to do this, then one may
expect code such as found in i2c_imx_init_recovery_info() to work.

However, consider that devm_gpiod_get() may invoke
pinctrl_gpio_request(), which changes the pinmux settings independently
of the pinctrl layer.

The result is that after devm_gpiod_get() has completed, the I2C bus
pins are in GPIO mode.

One may expect:

	pinctrl_select_state(i2c_imx->pinctrl, i2c_imx->pinctrl_pins_default);

to change them back to the default state, but that would be incorrect.
The first thing that pinctrl_select_state() does is check whether

	p->state == state

which it will do, as the pinctrl layer hasn't been informed of the
change that has happened behind its back at the pinmux level.

The result is, one needs to switch the state to gpio mode, and then
back to default to ensure that the pins are muxed back to the I2C
controller while the I2C controller is supposed to be operational.

GPIO mode is only used to recover the bus when a bus hang has happened
due to a slave device holding SDA low - and the only way that can be
recovered is by toggling the SCL signal. If the controller provides no
means to do this other than switching to GPIO mode, the above is
necessary.

I spotted this while trying out this method of i2c bus recovery on a
different I2C controller.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up

_______________________________________________
linux-arm-kernel mailing list
[email-masked]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel