From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mx.groups.io with SMTP id smtpd.web10.9140.1638519145727640544 for ; Fri, 03 Dec 2021 00:12:25 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=UpsGIFHj; spf=pass (domain: linaro.org, ip: 209.85.210.176, mailfrom: masami.hiramatsu@linaro.org) Received: by mail-pf1-f176.google.com with SMTP id n26so2175466pff.3 for ; Fri, 03 Dec 2021 00:12:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=xCRxhDrOHfaBRX/iUf27Y+jp/uWu2o2JanmhstS/Rc8=; b=UpsGIFHj7BB0kawP9BNCU5zOcXbb5QloiGykHo8zyo8sBKFZS4JzyUt1EBrrXeeRph QjgpHmtoivxT7OE6Iqv/fhVD8hy55WqltFwZVPDU6qlD/wwG6uSLMRnu1OZhGv3ASWh5 0hiTwOjgSFcpqcMHKgnogH6YGOxHBhAeKc3Il1QtgADgSqB5vGr37HXleK/T4+tfzxCU vCf2WbVf22Yl8/uYF05FFYEEVXi9+v2O2UNG5Lqsrj1ZhN9inBBZ4c5k5uJDKdX2B7JH wxkRwS71Pa77wzpAmyXo/6Q9CMBsJAqBx8dw+kf2r9C/4MUAZIFW3QtzBgsqLBOAYfb/ 7ELw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=xCRxhDrOHfaBRX/iUf27Y+jp/uWu2o2JanmhstS/Rc8=; b=uTsCCedu0iD/cVO4rTXeb2FQO9e0n048CjU4Xx2MO3MZxj/5zD8rHuqE6fCaNWMfUJ pzAd+jh1N9vHsh2mDjEWrRMtY59UOUwispZ+g8UbRBDPOIPCstbXmdQ8o8V8EiBqMdom oUFfkhMa/eBhlY7kOi3FfmjnH7uMqfI6WyxQU2oqIU63o3jrPxstVXuXuPqKaZuw/5q1 HRWGFlaZ2MyyvGLpuR0/C9HqY0GXx3L+OraGOeqFYHkCuFiIpsIK9d7Zz2RJp7aac4iI gHD7SqsiBzJwKgDYX4HWsZFzPdzT9OYCa2BCL+R32BHXgOYs2KwkcIsQsdrukalh911+ NyTw== X-Gm-Message-State: AOAM532D059gUNwqTsx5JmP5GKkek6BGS+HoJKltCXsF7uDHSEBClFnk /vKtYjOd0VfotrDpuVYy/DYU7A== X-Google-Smtp-Source: ABdhPJyLAq27jzoNJ0Cu7rJoYs7moLjGVM6W3RpW+WrJlmE60+p/FOOThDU5iCFWrB/yK8KTK/qV0w== X-Received: by 2002:a63:eb4a:: with SMTP id b10mr3496557pgk.78.1638519145048; Fri, 03 Dec 2021 00:12:25 -0800 (PST) Return-Path: Received: from localhost.localdomain (122x208x150x49.ap122.ftth.ucom.ne.jp. [122.208.150.49]) by smtp.gmail.com with ESMTPSA id k18sm1624484pgb.70.2021.12.03.00.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 00:12:24 -0800 (PST) From: "Masami Hiramatsu" To: Ard Biesheuvel , Leif Lindholm Cc: devel@edk2.groups.io, Kazuhiko Sakamoto , Masahisa Kojima Subject: [PATCH v2 1/5] [edk2-platforms] Silicon/SynQuacerI2cDxe: Wait for bus busy Date: Fri, 3 Dec 2021 17:12:22 +0900 Message-Id: <163851914200.1636051.8878791399296298132.stgit@localhost> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163851913341.1636051.3357297397950801289.stgit@localhost> References: <163851913341.1636051.3357297397950801289.stgit@localhost> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 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/SynQuacerI2cDxe.c b/Silicon/Socionext/SynQuacer/Drivers/SynQuacerI2cDxe/SynQuacerI2cDxe.c index 31f6e3072f..918a9e7752 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 +#define WAIT_FOR_BUS_READY_TIMEOUT 10 + /** Set the frequency for the I2C clock line. @@ -152,6 +154,7 @@ SynQuacerI2cMasterStart ( IN EFI_I2C_OPERATION *Op ) { + UINTN Timeout = WAIT_FOR_BUS_READY_TIMEOUT; UINT8 Bsr; UINT8 Bcr; @@ -167,24 +170,35 @@ SynQuacerI2cMasterStart ( Bsr = MmioRead8 (I2c->MmioBase + F_I2C_REG_BSR); Bcr = MmioRead8 (I2c->MmioBase + F_I2C_REG_BCR); - 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)) { - 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 = 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; }