[PATCH v2 1/2] i2c: i2c-gpio: Correctly handle new {sda, scl}-gpios bindings

gpio_request_list_by_name() returns the number of gpios requested. Notably it swallows the underlying -ENOENT when the "gpios" property does not exist.
Update the i2c-gpio driver to check for ret == 0 before trying the new sda-gpios/scl-gpios properties.
Signed-off-by: Chris Packham judge.packham@gmail.com --- This was originally sent as a single patch[1]. I've rolled it into this series as the board change is dependent on it.
[1] - https://lore.kernel.org/u-boot/20230720023107.1184147-1-judge.packham@gmail....
(no changes since v1)
drivers/i2c/i2c-gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/i2c/i2c-gpio.c b/drivers/i2c/i2c-gpio.c index 4ed9e9e7cddd..c1fc290bd253 100644 --- a/drivers/i2c/i2c-gpio.c +++ b/drivers/i2c/i2c-gpio.c @@ -339,7 +339,7 @@ static int i2c_gpio_of_to_plat(struct udevice *dev) /* "gpios" is deprecated and replaced by "sda-gpios" + "scl-gpios". */ ret = gpio_request_list_by_name(dev, "gpios", bus->gpios, ARRAY_SIZE(bus->gpios), 0); - if (ret == -ENOENT) { + if (ret == 0) { ret = gpio_request_by_name(dev, "sda-gpios", 0, &bus->gpios[PIN_SDA], 0); if (ret < 0)

There is an Errata with the built-in I2C controller where various I2C hardware errors cause a complete lockup of the CPU (which eventually results in an watchdog reset).
Put the I2C MPP pins into GPIO mode and use the i2c-gpio driver instead. This uses a bit-banged implementation of an I2C controller and avoids triggering the Errata.
Signed-off-by: Chris Packham judge.packham@gmail.com Reviewed-by: Stefan Roese sr@denx.de ---
Changes in v2: - Update i2c0 alias - Move i2c-gpio definition to root of device tree - Remove &i2c0 instead of just disabling it - Add r-by from Stefan
arch/arm/dts/ac5-98dx35xx-atl-x240.dts | 30 ++++++++++++++++++++------ configs/x240_defconfig | 1 + 2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/arch/arm/dts/ac5-98dx35xx-atl-x240.dts b/arch/arm/dts/ac5-98dx35xx-atl-x240.dts index 820ec18b4355..c19b25925ba2 100644 --- a/arch/arm/dts/ac5-98dx35xx-atl-x240.dts +++ b/arch/arm/dts/ac5-98dx35xx-atl-x240.dts @@ -16,7 +16,7 @@ gpio0 = &gpio0; gpio1 = &gpio1; spi0 = &spi0; - i2c0 = &i2c0; + i2c0 = &i2cgpio; usb0 = &usb0; pinctrl0 = &pinctrl0; }; @@ -40,6 +40,19 @@ default-state = "on"; }; }; + + i2cgpio: i2c-gpio-0 { + compatible = "i2c-gpio"; + #address-cells = <1>; + #size-cells = <0>; + + pinctrl-names = "default"; + pinctrl-0 = <&i2c0_gpio>; + scl-gpios = <&gpio0 26 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + sda-gpios = <&gpio0 27 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>; + i2c-gpio,delay-us = <2>; + status = "okay"; + }; };
&nand { @@ -70,9 +83,7 @@ status = "okay"; };
-&i2c0 { - status = "okay"; - +&i2cgpio { mux@71 { #address-cells = <1>; #size-cells = <0>; @@ -177,8 +188,8 @@ * LED_OE_N [23] * USB_PWR_FLT_N [24] * SFP_INT_N [25] - * I2C0_SCL [26] - * I2C0_SDA [27] + * I2C0_SCL [26] (GPIO) + * I2C0_SDA [27] (GPIO) * USB_EN [28] * MONITOR_INT_N [29] * XM1_MDC [30] @@ -201,7 +212,7 @@ /* 0 1 2 3 4 5 6 7 8 9 */ pin-func = < 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 1 1 1 1 0xff 0xff 0 0 - 0 0 0 0 0 0 1 1 0 0 + 0 0 0 0 0 0 0xff 0xff 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 >;
@@ -209,4 +220,9 @@ marvell,pins = <0 1 2 3 4 5 6 7 8 9 10 11 16 17>; marvell,function = <2>; }; + + i2c0_gpio: i2c0-gpio-pins { + marvell,pins = <26 27>; + marvell,function = <0>; + }; }; diff --git a/configs/x240_defconfig b/configs/x240_defconfig index a78cb3ce6cbf..7d2b8603e6f4 100644 --- a/configs/x240_defconfig +++ b/configs/x240_defconfig @@ -42,6 +42,7 @@ CONFIG_CLK_MVEBU=y CONFIG_GPIO_HOG=y CONFIG_DM_PCA953X=y CONFIG_DM_I2C=y +CONFIG_DM_I2C_GPIO=y CONFIG_SYS_I2C_MVTWSI=y CONFIG_I2C_MUX=y CONFIG_I2C_MUX_PCA954x=y

On 7/26/23 01:13, Chris Packham wrote:
There is an Errata with the built-in I2C controller where various I2C hardware errors cause a complete lockup of the CPU (which eventually results in an watchdog reset).
Put the I2C MPP pins into GPIO mode and use the i2c-gpio driver instead. This uses a bit-banged implementation of an I2C controller and avoids triggering the Errata.
Signed-off-by: Chris Packham judge.packham@gmail.com Reviewed-by: Stefan Roese sr@denx.de
Applied to u-boot-marvell/master
Thanks, Stefan
Changes in v2:
Update i2c0 alias
Move i2c-gpio definition to root of device tree
Remove &i2c0 instead of just disabling it
Add r-by from Stefan
arch/arm/dts/ac5-98dx35xx-atl-x240.dts | 30 ++++++++++++++++++++------ configs/x240_defconfig | 1 + 2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/arch/arm/dts/ac5-98dx35xx-atl-x240.dts b/arch/arm/dts/ac5-98dx35xx-atl-x240.dts index 820ec18b4355..c19b25925ba2 100644 --- a/arch/arm/dts/ac5-98dx35xx-atl-x240.dts +++ b/arch/arm/dts/ac5-98dx35xx-atl-x240.dts @@ -16,7 +16,7 @@ gpio0 = &gpio0; gpio1 = &gpio1; spi0 = &spi0;
i2c0 = &i2c0;
usb0 = &usb0; pinctrl0 = &pinctrl0; };i2c0 = &i2cgpio;
@@ -40,6 +40,19 @@ default-state = "on"; }; };
i2cgpio: i2c-gpio-0 {
compatible = "i2c-gpio";
#address-cells = <1>;
#size-cells = <0>;
pinctrl-names = "default";
pinctrl-0 = <&i2c0_gpio>;
scl-gpios = <&gpio0 26 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
sda-gpios = <&gpio0 27 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
i2c-gpio,delay-us = <2>;
status = "okay";
};
};
&nand {
@@ -70,9 +83,7 @@ status = "okay"; };
-&i2c0 {
- status = "okay";
+&i2cgpio { mux@71 { #address-cells = <1>; #size-cells = <0>; @@ -177,8 +188,8 @@ * LED_OE_N [23] * USB_PWR_FLT_N [24] * SFP_INT_N [25]
* I2C0_SCL [26]
* I2C0_SDA [27]
* I2C0_SCL [26] (GPIO)
* I2C0_SDA [27] (GPIO)
- USB_EN [28]
- MONITOR_INT_N [29]
- XM1_MDC [30]
@@ -201,7 +212,7 @@ /* 0 1 2 3 4 5 6 7 8 9 */ pin-func = < 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 1 1 1 1 0xff 0xff 0 0
0 0 0 0 0 0 1 1 0 0
0 0 0 0 0 0 0xff 0xff 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 >;
@@ -209,4 +220,9 @@ marvell,pins = <0 1 2 3 4 5 6 7 8 9 10 11 16 17>; marvell,function = <2>; };
- i2c0_gpio: i2c0-gpio-pins {
marvell,pins = <26 27>;
marvell,function = <0>;
- }; };
diff --git a/configs/x240_defconfig b/configs/x240_defconfig index a78cb3ce6cbf..7d2b8603e6f4 100644 --- a/configs/x240_defconfig +++ b/configs/x240_defconfig @@ -42,6 +42,7 @@ CONFIG_CLK_MVEBU=y CONFIG_GPIO_HOG=y CONFIG_DM_PCA953X=y CONFIG_DM_I2C=y +CONFIG_DM_I2C_GPIO=y CONFIG_SYS_I2C_MVTWSI=y CONFIG_I2C_MUX=y CONFIG_I2C_MUX_PCA954x=y
Viele Grüße, Stefan Roese

On 7/26/23 01:13, Chris Packham wrote:
gpio_request_list_by_name() returns the number of gpios requested. Notably it swallows the underlying -ENOENT when the "gpios" property does not exist.
Update the i2c-gpio driver to check for ret == 0 before trying the new sda-gpios/scl-gpios properties.
Signed-off-by: Chris Packham judge.packham@gmail.com
Applied to u-boot-marvell/master
Thanks, Stefan
This was originally sent as a single patch[1]. I've rolled it into this series as the board change is dependent on it.
[1] - https://lore.kernel.org/u-boot/20230720023107.1184147-1-judge.packham@gmail....
(no changes since v1)
drivers/i2c/i2c-gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/i2c/i2c-gpio.c b/drivers/i2c/i2c-gpio.c index 4ed9e9e7cddd..c1fc290bd253 100644 --- a/drivers/i2c/i2c-gpio.c +++ b/drivers/i2c/i2c-gpio.c @@ -339,7 +339,7 @@ static int i2c_gpio_of_to_plat(struct udevice *dev) /* "gpios" is deprecated and replaced by "sda-gpios" + "scl-gpios". */ ret = gpio_request_list_by_name(dev, "gpios", bus->gpios, ARRAY_SIZE(bus->gpios), 0);
- if (ret == -ENOENT) {
- if (ret == 0) { ret = gpio_request_by_name(dev, "sda-gpios", 0, &bus->gpios[PIN_SDA], 0); if (ret < 0)
Viele Grüße, Stefan Roese

Hello Chris,
On 26.07.23 01:13, Chris Packham wrote:
gpio_request_list_by_name() returns the number of gpios requested. Notably it swallows the underlying -ENOENT when the "gpios" property does not exist.
Update the i2c-gpio driver to check for ret == 0 before trying the new sda-gpios/scl-gpios properties.
Signed-off-by: Chris Packham judge.packham@gmail.com
This was originally sent as a single patch[1]. I've rolled it into this series as the board change is dependent on it.
[1] - https://lore.kernel.org/u-boot/20230720023107.1184147-1-judge.packham@gmail....
(no changes since v1)
drivers/i2c/i2c-gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Heiko Schocher hs@denx.de
bye, Heiko
participants (3)
-
Chris Packham
-
Heiko Schocher
-
Stefan Roese