Skip to content

Commit 77c1aed

Browse files
le-quang168cfriedt
authored andcommitted
drivers: clock control: Add Clock Control support for RZ/N2L, T2M
Add Clock Control driver support for Renesas RZ/N2L, T2M Signed-off-by: Quang Le <[email protected]> Signed-off-by: Tien Nguyen <[email protected]>
1 parent 5197129 commit 77c1aed

File tree

11 files changed

+431
-0
lines changed

11 files changed

+431
-0
lines changed

drivers/clock_control/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RENESAS_RA_CGC clock_cont
4545
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RENESAS_RX_ROOT clock_control_renesas_rx_root_cgc.c)
4646
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RENESAS_RX_PLL clock_control_renesas_rx_pll_cgc.c)
4747
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RENESAS_RX_PCLK clock_control_renesas_rx_pclk_cgc.c)
48+
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RENESAS_RZ_CGC clock_control_renesas_rz_cgc.c)
4849
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RENESAS_RZ_CPG clock_control_renesas_rz_cpg.c)
4950
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_AMBIQ clock_control_ambiq.c)
5051
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_PWM clock_control_pwm.c)

drivers/clock_control/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ source "drivers/clock_control/Kconfig.renesas_rx_cgc"
9696

9797
source "drivers/clock_control/Kconfig.renesas_rz_cpg"
9898

99+
source "drivers/clock_control/Kconfig.renesas_rz_cgc"
100+
99101
source "drivers/clock_control/Kconfig.max32"
100102

101103
source "drivers/clock_control/Kconfig.ambiq"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2025 Renesas Electronics Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config CLOCK_CONTROL_RENESAS_RZ_CGC
5+
bool "Renesas RZ Clock Control Driver"
6+
default y
7+
depends on DT_HAS_RENESAS_RZ_CGC_ENABLED
8+
select USE_RZ_FSP_CGC
9+
help
10+
Enable support for Renesas RZ CGC Clock Generator Circuit (CGC) driver.
11+
The CGC driver supports only module's clocks.
12+
The PLLs and core clocks are not configured by the CGC driver.
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/drivers/clock_control.h>
8+
#include <zephyr/dt-bindings/clock/renesas_rztn_clock.h>
9+
#include <zephyr/kernel.h>
10+
#include "bsp_api.h"
11+
12+
#define DT_DRV_COMPAT renesas_rz_cgc
13+
14+
static int clock_control_renesas_rz_on(const struct device *dev, clock_control_subsys_t sys)
15+
{
16+
if (!dev || !sys) {
17+
return -EINVAL;
18+
}
19+
20+
uint32_t *clock_id = (uint32_t *)sys;
21+
22+
uint32_t ip = (*clock_id & RZ_IP_MASK) >> RZ_IP_SHIFT;
23+
uint32_t ch = (*clock_id & RZ_IP_CH_MASK) >> RZ_IP_CH_SHIFT;
24+
25+
R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_LPC_RESET);
26+
switch (ip) {
27+
case RZ_IP_BSC:
28+
R_BSP_MODULE_START(FSP_IP_BSC, ch);
29+
break;
30+
case RZ_IP_XSPI:
31+
R_BSP_MODULE_START(FSP_IP_XSPI, ch);
32+
break;
33+
case RZ_IP_SCI:
34+
R_BSP_MODULE_START(FSP_IP_SCI, ch);
35+
break;
36+
case RZ_IP_IIC:
37+
R_BSP_MODULE_START(FSP_IP_IIC, ch);
38+
break;
39+
case RZ_IP_SPI:
40+
R_BSP_MODULE_START(FSP_IP_SPI, ch);
41+
break;
42+
case RZ_IP_GPT:
43+
R_BSP_MODULE_START(FSP_IP_GPT, ch);
44+
break;
45+
case RZ_IP_ADC12:
46+
R_BSP_MODULE_START(FSP_IP_ADC12, ch);
47+
break;
48+
case RZ_IP_CMT:
49+
R_BSP_MODULE_START(FSP_IP_CMT, ch);
50+
break;
51+
case RZ_IP_CMTW:
52+
R_BSP_MODULE_START(FSP_IP_CMTW, ch);
53+
break;
54+
case RZ_IP_CANFD:
55+
R_BSP_MODULE_START(FSP_IP_CANFD, ch);
56+
break;
57+
case RZ_IP_GMAC:
58+
R_BSP_MODULE_START(FSP_IP_GMAC, ch);
59+
break;
60+
case RZ_IP_ETHSW:
61+
R_BSP_MODULE_START(FSP_IP_ETHSW, ch);
62+
break;
63+
case RZ_IP_USBHS:
64+
R_BSP_MODULE_START(FSP_IP_USBHS, ch);
65+
break;
66+
case RZ_IP_RTC:
67+
R_BSP_MODULE_START(FSP_IP_RTC, ch);
68+
break;
69+
default:
70+
R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_LPC_RESET);
71+
return -EINVAL; /* Invalid FSP IP Module */
72+
}
73+
R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_LPC_RESET);
74+
75+
return 0;
76+
}
77+
78+
static int clock_control_renesas_rz_off(const struct device *dev, clock_control_subsys_t sys)
79+
{
80+
if (!dev || !sys) {
81+
return -EINVAL;
82+
}
83+
84+
uint32_t *clock_id = (uint32_t *)sys;
85+
86+
uint32_t ip = (*clock_id & RZ_IP_MASK) >> RZ_IP_SHIFT;
87+
uint32_t ch = (*clock_id & RZ_IP_CH_MASK) >> RZ_IP_CH_SHIFT;
88+
89+
R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_LPC_RESET);
90+
switch (ip) {
91+
case RZ_IP_BSC:
92+
R_BSP_MODULE_STOP(FSP_IP_BSC, ch);
93+
break;
94+
case RZ_IP_XSPI:
95+
R_BSP_MODULE_STOP(FSP_IP_XSPI, ch);
96+
break;
97+
case RZ_IP_SCI:
98+
R_BSP_MODULE_STOP(FSP_IP_SCI, ch);
99+
break;
100+
case RZ_IP_IIC:
101+
R_BSP_MODULE_STOP(FSP_IP_IIC, ch);
102+
break;
103+
case RZ_IP_SPI:
104+
R_BSP_MODULE_STOP(FSP_IP_SPI, ch);
105+
break;
106+
case RZ_IP_GPT:
107+
R_BSP_MODULE_STOP(FSP_IP_GPT, ch);
108+
break;
109+
case RZ_IP_ADC12:
110+
R_BSP_MODULE_STOP(FSP_IP_ADC12, ch);
111+
break;
112+
case RZ_IP_CMT:
113+
R_BSP_MODULE_STOP(FSP_IP_CMT, ch);
114+
break;
115+
case RZ_IP_CMTW:
116+
R_BSP_MODULE_STOP(FSP_IP_CMTW, ch);
117+
break;
118+
case RZ_IP_CANFD:
119+
R_BSP_MODULE_STOP(FSP_IP_CANFD, ch);
120+
break;
121+
case RZ_IP_GMAC:
122+
R_BSP_MODULE_STOP(FSP_IP_GMAC, ch);
123+
break;
124+
case RZ_IP_ETHSW:
125+
R_BSP_MODULE_STOP(FSP_IP_ETHSW, ch);
126+
break;
127+
case RZ_IP_USBHS:
128+
R_BSP_MODULE_STOP(FSP_IP_USBHS, ch);
129+
break;
130+
case RZ_IP_RTC:
131+
R_BSP_MODULE_STOP(FSP_IP_RTC, ch);
132+
break;
133+
default:
134+
R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_LPC_RESET);
135+
return -EINVAL; /* Invalid FSP IP Module */
136+
}
137+
R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_LPC_RESET);
138+
139+
return 0;
140+
}
141+
142+
static int clock_control_renesas_rz_get_rate(const struct device *dev, clock_control_subsys_t sys,
143+
uint32_t *rate)
144+
{
145+
if (!dev || !sys || !rate) {
146+
return -EINVAL;
147+
}
148+
149+
uint32_t *clock_id = (uint32_t *)sys;
150+
fsp_priv_clock_t clk_src = (*clock_id & RZ_CLOCK_MASK) >> RZ_CLOCK_SHIFT;
151+
uint32_t clk_hz = R_FSP_SystemClockHzGet(clk_src);
152+
153+
*rate = clk_hz;
154+
155+
return 0;
156+
}
157+
158+
static DEVICE_API(clock_control, rz_clock_control_driver_api) = {
159+
.on = clock_control_renesas_rz_on,
160+
.off = clock_control_renesas_rz_off,
161+
.get_rate = clock_control_renesas_rz_get_rate,
162+
};
163+
164+
static int clock_control_rz_init(const struct device *dev)
165+
{
166+
ARG_UNUSED(dev);
167+
168+
return 0;
169+
}
170+
171+
DEVICE_DT_INST_DEFINE(0, clock_control_rz_init, NULL, NULL, NULL, PRE_KERNEL_1,
172+
CONFIG_CLOCK_CONTROL_INIT_PRIORITY, &rz_clock_control_driver_api);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2025 Renesas Electronics Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Renesas RZ Clock Generator Circuit PLL Clock
5+
compatible: "renesas,rz-cgc-pll"
6+
7+
include: [base.yaml]
8+
9+
properties:
10+
state:
11+
type: string
12+
default: initial
13+
enum:
14+
- initial
15+
- standby
16+
- normal
17+
description: PLL1 state
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) 2025 Renesas Electronics Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Renesas RZ Clock Control Peripheral Sub-Clock
5+
6+
compatible: "renesas,rz-cgc-subclk"
7+
8+
include: [base.yaml]
9+
10+
properties:
11+
clock-frequency:
12+
type: int
13+
default: 96000000
14+
enum:
15+
- 75000000
16+
- 96000000
17+
description: |
18+
Select clock frequency (Hz) when asynchronous serial clock is selected in SPI and SCI
19+
20+
xspi-clk-frequency:
21+
type: int
22+
default: 12500000
23+
enum:
24+
- 133333333
25+
- 100000000
26+
- 50000000
27+
- 25000000
28+
- 12500000
29+
- 75000000
30+
- 37500000
31+
description: Select clock frequency (Hz) supplied to xSPI
32+
33+
canfd-source:
34+
type: int
35+
default: 1
36+
enum:
37+
- 0
38+
- 1
39+
- 2
40+
description: |
41+
Select clock source supplied to CANFD
42+
- 0: PCLKCAN 80MHz
43+
- 1: PCLKCAN 40MHz
44+
- 2: PCLKM 100MHz
45+
46+
eth-phy-source:
47+
type: string
48+
default: main
49+
enum:
50+
- "pll1"
51+
- "main"
52+
description: |
53+
25 MHz reference clock to the external Ethernet PHY.
54+
Clock source is selectable from main clock or frequency-dividing clock for PLL1.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (c) 2025 Renesas Electronics Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Renesas RZ Clock Control System Clock
5+
6+
compatible: "renesas,rz-cgc-sys-clock"
7+
8+
include: [base.yaml]
9+
10+
properties:
11+
clock-frequency:
12+
type: int
13+
default: 200000000
14+
enum:
15+
- 200000000
16+
- 150000000
17+
description: Select frequency of iclk.
18+
19+
div:
20+
type: int
21+
default: 4
22+
enum:
23+
- 2
24+
- 3
25+
- 4
26+
- 5
27+
- 6
28+
- 7
29+
- 8
30+
description: |
31+
Prescale divider to calculate the subclock frequency from the
32+
system clock frequency.
33+
34+
mul:
35+
type: int
36+
default: 1
37+
description: |
38+
Multiplier to calculate the subclock frequency from the
39+
system clock frequency.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2025 Renesas Electronics Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
Renesas RZ Clock Generator Circuit
6+
7+
Usage example:
8+
9+
#include <zephyr/dt-bindings/clock/renesas_rztn_clock.h>
10+
11+
sci0: sci@xxx {
12+
...
13+
channel = <0>;
14+
/* Cell encodes HWIP, channel, clock source */
15+
clocks = <&cgc RZ_CLOCK(RZ_IP_SCI, 0, RZ_CLOCK_PCLKSCI0)>;
16+
...
17+
}
18+
19+
compatible: "renesas,rz-cgc"
20+
21+
include: [base.yaml, clock-controller.yaml]
22+
23+
properties:
24+
"#clock-cells":
25+
const: 1
26+
27+
clock-cells:
28+
- clk-id
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2025 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_RENESAS_RZ_CGC_H_
8+
#define ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_RENESAS_RZ_CGC_H_
9+
10+
#include <zephyr/drivers/clock_control.h>
11+
12+
#define RZ_CGC_SUBCLK_DIV(subclk) \
13+
UTIL_CAT(RZ_CGC_DIV_, DT_NODE_FULL_NAME_UPPER_TOKEN(subclk)) \
14+
(DT_PROP(subclk, div))
15+
16+
#define RZ_CGC_SUBCLK_MUL(subclk) \
17+
UTIL_CAT(RZ_CGC_MUL_, DT_NODE_FULL_NAME_UPPER_TOKEN(subclk)) \
18+
(DT_PROP(subclk, mul))
19+
20+
#define RZ_CGC_DIV_CKIO(n) UTIL_CAT(BSP_CLOCKS_CKIO_ICLK_DIV, n)
21+
#define RZ_CGC_MUL_CPU0CLK(n) UTIL_CAT(BSP_CLOCKS_FSELCPU0_ICLK_MUL, n)
22+
#define RZ_CGC_MUL_CPU1CLK(n) UTIL_CAT(BSP_CLOCKS_FSELCPU1_ICLK_MUL, n)
23+
24+
#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_RENESAS_RZ_CGC_H_ */

0 commit comments

Comments
 (0)