From patchwork Thu Aug 11 18:59:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Harvey X-Patchwork-Id: 1665687 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4M3bh24Ysmz9sGG for ; Fri, 12 Aug 2022 04:59:14 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3D2BB849B0; Thu, 11 Aug 2022 20:59:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gateworks.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 1AE0884926; Thu, 11 Aug 2022 20:59:10 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from finn.localdomain (finn.gateworks.com [108.161.129.64]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 57CCC849FD for ; Thu, 11 Aug 2022 20:59:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gateworks.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=tharvey@gateworks.com Received: from 068-189-091-139.biz.spectrum.com ([68.189.91.139] helo=tharvey.pdc.gateworks.com) by finn.localdomain with esmtp (Exim 4.93) (envelope-from ) id 1oMDOa-00FomH-04; Thu, 11 Aug 2022 18:59:04 +0000 From: Tim Harvey To: Stefano Babic , Fabio Estevam , "NXP i . MX U-Boot Team" , u-boot@lists.denx.de Cc: Tim Harvey Subject: [PATCH] board: gateworks: venice: poll I2C lines to wait for GSC firmware Date: Thu, 11 Aug 2022 11:59:01 -0700 Message-Id: <20220811185901.3992631-1-tharvey@gateworks.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean 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 --- 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(-) diff --git a/arch/arm/dts/imx8mm-venice.dts b/arch/arm/dts/imx8mm-venice.dts index 39b030691e53..a1f292fbd9d3 100644 --- a/arch/arm/dts/imx8mm-venice.dts +++ b/arch/arm/dts/imx8mm-venice.dts @@ -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 diff --git a/arch/arm/dts/imx8mn-venice.dts b/arch/arm/dts/imx8mn-venice.dts index eeae225632d7..8480a2e368aa 100644 --- a/arch/arm/dts/imx8mn-venice.dts +++ b/arch/arm/dts/imx8mn-venice.dts @@ -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 diff --git a/arch/arm/dts/imx8mp-venice.dts b/arch/arm/dts/imx8mp-venice.dts index 6b1a7f1a89d4..93145b37049b 100644 --- a/arch/arm/dts/imx8mp-venice.dts +++ b/arch/arm/dts/imx8mp-venice.dts @@ -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 diff --git a/board/gateworks/venice/spl.c b/board/gateworks/venice/spl.c index 914a56a96f52..ae460296cb99 100644 --- a/board/gateworks/venice/spl.c +++ b/board/gateworks/venice/spl.c @@ -16,10 +16,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -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;