From 5e4affd23d84c1f025a3de14e94cb088ba601445 Mon Sep 17 00:00:00 2001 From: SamulKyull <166363804+SamulKyull@users.noreply.github.com> Date: Sat, 13 Apr 2024 01:30:08 +0800 Subject: [PATCH] fix dw read state error --- .../sunxi_device/hardware/lowlevel_hdmi20/dw_i2cm.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bsp/drivers/drm/sunxi_device/hardware/lowlevel_hdmi20/dw_i2cm.c b/bsp/drivers/drm/sunxi_device/hardware/lowlevel_hdmi20/dw_i2cm.c index 08dd4f8d7f..1a5bd41542 100644 --- a/bsp/drivers/drm/sunxi_device/hardware/lowlevel_hdmi20/dw_i2cm.c +++ b/bsp/drivers/drm/sunxi_device/hardware/lowlevel_hdmi20/dw_i2cm.c @@ -63,7 +63,7 @@ int _dw_i2cm_read(unsigned char *buf, unsigned int length) { u8 state = 0x0; int timeout = DW_I2CM_TIMEOUT; - u8 retry_cnt = 5; + u8 retry_cnt = 2; log_trace1(length); @@ -87,11 +87,13 @@ int _dw_i2cm_read(unsigned char *buf, unsigned int length) dw_write(I2CM_OPERATION, I2CM_OPERATION_RD_MASK); do { - udelay(20); - state = dw_read(IH_I2CM_STAT0); + udelay(10); + state = dw_read_mask(IH_I2CM_STAT0, + IH_I2CM_STAT0_I2CMASTERERROR_MASK + | IH_I2CM_STAT0_I2CMASTERDONE_MASK); } while ((state == 0) && (timeout--)); - if ((state == 0) && (timeout == 0)) { + if ((state == 0) || (timeout == 0)) { /* TODO, i2c may has issue. try to sw reset */ hdmi_inf("i2c read wait state timeout\n"); return -2; @@ -154,8 +156,9 @@ int _dw_i2cm_write(unsigned char *buf, unsigned int length) state = dw_read(IH_I2CM_STAT0); } while ((state == 0) && (timeout--)); - if ((state == 0) && (timeout == 0)) { + if ((state == 0) || (timeout == 0)) { /* TODO, i2c may has issue. try to sw reset */ + hdmi_inf("i2c read wait state timeout\n"); return -2; }