xref: /linux/drivers/clk/renesas/r9a09g047-cpg.c (revision 641b0c64b85a9b21110268f511f20d6887406117)
1bb6a9aafSBiju Das // SPDX-License-Identifier: GPL-2.0
2bb6a9aafSBiju Das /*
3bb6a9aafSBiju Das  * Renesas RZ/G3E CPG driver
4bb6a9aafSBiju Das  *
5bb6a9aafSBiju Das  * Copyright (C) 2024 Renesas Electronics Corp.
6bb6a9aafSBiju Das  */
7bb6a9aafSBiju Das 
8bb6a9aafSBiju Das #include <linux/clk-provider.h>
9bb6a9aafSBiju Das #include <linux/device.h>
10bb6a9aafSBiju Das #include <linux/init.h>
11bb6a9aafSBiju Das #include <linux/kernel.h>
12bb6a9aafSBiju Das 
13bb6a9aafSBiju Das #include <dt-bindings/clock/renesas,r9a09g047-cpg.h>
14bb6a9aafSBiju Das 
15bb6a9aafSBiju Das #include "rzv2h-cpg.h"
16bb6a9aafSBiju Das 
17bb6a9aafSBiju Das enum clk_ids {
18bb6a9aafSBiju Das 	/* Core Clock Outputs exported to DT */
19bb6a9aafSBiju Das 	LAST_DT_CORE_CLK = R9A09G047_IOTOP_0_SHCLK,
20bb6a9aafSBiju Das 
21bb6a9aafSBiju Das 	/* External Input Clocks */
22bb6a9aafSBiju Das 	CLK_AUDIO_EXTAL,
23bb6a9aafSBiju Das 	CLK_RTXIN,
24bb6a9aafSBiju Das 	CLK_QEXTAL,
25bb6a9aafSBiju Das 
26bb6a9aafSBiju Das 	/* PLL Clocks */
27bb6a9aafSBiju Das 	CLK_PLLCM33,
28*29ebc619SBiju Das 	CLK_PLLCLN,
29bb6a9aafSBiju Das 	CLK_PLLDTY,
30bb6a9aafSBiju Das 	CLK_PLLCA55,
31bb6a9aafSBiju Das 
32bb6a9aafSBiju Das 	/* Internal Core Clocks */
33bb6a9aafSBiju Das 	CLK_PLLCM33_DIV16,
34*29ebc619SBiju Das 	CLK_PLLCLN_DIV16,
35bb6a9aafSBiju Das 	CLK_PLLDTY_ACPU,
36bb6a9aafSBiju Das 	CLK_PLLDTY_ACPU_DIV4,
37bb6a9aafSBiju Das 
38bb6a9aafSBiju Das 	/* Module Clocks */
39bb6a9aafSBiju Das 	MOD_CLK_BASE,
40bb6a9aafSBiju Das };
41bb6a9aafSBiju Das 
423baf0273SBiju Das static const struct clk_div_table dtable_1_8[] = {
433baf0273SBiju Das 	{0, 1},
443baf0273SBiju Das 	{1, 2},
453baf0273SBiju Das 	{2, 4},
463baf0273SBiju Das 	{3, 8},
473baf0273SBiju Das 	{0, 0},
483baf0273SBiju Das };
493baf0273SBiju Das 
50bb6a9aafSBiju Das static const struct clk_div_table dtable_2_64[] = {
51bb6a9aafSBiju Das 	{0, 2},
52bb6a9aafSBiju Das 	{1, 4},
53bb6a9aafSBiju Das 	{2, 8},
54bb6a9aafSBiju Das 	{3, 16},
55bb6a9aafSBiju Das 	{4, 64},
56bb6a9aafSBiju Das 	{0, 0},
57bb6a9aafSBiju Das };
58bb6a9aafSBiju Das 
59bb6a9aafSBiju Das static const struct cpg_core_clk r9a09g047_core_clks[] __initconst = {
60bb6a9aafSBiju Das 	/* External Clock Inputs */
61bb6a9aafSBiju Das 	DEF_INPUT("audio_extal", CLK_AUDIO_EXTAL),
62bb6a9aafSBiju Das 	DEF_INPUT("rtxin", CLK_RTXIN),
63bb6a9aafSBiju Das 	DEF_INPUT("qextal", CLK_QEXTAL),
64bb6a9aafSBiju Das 
65bb6a9aafSBiju Das 	/* PLL Clocks */
66bb6a9aafSBiju Das 	DEF_FIXED(".pllcm33", CLK_PLLCM33, CLK_QEXTAL, 200, 3),
67*29ebc619SBiju Das 	DEF_FIXED(".pllcln", CLK_PLLCLN, CLK_QEXTAL, 200, 3),
68bb6a9aafSBiju Das 	DEF_FIXED(".plldty", CLK_PLLDTY, CLK_QEXTAL, 200, 3),
69bb6a9aafSBiju Das 	DEF_PLL(".pllca55", CLK_PLLCA55, CLK_QEXTAL, PLL_CONF(0x64)),
70bb6a9aafSBiju Das 
71bb6a9aafSBiju Das 	/* Internal Core Clocks */
72bb6a9aafSBiju Das 	DEF_FIXED(".pllcm33_div16", CLK_PLLCM33_DIV16, CLK_PLLCM33, 1, 16),
73bb6a9aafSBiju Das 
74*29ebc619SBiju Das 	DEF_FIXED(".pllcln_div16", CLK_PLLCLN_DIV16, CLK_PLLCLN, 1, 16),
75*29ebc619SBiju Das 
76bb6a9aafSBiju Das 	DEF_DDIV(".plldty_acpu", CLK_PLLDTY_ACPU, CLK_PLLDTY, CDDIV0_DIVCTL2, dtable_2_64),
77bb6a9aafSBiju Das 	DEF_FIXED(".plldty_acpu_div4", CLK_PLLDTY_ACPU_DIV4, CLK_PLLDTY_ACPU, 1, 4),
78bb6a9aafSBiju Das 
79bb6a9aafSBiju Das 	/* Core Clocks */
80bb6a9aafSBiju Das 	DEF_FIXED("sys_0_pclk", R9A09G047_SYS_0_PCLK, CLK_QEXTAL, 1, 1),
813baf0273SBiju Das 	DEF_DDIV("ca55_0_coreclk0", R9A09G047_CA55_0_CORECLK0, CLK_PLLCA55,
823baf0273SBiju Das 		 CDDIV1_DIVCTL0, dtable_1_8),
833baf0273SBiju Das 	DEF_DDIV("ca55_0_coreclk1", R9A09G047_CA55_0_CORECLK1, CLK_PLLCA55,
843baf0273SBiju Das 		 CDDIV1_DIVCTL1, dtable_1_8),
853baf0273SBiju Das 	DEF_DDIV("ca55_0_coreclk2", R9A09G047_CA55_0_CORECLK2, CLK_PLLCA55,
863baf0273SBiju Das 		 CDDIV1_DIVCTL2, dtable_1_8),
873baf0273SBiju Das 	DEF_DDIV("ca55_0_coreclk3", R9A09G047_CA55_0_CORECLK3, CLK_PLLCA55,
883baf0273SBiju Das 		 CDDIV1_DIVCTL3, dtable_1_8),
89bb6a9aafSBiju Das 	DEF_FIXED("iotop_0_shclk", R9A09G047_IOTOP_0_SHCLK, CLK_PLLCM33_DIV16, 1, 1),
90bb6a9aafSBiju Das };
91bb6a9aafSBiju Das 
92bb6a9aafSBiju Das static const struct rzv2h_mod_clk r9a09g047_mod_clks[] __initconst = {
93bb6a9aafSBiju Das 	DEF_MOD_CRITICAL("gic_0_gicclk",	CLK_PLLDTY_ACPU_DIV4, 1, 3, 0, 19,
94bb6a9aafSBiju Das 						BUS_MSTOP(3, BIT(5))),
95bb6a9aafSBiju Das 	DEF_MOD("scif_0_clk_pck",		CLK_PLLCM33_DIV16, 8, 15, 4, 15,
96bb6a9aafSBiju Das 						BUS_MSTOP(3, BIT(14))),
97*29ebc619SBiju Das 	DEF_MOD("riic_8_ckm",			CLK_PLLCM33_DIV16, 9, 3, 4, 19,
98*29ebc619SBiju Das 						BUS_MSTOP(3, BIT(13))),
99*29ebc619SBiju Das 	DEF_MOD("riic_0_ckm",			CLK_PLLCLN_DIV16, 9, 4, 4, 20,
100*29ebc619SBiju Das 						BUS_MSTOP(1, BIT(1))),
101*29ebc619SBiju Das 	DEF_MOD("riic_1_ckm",			CLK_PLLCLN_DIV16, 9, 5, 4, 21,
102*29ebc619SBiju Das 						BUS_MSTOP(1, BIT(2))),
103*29ebc619SBiju Das 	DEF_MOD("riic_2_ckm",			CLK_PLLCLN_DIV16, 9, 6, 4, 22,
104*29ebc619SBiju Das 						BUS_MSTOP(1, BIT(3))),
105*29ebc619SBiju Das 	DEF_MOD("riic_3_ckm",			CLK_PLLCLN_DIV16, 9, 7, 4, 23,
106*29ebc619SBiju Das 						BUS_MSTOP(1, BIT(4))),
107*29ebc619SBiju Das 	DEF_MOD("riic_4_ckm",			CLK_PLLCLN_DIV16, 9, 8, 4, 24,
108*29ebc619SBiju Das 						BUS_MSTOP(1, BIT(5))),
109*29ebc619SBiju Das 	DEF_MOD("riic_5_ckm",			CLK_PLLCLN_DIV16, 9, 9, 4, 25,
110*29ebc619SBiju Das 						BUS_MSTOP(1, BIT(6))),
111*29ebc619SBiju Das 	DEF_MOD("riic_6_ckm",			CLK_PLLCLN_DIV16, 9, 10, 4, 26,
112*29ebc619SBiju Das 						BUS_MSTOP(1, BIT(7))),
113*29ebc619SBiju Das 	DEF_MOD("riic_7_ckm",			CLK_PLLCLN_DIV16, 9, 11, 4, 27,
114*29ebc619SBiju Das 						BUS_MSTOP(1, BIT(8))),
115bb6a9aafSBiju Das };
116bb6a9aafSBiju Das 
117bb6a9aafSBiju Das static const struct rzv2h_reset r9a09g047_resets[] __initconst = {
118bb6a9aafSBiju Das 	DEF_RST(3, 0, 1, 1),		/* SYS_0_PRESETN */
119bb6a9aafSBiju Das 	DEF_RST(3, 8, 1, 9),		/* GIC_0_GICRESET_N */
120bb6a9aafSBiju Das 	DEF_RST(3, 9, 1, 10),		/* GIC_0_DBG_GICRESET_N */
121bb6a9aafSBiju Das 	DEF_RST(9, 5, 4, 6),		/* SCIF_0_RST_SYSTEM_N */
122*29ebc619SBiju Das 	DEF_RST(9, 8, 4, 9),		/* RIIC_0_MRST */
123*29ebc619SBiju Das 	DEF_RST(9, 9, 4, 10),		/* RIIC_1_MRST */
124*29ebc619SBiju Das 	DEF_RST(9, 10, 4, 11),		/* RIIC_2_MRST */
125*29ebc619SBiju Das 	DEF_RST(9, 11, 4, 12),		/* RIIC_3_MRST */
126*29ebc619SBiju Das 	DEF_RST(9, 12, 4, 13),		/* RIIC_4_MRST */
127*29ebc619SBiju Das 	DEF_RST(9, 13, 4, 14),		/* RIIC_5_MRST */
128*29ebc619SBiju Das 	DEF_RST(9, 14, 4, 15),		/* RIIC_6_MRST */
129*29ebc619SBiju Das 	DEF_RST(9, 15, 4, 16),		/* RIIC_7_MRST */
130*29ebc619SBiju Das 	DEF_RST(10, 0, 4, 17),		/* RIIC_8_MRST */
131bb6a9aafSBiju Das };
132bb6a9aafSBiju Das 
133bb6a9aafSBiju Das const struct rzv2h_cpg_info r9a09g047_cpg_info __initconst = {
134bb6a9aafSBiju Das 	/* Core Clocks */
135bb6a9aafSBiju Das 	.core_clks = r9a09g047_core_clks,
136bb6a9aafSBiju Das 	.num_core_clks = ARRAY_SIZE(r9a09g047_core_clks),
137bb6a9aafSBiju Das 	.last_dt_core_clk = LAST_DT_CORE_CLK,
138bb6a9aafSBiju Das 	.num_total_core_clks = MOD_CLK_BASE,
139bb6a9aafSBiju Das 
140bb6a9aafSBiju Das 	/* Module Clocks */
141bb6a9aafSBiju Das 	.mod_clks = r9a09g047_mod_clks,
142bb6a9aafSBiju Das 	.num_mod_clks = ARRAY_SIZE(r9a09g047_mod_clks),
143bb6a9aafSBiju Das 	.num_hw_mod_clks = 28 * 16,
144bb6a9aafSBiju Das 
145bb6a9aafSBiju Das 	/* Resets */
146bb6a9aafSBiju Das 	.resets = r9a09g047_resets,
147bb6a9aafSBiju Das 	.num_resets = ARRAY_SIZE(r9a09g047_resets),
148bb6a9aafSBiju Das 
149bb6a9aafSBiju Das 	.num_mstop_bits = 208,
150bb6a9aafSBiju Das };
151