Skip to content

Commit b9a4e30

Browse files
tiennguyenzgkartben
authored andcommitted
drivers: clock control: Initial support for RZ/G3S
Add Clock Control driver support for Renesas RZ/G3S Signed-off-by: Tien Nguyen <tien.nguyen.zg@renesas.com> Signed-off-by: Nhut Nguyen <nhut.nguyen.kc@renesas.com>
1 parent c57e888 commit b9a4e30

File tree

7 files changed

+262
-0
lines changed

7 files changed

+262
-0
lines changed

drivers/clock_control/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_SMARTBOND clock_cont
3535
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_NUMAKER_SCC clock_control_numaker_scc.c)
3636
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_NXP_S32 clock_control_nxp_s32.c)
3737
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RENESAS_RA_CGC clock_control_renesas_ra_cgc.c)
38+
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RENESAS_RZ_CPG clock_control_renesas_rz_cpg.c)
3839
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_AMBIQ clock_control_ambiq.c)
3940
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_PWM clock_control_pwm.c)
4041
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RPI_PICO clock_control_rpi_pico.c)

drivers/clock_control/Kconfig

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

8989
source "drivers/clock_control/Kconfig.renesas_ra_cgc"
9090

91+
source "drivers/clock_control/Kconfig.renesas_rz_cpg"
92+
9193
source "drivers/clock_control/Kconfig.max32"
9294

9395
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) 2024 Renesas Electronics Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config CLOCK_CONTROL_RENESAS_RZ_CPG
5+
bool "Renesas RZ/G Clock Control Driver"
6+
default y
7+
depends on DT_HAS_RENESAS_RZ_CPG_ENABLED
8+
select USE_RZ_FSP_CPG
9+
help
10+
Enable support for Renesas RZ CPG Clock Pulse Generator (CPG) driver.
11+
The CPG driver supports only module's clocks.
12+
The PLLs and core clocks are not configured by the CPG driver.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright (c) 2024 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_rzg_clock.h>
9+
#include <zephyr/kernel.h>
10+
11+
#define DT_DRV_COMPAT renesas_rz_cpg
12+
13+
static int clock_control_renesas_rz_on(const struct device *dev, clock_control_subsys_t sys)
14+
{
15+
if (!dev || !sys) {
16+
return -EINVAL;
17+
}
18+
19+
uint32_t *clock_id = (uint32_t *)sys;
20+
21+
uint32_t ip = (*clock_id & RZ_IP_MASK) >> RZ_IP_SHIFT;
22+
uint32_t ch = (*clock_id & RZ_IP_CH_MASK) >> RZ_IP_CH_SHIFT;
23+
24+
switch (ip) {
25+
case RZ_IP_GTM:
26+
R_BSP_MODULE_START(FSP_IP_GTM, ch);
27+
break;
28+
case RZ_IP_GPT:
29+
R_BSP_MODULE_START(FSP_IP_GPT, ch);
30+
break;
31+
case RZ_IP_SCIF:
32+
R_BSP_MODULE_START(FSP_IP_SCIF, ch);
33+
break;
34+
case RZ_IP_RIIC:
35+
R_BSP_MODULE_START(FSP_IP_RIIC, ch);
36+
break;
37+
case RZ_IP_RSPI:
38+
R_BSP_MODULE_START(FSP_IP_RSPI, ch);
39+
break;
40+
case RZ_IP_MHU:
41+
R_BSP_MODULE_START(FSP_IP_MHU, ch);
42+
break;
43+
case RZ_IP_DMAC:
44+
R_BSP_MODULE_START(FSP_IP_DMAC, ch);
45+
break;
46+
case RZ_IP_CANFD:
47+
R_BSP_MODULE_START(FSP_IP_CANFD, ch);
48+
break;
49+
case RZ_IP_ADC:
50+
R_BSP_MODULE_START(FSP_IP_ADC, ch);
51+
break;
52+
default:
53+
return -EINVAL; /* Invalid FSP IP Module */
54+
}
55+
56+
return 0;
57+
}
58+
59+
static int clock_control_renesas_rz_off(const struct device *dev, clock_control_subsys_t sys)
60+
{
61+
if (!dev || !sys) {
62+
return -EINVAL;
63+
}
64+
65+
uint32_t *clock_id = (uint32_t *)sys;
66+
67+
uint32_t ip = (*clock_id & RZ_IP_MASK) >> RZ_IP_SHIFT;
68+
uint32_t ch = (*clock_id & RZ_IP_CH_MASK) >> RZ_IP_CH_SHIFT;
69+
70+
switch (ip) {
71+
case RZ_IP_GTM:
72+
R_BSP_MODULE_STOP(FSP_IP_GTM, ch);
73+
break;
74+
case RZ_IP_GPT:
75+
R_BSP_MODULE_STOP(FSP_IP_GPT, ch);
76+
break;
77+
case RZ_IP_SCIF:
78+
R_BSP_MODULE_STOP(FSP_IP_SCIF, ch);
79+
break;
80+
case RZ_IP_RIIC:
81+
R_BSP_MODULE_STOP(FSP_IP_RIIC, ch);
82+
break;
83+
case RZ_IP_RSPI:
84+
R_BSP_MODULE_STOP(FSP_IP_RSPI, ch);
85+
break;
86+
case RZ_IP_MHU:
87+
R_BSP_MODULE_STOP(FSP_IP_MHU, ch);
88+
break;
89+
case RZ_IP_DMAC:
90+
R_BSP_MODULE_STOP(FSP_IP_DMAC, ch);
91+
break;
92+
case RZ_IP_CANFD:
93+
R_BSP_MODULE_STOP(FSP_IP_CANFD, ch);
94+
break;
95+
case RZ_IP_ADC:
96+
R_BSP_MODULE_STOP(FSP_IP_ADC, ch);
97+
break;
98+
default:
99+
return -EINVAL; /* Invalid */
100+
}
101+
return 0;
102+
}
103+
104+
static int clock_control_renesas_rz_get_rate(const struct device *dev, clock_control_subsys_t sys,
105+
uint32_t *rate)
106+
{
107+
if (!dev || !sys || !rate) {
108+
return -EINVAL;
109+
}
110+
111+
uint32_t *clock_id = (uint32_t *)sys;
112+
113+
fsp_priv_clock_t clk_src = (*clock_id & RZ_CLOCK_MASK) >> RZ_CLOCK_SHIFT;
114+
uint32_t clk_div = (*clock_id & RZ_CLOCK_DIV_MASK) >> RZ_CLOCK_DIV_SHIFT;
115+
116+
uint32_t clk_hz = R_FSP_SystemClockHzGet(clk_src);
117+
*rate = clk_hz / clk_div;
118+
return 0;
119+
}
120+
121+
static DEVICE_API(clock_control, rz_clock_control_driver_api) = {
122+
.on = clock_control_renesas_rz_on,
123+
.off = clock_control_renesas_rz_off,
124+
.get_rate = clock_control_renesas_rz_get_rate,
125+
};
126+
127+
static int clock_control_rz_init(const struct device *dev)
128+
{
129+
ARG_UNUSED(dev);
130+
return 0;
131+
}
132+
133+
DEVICE_DT_INST_DEFINE(0, clock_control_rz_init, NULL, NULL, NULL, PRE_KERNEL_1,
134+
CONFIG_CLOCK_CONTROL_INIT_PRIORITY, &rz_clock_control_driver_api);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2024 Renesas Electronics Corporation24
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: RZ Clock Pulse Generator
5+
compatible: "renesas,rz-cpg"
6+
7+
include: [base.yaml, clock-controller.yaml]
8+
9+
properties:
10+
11+
"#clock-cells":
12+
const: 1
13+
14+
clock-cells:
15+
- clk-id
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2024 Renesas Electronics Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_RENESAS_RZG_CLOCK_H_
8+
#define ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_RENESAS_RZG_CLOCK_H_
9+
10+
/** RZ clock configuration values */
11+
#define RZ_IP_MASK 0xFF000000UL
12+
#define RZ_IP_SHIFT 24UL
13+
#define RZ_IP_CH_MASK 0xFF0000UL
14+
#define RZ_IP_CH_SHIFT 16UL
15+
#define RZ_CLOCK_MASK 0xFF00UL
16+
#define RZ_CLOCK_SHIFT 8UL
17+
#define RZ_CLOCK_DIV_MASK 0xFFUL
18+
#define RZ_CLOCK_DIV_SHIFT 0UL
19+
20+
#define RZ_IP_GTM 0UL /* General Timer */
21+
#define RZ_IP_GPT 1UL /* General PWM Timer */
22+
#define RZ_IP_SCIF 2UL /* Serial Communications Interface with FIFO */
23+
#define RZ_IP_RIIC 3UL /* I2C Bus Interface */
24+
#define RZ_IP_RSPI 4UL /* Renesas Serial Peripheral Interface */
25+
#define RZ_IP_MHU 5UL /* Message Handling Unit */
26+
#define RZ_IP_DMAC 6UL /* Direct Memory Access Controller */
27+
#define RZ_IP_CANFD 7UL /* CANFD Interface (RS-CANFD) */
28+
#define RZ_IP_ADC 8UL /* A/D Converter */
29+
30+
#define RZ_CLOCK_ICLK 0UL /* Cortex-A55 Clock */
31+
#define RZ_CLOCK_I2CLK 1UL /* Cortex-M33 Clock */
32+
#define RZ_CLOCK_I3CLK 2UL /* Cortex-M33 FPU Clock */
33+
#define RZ_CLOCK_S0CLK 3UL /* DDR-PHY Clock */
34+
#define RZ_CLOCK_OC0CLK 4UL /* OCTA0 Clock */
35+
#define RZ_CLOCK_OC1CLK 5UL /* OCTA1 Clock */
36+
#define RZ_CLOCK_SPI0CLK 6UL /* SPI0 Clock */
37+
#define RZ_CLOCK_SPI1CLK 7UL /* SPI1 Clock */
38+
#define RZ_CLOCK_SD0CLK 8UL /* SDH0 Clock */
39+
#define RZ_CLOCK_SD1CLK 9UL /* SDH1 Clock */
40+
#define RZ_CLOCK_SD2CLK 10UL /* SDH2 Clock */
41+
#define RZ_CLOCK_M0CLK 11UL /* VCP LCDC Clock */
42+
#define RZ_CLOCK_HPCLK 12UL /* Ethernet Clock */
43+
#define RZ_CLOCK_TSUCLK 13UL /* TSU Clock */
44+
#define RZ_CLOCK_ZTCLK 14UL /* JAUTH Clock */
45+
#define RZ_CLOCK_P0CLK 15UL /* APB-BUS Clock */
46+
#define RZ_CLOCK_P1CLK 16UL /* AXI-BUS Clock */
47+
#define RZ_CLOCK_P2CLK 17UL /* P2CLK */
48+
#define RZ_CLOCK_P3CLK 18UL /* P3CLK */
49+
#define RZ_CLOCK_P4CLK 19UL /* P4CLK */
50+
#define RZ_CLOCK_P5CLK 20UL /* P5CLK */
51+
#define RZ_CLOCK_ATCLK 21UL /* ATCLK */
52+
#define RZ_CLOCK_OSCCLK 22UL /* OSC Clock */
53+
#define RZ_CLOCK_OSCCLK2 23UL /* OSC2 Clock */
54+
55+
#define RZ_CLOCK(IP, ch, clk, div) \
56+
((RZ_IP_##IP << RZ_IP_SHIFT) | ((ch) << RZ_IP_CH_SHIFT) | ((clk) << RZ_CLOCK_SHIFT) | \
57+
((div) << RZ_CLOCK_DIV_SHIFT))
58+
59+
/**
60+
* Pack clock configurations in a 32-bit value
61+
* as expected for the Device Tree `clocks` property on Renesas RZ/G.
62+
*
63+
* @param ch Peripheral channel/unit
64+
*/
65+
66+
/* SCIF */
67+
#define RZ_CLOCK_SCIF(ch) RZ_CLOCK(SCIF, ch, RZ_CLOCK_P0CLK, 1)
68+
69+
/* GPT */
70+
#define RZ_CLOCK_GPT(ch) RZ_CLOCK(GPT, ch, RZ_CLOCK_P0CLK, 1)
71+
72+
/* MHU */
73+
#define RZ_CLOCK_MHU(ch) RZ_CLOCK(MHU, ch, RZ_CLOCK_P1CLK, 2)
74+
75+
/* ADC */
76+
#define RZ_CLOCK_ADC(ch) RZ_CLOCK(ADC, ch, RZ_CLOCK_TSUCLK, 1)
77+
78+
/* RIIC */
79+
#define RZ_CLOCK_RIIC(ch) RZ_CLOCK(RIIC, ch, RZ_CLOCK_P0CLK, 1)
80+
81+
/* GTM */
82+
#define RZ_CLOCK_GTM(ch) RZ_CLOCK(GTM, ch, RZ_CLOCK_P0CLK, 1)
83+
84+
/* CAN */
85+
#define RZ_CLOCK_CANFD(ch) RZ_CLOCK(CANFD, ch, RZ_CLOCK_P4CLK, 2)
86+
87+
/* RSPI */
88+
#define RZ_CLOCK_RSPI(ch) RZ_CLOCK(RSPI, ch, RZ_CLOCK_P0CLK, 1)
89+
90+
/* DMAC */
91+
#define RZ_CLOCK_DMAC(ch) RZ_CLOCK(DMAC, ch, RZ_CLOCK_P3CLK, 1)
92+
93+
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_CLOCK_RENESAS_RZG_CLOCK_H_ */

modules/Kconfig.renesas_fsp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,9 @@ config USE_RZ_FSP_EXT_IRQ
183183
help
184184
Enable RZ FSP External IRQ driver
185185

186+
config USE_RZ_FSP_CPG
187+
bool
188+
help
189+
Enable RZ FSP CLOCK CONTROL driver
190+
186191
endif

0 commit comments

Comments
 (0)