Skip to content

Commit 2b4227c

Browse files
committed
drivers: can: numaker: fix m55m1x core clock
On M55M1 series, the clock module index is virtual to stay compatible with 32-bit only cell value in devicetree. Its real value of being 64-bit integer needs to acquire indirectly. Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
1 parent 9e6256e commit 2b4227c

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

drivers/can/can_numaker.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#include <soc.h>
1717
#include <NuMicro.h>
1818

19+
#if defined(CONFIG_SOC_SERIES_M55M1X)
20+
#include <zephyr/dt-bindings/clock/numaker_m55m1x_clock.h>
21+
#endif
22+
1923
LOG_MODULE_REGISTER(can_numaker, CONFIG_CAN_LOG_LEVEL);
2024

2125
/* Implementation notes
@@ -42,11 +46,27 @@ static int can_numaker_get_core_clock(const struct device *dev, uint32_t *rate)
4246
const struct can_numaker_config *config = mcan_config->custom;
4347
uint32_t clksrc_rate_idx;
4448
uint32_t clkdiv_divider;
49+
__typeof__(CANFD0_MODULE) clk_modidx_real;
50+
51+
#if defined(CONFIG_SOC_SERIES_M55M1X)
52+
switch (config->clk_modidx) {
53+
case NUMAKER_CANFD0_MODULE:
54+
clk_modidx_real = CANFD0_MODULE;
55+
break;
56+
case NUMAKER_CANFD1_MODULE:
57+
clk_modidx_real = CANFD1_MODULE;
58+
default:
59+
LOG_ERR("Invalid clock module index");
60+
return -EIO;
61+
}
62+
#else
63+
clk_modidx_real = config->clk_modidx;
64+
#endif
4565

4666
/* Module clock source rate */
47-
clksrc_rate_idx = CLK_GetModuleClockSource(config->clk_modidx);
67+
clksrc_rate_idx = CLK_GetModuleClockSource(clk_modidx_real);
4868
/* Module clock divider */
49-
clkdiv_divider = CLK_GetModuleClockDivider(config->clk_modidx) + 1;
69+
clkdiv_divider = CLK_GetModuleClockDivider(clk_modidx_real) + 1;
5070

5171
switch (clksrc_rate_idx) {
5272
#if defined(CONFIG_SOC_SERIES_M46X)

0 commit comments

Comments
 (0)