i2c: imx: implement bus recovery
Subsystems (4)
PATCH v8 1/1 i2c: imx: implement bus recovery
Implement bus recovery methods for i2c-imx so we can recover from situations where SCL/SDA are stuck low.
Once i2c bus SCL/SDA are stuck low during transfer, config the i2c pinctrl to gpio mode by calling pinctrl sleep set function, and then use GPIO to emulate the i2c protocol to send nine dummy clock to recover i2c device. After recovery, set i2c pinctrl to default group setting.
---
V2:
As Uwe Kleine-König's suggestion, the version do below changes:
-replace of_get_named_gpio() with devm_gpiod_get_optional() -move gpio_direction_input() and gpio_direction_output() call to the
prepare callback
-use 0 and 1 as return value for the get_scl and get_sda callbacks
V3:
-replace "...-gpio" with "...-gpios" in i2c binding doc -document the requirement of using sleep state to configure
the pins as gpio in i2c binding doc
-remove i2c_recover_bus() in i2c_imx_trx_complete() -use GPIOD_OUT_HIGH as the parameter of devm_gpiod_get_optional to
config the gpios as output high
-add error disposal as devm_gpiod_get_optional meets error
V4:
-remove include <linux/of_gpio.h>
-call i2c_recover_bus under the condition of the existing of
both sda and scl. Drop the sda and scl check in i2c_imx_get_scl, i2c_imx_get_sda, i2c_imx_set_scl, i2c_imx_prepare_recovery and i2c_imx_prepare_recovery
-use GPIOD_OUT_IN as the parameter of devm_gpiod_get_optional -remove documenting the requirement of using sleep state to configure
the pins as gpio in i2c binding doc
V5:
-introduce a dedicated gpio state for bus recovery.
-assign adapter.bus_recovery_info after the two gpios were aquired successfully
V6:
-assign adapter.bus_recovery_info under the condition that gpios are acquired successfully -not try the recovery when pinctrl_lookup_state returns an error
V7:
-execute the bus recovery once in a transfer, when the controller fails to start -use i2c_generic_gpio_recovery() to handle the bus recovery with gpios
V8:
-remove unused symbol and unrelated whitespace changes
Documentation/devicetree/bindings/i2c/i2c-imx.txt | 9 +++ drivers/i2c/busses/i2c-imx.c | 71 +++++++++++++++++++++++ 2 files changed, 80 insertions(+)
Documentation/devicetree/bindings/i2c/i2c-imx.txt +9 -0
@@ -14,6 +14,10 @@ Optional properties: The absence of the propoerty indicates the default frequency 100 kHz. - dmas: A list of two dma specifiers, one for each entry in dma-names. - dma-names: should contain "tx" and "rx". +- scl-gpios: specify the gpio related to SCL pin +- sda-gpios: specify the gpio related to SDA pin +- pinctrl: add extra pinctrl to configure i2c pins to gpio function for i2c + bus recovery, call it "gpio" state Examples:
@@ -37,4 +41,9 @@ i2c0: i2c@40066000 { /* i2c0 on vf610 */ dmas = <&edma0 0 50>, <&edma0 0 51>; dma-names = "rx","tx"; + pinctrl-names = "default", "gpio"; + pinctrl-0 = <&pinctrl_i2c1>; + pinctrl-1 = <&pinctrl_i2c1_gpio>; + scl-gpios = <&gpio5 26 GPIO_ACTIVE_HIGH>; + sda-gpios = <&gpio5 27 GPIO_ACTIVE_HIGH>; };
drivers/i2c/busses/i2c-imx.c +71 -0
107 lines not on this page · raw message
Signature · 1 line
1.9.1
Wolfram Sang
AppliedQuoted 11 lines · Gao Pan
Implement bus recovery methods for i2c-imx so we can recover from situations where SCL/SDA are stuck low.
Once i2c bus SCL/SDA are stuck low during transfer, config the i2c pinctrl to gpio mode by calling pinctrl sleep set function, and then use GPIO to emulate the i2c protocol to send nine dummy clock to recover i2c device. After recovery, set i2c pinctrl to default group setting.
Signed-off-by Fugang Duan <[email protected]>Signed-off-by Gao Pan <[email protected]>Signed-off-by Sascha Hauer <[email protected]>
Applied to for-next, thanks!