From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=tFzOEuKF; spf=pass (domain: linaro.org, ip: 209.85.215.170, mailfrom: masami.hiramatsu@linaro.org) Received: by mail-pg1-f170.google.com with SMTP id t7so7887387pgl.9 for ; Fri, 05 Nov 2021 02:23:31 -0700 (PDT) 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=gxUCQ5YuLH6uVec3+hb+eNJaPsZJlKrBVMsVAfKmldg=; b=tFzOEuKFoLFCdHkqTK0Xljkqon2b48AkFC9xSzokcUALxdqE+KTVSSYNCFBUyGxi9F ySBvPymh1+HYkQ2pNbJU/2m76fCdm+Z7gnnntFNUvkSOqoahGPB1IWZaigFSqDG+lGw7 SK5L4PbjD60zqdLetixgsldhkR5fjfjlEuJFAfozkj7CCL7i0Cq0T0lWvB8pjNdOEAq7 YzLpb2A0eB0f2MCfnBYXpdDdi92gmWEzTuWwB8c14lQOtPBuYhjG7+IUC4dhTXnPOtzx HUHsyr/r6d+snfqACLH4CnUCXOwKheGUEKHWX1OGTlFYw29W1l5/a/VJDYPPCmNGDeBw MOKA== 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=gxUCQ5YuLH6uVec3+hb+eNJaPsZJlKrBVMsVAfKmldg=; b=ebaVCsalfjXbqlgjnIGVuzGS/iQGS+eHtgUNyHC7TmQe7yOhMOLpNZg0XwsL36VHpg 80kFsN0j4DwJAvGg5Yf8Pmv6Jwk/E2UgXTMEIergYrIIF7ORBuC4ZHmTEoNRrqYeLC4v gf5BFUt2F1GBueaNHvbfCyXea5DanfL6XM1EnODcR3CfZHIw//9f7Sy6YcKVTAx84e9y 8j9ZK9u9kQOpxf5QwcRwvDkCvME7/E4fZZ2zCXYgSecDoPOdvSuzq9tPCCyfVrcW13PU RCCc+Uk6IRgcpKmpJgZ/sWnpIovKo+4tQ+VWlI/pc6iX6RtGDVeMqtaPVo52TcNO4NE8 y9wA== X-Gm-Message-State: AOAM532SardgOjzwD+ysGGKNgxm0yoe4wH77dOV2R7ZVxZliguI9kBrl vuY/h9HinDK6qZ5exce/Fncbig== 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163610419943.391624.9289897029386201296.stgit@localhost> References: <163610419943.391624.9289897029386201296.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 --- .../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..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 +#define WAIT_FOR_BUS_BUSY_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_BUSY_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; }