From nobody Sun Nov 24 20:43:42 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+83376+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+83376+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1636104212; cv=none; d=zohomail.com; s=zohoarc; b=ku9mHq6+HjWCYm8ypyV3R0+f8DqKypOJ5YOzWX60gJGBEzWcUn5dIwr/upF9DGq9ZH9HI/quHgRuArplR7WoqVBJMWda7QuFl8sYAa2Ji9pmMpcZ1fr6T7kaeXUxnYNyNVDg7OKT73sZKGEd83XHRH7BDTJgABO7+rtPfz2aixw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636104212; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=99pDHLzeFmmLYzONJ+mF5mpYbO8mg6yD4Q9Oh+lnHWU=; b=CKw2jqB03d0DrbJcgKzfclRuUNziY4g648IuWyt7PG5bHO/RFcdJ0n4i4xcl1JmSshvccdasqdsnfsY2QYpwESZBlkG7hvXWxQTIE91hkYYLgLOO1kJUc82M/z3Va0GCaUvVjJJPZQp0U0FXwAvepPqJsA4p0YD4b3gjiLby/1c= 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+83376+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 1636104212623167.53916401626702; Fri, 5 Nov 2021 02:23:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id HYHcYY1788612x3kLoJCSZSF; Fri, 05 Nov 2021 02:23:32 -0700 X-Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by mx.groups.io with SMTP id smtpd.web10.3063.1636104211666689586 for ; Fri, 05 Nov 2021 02:23:31 -0700 X-Received: by mail-pg1-f170.google.com with SMTP id t7so7887387pgl.9 for ; Fri, 05 Nov 2021 02:23:31 -0700 (PDT) X-Gm-Message-State: V4b5dgg0MExxqJKXq8mZVBoZx1787277AA= X-Google-Smtp-Source: ABdhPJyMI6nbY+0vzTk94fb75UG9cQAi8n9gg52XXJRW491vp+I3fhyStkea7pcGnnedRkC1f1kwww== X-Received: by 2002:a65:408c:: with SMTP id t12mr24526681pgp.262.1636104211227; Fri, 05 Nov 2021 02:23:31 -0700 (PDT) X-Received: from localhost.localdomain (122x208x150x49.ap122.ftth.ucom.ne.jp. [122.208.150.49]) by smtp.gmail.com with ESMTPSA id k16sm142617pfu.183.2021.11.05.02.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Nov 2021 02:23:30 -0700 (PDT) From: "Masami Hiramatsu" To: Ard Biesheuvel , Leif Lindholm Cc: devel@edk2.groups.io, Kazuhiko Sakamoto , Masahisa Kojima Subject: [edk2-devel] [PATCH 1/5] [RESEND][edk2-platforms] Silicon/SynQuacerI2cDxe: Wait for bus busy Date: Fri, 5 Nov 2021 18:23:28 +0900 Message-Id: <163610420797.391624.17492204385268340229.stgit@localhost> In-Reply-To: <163610419943.391624.9289897029386201296.stgit@localhost> References: <163610419943.391624.9289897029386201296.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=1636104212; bh=ciU21sUtPCzf7H+HZnOrvegT7TdxCjHT6ehqal/1eig=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=uO1GcVkA2u+s6NkSVoieW8IUEloY9HBCYoITGEEQJlxAJsfukdXBohF05T6xJ0BnG0l cm1lx6aH36faMIubuIBpOLBHtHe5r0zRMajryqKvJiGXlLSjXTDtgnwvHHNPCyZSk7ZaA NmM6b16r3hBfg2dlhjX+YBfBN3X4m7mvnQs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1636104214283100001 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 --- .../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 (#83376): https://edk2.groups.io/g/devel/message/83376 Mute This Topic: https://groups.io/mt/86836377/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-