From nobody Sun Nov 24 18:38:14 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+84621+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+84621+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1639119043; cv=none; d=zohomail.com; s=zohoarc; b=ZffMAgEtb7iU9pDs3rFuohEAvt2klyQjCt0QsBRJaoACMNJjSeS39f8pW3i293mpiN6F1zYeIeHFH4vuLd+dS1MfCbgvMYQM9nDf5fXdLaNqoUaX7bTVq3Vv3kCfK0TPHbNCkzIVpFOZ58RaQQZ6nR8Pqny2QP95EwfxMcBYIYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639119043; 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=h55AvyfIi8mcw+2xrrCITwzqifO8zi8sXiJFdiJLfrw=; b=PjgMLLctoAFQ8/fYIBd7+J5dskFP+yObtAYCqagyqbVwJC7wY4B/kS4dhM3Qq9+k1ijtAHEBDEYso8QP9Jxo30JNJ+Yhs9J41RyeilnX8NV9v95h3yLLHwdC8dA+SnIhZEMmT8YoFtzTW4BU8D56GWYJsMFw+zBct87BHQ9are0= 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+84621+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 1639119043513706.7140113106954; Thu, 9 Dec 2021 22:50:43 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id lb93YY1788612xbS0d2JdvGG; Thu, 09 Dec 2021 22:50:43 -0800 X-Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by mx.groups.io with SMTP id smtpd.web08.4068.1639119042433334757 for ; Thu, 09 Dec 2021 22:50:42 -0800 X-Received: by mail-pf1-f171.google.com with SMTP id g18so7635127pfk.5 for ; Thu, 09 Dec 2021 22:50:42 -0800 (PST) X-Gm-Message-State: ZSXBBpIgPCoAX0qntsQPAcPax1787277AA= X-Google-Smtp-Source: ABdhPJx3eCXnunPwJh/ZbWwNc65FE+AbXGMKQBi85Vt1ZVzSLhj/M9jeuWNjU6muR9j0nh4QfdYyDQ== X-Received: by 2002:a63:c154:: with SMTP id p20mr37475532pgi.132.1639119041913; Thu, 09 Dec 2021 22:50:41 -0800 (PST) X-Received: from localhost.localdomain (122x208x150x49.ap122.ftth.ucom.ne.jp. [122.208.150.49]) by smtp.gmail.com with ESMTPSA id mz7sm11506114pjb.7.2021.12.09.22.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Dec 2021 22:50:41 -0800 (PST) From: "Masami Hiramatsu" To: Ard Biesheuvel , Leif Lindholm Cc: devel@edk2.groups.io, Kazuhiko Sakamoto , Masahisa Kojima Subject: [edk2-devel] [PATCH v3 1/6] [edk2-platforms] Silicon/SynQuacerI2cDxe: Wait for bus ready Date: Fri, 10 Dec 2021 15:50:39 +0900 Message-Id: <163911903882.561661.7568498557575354057.stgit@localhost> In-Reply-To: <163911902995.561661.9429300579159746333.stgit@localhost> References: <163911902995.561661.9429300579159746333.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=1639119043; bh=ibs/2EHfrIgv3fgJchRPIxhllDWO3YrwSRNPgU+M9y0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=i5HnavjKZ7m4erpCO1foF5Xpu7+OUc9OMMnMEGP2TIraJummaPiL/4rLVckcRvDjqvW 3LVrcoXFL1ymuHpfqpo4izR1LYXycks551BulfhFHR51o+WcELK/qZeTOO33b7605FUfR C1s7Ps8G4ZdJJpeOXnWbXLdSghf+Kl+rcxQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639119044393100002 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 --- Changes in v3: - Fix LF to CRLF. - Change title to wait for bus ready. Changes in v2: - Rename WAIT_FOR_BUS_BUSY_TIMEOUT to WAIT_FOR_BUS_READY_TIMEOUT - Fix indentation. --- .../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 8aa9799018..c8646db800 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_READY_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_READY_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 (#84621): https://edk2.groups.io/g/devel/message/84621 Mute This Topic: https://groups.io/mt/87631124/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-