From nobody Sat May 18 23:23:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81313+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81313+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1632980665; cv=none; d=zohomail.com; s=zohoarc; b=c/usHEqYch8JWQLzEPMDxdBzE2noMYopBOEq1CQlHuasdNldeNvzyPkNJsN8vJ9GdZ7t4RZ841IZLN3bvnksTiCaGeCrLzaTrgluZZH1X56PffOGEcI9ZXvfk/vuBxFN6CXHHlMNhTc84rt9p2XvtqZgAZSEH/NNxXktu+NmQk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632980665; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=+RgQmTUA4OBpQsbB1ng4B2hedxO38HGIex0Uev9Qc2w=; b=GjAlKRszx6uJNW+yLZCc6ecuW2V2AdAjc0mag0skyfU84Z498+0F7dIdFZmgmZFGAdn5zTEZwPTILAg6yfCLR6oZ5THWsATXXwWYlPI3phSfzFhj+dPCWxS2woUs6IX3Z//o81LkulGBBGdvjJLE0kZvnieeL1xTm6O+H3mkkX0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81313+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1632980665110913.8562463939306; Wed, 29 Sep 2021 22:44:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id i7UMYY1788612xn25OtN89q6; Wed, 29 Sep 2021 22:44:24 -0700 X-Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by mx.groups.io with SMTP id smtpd.web09.8596.1632980663944315109 for ; Wed, 29 Sep 2021 22:44:24 -0700 X-Received: by mail-pg1-f175.google.com with SMTP id 133so5126524pgb.1 for ; Wed, 29 Sep 2021 22:44:23 -0700 (PDT) X-Gm-Message-State: FhZaBMIcwa9eSBwWVQAus8ysx1787277AA= X-Google-Smtp-Source: ABdhPJwFl8oAxbMeKzCIyM6XwEBHzxZ/e2zXyXpgJOi6yqwxVZZ3ApWmgffI/CPXEKVuORA2hFXqdg== X-Received: by 2002:aa7:9596:0:b0:43e:48:dbeb with SMTP id z22-20020aa79596000000b0043e0048dbebmr2444390pfj.77.1632980663284; Wed, 29 Sep 2021 22:44:23 -0700 (PDT) X-Received: from localhost.localdomain (122x208x150x49.ap122.ftth.ucom.ne.jp. [122.208.150.49]) by smtp.gmail.com with ESMTPSA id v7sm1433812pff.195.2021.09.29.22.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 22:44:22 -0700 (PDT) From: "Masami Hiramatsu" To: Ard Biesheuvel , Leif Lindholm Cc: devel@edk2.groups.io, Kazuhiko Sakamoto Subject: [edk2-devel] [PATCH] Silicon/SynQuacerI2cDxe: Wait for bus busy Date: Thu, 30 Sep 2021 14:44:20 +0900 Message-Id: <163298066001.291769.2577514894991820447.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,masami.hiramatsu@linaro.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1632980664; bh=4J71ZX9YaLnzvZNSwnoPBF75OqoVNSzxjFQ4gYKvl3E=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=sUg/FjsCGkoRtZvAqf2AXVLrHX4sKg5CkgaKykiXKmZiAA8ijM3vrG8ZwqAmAGFtqya C6tHm3lIYea+KlFLHGX16nLV2oGBowg0LfQQTwx1B37/FO+QZzkSEFc0PbbCjJWWhfg1r /bZXeGkCxkooNs7rQyqD6w7P+f1PJoJxu9E= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1632980667530100002 If an EFI application frequently repeats SetTime and GetTime, the I2C bus can be busy and failed to start. To fix this issue, add waiting loop for the bus busy status. (Usually, it is enough to read 3 times for checking, but for safety this sets 10 for timeout.) This also clean up the code path a bit so that it is easy to understand what should do on each combinations of BSR.BB and BCR.MSS. Signed-off-by: Masami Hiramatsu Reported-by: Kazuhiko Sakamoto Contributed-under: TianoCore Contribution Agreement 1.1 --- .../Drivers/SynQuacerI2cDxe/SynQuacerI2cDxe.c | 38 ++++++++++++++--= ---- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/Silicon/Socionext/SynQuacer/Drivers/SynQuacerI2cDxe/SynQuacerI= 2cDxe.c b/Silicon/Socionext/SynQuacer/Drivers/SynQuacerI2cDxe/SynQuacerI2cD= xe.c index 31f6e3072f..380eba8059 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/SynQuacerI2cDxe/SynQuacerI2cDxe.c +++ b/Silicon/Socionext/SynQuacer/Drivers/SynQuacerI2cDxe/SynQuacerI2cDxe.c @@ -16,6 +16,8 @@ // #define WAIT_FOR_INTERRUPT_TIMEOUT 50000 =20 +#define WAIT_FOR_BUS_BUSY_TIMEOUT 10 + /** Set the frequency for the I2C clock line. =20 @@ -152,6 +154,7 @@ SynQuacerI2cMasterStart ( IN EFI_I2C_OPERATION *Op ) { + UINTN Timeout =3D WAIT_FOR_BUS_BUSY_TIMEOUT; UINT8 Bsr; UINT8 Bcr; =20 @@ -167,24 +170,35 @@ SynQuacerI2cMasterStart ( Bsr =3D MmioRead8 (I2c->MmioBase + F_I2C_REG_BSR); Bcr =3D MmioRead8 (I2c->MmioBase + F_I2C_REG_BCR); =20 - if ((Bsr & F_I2C_BSR_BB) && !(Bcr & F_I2C_BCR_MSS)) { - DEBUG ((DEBUG_INFO, "%a: bus is busy\n", __FUNCTION__)); - return EFI_ALREADY_STARTED; - } + if (!(Bcr & F_I2C_BCR_MSS)) { =20 - if (Bsr & F_I2C_BSR_BB) { // Bus is busy - DEBUG ((DEBUG_INFO, "%a: Continuous Start\n", __FUNCTION__)); - MmioWrite8 (I2c->MmioBase + F_I2C_REG_BCR, Bcr | F_I2C_BCR_SCC); - } else { - if (Bcr & F_I2C_BCR_MSS) { - DEBUG ((DEBUG_WARN, - "%a: is not in master mode\n", __FUNCTION__)); - return EFI_DEVICE_ERROR; + if (Bsr & F_I2C_BSR_BB) { // Bus is busy + do { + Bsr =3D MmioRead8 (I2c->MmioBase + F_I2C_REG_BSR); + } while (Timeout-- && (Bsr & F_I2C_BSR_BB)); + + if (Bsr & F_I2C_BSR_BB) { + DEBUG ((DEBUG_INFO, "%a: bus is busy\n", __FUNCTION__)); + return EFI_ALREADY_STARTED; + } } + DEBUG ((DEBUG_INFO, "%a: Start Condition\n", __FUNCTION__)); MmioWrite8 (I2c->MmioBase + F_I2C_REG_BCR, Bcr | F_I2C_BCR_MSS | F_I2C_BCR_INTE | F_I2C_BCR_BEIE); + + } else { // F_I2C_BCR_MSS is set + + if (!(Bsr & F_I2C_BSR_BB)) { + DEBUG ((DEBUG_WARN, + "%a: is not in master mode\n", __FUNCTION__)); + return EFI_DEVICE_ERROR; + } + + DEBUG ((DEBUG_INFO, "%a: Continuous Start\n", __FUNCTION__)); + MmioWrite8 (I2c->MmioBase + F_I2C_REG_BCR, Bcr | F_I2C_BCR_SCC); } + return EFI_SUCCESS; } =20 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#81313): https://edk2.groups.io/g/devel/message/81313 Mute This Topic: https://groups.io/mt/85967424/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-