Re: [PATCH 1/2] i2c: designware: determine HS tHIGH and tLOW based on HW paramters

From: Krzysztof Kozlowski
Date: Wed Sep 25 2024 - 07:33:39 EST


On 25/09/2024 10:04, 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",

Generic properties should be described in generic schema. Where is this
one defined?

Also, bindings come before users.

Best regards,
Krzysztof