Skip to contentSkip to conversation

board: gateworks: venice: poll I2C to wait for GSC

PATCH In review Tim Harvey 3 participants 9 messages Nov 11, 2022 – Jan 31, 2023

Subsystems (2)
lore
Share & tools
lore

Tim Harvey

author
#0 lore raw

cover board: gateworks: venice: poll I2C to wait for GSC

The first patch brings the dts up to date with upstream Linux commits. The second patch implements polling the I2C lines to wait for the Gateworks System Controller to be ready before reading the board EEPROM.

Tim Harvey (2):
arm: dts: imx8m*-venice-*: add I2C GPIO bus recovery support
board: gateworks: venice: poll I2C lines to wait for GSC firmware

 arch/arm/dts/imx8mm-venice-gw700x.dtsi | 24 +++++++++++--
 arch/arm/dts/imx8mm-venice-gw7901.dts  | 48 +++++++++++++++++++++++---
 arch/arm/dts/imx8mm-venice-gw7902.dts  | 48 +++++++++++++++++++++++---
 arch/arm/dts/imx8mm-venice-gw7903.dts  | 36 +++++++++++++++++--
 arch/arm/dts/imx8mm-venice-gw7904.dts  | 48 +++++++++++++++++++++++---
 arch/arm/dts/imx8mm-venice-u-boot.dtsi |  4 +++
 arch/arm/dts/imx8mm-venice.dts         | 12 ++++++-
 arch/arm/dts/imx8mn-venice-gw7902.dts  | 48 +++++++++++++++++++++++---
 arch/arm/dts/imx8mn-venice-u-boot.dtsi |  4 +++
 arch/arm/dts/imx8mn-venice.dts         | 12 ++++++-
 arch/arm/dts/imx8mp-venice-gw74xx.dts  | 48 +++++++++++++++++++++++---
 arch/arm/dts/imx8mp-venice-u-boot.dtsi |  4 +++
 arch/arm/dts/imx8mp-venice.dts         | 12 ++++++-
 board/gateworks/venice/spl.c           | 39 +++++++++++++--------
 14 files changed, 345 insertions(+), 42 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/2 arm: dts: imx8m*-venice-*: add I2C GPIO bus recovery support

Add I2C GPIO bus recovery support by adding scl-gpios and sda-gpios for the various I2C busses on Gateworks Venice boards.

---
Note this is taken from an upstream Linux commit

---
 arch/arm/dts/imx8mm-venice-gw700x.dtsi | 24 +++++++++++--
 arch/arm/dts/imx8mm-venice-gw7901.dts  | 48 +++++++++++++++++++++++---
 arch/arm/dts/imx8mm-venice-gw7902.dts  | 48 +++++++++++++++++++++++---
 arch/arm/dts/imx8mm-venice-gw7903.dts  | 36 +++++++++++++++++--
 arch/arm/dts/imx8mm-venice-gw7904.dts  | 48 +++++++++++++++++++++++---
 arch/arm/dts/imx8mn-venice-gw7902.dts  | 48 +++++++++++++++++++++++---
 arch/arm/dts/imx8mp-venice-gw74xx.dts  | 48 +++++++++++++++++++++++---
 7 files changed, 275 insertions(+), 25 deletions(-)
arch/arm/dts/imx8mm-venice-gw700x.dtsi +22 -2
index 66a0d103c90f..c305e325d007 100644
@@ -119,8 +119,11 @@
 
 &i2c1 {
 	clock-frequency = <100000>;
-	pinctrl-names = "default";
+	pinctrl-names = "default", "gpio";
 	pinctrl-0 = <&pinctrl_i2c1>;
+	pinctrl-1 = <&pinctrl_i2c1_gpio>;
+	scl-gpios = <&gpio5 14 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
+	sda-gpios = <&gpio5 15 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
 	status = "okay";
 
 	gsc: gsc@20 {
@@ -365,8 +368,11 @@
 
 &i2c2 {
 	clock-frequency = <400000>;
-	pinctrl-names = "default";
+	pinctrl-names = "default", "gpio";
 	pinctrl-0 = <&pinctrl_i2c2>;
+	pinctrl-1 = <&pinctrl_i2c2_gpio>;
+	scl-gpios = <&gpio5 16 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
+	sda-gpios = <&gpio5 17 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
 	status = "okay";
 
 	eeprom@52 {
@@ -435,6 +441,13 @@
 		>;
 	};
 
+	pinctrl_i2c1_gpio: i2c1gpiogrp {
+		fsl,pins = <
+			MX8MM_IOMUXC_I2C1_SCL_GPIO5_IO14	0x400001c3
+			MX8MM_IOMUXC_I2C1_SDA_GPIO5_IO15	0x400001c3
+		>;
+	};
+
 	pinctrl_i2c2: i2c2grp {
 		fsl,pins = <
 			MX8MM_IOMUXC_I2C2_SCL_I2C2_SCL		0x400001c3
@@ -442,6 +455,13 @@
 		>;
 	};
 
+	pinctrl_i2c2_gpio: i2c2gpiogrp {
+		fsl,pins = <
+			MX8MM_IOMUXC_I2C2_SCL_GPIO5_IO16	0x400001c3
+			MX8MM_IOMUXC_I2C2_SDA_GPIO5_IO17	0x400001c3
+		>;
+	};
+
 	pinctrl_uart2: uart2grp {
 		fsl,pins = <
 			MX8MM_IOMUXC_UART2_RXD_UART2_DCE_RX	0x140
arch/arm/dts/imx8mm-venice-gw7901.dts +44 -4

100 lines not on this page · raw message

arch/arm/dts/imx8mm-venice-gw7902.dts +44 -4

100 lines not on this page · raw message

arch/arm/dts/imx8mm-venice-gw7903.dts +33 -3
index 19f6d2943d26..1ec91c5c6a49 100644
@@ -265,8 +265,11 @@
 
 &i2c1 {
 	clock-frequency = <100000>;
-	pinctrl-names = "default";
+	pinctrl-names = "default", "gpio";
 	pinctrl-0 = <&pinctrl_i2c1>;
+	pinctrl-1 = <&pinctrl_i2c1_gpio>;
+	scl-gpios = <&gpio5 14 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
+	sda-gpios = <&gpio5 15 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
 	status = "okay";
 
 	gsc: gsc@20 {
@@ -397,8 +400,11 @@
 
 &i2c2 {
 	clock-frequency = <400000>;
-	pinctrl-names = "default";
+	pinctrl-names = "default", "gpio";
 	pinctrl-0 = <&pinctrl_i2c2>;
+	pinctrl-1 = <&pinctrl_i2c2_gpio>;
+	scl-gpios = <&gpio5 16 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
+	sda-gpios = <&gpio5 17 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
 	status = "okay";
 
 	pmic@4b {
@@ -520,8 +526,11 @@
 
 &i2c3 {
 	clock-frequency = <400000>;
-	pinctrl-names = "default";
+	pinctrl-names = "default", "gpio";
 	pinctrl-0 = <&pinctrl_i2c3>;
+	pinctrl-1 = <&pinctrl_i2c3_gpio>;
+	scl-gpios = <&gpio5 18 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
+	sda-gpios = <&gpio5 19 (GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN)>;
 	status = "okay";
 
 	accelerometer@19 {
@@ -681,6 +690,13 @@
 		>;
 	};
 
+	pinctrl_i2c1_gpio: i2c1gpiogrp {
+		fsl,pins = <
+			MX8MM_IOMUXC_I2C1_SCL_GPIO5_IO14	0x400001c3
+			MX8MM_IOMUXC_I2C1_SDA_GPIO5_IO15	0x400001c3
+		>;
+	};
+
 	pinctrl_i2c2: i2c2grp {
 		fsl,pins = <
 			MX8MM_IOMUXC_I2C2_SCL_I2C2_SCL		0x400001c3
@@ -688,6 +704,13 @@
 		>;
 	};
 
+	pinctrl_i2c2_gpio: i2c2gpiogrp {
+		fsl,pins = <
+			MX8MM_IOMUXC_I2C2_SCL_GPIO5_IO16	0x400001c3
+			MX8MM_IOMUXC_I2C2_SDA_GPIO5_IO17	0x400001c3
+		>;
+	};
+
 	pinctrl_i2c3: i2c3grp {
 		fsl,pins = <
 			MX8MM_IOMUXC_I2C3_SCL_I2C3_SCL		0x400001c3
@@ -695,6 +718,13 @@
 		>;
 	};
 
+	pinctrl_i2c3_gpio: i2c3gpiogrp {
+		fsl,pins = <
+			MX8MM_IOMUXC_I2C3_SCL_GPIO5_IO18	0x400001c3
+			MX8MM_IOMUXC_I2C3_SDA_GPIO5_IO19	0x400001c3
+		>;
+	};
+
 	pinctrl_gpio_leds: gpioledgrp {
 		fsl,pins = <
 			MX8MM_IOMUXC_SPDIF_EXT_CLK_GPIO5_IO5	0x19
arch/arm/dts/imx8mm-venice-gw7904.dts +44 -4

100 lines not on this page · raw message

arch/arm/dts/imx8mn-venice-gw7902.dts +44 -4

100 lines not on this page · raw message

arch/arm/dts/imx8mp-venice-gw74xx.dts +44 -4

100 lines not on this page · raw message

Signature · 1 line
2.25.1
reviewer
#2 lore raw

Re: [PATCH 1/2] arm: dts: imx8m*-venice-*: add I2C GPIO bus recovery support

Hi Tim,

Quoted 7 lines · Tim Harvey

Add I2C GPIO bus recovery support by adding scl-gpios and sda-gpios for the various I2C busses on Gateworks Venice boards.

---
Note this is taken from an upstream Linux commit

Why not syncing the whole dts with Linux instead?

author
#3 lore raw

Re: [PATCH 1/2] arm: dts: imx8m*-venice-*: add I2C GPIO bus recovery support

Quoted 5 lines · Fabio Estevam

Hi Tim,

Quoted 1 line · Tim Harvey
Quoted 8 lines
Quoted 6 lines

Add I2C GPIO bus recovery support by adding scl-gpios and sda-gpios for the various I2C busses on Gateworks Venice boards.

---
Note this is taken from an upstream Linux commit

Why not syncing the whole dts with Linux instead?

Fabio,

I believe this does sync up the venice boards. Regardless though, I was preferring a surgical feature based approach here however as syncing a large group of dts with such a long merge window on the imx u-boot tree is problematic.

Best Regards,

Tim

#5 lore raw

PATCH 1/2 arm: dts: imx8m*-venice-*: add I2C GPIO bus recovery support

In reply to Tim Harvey
Quoted 4 lines

Add I2C GPIO bus recovery support by adding scl-gpios and sda-gpios for the various I2C busses on Gateworks Venice boards.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,        Managing Director: Erika Unter  
HRB 165235 Munich,   Office: Kirchenstr.5, 82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================
author
#6 lore raw

PATCH 2/2 board: gateworks: venice: poll I2C lines to wait for GSC firmware

In reply to Tim Harvey

In some situations the GSC firmware where the EEPROM containing the model and DRAM configuration may not be ready by the time the SoC is ready to talk to it over I2C.

Instead of a hard delay, poll the I2C lines to wait until they are released to avoid the I2C drivers 'Arbitation lost' error message.

---
v2: move u-boot,dm-spl to *-u-boot.dtsi where it belongs

---
 arch/arm/dts/imx8mm-venice-u-boot.dtsi |  4 +++
 arch/arm/dts/imx8mm-venice.dts         | 12 +++++++-
 arch/arm/dts/imx8mn-venice-u-boot.dtsi |  4 +++
 arch/arm/dts/imx8mn-venice.dts         | 12 +++++++-
 arch/arm/dts/imx8mp-venice-u-boot.dtsi |  4 +++
 arch/arm/dts/imx8mp-venice.dts         | 12 +++++++-
 board/gateworks/venice/spl.c           | 39 +++++++++++++++++---------
 7 files changed, 70 insertions(+), 17 deletions(-)
arch/arm/dts/imx8mm-venice-u-boot.dtsi +4 -0
index 68978a0413ec..6f786b9467c2 100644
@@ -57,6 +57,10 @@
 	u-boot,dm-spl;
 };
 
+&pinctrl_i2c1_gpio {
+	u-boot,dm-spl;
+};
+
 &gsc {
 	u-boot,dm-spl;
 };
arch/arm/dts/imx8mm-venice.dts +11 -1
index 39b030691e53..d0929908ce84 100644
@@ -23,8 +23,11 @@
 
 &i2c1 {
 	clock-frequency = <100000>;
-	pinctrl-names = "default";
+	pinctrl-names = "default", "gpio";
 	pinctrl-0 = <&pinctrl_i2c1>;
+	pinctrl-1 = <&pinctrl_i2c1_gpio>;
+	scl-gpios = <&gpio5 14 GPIO_ACTIVE_HIGH>;
+	sda-gpios = <&gpio5 15 GPIO_ACTIVE_HIGH>;
 	status = "okay";
 
 	gsc: gsc@20 {
@@ -89,6 +92,13 @@
 		>;
 	};
 
+	pinctrl_i2c1_gpio: i2c1grp-gpio-grp {
+		fsl,pins = <
+			MX8MM_IOMUXC_I2C1_SCL_GPIO5_IO14	0x400001c3
+			MX8MM_IOMUXC_I2C1_SDA_GPIO5_IO15	0x400001c3
+		>;
+	};
+
 	pinctrl_i2c2: i2c2grp {
 		fsl,pins = <
 			MX8MM_IOMUXC_I2C2_SCL_I2C2_SCL		0x400001c3
arch/arm/dts/imx8mn-venice-u-boot.dtsi +4 -0
index aea48f2d795b..4af6b8b4ed87 100644
@@ -49,6 +49,10 @@
 	u-boot,dm-spl;
 };
 
+&pinctrl_i2c1_gpio {
+	u-boot,dm-spl;
+};
+
 &gsc {
 	u-boot,dm-spl;
 };
arch/arm/dts/imx8mn-venice.dts +11 -1
index eeae225632d7..9e31b37f2496 100644
@@ -23,8 +23,11 @@
 
 &i2c1 {
 	clock-frequency = <100000>;
-	pinctrl-names = "default";
+	pinctrl-names = "default", "gpio";
 	pinctrl-0 = <&pinctrl_i2c1>;
+	pinctrl-1 = <&pinctrl_i2c1_gpio>;
+	scl-gpios = <&gpio5 14 GPIO_ACTIVE_HIGH>;
+	sda-gpios = <&gpio5 15 GPIO_ACTIVE_HIGH>;
 	status = "okay";
 
 	gsc: gsc@20 {
@@ -89,6 +92,13 @@
 		>;
 	};
 
+	pinctrl_i2c1_gpio: i2c1grp-gpio-grp {
+		fsl,pins = <
+			MX8MN_IOMUXC_I2C1_SCL_GPIO5_IO14	0x400001c3
+			MX8MN_IOMUXC_I2C1_SDA_GPIO5_IO15	0x400001c3
+		>;
+	};
+
 	pinctrl_i2c2: i2c2grp {
 		fsl,pins = <
 			MX8MN_IOMUXC_I2C2_SCL_I2C2_SCL		0x400001c3
arch/arm/dts/imx8mp-venice-u-boot.dtsi +4 -0
index 96b9fa89cf46..f9068ebfbeea 100644
@@ -57,6 +57,10 @@
 	u-boot,dm-spl;
 };
 
+&pinctrl_i2c1_gpio {
+	u-boot,dm-spl;
+};
+
 &gsc {
 	u-boot,dm-spl;
 };
arch/arm/dts/imx8mp-venice.dts +11 -1
index 6b1a7f1a89d4..77e5ac423db3 100644
@@ -23,8 +23,11 @@
 
 &i2c1 {
 	clock-frequency = <100000>;
-	pinctrl-names = "default";
+	pinctrl-names = "default", "gpio";
 	pinctrl-0 = <&pinctrl_i2c1>;
+	pinctrl-1 = <&pinctrl_i2c1_gpio>;
+	scl-gpios = <&gpio5 14 GPIO_ACTIVE_HIGH>;
+	sda-gpios = <&gpio5 15 GPIO_ACTIVE_HIGH>;
 	status = "okay";
 
 	gsc: gsc@20 {
@@ -89,6 +92,13 @@
 		>;
 	};
 
+	pinctrl_i2c1_gpio: i2c1grp-gpio-grp {
+		fsl,pins = <
+			MX8MP_IOMUXC_I2C1_SCL__GPIO5_IO14	0x400001c3
+			MX8MP_IOMUXC_I2C1_SDA__GPIO5_IO15	0x400001c3
+		>;
+	};
+
 	pinctrl_i2c2: i2c2grp {
 		fsl,pins = <
 			MX8MP_IOMUXC_I2C2_SCL__I2C2_SCL		0x400001c3
board/gateworks/venice/spl.c +25 -14
index e06de8bb54c7..9d63f7db46d1 100644
@@ -16,10 +16,12 @@
 #include <asm/arch/imx8mp_pins.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/mach-imx/boot_mode.h>
+#include <asm/mach-imx/mxc_i2c.h>
 #include <asm/arch/ddr.h>
 #include <asm-generic/gpio.h>
 #include <dm/uclass.h>
 #include <dm/device.h>
+#include <dm/pinctrl.h>
 #include <linux/delay.h>
 #include <power/bd71837.h>
 #include <power/mp5416.h>
@@ -218,8 +220,8 @@ static int power_init_board(void)
 
 void board_init_f(ulong dummy)
 {
-	struct udevice *dev;
-	int ret;
+	struct udevice *bus, *dev;
+	int i, ret;
 	int dram_sz;
 
 	arch_cpu_init();
@@ -250,19 +252,28 @@ void board_init_f(ulong dummy)
 	 *
 	 * On a board with a missing/depleted backup battery for GSC, the
 	 * board may be ready to probe the GSC before its firmware is
-	 * running. We will wait here indefinately for the GSC EEPROM.
-	 */
-#ifdef CONFIG_IMX8MN
-	/*
-	 * IMX8MN boots quicker than IMX8MM and exposes issue
-	 * where because GSC I2C state machine isn't running and its
-	 * SCL/SDA are driven low the I2C driver spams 'Arbitration lost'
-	 * I2C errors.
-	 *
-	 * TODO: Put a loop here that somehow waits for I2C CLK/DAT to be high
+	 * running. Wait here for 50ms for the GSC firmware to let go of
+	 * the SCL/SDA lines to avoid the i2c driver spamming
+	 * 'Arbitration lost' I2C errors
 	 */
-	mdelay(50);
-#endif
+	if (!uclass_get_device_by_seq(UCLASS_I2C, 0, &bus)) {
+		if (!pinctrl_select_state(bus, "gpio")) {
+			struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
+			struct gpio_desc *scl_gpio = &i2c_bus->scl_gpio;
+			struct gpio_desc *sda_gpio = &i2c_bus->sda_gpio;
+
+			dm_gpio_set_dir_flags(scl_gpio, GPIOD_IS_IN);
+			dm_gpio_set_dir_flags(sda_gpio, GPIOD_IS_IN);
+			for (i = 0; i < 5; i++) {
+				if (dm_gpio_get_value(scl_gpio) &&
+				    dm_gpio_get_value(sda_gpio))
+					break;
+				mdelay(10);
+			}
+			pinctrl_select_state(bus, "default");
+		}
+	}
+	/* Wait indefiniately until the GSC probes */
 	while (1) {
 		if (!uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(gsc), &dev))
 			break;
Signature · 1 line
2.25.1
reviewer Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] board: gateworks: venice: poll I2C lines to wait for GSC firmware

Quoted 11 lines · Tim Harvey

In some situations the GSC firmware where the EEPROM containing the model and DRAM configuration may not be ready by the time the SoC is ready to talk to it over I2C.

Instead of a hard delay, poll the I2C lines to wait until they are released to avoid the I2C drivers 'Arbitation lost' error message.

---
v2: move u-boot,dm-spl to *-u-boot.dtsi where it belongs

#8 lore raw

PATCH 2/2 board: gateworks: venice: poll I2C lines to wait for GSC firmware

In reply to Tim Harvey
Quoted 7 lines

In some situations the GSC firmware where the EEPROM containing the model and DRAM configuration may not be ready by the time the SoC is ready to talk to it over I2C.
Instead of a hard delay, poll the I2C lines to wait until they are released to avoid the I2C drivers 'Arbitation lost' error message.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,        Managing Director: Erika Unter  
HRB 165235 Munich,   Office: Kirchenstr.5, 82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================