board: gateworks: venice: poll I2C lines to wait for GSC firmware
Subsystems (2)
PATCH 1/1 board: gateworks: venice: poll I2C lines to wait for GSC firmware
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.
--- arch/arm/dts/imx8mm-venice.dts | 13 +++++++++++- arch/arm/dts/imx8mn-venice.dts | 13 +++++++++++- arch/arm/dts/imx8mp-venice.dts | 13 +++++++++++- board/gateworks/venice/spl.c | 39 ++++++++++++++++++++++------------ 4 files changed, 61 insertions(+), 17 deletions(-)
arch/arm/dts/imx8mm-venice.dts +12 -1
@@ -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,14 @@ >; }; + pinctrl_i2c1_gpio: i2c1grp-gpio-grp { + fsl,pins = < + MX8MM_IOMUXC_I2C1_SCL_GPIO5_IO14 0x400001c3 + MX8MM_IOMUXC_I2C1_SDA_GPIO5_IO15 0x400001c3 + >; + u-boot,dm-spl; + }; + pinctrl_i2c2: i2c2grp { fsl,pins = < MX8MM_IOMUXC_I2C2_SCL_I2C2_SCL 0x400001c3
arch/arm/dts/imx8mn-venice.dts +12 -1
@@ -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,14 @@ >; }; + pinctrl_i2c1_gpio: i2c1grp-gpio-grp { + fsl,pins = < + MX8MN_IOMUXC_I2C1_SCL_GPIO5_IO14 0x400001c3 + MX8MN_IOMUXC_I2C1_SDA_GPIO5_IO15 0x400001c3 + >; + u-boot,dm-spl; + }; + pinctrl_i2c2: i2c2grp { fsl,pins = < MX8MN_IOMUXC_I2C2_SCL_I2C2_SCL 0x400001c3
arch/arm/dts/imx8mp-venice.dts +12 -1
@@ -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,14 @@ >; }; + pinctrl_i2c1_gpio: i2c1grp-gpio-grp { + fsl,pins = < + MX8MP_IOMUXC_I2C1_SCL__GPIO5_IO14 0x400001c3 + MX8MP_IOMUXC_I2C1_SDA__GPIO5_IO15 0x400001c3 + >; + u-boot,dm-spl; + }; + pinctrl_i2c2: i2c2grp { fsl,pins = < MX8MP_IOMUXC_I2C2_SCL__I2C2_SCL 0x400001c3
board/gateworks/venice/spl.c +25 -14
@@ -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>
@@ -219,8 +221,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 ();
@@ -251,19 +253,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
Quoted 33 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.
Signed-off-by Tim Harvey <[email protected]>--- arch/arm/dts/imx8mm-venice.dts | 13 +++++++++++- arch/arm/dts/imx8mn-venice.dts | 13 +++++++++++- arch/arm/dts/imx8mp-venice.dts | 13 +++++++++++- board/gateworks/venice/spl.c | 39 ++++++++++++++++++++++------------ 4 files changed, 61 insertions(+), 17 deletions(-)arch/arm/dts/imx8mm-venice.dts +4
-1@@ -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 {
arch/arm/dts/imx8mm-venice.dts line 100
Quoted 9 lines
arch/arm/dts/imx8mm-venice.dts +6
-0@@ -89,6 +92,14 @@ >; }; + pinctrl_i2c1_gpio: i2c1grp-gpio-grp { + fsl,pins = < + MX8MM_IOMUXC_I2C1_SCL_GPIO5_IO14 0x400001c3 + MX8MM_IOMUXC_I2C1_SDA_GPIO5_IO15 0x400001c3 + >; + u-boot,dm-spl;
u-boot,dm-spl should be in xx-u-boot.dtsi
Quoted 23 lines
arch/arm/dts/imx8mm-venice.dts +2
-0+ }; + pinctrl_i2c2: i2c2grp { fsl,pins = < MX8MM_IOMUXC_I2C2_SCL_I2C2_SCL 0x400001c3arch/arm/dts/imx8mn-venice.dts +4
-1@@ -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 {
arch/arm/dts/imx8mn-venice.dts line 100
Quoted 9 lines
arch/arm/dts/imx8mn-venice.dts +6
-0@@ -89,6 +92,14 @@ >; }; + pinctrl_i2c1_gpio: i2c1grp-gpio-grp { + fsl,pins = < + MX8MN_IOMUXC_I2C1_SCL_GPIO5_IO14 0x400001c3 + MX8MN_IOMUXC_I2C1_SDA_GPIO5_IO15 0x400001c3 + >; + u-boot,dm-spl;
Ditto.
Quoted 23 lines
arch/arm/dts/imx8mn-venice.dts +2
-0+ }; + pinctrl_i2c2: i2c2grp { fsl,pins = < MX8MN_IOMUXC_I2C2_SCL_I2C2_SCL 0x400001c3arch/arm/dts/imx8mp-venice.dts +4
-1@@ -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 {
arch/arm/dts/imx8mp-venice.dts line 100
Quoted 9 lines
arch/arm/dts/imx8mp-venice.dts +6
-0@@ -89,6 +92,14 @@ >; }; + pinctrl_i2c1_gpio: i2c1grp-gpio-grp { + fsl,pins = < + MX8MP_IOMUXC_I2C1_SCL__GPIO5_IO14 0x400001c3 + MX8MP_IOMUXC_I2C1_SDA__GPIO5_IO15 0x400001c3 + >; + u-boot,dm-spl;
Ditto.
Regards,
Peng.
Quoted 74 lines
arch/arm/dts/imx8mp-venice.dts +2
-0+ }; + pinctrl_i2c2: i2c2grp { fsl,pins = < MX8MP_IOMUXC_I2C2_SCL__I2C2_SCL 0x400001c3board/gateworks/venice/spl.c +25
-14@@ -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> @@ -219,8 +221,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 ();@@ -251,19 +253,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 ;
Quoted 40 lines · Peng Fan
Quoted 36 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.
Signed-off-by Tim Harvey <[email protected]>--- arch/arm/dts/imx8mm-venice.dts | 13 +++++++++++- arch/arm/dts/imx8mn-venice.dts | 13 +++++++++++- arch/arm/dts/imx8mp-venice.dts | 13 +++++++++++- board/gateworks/venice/spl.c | 39 ++++++++++++++++++++++------------ 4 files changed, 61 insertions(+), 17 deletions(-)arch/arm/dts/imx8mm-venice.dts +4
-1@@ -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,14 @@ >; };
Quoted 8 lines
arch/arm/dts/imx8mm-venice.dts line 100
Quoted 6 lines
arch/arm/dts/imx8mm-venice.dts +6
-0+ pinctrl_i2c1_gpio: i2c1grp-gpio-grp { + fsl,pins = < + MX8MM_IOMUXC_I2C1_SCL_GPIO5_IO14 0x400001c3 + MX8MM_IOMUXC_I2C1_SDA_GPIO5_IO15 0x400001c3 + >; + u-boot,dm-spl;u-boot,dm-spl should be in
xx-u-boot.dtsi
Peng,
Thanks for catching this! I will fix this and the others in this patch and send a new version.
Best Regards,
Tim