From: shaochangliang <[email protected]>

I2C may enable failed in D06, so retry I2C enable while
enable failed.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: shaochangliang <[email protected]>
Signed-off-by: Ming Huang <[email protected]>
Signed-off-by: Heyi Guo <[email protected]>
---
 Silicon/Hisilicon/Library/I2CLib/I2CLib.c | 22 ++++++++++++--------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/Silicon/Hisilicon/Library/I2CLib/I2CLib.c 
b/Silicon/Hisilicon/Library/I2CLib/I2CLib.c
index b5b388d756..ecd2f07c4d 100644
--- a/Silicon/Hisilicon/Library/I2CLib/I2CLib.c
+++ b/Silicon/Hisilicon/Library/I2CLib/I2CLib.c
@@ -83,6 +83,7 @@ I2C_Enable(UINT32 Socket,UINT8 Port)
 {
     I2C0_ENABLE_U           I2cEnableReg;
     I2C0_ENABLE_STATUS_U    I2cEnableStatusReg;
+    UINT32                  ulTimeCnt = I2C_READ_TIMEOUT;
 
     UINTN Base = GetI2cBase(Socket, Port);
 
@@ -91,16 +92,19 @@ I2C_Enable(UINT32 Socket,UINT8 Port)
     I2cEnableReg.bits.enable = 1;
     I2C_REG_WRITE(Base + I2C_ENABLE_OFFSET, I2cEnableReg.Val32);
 
-
-    I2C_REG_READ(Base + I2C_ENABLE_STATUS_OFFSET, I2cEnableStatusReg.Val32);
-    if (1 == I2cEnableStatusReg.bits.ic_en)
+    do
     {
-        return EFI_SUCCESS;
-    }
-    else
-    {
-        return EFI_DEVICE_ERROR;
-    }
+        I2C_Delay(10000);
+
+        ulTimeCnt--;
+        I2C_REG_READ(Base + I2C_ENABLE_STATUS_OFFSET, 
I2cEnableStatusReg.Val32);
+        if (0 == ulTimeCnt)
+        {
+            return EFI_DEVICE_ERROR;
+        }
+    }while (0 == I2cEnableStatusReg.bits.ic_en);
+
+    return EFI_SUCCESS;
 }
 
 void I2C_SetTarget(UINT32 Socket,UINT8 Port,UINT32 I2cDeviceAddr)
-- 
2.17.0

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to