Designware i2c driver, HCNT calculation logic

Manav Bedi mbedi.mb at gmail.com
Fri Sep 2 13:39:02 CEST 2022


In Designware I2C Uboot driver, the HCNT calculation in Fast plus mode(1MHZ
clock transfer rate) seems to be incorrect with default values present in
the driver.

In function, dw_i2c_calc_timing(), hcnt is being calculated using below
formula:-

"hcnt = min_thigh_cnt - fall_cnt - 7 - spk_cnt;"

With 1MHz tranfer rate and default values from the driver, min_thigh_cnt is
computed to be 26, fall_cnt to 50, and spk_cnt is 0.

So, hcnt comes out to be:- 26 - 50 - 7 - 0 = -31.

And as Hcnt comes out to be negative, the further check fails which checks
if either of hcnt or lcnt is negative, then return unsuccessful status:-

if (hcnt < 0 || lcnt < 0)
{ debug("dw_i2c: bad counts. hcnt = %d lcnt = %d\n", hcnt, lcnt); return
log_msg_ret("counts", -EINVAL); }

This appears to be failing for the higher transfer rates as well, i.e. High
speed mode as well.

Can someone confirm if this logic is correct?

Regards
Manav


More information about the U-Boot mailing list