From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4864:20::544; helo=mail-pg1-x544.google.com; envelope-from=ming.huang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 757DE210F16CC for ; Tue, 14 Aug 2018 01:10:42 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id r1-v6so8778695pgp.11 for ; Tue, 14 Aug 2018 01:10:42 -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; bh=ne7UD5d46U3RJ9EVF2uqubhT3FmUwsR/vgU37WDXFUM=; b=aJdvkUugVXDJcEGEhyiS37DSxBwzfUhVGYnCniRnHFLL6PCz3PikQjnc3wKy2W+s54 +AjFDY2nepIqcfoFm65LNZOa8kMIS/ZjGJL3TBmPUHrrP/AMya1Dihxh5najqfvkMahj YCkomKv9zJA5wXFGCERujzVPwS166dTRnbdMw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ne7UD5d46U3RJ9EVF2uqubhT3FmUwsR/vgU37WDXFUM=; b=ncRZ9KXxmpHyPcMV4YHsrJGQ5IHdDracEHP44Tkd+1ZLy3TBz8aXZScgNpVahghvt+ RvmjR4H+fIDq7Kk9Dhj1F/34rDirurNdU6Px5XLha44M7Va4qfUg9foEb4J2ztIT8dQC v2X7enfljwCIRJYNHW9qgpKdmLgAOxHnEttyLPVrDDmj8JlO1mG7k6j/eNf0x7KlWh99 w8yO22WWPXmaQ7W77i9ad6AcgBN17QY3SuPtxVC+2FziFYt7cMCMkF/C9+2XDneNWVAf 2fIAk/WimkiC0xpNh5x2zwubw2+DjuMCXm5a3K7J6ZXbMiwt7Uclkurc/4dMNDbucEpz D1OQ== X-Gm-Message-State: AOUpUlFxyoSNwVhuVaZhhL0BDmYf69SxyK495lQV7mXlum1YXJeVbge0 6ondENbuD5hoAE36/7RbCqyqCg== X-Google-Smtp-Source: AA+uWPzbhTrZ5Pi4smnVYxvM/f26fZbUu7iwlSsDat5JhZgke15wLoK/KQB/U7ZPvc6bMwz1iW6vhA== X-Received: by 2002:a62:6746:: with SMTP id b67-v6mr22269600pfc.243.1534234242194; Tue, 14 Aug 2018 01:10:42 -0700 (PDT) Received: from localhost.localdomain ([120.31.149.194]) by smtp.gmail.com with ESMTPSA id h130-v6sm72905670pgc.88.2018.08.14.01.10.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Aug 2018 01:10:41 -0700 (PDT) From: Ming Huang To: leif.lindholm@linaro.org, linaro-uefi@lists.linaro.org, edk2-devel@lists.01.org, graeme.gregory@linaro.org Cc: ard.biesheuvel@linaro.org, michael.d.kinney@intel.com, lersek@redhat.com, guoheyi@huawei.com, wanghuiqiang@huawei.com, huangming23@huawei.com, zhangjinsong2@huawei.com, huangdaode@hisilicon.com, john.garry@huawei.com, xinliang.liu@linaro.org, Ming Huang Date: Tue, 14 Aug 2018 16:08:42 +0800 Message-Id: <20180814080903.50466-23-ming.huang@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180814080903.50466-1-ming.huang@linaro.org> References: <20180814080903.50466-1-ming.huang@linaro.org> Subject: [PATCH edk2-platforms v2 22/43] Silicon/Hisilicon/D06: Fix I2C enable fail issue for D06 X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Aug 2018 08:10:42 -0000 I2C may enable failed in D06, so retry I2C enable while enable failed. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ming Huang --- Silicon/Hisilicon/Library/I2CLib/I2CLib.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Silicon/Hisilicon/Library/I2CLib/I2CLib.c b/Silicon/Hisilicon/Library/I2CLib/I2CLib.c index 9174e50dd4..d67ddc7f9b 100644 --- a/Silicon/Hisilicon/Library/I2CLib/I2CLib.c +++ b/Silicon/Hisilicon/Library/I2CLib/I2CLib.c @@ -86,6 +86,7 @@ I2C_Enable ( { I2C0_ENABLE_U I2cEnableReg; I2C0_ENABLE_STATUS_U I2cEnableStatusReg; + UINT32 TimeCnt = I2C_READ_TIMEOUT; UINTN Base = GetI2cBase (Socket, Port); @@ -93,13 +94,18 @@ I2C_Enable ( I2cEnableReg.bits.enable = 1; I2C_REG_WRITE (Base + I2C_ENABLE_OFFSET, I2cEnableReg.Val32); + do { + // This is a empirical value for I2C delay. MemoryFance is no need here. + I2C_Delay (10000); - I2C_REG_READ (Base + I2C_ENABLE_STATUS_OFFSET, I2cEnableStatusReg.Val32); - if (I2cEnableStatusReg.bits.ic_en == 1) { - return EFI_SUCCESS; - } else { - return EFI_DEVICE_ERROR; - } + TimeCnt--; + I2C_REG_READ (Base + I2C_ENABLE_STATUS_OFFSET, I2cEnableStatusReg.Val32); + if (TimeCnt == 0) { + return EFI_DEVICE_ERROR; + } + } while (I2cEnableStatusReg.bits.ic_en == 0); + + return EFI_SUCCESS; } VOID -- 2.17.0