From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=EQih4k7T; spf=pass (domain: linaro.org, ip: 209.85.210.171, mailfrom: masami.hiramatsu@linaro.org) Received: by mail-pf1-f171.google.com with SMTP id g18so7635127pfk.5 for ; Thu, 09 Dec 2021 22:50:42 -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=3mjT6hDAqL0Py1WetzT1UjfmCfIyJhAp9KWJIbBwtl8=; b=EQih4k7T24J0HnamX+f+8AKi8b08fldkGT4fBbzE1BWEQCLhVFKMin2p2cW8bRGjXJ mKX7PaUHyfCf2Yy8rgp6oxHyHFjMqNX7i33DXd0RU8esdNPvKRE8OARyC4LQY78Eodnn nDCam90x73Igfgv4iKaZuPdIjOXdrAB7pWgGYl1KWflbpyt6qTKg3J9ycuwCg6/oP5Ai ilgth/kBbxAwryYYXaMvsNs/DYQKqumuuC9ddSgOSDCMX651o61vjRSLtl/qVsdI3JZM jINXdUiCIFBcodwXQIZQUoXocYBziLaoWKhEc7cRb7XfGiiNBRTf0N7ObLh/c04/3Hd3 VkHA== 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=3mjT6hDAqL0Py1WetzT1UjfmCfIyJhAp9KWJIbBwtl8=; b=p5JNh/8ayyQZMF9XGkjE7txnx3xNUwfJODZ0mRBwJcDv11PVtHbNIk2Na04xp8vuuX 2Wk8ykUmf7AxIi3ESfwMLljCvio+KT3Hsjjl7SpEcmr0QqXNOBJZUQ04i7DcJ8IWfqAt kkqGwF06GLNq7opI2FWqb2z805Xr0pyMtiJBtzYpIX6dhLyBj4DvGhUPw/r0gEadeD01 Egf2KVk/db2Q7HQirJ24hLgmqatGvHfRqDUv7fPQAUHA5zyVoTMxE7w6XfSYkfNOpNaB 93+xQVzyUfOgH95vzfF1LXFUJ4BRYZBdJTwwsFWa6Qxhuqqr6iQrRx5ZluMm1K0pt6i/ TAUA== X-Gm-Message-State: AOAM5314ZL79hMZ8mjoHRS6qDulGiu2iMCyu5KhxAI10jeAZp35wRBXt TgazEqR+SpySNvFu9qNF+MUeMA== 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163911902995.561661.9429300579159746333.stgit@localhost> References: <163911902995.561661.9429300579159746333.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 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/SynQuacerI2cDxe.c b/Silicon/Socionext/SynQuacer/Drivers/SynQuacerI2cDxe/SynQuacerI2cDxe.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 +#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; }