Skip to content

Commit

Permalink
drivers: clock_control: support numaker 64-bit clock module index (dr…
Browse files Browse the repository at this point in the history
…aft 2)

This is a draft of supporting 64-bit clock module index on NuMaker SoC series.
Relevant points include:
1. No m55m1x yet, take m2l31x as an example
2. In binding file nuvoton,numaker-pcc.yaml, add clock cell clock-module-index-hi32
3. In clock header file for DT, 64-bit value of FOO_MODULE macro expands to two 32-bit cells in BE order
   NOTE: See dt-bindings/clock/numaker_m2l31x_clock.h
   NOTE: Check the link for requirement of 64-bit integer in zephyr
         https://docs.zephyrproject.org/latest/build/dts/intro-syntax-structure.html
4. Clock ontrol driver is soc-conditional on clock module index
5. Other drivers (gpio, serial, etc.) also must be soc-conditional on clock module index

Changes to existent soc port (taking m46x as an example):
1. In m46x.dtsi, change #clock-cells to 4 from 3
2. Re-generate numaker_m46x_clock.h which has FOO_MODULE macro expanding to two cells, with MSB cell being 0x0
3. No need to change other drivers for not supporting 64-bit module index

Signed-off-by: Chun-Chieh Li <[email protected]>
  • Loading branch information
ccli8 committed Jun 17, 2024
1 parent 17889d2 commit 47bfb61
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 87 deletions.
15 changes: 14 additions & 1 deletion drivers/gpio/gpio_numaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ struct gpio_numaker_config {
uint32_t reg;
uint32_t gpa_base;
uint32_t size;
#if defined(CONFIG_SOC_SERIES_M2L31X)
uint64_t clk_modidx;
#else
uint32_t clk_modidx;
#endif
const struct device *clk_dev;
};

Expand Down Expand Up @@ -226,6 +230,15 @@ static void gpio_numaker_isr(const struct device *dev)

#define CLOCK_CTRL_INIT(n) .clk_dev = DEVICE_DT_GET(DT_PARENT(DT_INST_CLOCKS_CTLR(n))),

#if defined(CONFIG_SOC_SERIES_M2L31X)
#define CLOCK_MODULE_INDEX_INIT(n) \
(((uint64_t) DT_INST_CLOCKS_CELL(n, clock_module_index_hi32)) << 32) \
|DT_INST_CLOCKS_CELL(n, clock_module_index)
#else
#define CLOCK_MODULE_INDEX_INIT(n) \
DT_INST_CLOCKS_CELL(n, clock_module_index)
#endif

#define GPIO_NUMAKER_IRQ_INIT(n) \
do { \
IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), gpio_numaker_isr, \
Expand All @@ -242,7 +255,7 @@ static void gpio_numaker_isr(const struct device *dev)
.reg = DT_INST_REG_ADDR(n), \
.gpa_base = DT_REG_ADDR(DT_NODELABEL(gpioa)), \
.size = DT_REG_SIZE(DT_NODELABEL(gpioa)), \
.clk_modidx = DT_INST_CLOCKS_CELL(n, clock_module_index), \
.clk_modidx = CLOCK_MODULE_INDEX_INIT(n), \
CLOCK_CTRL_INIT(n)}; \
\
static struct gpio_numaker_data gpio_numaker_data##n; \
Expand Down
15 changes: 14 additions & 1 deletion drivers/serial/uart_numaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ LOG_MODULE_REGISTER(numaker_uart, LOG_LEVEL_ERR);
struct uart_numaker_config {
UART_T *uart;
const struct reset_dt_spec reset;
#if defined(CONFIG_SOC_SERIES_M2L31X)
uint64_t clk_modidx;
#else
uint32_t clk_modidx;
#endif
uint32_t clk_src;
uint32_t clk_div;
const struct device *clk_dev;
Expand Down Expand Up @@ -405,6 +409,15 @@ static const struct uart_driver_api uart_numaker_driver_api = {

#define CLOCK_CTRL_INIT(n) .clk_dev = DEVICE_DT_GET(DT_PARENT(DT_INST_CLOCKS_CTLR(n))),

#if defined(CONFIG_SOC_SERIES_M2L31X)
#define CLOCK_MODULE_INDEX_INIT(n) \
(((uint64_t) DT_INST_CLOCKS_CELL(n, clock_module_index_hi32)) << 32) \
|DT_INST_CLOCKS_CELL(n, clock_module_index)
#else
#define CLOCK_MODULE_INDEX_INIT(n) \
DT_INST_CLOCKS_CELL(n, clock_module_index)
#endif

#define PINCTRL_DEFINE(n) PINCTRL_DT_INST_DEFINE(n);
#define PINCTRL_INIT(n) .pincfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n),

Expand All @@ -429,7 +442,7 @@ static const struct uart_driver_api uart_numaker_driver_api = {
static const struct uart_numaker_config uart_numaker_cfg_##inst = { \
.uart = (UART_T *)DT_INST_REG_ADDR(inst), \
.reset = RESET_DT_SPEC_INST_GET(inst), \
.clk_modidx = DT_INST_CLOCKS_CELL(inst, clock_module_index), \
.clk_modidx = CLOCK_MODULE_INDEX_INIT(inst), \
.clk_src = DT_INST_CLOCKS_CELL(inst, clock_source), \
.clk_div = DT_INST_CLOCKS_CELL(inst, clock_divider), \
CLOCK_CTRL_INIT(inst).irq_n = DT_INST_IRQN(inst), \
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nuvoton/m2l31x.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

pcc: peripheral-clock-controller {
compatible = "nuvoton,numaker-pcc";
#clock-cells = <3>;
#clock-cells = <4>;
};
};

Expand Down
9 changes: 5 additions & 4 deletions dts/bindings/clock/nuvoton,numaker-pcc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ include: [clock-controller.yaml, base.yaml]

properties:
"#clock-cells":
const: 3
const: 4

clock-cells:
- clock-module-index # Same as u32ModuleIdx on invoking BSP CLK driver CLK_SetModuleClock()
- clock-source # Same as u32ClkSrc on invoking BSP CLK driver CLK_SetModuleClock()
- clock-divider # Same as u32ClkDiv on invoking BSP CLK driver CLK_SetModuleClock()
- clock-module-index-hi32 # Same as u32ModuleIdx/u64ModuleIdx on invoking BSP CLK driver
- clock-module-index # CLK_SetModuleClock()
- clock-source # Same as u32ClkSrc on invoking BSP CLK driver CLK_SetModuleClock()
- clock-divider # Same as u32ClkDiv on invoking BSP CLK driver CLK_SetModuleClock()
6 changes: 5 additions & 1 deletion include/zephyr/drivers/clock_control/clock_control_numaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ struct numaker_scc_subsys {
uint32_t subsys_id; /* SCC sybsystem ID */

/* Peripheral clock control configuration structure
* clk_modidx is same as u32ModuleIdx in BSP CLK_SetModuleClock().
* clk_modidx is same as u32ModuleIdx/u64ModuleIdx in BSP CLK_SetModuleClock().
* clk_src is same as u32ClkSrc in BSP CLK_SetModuleClock().
* clk_div is same as u32ClkDiv in BSP CLK_SetModuleClock().
*/
union {
struct {
#if defined(CONFIG_SOC_SERIES_M2L31X)
uint64_t clk_modidx;
#else
uint32_t clk_modidx;
#endif
uint32_t clk_src;
uint32_t clk_div;
} pcc;
Expand Down
158 changes: 79 additions & 79 deletions include/zephyr/dt-bindings/clock/numaker_m2l31x_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_NUMAKER_M2L31_CLOCK_H
#define ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_NUMAKER_M2L31_CLOCK_H
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_NUMAKER_M2L31X_CLOCK_H
#define ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_NUMAKER_M2L31X_CLOCK_H

#define NUMAKER_CLK_CLKSEL0_HCLKSEL_HXT 0x00000000
#define NUMAKER_CLK_CLKSEL0_HCLKSEL_LXT 0x00000001
Expand Down Expand Up @@ -193,82 +193,82 @@
#define NUMAKER_CLK_PCLKDIV_APB1DIV_DIV4 0x00000020
#define NUMAKER_CLK_PCLKDIV_APB1DIV_DIV8 0x00000030
#define NUMAKER_CLK_PCLKDIV_APB1DIV_DIV16 0x00000040
#define NUMAKER_PDMA0_MODULE 0x00000001
#define NUMAKER_ISP_MODULE 0x00000002
#define NUMAKER_EBI_MODULE 0x00000003
#define NUMAKER_ST_MODULE 0x018C0004
#define NUMAKER_CRC_MODULE 0x00000007
#define NUMAKER_CRPT_MODULE 0x0000000C
#define NUMAKER_KS_MODULE 0x0000000D
#define NUMAKER_USBH_MODULE 0x00A01090
#define NUMAKER_GPA_MODULE 0x00000018
#define NUMAKER_GPB_MODULE 0x00000019
#define NUMAKER_GPC_MODULE 0x0000001A
#define NUMAKER_GPD_MODULE 0x0000001B
#define NUMAKER_GPE_MODULE 0x0000001C
#define NUMAKER_GPF_MODULE 0x0000001D
#define NUMAKER_GPG_MODULE 0x0000001E
#define NUMAKER_GPH_MODULE 0x0000001F
#define NUMAKER_RTC_MODULE 0x20000001
#define NUMAKER_TMR0_MODULE 0x25A00002
#define NUMAKER_TMR1_MODULE 0x25B00003
#define NUMAKER_TMR2_MODULE 0x25C00004
#define NUMAKER_TMR3_MODULE 0x25D00005
#define NUMAKER_CLKO_MODULE 0x26100006
#define NUMAKER_ACMP01_MODULE 0x20000007
#define NUMAKER_I2C0_MODULE 0x20000008
#define NUMAKER_I2C1_MODULE 0x20000009
#define NUMAKER_I2C2_MODULE 0x2000000A
#define NUMAKER_I2C3_MODULE 0x2000000B
#define NUMAKER_QSPI0_MODULE 0x2908000C
#define NUMAKER_SPI0_MODULE 0x2990000D
#define NUMAKER_SPI1_MODULE 0x29B0000E
#define NUMAKER_SPI2_MODULE 0x2DA0000F
#define NUMAKER_UART0_MODULE 0x31801110
#define NUMAKER_UART1_MODULE 0x31901191
#define NUMAKER_UART2_MODULE 0x31A11012
#define NUMAKER_UART3_MODULE 0x31B11093
#define NUMAKER_UART4_MODULE 0x31C11114
#define NUMAKER_UART5_MODULE 0x31D11195
#define NUMAKER_UART6_MODULE 0x31E11216
#define NUMAKER_UART7_MODULE 0x31F11297
#define NUMAKER_OTG_MODULE 0x2000001A
#define NUMAKER_USBD_MODULE 0x20A0109B
#define NUMAKER_EADC0_MODULE 0x2128221C
#define NUMAKER_TRNG_MODULE 0x2000001F
#define NUMAKER_SPI3_MODULE 0x4DB00006
#define NUMAKER_USCI0_MODULE 0x40000008
#define NUMAKER_USCI1_MODULE 0x40000009
#define NUMAKER_WWDT_MODULE 0x4578000B
#define NUMAKER_DAC_MODULE 0x4000000C
#define NUMAKER_EPWM0_MODULE 0x48800010
#define NUMAKER_EPWM1_MODULE 0x48840011
#define NUMAKER_EQEI0_MODULE 0x40000016
#define NUMAKER_EQEI1_MODULE 0x40000017
#define NUMAKER_TK_MODULE 0x489C0019
#define NUMAKER_ECAP0_MODULE 0x4000001A
#define NUMAKER_ECAP1_MODULE 0x4000001B
#define NUMAKER_ACMP2_MODULE 0x60000007
#define NUMAKER_PWM0_MODULE 0x6C980008
#define NUMAKER_PWM1_MODULE 0x6C9C0009
#define NUMAKER_UTCPD0_MODULE 0x6000000F
#define NUMAKER_CANRAM0_MODULE 0x80000010
#define NUMAKER_CANRAM1_MODULE 0x80000011
#define NUMAKER_CANFD0_MODULE 0x81621014
#define NUMAKER_CANFD1_MODULE 0x816A1095
#define NUMAKER_HCLK1_MODULE 0x81B3101C
#define NUMAKER_LPPDMA0_MODULE 0xA0000000
#define NUMAKER_LPGPIO_MODULE 0xA0000001
#define NUMAKER_LPSRAM_MODULE 0xA0000002
#define NUMAKER_WDT_MODULE 0xB5600010
#define NUMAKER_LPSPI0_MODULE 0xB5080011
#define NUMAKER_LPI2C0_MODULE 0xA0000012
#define NUMAKER_LPUART0_MODULE 0xB5031113
#define NUMAKER_LPTMR0_MODULE 0xB5A00014
#define NUMAKER_LPTMR1_MODULE 0xB5B00015
#define NUMAKER_TTMR0_MODULE 0xB5100016
#define NUMAKER_TTMR1_MODULE 0xB5180017
#define NUMAKER_LPADC0_MODULE 0xB5431218
#define NUMAKER_OPA_MODULE 0xA000001B
#define NUMAKER_PDMA0_MODULE 0x00000000 0x00000001
#define NUMAKER_ISP_MODULE 0x00000000 0x00000002
#define NUMAKER_EBI_MODULE 0x00000000 0x00000003
#define NUMAKER_ST_MODULE 0x00000000 0x018C0004
#define NUMAKER_CRC_MODULE 0x00000000 0x00000007
#define NUMAKER_CRPT_MODULE 0x00000000 0x0000000C
#define NUMAKER_KS_MODULE 0x00000000 0x0000000D
#define NUMAKER_USBH_MODULE 0x00000000 0x00A01090
#define NUMAKER_GPA_MODULE 0x00000000 0x00000018
#define NUMAKER_GPB_MODULE 0x00000000 0x00000019
#define NUMAKER_GPC_MODULE 0x00000000 0x0000001A
#define NUMAKER_GPD_MODULE 0x00000000 0x0000001B
#define NUMAKER_GPE_MODULE 0x00000000 0x0000001C
#define NUMAKER_GPF_MODULE 0x00000000 0x0000001D
#define NUMAKER_GPG_MODULE 0x00000000 0x0000001E
#define NUMAKER_GPH_MODULE 0x00000000 0x0000001F
#define NUMAKER_RTC_MODULE 0x00000000 0x20000001
#define NUMAKER_TMR0_MODULE 0x00000000 0x25A00002
#define NUMAKER_TMR1_MODULE 0x00000000 0x25B00003
#define NUMAKER_TMR2_MODULE 0x00000000 0x25C00004
#define NUMAKER_TMR3_MODULE 0x00000000 0x25D00005
#define NUMAKER_CLKO_MODULE 0x00000000 0x26100006
#define NUMAKER_ACMP01_MODULE 0x00000000 0x20000007
#define NUMAKER_I2C0_MODULE 0x00000000 0x20000008
#define NUMAKER_I2C1_MODULE 0x00000000 0x20000009
#define NUMAKER_I2C2_MODULE 0x00000000 0x2000000A
#define NUMAKER_I2C3_MODULE 0x00000000 0x2000000B
#define NUMAKER_QSPI0_MODULE 0x00000000 0x2908000C
#define NUMAKER_SPI0_MODULE 0x00000000 0x2990000D
#define NUMAKER_SPI1_MODULE 0x00000000 0x29B0000E
#define NUMAKER_SPI2_MODULE 0x00000000 0x2DA0000F
#define NUMAKER_UART0_MODULE 0x00000000 0x31801110
#define NUMAKER_UART1_MODULE 0x00000000 0x31901191
#define NUMAKER_UART2_MODULE 0x00000000 0x31A11012
#define NUMAKER_UART3_MODULE 0x00000000 0x31B11093
#define NUMAKER_UART4_MODULE 0x00000000 0x31C11114
#define NUMAKER_UART5_MODULE 0x00000000 0x31D11195
#define NUMAKER_UART6_MODULE 0x00000000 0x31E11216
#define NUMAKER_UART7_MODULE 0x00000000 0x31F11297
#define NUMAKER_OTG_MODULE 0x00000000 0x2000001A
#define NUMAKER_USBD_MODULE 0x00000000 0x20A0109B
#define NUMAKER_EADC0_MODULE 0x00000000 0x2128221C
#define NUMAKER_TRNG_MODULE 0x00000000 0x2000001F
#define NUMAKER_SPI3_MODULE 0x00000000 0x4DB00006
#define NUMAKER_USCI0_MODULE 0x00000000 0x40000008
#define NUMAKER_USCI1_MODULE 0x00000000 0x40000009
#define NUMAKER_WWDT_MODULE 0x00000000 0x4578000B
#define NUMAKER_DAC_MODULE 0x00000000 0x4000000C
#define NUMAKER_EPWM0_MODULE 0x00000000 0x48800010
#define NUMAKER_EPWM1_MODULE 0x00000000 0x48840011
#define NUMAKER_EQEI0_MODULE 0x00000000 0x40000016
#define NUMAKER_EQEI1_MODULE 0x00000000 0x40000017
#define NUMAKER_TK_MODULE 0x00000000 0x489C0019
#define NUMAKER_ECAP0_MODULE 0x00000000 0x4000001A
#define NUMAKER_ECAP1_MODULE 0x00000000 0x4000001B
#define NUMAKER_ACMP2_MODULE 0x00000000 0x60000007
#define NUMAKER_PWM0_MODULE 0x00000000 0x6C980008
#define NUMAKER_PWM1_MODULE 0x00000000 0x6C9C0009
#define NUMAKER_UTCPD0_MODULE 0x00000000 0x6000000F
#define NUMAKER_CANRAM0_MODULE 0x00000000 0x80000010
#define NUMAKER_CANRAM1_MODULE 0x00000000 0x80000011
#define NUMAKER_CANFD0_MODULE 0x00000000 0x81621014
#define NUMAKER_CANFD1_MODULE 0x00000000 0x816A1095
#define NUMAKER_HCLK1_MODULE 0x00000000 0x81B3101C
#define NUMAKER_LPPDMA0_MODULE 0x00000000 0xA0000000
#define NUMAKER_LPGPIO_MODULE 0x00000000 0xA0000001
#define NUMAKER_LPSRAM_MODULE 0x00000000 0xA0000002
#define NUMAKER_WDT_MODULE 0x00000000 0xB5600010
#define NUMAKER_LPSPI0_MODULE 0x00000000 0xB5080011
#define NUMAKER_LPI2C0_MODULE 0x00000000 0xA0000012
#define NUMAKER_LPUART0_MODULE 0x00000000 0xB5031113
#define NUMAKER_LPTMR0_MODULE 0x00000000 0xB5A00014
#define NUMAKER_LPTMR1_MODULE 0x00000000 0xB5B00015
#define NUMAKER_TTMR0_MODULE 0x00000000 0xB5100016
#define NUMAKER_TTMR1_MODULE 0x00000000 0xB5180017
#define NUMAKER_LPADC0_MODULE 0x00000000 0xB5431218
#define NUMAKER_OPA_MODULE 0x00000000 0xA000001B

#endif

0 comments on commit 47bfb61

Please sign in to comment.