blob: 578892eb32e369a558434885f02fa3b060721935 [file] [log] [blame]
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02001/*
Madhukar Pappireddyfc9b4112019-12-23 14:49:52 -06002 * Copyright (c) 2018-2020, Renesas Electronics Corporation. All rights reserved.
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02003 *
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
Madhukar Pappireddyfc9b4112019-12-23 14:49:52 -060042#if RCAR_BL2_DCACHE == 1
43/*
44 * Following symbols are only used during plat_arch_setup() only
45 * when RCAR_BL2_DCACHE is enabled.
46 */
47static const uint64_t BL2_RO_BASE = BL_CODE_BASE;
48static const uint64_t BL2_RO_LIMIT = BL_CODE_END;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020049
50#if USE_COHERENT_MEM
Madhukar Pappireddyfc9b4112019-12-23 14:49:52 -060051static const uint64_t BL2_COHERENT_RAM_BASE = BL_COHERENT_RAM_BASE;
52static const uint64_t BL2_COHERENT_RAM_LIMIT = BL_COHERENT_RAM_END;
53#endif
54
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020055#endif
56
57extern void plat_rcar_gic_driver_init(void);
58extern void plat_rcar_gic_init(void);
59extern void bl2_enter_bl31(const struct entry_point_info *bl_ep_info);
60extern void bl2_system_cpg_init(void);
61extern void bl2_secure_setting(void);
62extern void bl2_cpg_init(void);
63extern void rcar_io_emmc_setup(void);
64extern void rcar_io_setup(void);
65extern void rcar_swdt_release(void);
66extern void rcar_swdt_init(void);
67extern void rcar_rpc_init(void);
68extern void rcar_pfc_init(void);
69extern void rcar_dma_init(void);
70
Marek Vasut1eca7782018-12-28 20:12:13 +010071static void bl2_init_generic_timer(void);
72
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020073/* R-Car Gen3 product check */
74#if (RCAR_LSI == RCAR_H3) || (RCAR_LSI == RCAR_H3N)
Marek Vasut9cadc782019-08-06 19:13:22 +020075#define TARGET_PRODUCT PRR_PRODUCT_H3
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020076#define TARGET_NAME "R-Car H3"
77#elif RCAR_LSI == RCAR_M3
Marek Vasut9cadc782019-08-06 19:13:22 +020078#define TARGET_PRODUCT PRR_PRODUCT_M3
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020079#define TARGET_NAME "R-Car M3"
80#elif RCAR_LSI == RCAR_M3N
Marek Vasut9cadc782019-08-06 19:13:22 +020081#define TARGET_PRODUCT PRR_PRODUCT_M3N
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020082#define TARGET_NAME "R-Car M3N"
Valentine Barshakf2184142018-10-30 02:06:17 +030083#elif RCAR_LSI == RCAR_V3M
Marek Vasut9cadc782019-08-06 19:13:22 +020084#define TARGET_PRODUCT PRR_PRODUCT_V3M
Valentine Barshakf2184142018-10-30 02:06:17 +030085#define TARGET_NAME "R-Car V3M"
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020086#elif RCAR_LSI == RCAR_E3
Marek Vasut9cadc782019-08-06 19:13:22 +020087#define TARGET_PRODUCT PRR_PRODUCT_E3
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020088#define TARGET_NAME "R-Car E3"
Marek Vasut4ae342c2019-01-05 13:56:03 +010089#elif RCAR_LSI == RCAR_D3
Marek Vasut9cadc782019-08-06 19:13:22 +020090#define TARGET_PRODUCT PRR_PRODUCT_D3
Marek Vasut4ae342c2019-01-05 13:56:03 +010091#define TARGET_NAME "R-Car D3"
Marek Vasut94cc0f82018-12-28 20:11:26 +010092#elif RCAR_LSI == RCAR_AUTO
Valentine Barshakf2184142018-10-30 02:06:17 +030093#define TARGET_NAME "R-Car H3/M3/M3N/V3M"
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020094#endif
95
96#if (RCAR_LSI == RCAR_E3)
97#define GPIO_INDT (GPIO_INDT6)
98#define GPIO_BKUP_TRG_SHIFT ((uint32_t)1U<<13U)
99#else
100#define GPIO_INDT (GPIO_INDT1)
101#define GPIO_BKUP_TRG_SHIFT ((uint32_t)1U<<8U)
102#endif
103
104CASSERT((PARAMS_BASE + sizeof(bl2_to_bl31_params_mem_t) + 0x100)
105 < (RCAR_SHARED_MEM_BASE + RCAR_SHARED_MEM_SIZE),
106 assert_bl31_params_do_not_fit_in_shared_memory);
107
108static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
109
Marek Vasut93c85fc2018-10-02 20:45:18 +0200110/* FDT with DRAM configuration */
111uint64_t fdt_blob[PAGE_SIZE_4KB / sizeof(uint64_t)];
112static void *fdt = (void *)fdt_blob;
113
114static void unsigned_num_print(unsigned long long int unum, unsigned int radix,
115 char *string)
116{
117 /* Just need enough space to store 64 bit decimal integer */
118 char num_buf[20];
119 int i = 0;
120 unsigned int rem;
121
122 do {
123 rem = unum % radix;
124 if (rem < 0xa)
125 num_buf[i] = '0' + rem;
126 else
127 num_buf[i] = 'a' + (rem - 0xa);
128 i++;
129 unum /= radix;
130 } while (unum > 0U);
131
132 while (--i >= 0)
133 *string++ = num_buf[i];
134}
135
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200136#if (RCAR_LOSSY_ENABLE == 1)
137typedef struct bl2_lossy_info {
138 uint32_t magic;
139 uint32_t a0;
140 uint32_t b0;
141} bl2_lossy_info_t;
142
Marek Vasut4d693c22018-10-11 16:53:58 +0200143static void bl2_lossy_gen_fdt(uint32_t no, uint64_t start_addr,
144 uint64_t end_addr, uint32_t format,
145 uint32_t enable, int fcnlnode)
146{
147 const uint64_t fcnlsize = cpu_to_fdt64(end_addr - start_addr);
148 char nodename[40] = { 0 };
149 int ret, node;
150
151 /* Ignore undefined addresses */
152 if (start_addr == 0 && end_addr == 0)
153 return;
154
155 snprintf(nodename, sizeof(nodename), "lossy-decompression@");
156 unsigned_num_print(start_addr, 16, nodename + strlen(nodename));
157
158 node = ret = fdt_add_subnode(fdt, fcnlnode, nodename);
159 if (ret < 0) {
160 NOTICE("BL2: Cannot create FCNL node (ret=%i)\n", ret);
161 panic();
162 }
163
164 ret = fdt_setprop_string(fdt, node, "compatible",
165 "renesas,lossy-decompression");
166 if (ret < 0) {
167 NOTICE("BL2: Cannot add FCNL compat string (ret=%i)\n", ret);
168 panic();
169 }
170
171 ret = fdt_appendprop_string(fdt, node, "compatible",
172 "shared-dma-pool");
173 if (ret < 0) {
174 NOTICE("BL2: Cannot append FCNL compat string (ret=%i)\n", ret);
175 panic();
176 }
177
178 ret = fdt_setprop_u64(fdt, node, "reg", start_addr);
179 if (ret < 0) {
180 NOTICE("BL2: Cannot add FCNL reg prop (ret=%i)\n", ret);
181 panic();
182 }
183
184 ret = fdt_appendprop(fdt, node, "reg", &fcnlsize, sizeof(fcnlsize));
185 if (ret < 0) {
186 NOTICE("BL2: Cannot append FCNL reg size prop (ret=%i)\n", ret);
187 panic();
188 }
189
190 ret = fdt_setprop(fdt, node, "no-map", NULL, 0);
191 if (ret < 0) {
192 NOTICE("BL2: Cannot add FCNL no-map prop (ret=%i)\n", ret);
193 panic();
194 }
195
196 ret = fdt_setprop_u32(fdt, node, "renesas,formats", format);
197 if (ret < 0) {
198 NOTICE("BL2: Cannot add FCNL formats prop (ret=%i)\n", ret);
199 panic();
200 }
201}
202
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200203static void bl2_lossy_setting(uint32_t no, uint64_t start_addr,
204 uint64_t end_addr, uint32_t format,
Marek Vasut4d693c22018-10-11 16:53:58 +0200205 uint32_t enable, int fcnlnode)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200206{
207 bl2_lossy_info_t info;
208 uint32_t reg;
209
Marek Vasut4d693c22018-10-11 16:53:58 +0200210 bl2_lossy_gen_fdt(no, start_addr, end_addr, format, enable, fcnlnode);
211
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200212 reg = format | (start_addr >> 20);
213 mmio_write_32(AXI_DCMPAREACRA0 + 0x8 * no, reg);
214 mmio_write_32(AXI_DCMPAREACRB0 + 0x8 * no, end_addr >> 20);
215 mmio_write_32(AXI_DCMPAREACRA0 + 0x8 * no, reg | enable);
216
217 info.magic = 0x12345678U;
218 info.a0 = mmio_read_32(AXI_DCMPAREACRA0 + 0x8 * no);
219 info.b0 = mmio_read_32(AXI_DCMPAREACRB0 + 0x8 * no);
220
221 mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no, info.magic);
222 mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no + 0x4, info.a0);
223 mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no + 0x8, info.b0);
224
225 NOTICE(" Entry %d: DCMPAREACRAx:0x%x DCMPAREACRBx:0x%x\n", no,
226 mmio_read_32(AXI_DCMPAREACRA0 + 0x8 * no),
227 mmio_read_32(AXI_DCMPAREACRB0 + 0x8 * no));
228}
229#endif
230
231void bl2_plat_flush_bl31_params(void)
232{
233 uint32_t product_cut, product, cut;
234 uint32_t boot_dev, boot_cpu;
235 uint32_t lcs, reg, val;
236
237 reg = mmio_read_32(RCAR_MODEMR);
238 boot_dev = reg & MODEMR_BOOT_DEV_MASK;
239
240 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
241 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8)
242 emmc_terminate();
243
244 if ((reg & MODEMR_BOOT_CPU_MASK) != MODEMR_BOOT_CPU_CR7)
245 bl2_secure_setting();
246
247 reg = mmio_read_32(RCAR_PRR);
Marek Vasut9cadc782019-08-06 19:13:22 +0200248 product_cut = reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK);
249 product = reg & PRR_PRODUCT_MASK;
250 cut = reg & PRR_CUT_MASK;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200251
Marek Vasut9cadc782019-08-06 19:13:22 +0200252 if (product == PRR_PRODUCT_M3 && PRR_PRODUCT_30 > cut)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200253 goto tlb;
254
Marek Vasut9cadc782019-08-06 19:13:22 +0200255 if (product == PRR_PRODUCT_H3 && PRR_PRODUCT_20 > cut)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200256 goto tlb;
257
Marek Vasut9cadc782019-08-06 19:13:22 +0200258 if (product == PRR_PRODUCT_D3)
Marek Vasut4ae342c2019-01-05 13:56:03 +0100259 goto tlb;
260
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200261 /* Disable MFIS write protection */
262 mmio_write_32(MFISWPCNTR, MFISWPCNTR_PASSWORD | 1);
263
264tlb:
265 reg = mmio_read_32(RCAR_MODEMR);
266 boot_cpu = reg & MODEMR_BOOT_CPU_MASK;
267 if (boot_cpu != MODEMR_BOOT_CPU_CA57 &&
268 boot_cpu != MODEMR_BOOT_CPU_CA53)
269 goto mmu;
270
Marek Vasut9cadc782019-08-06 19:13:22 +0200271 if (product_cut == PRR_PRODUCT_H3_CUT20) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200272 mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE);
273 mmio_write_32(IPMMUVI1_IMSCTLR, IMSCTLR_DISCACHE);
274 mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE);
275 mmio_write_32(IPMMUPV1_IMSCTLR, IMSCTLR_DISCACHE);
276 mmio_write_32(IPMMUPV2_IMSCTLR, IMSCTLR_DISCACHE);
277 mmio_write_32(IPMMUPV3_IMSCTLR, IMSCTLR_DISCACHE);
Marek Vasut9cadc782019-08-06 19:13:22 +0200278 } else if (product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_10) ||
279 product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_11)) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200280 mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE);
281 mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE);
Marek Vasut9cadc782019-08-06 19:13:22 +0200282 } else if ((product_cut == (PRR_PRODUCT_E3 | PRR_PRODUCT_10)) ||
283 (product_cut == (PRR_PRODUCT_E3 | PRR_PRODUCT_11))) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200284 mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE);
Marek Vasute6208012018-12-31 16:48:04 +0100285 mmio_write_32(IPMMUVP0_IMSCTLR, IMSCTLR_DISCACHE);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200286 mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE);
287 }
288
Marek Vasut9cadc782019-08-06 19:13:22 +0200289 if (product_cut == (PRR_PRODUCT_H3_CUT20) ||
290 product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_10) ||
291 product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_11) ||
292 product_cut == (PRR_PRODUCT_E3 | PRR_PRODUCT_10)) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200293 mmio_write_32(IPMMUHC_IMSCTLR, IMSCTLR_DISCACHE);
294 mmio_write_32(IPMMURT_IMSCTLR, IMSCTLR_DISCACHE);
295 mmio_write_32(IPMMUMP_IMSCTLR, IMSCTLR_DISCACHE);
296
297 mmio_write_32(IPMMUDS0_IMSCTLR, IMSCTLR_DISCACHE);
298 mmio_write_32(IPMMUDS1_IMSCTLR, IMSCTLR_DISCACHE);
299 }
300
301mmu:
302 mmio_write_32(IPMMUMM_IMSCTLR, IPMMUMM_IMSCTLR_ENABLE);
303 mmio_write_32(IPMMUMM_IMAUXCTLR, IPMMUMM_IMAUXCTLR_NMERGE40_BIT);
304
305 val = rcar_rom_get_lcs(&lcs);
306 if (val) {
307 ERROR("BL2: Failed to get the LCS. (%d)\n", val);
308 panic();
309 }
310
311 if (lcs == LCS_SE)
312 mmio_clrbits_32(P_ARMREG_SEC_CTRL, P_ARMREG_SEC_CTRL_PROT);
313
314 rcar_swdt_release();
315 bl2_system_cpg_init();
316
317#if RCAR_BL2_DCACHE == 1
318 /* Disable data cache (clean and invalidate) */
319 disable_mmu_el3();
320#endif
321}
322
323static uint32_t is_ddr_backup_mode(void)
324{
325#if RCAR_SYSTEM_SUSPEND
326 static uint32_t reason = RCAR_COLD_BOOT;
327 static uint32_t once;
328
329#if PMIC_ROHM_BD9571 && RCAR_SYSTEM_RESET_KEEPON_DDR
330 uint8_t data;
331#endif
332 if (once)
333 return reason;
334
335 once = 1;
336 if ((mmio_read_32(GPIO_INDT) & GPIO_BKUP_TRG_SHIFT) == 0)
337 return reason;
338
339#if PMIC_ROHM_BD9571 && RCAR_SYSTEM_RESET_KEEPON_DDR
340 if (rcar_iic_dvfs_receive(PMIC, REG_KEEP10, &data)) {
341 ERROR("BL2: REG Keep10 READ ERROR.\n");
342 panic();
343 }
344
345 if (KEEP10_MAGIC != data)
346 reason = RCAR_WARM_BOOT;
347#else
348 reason = RCAR_WARM_BOOT;
349#endif
350 return reason;
351#else
352 return RCAR_COLD_BOOT;
353#endif
354}
355
356int bl2_plat_handle_pre_image_load(unsigned int image_id)
357{
358 u_register_t *boot_kind = (void *) BOOT_KIND_BASE;
359 bl_mem_params_node_t *bl_mem_params;
360
361 if (image_id != BL31_IMAGE_ID)
362 return 0;
363
364 bl_mem_params = get_bl_mem_params_node(image_id);
365
366 if (is_ddr_backup_mode() == RCAR_COLD_BOOT)
367 goto cold_boot;
368
369 *boot_kind = RCAR_WARM_BOOT;
370 flush_dcache_range(BOOT_KIND_BASE, sizeof(*boot_kind));
371
372 console_flush();
373 bl2_plat_flush_bl31_params();
374
375 /* will not return */
376 bl2_enter_bl31(&bl_mem_params->ep_info);
377
378cold_boot:
379 *boot_kind = RCAR_COLD_BOOT;
380 flush_dcache_range(BOOT_KIND_BASE, sizeof(*boot_kind));
381
382 return 0;
383}
384
385int bl2_plat_handle_post_image_load(unsigned int image_id)
386{
387 static bl2_to_bl31_params_mem_t *params;
388 bl_mem_params_node_t *bl_mem_params;
389
390 if (!params) {
391 params = (bl2_to_bl31_params_mem_t *) PARAMS_BASE;
392 memset((void *)PARAMS_BASE, 0, sizeof(*params));
393 }
394
395 bl_mem_params = get_bl_mem_params_node(image_id);
396
397 switch (image_id) {
398 case BL31_IMAGE_ID:
399 break;
400 case BL32_IMAGE_ID:
401 memcpy(&params->bl32_ep_info, &bl_mem_params->ep_info,
402 sizeof(entry_point_info_t));
403 break;
404 case BL33_IMAGE_ID:
405 memcpy(&params->bl33_ep_info, &bl_mem_params->ep_info,
406 sizeof(entry_point_info_t));
407 break;
408 }
409
410 return 0;
411}
412
Marek Vasutc7077c62018-12-26 15:57:08 +0100413struct meminfo *bl2_plat_sec_mem_layout(void)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200414{
415 return &bl2_tzram_layout;
416}
417
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100418static void bl2_populate_compatible_string(void *dt)
Marek Vasuta987b002018-10-11 16:15:41 +0200419{
420 uint32_t board_type;
421 uint32_t board_rev;
422 uint32_t reg;
423 int ret;
424
Marek Vasut688251a2020-01-06 03:26:43 +0100425 fdt_setprop_u32(dt, 0, "#address-cells", 2);
426 fdt_setprop_u32(dt, 0, "#size-cells", 2);
427
Marek Vasuta987b002018-10-11 16:15:41 +0200428 /* Populate compatible string */
429 rcar_get_board_type(&board_type, &board_rev);
430 switch (board_type) {
431 case BOARD_SALVATOR_X:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100432 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200433 "renesas,salvator-x");
434 break;
435 case BOARD_SALVATOR_XS:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100436 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200437 "renesas,salvator-xs");
438 break;
439 case BOARD_STARTER_KIT:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100440 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200441 "renesas,m3ulcb");
442 break;
443 case BOARD_STARTER_KIT_PRE:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100444 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200445 "renesas,h3ulcb");
446 break;
Valentine Barshakf2184142018-10-30 02:06:17 +0300447 case BOARD_EAGLE:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100448 ret = fdt_setprop_string(dt, 0, "compatible",
Valentine Barshakf2184142018-10-30 02:06:17 +0300449 "renesas,eagle");
450 break;
Marek Vasuta987b002018-10-11 16:15:41 +0200451 case BOARD_EBISU:
452 case BOARD_EBISU_4D:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100453 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200454 "renesas,ebisu");
455 break;
Marek Vasut4ae342c2019-01-05 13:56:03 +0100456 case BOARD_DRAAK:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100457 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasut4ae342c2019-01-05 13:56:03 +0100458 "renesas,draak");
459 break;
Marek Vasuta987b002018-10-11 16:15:41 +0200460 default:
461 NOTICE("BL2: Cannot set compatible string, board unsupported\n");
462 panic();
463 }
464
465 if (ret < 0) {
466 NOTICE("BL2: Cannot set compatible string (ret=%i)\n", ret);
467 panic();
468 }
469
470 reg = mmio_read_32(RCAR_PRR);
Marek Vasut9cadc782019-08-06 19:13:22 +0200471 switch (reg & PRR_PRODUCT_MASK) {
472 case PRR_PRODUCT_H3:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100473 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200474 "renesas,r8a7795");
475 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200476 case PRR_PRODUCT_M3:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100477 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200478 "renesas,r8a7796");
479 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200480 case PRR_PRODUCT_M3N:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100481 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200482 "renesas,r8a77965");
483 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200484 case PRR_PRODUCT_V3M:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100485 ret = fdt_appendprop_string(dt, 0, "compatible",
Valentine Barshakf2184142018-10-30 02:06:17 +0300486 "renesas,r8a77970");
487 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200488 case PRR_PRODUCT_E3:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100489 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200490 "renesas,r8a77990");
491 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200492 case PRR_PRODUCT_D3:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100493 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasut4ae342c2019-01-05 13:56:03 +0100494 "renesas,r8a77995");
495 break;
Marek Vasuta987b002018-10-11 16:15:41 +0200496 default:
497 NOTICE("BL2: Cannot set compatible string, SoC unsupported\n");
498 panic();
499 }
500
501 if (ret < 0) {
502 NOTICE("BL2: Cannot set compatible string (ret=%i)\n", ret);
503 panic();
504 }
505}
506
Marek Vasut6a6881a2018-10-02 20:43:09 +0200507static void bl2_advertise_dram_entries(uint64_t dram_config[8])
508{
Marek Vasut93c85fc2018-10-02 20:45:18 +0200509 char nodename[32] = { 0 };
Marek Vasut6a6881a2018-10-02 20:43:09 +0200510 uint64_t start, size;
Marek Vasut93c85fc2018-10-02 20:45:18 +0200511 uint64_t fdtsize;
512 int ret, node, chan;
Marek Vasut6a6881a2018-10-02 20:43:09 +0200513
514 for (chan = 0; chan < 4; chan++) {
515 start = dram_config[2 * chan];
516 size = dram_config[2 * chan + 1];
517 if (!size)
518 continue;
519
Marek Vasut89c17512019-03-30 04:01:41 +0100520 NOTICE("BL2: CH%d: %llx - %llx, %lld %siB\n",
521 chan, start, start + size - 1,
522 (size >> 30) ? : size >> 20,
523 (size >> 30) ? "G" : "M");
Marek Vasut6a6881a2018-10-02 20:43:09 +0200524 }
Marek Vasut93c85fc2018-10-02 20:45:18 +0200525
526 /*
527 * We add the DT nodes in reverse order here. The fdt_add_subnode()
528 * adds the DT node before the first existing DT node, so we have
529 * to add them in reverse order to get nodes sorted by address in
530 * the resulting DT.
531 */
532 for (chan = 3; chan >= 0; chan--) {
533 start = dram_config[2 * chan];
534 size = dram_config[2 * chan + 1];
535 if (!size)
536 continue;
537
538 /*
539 * Channel 0 is mapped in 32bit space and the first
540 * 128 MiB are reserved
541 */
542 if (chan == 0) {
543 start = 0x48000000;
544 size -= 0x8000000;
545 }
546
547 fdtsize = cpu_to_fdt64(size);
548
549 snprintf(nodename, sizeof(nodename), "memory@");
550 unsigned_num_print(start, 16, nodename + strlen(nodename));
551 node = ret = fdt_add_subnode(fdt, 0, nodename);
552 if (ret < 0)
553 goto err;
554
555 ret = fdt_setprop_string(fdt, node, "device_type", "memory");
556 if (ret < 0)
557 goto err;
558
559 ret = fdt_setprop_u64(fdt, node, "reg", start);
560 if (ret < 0)
561 goto err;
562
563 ret = fdt_appendprop(fdt, node, "reg", &fdtsize,
564 sizeof(fdtsize));
565 if (ret < 0)
566 goto err;
567 }
568
569 return;
570err:
571 NOTICE("BL2: Cannot add memory node to FDT (ret=%i)\n", ret);
572 panic();
Marek Vasut6a6881a2018-10-02 20:43:09 +0200573}
574
Marek Vasutb0e13592018-10-02 14:53:27 +0200575static void bl2_advertise_dram_size(uint32_t product)
Marek Vasut673bc322018-10-02 13:33:32 +0200576{
Marek Vasut6a6881a2018-10-02 20:43:09 +0200577 uint64_t dram_config[8] = {
578 [0] = 0x400000000ULL,
579 [2] = 0x500000000ULL,
580 [4] = 0x600000000ULL,
581 [6] = 0x700000000ULL,
582 };
583
Marek Vasut9963f702018-10-02 15:09:04 +0200584 switch (product) {
Marek Vasut9cadc782019-08-06 19:13:22 +0200585 case PRR_PRODUCT_H3:
Marek Vasut673bc322018-10-02 13:33:32 +0200586#if (RCAR_DRAM_LPDDR4_MEMCONF == 0)
587 /* 4GB(1GBx4) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200588 dram_config[1] = 0x40000000ULL;
589 dram_config[3] = 0x40000000ULL;
590 dram_config[5] = 0x40000000ULL;
591 dram_config[7] = 0x40000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200592#elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && \
593 (RCAR_DRAM_CHANNEL == 5) && \
594 (RCAR_DRAM_SPLIT == 2)
595 /* 4GB(2GBx2 2ch split) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200596 dram_config[1] = 0x80000000ULL;
597 dram_config[3] = 0x80000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200598#elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && (RCAR_DRAM_CHANNEL == 15)
599 /* 8GB(2GBx4: default) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200600 dram_config[1] = 0x80000000ULL;
601 dram_config[3] = 0x80000000ULL;
602 dram_config[5] = 0x80000000ULL;
603 dram_config[7] = 0x80000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200604#endif /* RCAR_DRAM_LPDDR4_MEMCONF == 0 */
Marek Vasut9963f702018-10-02 15:09:04 +0200605 break;
Marek Vasut673bc322018-10-02 13:33:32 +0200606
Marek Vasut9cadc782019-08-06 19:13:22 +0200607 case PRR_PRODUCT_M3:
Marek Vasut0208c942019-03-09 16:10:59 +0100608#if (RCAR_GEN3_ULCB == 1)
609 /* 2GB(1GBx2 2ch split) */
610 dram_config[1] = 0x40000000ULL;
611 dram_config[5] = 0x40000000ULL;
612#else
Marek Vasut9963f702018-10-02 15:09:04 +0200613 /* 4GB(2GBx2 2ch split) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200614 dram_config[1] = 0x80000000ULL;
615 dram_config[5] = 0x80000000ULL;
Marek Vasut0208c942019-03-09 16:10:59 +0100616#endif
Marek Vasut9963f702018-10-02 15:09:04 +0200617 break;
618
Marek Vasut9cadc782019-08-06 19:13:22 +0200619 case PRR_PRODUCT_M3N:
Marek Vasut9963f702018-10-02 15:09:04 +0200620 /* 2GB(1GBx2) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200621 dram_config[1] = 0x80000000ULL;
Marek Vasut9963f702018-10-02 15:09:04 +0200622 break;
623
Marek Vasut9cadc782019-08-06 19:13:22 +0200624 case PRR_PRODUCT_V3M:
Valentine Barshakf2184142018-10-30 02:06:17 +0300625 /* 1GB(512MBx2) */
626 dram_config[1] = 0x40000000ULL;
627 break;
628
Marek Vasut9cadc782019-08-06 19:13:22 +0200629 case PRR_PRODUCT_E3:
Marek Vasut673bc322018-10-02 13:33:32 +0200630#if (RCAR_DRAM_DDR3L_MEMCONF == 0)
631 /* 1GB(512MBx2) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200632 dram_config[1] = 0x40000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200633#elif (RCAR_DRAM_DDR3L_MEMCONF == 1)
634 /* 2GB(512MBx4) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200635 dram_config[1] = 0x80000000ULL;
Marek Vasut8cb12ec2018-10-02 13:51:19 +0200636#elif (RCAR_DRAM_DDR3L_MEMCONF == 2)
637 /* 4GB(1GBx4) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200638 dram_config[1] = 0x100000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200639#endif /* RCAR_DRAM_DDR3L_MEMCONF == 0 */
Marek Vasut9963f702018-10-02 15:09:04 +0200640 break;
Marek Vasut4ae342c2019-01-05 13:56:03 +0100641
Marek Vasut9cadc782019-08-06 19:13:22 +0200642 case PRR_PRODUCT_D3:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100643 /* 512MB */
644 dram_config[1] = 0x20000000ULL;
645 break;
Marek Vasut673bc322018-10-02 13:33:32 +0200646 }
Marek Vasut6a6881a2018-10-02 20:43:09 +0200647
648 bl2_advertise_dram_entries(dram_config);
Marek Vasut673bc322018-10-02 13:33:32 +0200649}
650
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200651void bl2_el3_early_platform_setup(u_register_t arg1, u_register_t arg2,
652 u_register_t arg3, u_register_t arg4)
653{
654 uint32_t reg, midr, lcs, boot_dev, boot_cpu, sscg, type, rev;
Marek Vasutb0e13592018-10-02 14:53:27 +0200655 uint32_t product, product_cut, major, minor;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200656 int32_t ret;
657 const char *str;
658 const char *unknown = "unknown";
659 const char *cpu_ca57 = "CA57";
660 const char *cpu_ca53 = "CA53";
661 const char *product_m3n = "M3N";
662 const char *product_h3 = "H3";
663 const char *product_m3 = "M3";
664 const char *product_e3 = "E3";
Marek Vasut4ae342c2019-01-05 13:56:03 +0100665 const char *product_d3 = "D3";
Valentine Barshakf2184142018-10-30 02:06:17 +0300666 const char *product_v3m = "V3M";
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200667 const char *lcs_secure = "SE";
668 const char *lcs_cm = "CM";
669 const char *lcs_dm = "DM";
670 const char *lcs_sd = "SD";
671 const char *lcs_fa = "FA";
672 const char *sscg_off = "PLL1 nonSSCG Clock select";
673 const char *sscg_on = "PLL1 SSCG Clock select";
674 const char *boot_hyper80 = "HyperFlash(80MHz)";
675 const char *boot_qspi40 = "QSPI Flash(40MHz)";
676 const char *boot_qspi80 = "QSPI Flash(80MHz)";
677 const char *boot_emmc25x1 = "eMMC(25MHz x1)";
678 const char *boot_emmc50x8 = "eMMC(50MHz x8)";
Marek Vasut4ae342c2019-01-05 13:56:03 +0100679#if (RCAR_LSI == RCAR_E3) || (RCAR_LSI == RCAR_D3)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200680 const char *boot_hyper160 = "HyperFlash(150MHz)";
681#else
682 const char *boot_hyper160 = "HyperFlash(160MHz)";
683#endif
Marek Vasut4d693c22018-10-11 16:53:58 +0200684#if (RCAR_LOSSY_ENABLE == 1)
685 int fcnlnode;
686#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200687
Marek Vasut1eca7782018-12-28 20:12:13 +0100688 bl2_init_generic_timer();
689
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200690 reg = mmio_read_32(RCAR_MODEMR);
691 boot_dev = reg & MODEMR_BOOT_DEV_MASK;
692 boot_cpu = reg & MODEMR_BOOT_CPU_MASK;
693
694 bl2_cpg_init();
695
696 if (boot_cpu == MODEMR_BOOT_CPU_CA57 ||
697 boot_cpu == MODEMR_BOOT_CPU_CA53) {
698 rcar_pfc_init();
Marek Vasut0aa268e2019-05-18 19:29:16 +0200699 rcar_console_boot_init();
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200700 }
701
702 plat_rcar_gic_driver_init();
703 plat_rcar_gic_init();
704 rcar_swdt_init();
705
706 /* FIQ interrupts are taken to EL3 */
707 write_scr_el3(read_scr_el3() | SCR_FIQ_BIT);
708
709 write_daifclr(DAIF_FIQ_BIT);
710
711 reg = read_midr();
712 midr = reg & (MIDR_PN_MASK << MIDR_PN_SHIFT);
713 switch (midr) {
714 case MIDR_CA57:
715 str = cpu_ca57;
716 break;
717 case MIDR_CA53:
718 str = cpu_ca53;
719 break;
720 default:
721 str = unknown;
722 break;
723 }
724
725 NOTICE("BL2: R-Car Gen3 Initial Program Loader(%s) Rev.%s\n", str,
726 version_of_renesas);
727
728 reg = mmio_read_32(RCAR_PRR);
Marek Vasut9cadc782019-08-06 19:13:22 +0200729 product_cut = reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK);
730 product = reg & PRR_PRODUCT_MASK;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200731
732 switch (product) {
Marek Vasut9cadc782019-08-06 19:13:22 +0200733 case PRR_PRODUCT_H3:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200734 str = product_h3;
735 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200736 case PRR_PRODUCT_M3:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200737 str = product_m3;
738 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200739 case PRR_PRODUCT_M3N:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200740 str = product_m3n;
741 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200742 case PRR_PRODUCT_V3M:
Valentine Barshakf2184142018-10-30 02:06:17 +0300743 str = product_v3m;
744 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200745 case PRR_PRODUCT_E3:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200746 str = product_e3;
747 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200748 case PRR_PRODUCT_D3:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100749 str = product_d3;
750 break;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200751 default:
752 str = unknown;
753 break;
754 }
755
Marek Vasut9cadc782019-08-06 19:13:22 +0200756 if ((PRR_PRODUCT_M3 == product) &&
757 (PRR_PRODUCT_20 == (reg & RCAR_MAJOR_MASK))) {
758 if (RCAR_M3_CUT_VER11 == (reg & PRR_CUT_MASK)) {
Marek Vasut3af20052019-02-25 14:57:08 +0100759 /* M3 Ver.1.1 or Ver.1.2 */
760 NOTICE("BL2: PRR is R-Car %s Ver.1.1 / Ver.1.2\n",
761 str);
762 } else {
763 NOTICE("BL2: PRR is R-Car %s Ver.1.%d\n",
764 str,
765 (reg & RCAR_MINOR_MASK) + RCAR_M3_MINOR_OFFSET);
766 }
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200767 } else {
768 major = (reg & RCAR_MAJOR_MASK) >> RCAR_MAJOR_SHIFT;
769 major = major + RCAR_MAJOR_OFFSET;
770 minor = reg & RCAR_MINOR_MASK;
771 NOTICE("BL2: PRR is R-Car %s Ver.%d.%d\n", str, major, minor);
772 }
773
Marek Vasut9cadc782019-08-06 19:13:22 +0200774 if (product == PRR_PRODUCT_E3) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200775 reg = mmio_read_32(RCAR_MODEMR);
776 sscg = reg & RCAR_SSCG_MASK;
777 str = sscg == RCAR_SSCG_ENABLE ? sscg_on : sscg_off;
778 NOTICE("BL2: %s\n", str);
779 }
780
781 rcar_get_board_type(&type, &rev);
782
783 switch (type) {
784 case BOARD_SALVATOR_X:
785 case BOARD_KRIEK:
786 case BOARD_STARTER_KIT:
787 case BOARD_SALVATOR_XS:
788 case BOARD_EBISU:
789 case BOARD_STARTER_KIT_PRE:
790 case BOARD_EBISU_4D:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100791 case BOARD_DRAAK:
Valentine Barshakf2184142018-10-30 02:06:17 +0300792 case BOARD_EAGLE:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200793 break;
794 default:
795 type = BOARD_UNKNOWN;
796 break;
797 }
798
799 if (type == BOARD_UNKNOWN || rev == BOARD_REV_UNKNOWN)
800 NOTICE("BL2: Board is %s Rev.---\n", GET_BOARD_NAME(type));
801 else {
802 NOTICE("BL2: Board is %s Rev.%d.%d\n",
803 GET_BOARD_NAME(type),
804 GET_BOARD_MAJOR(rev), GET_BOARD_MINOR(rev));
805 }
806
807#if RCAR_LSI != RCAR_AUTO
808 if (product != TARGET_PRODUCT) {
809 ERROR("BL2: IPL was been built for the %s.\n", TARGET_NAME);
810 ERROR("BL2: Please write the correct IPL to flash memory.\n");
811 panic();
812 }
813#endif
814 rcar_avs_init();
815 rcar_avs_setting();
816
817 switch (boot_dev) {
818 case MODEMR_BOOT_DEV_HYPERFLASH160:
819 str = boot_hyper160;
820 break;
821 case MODEMR_BOOT_DEV_HYPERFLASH80:
822 str = boot_hyper80;
823 break;
824 case MODEMR_BOOT_DEV_QSPI_FLASH40:
825 str = boot_qspi40;
826 break;
827 case MODEMR_BOOT_DEV_QSPI_FLASH80:
828 str = boot_qspi80;
829 break;
830 case MODEMR_BOOT_DEV_EMMC_25X1:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100831#if RCAR_LSI == RCAR_D3
832 ERROR("BL2: Failed to Initialize. eMMC is not supported.\n");
833 panic();
834#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200835 str = boot_emmc25x1;
836 break;
837 case MODEMR_BOOT_DEV_EMMC_50X8:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100838#if RCAR_LSI == RCAR_D3
839 ERROR("BL2: Failed to Initialize. eMMC is not supported.\n");
840 panic();
841#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200842 str = boot_emmc50x8;
843 break;
844 default:
845 str = unknown;
846 break;
847 }
848 NOTICE("BL2: Boot device is %s\n", str);
849
850 rcar_avs_setting();
851 reg = rcar_rom_get_lcs(&lcs);
852 if (reg) {
853 str = unknown;
854 goto lcm_state;
855 }
856
857 switch (lcs) {
858 case LCS_CM:
859 str = lcs_cm;
860 break;
861 case LCS_DM:
862 str = lcs_dm;
863 break;
864 case LCS_SD:
865 str = lcs_sd;
866 break;
867 case LCS_SE:
868 str = lcs_secure;
869 break;
870 case LCS_FA:
871 str = lcs_fa;
872 break;
873 default:
874 str = unknown;
875 break;
876 }
877
878lcm_state:
879 NOTICE("BL2: LCM state is %s\n", str);
880
881 rcar_avs_end();
882 is_ddr_backup_mode();
883
884 bl2_tzram_layout.total_base = BL31_BASE;
885 bl2_tzram_layout.total_size = BL31_LIMIT - BL31_BASE;
886
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200887 if (boot_cpu == MODEMR_BOOT_CPU_CA57 ||
888 boot_cpu == MODEMR_BOOT_CPU_CA53) {
889 ret = rcar_dram_init();
890 if (ret) {
891 NOTICE("BL2: Failed to DRAM initialize (%d).\n", ret);
892 panic();
893 }
894 rcar_qos_init();
895 }
896
Marek Vasut93c85fc2018-10-02 20:45:18 +0200897 /* Set up FDT */
898 ret = fdt_create_empty_tree(fdt, sizeof(fdt_blob));
899 if (ret) {
900 NOTICE("BL2: Cannot allocate FDT for U-Boot (ret=%i)\n", ret);
901 panic();
902 }
903
Marek Vasuta987b002018-10-11 16:15:41 +0200904 /* Add platform compatible string */
905 bl2_populate_compatible_string(fdt);
906
Marek Vasut63659fd2018-10-02 15:12:15 +0200907 /* Print DRAM layout */
908 bl2_advertise_dram_size(product);
909
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200910 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
911 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8) {
912 if (rcar_emmc_init() != EMMC_SUCCESS) {
913 NOTICE("BL2: Failed to eMMC driver initialize.\n");
914 panic();
915 }
916 rcar_emmc_memcard_power(EMMC_POWER_ON);
917 if (rcar_emmc_mount() != EMMC_SUCCESS) {
918 NOTICE("BL2: Failed to eMMC mount operation.\n");
919 panic();
920 }
921 } else {
922 rcar_rpc_init();
923 rcar_dma_init();
924 }
925
926 reg = mmio_read_32(RST_WDTRSTCR);
927 reg &= ~WDTRSTCR_RWDT_RSTMSK;
928 reg |= WDTRSTCR_PASSWORD;
929 mmio_write_32(RST_WDTRSTCR, reg);
930
931 mmio_write_32(CPG_CPGWPR, CPGWPR_PASSWORD);
932 mmio_write_32(CPG_CPGWPCR, CPGWPCR_PASSWORD);
933
934 reg = mmio_read_32(RCAR_PRR);
935 if ((reg & RCAR_CPU_MASK_CA57) == RCAR_CPU_HAVE_CA57)
936 mmio_write_32(CPG_CA57DBGRCR,
937 DBGCPUPREN | mmio_read_32(CPG_CA57DBGRCR));
938
939 if ((reg & RCAR_CPU_MASK_CA53) == RCAR_CPU_HAVE_CA53)
940 mmio_write_32(CPG_CA53DBGRCR,
941 DBGCPUPREN | mmio_read_32(CPG_CA53DBGRCR));
942
Marek Vasut9cadc782019-08-06 19:13:22 +0200943 if (product_cut == PRR_PRODUCT_H3_CUT10) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200944 reg = mmio_read_32(CPG_PLL2CR);
945 reg &= ~((uint32_t) 1 << 5);
946 mmio_write_32(CPG_PLL2CR, reg);
947
948 reg = mmio_read_32(CPG_PLL4CR);
949 reg &= ~((uint32_t) 1 << 5);
950 mmio_write_32(CPG_PLL4CR, reg);
951
952 reg = mmio_read_32(CPG_PLL0CR);
953 reg &= ~((uint32_t) 1 << 12);
954 mmio_write_32(CPG_PLL0CR, reg);
955 }
956#if (RCAR_LOSSY_ENABLE == 1)
957 NOTICE("BL2: Lossy Decomp areas\n");
Marek Vasut4d693c22018-10-11 16:53:58 +0200958
959 fcnlnode = fdt_add_subnode(fdt, 0, "reserved-memory");
960 if (fcnlnode < 0) {
961 NOTICE("BL2: Cannot create reserved mem node (ret=%i)\n",
962 fcnlnode);
963 panic();
964 }
965
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200966 bl2_lossy_setting(0, LOSSY_ST_ADDR0, LOSSY_END_ADDR0,
Marek Vasut4d693c22018-10-11 16:53:58 +0200967 LOSSY_FMT0, LOSSY_ENA_DIS0, fcnlnode);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200968 bl2_lossy_setting(1, LOSSY_ST_ADDR1, LOSSY_END_ADDR1,
Marek Vasut4d693c22018-10-11 16:53:58 +0200969 LOSSY_FMT1, LOSSY_ENA_DIS1, fcnlnode);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200970 bl2_lossy_setting(2, LOSSY_ST_ADDR2, LOSSY_END_ADDR2,
Marek Vasut4d693c22018-10-11 16:53:58 +0200971 LOSSY_FMT2, LOSSY_ENA_DIS2, fcnlnode);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200972#endif
973
Marek Vasut93c85fc2018-10-02 20:45:18 +0200974 fdt_pack(fdt);
975 NOTICE("BL2: FDT at %p\n", fdt);
976
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200977 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
978 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8)
979 rcar_io_emmc_setup();
980 else
981 rcar_io_setup();
982}
983
984void bl2_el3_plat_arch_setup(void)
985{
986#if RCAR_BL2_DCACHE == 1
987 NOTICE("BL2: D-Cache enable\n");
988 rcar_configure_mmu_el3(BL2_BASE,
Marek Vasut2e032c02018-12-26 15:57:08 +0100989 BL2_END - BL2_BASE,
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200990 BL2_RO_BASE, BL2_RO_LIMIT
991#if USE_COHERENT_MEM
992 , BL2_COHERENT_RAM_BASE, BL2_COHERENT_RAM_LIMIT
993#endif
994 );
995#endif
996}
997
998void bl2_platform_setup(void)
999{
1000
1001}
Marek Vasut1eca7782018-12-28 20:12:13 +01001002
1003static void bl2_init_generic_timer(void)
1004{
Valentine Barshakf2184142018-10-30 02:06:17 +03001005/* FIXME: V3M 16.666 MHz ? */
Marek Vasut4ae342c2019-01-05 13:56:03 +01001006#if RCAR_LSI == RCAR_D3
1007 uint32_t reg_cntfid = EXTAL_DRAAK;
1008#elif RCAR_LSI == RCAR_E3
Marek Vasut1eca7782018-12-28 20:12:13 +01001009 uint32_t reg_cntfid = EXTAL_EBISU;
1010#else /* RCAR_LSI == RCAR_E3 */
1011 uint32_t reg;
1012 uint32_t reg_cntfid;
1013 uint32_t modemr;
1014 uint32_t modemr_pll;
1015 uint32_t board_type;
1016 uint32_t board_rev;
1017 uint32_t pll_table[] = {
1018 EXTAL_MD14_MD13_TYPE_0, /* MD14/MD13 : 0b00 */
1019 EXTAL_MD14_MD13_TYPE_1, /* MD14/MD13 : 0b01 */
1020 EXTAL_MD14_MD13_TYPE_2, /* MD14/MD13 : 0b10 */
1021 EXTAL_MD14_MD13_TYPE_3 /* MD14/MD13 : 0b11 */
1022 };
1023
1024 modemr = mmio_read_32(RCAR_MODEMR);
1025 modemr_pll = (modemr & MODEMR_BOOT_PLL_MASK);
1026
1027 /* Set frequency data in CNTFID0 */
1028 reg_cntfid = pll_table[modemr_pll >> MODEMR_BOOT_PLL_SHIFT];
Marek Vasut9cadc782019-08-06 19:13:22 +02001029 reg = mmio_read_32(RCAR_PRR) & (PRR_PRODUCT_MASK | PRR_CUT_MASK);
Marek Vasut1eca7782018-12-28 20:12:13 +01001030 switch (modemr_pll) {
1031 case MD14_MD13_TYPE_0:
1032 rcar_get_board_type(&board_type, &board_rev);
1033 if (BOARD_SALVATOR_XS == board_type) {
1034 reg_cntfid = EXTAL_SALVATOR_XS;
1035 }
1036 break;
1037 case MD14_MD13_TYPE_3:
Marek Vasut9cadc782019-08-06 19:13:22 +02001038 if (PRR_PRODUCT_H3_CUT10 == reg) {
Marek Vasut1eca7782018-12-28 20:12:13 +01001039 reg_cntfid = reg_cntfid >> 1U;
1040 }
1041 break;
1042 default:
1043 /* none */
1044 break;
1045 }
1046#endif /* RCAR_LSI == RCAR_E3 */
1047 /* Update memory mapped and register based freqency */
1048 write_cntfrq_el0((u_register_t )reg_cntfid);
1049 mmio_write_32(ARM_SYS_CNTCTL_BASE + (uintptr_t)CNTFID_OFF, reg_cntfid);
1050 /* Enable counter */
1051 mmio_setbits_32(RCAR_CNTC_BASE + (uintptr_t)CNTCR_OFF,
1052 (uint32_t)CNTCR_EN);
1053}