bl2_cpg_init.c 11.8 KB
Newer Older
1
/*
2
 * Copyright (c) 2015-2021, Renesas Electronics Corporation. All rights reserved.
3
4
5
6
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

7
8
9
#include <common/debug.h>
#include <lib/mmio.h>

10
#include "cpg_registers.h"
11
#include "rcar_def.h"
12
13
14
15
#include "rcar_private.h"

static void bl2_secure_cpg_init(void);

16
17
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_H3) || \
	(RCAR_LSI == RCAR_H3N) || (RCAR_LSI == RZ_G2H)
18
19
20
21
static void bl2_realtime_cpg_init_h3(void);
static void bl2_system_cpg_init_h3(void);
#endif

22
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3) || (RCAR_LSI == RZ_G2M)
23
24
25
26
static void bl2_realtime_cpg_init_m3(void);
static void bl2_system_cpg_init_m3(void);
#endif

27
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3N) || (RCAR_LSI == RZ_G2N)
28
29
30
31
static void bl2_realtime_cpg_init_m3n(void);
static void bl2_system_cpg_init_m3n(void);
#endif

32
33
34
35
36
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_V3M)
static void bl2_realtime_cpg_init_v3m(void);
static void bl2_system_cpg_init_v3m(void);
#endif

37
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_E3) || (RCAR_LSI == RZ_G2E)
38
39
40
41
static void bl2_realtime_cpg_init_e3(void);
static void bl2_system_cpg_init_e3(void);
#endif

42
43
44
45
46
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_D3)
static void bl2_realtime_cpg_init_d3(void);
static void bl2_system_cpg_init_d3(void);
#endif

47
48
49
50
51
52
53
54
typedef struct {
	uintptr_t adr;
	uint32_t val;
} reg_setting_t;

static void bl2_secure_cpg_init(void)
{
	uint32_t stop_cr2, reset_cr2;
55
56
	uint32_t stop_cr4, reset_cr4;
	uint32_t stop_cr5, reset_cr5;
57

58
59
60
#if (RCAR_LSI == RCAR_D3)
	reset_cr2 = 0x00000000U;
	stop_cr2 = 0xFFFFFFFFU;
61
#elif (RCAR_LSI == RCAR_E3) || (RCAR_LSI == RZ_G2E)
62
63
	reset_cr2 = 0x10000000U;
	stop_cr2 = 0xEFFFFFFFU;
64
65
66
67
#else
	reset_cr2 = 0x14000000U;
	stop_cr2 = 0xEBFFFFFFU;
#endif
68
69
70
71
72
73
74
75
76
77
78
79
80

#if (RCAR_LSI == RCAR_D3)
	reset_cr4 = 0x00000000U;
	stop_cr4 = 0xFFFFFFFFU;
	reset_cr5 = 0x00000000U;
	stop_cr5 = 0xFFFFFFFFU;
#else
	reset_cr4 = 0x80000003U;
	stop_cr4 = 0x7FFFFFFFU;
	reset_cr5 = 0x40000000U;
	stop_cr5 = 0xBFFFFFFFU;
#endif

81
	/* Secure Module Stop Control Registers */
82
83
84
85
	cpg_write(SCMSTPCR0, 0xFFFFFFFFU);
	cpg_write(SCMSTPCR1, 0xFFFFFFFFU);
	cpg_write(SCMSTPCR2, stop_cr2);
	cpg_write(SCMSTPCR3, 0xFFFFFFFFU);
86
87
	cpg_write(SCMSTPCR4, stop_cr4);
	cpg_write(SCMSTPCR5, stop_cr5);
88
89
90
91
92
93
94
	cpg_write(SCMSTPCR6, 0xFFFFFFFFU);
	cpg_write(SCMSTPCR7, 0xFFFFFFFFU);
	cpg_write(SCMSTPCR8, 0xFFFFFFFFU);
	cpg_write(SCMSTPCR9, 0xFFFDFFFFU);
	cpg_write(SCMSTPCR10, 0xFFFFFFFFU);
	cpg_write(SCMSTPCR11, 0xFFFFFFFFU);

95
	/* Secure Software Reset Access Enable Control Registers */
96
97
98
99
	cpg_write(SCSRSTECR0, 0x00000000U);
	cpg_write(SCSRSTECR1, 0x00000000U);
	cpg_write(SCSRSTECR2, reset_cr2);
	cpg_write(SCSRSTECR3, 0x00000000U);
100
101
	cpg_write(SCSRSTECR4, reset_cr4);
	cpg_write(SCSRSTECR5, reset_cr5);
102
103
104
105
106
107
108
109
	cpg_write(SCSRSTECR6, 0x00000000U);
	cpg_write(SCSRSTECR7, 0x00000000U);
	cpg_write(SCSRSTECR8, 0x00000000U);
	cpg_write(SCSRSTECR9, 0x00020000U);
	cpg_write(SCSRSTECR10, 0x00000000U);
	cpg_write(SCSRSTECR11, 0x00000000U);
}

110
111
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_H3) || \
	(RCAR_LSI == RCAR_H3N) || (RCAR_LSI == RZ_G2H)
112
113
static void bl2_realtime_cpg_init_h3(void)
{
114
	uint32_t cut = mmio_read_32(RCAR_PRR) & PRR_CUT_MASK;
115
116
	uint32_t cr0, cr8;

117
	cr0 = (cut == PRR_PRODUCT_10 || cut == PRR_PRODUCT_11) ?
118
	    0x00200000U : 0x00210000U;
119
	cr8 = (cut == PRR_PRODUCT_10 || cut == PRR_PRODUCT_11) ?
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
	    0x01F1FFF4U : 0x01F1FFF7U;

	cpg_write(RMSTPCR0, cr0);
	cpg_write(RMSTPCR1, 0xFFFFFFFFU);
	cpg_write(RMSTPCR2, 0x040E0FDCU);
	cpg_write(RMSTPCR3, 0xFFFFFFDFU);
	cpg_write(RMSTPCR4, 0x80000004U);
	cpg_write(RMSTPCR5, 0xC3FFFFFFU);
	cpg_write(RMSTPCR6, 0xFFFFFFFFU);
	cpg_write(RMSTPCR7, 0xFFFFFFFFU);
	cpg_write(RMSTPCR8, cr8);
	cpg_write(RMSTPCR9, 0xFFFFFFFEU);
	cpg_write(RMSTPCR10, 0xFFFEFFE0U);
	cpg_write(RMSTPCR11, 0x000000B7U);
}

static void bl2_system_cpg_init_h3(void)
{
	/** System Module Stop Control Registers */
	cpg_write(SMSTPCR0, 0x00210000U);
	cpg_write(SMSTPCR1, 0xFFFFFFFFU);
	cpg_write(SMSTPCR2, 0x040E2FDCU);
	cpg_write(SMSTPCR3, 0xFFFFFBDFU);
	cpg_write(SMSTPCR4, 0x80000004U);
	cpg_write(SMSTPCR5, 0xC3FFFFFFU);
	cpg_write(SMSTPCR6, 0xFFFFFFFFU);
	cpg_write(SMSTPCR7, 0xFFFFFFFFU);
	cpg_write(SMSTPCR8, 0x01F1FFF5U);
	cpg_write(SMSTPCR9, 0xFFFFFFFFU);
	cpg_write(SMSTPCR10, 0xFFFEFFE0U);
	cpg_write(SMSTPCR11, 0x000000B7U);
}
#endif

154
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3) || (RCAR_LSI == RZ_G2M)
155
156
static void bl2_realtime_cpg_init_m3(void)
{
157
	/* Realtime Module Stop Control Registers */
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
	cpg_write(RMSTPCR0, 0x00200000U);
	cpg_write(RMSTPCR1, 0xFFFFFFFFU);
	cpg_write(RMSTPCR2, 0x040E0FDCU);
	cpg_write(RMSTPCR3, 0xFFFFFFDFU);
	cpg_write(RMSTPCR4, 0x80000004U);
	cpg_write(RMSTPCR5, 0xC3FFFFFFU);
	cpg_write(RMSTPCR6, 0xFFFFFFFFU);
	cpg_write(RMSTPCR7, 0xFFFFFFFFU);
	cpg_write(RMSTPCR8, 0x01F1FFF7U);
	cpg_write(RMSTPCR9, 0xFFFFFFFEU);
	cpg_write(RMSTPCR10, 0xFFFEFFE0U);
	cpg_write(RMSTPCR11, 0x000000B7U);
}

static void bl2_system_cpg_init_m3(void)
{
174
	/* System Module Stop Control Registers */
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
	cpg_write(SMSTPCR0, 0x00200000U);
	cpg_write(SMSTPCR1, 0xFFFFFFFFU);
	cpg_write(SMSTPCR2, 0x040E2FDCU);
	cpg_write(SMSTPCR3, 0xFFFFFBDFU);
	cpg_write(SMSTPCR4, 0x80000004U);
	cpg_write(SMSTPCR5, 0xC3FFFFFFU);
	cpg_write(SMSTPCR6, 0xFFFFFFFFU);
	cpg_write(SMSTPCR7, 0xFFFFFFFFU);
	cpg_write(SMSTPCR8, 0x01F1FFF7U);
	cpg_write(SMSTPCR9, 0xFFFFFFFFU);
	cpg_write(SMSTPCR10, 0xFFFEFFE0U);
	cpg_write(SMSTPCR11, 0x000000B7U);
}
#endif

190
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3N)  || (RCAR_LSI == RZ_G2N)
191
192
static void bl2_realtime_cpg_init_m3n(void)
{
193
	/* Realtime Module Stop Control Registers */
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
	cpg_write(RMSTPCR0, 0x00210000U);
	cpg_write(RMSTPCR1, 0xFFFFFFFFU);
	cpg_write(RMSTPCR2, 0x040E0FDCU);
	cpg_write(RMSTPCR3, 0xFFFFFFDFU);
	cpg_write(RMSTPCR4, 0x80000004U);
	cpg_write(RMSTPCR5, 0xC3FFFFFFU);
	cpg_write(RMSTPCR6, 0xFFFFFFFFU);
	cpg_write(RMSTPCR7, 0xFFFFFFFFU);
	cpg_write(RMSTPCR8, 0x00F1FFF7U);
	cpg_write(RMSTPCR9, 0xFFFFFFFFU);
	cpg_write(RMSTPCR10, 0xFFFFFFE0U);
	cpg_write(RMSTPCR11, 0x000000B7U);
}

static void bl2_system_cpg_init_m3n(void)
{
	/* System Module Stop Control Registers */
	cpg_write(SMSTPCR0, 0x00210000U);
	cpg_write(SMSTPCR1, 0xFFFFFFFFU);
	cpg_write(SMSTPCR2, 0x040E2FDCU);
	cpg_write(SMSTPCR3, 0xFFFFFBDFU);
	cpg_write(SMSTPCR4, 0x80000004U);
	cpg_write(SMSTPCR5, 0xC3FFFFFFU);
	cpg_write(SMSTPCR6, 0xFFFFFFFFU);
	cpg_write(SMSTPCR7, 0xFFFFFFFFU);
	cpg_write(SMSTPCR8, 0x00F1FFF7U);
	cpg_write(SMSTPCR9, 0xFFFFFFFFU);
	cpg_write(SMSTPCR10, 0xFFFFFFE0U);
	cpg_write(SMSTPCR11, 0x000000B7U);
}
#endif

226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_V3M)
static void bl2_realtime_cpg_init_v3m(void)
{
	/* Realtime Module Stop Control Registers */
	cpg_write(RMSTPCR0, 0x00230000U);
	cpg_write(RMSTPCR1, 0xFFFFFFFFU);
	cpg_write(RMSTPCR2, 0x14062FD8U);
	cpg_write(RMSTPCR3, 0xFFFFFFDFU);
	cpg_write(RMSTPCR4, 0x80000184U);
	cpg_write(RMSTPCR5, 0x83FFFFFFU);
	cpg_write(RMSTPCR6, 0xFFFFFFFFU);
	cpg_write(RMSTPCR7, 0xFFFFFFFFU);
	cpg_write(RMSTPCR8, 0x7FF3FFF4U);
	cpg_write(RMSTPCR9, 0xFFFFFFFEU);
}

static void bl2_system_cpg_init_v3m(void)
{
	/* System Module Stop Control Registers */
	cpg_write(SMSTPCR0, 0x00210000U);
	cpg_write(SMSTPCR1, 0xFFFFFFFFU);
	cpg_write(SMSTPCR2, 0x340E2FDCU);
	cpg_write(SMSTPCR3, 0xFFFFFBDFU);
	cpg_write(SMSTPCR4, 0x80000004U);
	cpg_write(SMSTPCR5, 0xC3FFFFFFU);
	cpg_write(SMSTPCR6, 0xFFFFFFFFU);
	cpg_write(SMSTPCR7, 0xFFFFFFFFU);
	cpg_write(SMSTPCR8, 0x01F1FFF5U);
	cpg_write(SMSTPCR9, 0xFFFFFFFEU);
}
#endif

258
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_E3) || (RCAR_LSI == RZ_G2E)
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
static void bl2_realtime_cpg_init_e3(void)
{
	/* Realtime Module Stop Control Registers */
	cpg_write(RMSTPCR0, 0x00210000U);
	cpg_write(RMSTPCR1, 0xFFFFFFFFU);
	cpg_write(RMSTPCR2, 0x000E0FDCU);
	cpg_write(RMSTPCR3, 0xFFFFFFDFU);
	cpg_write(RMSTPCR4, 0x80000004U);
	cpg_write(RMSTPCR5, 0xC3FFFFFFU);
	cpg_write(RMSTPCR6, 0xFFFFFFFFU);
	cpg_write(RMSTPCR7, 0xFFFFFFFFU);
	cpg_write(RMSTPCR8, 0x00F1FFF7U);
	cpg_write(RMSTPCR9, 0xFFFFFFDFU);
	cpg_write(RMSTPCR10, 0xFFFFFFE8U);
	cpg_write(RMSTPCR11, 0x000000B7U);
}

static void bl2_system_cpg_init_e3(void)
{
	/* System Module Stop Control Registers */
	cpg_write(SMSTPCR0, 0x00210000U);
	cpg_write(SMSTPCR1, 0xFFFFFFFFU);
	cpg_write(SMSTPCR2, 0x000E2FDCU);
	cpg_write(SMSTPCR3, 0xFFFFFBDFU);
	cpg_write(SMSTPCR4, 0x80000004U);
	cpg_write(SMSTPCR5, 0xC3FFFFFFU);
	cpg_write(SMSTPCR6, 0xFFFFFFFFU);
	cpg_write(SMSTPCR7, 0xFFFFFFFFU);
	cpg_write(SMSTPCR8, 0x00F1FFF7U);
	cpg_write(SMSTPCR9, 0xFFFFFFDFU);
	cpg_write(SMSTPCR10, 0xFFFFFFE8U);
	cpg_write(SMSTPCR11, 0x000000B7U);
}
#endif

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_D3)
static void bl2_realtime_cpg_init_d3(void)
{
	/* Realtime Module Stop Control Registers */
	cpg_write(RMSTPCR0, 0x00010000U);
	cpg_write(RMSTPCR1, 0xFFFFFFFFU);
	cpg_write(RMSTPCR2, 0x00060FDCU);
	cpg_write(RMSTPCR3, 0xFFFFFFDFU);
	cpg_write(RMSTPCR4, 0x80000184U);
	cpg_write(RMSTPCR5, 0x83FFFFFFU);
	cpg_write(RMSTPCR6, 0xFFFFFFFFU);
	cpg_write(RMSTPCR7, 0xFFFFFFFFU);
	cpg_write(RMSTPCR8, 0x00F1FFF7U);
	cpg_write(RMSTPCR9, 0xF3F5E016U);
	cpg_write(RMSTPCR10, 0xFFFEFFE0U);
	cpg_write(RMSTPCR11, 0x000000B7U);
}

static void bl2_system_cpg_init_d3(void)
{
	/* System Module Stop Control Registers */
	cpg_write(SMSTPCR0, 0x00010000U);
	cpg_write(SMSTPCR1, 0xFFFFFFFFU);
	cpg_write(SMSTPCR2, 0x00060FDCU);
	cpg_write(SMSTPCR3, 0xFFFFFBDFU);
	cpg_write(SMSTPCR4, 0x00000084U);
	cpg_write(SMSTPCR5, 0x83FFFFFFU);
	cpg_write(SMSTPCR6, 0xFFFFFFFFU);
	cpg_write(SMSTPCR7, 0xFFFFFFFFU);
	cpg_write(SMSTPCR8, 0x00F1FFF7U);
	cpg_write(SMSTPCR9, 0xF3F5E016U);
	cpg_write(SMSTPCR10, 0xFFFEFFE0U);
	cpg_write(SMSTPCR11, 0x000000B7U);
}
#endif

330
331
332
333
void bl2_cpg_init(void)
{
	uint32_t boot_cpu = mmio_read_32(RCAR_MODEMR) & MODEMR_BOOT_CPU_MASK;
#if RCAR_LSI == RCAR_AUTO
334
	uint32_t product = mmio_read_32(RCAR_PRR) & PRR_PRODUCT_MASK;
335
336
337
338
339
340
341
342
#endif
	bl2_secure_cpg_init();

	if (boot_cpu == MODEMR_BOOT_CPU_CA57 ||
	    boot_cpu == MODEMR_BOOT_CPU_CA53) {
#if RCAR_LSI == RCAR_AUTO

		switch (product) {
343
		case PRR_PRODUCT_H3:
344
345
			bl2_realtime_cpg_init_h3();
			break;
346
		case PRR_PRODUCT_M3:
347
348
			bl2_realtime_cpg_init_m3();
			break;
349
		case PRR_PRODUCT_M3N:
350
351
			bl2_realtime_cpg_init_m3n();
			break;
352
		case PRR_PRODUCT_V3M:
353
354
			bl2_realtime_cpg_init_v3m();
			break;
355
		case PRR_PRODUCT_E3:
356
357
			bl2_realtime_cpg_init_e3();
			break;
358
		case PRR_PRODUCT_D3:
359
360
			bl2_realtime_cpg_init_d3();
			break;
361
362
363
364
		default:
			panic();
			break;
		}
365
#elif (RCAR_LSI == RCAR_H3) || (RCAR_LSI == RCAR_H3N) || (RCAR_LSI == RZ_G2H)
366
		bl2_realtime_cpg_init_h3();
367
#elif (RCAR_LSI == RCAR_M3) || (RCAR_LSI == RZ_G2M)
368
		bl2_realtime_cpg_init_m3();
369
#elif RCAR_LSI == RCAR_M3N || (RCAR_LSI == RZ_G2N)
370
		bl2_realtime_cpg_init_m3n();
371
372
#elif RCAR_LSI == RCAR_V3M
		bl2_realtime_cpg_init_v3m();
373
#elif RCAR_LSI == RCAR_E3 || RCAR_LSI == RZ_G2E
374
		bl2_realtime_cpg_init_e3();
375
376
#elif RCAR_LSI == RCAR_D3
		bl2_realtime_cpg_init_d3();
377
378
379
380
381
382
383
384
385
#else
#error "Don't have CPG initialize routine(unknown)."
#endif
	}
}

void bl2_system_cpg_init(void)
{
#if RCAR_LSI == RCAR_AUTO
386
	uint32_t product = mmio_read_32(RCAR_PRR) & PRR_PRODUCT_MASK;
387
388

	switch (product) {
389
	case PRR_PRODUCT_H3:
390
391
		bl2_system_cpg_init_h3();
		break;
392
	case PRR_PRODUCT_M3:
393
394
		bl2_system_cpg_init_m3();
		break;
395
	case PRR_PRODUCT_M3N:
396
397
		bl2_system_cpg_init_m3n();
		break;
398
	case PRR_PRODUCT_V3M:
399
400
		bl2_system_cpg_init_v3m();
		break;
401
	case PRR_PRODUCT_E3:
402
403
		bl2_system_cpg_init_e3();
		break;
404
	case PRR_PRODUCT_D3:
405
406
		bl2_system_cpg_init_d3();
		break;
407
408
409
410
	default:
		panic();
		break;
	}
411
#elif (RCAR_LSI == RCAR_H3) || (RCAR_LSI == RCAR_H3N) || (RCAR_LSI == RZ_G2H)
412
	bl2_system_cpg_init_h3();
413
#elif (RCAR_LSI == RCAR_M3) || (RCAR_LSI == RZ_G2M)
414
	bl2_system_cpg_init_m3();
415
#elif RCAR_LSI == RCAR_M3N  || (RCAR_LSI == RZ_G2N)
416
	bl2_system_cpg_init_m3n();
417
418
#elif RCAR_LSI == RCAR_V3M
	bl2_system_cpg_init_v3m();
419
#elif RCAR_LSI == RCAR_E3 || RCAR_LSI == RZ_G2E
420
	bl2_system_cpg_init_e3();
421
422
#elif RCAR_LSI == RCAR_D3
	bl2_system_cpg_init_d3();
423
424
425
426
#else
#error "Don't have CPG initialize routine(unknown)."
#endif
}