blob: 75b9b900a4c64447adbff6a19524ff420a33d8bb [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
7#include <desc_image_load.h>
8#include <arch_helpers.h>
9#include <bl_common.h>
10#include <bl1.h>
11#include <console.h>
12#include <debug.h>
13#include <mmio.h>
14#include <platform.h>
15#include <platform_def.h>
16#include <string.h>
17
18#include "avs_driver.h"
19#include "boot_init_dram.h"
20#include "cpg_registers.h"
21#include "board.h"
22#include "emmc_def.h"
23#include "emmc_hal.h"
24#include "emmc_std.h"
25
26#if PMIC_ROHM_BD9571 && RCAR_SYSTEM_RESET_KEEPON_DDR
27#include "iic_dvfs.h"
28#endif
29
30#include "io_common.h"
31#include "qos_init.h"
32#include "rcar_def.h"
33#include "rcar_private.h"
34#include "rcar_version.h"
35#include "rom_api.h"
36
37IMPORT_SYM(unsigned long, __RO_START__, BL2_RO_BASE)
38IMPORT_SYM(unsigned long, __RO_END__, BL2_RO_LIMIT)
39
40#if USE_COHERENT_MEM
41IMPORT_SYM(unsigned long, __COHERENT_RAM_START__, BL2_COHERENT_RAM_BASE)
42IMPORT_SYM(unsigned long, __COHERENT_RAM_END__, BL2_COHERENT_RAM_LIMIT)
43#endif
44
45extern void plat_rcar_gic_driver_init(void);
46extern void plat_rcar_gic_init(void);
47extern void bl2_enter_bl31(const struct entry_point_info *bl_ep_info);
48extern void bl2_system_cpg_init(void);
49extern void bl2_secure_setting(void);
50extern void bl2_cpg_init(void);
51extern void rcar_io_emmc_setup(void);
52extern void rcar_io_setup(void);
53extern void rcar_swdt_release(void);
54extern void rcar_swdt_init(void);
55extern void rcar_rpc_init(void);
56extern void rcar_pfc_init(void);
57extern void rcar_dma_init(void);
58
59/* R-Car Gen3 product check */
60#if (RCAR_LSI == RCAR_H3) || (RCAR_LSI == RCAR_H3N)
61#define TARGET_PRODUCT RCAR_PRODUCT_H3
62#define TARGET_NAME "R-Car H3"
63#elif RCAR_LSI == RCAR_M3
64#define TARGET_PRODUCT RCAR_PRODUCT_M3
65#define TARGET_NAME "R-Car M3"
66#elif RCAR_LSI == RCAR_M3N
67#define TARGET_PRODUCT RCAR_PRODUCT_M3N
68#define TARGET_NAME "R-Car M3N"
69#elif RCAR_LSI == RCAR_E3
70#define TARGET_PRODUCT RCAR_PRODUCT_E3
71#define TARGET_NAME "R-Car E3"
72#endif
73
74#if (RCAR_LSI == RCAR_E3)
75#define GPIO_INDT (GPIO_INDT6)
76#define GPIO_BKUP_TRG_SHIFT ((uint32_t)1U<<13U)
77#else
78#define GPIO_INDT (GPIO_INDT1)
79#define GPIO_BKUP_TRG_SHIFT ((uint32_t)1U<<8U)
80#endif
81
82CASSERT((PARAMS_BASE + sizeof(bl2_to_bl31_params_mem_t) + 0x100)
83 < (RCAR_SHARED_MEM_BASE + RCAR_SHARED_MEM_SIZE),
84 assert_bl31_params_do_not_fit_in_shared_memory);
85
86static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
87
88#if (RCAR_LOSSY_ENABLE == 1)
89typedef struct bl2_lossy_info {
90 uint32_t magic;
91 uint32_t a0;
92 uint32_t b0;
93} bl2_lossy_info_t;
94
95static void bl2_lossy_setting(uint32_t no, uint64_t start_addr,
96 uint64_t end_addr, uint32_t format,
97 uint32_t enable)
98{
99 bl2_lossy_info_t info;
100 uint32_t reg;
101
102 reg = format | (start_addr >> 20);
103 mmio_write_32(AXI_DCMPAREACRA0 + 0x8 * no, reg);
104 mmio_write_32(AXI_DCMPAREACRB0 + 0x8 * no, end_addr >> 20);
105 mmio_write_32(AXI_DCMPAREACRA0 + 0x8 * no, reg | enable);
106
107 info.magic = 0x12345678U;
108 info.a0 = mmio_read_32(AXI_DCMPAREACRA0 + 0x8 * no);
109 info.b0 = mmio_read_32(AXI_DCMPAREACRB0 + 0x8 * no);
110
111 mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no, info.magic);
112 mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no + 0x4, info.a0);
113 mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no + 0x8, info.b0);
114
115 NOTICE(" Entry %d: DCMPAREACRAx:0x%x DCMPAREACRBx:0x%x\n", no,
116 mmio_read_32(AXI_DCMPAREACRA0 + 0x8 * no),
117 mmio_read_32(AXI_DCMPAREACRB0 + 0x8 * no));
118}
119#endif
120
121void bl2_plat_flush_bl31_params(void)
122{
123 uint32_t product_cut, product, cut;
124 uint32_t boot_dev, boot_cpu;
125 uint32_t lcs, reg, val;
126
127 reg = mmio_read_32(RCAR_MODEMR);
128 boot_dev = reg & MODEMR_BOOT_DEV_MASK;
129
130 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
131 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8)
132 emmc_terminate();
133
134 if ((reg & MODEMR_BOOT_CPU_MASK) != MODEMR_BOOT_CPU_CR7)
135 bl2_secure_setting();
136
137 reg = mmio_read_32(RCAR_PRR);
138 product_cut = reg & (RCAR_PRODUCT_MASK | RCAR_CUT_MASK);
139 product = reg & RCAR_PRODUCT_MASK;
140 cut = reg & RCAR_CUT_MASK;
141
142 if (product == RCAR_PRODUCT_M3)
143 goto tlb;
144
145 if (product == RCAR_PRODUCT_H3 && RCAR_CUT_VER20 > cut)
146 goto tlb;
147
148 /* Disable MFIS write protection */
149 mmio_write_32(MFISWPCNTR, MFISWPCNTR_PASSWORD | 1);
150
151tlb:
152 reg = mmio_read_32(RCAR_MODEMR);
153 boot_cpu = reg & MODEMR_BOOT_CPU_MASK;
154 if (boot_cpu != MODEMR_BOOT_CPU_CA57 &&
155 boot_cpu != MODEMR_BOOT_CPU_CA53)
156 goto mmu;
157
158 if (product_cut == RCAR_PRODUCT_H3_CUT20) {
159 mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE);
160 mmio_write_32(IPMMUVI1_IMSCTLR, IMSCTLR_DISCACHE);
161 mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE);
162 mmio_write_32(IPMMUPV1_IMSCTLR, IMSCTLR_DISCACHE);
163 mmio_write_32(IPMMUPV2_IMSCTLR, IMSCTLR_DISCACHE);
164 mmio_write_32(IPMMUPV3_IMSCTLR, IMSCTLR_DISCACHE);
165 } else if (product_cut == (RCAR_PRODUCT_M3N | RCAR_CUT_VER10) ||
166 product_cut == (RCAR_PRODUCT_M3N | RCAR_CUT_VER11)) {
167 mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE);
168 mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE);
169 } else if (product_cut == (RCAR_PRODUCT_E3 | RCAR_CUT_VER10)) {
170 mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE);
171 mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE);
172 }
173
174 if (product_cut == (RCAR_PRODUCT_H3_CUT20) ||
175 product_cut == (RCAR_PRODUCT_M3N | RCAR_CUT_VER10) ||
176 product_cut == (RCAR_PRODUCT_M3N | RCAR_CUT_VER11) ||
177 product_cut == (RCAR_PRODUCT_E3 | RCAR_CUT_VER10)) {
178 mmio_write_32(IPMMUHC_IMSCTLR, IMSCTLR_DISCACHE);
179 mmio_write_32(IPMMURT_IMSCTLR, IMSCTLR_DISCACHE);
180 mmio_write_32(IPMMUMP_IMSCTLR, IMSCTLR_DISCACHE);
181
182 mmio_write_32(IPMMUDS0_IMSCTLR, IMSCTLR_DISCACHE);
183 mmio_write_32(IPMMUDS1_IMSCTLR, IMSCTLR_DISCACHE);
184 }
185
186mmu:
187 mmio_write_32(IPMMUMM_IMSCTLR, IPMMUMM_IMSCTLR_ENABLE);
188 mmio_write_32(IPMMUMM_IMAUXCTLR, IPMMUMM_IMAUXCTLR_NMERGE40_BIT);
189
190 val = rcar_rom_get_lcs(&lcs);
191 if (val) {
192 ERROR("BL2: Failed to get the LCS. (%d)\n", val);
193 panic();
194 }
195
196 if (lcs == LCS_SE)
197 mmio_clrbits_32(P_ARMREG_SEC_CTRL, P_ARMREG_SEC_CTRL_PROT);
198
199 rcar_swdt_release();
200 bl2_system_cpg_init();
201
202#if RCAR_BL2_DCACHE == 1
203 /* Disable data cache (clean and invalidate) */
204 disable_mmu_el3();
205#endif
206}
207
208static uint32_t is_ddr_backup_mode(void)
209{
210#if RCAR_SYSTEM_SUSPEND
211 static uint32_t reason = RCAR_COLD_BOOT;
212 static uint32_t once;
213
214#if PMIC_ROHM_BD9571 && RCAR_SYSTEM_RESET_KEEPON_DDR
215 uint8_t data;
216#endif
217 if (once)
218 return reason;
219
220 once = 1;
221 if ((mmio_read_32(GPIO_INDT) & GPIO_BKUP_TRG_SHIFT) == 0)
222 return reason;
223
224#if PMIC_ROHM_BD9571 && RCAR_SYSTEM_RESET_KEEPON_DDR
225 if (rcar_iic_dvfs_receive(PMIC, REG_KEEP10, &data)) {
226 ERROR("BL2: REG Keep10 READ ERROR.\n");
227 panic();
228 }
229
230 if (KEEP10_MAGIC != data)
231 reason = RCAR_WARM_BOOT;
232#else
233 reason = RCAR_WARM_BOOT;
234#endif
235 return reason;
236#else
237 return RCAR_COLD_BOOT;
238#endif
239}
240
241int bl2_plat_handle_pre_image_load(unsigned int image_id)
242{
243 u_register_t *boot_kind = (void *) BOOT_KIND_BASE;
244 bl_mem_params_node_t *bl_mem_params;
245
246 if (image_id != BL31_IMAGE_ID)
247 return 0;
248
249 bl_mem_params = get_bl_mem_params_node(image_id);
250
251 if (is_ddr_backup_mode() == RCAR_COLD_BOOT)
252 goto cold_boot;
253
254 *boot_kind = RCAR_WARM_BOOT;
255 flush_dcache_range(BOOT_KIND_BASE, sizeof(*boot_kind));
256
257 console_flush();
258 bl2_plat_flush_bl31_params();
259
260 /* will not return */
261 bl2_enter_bl31(&bl_mem_params->ep_info);
262
263cold_boot:
264 *boot_kind = RCAR_COLD_BOOT;
265 flush_dcache_range(BOOT_KIND_BASE, sizeof(*boot_kind));
266
267 return 0;
268}
269
270int bl2_plat_handle_post_image_load(unsigned int image_id)
271{
272 static bl2_to_bl31_params_mem_t *params;
273 bl_mem_params_node_t *bl_mem_params;
274
275 if (!params) {
276 params = (bl2_to_bl31_params_mem_t *) PARAMS_BASE;
277 memset((void *)PARAMS_BASE, 0, sizeof(*params));
278 }
279
280 bl_mem_params = get_bl_mem_params_node(image_id);
281
282 switch (image_id) {
283 case BL31_IMAGE_ID:
284 break;
285 case BL32_IMAGE_ID:
286 memcpy(&params->bl32_ep_info, &bl_mem_params->ep_info,
287 sizeof(entry_point_info_t));
288 break;
289 case BL33_IMAGE_ID:
290 memcpy(&params->bl33_ep_info, &bl_mem_params->ep_info,
291 sizeof(entry_point_info_t));
292 break;
293 }
294
295 return 0;
296}
297
298meminfo_t *bl2_plat_sec_mem_layout(void)
299{
300 return &bl2_tzram_layout;
301}
302
Marek Vasut6a6881a2018-10-02 20:43:09 +0200303static void bl2_advertise_dram_entries(uint64_t dram_config[8])
304{
305 uint64_t start, size;
306 int chan;
307
308 for (chan = 0; chan < 4; chan++) {
309 start = dram_config[2 * chan];
310 size = dram_config[2 * chan + 1];
311 if (!size)
312 continue;
313
314 NOTICE("BL2: CH%d: %llx - %llx, %lld GiB\n",
315 chan, start, start + size - 1, size >> 30);
316 }
317}
318
Marek Vasutb0e13592018-10-02 14:53:27 +0200319static void bl2_advertise_dram_size(uint32_t product)
Marek Vasut673bc322018-10-02 13:33:32 +0200320{
Marek Vasut6a6881a2018-10-02 20:43:09 +0200321 uint64_t dram_config[8] = {
322 [0] = 0x400000000ULL,
323 [2] = 0x500000000ULL,
324 [4] = 0x600000000ULL,
325 [6] = 0x700000000ULL,
326 };
327
Marek Vasut9963f702018-10-02 15:09:04 +0200328 switch (product) {
329 case RCAR_PRODUCT_H3:
Marek Vasut673bc322018-10-02 13:33:32 +0200330#if (RCAR_DRAM_LPDDR4_MEMCONF == 0)
331 /* 4GB(1GBx4) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200332 dram_config[1] = 0x40000000ULL;
333 dram_config[3] = 0x40000000ULL;
334 dram_config[5] = 0x40000000ULL;
335 dram_config[7] = 0x40000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200336#elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && \
337 (RCAR_DRAM_CHANNEL == 5) && \
338 (RCAR_DRAM_SPLIT == 2)
339 /* 4GB(2GBx2 2ch split) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200340 dram_config[1] = 0x80000000ULL;
341 dram_config[3] = 0x80000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200342#elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && (RCAR_DRAM_CHANNEL == 15)
343 /* 8GB(2GBx4: default) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200344 dram_config[1] = 0x80000000ULL;
345 dram_config[3] = 0x80000000ULL;
346 dram_config[5] = 0x80000000ULL;
347 dram_config[7] = 0x80000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200348#endif /* RCAR_DRAM_LPDDR4_MEMCONF == 0 */
Marek Vasut9963f702018-10-02 15:09:04 +0200349 break;
Marek Vasut673bc322018-10-02 13:33:32 +0200350
Marek Vasut9963f702018-10-02 15:09:04 +0200351 case RCAR_PRODUCT_M3:
352 /* 4GB(2GBx2 2ch split) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200353 dram_config[1] = 0x80000000ULL;
354 dram_config[5] = 0x80000000ULL;
Marek Vasut9963f702018-10-02 15:09:04 +0200355 break;
356
357 case RCAR_PRODUCT_M3N:
358 /* 2GB(1GBx2) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200359 dram_config[1] = 0x80000000ULL;
Marek Vasut9963f702018-10-02 15:09:04 +0200360 break;
361
362 case RCAR_PRODUCT_E3:
Marek Vasut673bc322018-10-02 13:33:32 +0200363#if (RCAR_DRAM_DDR3L_MEMCONF == 0)
364 /* 1GB(512MBx2) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200365 dram_config[1] = 0x40000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200366#elif (RCAR_DRAM_DDR3L_MEMCONF == 1)
367 /* 2GB(512MBx4) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200368 dram_config[1] = 0x80000000ULL;
Marek Vasut8cb12ec2018-10-02 13:51:19 +0200369#elif (RCAR_DRAM_DDR3L_MEMCONF == 2)
370 /* 4GB(1GBx4) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200371 dram_config[1] = 0x100000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200372#endif /* RCAR_DRAM_DDR3L_MEMCONF == 0 */
Marek Vasut9963f702018-10-02 15:09:04 +0200373 break;
Marek Vasut673bc322018-10-02 13:33:32 +0200374 }
Marek Vasut6a6881a2018-10-02 20:43:09 +0200375
376 bl2_advertise_dram_entries(dram_config);
Marek Vasut673bc322018-10-02 13:33:32 +0200377}
378
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200379void bl2_el3_early_platform_setup(u_register_t arg1, u_register_t arg2,
380 u_register_t arg3, u_register_t arg4)
381{
382 uint32_t reg, midr, lcs, boot_dev, boot_cpu, sscg, type, rev;
Marek Vasutb0e13592018-10-02 14:53:27 +0200383 uint32_t product, product_cut, major, minor;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200384 int32_t ret;
385 const char *str;
386 const char *unknown = "unknown";
387 const char *cpu_ca57 = "CA57";
388 const char *cpu_ca53 = "CA53";
389 const char *product_m3n = "M3N";
390 const char *product_h3 = "H3";
391 const char *product_m3 = "M3";
392 const char *product_e3 = "E3";
393 const char *lcs_secure = "SE";
394 const char *lcs_cm = "CM";
395 const char *lcs_dm = "DM";
396 const char *lcs_sd = "SD";
397 const char *lcs_fa = "FA";
398 const char *sscg_off = "PLL1 nonSSCG Clock select";
399 const char *sscg_on = "PLL1 SSCG Clock select";
400 const char *boot_hyper80 = "HyperFlash(80MHz)";
401 const char *boot_qspi40 = "QSPI Flash(40MHz)";
402 const char *boot_qspi80 = "QSPI Flash(80MHz)";
403 const char *boot_emmc25x1 = "eMMC(25MHz x1)";
404 const char *boot_emmc50x8 = "eMMC(50MHz x8)";
405#if RCAR_LSI == RCAR_E3
406 const char *boot_hyper160 = "HyperFlash(150MHz)";
407#else
408 const char *boot_hyper160 = "HyperFlash(160MHz)";
409#endif
410
411 reg = mmio_read_32(RCAR_MODEMR);
412 boot_dev = reg & MODEMR_BOOT_DEV_MASK;
413 boot_cpu = reg & MODEMR_BOOT_CPU_MASK;
414
415 bl2_cpg_init();
416
417 if (boot_cpu == MODEMR_BOOT_CPU_CA57 ||
418 boot_cpu == MODEMR_BOOT_CPU_CA53) {
419 rcar_pfc_init();
420 /* console configuration (platform specific) done in driver */
421 console_init(0, 0, 0);
422 }
423
424 plat_rcar_gic_driver_init();
425 plat_rcar_gic_init();
426 rcar_swdt_init();
427
428 /* FIQ interrupts are taken to EL3 */
429 write_scr_el3(read_scr_el3() | SCR_FIQ_BIT);
430
431 write_daifclr(DAIF_FIQ_BIT);
432
433 reg = read_midr();
434 midr = reg & (MIDR_PN_MASK << MIDR_PN_SHIFT);
435 switch (midr) {
436 case MIDR_CA57:
437 str = cpu_ca57;
438 break;
439 case MIDR_CA53:
440 str = cpu_ca53;
441 break;
442 default:
443 str = unknown;
444 break;
445 }
446
447 NOTICE("BL2: R-Car Gen3 Initial Program Loader(%s) Rev.%s\n", str,
448 version_of_renesas);
449
450 reg = mmio_read_32(RCAR_PRR);
451 product_cut = reg & (RCAR_PRODUCT_MASK | RCAR_CUT_MASK);
452 product = reg & RCAR_PRODUCT_MASK;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200453
454 switch (product) {
455 case RCAR_PRODUCT_H3:
456 str = product_h3;
457 break;
458 case RCAR_PRODUCT_M3:
459 str = product_m3;
460 break;
461 case RCAR_PRODUCT_M3N:
462 str = product_m3n;
463 break;
464 case RCAR_PRODUCT_E3:
465 str = product_e3;
466 break;
467 default:
468 str = unknown;
469 break;
470 }
471
472 if (RCAR_PRODUCT_M3_CUT11 == product_cut) {
473 NOTICE("BL2: PRR is R-Car %s Ver.1.1 / Ver.1.2\n", str);
474 } else {
475 major = (reg & RCAR_MAJOR_MASK) >> RCAR_MAJOR_SHIFT;
476 major = major + RCAR_MAJOR_OFFSET;
477 minor = reg & RCAR_MINOR_MASK;
478 NOTICE("BL2: PRR is R-Car %s Ver.%d.%d\n", str, major, minor);
479 }
480
481 if (product == RCAR_PRODUCT_E3) {
482 reg = mmio_read_32(RCAR_MODEMR);
483 sscg = reg & RCAR_SSCG_MASK;
484 str = sscg == RCAR_SSCG_ENABLE ? sscg_on : sscg_off;
485 NOTICE("BL2: %s\n", str);
486 }
487
488 rcar_get_board_type(&type, &rev);
489
490 switch (type) {
491 case BOARD_SALVATOR_X:
492 case BOARD_KRIEK:
493 case BOARD_STARTER_KIT:
494 case BOARD_SALVATOR_XS:
495 case BOARD_EBISU:
496 case BOARD_STARTER_KIT_PRE:
497 case BOARD_EBISU_4D:
498 break;
499 default:
500 type = BOARD_UNKNOWN;
501 break;
502 }
503
504 if (type == BOARD_UNKNOWN || rev == BOARD_REV_UNKNOWN)
505 NOTICE("BL2: Board is %s Rev.---\n", GET_BOARD_NAME(type));
506 else {
507 NOTICE("BL2: Board is %s Rev.%d.%d\n",
508 GET_BOARD_NAME(type),
509 GET_BOARD_MAJOR(rev), GET_BOARD_MINOR(rev));
510 }
511
512#if RCAR_LSI != RCAR_AUTO
513 if (product != TARGET_PRODUCT) {
514 ERROR("BL2: IPL was been built for the %s.\n", TARGET_NAME);
515 ERROR("BL2: Please write the correct IPL to flash memory.\n");
516 panic();
517 }
518#endif
519 rcar_avs_init();
520 rcar_avs_setting();
521
522 switch (boot_dev) {
523 case MODEMR_BOOT_DEV_HYPERFLASH160:
524 str = boot_hyper160;
525 break;
526 case MODEMR_BOOT_DEV_HYPERFLASH80:
527 str = boot_hyper80;
528 break;
529 case MODEMR_BOOT_DEV_QSPI_FLASH40:
530 str = boot_qspi40;
531 break;
532 case MODEMR_BOOT_DEV_QSPI_FLASH80:
533 str = boot_qspi80;
534 break;
535 case MODEMR_BOOT_DEV_EMMC_25X1:
536 str = boot_emmc25x1;
537 break;
538 case MODEMR_BOOT_DEV_EMMC_50X8:
539 str = boot_emmc50x8;
540 break;
541 default:
542 str = unknown;
543 break;
544 }
545 NOTICE("BL2: Boot device is %s\n", str);
546
547 rcar_avs_setting();
548 reg = rcar_rom_get_lcs(&lcs);
549 if (reg) {
550 str = unknown;
551 goto lcm_state;
552 }
553
554 switch (lcs) {
555 case LCS_CM:
556 str = lcs_cm;
557 break;
558 case LCS_DM:
559 str = lcs_dm;
560 break;
561 case LCS_SD:
562 str = lcs_sd;
563 break;
564 case LCS_SE:
565 str = lcs_secure;
566 break;
567 case LCS_FA:
568 str = lcs_fa;
569 break;
570 default:
571 str = unknown;
572 break;
573 }
574
575lcm_state:
576 NOTICE("BL2: LCM state is %s\n", str);
577
578 rcar_avs_end();
579 is_ddr_backup_mode();
580
581 bl2_tzram_layout.total_base = BL31_BASE;
582 bl2_tzram_layout.total_size = BL31_LIMIT - BL31_BASE;
583
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200584 if (boot_cpu == MODEMR_BOOT_CPU_CA57 ||
585 boot_cpu == MODEMR_BOOT_CPU_CA53) {
586 ret = rcar_dram_init();
587 if (ret) {
588 NOTICE("BL2: Failed to DRAM initialize (%d).\n", ret);
589 panic();
590 }
591 rcar_qos_init();
592 }
593
Marek Vasut63659fd2018-10-02 15:12:15 +0200594 /* Print DRAM layout */
595 bl2_advertise_dram_size(product);
596
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200597 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
598 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8) {
599 if (rcar_emmc_init() != EMMC_SUCCESS) {
600 NOTICE("BL2: Failed to eMMC driver initialize.\n");
601 panic();
602 }
603 rcar_emmc_memcard_power(EMMC_POWER_ON);
604 if (rcar_emmc_mount() != EMMC_SUCCESS) {
605 NOTICE("BL2: Failed to eMMC mount operation.\n");
606 panic();
607 }
608 } else {
609 rcar_rpc_init();
610 rcar_dma_init();
611 }
612
613 reg = mmio_read_32(RST_WDTRSTCR);
614 reg &= ~WDTRSTCR_RWDT_RSTMSK;
615 reg |= WDTRSTCR_PASSWORD;
616 mmio_write_32(RST_WDTRSTCR, reg);
617
618 mmio_write_32(CPG_CPGWPR, CPGWPR_PASSWORD);
619 mmio_write_32(CPG_CPGWPCR, CPGWPCR_PASSWORD);
620
621 reg = mmio_read_32(RCAR_PRR);
622 if ((reg & RCAR_CPU_MASK_CA57) == RCAR_CPU_HAVE_CA57)
623 mmio_write_32(CPG_CA57DBGRCR,
624 DBGCPUPREN | mmio_read_32(CPG_CA57DBGRCR));
625
626 if ((reg & RCAR_CPU_MASK_CA53) == RCAR_CPU_HAVE_CA53)
627 mmio_write_32(CPG_CA53DBGRCR,
628 DBGCPUPREN | mmio_read_32(CPG_CA53DBGRCR));
629
630 if (product_cut == RCAR_PRODUCT_H3_CUT10) {
631 reg = mmio_read_32(CPG_PLL2CR);
632 reg &= ~((uint32_t) 1 << 5);
633 mmio_write_32(CPG_PLL2CR, reg);
634
635 reg = mmio_read_32(CPG_PLL4CR);
636 reg &= ~((uint32_t) 1 << 5);
637 mmio_write_32(CPG_PLL4CR, reg);
638
639 reg = mmio_read_32(CPG_PLL0CR);
640 reg &= ~((uint32_t) 1 << 12);
641 mmio_write_32(CPG_PLL0CR, reg);
642 }
643#if (RCAR_LOSSY_ENABLE == 1)
644 NOTICE("BL2: Lossy Decomp areas\n");
645 bl2_lossy_setting(0, LOSSY_ST_ADDR0, LOSSY_END_ADDR0,
646 LOSSY_FMT0, LOSSY_ENA_DIS0);
647 bl2_lossy_setting(1, LOSSY_ST_ADDR1, LOSSY_END_ADDR1,
648 LOSSY_FMT1, LOSSY_ENA_DIS1);
649 bl2_lossy_setting(2, LOSSY_ST_ADDR2, LOSSY_END_ADDR2,
650 LOSSY_FMT2, LOSSY_ENA_DIS2);
651#endif
652
653 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
654 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8)
655 rcar_io_emmc_setup();
656 else
657 rcar_io_setup();
658}
659
660void bl2_el3_plat_arch_setup(void)
661{
662#if RCAR_BL2_DCACHE == 1
663 NOTICE("BL2: D-Cache enable\n");
664 rcar_configure_mmu_el3(BL2_BASE,
665 RCAR_SYSRAM_LIMIT - BL2_BASE,
666 BL2_RO_BASE, BL2_RO_LIMIT
667#if USE_COHERENT_MEM
668 , BL2_COHERENT_RAM_BASE, BL2_COHERENT_RAM_LIMIT
669#endif
670 );
671#endif
672}
673
674void bl2_platform_setup(void)
675{
676
677}