blob: 108655f145d07de72c7aef56f982ee345e0044e1 [file] [log] [blame]
Hai Pham99d40392023-02-28 22:34:39 +01001// SPDX-License-Identifier: GPL-2.0
2/*
3 * r8a779f0 Clock Pulse Generator / Module Standby and Software Reset
4 *
5 * Copyright (C) 2021 Renesas Electronics Corp.
6 *
7 * Based on r8a779a0-cpg-mssr.c
8 */
9
Hai Pham99d40392023-02-28 22:34:39 +010010#include <clk-uclass.h>
11#include <dm.h>
12
13#include <dt-bindings/clock/r8a779f0-cpg-mssr.h>
14
15#include "renesas-cpg-mssr.h"
16#include "rcar-gen3-cpg.h"
17
18enum clk_ids {
19 /* Core Clock Outputs exported to DT */
20 LAST_DT_CORE_CLK = R8A779F0_CLK_R,
21
22 /* External Input Clocks */
23 CLK_EXTAL,
24 CLK_EXTALR,
25
26 /* Internal Core Clocks */
27 CLK_MAIN,
28 CLK_PLL1,
29 CLK_PLL2,
30 CLK_PLL3,
31 CLK_PLL5,
32 CLK_PLL6,
33 CLK_PLL1_DIV2,
34 CLK_PLL2_DIV2,
35 CLK_PLL3_DIV2,
36 CLK_PLL5_DIV2,
37 CLK_PLL5_DIV4,
38 CLK_PLL6_DIV2,
39 CLK_S0,
40 CLK_SASYNCPER,
41 CLK_SDSRC,
42 CLK_RPCSRC,
43 CLK_OCO,
44
45 /* Module Clocks */
46 MOD_CLK_BASE
47};
48
Marek Vasut97e1ba32023-09-17 16:11:36 +020049static const struct cpg_core_clk r8a779f0_core_clks[] __initconst = {
Hai Pham99d40392023-02-28 22:34:39 +010050 /* External Clock Inputs */
51 DEF_INPUT("extal", CLK_EXTAL),
52 DEF_INPUT("extalr", CLK_EXTALR),
53
54 /* Internal Core Clocks */
55 DEF_BASE(".main", CLK_MAIN, CLK_TYPE_GEN4_MAIN, CLK_EXTAL),
56 DEF_BASE(".pll1", CLK_PLL1, CLK_TYPE_GEN4_PLL1, CLK_MAIN),
57 DEF_BASE(".pll2", CLK_PLL2, CLK_TYPE_GEN4_PLL2, CLK_MAIN),
58 DEF_BASE(".pll3", CLK_PLL3, CLK_TYPE_GEN4_PLL3, CLK_MAIN),
59 DEF_BASE(".pll5", CLK_PLL5, CLK_TYPE_GEN4_PLL5, CLK_MAIN),
60 DEF_BASE(".pll6", CLK_PLL6, CLK_TYPE_GEN4_PLL6, CLK_MAIN),
61
62 DEF_FIXED(".pll1_div2", CLK_PLL1_DIV2, CLK_PLL1, 2, 1),
63 DEF_FIXED(".pll2_div2", CLK_PLL2_DIV2, CLK_PLL2, 2, 1),
64 DEF_FIXED(".pll3_div2", CLK_PLL3_DIV2, CLK_PLL3, 2, 1),
65 DEF_FIXED(".pll5_div2", CLK_PLL5_DIV2, CLK_PLL5, 2, 1),
66 DEF_FIXED(".pll5_div4", CLK_PLL5_DIV4, CLK_PLL5_DIV2, 2, 1),
67 DEF_FIXED(".pll6_div2", CLK_PLL6_DIV2, CLK_PLL6, 2, 1),
68 DEF_FIXED(".s0", CLK_S0, CLK_PLL1_DIV2, 2, 1),
69
70 DEF_FIXED(".sasyncper", CLK_SASYNCPER, CLK_PLL5_DIV4, 3, 1),
71 DEF_BASE(".sdsrc", CLK_SDSRC, CLK_TYPE_GEN4_SDSRC, CLK_PLL5),
72 DEF_RATE(".oco", CLK_OCO, 32768),
73
74 DEF_BASE(".rpcsrc", CLK_RPCSRC, CLK_TYPE_GEN4_RPCSRC, CLK_PLL5),
75
76 /* Core Clock Outputs */
77 DEF_GEN4_Z("z0", R8A779F0_CLK_Z0, CLK_TYPE_GEN4_Z, CLK_PLL2, 2, 0),
78 DEF_GEN4_Z("z1", R8A779F0_CLK_Z1, CLK_TYPE_GEN4_Z, CLK_PLL2, 2, 8),
79 DEF_FIXED("s0d2", R8A779F0_CLK_S0D2, CLK_S0, 2, 1),
80 DEF_FIXED("s0d3", R8A779F0_CLK_S0D3, CLK_S0, 3, 1),
81 DEF_FIXED("s0d4", R8A779F0_CLK_S0D4, CLK_S0, 4, 1),
82 DEF_FIXED("cl16m", R8A779F0_CLK_CL16M, CLK_S0, 48, 1),
83 DEF_FIXED("s0d2_mm", R8A779F0_CLK_S0D2_MM, CLK_S0, 2, 1),
84 DEF_FIXED("s0d3_mm", R8A779F0_CLK_S0D3_MM, CLK_S0, 3, 1),
85 DEF_FIXED("s0d4_mm", R8A779F0_CLK_S0D4_MM, CLK_S0, 4, 1),
86 DEF_FIXED("cl16m_mm", R8A779F0_CLK_CL16M_MM, CLK_S0, 48, 1),
87 DEF_FIXED("s0d2_rt", R8A779F0_CLK_S0D2_RT, CLK_S0, 2, 1),
88 DEF_FIXED("s0d3_rt", R8A779F0_CLK_S0D3_RT, CLK_S0, 3, 1),
89 DEF_FIXED("s0d4_rt", R8A779F0_CLK_S0D4_RT, CLK_S0, 4, 1),
90 DEF_FIXED("s0d6_rt", R8A779F0_CLK_S0D6_RT, CLK_S0, 6, 1),
91 DEF_FIXED("cl16m_rt", R8A779F0_CLK_CL16M_RT, CLK_S0, 48, 1),
92 DEF_FIXED("s0d3_per", R8A779F0_CLK_S0D3_PER, CLK_S0, 3, 1),
93 DEF_FIXED("s0d6_per", R8A779F0_CLK_S0D6_PER, CLK_S0, 6, 1),
94 DEF_FIXED("s0d12_per", R8A779F0_CLK_S0D12_PER, CLK_S0, 12, 1),
95 DEF_FIXED("s0d24_per", R8A779F0_CLK_S0D24_PER, CLK_S0, 24, 1),
96 DEF_FIXED("cl16m_per", R8A779F0_CLK_CL16M_PER, CLK_S0, 48, 1),
97 DEF_FIXED("s0d2_hsc", R8A779F0_CLK_S0D2_HSC, CLK_S0, 2, 1),
98 DEF_FIXED("s0d3_hsc", R8A779F0_CLK_S0D3_HSC, CLK_S0, 3, 1),
99 DEF_FIXED("s0d4_hsc", R8A779F0_CLK_S0D4_HSC, CLK_S0, 4, 1),
100 DEF_FIXED("s0d6_hsc", R8A779F0_CLK_S0D6_HSC, CLK_S0, 6, 1),
101 DEF_FIXED("s0d12_hsc", R8A779F0_CLK_S0D12_HSC, CLK_S0, 12, 1),
102 DEF_FIXED("cl16m_hsc", R8A779F0_CLK_CL16M_HSC, CLK_S0, 48, 1),
103 DEF_FIXED("s0d2_cc", R8A779F0_CLK_S0D2_CC, CLK_S0, 2, 1),
104 DEF_FIXED("rsw2", R8A779F0_CLK_RSW2, CLK_PLL5_DIV2, 5, 1),
105 DEF_FIXED("cbfusa", R8A779F0_CLK_CBFUSA, CLK_EXTAL, 2, 1),
106 DEF_FIXED("cpex", R8A779F0_CLK_CPEX, CLK_EXTAL, 2, 1),
107
108 DEF_FIXED("sasyncrt", R8A779F0_CLK_SASYNCRT, CLK_PLL5_DIV4, 48, 1),
109 DEF_FIXED("sasyncperd1",R8A779F0_CLK_SASYNCPERD1, CLK_SASYNCPER,1, 1),
110 DEF_FIXED("sasyncperd2",R8A779F0_CLK_SASYNCPERD2, CLK_SASYNCPER,2, 1),
111 DEF_FIXED("sasyncperd4",R8A779F0_CLK_SASYNCPERD4, CLK_SASYNCPER,4, 1),
112
113 DEF_GEN4_SDH("sd0h", R8A779F0_CLK_SD0H, CLK_SDSRC, 0x870),
114 DEF_GEN4_SD("sd0", R8A779F0_CLK_SD0, R8A779F0_CLK_SD0H, 0x870),
115
116 DEF_BASE("rpc", R8A779F0_CLK_RPC, CLK_TYPE_GEN4_RPC, CLK_RPCSRC),
117 DEF_BASE("rpcd2", R8A779F0_CLK_RPCD2, CLK_TYPE_GEN4_RPCD2, R8A779F0_CLK_RPC),
118
119 DEF_DIV6P1("mso", R8A779F0_CLK_MSO, CLK_PLL5_DIV4, 0x87c),
120
121 DEF_GEN4_OSC("osc", R8A779F0_CLK_OSC, CLK_EXTAL, 8),
122 DEF_GEN4_MDSEL("r", R8A779F0_CLK_R, 29, CLK_EXTALR, 1, CLK_OCO, 1),
123};
124
Marek Vasut97e1ba32023-09-17 16:11:36 +0200125static const struct mssr_mod_clk r8a779f0_mod_clks[] __initconst = {
Hai Pham99d40392023-02-28 22:34:39 +0100126 DEF_MOD("hscif0", 514, R8A779F0_CLK_SASYNCPERD1),
127 DEF_MOD("hscif1", 515, R8A779F0_CLK_SASYNCPERD1),
128 DEF_MOD("hscif2", 516, R8A779F0_CLK_SASYNCPERD1),
129 DEF_MOD("hscif3", 517, R8A779F0_CLK_SASYNCPERD1),
130 DEF_MOD("i2c0", 518, R8A779F0_CLK_S0D6_PER),
131 DEF_MOD("i2c1", 519, R8A779F0_CLK_S0D6_PER),
132 DEF_MOD("i2c2", 520, R8A779F0_CLK_S0D6_PER),
133 DEF_MOD("i2c3", 521, R8A779F0_CLK_S0D6_PER),
134 DEF_MOD("i2c4", 522, R8A779F0_CLK_S0D6_PER),
135 DEF_MOD("i2c5", 523, R8A779F0_CLK_S0D6_PER),
136 DEF_MOD("msiof0", 618, R8A779F0_CLK_MSO),
137 DEF_MOD("msiof1", 619, R8A779F0_CLK_MSO),
138 DEF_MOD("msiof2", 620, R8A779F0_CLK_MSO),
139 DEF_MOD("msiof3", 621, R8A779F0_CLK_MSO),
140 DEF_MOD("pcie0", 624, R8A779F0_CLK_S0D2),
141 DEF_MOD("pcie1", 625, R8A779F0_CLK_S0D2),
142 DEF_MOD("scif0", 702, R8A779F0_CLK_SASYNCPERD4),
143 DEF_MOD("scif1", 703, R8A779F0_CLK_SASYNCPERD4),
144 DEF_MOD("scif3", 704, R8A779F0_CLK_SASYNCPERD4),
145 DEF_MOD("scif4", 705, R8A779F0_CLK_SASYNCPERD4),
146 DEF_MOD("sdhi0", 706, R8A779F0_CLK_SD0),
147 DEF_MOD("sys-dmac0", 709, R8A779F0_CLK_S0D3_PER),
148 DEF_MOD("sys-dmac1", 710, R8A779F0_CLK_S0D3_PER),
149 DEF_MOD("tmu0", 713, R8A779F0_CLK_SASYNCRT),
150 DEF_MOD("tmu1", 714, R8A779F0_CLK_SASYNCPERD2),
151 DEF_MOD("tmu2", 715, R8A779F0_CLK_SASYNCPERD2),
152 DEF_MOD("tmu3", 716, R8A779F0_CLK_SASYNCPERD2),
153 DEF_MOD("tmu4", 717, R8A779F0_CLK_SASYNCPERD2),
154 DEF_MOD("wdt", 907, R8A779F0_CLK_R),
155 DEF_MOD("cmt0", 910, R8A779F0_CLK_R),
156 DEF_MOD("cmt1", 911, R8A779F0_CLK_R),
157 DEF_MOD("cmt2", 912, R8A779F0_CLK_R),
158 DEF_MOD("cmt3", 913, R8A779F0_CLK_R),
159 DEF_MOD("pfc0", 915, R8A779F0_CLK_CL16M),
160 DEF_MOD("tsc", 919, R8A779F0_CLK_CL16M),
161 DEF_MOD("rswitch2", 1505, R8A779F0_CLK_RSW2),
162 DEF_MOD("ether-serdes", 1506, R8A779F0_CLK_S0D2_HSC),
163 DEF_MOD("ufs", 1514, R8A779F0_CLK_S0D4_HSC),
164};
165
166/*
167 * CPG Clock Data
168 */
169/*
170 * MD EXTAL PLL1 PLL2 PLL3 PLL4 PLL5 PLL6 OSC
171 * 14 13 (MHz)
172 * ------------------------------------------------------------------------
173 * 0 0 16 / 1 x200 x150 x200 n/a x200 x134 /15
174 * 0 1 20 / 1 x160 x120 x160 n/a x160 x106 /19
175 * 1 0 Prohibited setting
176 * 1 1 40 / 2 x160 x120 x160 n/a x160 x106 /38
177 */
178#define CPG_PLL_CONFIG_INDEX(md) ((((md) & BIT(14)) >> 13) | \
179 (((md) & BIT(13)) >> 13))
180
181static const struct rcar_gen4_cpg_pll_config cpg_pll_configs[4] = {
182 /* EXTAL div PLL1 mult/div PLL2 mult/div PLL3 mult/div PLL4 mult/div PLL5 mult/div PLL6 mult/div OSC prediv */
183 { 1, 200, 1, 150, 1, 200, 1, 0, 0, 200, 1, 134, 1, 15, },
184 { 1, 160, 1, 120, 1, 160, 1, 0, 0, 160, 1, 106, 1, 19, },
185 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
186 { 2, 160, 1, 120, 1, 160, 1, 0, 0, 160, 1, 106, 1, 38, },
187};
188
189/*
190 * Note that the only clock left running before booting Linux are now
191 * MFIS, INTC-AP, INTC-EX and HSCIF0/SCIF3 on S4
192 */
193#define MSTPCR5_HSCIF0 BIT(14)
194#define MSTPCR7_SCIF3 BIT(4) /* No information: MFIS, INTC-AP, INTC-EX */
195static const struct mstp_stop_table r8a779f0_mstp_table[] = {
196 { 0x00000000, 0x0, 0x0, 0x0 },
197 { 0x00800000, 0x0, 0x0, 0x0 },
198 { 0x00000000, 0x0, 0x0, 0x0 },
199 { 0x00000000, 0x0, 0x0, 0x0 },
200 { 0x00000000, 0x0, 0x0, 0x0 },
201 { 0x0003c000, MSTPCR5_HSCIF0, 0x0, 0x0 },
202 { 0x03000000, 0x0, 0x0, 0x0 },
203 { 0x1ffbe040, MSTPCR7_SCIF3, 0x0, 0x0 },
204 { 0x00000000, 0x0, 0x0, 0x0 },
205 { 0x00003c78, 0x0, 0x0, 0x0 },
206 { 0x00000000, 0x0, 0x0, 0x0 },
207 { 0x00000000, 0x0, 0x0, 0x0 },
208 { 0x9e800000, 0x0, 0x0, 0x0 },
209 { 0x00000027, 0x0, 0x0, 0x0 },
210 { 0x00000000, 0x0, 0x0, 0x0 },
211 { 0x00005800, 0x0, 0x0, 0x0 },
212};
213
214static const void *r8a779f0_get_pll_config(const u32 cpg_mode)
215{
216 return &cpg_pll_configs[CPG_PLL_CONFIG_INDEX(cpg_mode)];
217}
218
219static const struct cpg_mssr_info r8a779f0_cpg_mssr_info = {
220 .core_clk = r8a779f0_core_clks,
221 .core_clk_size = ARRAY_SIZE(r8a779f0_core_clks),
222 .mod_clk = r8a779f0_mod_clks,
223 .mod_clk_size = ARRAY_SIZE(r8a779f0_mod_clks),
224 .mstp_table = r8a779f0_mstp_table,
225 .mstp_table_size = ARRAY_SIZE(r8a779f0_mstp_table),
226 .reset_node = "renesas,r8a779f0-rst",
227 .reset_modemr_offset = CPG_RST_MODEMR0,
228 .extalr_node = "extalr",
229 .mod_clk_base = MOD_CLK_BASE,
230 .clk_extal_id = CLK_EXTAL,
231 .clk_extalr_id = CLK_EXTALR,
232 .get_pll_config = r8a779f0_get_pll_config,
233 .reg_layout = CLK_REG_LAYOUT_RCAR_GEN4,
234};
235
236static const struct udevice_id r8a779f0_cpg_ids[] = {
237 {
238 .compatible = "renesas,r8a779f0-cpg-mssr",
239 .data = (ulong)&r8a779f0_cpg_mssr_info
240 },
241 { }
242};
243
244U_BOOT_DRIVER(cpg_r8a779f0) = {
245 .name = "cpg_r8a779f0",
246 .id = UCLASS_NOP,
247 .of_match = r8a779f0_cpg_ids,
248 .bind = gen3_cpg_bind,
249};