lkml.org 
[lkml]   [2021]   [Nov]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] i2c: designware: Get HCNT/LCNT values from dts
Date
From: "Wang, Lawrence" <lawrence.wang@nokia-sbell.com>

Current code support config the HCNT/LCNT only via ACPI method. for those
platform that not support ACPI, will get the HCNT/LCNT value based on input
clock. But it is not always accuracy. for example in some platform will get
lower speed(320khz) in fast mode, and get faster speed(105khz/even more) in
standard mode.

This patch makes it possible for the non-ACPI platform to pass more optimal
HCNT/LCNT values to the core driver via dts if they are known beforehand.
If these are not set we use the calculated values.

Signed-off-by: Wang, Lawrence <lawrence.wang@nokia-sbell.com>
---
drivers/i2c/busses/i2c-designware-common.c | 37 +++++++++++++++++++++
drivers/i2c/busses/i2c-designware-core.h | 1 +
drivers/i2c/busses/i2c-designware-platdrv.c | 3 ++
3 files changed, 41 insertions(+)

diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c
index bf2a4920638a..7cdceeaa9741 100644
--- a/drivers/i2c/busses/i2c-designware-common.c
+++ b/drivers/i2c/busses/i2c-designware-common.c
@@ -314,6 +314,43 @@ static inline u32 i2c_dw_acpi_round_bus_speed(struct device *device) { return 0;

#endif /* CONFIG_ACPI */

+struct dw_scl_cfg {
+ u16 ss_hcnt;
+ u16 ss_lcnt;
+ u16 fs_hcnt;
+ u16 fs_lcnt;
+ u16 fp_hcnt;
+ u16 fp_lcnt;
+ u16 hs_hcnt;
+ u16 hs_lcnt;
+};
+
+/*
+ * The HCNT/LCNT information calculated based on the input clock are not always
+ * accurate for some given platform. In some systems get it more higher SCL speed.
+ * On such systems we better get results from dts config.
+ */
+void i2c_dw_scl_timing_configure(struct dw_i2c_dev *dev)
+{
+ int ret;
+ struct dw_scl_cfg i2c_scl_timing;
+
+ ret = device_property_read_u16_array(dev->dev, "dw-i2c-scl-timing",
+ (u16 *)&i2c_scl_timing, sizeof(i2c_scl_timing)/sizeof(u16));
+ if (ret)
+ return;
+
+ dev->ss_hcnt = i2c_scl_timing.ss_hcnt;
+ dev->ss_lcnt = i2c_scl_timing.ss_lcnt;
+ dev->fs_hcnt = i2c_scl_timing.fs_hcnt;
+ dev->fs_lcnt = i2c_scl_timing.fs_lcnt;
+ dev->fp_hcnt = i2c_scl_timing.fp_hcnt;
+ dev->fp_lcnt = i2c_scl_timing.fp_lcnt;
+ dev->hs_hcnt = i2c_scl_timing.hs_hcnt;
+ dev->hs_lcnt = i2c_scl_timing.hs_lcnt;
+}
+EXPORT_SYMBOL_GPL(i2c_dw_scl_timing_configure);
+
void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev)
{
u32 acpi_speed = i2c_dw_acpi_round_bus_speed(dev->dev);
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 60a2e750cee9..536b30ea723b 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -372,6 +372,7 @@ static inline int i2c_dw_probe_lock_support(struct dw_i2c_dev *dev) { return 0;

int i2c_dw_validate_speed(struct dw_i2c_dev *dev);
void i2c_dw_adjust_bus_speed(struct dw_i2c_dev *dev);
+void i2c_dw_scl_timing_configure(struct dw_i2c_dev *dev);

#if IS_ENABLED(CONFIG_ACPI)
int i2c_dw_acpi_configure(struct device *device);
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index 21113665ddea..b08177edf1fc 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -237,6 +237,9 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
t = &dev->timings;
i2c_parse_fw_timings(&pdev->dev, t, false);

+ // Try to get HCNT/LCNT from dts
+ i2c_dw_scl_timing_configure(dev);
+
i2c_dw_adjust_bus_speed(dev);

if (pdev->dev.of_node)
--
2.25.1
\
 
 \ /
  Last update: 2021-11-15 10:36    [W:0.044 / U:0.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site