blob: b4762f33098d5c73038fa9468559eb4b9b5e37b6 [file] [log] [blame]
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02001/*
Marek Vasut0aa268e2019-05-18 19:29:16 +02002 * Copyright (c) 2018-2019, 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
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)
Marek Vasut9cadc782019-08-06 19:13:22 +020068#define TARGET_PRODUCT PRR_PRODUCT_H3
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020069#define TARGET_NAME "R-Car H3"
70#elif RCAR_LSI == RCAR_M3
Marek Vasut9cadc782019-08-06 19:13:22 +020071#define TARGET_PRODUCT PRR_PRODUCT_M3
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020072#define TARGET_NAME "R-Car M3"
73#elif RCAR_LSI == RCAR_M3N
Marek Vasut9cadc782019-08-06 19:13:22 +020074#define TARGET_PRODUCT PRR_PRODUCT_M3N
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020075#define TARGET_NAME "R-Car M3N"
Valentine Barshakf2184142018-10-30 02:06:17 +030076#elif RCAR_LSI == RCAR_V3M
Marek Vasut9cadc782019-08-06 19:13:22 +020077#define TARGET_PRODUCT PRR_PRODUCT_V3M
Valentine Barshakf2184142018-10-30 02:06:17 +030078#define TARGET_NAME "R-Car V3M"
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020079#elif RCAR_LSI == RCAR_E3
Marek Vasut9cadc782019-08-06 19:13:22 +020080#define TARGET_PRODUCT PRR_PRODUCT_E3
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020081#define TARGET_NAME "R-Car E3"
Marek Vasut4ae342c2019-01-05 13:56:03 +010082#elif RCAR_LSI == RCAR_D3
Marek Vasut9cadc782019-08-06 19:13:22 +020083#define TARGET_PRODUCT PRR_PRODUCT_D3
Marek Vasut4ae342c2019-01-05 13:56:03 +010084#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);
Marek Vasut9cadc782019-08-06 19:13:22 +0200241 product_cut = reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK);
242 product = reg & PRR_PRODUCT_MASK;
243 cut = reg & PRR_CUT_MASK;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200244
Marek Vasut9cadc782019-08-06 19:13:22 +0200245 if (product == PRR_PRODUCT_M3 && PRR_PRODUCT_30 > cut)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200246 goto tlb;
247
Marek Vasut9cadc782019-08-06 19:13:22 +0200248 if (product == PRR_PRODUCT_H3 && PRR_PRODUCT_20 > cut)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200249 goto tlb;
250
Marek Vasut9cadc782019-08-06 19:13:22 +0200251 if (product == PRR_PRODUCT_D3)
Marek Vasut4ae342c2019-01-05 13:56:03 +0100252 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
Marek Vasut9cadc782019-08-06 19:13:22 +0200264 if (product_cut == PRR_PRODUCT_H3_CUT20) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200265 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);
Marek Vasut9cadc782019-08-06 19:13:22 +0200271 } else if (product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_10) ||
272 product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_11)) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200273 mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE);
274 mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE);
Marek Vasut9cadc782019-08-06 19:13:22 +0200275 } else if ((product_cut == (PRR_PRODUCT_E3 | PRR_PRODUCT_10)) ||
276 (product_cut == (PRR_PRODUCT_E3 | PRR_PRODUCT_11))) {
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
Marek Vasut9cadc782019-08-06 19:13:22 +0200282 if (product_cut == (PRR_PRODUCT_H3_CUT20) ||
283 product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_10) ||
284 product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_11) ||
285 product_cut == (PRR_PRODUCT_E3 | PRR_PRODUCT_10)) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200286 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
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100411static void bl2_populate_compatible_string(void *dt)
Marek Vasuta987b002018-10-11 16:15:41 +0200412{
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:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100422 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200423 "renesas,salvator-x");
424 break;
425 case BOARD_SALVATOR_XS:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100426 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200427 "renesas,salvator-xs");
428 break;
429 case BOARD_STARTER_KIT:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100430 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200431 "renesas,m3ulcb");
432 break;
433 case BOARD_STARTER_KIT_PRE:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100434 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200435 "renesas,h3ulcb");
436 break;
Valentine Barshakf2184142018-10-30 02:06:17 +0300437 case BOARD_EAGLE:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100438 ret = fdt_setprop_string(dt, 0, "compatible",
Valentine Barshakf2184142018-10-30 02:06:17 +0300439 "renesas,eagle");
440 break;
Marek Vasuta987b002018-10-11 16:15:41 +0200441 case BOARD_EBISU:
442 case BOARD_EBISU_4D:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100443 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200444 "renesas,ebisu");
445 break;
Marek Vasut4ae342c2019-01-05 13:56:03 +0100446 case BOARD_DRAAK:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100447 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasut4ae342c2019-01-05 13:56:03 +0100448 "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);
Marek Vasut9cadc782019-08-06 19:13:22 +0200461 switch (reg & PRR_PRODUCT_MASK) {
462 case PRR_PRODUCT_H3:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100463 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200464 "renesas,r8a7795");
465 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200466 case PRR_PRODUCT_M3:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100467 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200468 "renesas,r8a7796");
469 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200470 case PRR_PRODUCT_M3N:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100471 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200472 "renesas,r8a77965");
473 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200474 case PRR_PRODUCT_V3M:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100475 ret = fdt_appendprop_string(dt, 0, "compatible",
Valentine Barshakf2184142018-10-30 02:06:17 +0300476 "renesas,r8a77970");
477 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200478 case PRR_PRODUCT_E3:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100479 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200480 "renesas,r8a77990");
481 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200482 case PRR_PRODUCT_D3:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100483 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasut4ae342c2019-01-05 13:56:03 +0100484 "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) {
Marek Vasut9cadc782019-08-06 19:13:22 +0200575 case PRR_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 Vasut9cadc782019-08-06 19:13:22 +0200597 case PRR_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
Marek Vasut9cadc782019-08-06 19:13:22 +0200609 case PRR_PRODUCT_M3N:
Marek Vasut9963f702018-10-02 15:09:04 +0200610 /* 2GB(1GBx2) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200611 dram_config[1] = 0x80000000ULL;
Marek Vasut9963f702018-10-02 15:09:04 +0200612 break;
613
Marek Vasut9cadc782019-08-06 19:13:22 +0200614 case PRR_PRODUCT_V3M:
Valentine Barshakf2184142018-10-30 02:06:17 +0300615 /* 1GB(512MBx2) */
616 dram_config[1] = 0x40000000ULL;
617 break;
618
Marek Vasut9cadc782019-08-06 19:13:22 +0200619 case PRR_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
Marek Vasut9cadc782019-08-06 19:13:22 +0200632 case PRR_PRODUCT_D3:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100633 /* 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();
Marek Vasut0aa268e2019-05-18 19:29:16 +0200689 rcar_console_boot_init();
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200690 }
691
692 plat_rcar_gic_driver_init();
693 plat_rcar_gic_init();
694 rcar_swdt_init();
695
696 /* FIQ interrupts are taken to EL3 */
697 write_scr_el3(read_scr_el3() | SCR_FIQ_BIT);
698
699 write_daifclr(DAIF_FIQ_BIT);
700
701 reg = read_midr();
702 midr = reg & (MIDR_PN_MASK << MIDR_PN_SHIFT);
703 switch (midr) {
704 case MIDR_CA57:
705 str = cpu_ca57;
706 break;
707 case MIDR_CA53:
708 str = cpu_ca53;
709 break;
710 default:
711 str = unknown;
712 break;
713 }
714
715 NOTICE("BL2: R-Car Gen3 Initial Program Loader(%s) Rev.%s\n", str,
716 version_of_renesas);
717
718 reg = mmio_read_32(RCAR_PRR);
Marek Vasut9cadc782019-08-06 19:13:22 +0200719 product_cut = reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK);
720 product = reg & PRR_PRODUCT_MASK;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200721
722 switch (product) {
Marek Vasut9cadc782019-08-06 19:13:22 +0200723 case PRR_PRODUCT_H3:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200724 str = product_h3;
725 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200726 case PRR_PRODUCT_M3:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200727 str = product_m3;
728 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200729 case PRR_PRODUCT_M3N:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200730 str = product_m3n;
731 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200732 case PRR_PRODUCT_V3M:
Valentine Barshakf2184142018-10-30 02:06:17 +0300733 str = product_v3m;
734 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200735 case PRR_PRODUCT_E3:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200736 str = product_e3;
737 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200738 case PRR_PRODUCT_D3:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100739 str = product_d3;
740 break;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200741 default:
742 str = unknown;
743 break;
744 }
745
Marek Vasut9cadc782019-08-06 19:13:22 +0200746 if ((PRR_PRODUCT_M3 == product) &&
747 (PRR_PRODUCT_20 == (reg & RCAR_MAJOR_MASK))) {
748 if (RCAR_M3_CUT_VER11 == (reg & PRR_CUT_MASK)) {
Marek Vasut3af20052019-02-25 14:57:08 +0100749 /* M3 Ver.1.1 or Ver.1.2 */
750 NOTICE("BL2: PRR is R-Car %s Ver.1.1 / Ver.1.2\n",
751 str);
752 } else {
753 NOTICE("BL2: PRR is R-Car %s Ver.1.%d\n",
754 str,
755 (reg & RCAR_MINOR_MASK) + RCAR_M3_MINOR_OFFSET);
756 }
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200757 } else {
758 major = (reg & RCAR_MAJOR_MASK) >> RCAR_MAJOR_SHIFT;
759 major = major + RCAR_MAJOR_OFFSET;
760 minor = reg & RCAR_MINOR_MASK;
761 NOTICE("BL2: PRR is R-Car %s Ver.%d.%d\n", str, major, minor);
762 }
763
Marek Vasut9cadc782019-08-06 19:13:22 +0200764 if (product == PRR_PRODUCT_E3) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200765 reg = mmio_read_32(RCAR_MODEMR);
766 sscg = reg & RCAR_SSCG_MASK;
767 str = sscg == RCAR_SSCG_ENABLE ? sscg_on : sscg_off;
768 NOTICE("BL2: %s\n", str);
769 }
770
771 rcar_get_board_type(&type, &rev);
772
773 switch (type) {
774 case BOARD_SALVATOR_X:
775 case BOARD_KRIEK:
776 case BOARD_STARTER_KIT:
777 case BOARD_SALVATOR_XS:
778 case BOARD_EBISU:
779 case BOARD_STARTER_KIT_PRE:
780 case BOARD_EBISU_4D:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100781 case BOARD_DRAAK:
Valentine Barshakf2184142018-10-30 02:06:17 +0300782 case BOARD_EAGLE:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200783 break;
784 default:
785 type = BOARD_UNKNOWN;
786 break;
787 }
788
789 if (type == BOARD_UNKNOWN || rev == BOARD_REV_UNKNOWN)
790 NOTICE("BL2: Board is %s Rev.---\n", GET_BOARD_NAME(type));
791 else {
792 NOTICE("BL2: Board is %s Rev.%d.%d\n",
793 GET_BOARD_NAME(type),
794 GET_BOARD_MAJOR(rev), GET_BOARD_MINOR(rev));
795 }
796
797#if RCAR_LSI != RCAR_AUTO
798 if (product != TARGET_PRODUCT) {
799 ERROR("BL2: IPL was been built for the %s.\n", TARGET_NAME);
800 ERROR("BL2: Please write the correct IPL to flash memory.\n");
801 panic();
802 }
803#endif
804 rcar_avs_init();
805 rcar_avs_setting();
806
807 switch (boot_dev) {
808 case MODEMR_BOOT_DEV_HYPERFLASH160:
809 str = boot_hyper160;
810 break;
811 case MODEMR_BOOT_DEV_HYPERFLASH80:
812 str = boot_hyper80;
813 break;
814 case MODEMR_BOOT_DEV_QSPI_FLASH40:
815 str = boot_qspi40;
816 break;
817 case MODEMR_BOOT_DEV_QSPI_FLASH80:
818 str = boot_qspi80;
819 break;
820 case MODEMR_BOOT_DEV_EMMC_25X1:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100821#if RCAR_LSI == RCAR_D3
822 ERROR("BL2: Failed to Initialize. eMMC is not supported.\n");
823 panic();
824#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200825 str = boot_emmc25x1;
826 break;
827 case MODEMR_BOOT_DEV_EMMC_50X8:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100828#if RCAR_LSI == RCAR_D3
829 ERROR("BL2: Failed to Initialize. eMMC is not supported.\n");
830 panic();
831#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200832 str = boot_emmc50x8;
833 break;
834 default:
835 str = unknown;
836 break;
837 }
838 NOTICE("BL2: Boot device is %s\n", str);
839
840 rcar_avs_setting();
841 reg = rcar_rom_get_lcs(&lcs);
842 if (reg) {
843 str = unknown;
844 goto lcm_state;
845 }
846
847 switch (lcs) {
848 case LCS_CM:
849 str = lcs_cm;
850 break;
851 case LCS_DM:
852 str = lcs_dm;
853 break;
854 case LCS_SD:
855 str = lcs_sd;
856 break;
857 case LCS_SE:
858 str = lcs_secure;
859 break;
860 case LCS_FA:
861 str = lcs_fa;
862 break;
863 default:
864 str = unknown;
865 break;
866 }
867
868lcm_state:
869 NOTICE("BL2: LCM state is %s\n", str);
870
871 rcar_avs_end();
872 is_ddr_backup_mode();
873
874 bl2_tzram_layout.total_base = BL31_BASE;
875 bl2_tzram_layout.total_size = BL31_LIMIT - BL31_BASE;
876
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200877 if (boot_cpu == MODEMR_BOOT_CPU_CA57 ||
878 boot_cpu == MODEMR_BOOT_CPU_CA53) {
879 ret = rcar_dram_init();
880 if (ret) {
881 NOTICE("BL2: Failed to DRAM initialize (%d).\n", ret);
882 panic();
883 }
884 rcar_qos_init();
885 }
886
Marek Vasut93c85fc2018-10-02 20:45:18 +0200887 /* Set up FDT */
888 ret = fdt_create_empty_tree(fdt, sizeof(fdt_blob));
889 if (ret) {
890 NOTICE("BL2: Cannot allocate FDT for U-Boot (ret=%i)\n", ret);
891 panic();
892 }
893
Marek Vasuta987b002018-10-11 16:15:41 +0200894 /* Add platform compatible string */
895 bl2_populate_compatible_string(fdt);
896
Marek Vasut63659fd2018-10-02 15:12:15 +0200897 /* Print DRAM layout */
898 bl2_advertise_dram_size(product);
899
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200900 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
901 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8) {
902 if (rcar_emmc_init() != EMMC_SUCCESS) {
903 NOTICE("BL2: Failed to eMMC driver initialize.\n");
904 panic();
905 }
906 rcar_emmc_memcard_power(EMMC_POWER_ON);
907 if (rcar_emmc_mount() != EMMC_SUCCESS) {
908 NOTICE("BL2: Failed to eMMC mount operation.\n");
909 panic();
910 }
911 } else {
912 rcar_rpc_init();
913 rcar_dma_init();
914 }
915
916 reg = mmio_read_32(RST_WDTRSTCR);
917 reg &= ~WDTRSTCR_RWDT_RSTMSK;
918 reg |= WDTRSTCR_PASSWORD;
919 mmio_write_32(RST_WDTRSTCR, reg);
920
921 mmio_write_32(CPG_CPGWPR, CPGWPR_PASSWORD);
922 mmio_write_32(CPG_CPGWPCR, CPGWPCR_PASSWORD);
923
924 reg = mmio_read_32(RCAR_PRR);
925 if ((reg & RCAR_CPU_MASK_CA57) == RCAR_CPU_HAVE_CA57)
926 mmio_write_32(CPG_CA57DBGRCR,
927 DBGCPUPREN | mmio_read_32(CPG_CA57DBGRCR));
928
929 if ((reg & RCAR_CPU_MASK_CA53) == RCAR_CPU_HAVE_CA53)
930 mmio_write_32(CPG_CA53DBGRCR,
931 DBGCPUPREN | mmio_read_32(CPG_CA53DBGRCR));
932
Marek Vasut9cadc782019-08-06 19:13:22 +0200933 if (product_cut == PRR_PRODUCT_H3_CUT10) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200934 reg = mmio_read_32(CPG_PLL2CR);
935 reg &= ~((uint32_t) 1 << 5);
936 mmio_write_32(CPG_PLL2CR, reg);
937
938 reg = mmio_read_32(CPG_PLL4CR);
939 reg &= ~((uint32_t) 1 << 5);
940 mmio_write_32(CPG_PLL4CR, reg);
941
942 reg = mmio_read_32(CPG_PLL0CR);
943 reg &= ~((uint32_t) 1 << 12);
944 mmio_write_32(CPG_PLL0CR, reg);
945 }
946#if (RCAR_LOSSY_ENABLE == 1)
947 NOTICE("BL2: Lossy Decomp areas\n");
Marek Vasut4d693c22018-10-11 16:53:58 +0200948
949 fcnlnode = fdt_add_subnode(fdt, 0, "reserved-memory");
950 if (fcnlnode < 0) {
951 NOTICE("BL2: Cannot create reserved mem node (ret=%i)\n",
952 fcnlnode);
953 panic();
954 }
955
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200956 bl2_lossy_setting(0, LOSSY_ST_ADDR0, LOSSY_END_ADDR0,
Marek Vasut4d693c22018-10-11 16:53:58 +0200957 LOSSY_FMT0, LOSSY_ENA_DIS0, fcnlnode);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200958 bl2_lossy_setting(1, LOSSY_ST_ADDR1, LOSSY_END_ADDR1,
Marek Vasut4d693c22018-10-11 16:53:58 +0200959 LOSSY_FMT1, LOSSY_ENA_DIS1, fcnlnode);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200960 bl2_lossy_setting(2, LOSSY_ST_ADDR2, LOSSY_END_ADDR2,
Marek Vasut4d693c22018-10-11 16:53:58 +0200961 LOSSY_FMT2, LOSSY_ENA_DIS2, fcnlnode);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200962#endif
963
Marek Vasut93c85fc2018-10-02 20:45:18 +0200964 fdt_pack(fdt);
965 NOTICE("BL2: FDT at %p\n", fdt);
966
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200967 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
968 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8)
969 rcar_io_emmc_setup();
970 else
971 rcar_io_setup();
972}
973
974void bl2_el3_plat_arch_setup(void)
975{
976#if RCAR_BL2_DCACHE == 1
977 NOTICE("BL2: D-Cache enable\n");
978 rcar_configure_mmu_el3(BL2_BASE,
Marek Vasut2e032c02018-12-26 15:57:08 +0100979 BL2_END - BL2_BASE,
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200980 BL2_RO_BASE, BL2_RO_LIMIT
981#if USE_COHERENT_MEM
982 , BL2_COHERENT_RAM_BASE, BL2_COHERENT_RAM_LIMIT
983#endif
984 );
985#endif
986}
987
988void bl2_platform_setup(void)
989{
990
991}
Marek Vasut1eca7782018-12-28 20:12:13 +0100992
993static void bl2_init_generic_timer(void)
994{
Valentine Barshakf2184142018-10-30 02:06:17 +0300995/* FIXME: V3M 16.666 MHz ? */
Marek Vasut4ae342c2019-01-05 13:56:03 +0100996#if RCAR_LSI == RCAR_D3
997 uint32_t reg_cntfid = EXTAL_DRAAK;
998#elif RCAR_LSI == RCAR_E3
Marek Vasut1eca7782018-12-28 20:12:13 +0100999 uint32_t reg_cntfid = EXTAL_EBISU;
1000#else /* RCAR_LSI == RCAR_E3 */
1001 uint32_t reg;
1002 uint32_t reg_cntfid;
1003 uint32_t modemr;
1004 uint32_t modemr_pll;
1005 uint32_t board_type;
1006 uint32_t board_rev;
1007 uint32_t pll_table[] = {
1008 EXTAL_MD14_MD13_TYPE_0, /* MD14/MD13 : 0b00 */
1009 EXTAL_MD14_MD13_TYPE_1, /* MD14/MD13 : 0b01 */
1010 EXTAL_MD14_MD13_TYPE_2, /* MD14/MD13 : 0b10 */
1011 EXTAL_MD14_MD13_TYPE_3 /* MD14/MD13 : 0b11 */
1012 };
1013
1014 modemr = mmio_read_32(RCAR_MODEMR);
1015 modemr_pll = (modemr & MODEMR_BOOT_PLL_MASK);
1016
1017 /* Set frequency data in CNTFID0 */
1018 reg_cntfid = pll_table[modemr_pll >> MODEMR_BOOT_PLL_SHIFT];
Marek Vasut9cadc782019-08-06 19:13:22 +02001019 reg = mmio_read_32(RCAR_PRR) & (PRR_PRODUCT_MASK | PRR_CUT_MASK);
Marek Vasut1eca7782018-12-28 20:12:13 +01001020 switch (modemr_pll) {
1021 case MD14_MD13_TYPE_0:
1022 rcar_get_board_type(&board_type, &board_rev);
1023 if (BOARD_SALVATOR_XS == board_type) {
1024 reg_cntfid = EXTAL_SALVATOR_XS;
1025 }
1026 break;
1027 case MD14_MD13_TYPE_3:
Marek Vasut9cadc782019-08-06 19:13:22 +02001028 if (PRR_PRODUCT_H3_CUT10 == reg) {
Marek Vasut1eca7782018-12-28 20:12:13 +01001029 reg_cntfid = reg_cntfid >> 1U;
1030 }
1031 break;
1032 default:
1033 /* none */
1034 break;
1035 }
1036#endif /* RCAR_LSI == RCAR_E3 */
1037 /* Update memory mapped and register based freqency */
1038 write_cntfrq_el0((u_register_t )reg_cntfid);
1039 mmio_write_32(ARM_SYS_CNTCTL_BASE + (uintptr_t)CNTFID_OFF, reg_cntfid);
1040 /* Enable counter */
1041 mmio_setbits_32(RCAR_CNTC_BASE + (uintptr_t)CNTCR_OFF,
1042 (uint32_t)CNTCR_EN);
1043}