Hi
On 9/25/24 11:04 AM, Michael Wu wrote:
In commit 35eba185fd1a ("i2c: designware: Calculate SCL timing
parameter for High Speed Mode") hs_hcnt and hs_hcnt are computed based on
fixed tHIGH = 160 and tLOW = 320. However, this fixed values only applies
to the set of conditions of IC_CAP_LOADING = 400pF and
IC_FREQ_OPTIMIZATION = 1. Outside of this conditions set, if this fixed
values are still used, the calculated HCNT and LCNT will make the SCL
frequency unabled to reach 3.4 MHz.
If hs_hcnt and hs_lcnt are calculated based on fixed tHIGH = 160 and
tLOW = 320, SCL frequency may not reach 3.4 MHz when IC_CAP_LOADING is not
400pF or IC_FREQ_OPTIMIZATION is not 1.
Section 3.15.4.5 in DesignWare DW_apb_i2c Databook v2.03 says when
IC_CLK_FREQ_OPTIMIZATION = 0,
MIN_SCL_HIGHtime = 60 ns for 3.4 Mbps, bus loading = 100pF
= 120 ns for 3,4 Mbps, bus loading = 400pF
MIN_SCL_LOWtime = 160 ns for 3.4 Mbps, bus loading = 100pF
= 320 ns for 3.4 Mbps, bus loading = 400pF
and section 3.15.4.6 says when IC_CLK_FREQ_OPTIMIZATION = 1,
MIN_SCL_HIGHtime = 60 ns for 3.4 Mbps, bus loading = 100pF
= 160 ns for 3.4 Mbps, bus loading = 400pF
MIN_SCL_LOWtime = 120 ns for 3.4 Mbps, bus loading = 100pF
= 320 ns for 3.4 Mbps, bus loading = 400pF
In order to calculate more accurate hs_hcnt and hs_lcnt, two hardware
parameters IC_CAP_LOADING and IC_CLK_FREQ_OPTIMIZATION must be
considered together.
Signed-off-by: Michael Wu <michael.wu@xxxxxxxxx>
---
drivers/i2c/busses/i2c-designware-common.c | 16 ++++++++++++++
drivers/i2c/busses/i2c-designware-core.h | 8 +++++++
drivers/i2c/busses/i2c-designware-master.c | 24 +++++++++++++++++++--
drivers/i2c/busses/i2c-designware-platdrv.c | 2 ++
4 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c
index e8a688d04aee..f0a7d0ce6fd6 100644
--- a/drivers/i2c/busses/i2c-designware-common.c
+++ b/drivers/i2c/busses/i2c-designware-common.c
@@ -332,6 +332,22 @@ void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev)
}
EXPORT_SYMBOL_GPL(i2c_dw_adjust_bus_speed);
+void i2c_dw_parse_of(struct dw_i2c_dev *dev)
+{
+ int ret;
+
+ ret = device_property_read_u32(dev->dev, "bus-loading",
+ &dev->bus_loading);
Like Andy said better name would be bus_capacitance_pf.
Also i2c_dw_parse_of() sounds too generic and may lead to think all and
only device tree related parameters are parsed here.
+ if (ret || dev->bus_loading < 400)
+ dev->bus_loading = 100;
+ else
+ dev->bus_loading = 400;
+
I think these are more understandable and robust if no parameter
adjustments are not done here but used straight in the if statements in
the i2c_dw_set_timings_master(). Less if statements that way and all
checked in one place.