[PATCH 6.1.y-cip] i3c: master: dw: stop hardcoding initial speed
Nobuhiro Iwamatsu <[email protected]> Tue, 21 Jul 2026 10:49:26 +0900
| Newsgroups | org.cip-project.lists.cip-dev |
|---|---|
| Message-ID | <1784598566-26268-1-git-send-email-nobuhiro.iwamatsu.x90@mail.toshiba> |
From: Jack Chen <[email protected]> commit 510d2358c466bf6588034f0d3b2266eed2bc0a51 upstream. Bus-speed could be default(12.5MHz) or defined by users in dts. Dw-i3c-master should not hard-code the initial speed to be I3C_BUS_TYP_I3C_SCL_RATE (12.5MHz) And because of Synopsys's I3C controller limit (hcnt/lcnt register length) and core-clk provided, there is a limit to bus speed, too. For example, when core-clk is 250 MHz, the bus speed cannot be lowered below 1MHz. Tested: tested with an i3c sensor and captured with a logic analyzer. Signed-off-by: Jack Chen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Belloni <[email protected]> Signed-off-by: Nobuhiro Iwamatsu <[email protected]> --- This fixes a build error in “drivers/i3c/master/dw-i3c-master.c” caused by a Renesas backport patch. ``` CC drivers/i3c/master/dw-i3c-master.o In file included from ./include/vdso/const.h:5, from ./include/linux/const.h:4, from ./include/linux/bits.h:5, from ./include/linux/bitops.h:6, from drivers/i3c/master/dw-i3c-master.c:8: drivers/i3c/master/dw-i3c-master.c: In function ‘dw_i3c_clk_cfg’: drivers/i3c/master/dw-i3c-master.c:534:40: error: ‘I3C_BUS_TYP_I3C_SCL_RATE’ undeclared (first use in this function); did you mean ‘I3C_BUS_SDR3_SCL_RATE’? 534 | lcnt = DIV_ROUND_UP(core_rate, I3C_BUS_TYP_I3C_SCL_RATE) - hcnt; | ^~~~~~~~~~~~~~~~~~~~~~~~ ./include/uapi/linux/const.h:34:46: note: in definition of macro ‘__KERNEL_DIV_ROUND_UP’ 34 | #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) | ^ drivers/i3c/master/dw-i3c-master.c:534:16: note: in expansion of macro ‘DIV_ROUND_UP’ 534 | lcnt = DIV_ROUND_UP(core_rate, I3C_BUS_TYP_I3C_SCL_RATE) - hcnt; | ^~~~~~~~~~~~ drivers/i3c/master/dw-i3c-master.c:534:40: note: each undeclared identifier is reported only once for each function it appears in 534 | lcnt = DIV_ROUND_UP(core_rate, I3C_BUS_TYP_I3C_SCL_RATE) - hcnt; | ^~~~~~~~~~~~~~~~~~~~~~~~ ./include/uapi/linux/const.h:34:46: note: in definition of macro ‘__KERNEL_DIV_ROUND_UP’ 34 | #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) | ^ drivers/i3c/master/dw-i3c-master.c:534:16: note: in expansion of macro ‘DIV_ROUND_UP’ 534 | lcnt = DIV_ROUND_UP(core_rate, I3C_BUS_TYP_I3C_SCL_RATE) - hcnt; | ^~~~~~~~~~~~ make[4]: *** [scripts/Makefile.build:250: drivers/i3c/master/dw-i3c-master.o] Error 1 make[3]: *** [scripts/Makefile.build:503: drivers/i3c/master] Error 2 make[2]: *** [scripts/Makefile.build:503: drivers/i3c] Error 2 make[1]: *** [scripts/Makefile.build:503: drivers] Error 2 make: *** [Makefile:2025: .] Error 2 ``` drivers/i3c/master/dw-i3c-master.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c index d6585d0a20c50..8af2229df82ae 100644 --- a/drivers/i3c/master/dw-i3c-master.c +++ b/drivers/i3c/master/dw-i3c-master.c @@ -531,7 +531,7 @@ static int dw_i3c_clk_cfg(struct dw_i3c_master *master) if (hcnt < SCL_I3C_TIMING_CNT_MIN) hcnt = SCL_I3C_TIMING_CNT_MIN; - lcnt = DIV_ROUND_UP(core_rate, I3C_BUS_TYP_I3C_SCL_RATE) - hcnt; + lcnt = DIV_ROUND_UP(core_rate, master->base.bus.scl_rate.i3c) - hcnt; if (lcnt < SCL_I3C_TIMING_CNT_MIN) lcnt = SCL_I3C_TIMING_CNT_MIN; @@ -541,7 +541,8 @@ static int dw_i3c_clk_cfg(struct dw_i3c_master *master) if (!(readl(master->regs + DEVICE_CTRL) & DEV_CTRL_I2C_SLAVE_PRESENT)) writel(BUS_I3C_MST_FREE(lcnt), master->regs + BUS_FREE_TIMING); - lcnt = DIV_ROUND_UP(I3C_BUS_TLOW_OD_MIN_NS, core_period); + lcnt = max_t(u8, + DIV_ROUND_UP(I3C_BUS_TLOW_OD_MIN_NS, core_period), lcnt); scl_timing = SCL_I3C_TIMING_HCNT(hcnt) | SCL_I3C_TIMING_LCNT(lcnt); writel(scl_timing, master->regs + SCL_I3C_OD_TIMING); -- 2.53.0