blob: a21d6ab61cb482c705839c74587b1cdd408c016a [file] [log] [blame]
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02001/*
2 * Copyright (c) 2018, Renesas Electronics Corporation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <string.h>
8
Marek Vasut93c85fc2018-10-02 20:45:18 +02009#include <libfdt.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020011#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012
13#include <arch_helpers.h>
14#include <bl1/bl1.h>
15#include <common/bl_common.h>
16#include <common/debug.h>
17#include <common/desc_image_load.h>
18#include <drivers/console.h>
19#include <lib/mmio.h>
20#include <lib/xlat_tables/xlat_tables_defs.h>
21#include <plat/common/platform.h>
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020022
23#include "avs_driver.h"
24#include "boot_init_dram.h"
25#include "cpg_registers.h"
26#include "board.h"
27#include "emmc_def.h"
28#include "emmc_hal.h"
29#include "emmc_std.h"
30
31#if PMIC_ROHM_BD9571 && RCAR_SYSTEM_RESET_KEEPON_DDR
32#include "iic_dvfs.h"
33#endif
34
35#include "io_common.h"
36#include "qos_init.h"
37#include "rcar_def.h"
38#include "rcar_private.h"
39#include "rcar_version.h"
40#include "rom_api.h"
41
42IMPORT_SYM(unsigned long, __RO_START__, BL2_RO_BASE)
43IMPORT_SYM(unsigned long, __RO_END__, BL2_RO_LIMIT)
44
45#if USE_COHERENT_MEM
46IMPORT_SYM(unsigned long, __COHERENT_RAM_START__, BL2_COHERENT_RAM_BASE)
47IMPORT_SYM(unsigned long, __COHERENT_RAM_END__, BL2_COHERENT_RAM_LIMIT)
48#endif
49
50extern void plat_rcar_gic_driver_init(void);
51extern void plat_rcar_gic_init(void);
52extern void bl2_enter_bl31(const struct entry_point_info *bl_ep_info);
53extern void bl2_system_cpg_init(void);
54extern void bl2_secure_setting(void);
55extern void bl2_cpg_init(void);
56extern void rcar_io_emmc_setup(void);
57extern void rcar_io_setup(void);
58extern void rcar_swdt_release(void);
59extern void rcar_swdt_init(void);
60extern void rcar_rpc_init(void);
61extern void rcar_pfc_init(void);
62extern void rcar_dma_init(void);
63
Marek Vasut1eca7782018-12-28 20:12:13 +010064static void bl2_init_generic_timer(void);
65
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020066/* R-Car Gen3 product check */
67#if (RCAR_LSI == RCAR_H3) || (RCAR_LSI == RCAR_H3N)
68#define TARGET_PRODUCT RCAR_PRODUCT_H3
69#define TARGET_NAME "R-Car H3"
70#elif RCAR_LSI == RCAR_M3
71#define TARGET_PRODUCT RCAR_PRODUCT_M3
72#define TARGET_NAME "R-Car M3"
73#elif RCAR_LSI == RCAR_M3N
74#define TARGET_PRODUCT RCAR_PRODUCT_M3N
75#define TARGET_NAME "R-Car M3N"
Valentine Barshakf2184142018-10-30 02:06:17 +030076#elif RCAR_LSI == RCAR_V3M
77#define TARGET_PRODUCT RCAR_PRODUCT_V3M
78#define TARGET_NAME "R-Car V3M"
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020079#elif RCAR_LSI == RCAR_E3
80#define TARGET_PRODUCT RCAR_PRODUCT_E3
81#define TARGET_NAME "R-Car E3"
Marek Vasut4ae342c2019-01-05 13:56:03 +010082#elif RCAR_LSI == RCAR_D3
83#define TARGET_PRODUCT RCAR_PRODUCT_D3
84#define TARGET_NAME "R-Car D3"
Marek Vasut94cc0f82018-12-28 20:11:26 +010085#elif RCAR_LSI == RCAR_AUTO
Valentine Barshakf2184142018-10-30 02:06:17 +030086#define TARGET_NAME "R-Car H3/M3/M3N/V3M"
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020087#endif
88
89#if (RCAR_LSI == RCAR_E3)
90#define GPIO_INDT (GPIO_INDT6)
91#define GPIO_BKUP_TRG_SHIFT ((uint32_t)1U<<13U)
92#else
93#define GPIO_INDT (GPIO_INDT1)
94#define GPIO_BKUP_TRG_SHIFT ((uint32_t)1U<<8U)
95#endif
96
97CASSERT((PARAMS_BASE + sizeof(bl2_to_bl31_params_mem_t) + 0x100)
98 < (RCAR_SHARED_MEM_BASE + RCAR_SHARED_MEM_SIZE),
99 assert_bl31_params_do_not_fit_in_shared_memory);
100
101static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
102
Marek Vasut93c85fc2018-10-02 20:45:18 +0200103/* FDT with DRAM configuration */
104uint64_t fdt_blob[PAGE_SIZE_4KB / sizeof(uint64_t)];
105static void *fdt = (void *)fdt_blob;
106
107static void unsigned_num_print(unsigned long long int unum, unsigned int radix,
108 char *string)
109{
110 /* Just need enough space to store 64 bit decimal integer */
111 char num_buf[20];
112 int i = 0;
113 unsigned int rem;
114
115 do {
116 rem = unum % radix;
117 if (rem < 0xa)
118 num_buf[i] = '0' + rem;
119 else
120 num_buf[i] = 'a' + (rem - 0xa);
121 i++;
122 unum /= radix;
123 } while (unum > 0U);
124
125 while (--i >= 0)
126 *string++ = num_buf[i];
127}
128
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200129#if (RCAR_LOSSY_ENABLE == 1)
130typedef struct bl2_lossy_info {
131 uint32_t magic;
132 uint32_t a0;
133 uint32_t b0;
134} bl2_lossy_info_t;
135
Marek Vasut4d693c22018-10-11 16:53:58 +0200136static void bl2_lossy_gen_fdt(uint32_t no, uint64_t start_addr,
137 uint64_t end_addr, uint32_t format,
138 uint32_t enable, int fcnlnode)
139{
140 const uint64_t fcnlsize = cpu_to_fdt64(end_addr - start_addr);
141 char nodename[40] = { 0 };
142 int ret, node;
143
144 /* Ignore undefined addresses */
145 if (start_addr == 0 && end_addr == 0)
146 return;
147
148 snprintf(nodename, sizeof(nodename), "lossy-decompression@");
149 unsigned_num_print(start_addr, 16, nodename + strlen(nodename));
150
151 node = ret = fdt_add_subnode(fdt, fcnlnode, nodename);
152 if (ret < 0) {
153 NOTICE("BL2: Cannot create FCNL node (ret=%i)\n", ret);
154 panic();
155 }
156
157 ret = fdt_setprop_string(fdt, node, "compatible",
158 "renesas,lossy-decompression");
159 if (ret < 0) {
160 NOTICE("BL2: Cannot add FCNL compat string (ret=%i)\n", ret);
161 panic();
162 }
163
164 ret = fdt_appendprop_string(fdt, node, "compatible",
165 "shared-dma-pool");
166 if (ret < 0) {
167 NOTICE("BL2: Cannot append FCNL compat string (ret=%i)\n", ret);
168 panic();
169 }
170
171 ret = fdt_setprop_u64(fdt, node, "reg", start_addr);
172 if (ret < 0) {
173 NOTICE("BL2: Cannot add FCNL reg prop (ret=%i)\n", ret);
174 panic();
175 }
176
177 ret = fdt_appendprop(fdt, node, "reg", &fcnlsize, sizeof(fcnlsize));
178 if (ret < 0) {
179 NOTICE("BL2: Cannot append FCNL reg size prop (ret=%i)\n", ret);
180 panic();
181 }
182
183 ret = fdt_setprop(fdt, node, "no-map", NULL, 0);
184 if (ret < 0) {
185 NOTICE("BL2: Cannot add FCNL no-map prop (ret=%i)\n", ret);
186 panic();
187 }
188
189 ret = fdt_setprop_u32(fdt, node, "renesas,formats", format);
190 if (ret < 0) {
191 NOTICE("BL2: Cannot add FCNL formats prop (ret=%i)\n", ret);
192 panic();
193 }
194}
195
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200196static void bl2_lossy_setting(uint32_t no, uint64_t start_addr,
197 uint64_t end_addr, uint32_t format,
Marek Vasut4d693c22018-10-11 16:53:58 +0200198 uint32_t enable, int fcnlnode)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200199{
200 bl2_lossy_info_t info;
201 uint32_t reg;
202
Marek Vasut4d693c22018-10-11 16:53:58 +0200203 bl2_lossy_gen_fdt(no, start_addr, end_addr, format, enable, fcnlnode);
204
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200205 reg = format | (start_addr >> 20);
206 mmio_write_32(AXI_DCMPAREACRA0 + 0x8 * no, reg);
207 mmio_write_32(AXI_DCMPAREACRB0 + 0x8 * no, end_addr >> 20);
208 mmio_write_32(AXI_DCMPAREACRA0 + 0x8 * no, reg | enable);
209
210 info.magic = 0x12345678U;
211 info.a0 = mmio_read_32(AXI_DCMPAREACRA0 + 0x8 * no);
212 info.b0 = mmio_read_32(AXI_DCMPAREACRB0 + 0x8 * no);
213
214 mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no, info.magic);
215 mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no + 0x4, info.a0);
216 mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no + 0x8, info.b0);
217
218 NOTICE(" Entry %d: DCMPAREACRAx:0x%x DCMPAREACRBx:0x%x\n", no,
219 mmio_read_32(AXI_DCMPAREACRA0 + 0x8 * no),
220 mmio_read_32(AXI_DCMPAREACRB0 + 0x8 * no));
221}
222#endif
223
224void bl2_plat_flush_bl31_params(void)
225{
226 uint32_t product_cut, product, cut;
227 uint32_t boot_dev, boot_cpu;
228 uint32_t lcs, reg, val;
229
230 reg = mmio_read_32(RCAR_MODEMR);
231 boot_dev = reg & MODEMR_BOOT_DEV_MASK;
232
233 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
234 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8)
235 emmc_terminate();
236
237 if ((reg & MODEMR_BOOT_CPU_MASK) != MODEMR_BOOT_CPU_CR7)
238 bl2_secure_setting();
239
240 reg = mmio_read_32(RCAR_PRR);
241 product_cut = reg & (RCAR_PRODUCT_MASK | RCAR_CUT_MASK);
242 product = reg & RCAR_PRODUCT_MASK;
243 cut = reg & RCAR_CUT_MASK;
244
Marek Vasut3af20052019-02-25 14:57:08 +0100245 if (product == RCAR_PRODUCT_M3 && RCAR_CUT_VER30 > cut)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200246 goto tlb;
247
248 if (product == RCAR_PRODUCT_H3 && RCAR_CUT_VER20 > cut)
249 goto tlb;
250
Marek Vasut4ae342c2019-01-05 13:56:03 +0100251 if (product == RCAR_PRODUCT_D3)
252 goto tlb;
253
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200254 /* Disable MFIS write protection */
255 mmio_write_32(MFISWPCNTR, MFISWPCNTR_PASSWORD | 1);
256
257tlb:
258 reg = mmio_read_32(RCAR_MODEMR);
259 boot_cpu = reg & MODEMR_BOOT_CPU_MASK;
260 if (boot_cpu != MODEMR_BOOT_CPU_CA57 &&
261 boot_cpu != MODEMR_BOOT_CPU_CA53)
262 goto mmu;
263
264 if (product_cut == RCAR_PRODUCT_H3_CUT20) {
265 mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE);
266 mmio_write_32(IPMMUVI1_IMSCTLR, IMSCTLR_DISCACHE);
267 mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE);
268 mmio_write_32(IPMMUPV1_IMSCTLR, IMSCTLR_DISCACHE);
269 mmio_write_32(IPMMUPV2_IMSCTLR, IMSCTLR_DISCACHE);
270 mmio_write_32(IPMMUPV3_IMSCTLR, IMSCTLR_DISCACHE);
271 } else if (product_cut == (RCAR_PRODUCT_M3N | RCAR_CUT_VER10) ||
272 product_cut == (RCAR_PRODUCT_M3N | RCAR_CUT_VER11)) {
273 mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE);
274 mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE);
Marek Vasut87613d12018-12-28 20:11:38 +0100275 } else if ((product_cut == (RCAR_PRODUCT_E3 | RCAR_CUT_VER10)) ||
276 (product_cut == (RCAR_PRODUCT_E3 | RCAR_CUT_VER11))) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200277 mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE);
Marek Vasute6208012018-12-31 16:48:04 +0100278 mmio_write_32(IPMMUVP0_IMSCTLR, IMSCTLR_DISCACHE);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200279 mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE);
280 }
281
282 if (product_cut == (RCAR_PRODUCT_H3_CUT20) ||
283 product_cut == (RCAR_PRODUCT_M3N | RCAR_CUT_VER10) ||
284 product_cut == (RCAR_PRODUCT_M3N | RCAR_CUT_VER11) ||
285 product_cut == (RCAR_PRODUCT_E3 | RCAR_CUT_VER10)) {
286 mmio_write_32(IPMMUHC_IMSCTLR, IMSCTLR_DISCACHE);
287 mmio_write_32(IPMMURT_IMSCTLR, IMSCTLR_DISCACHE);
288 mmio_write_32(IPMMUMP_IMSCTLR, IMSCTLR_DISCACHE);
289
290 mmio_write_32(IPMMUDS0_IMSCTLR, IMSCTLR_DISCACHE);
291 mmio_write_32(IPMMUDS1_IMSCTLR, IMSCTLR_DISCACHE);
292 }
293
294mmu:
295 mmio_write_32(IPMMUMM_IMSCTLR, IPMMUMM_IMSCTLR_ENABLE);
296 mmio_write_32(IPMMUMM_IMAUXCTLR, IPMMUMM_IMAUXCTLR_NMERGE40_BIT);
297
298 val = rcar_rom_get_lcs(&lcs);
299 if (val) {
300 ERROR("BL2: Failed to get the LCS. (%d)\n", val);
301 panic();
302 }
303
304 if (lcs == LCS_SE)
305 mmio_clrbits_32(P_ARMREG_SEC_CTRL, P_ARMREG_SEC_CTRL_PROT);
306
307 rcar_swdt_release();
308 bl2_system_cpg_init();
309
310#if RCAR_BL2_DCACHE == 1
311 /* Disable data cache (clean and invalidate) */
312 disable_mmu_el3();
313#endif
314}
315
316static uint32_t is_ddr_backup_mode(void)
317{
318#if RCAR_SYSTEM_SUSPEND
319 static uint32_t reason = RCAR_COLD_BOOT;
320 static uint32_t once;
321
322#if PMIC_ROHM_BD9571 && RCAR_SYSTEM_RESET_KEEPON_DDR
323 uint8_t data;
324#endif
325 if (once)
326 return reason;
327
328 once = 1;
329 if ((mmio_read_32(GPIO_INDT) & GPIO_BKUP_TRG_SHIFT) == 0)
330 return reason;
331
332#if PMIC_ROHM_BD9571 && RCAR_SYSTEM_RESET_KEEPON_DDR
333 if (rcar_iic_dvfs_receive(PMIC, REG_KEEP10, &data)) {
334 ERROR("BL2: REG Keep10 READ ERROR.\n");
335 panic();
336 }
337
338 if (KEEP10_MAGIC != data)
339 reason = RCAR_WARM_BOOT;
340#else
341 reason = RCAR_WARM_BOOT;
342#endif
343 return reason;
344#else
345 return RCAR_COLD_BOOT;
346#endif
347}
348
349int bl2_plat_handle_pre_image_load(unsigned int image_id)
350{
351 u_register_t *boot_kind = (void *) BOOT_KIND_BASE;
352 bl_mem_params_node_t *bl_mem_params;
353
354 if (image_id != BL31_IMAGE_ID)
355 return 0;
356
357 bl_mem_params = get_bl_mem_params_node(image_id);
358
359 if (is_ddr_backup_mode() == RCAR_COLD_BOOT)
360 goto cold_boot;
361
362 *boot_kind = RCAR_WARM_BOOT;
363 flush_dcache_range(BOOT_KIND_BASE, sizeof(*boot_kind));
364
365 console_flush();
366 bl2_plat_flush_bl31_params();
367
368 /* will not return */
369 bl2_enter_bl31(&bl_mem_params->ep_info);
370
371cold_boot:
372 *boot_kind = RCAR_COLD_BOOT;
373 flush_dcache_range(BOOT_KIND_BASE, sizeof(*boot_kind));
374
375 return 0;
376}
377
378int bl2_plat_handle_post_image_load(unsigned int image_id)
379{
380 static bl2_to_bl31_params_mem_t *params;
381 bl_mem_params_node_t *bl_mem_params;
382
383 if (!params) {
384 params = (bl2_to_bl31_params_mem_t *) PARAMS_BASE;
385 memset((void *)PARAMS_BASE, 0, sizeof(*params));
386 }
387
388 bl_mem_params = get_bl_mem_params_node(image_id);
389
390 switch (image_id) {
391 case BL31_IMAGE_ID:
392 break;
393 case BL32_IMAGE_ID:
394 memcpy(&params->bl32_ep_info, &bl_mem_params->ep_info,
395 sizeof(entry_point_info_t));
396 break;
397 case BL33_IMAGE_ID:
398 memcpy(&params->bl33_ep_info, &bl_mem_params->ep_info,
399 sizeof(entry_point_info_t));
400 break;
401 }
402
403 return 0;
404}
405
Marek Vasutc7077c62018-12-26 15:57:08 +0100406struct meminfo *bl2_plat_sec_mem_layout(void)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200407{
408 return &bl2_tzram_layout;
409}
410
Marek Vasuta987b002018-10-11 16:15:41 +0200411static void bl2_populate_compatible_string(void *fdt)
412{
413 uint32_t board_type;
414 uint32_t board_rev;
415 uint32_t reg;
416 int ret;
417
418 /* Populate compatible string */
419 rcar_get_board_type(&board_type, &board_rev);
420 switch (board_type) {
421 case BOARD_SALVATOR_X:
422 ret = fdt_setprop_string(fdt, 0, "compatible",
423 "renesas,salvator-x");
424 break;
425 case BOARD_SALVATOR_XS:
426 ret = fdt_setprop_string(fdt, 0, "compatible",
427 "renesas,salvator-xs");
428 break;
429 case BOARD_STARTER_KIT:
430 ret = fdt_setprop_string(fdt, 0, "compatible",
431 "renesas,m3ulcb");
432 break;
433 case BOARD_STARTER_KIT_PRE:
434 ret = fdt_setprop_string(fdt, 0, "compatible",
435 "renesas,h3ulcb");
436 break;
Valentine Barshakf2184142018-10-30 02:06:17 +0300437 case BOARD_EAGLE:
438 ret = fdt_setprop_string(fdt, 0, "compatible",
439 "renesas,eagle");
440 break;
Marek Vasuta987b002018-10-11 16:15:41 +0200441 case BOARD_EBISU:
442 case BOARD_EBISU_4D:
443 ret = fdt_setprop_string(fdt, 0, "compatible",
444 "renesas,ebisu");
445 break;
Marek Vasut4ae342c2019-01-05 13:56:03 +0100446 case BOARD_DRAAK:
447 ret = fdt_setprop_string(fdt, 0, "compatible",
448 "renesas,draak");
449 break;
Marek Vasuta987b002018-10-11 16:15:41 +0200450 default:
451 NOTICE("BL2: Cannot set compatible string, board unsupported\n");
452 panic();
453 }
454
455 if (ret < 0) {
456 NOTICE("BL2: Cannot set compatible string (ret=%i)\n", ret);
457 panic();
458 }
459
460 reg = mmio_read_32(RCAR_PRR);
461 switch (reg & RCAR_PRODUCT_MASK) {
462 case RCAR_PRODUCT_H3:
463 ret = fdt_appendprop_string(fdt, 0, "compatible",
464 "renesas,r8a7795");
465 break;
466 case RCAR_PRODUCT_M3:
467 ret = fdt_appendprop_string(fdt, 0, "compatible",
468 "renesas,r8a7796");
469 break;
470 case RCAR_PRODUCT_M3N:
471 ret = fdt_appendprop_string(fdt, 0, "compatible",
472 "renesas,r8a77965");
473 break;
Valentine Barshakf2184142018-10-30 02:06:17 +0300474 case RCAR_PRODUCT_V3M:
475 ret = fdt_appendprop_string(fdt, 0, "compatible",
476 "renesas,r8a77970");
477 break;
Marek Vasuta987b002018-10-11 16:15:41 +0200478 case RCAR_PRODUCT_E3:
479 ret = fdt_appendprop_string(fdt, 0, "compatible",
480 "renesas,r8a77990");
481 break;
Marek Vasut4ae342c2019-01-05 13:56:03 +0100482 case RCAR_PRODUCT_D3:
483 ret = fdt_appendprop_string(fdt, 0, "compatible",
484 "renesas,r8a77995");
485 break;
Marek Vasuta987b002018-10-11 16:15:41 +0200486 default:
487 NOTICE("BL2: Cannot set compatible string, SoC unsupported\n");
488 panic();
489 }
490
491 if (ret < 0) {
492 NOTICE("BL2: Cannot set compatible string (ret=%i)\n", ret);
493 panic();
494 }
495}
496
Marek Vasut6a6881a2018-10-02 20:43:09 +0200497static void bl2_advertise_dram_entries(uint64_t dram_config[8])
498{
Marek Vasut93c85fc2018-10-02 20:45:18 +0200499 char nodename[32] = { 0 };
Marek Vasut6a6881a2018-10-02 20:43:09 +0200500 uint64_t start, size;
Marek Vasut93c85fc2018-10-02 20:45:18 +0200501 uint64_t fdtsize;
502 int ret, node, chan;
Marek Vasut6a6881a2018-10-02 20:43:09 +0200503
504 for (chan = 0; chan < 4; chan++) {
505 start = dram_config[2 * chan];
506 size = dram_config[2 * chan + 1];
507 if (!size)
508 continue;
509
Marek Vasut89c17512019-03-30 04:01:41 +0100510 NOTICE("BL2: CH%d: %llx - %llx, %lld %siB\n",
511 chan, start, start + size - 1,
512 (size >> 30) ? : size >> 20,
513 (size >> 30) ? "G" : "M");
Marek Vasut6a6881a2018-10-02 20:43:09 +0200514 }
Marek Vasut93c85fc2018-10-02 20:45:18 +0200515
516 /*
517 * We add the DT nodes in reverse order here. The fdt_add_subnode()
518 * adds the DT node before the first existing DT node, so we have
519 * to add them in reverse order to get nodes sorted by address in
520 * the resulting DT.
521 */
522 for (chan = 3; chan >= 0; chan--) {
523 start = dram_config[2 * chan];
524 size = dram_config[2 * chan + 1];
525 if (!size)
526 continue;
527
528 /*
529 * Channel 0 is mapped in 32bit space and the first
530 * 128 MiB are reserved
531 */
532 if (chan == 0) {
533 start = 0x48000000;
534 size -= 0x8000000;
535 }
536
537 fdtsize = cpu_to_fdt64(size);
538
539 snprintf(nodename, sizeof(nodename), "memory@");
540 unsigned_num_print(start, 16, nodename + strlen(nodename));
541 node = ret = fdt_add_subnode(fdt, 0, nodename);
542 if (ret < 0)
543 goto err;
544
545 ret = fdt_setprop_string(fdt, node, "device_type", "memory");
546 if (ret < 0)
547 goto err;
548
549 ret = fdt_setprop_u64(fdt, node, "reg", start);
550 if (ret < 0)
551 goto err;
552
553 ret = fdt_appendprop(fdt, node, "reg", &fdtsize,
554 sizeof(fdtsize));
555 if (ret < 0)
556 goto err;
557 }
558
559 return;
560err:
561 NOTICE("BL2: Cannot add memory node to FDT (ret=%i)\n", ret);
562 panic();
Marek Vasut6a6881a2018-10-02 20:43:09 +0200563}
564
Marek Vasutb0e13592018-10-02 14:53:27 +0200565static void bl2_advertise_dram_size(uint32_t product)
Marek Vasut673bc322018-10-02 13:33:32 +0200566{
Marek Vasut6a6881a2018-10-02 20:43:09 +0200567 uint64_t dram_config[8] = {
568 [0] = 0x400000000ULL,
569 [2] = 0x500000000ULL,
570 [4] = 0x600000000ULL,
571 [6] = 0x700000000ULL,
572 };
573
Marek Vasut9963f702018-10-02 15:09:04 +0200574 switch (product) {
575 case RCAR_PRODUCT_H3:
Marek Vasut673bc322018-10-02 13:33:32 +0200576#if (RCAR_DRAM_LPDDR4_MEMCONF == 0)
577 /* 4GB(1GBx4) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200578 dram_config[1] = 0x40000000ULL;
579 dram_config[3] = 0x40000000ULL;
580 dram_config[5] = 0x40000000ULL;
581 dram_config[7] = 0x40000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200582#elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && \
583 (RCAR_DRAM_CHANNEL == 5) && \
584 (RCAR_DRAM_SPLIT == 2)
585 /* 4GB(2GBx2 2ch split) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200586 dram_config[1] = 0x80000000ULL;
587 dram_config[3] = 0x80000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200588#elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && (RCAR_DRAM_CHANNEL == 15)
589 /* 8GB(2GBx4: default) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200590 dram_config[1] = 0x80000000ULL;
591 dram_config[3] = 0x80000000ULL;
592 dram_config[5] = 0x80000000ULL;
593 dram_config[7] = 0x80000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200594#endif /* RCAR_DRAM_LPDDR4_MEMCONF == 0 */
Marek Vasut9963f702018-10-02 15:09:04 +0200595 break;
Marek Vasut673bc322018-10-02 13:33:32 +0200596
Marek Vasut9963f702018-10-02 15:09:04 +0200597 case RCAR_PRODUCT_M3:
Marek Vasut0208c942019-03-09 16:10:59 +0100598#if (RCAR_GEN3_ULCB == 1)
599 /* 2GB(1GBx2 2ch split) */
600 dram_config[1] = 0x40000000ULL;
601 dram_config[5] = 0x40000000ULL;
602#else
Marek Vasut9963f702018-10-02 15:09:04 +0200603 /* 4GB(2GBx2 2ch split) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200604 dram_config[1] = 0x80000000ULL;
605 dram_config[5] = 0x80000000ULL;
Marek Vasut0208c942019-03-09 16:10:59 +0100606#endif
Marek Vasut9963f702018-10-02 15:09:04 +0200607 break;
608
609 case RCAR_PRODUCT_M3N:
610 /* 2GB(1GBx2) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200611 dram_config[1] = 0x80000000ULL;
Marek Vasut9963f702018-10-02 15:09:04 +0200612 break;
613
Valentine Barshakf2184142018-10-30 02:06:17 +0300614 case RCAR_PRODUCT_V3M:
615 /* 1GB(512MBx2) */
616 dram_config[1] = 0x40000000ULL;
617 break;
618
Marek Vasut9963f702018-10-02 15:09:04 +0200619 case RCAR_PRODUCT_E3:
Marek Vasut673bc322018-10-02 13:33:32 +0200620#if (RCAR_DRAM_DDR3L_MEMCONF == 0)
621 /* 1GB(512MBx2) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200622 dram_config[1] = 0x40000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200623#elif (RCAR_DRAM_DDR3L_MEMCONF == 1)
624 /* 2GB(512MBx4) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200625 dram_config[1] = 0x80000000ULL;
Marek Vasut8cb12ec2018-10-02 13:51:19 +0200626#elif (RCAR_DRAM_DDR3L_MEMCONF == 2)
627 /* 4GB(1GBx4) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200628 dram_config[1] = 0x100000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200629#endif /* RCAR_DRAM_DDR3L_MEMCONF == 0 */
Marek Vasut9963f702018-10-02 15:09:04 +0200630 break;
Marek Vasut4ae342c2019-01-05 13:56:03 +0100631
632 case RCAR_PRODUCT_D3:
633 /* 512MB */
634 dram_config[1] = 0x20000000ULL;
635 break;
Marek Vasut673bc322018-10-02 13:33:32 +0200636 }
Marek Vasut6a6881a2018-10-02 20:43:09 +0200637
638 bl2_advertise_dram_entries(dram_config);
Marek Vasut673bc322018-10-02 13:33:32 +0200639}
640
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200641void bl2_el3_early_platform_setup(u_register_t arg1, u_register_t arg2,
642 u_register_t arg3, u_register_t arg4)
643{
644 uint32_t reg, midr, lcs, boot_dev, boot_cpu, sscg, type, rev;
Marek Vasutb0e13592018-10-02 14:53:27 +0200645 uint32_t product, product_cut, major, minor;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200646 int32_t ret;
647 const char *str;
648 const char *unknown = "unknown";
649 const char *cpu_ca57 = "CA57";
650 const char *cpu_ca53 = "CA53";
651 const char *product_m3n = "M3N";
652 const char *product_h3 = "H3";
653 const char *product_m3 = "M3";
654 const char *product_e3 = "E3";
Marek Vasut4ae342c2019-01-05 13:56:03 +0100655 const char *product_d3 = "D3";
Valentine Barshakf2184142018-10-30 02:06:17 +0300656 const char *product_v3m = "V3M";
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200657 const char *lcs_secure = "SE";
658 const char *lcs_cm = "CM";
659 const char *lcs_dm = "DM";
660 const char *lcs_sd = "SD";
661 const char *lcs_fa = "FA";
662 const char *sscg_off = "PLL1 nonSSCG Clock select";
663 const char *sscg_on = "PLL1 SSCG Clock select";
664 const char *boot_hyper80 = "HyperFlash(80MHz)";
665 const char *boot_qspi40 = "QSPI Flash(40MHz)";
666 const char *boot_qspi80 = "QSPI Flash(80MHz)";
667 const char *boot_emmc25x1 = "eMMC(25MHz x1)";
668 const char *boot_emmc50x8 = "eMMC(50MHz x8)";
Marek Vasut4ae342c2019-01-05 13:56:03 +0100669#if (RCAR_LSI == RCAR_E3) || (RCAR_LSI == RCAR_D3)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200670 const char *boot_hyper160 = "HyperFlash(150MHz)";
671#else
672 const char *boot_hyper160 = "HyperFlash(160MHz)";
673#endif
Marek Vasut4d693c22018-10-11 16:53:58 +0200674#if (RCAR_LOSSY_ENABLE == 1)
675 int fcnlnode;
676#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200677
Marek Vasut1eca7782018-12-28 20:12:13 +0100678 bl2_init_generic_timer();
679
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200680 reg = mmio_read_32(RCAR_MODEMR);
681 boot_dev = reg & MODEMR_BOOT_DEV_MASK;
682 boot_cpu = reg & MODEMR_BOOT_CPU_MASK;
683
684 bl2_cpg_init();
685
686 if (boot_cpu == MODEMR_BOOT_CPU_CA57 ||
687 boot_cpu == MODEMR_BOOT_CPU_CA53) {
688 rcar_pfc_init();
689 /* console configuration (platform specific) done in driver */
690 console_init(0, 0, 0);
691 }
692
693 plat_rcar_gic_driver_init();
694 plat_rcar_gic_init();
695 rcar_swdt_init();
696
697 /* FIQ interrupts are taken to EL3 */
698 write_scr_el3(read_scr_el3() | SCR_FIQ_BIT);
699
700 write_daifclr(DAIF_FIQ_BIT);
701
702 reg = read_midr();
703 midr = reg & (MIDR_PN_MASK << MIDR_PN_SHIFT);
704 switch (midr) {
705 case MIDR_CA57:
706 str = cpu_ca57;
707 break;
708 case MIDR_CA53:
709 str = cpu_ca53;
710 break;
711 default:
712 str = unknown;
713 break;
714 }
715
716 NOTICE("BL2: R-Car Gen3 Initial Program Loader(%s) Rev.%s\n", str,
717 version_of_renesas);
718
719 reg = mmio_read_32(RCAR_PRR);
720 product_cut = reg & (RCAR_PRODUCT_MASK | RCAR_CUT_MASK);
721 product = reg & RCAR_PRODUCT_MASK;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200722
723 switch (product) {
724 case RCAR_PRODUCT_H3:
725 str = product_h3;
726 break;
727 case RCAR_PRODUCT_M3:
728 str = product_m3;
729 break;
730 case RCAR_PRODUCT_M3N:
731 str = product_m3n;
732 break;
Valentine Barshakf2184142018-10-30 02:06:17 +0300733 case RCAR_PRODUCT_V3M:
734 str = product_v3m;
735 break;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200736 case RCAR_PRODUCT_E3:
737 str = product_e3;
738 break;
Marek Vasut4ae342c2019-01-05 13:56:03 +0100739 case RCAR_PRODUCT_D3:
740 str = product_d3;
741 break;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200742 default:
743 str = unknown;
744 break;
745 }
746
Marek Vasut3af20052019-02-25 14:57:08 +0100747 if ((RCAR_PRODUCT_M3 == product) &&
748 (RCAR_CUT_VER20 == (reg & RCAR_MAJOR_MASK))) {
749 if (RCAR_M3_CUT_VER11 == (reg & RCAR_CUT_MASK)) {
750 /* M3 Ver.1.1 or Ver.1.2 */
751 NOTICE("BL2: PRR is R-Car %s Ver.1.1 / Ver.1.2\n",
752 str);
753 } else {
754 NOTICE("BL2: PRR is R-Car %s Ver.1.%d\n",
755 str,
756 (reg & RCAR_MINOR_MASK) + RCAR_M3_MINOR_OFFSET);
757 }
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200758 } else {
759 major = (reg & RCAR_MAJOR_MASK) >> RCAR_MAJOR_SHIFT;
760 major = major + RCAR_MAJOR_OFFSET;
761 minor = reg & RCAR_MINOR_MASK;
762 NOTICE("BL2: PRR is R-Car %s Ver.%d.%d\n", str, major, minor);
763 }
764
765 if (product == RCAR_PRODUCT_E3) {
766 reg = mmio_read_32(RCAR_MODEMR);
767 sscg = reg & RCAR_SSCG_MASK;
768 str = sscg == RCAR_SSCG_ENABLE ? sscg_on : sscg_off;
769 NOTICE("BL2: %s\n", str);
770 }
771
772 rcar_get_board_type(&type, &rev);
773
774 switch (type) {
775 case BOARD_SALVATOR_X:
776 case BOARD_KRIEK:
777 case BOARD_STARTER_KIT:
778 case BOARD_SALVATOR_XS:
779 case BOARD_EBISU:
780 case BOARD_STARTER_KIT_PRE:
781 case BOARD_EBISU_4D:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100782 case BOARD_DRAAK:
Valentine Barshakf2184142018-10-30 02:06:17 +0300783 case BOARD_EAGLE:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200784 break;
785 default:
786 type = BOARD_UNKNOWN;
787 break;
788 }
789
790 if (type == BOARD_UNKNOWN || rev == BOARD_REV_UNKNOWN)
791 NOTICE("BL2: Board is %s Rev.---\n", GET_BOARD_NAME(type));
792 else {
793 NOTICE("BL2: Board is %s Rev.%d.%d\n",
794 GET_BOARD_NAME(type),
795 GET_BOARD_MAJOR(rev), GET_BOARD_MINOR(rev));
796 }
797
798#if RCAR_LSI != RCAR_AUTO
799 if (product != TARGET_PRODUCT) {
800 ERROR("BL2: IPL was been built for the %s.\n", TARGET_NAME);
801 ERROR("BL2: Please write the correct IPL to flash memory.\n");
802 panic();
803 }
804#endif
805 rcar_avs_init();
806 rcar_avs_setting();
807
808 switch (boot_dev) {
809 case MODEMR_BOOT_DEV_HYPERFLASH160:
810 str = boot_hyper160;
811 break;
812 case MODEMR_BOOT_DEV_HYPERFLASH80:
813 str = boot_hyper80;
814 break;
815 case MODEMR_BOOT_DEV_QSPI_FLASH40:
816 str = boot_qspi40;
817 break;
818 case MODEMR_BOOT_DEV_QSPI_FLASH80:
819 str = boot_qspi80;
820 break;
821 case MODEMR_BOOT_DEV_EMMC_25X1:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100822#if RCAR_LSI == RCAR_D3
823 ERROR("BL2: Failed to Initialize. eMMC is not supported.\n");
824 panic();
825#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200826 str = boot_emmc25x1;
827 break;
828 case MODEMR_BOOT_DEV_EMMC_50X8:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100829#if RCAR_LSI == RCAR_D3
830 ERROR("BL2: Failed to Initialize. eMMC is not supported.\n");
831 panic();
832#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200833 str = boot_emmc50x8;
834 break;
835 default:
836 str = unknown;
837 break;
838 }
839 NOTICE("BL2: Boot device is %s\n", str);
840
841 rcar_avs_setting();
842 reg = rcar_rom_get_lcs(&lcs);
843 if (reg) {
844 str = unknown;
845 goto lcm_state;
846 }
847
848 switch (lcs) {
849 case LCS_CM:
850 str = lcs_cm;
851 break;
852 case LCS_DM:
853 str = lcs_dm;
854 break;
855 case LCS_SD:
856 str = lcs_sd;
857 break;
858 case LCS_SE:
859 str = lcs_secure;
860 break;
861 case LCS_FA:
862 str = lcs_fa;
863 break;
864 default:
865 str = unknown;
866 break;
867 }
868
869lcm_state:
870 NOTICE("BL2: LCM state is %s\n", str);
871
872 rcar_avs_end();
873 is_ddr_backup_mode();
874
875 bl2_tzram_layout.total_base = BL31_BASE;
876 bl2_tzram_layout.total_size = BL31_LIMIT - BL31_BASE;
877
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200878 if (boot_cpu == MODEMR_BOOT_CPU_CA57 ||
879 boot_cpu == MODEMR_BOOT_CPU_CA53) {
880 ret = rcar_dram_init();
881 if (ret) {
882 NOTICE("BL2: Failed to DRAM initialize (%d).\n", ret);
883 panic();
884 }
885 rcar_qos_init();
886 }
887
Marek Vasut93c85fc2018-10-02 20:45:18 +0200888 /* Set up FDT */
889 ret = fdt_create_empty_tree(fdt, sizeof(fdt_blob));
890 if (ret) {
891 NOTICE("BL2: Cannot allocate FDT for U-Boot (ret=%i)\n", ret);
892 panic();
893 }
894
Marek Vasuta987b002018-10-11 16:15:41 +0200895 /* Add platform compatible string */
896 bl2_populate_compatible_string(fdt);
897
Marek Vasut63659fd2018-10-02 15:12:15 +0200898 /* Print DRAM layout */
899 bl2_advertise_dram_size(product);
900
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200901 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
902 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8) {
903 if (rcar_emmc_init() != EMMC_SUCCESS) {
904 NOTICE("BL2: Failed to eMMC driver initialize.\n");
905 panic();
906 }
907 rcar_emmc_memcard_power(EMMC_POWER_ON);
908 if (rcar_emmc_mount() != EMMC_SUCCESS) {
909 NOTICE("BL2: Failed to eMMC mount operation.\n");
910 panic();
911 }
912 } else {
913 rcar_rpc_init();
914 rcar_dma_init();
915 }
916
917 reg = mmio_read_32(RST_WDTRSTCR);
918 reg &= ~WDTRSTCR_RWDT_RSTMSK;
919 reg |= WDTRSTCR_PASSWORD;
920 mmio_write_32(RST_WDTRSTCR, reg);
921
922 mmio_write_32(CPG_CPGWPR, CPGWPR_PASSWORD);
923 mmio_write_32(CPG_CPGWPCR, CPGWPCR_PASSWORD);
924
925 reg = mmio_read_32(RCAR_PRR);
926 if ((reg & RCAR_CPU_MASK_CA57) == RCAR_CPU_HAVE_CA57)
927 mmio_write_32(CPG_CA57DBGRCR,
928 DBGCPUPREN | mmio_read_32(CPG_CA57DBGRCR));
929
930 if ((reg & RCAR_CPU_MASK_CA53) == RCAR_CPU_HAVE_CA53)
931 mmio_write_32(CPG_CA53DBGRCR,
932 DBGCPUPREN | mmio_read_32(CPG_CA53DBGRCR));
933
934 if (product_cut == RCAR_PRODUCT_H3_CUT10) {
935 reg = mmio_read_32(CPG_PLL2CR);
936 reg &= ~((uint32_t) 1 << 5);
937 mmio_write_32(CPG_PLL2CR, reg);
938
939 reg = mmio_read_32(CPG_PLL4CR);
940 reg &= ~((uint32_t) 1 << 5);
941 mmio_write_32(CPG_PLL4CR, reg);
942
943 reg = mmio_read_32(CPG_PLL0CR);
944 reg &= ~((uint32_t) 1 << 12);
945 mmio_write_32(CPG_PLL0CR, reg);
946 }
947#if (RCAR_LOSSY_ENABLE == 1)
948 NOTICE("BL2: Lossy Decomp areas\n");
Marek Vasut4d693c22018-10-11 16:53:58 +0200949
950 fcnlnode = fdt_add_subnode(fdt, 0, "reserved-memory");
951 if (fcnlnode < 0) {
952 NOTICE("BL2: Cannot create reserved mem node (ret=%i)\n",
953 fcnlnode);
954 panic();
955 }
956
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200957 bl2_lossy_setting(0, LOSSY_ST_ADDR0, LOSSY_END_ADDR0,
Marek Vasut4d693c22018-10-11 16:53:58 +0200958 LOSSY_FMT0, LOSSY_ENA_DIS0, fcnlnode);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200959 bl2_lossy_setting(1, LOSSY_ST_ADDR1, LOSSY_END_ADDR1,
Marek Vasut4d693c22018-10-11 16:53:58 +0200960 LOSSY_FMT1, LOSSY_ENA_DIS1, fcnlnode);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200961 bl2_lossy_setting(2, LOSSY_ST_ADDR2, LOSSY_END_ADDR2,
Marek Vasut4d693c22018-10-11 16:53:58 +0200962 LOSSY_FMT2, LOSSY_ENA_DIS2, fcnlnode);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200963#endif
964
Marek Vasut93c85fc2018-10-02 20:45:18 +0200965 fdt_pack(fdt);
966 NOTICE("BL2: FDT at %p\n", fdt);
967
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200968 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
969 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8)
970 rcar_io_emmc_setup();
971 else
972 rcar_io_setup();
973}
974
975void bl2_el3_plat_arch_setup(void)
976{
977#if RCAR_BL2_DCACHE == 1
978 NOTICE("BL2: D-Cache enable\n");
979 rcar_configure_mmu_el3(BL2_BASE,
Marek Vasut2e032c02018-12-26 15:57:08 +0100980 BL2_END - BL2_BASE,
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200981 BL2_RO_BASE, BL2_RO_LIMIT
982#if USE_COHERENT_MEM
983 , BL2_COHERENT_RAM_BASE, BL2_COHERENT_RAM_LIMIT
984#endif
985 );
986#endif
987}
988
989void bl2_platform_setup(void)
990{
991
992}
Marek Vasut1eca7782018-12-28 20:12:13 +0100993
994static void bl2_init_generic_timer(void)
995{
Valentine Barshakf2184142018-10-30 02:06:17 +0300996/* FIXME: V3M 16.666 MHz ? */
Marek Vasut4ae342c2019-01-05 13:56:03 +0100997#if RCAR_LSI == RCAR_D3
998 uint32_t reg_cntfid = EXTAL_DRAAK;
999#elif RCAR_LSI == RCAR_E3
Marek Vasut1eca7782018-12-28 20:12:13 +01001000 uint32_t reg_cntfid = EXTAL_EBISU;
1001#else /* RCAR_LSI == RCAR_E3 */
1002 uint32_t reg;
1003 uint32_t reg_cntfid;
1004 uint32_t modemr;
1005 uint32_t modemr_pll;
1006 uint32_t board_type;
1007 uint32_t board_rev;
1008 uint32_t pll_table[] = {
1009 EXTAL_MD14_MD13_TYPE_0, /* MD14/MD13 : 0b00 */
1010 EXTAL_MD14_MD13_TYPE_1, /* MD14/MD13 : 0b01 */
1011 EXTAL_MD14_MD13_TYPE_2, /* MD14/MD13 : 0b10 */
1012 EXTAL_MD14_MD13_TYPE_3 /* MD14/MD13 : 0b11 */
1013 };
1014
1015 modemr = mmio_read_32(RCAR_MODEMR);
1016 modemr_pll = (modemr & MODEMR_BOOT_PLL_MASK);
1017
1018 /* Set frequency data in CNTFID0 */
1019 reg_cntfid = pll_table[modemr_pll >> MODEMR_BOOT_PLL_SHIFT];
1020 reg = mmio_read_32(RCAR_PRR) & (RCAR_PRODUCT_MASK | RCAR_CUT_MASK);
1021 switch (modemr_pll) {
1022 case MD14_MD13_TYPE_0:
1023 rcar_get_board_type(&board_type, &board_rev);
1024 if (BOARD_SALVATOR_XS == board_type) {
1025 reg_cntfid = EXTAL_SALVATOR_XS;
1026 }
1027 break;
1028 case MD14_MD13_TYPE_3:
1029 if (RCAR_PRODUCT_H3_CUT10 == reg) {
1030 reg_cntfid = reg_cntfid >> 1U;
1031 }
1032 break;
1033 default:
1034 /* none */
1035 break;
1036 }
1037#endif /* RCAR_LSI == RCAR_E3 */
1038 /* Update memory mapped and register based freqency */
1039 write_cntfrq_el0((u_register_t )reg_cntfid);
1040 mmio_write_32(ARM_SYS_CNTCTL_BASE + (uintptr_t)CNTFID_OFF, reg_cntfid);
1041 /* Enable counter */
1042 mmio_setbits_32(RCAR_CNTC_BASE + (uintptr_t)CNTCR_OFF,
1043 (uint32_t)CNTCR_EN);
1044}