Skip to content

Commit a5f8645

Browse files
cyliangtwfabiobaltieri
authored andcommitted
drivers: pwm: support for numaker m55m1x
Modify Nuvoton numaker pwm driver for m55m1x series. Add pwm nodes in m55m1x.dtsi Signed-off-by: cyliang tw <[email protected]>
1 parent 46a3bbb commit a5f8645

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

drivers/pwm/pwm_numaker.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ LOG_MODULE_REGISTER(pwm_numaker, CONFIG_PWM_LOG_LEVEL);
2525
#define NUMAKER_SYSCLK_FREQ DT_PROP(DT_NODELABEL(sysclk), clock_frequency)
2626
/* EPWM channel 0~5 mask */
2727
#define NUMAKER_PWM_CHANNEL_MASK (0x3FU)
28+
#define NUMAKER_PWM_HCLK0 1U
2829

2930
/* Device config */
3031
struct pwm_numaker_config {
@@ -432,6 +433,29 @@ static int pwm_numaker_clk_get_rate(EPWM_T *epwm, uint32_t *rate)
432433
uint32_t clk_src;
433434
uint32_t epwm_clk_src;
434435

436+
#if defined(CONFIG_SOC_SERIES_M55M1X)
437+
if (epwm == EPWM0) {
438+
clk_src = CLK->EPWMSEL & CLK_EPWMSEL_EPWM0SEL_Msk;
439+
} else if (epwm == EPWM1) {
440+
clk_src = CLK->EPWMSEL & CLK_EPWMSEL_EPWM1SEL_Msk;
441+
} else {
442+
LOG_ERR("Invalid EPWM node");
443+
return -EINVAL;
444+
}
445+
446+
if (clk_src == NUMAKER_PWM_HCLK0) {
447+
/* clock source is from HCLK0 clock */
448+
epwm_clk_src = CLK_GetHCLK0Freq();
449+
} else {
450+
/* clock source is from PCLK */
451+
SystemCoreClockUpdate();
452+
if (epwm == EPWM0) {
453+
epwm_clk_src = CLK_GetPCLK0Freq();
454+
} else { /* (epwm == EPWM1) */
455+
epwm_clk_src = CLK_GetPCLK2Freq();
456+
}
457+
}
458+
#else
435459
if (epwm == EPWM0) {
436460
clk_src = CLK->CLKSEL2 & CLK_CLKSEL2_EPWM0SEL_Msk;
437461
} else if (epwm == EPWM1) {
@@ -453,6 +477,7 @@ static int pwm_numaker_clk_get_rate(EPWM_T *epwm, uint32_t *rate)
453477
epwm_clk_src = CLK_GetPCLK1Freq();
454478
}
455479
}
480+
#endif
456481
*rate = epwm_clk_src;
457482
return 0;
458483
}

dts/arm/nuvoton/m55m1x.dtsi

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,30 @@
436436
status = "disabled";
437437
#io-channel-cells = <1>;
438438
};
439+
440+
epwm0: epwm@40242000 {
441+
compatible = "nuvoton,numaker-pwm";
442+
reg = <0x40242000 0x37c>;
443+
interrupts = <31 0>, <32 0>, <33 0>;
444+
interrupt-names = "pair0", "pair1", "pair2";
445+
resets = <&rst NUMAKER_SYS_EPWM0RST>;
446+
prescaler = <19>;
447+
clocks = <&pcc NUMAKER_EPWM0_MODULE NUMAKER_CLK_EPWMSEL_EPWM0SEL_PCLK0 0>;
448+
#pwm-cells = <3>;
449+
status = "disabled";
450+
};
451+
452+
epwm1: epwm@40282000 {
453+
compatible = "nuvoton,numaker-pwm";
454+
reg = <0x40282000 0x37c>;
455+
interrupts = <35 0>, <36 0>, <37 0>;
456+
interrupt-names = "pair0", "pair1", "pair2";
457+
resets = <&rst NUMAKER_SYS_EPWM1RST>;
458+
prescaler = <19>;
459+
clocks = <&pcc NUMAKER_EPWM1_MODULE NUMAKER_CLK_EPWMSEL_EPWM1SEL_PCLK2 0>;
460+
#pwm-cells = <3>;
461+
status = "disabled";
462+
};
439463
};
440464
};
441465

0 commit comments

Comments
 (0)