blob: add2a4f9bfd358c8475492435ad7bf1f88465fcb [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>
Toshiyuki Ogasahara04f16282019-12-13 14:43:52 +090019#include <drivers/io/io_driver.h>
20#include <drivers/io/io_storage.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000021#include <lib/mmio.h>
22#include <lib/xlat_tables/xlat_tables_defs.h>
23#include <plat/common/platform.h>
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020024
25#include "avs_driver.h"
26#include "boot_init_dram.h"
27#include "cpg_registers.h"
28#include "board.h"
29#include "emmc_def.h"
30#include "emmc_hal.h"
31#include "emmc_std.h"
32
33#if PMIC_ROHM_BD9571 && RCAR_SYSTEM_RESET_KEEPON_DDR
34#include "iic_dvfs.h"
35#endif
36
37#include "io_common.h"
Toshiyuki Ogasahara04f16282019-12-13 14:43:52 +090038#include "io_rcar.h"
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020039#include "qos_init.h"
40#include "rcar_def.h"
41#include "rcar_private.h"
42#include "rcar_version.h"
43#include "rom_api.h"
44
Madhukar Pappireddyfc9b4112019-12-23 14:49:52 -060045#if RCAR_BL2_DCACHE == 1
46/*
47 * Following symbols are only used during plat_arch_setup() only
48 * when RCAR_BL2_DCACHE is enabled.
49 */
50static const uint64_t BL2_RO_BASE = BL_CODE_BASE;
51static const uint64_t BL2_RO_LIMIT = BL_CODE_END;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020052
53#if USE_COHERENT_MEM
Madhukar Pappireddyfc9b4112019-12-23 14:49:52 -060054static const uint64_t BL2_COHERENT_RAM_BASE = BL_COHERENT_RAM_BASE;
55static const uint64_t BL2_COHERENT_RAM_LIMIT = BL_COHERENT_RAM_END;
56#endif
57
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020058#endif
59
60extern void plat_rcar_gic_driver_init(void);
61extern void plat_rcar_gic_init(void);
62extern void bl2_enter_bl31(const struct entry_point_info *bl_ep_info);
63extern void bl2_system_cpg_init(void);
64extern void bl2_secure_setting(void);
65extern void bl2_cpg_init(void);
66extern void rcar_io_emmc_setup(void);
67extern void rcar_io_setup(void);
68extern void rcar_swdt_release(void);
69extern void rcar_swdt_init(void);
70extern void rcar_rpc_init(void);
71extern void rcar_pfc_init(void);
72extern void rcar_dma_init(void);
73
Marek Vasut1eca7782018-12-28 20:12:13 +010074static void bl2_init_generic_timer(void);
75
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020076/* R-Car Gen3 product check */
77#if (RCAR_LSI == RCAR_H3) || (RCAR_LSI == RCAR_H3N)
Marek Vasut9cadc782019-08-06 19:13:22 +020078#define TARGET_PRODUCT PRR_PRODUCT_H3
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020079#define TARGET_NAME "R-Car H3"
80#elif RCAR_LSI == RCAR_M3
Marek Vasut9cadc782019-08-06 19:13:22 +020081#define TARGET_PRODUCT PRR_PRODUCT_M3
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020082#define TARGET_NAME "R-Car M3"
83#elif RCAR_LSI == RCAR_M3N
Marek Vasut9cadc782019-08-06 19:13:22 +020084#define TARGET_PRODUCT PRR_PRODUCT_M3N
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020085#define TARGET_NAME "R-Car M3N"
Valentine Barshakf2184142018-10-30 02:06:17 +030086#elif RCAR_LSI == RCAR_V3M
Marek Vasut9cadc782019-08-06 19:13:22 +020087#define TARGET_PRODUCT PRR_PRODUCT_V3M
Valentine Barshakf2184142018-10-30 02:06:17 +030088#define TARGET_NAME "R-Car V3M"
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020089#elif RCAR_LSI == RCAR_E3
Marek Vasut9cadc782019-08-06 19:13:22 +020090#define TARGET_PRODUCT PRR_PRODUCT_E3
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020091#define TARGET_NAME "R-Car E3"
Marek Vasut4ae342c2019-01-05 13:56:03 +010092#elif RCAR_LSI == RCAR_D3
Marek Vasut9cadc782019-08-06 19:13:22 +020093#define TARGET_PRODUCT PRR_PRODUCT_D3
Marek Vasut4ae342c2019-01-05 13:56:03 +010094#define TARGET_NAME "R-Car D3"
Marek Vasut94cc0f82018-12-28 20:11:26 +010095#elif RCAR_LSI == RCAR_AUTO
Valentine Barshakf2184142018-10-30 02:06:17 +030096#define TARGET_NAME "R-Car H3/M3/M3N/V3M"
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020097#endif
98
99#if (RCAR_LSI == RCAR_E3)
100#define GPIO_INDT (GPIO_INDT6)
101#define GPIO_BKUP_TRG_SHIFT ((uint32_t)1U<<13U)
102#else
103#define GPIO_INDT (GPIO_INDT1)
104#define GPIO_BKUP_TRG_SHIFT ((uint32_t)1U<<8U)
105#endif
106
107CASSERT((PARAMS_BASE + sizeof(bl2_to_bl31_params_mem_t) + 0x100)
108 < (RCAR_SHARED_MEM_BASE + RCAR_SHARED_MEM_SIZE),
109 assert_bl31_params_do_not_fit_in_shared_memory);
110
111static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
112
Marek Vasut93c85fc2018-10-02 20:45:18 +0200113/* FDT with DRAM configuration */
114uint64_t fdt_blob[PAGE_SIZE_4KB / sizeof(uint64_t)];
115static void *fdt = (void *)fdt_blob;
116
117static void unsigned_num_print(unsigned long long int unum, unsigned int radix,
118 char *string)
119{
120 /* Just need enough space to store 64 bit decimal integer */
121 char num_buf[20];
122 int i = 0;
123 unsigned int rem;
124
125 do {
126 rem = unum % radix;
127 if (rem < 0xa)
128 num_buf[i] = '0' + rem;
129 else
130 num_buf[i] = 'a' + (rem - 0xa);
131 i++;
132 unum /= radix;
133 } while (unum > 0U);
134
135 while (--i >= 0)
136 *string++ = num_buf[i];
Marek Vasut64299332020-04-11 19:02:29 +0200137 *string = 0;
Marek Vasut93c85fc2018-10-02 20:45:18 +0200138}
139
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200140#if (RCAR_LOSSY_ENABLE == 1)
141typedef struct bl2_lossy_info {
142 uint32_t magic;
143 uint32_t a0;
144 uint32_t b0;
145} bl2_lossy_info_t;
146
Marek Vasut4d693c22018-10-11 16:53:58 +0200147static void bl2_lossy_gen_fdt(uint32_t no, uint64_t start_addr,
148 uint64_t end_addr, uint32_t format,
149 uint32_t enable, int fcnlnode)
150{
151 const uint64_t fcnlsize = cpu_to_fdt64(end_addr - start_addr);
152 char nodename[40] = { 0 };
153 int ret, node;
154
155 /* Ignore undefined addresses */
156 if (start_addr == 0 && end_addr == 0)
157 return;
158
159 snprintf(nodename, sizeof(nodename), "lossy-decompression@");
160 unsigned_num_print(start_addr, 16, nodename + strlen(nodename));
161
162 node = ret = fdt_add_subnode(fdt, fcnlnode, nodename);
163 if (ret < 0) {
164 NOTICE("BL2: Cannot create FCNL node (ret=%i)\n", ret);
165 panic();
166 }
167
168 ret = fdt_setprop_string(fdt, node, "compatible",
169 "renesas,lossy-decompression");
170 if (ret < 0) {
171 NOTICE("BL2: Cannot add FCNL compat string (ret=%i)\n", ret);
172 panic();
173 }
174
175 ret = fdt_appendprop_string(fdt, node, "compatible",
176 "shared-dma-pool");
177 if (ret < 0) {
178 NOTICE("BL2: Cannot append FCNL compat string (ret=%i)\n", ret);
179 panic();
180 }
181
182 ret = fdt_setprop_u64(fdt, node, "reg", start_addr);
183 if (ret < 0) {
184 NOTICE("BL2: Cannot add FCNL reg prop (ret=%i)\n", ret);
185 panic();
186 }
187
188 ret = fdt_appendprop(fdt, node, "reg", &fcnlsize, sizeof(fcnlsize));
189 if (ret < 0) {
190 NOTICE("BL2: Cannot append FCNL reg size prop (ret=%i)\n", ret);
191 panic();
192 }
193
194 ret = fdt_setprop(fdt, node, "no-map", NULL, 0);
195 if (ret < 0) {
196 NOTICE("BL2: Cannot add FCNL no-map prop (ret=%i)\n", ret);
197 panic();
198 }
199
200 ret = fdt_setprop_u32(fdt, node, "renesas,formats", format);
201 if (ret < 0) {
202 NOTICE("BL2: Cannot add FCNL formats prop (ret=%i)\n", ret);
203 panic();
204 }
205}
206
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200207static void bl2_lossy_setting(uint32_t no, uint64_t start_addr,
208 uint64_t end_addr, uint32_t format,
Marek Vasut4d693c22018-10-11 16:53:58 +0200209 uint32_t enable, int fcnlnode)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200210{
211 bl2_lossy_info_t info;
212 uint32_t reg;
213
Marek Vasut4d693c22018-10-11 16:53:58 +0200214 bl2_lossy_gen_fdt(no, start_addr, end_addr, format, enable, fcnlnode);
215
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200216 reg = format | (start_addr >> 20);
217 mmio_write_32(AXI_DCMPAREACRA0 + 0x8 * no, reg);
218 mmio_write_32(AXI_DCMPAREACRB0 + 0x8 * no, end_addr >> 20);
219 mmio_write_32(AXI_DCMPAREACRA0 + 0x8 * no, reg | enable);
220
221 info.magic = 0x12345678U;
222 info.a0 = mmio_read_32(AXI_DCMPAREACRA0 + 0x8 * no);
223 info.b0 = mmio_read_32(AXI_DCMPAREACRB0 + 0x8 * no);
224
225 mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no, info.magic);
226 mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no + 0x4, info.a0);
227 mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no + 0x8, info.b0);
228
229 NOTICE(" Entry %d: DCMPAREACRAx:0x%x DCMPAREACRBx:0x%x\n", no,
230 mmio_read_32(AXI_DCMPAREACRA0 + 0x8 * no),
231 mmio_read_32(AXI_DCMPAREACRB0 + 0x8 * no));
232}
233#endif
234
235void bl2_plat_flush_bl31_params(void)
236{
237 uint32_t product_cut, product, cut;
238 uint32_t boot_dev, boot_cpu;
239 uint32_t lcs, reg, val;
240
241 reg = mmio_read_32(RCAR_MODEMR);
242 boot_dev = reg & MODEMR_BOOT_DEV_MASK;
243
244 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
245 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8)
246 emmc_terminate();
247
248 if ((reg & MODEMR_BOOT_CPU_MASK) != MODEMR_BOOT_CPU_CR7)
249 bl2_secure_setting();
250
251 reg = mmio_read_32(RCAR_PRR);
Marek Vasut9cadc782019-08-06 19:13:22 +0200252 product_cut = reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK);
253 product = reg & PRR_PRODUCT_MASK;
254 cut = reg & PRR_CUT_MASK;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200255
Marek Vasut9cadc782019-08-06 19:13:22 +0200256 if (product == PRR_PRODUCT_M3 && PRR_PRODUCT_30 > cut)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200257 goto tlb;
258
Marek Vasut9cadc782019-08-06 19:13:22 +0200259 if (product == PRR_PRODUCT_H3 && PRR_PRODUCT_20 > cut)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200260 goto tlb;
261
Marek Vasut9cadc782019-08-06 19:13:22 +0200262 if (product == PRR_PRODUCT_D3)
Marek Vasut4ae342c2019-01-05 13:56:03 +0100263 goto tlb;
264
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200265 /* Disable MFIS write protection */
266 mmio_write_32(MFISWPCNTR, MFISWPCNTR_PASSWORD | 1);
267
268tlb:
269 reg = mmio_read_32(RCAR_MODEMR);
270 boot_cpu = reg & MODEMR_BOOT_CPU_MASK;
271 if (boot_cpu != MODEMR_BOOT_CPU_CA57 &&
272 boot_cpu != MODEMR_BOOT_CPU_CA53)
273 goto mmu;
274
Marek Vasut9cadc782019-08-06 19:13:22 +0200275 if (product_cut == PRR_PRODUCT_H3_CUT20) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200276 mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE);
277 mmio_write_32(IPMMUVI1_IMSCTLR, IMSCTLR_DISCACHE);
278 mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE);
279 mmio_write_32(IPMMUPV1_IMSCTLR, IMSCTLR_DISCACHE);
280 mmio_write_32(IPMMUPV2_IMSCTLR, IMSCTLR_DISCACHE);
281 mmio_write_32(IPMMUPV3_IMSCTLR, IMSCTLR_DISCACHE);
Marek Vasut9cadc782019-08-06 19:13:22 +0200282 } else if (product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_10) ||
283 product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_11)) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200284 mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE);
285 mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE);
Marek Vasut9cadc782019-08-06 19:13:22 +0200286 } else if ((product_cut == (PRR_PRODUCT_E3 | PRR_PRODUCT_10)) ||
287 (product_cut == (PRR_PRODUCT_E3 | PRR_PRODUCT_11))) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200288 mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE);
Marek Vasute6208012018-12-31 16:48:04 +0100289 mmio_write_32(IPMMUVP0_IMSCTLR, IMSCTLR_DISCACHE);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200290 mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE);
291 }
292
Marek Vasut9cadc782019-08-06 19:13:22 +0200293 if (product_cut == (PRR_PRODUCT_H3_CUT20) ||
294 product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_10) ||
295 product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_11) ||
296 product_cut == (PRR_PRODUCT_E3 | PRR_PRODUCT_10)) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200297 mmio_write_32(IPMMUHC_IMSCTLR, IMSCTLR_DISCACHE);
298 mmio_write_32(IPMMURT_IMSCTLR, IMSCTLR_DISCACHE);
299 mmio_write_32(IPMMUMP_IMSCTLR, IMSCTLR_DISCACHE);
300
301 mmio_write_32(IPMMUDS0_IMSCTLR, IMSCTLR_DISCACHE);
302 mmio_write_32(IPMMUDS1_IMSCTLR, IMSCTLR_DISCACHE);
303 }
304
305mmu:
306 mmio_write_32(IPMMUMM_IMSCTLR, IPMMUMM_IMSCTLR_ENABLE);
307 mmio_write_32(IPMMUMM_IMAUXCTLR, IPMMUMM_IMAUXCTLR_NMERGE40_BIT);
308
309 val = rcar_rom_get_lcs(&lcs);
310 if (val) {
311 ERROR("BL2: Failed to get the LCS. (%d)\n", val);
312 panic();
313 }
314
315 if (lcs == LCS_SE)
316 mmio_clrbits_32(P_ARMREG_SEC_CTRL, P_ARMREG_SEC_CTRL_PROT);
317
318 rcar_swdt_release();
319 bl2_system_cpg_init();
320
321#if RCAR_BL2_DCACHE == 1
322 /* Disable data cache (clean and invalidate) */
323 disable_mmu_el3();
324#endif
325}
326
327static uint32_t is_ddr_backup_mode(void)
328{
329#if RCAR_SYSTEM_SUSPEND
330 static uint32_t reason = RCAR_COLD_BOOT;
331 static uint32_t once;
332
333#if PMIC_ROHM_BD9571 && RCAR_SYSTEM_RESET_KEEPON_DDR
334 uint8_t data;
335#endif
336 if (once)
337 return reason;
338
339 once = 1;
340 if ((mmio_read_32(GPIO_INDT) & GPIO_BKUP_TRG_SHIFT) == 0)
341 return reason;
342
343#if PMIC_ROHM_BD9571 && RCAR_SYSTEM_RESET_KEEPON_DDR
344 if (rcar_iic_dvfs_receive(PMIC, REG_KEEP10, &data)) {
345 ERROR("BL2: REG Keep10 READ ERROR.\n");
346 panic();
347 }
348
349 if (KEEP10_MAGIC != data)
350 reason = RCAR_WARM_BOOT;
351#else
352 reason = RCAR_WARM_BOOT;
353#endif
354 return reason;
355#else
356 return RCAR_COLD_BOOT;
357#endif
358}
359
360int bl2_plat_handle_pre_image_load(unsigned int image_id)
361{
362 u_register_t *boot_kind = (void *) BOOT_KIND_BASE;
363 bl_mem_params_node_t *bl_mem_params;
364
365 if (image_id != BL31_IMAGE_ID)
366 return 0;
367
368 bl_mem_params = get_bl_mem_params_node(image_id);
369
370 if (is_ddr_backup_mode() == RCAR_COLD_BOOT)
371 goto cold_boot;
372
373 *boot_kind = RCAR_WARM_BOOT;
374 flush_dcache_range(BOOT_KIND_BASE, sizeof(*boot_kind));
375
376 console_flush();
377 bl2_plat_flush_bl31_params();
378
379 /* will not return */
380 bl2_enter_bl31(&bl_mem_params->ep_info);
381
382cold_boot:
383 *boot_kind = RCAR_COLD_BOOT;
384 flush_dcache_range(BOOT_KIND_BASE, sizeof(*boot_kind));
385
386 return 0;
387}
388
Toshiyuki Ogasahara04f16282019-12-13 14:43:52 +0900389static uint64_t rcar_get_dest_addr_from_cert(uint32_t certid, uintptr_t *dest)
390{
391 uint32_t cert, len;
392 int ret;
393
394 ret = rcar_get_certificate(certid, &cert);
395 if (ret) {
396 ERROR("%s : cert file load error", __func__);
397 return 1;
398 }
399
400 rcar_read_certificate((uint64_t) cert, &len, dest);
401
402 return 0;
403}
404
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200405int bl2_plat_handle_post_image_load(unsigned int image_id)
406{
407 static bl2_to_bl31_params_mem_t *params;
408 bl_mem_params_node_t *bl_mem_params;
Toshiyuki Ogasahara04f16282019-12-13 14:43:52 +0900409 uintptr_t dest;
410 int ret;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200411
412 if (!params) {
413 params = (bl2_to_bl31_params_mem_t *) PARAMS_BASE;
414 memset((void *)PARAMS_BASE, 0, sizeof(*params));
415 }
416
417 bl_mem_params = get_bl_mem_params_node(image_id);
418
419 switch (image_id) {
420 case BL31_IMAGE_ID:
Toshiyuki Ogasahara04f16282019-12-13 14:43:52 +0900421 ret = rcar_get_dest_addr_from_cert(SOC_FW_CONTENT_CERT_ID,
422 &dest);
423 if (!ret)
424 bl_mem_params->image_info.image_base = dest;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200425 break;
426 case BL32_IMAGE_ID:
Toshiyuki Ogasahara04f16282019-12-13 14:43:52 +0900427 ret = rcar_get_dest_addr_from_cert(TRUSTED_OS_FW_CONTENT_CERT_ID,
428 &dest);
429 if (!ret)
430 bl_mem_params->image_info.image_base = dest;
431
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200432 memcpy(&params->bl32_ep_info, &bl_mem_params->ep_info,
433 sizeof(entry_point_info_t));
434 break;
435 case BL33_IMAGE_ID:
436 memcpy(&params->bl33_ep_info, &bl_mem_params->ep_info,
437 sizeof(entry_point_info_t));
438 break;
439 }
440
441 return 0;
442}
443
Marek Vasutc7077c62018-12-26 15:57:08 +0100444struct meminfo *bl2_plat_sec_mem_layout(void)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200445{
446 return &bl2_tzram_layout;
447}
448
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100449static void bl2_populate_compatible_string(void *dt)
Marek Vasuta987b002018-10-11 16:15:41 +0200450{
451 uint32_t board_type;
452 uint32_t board_rev;
453 uint32_t reg;
454 int ret;
455
Marek Vasut688251a2020-01-06 03:26:43 +0100456 fdt_setprop_u32(dt, 0, "#address-cells", 2);
457 fdt_setprop_u32(dt, 0, "#size-cells", 2);
458
Marek Vasuta987b002018-10-11 16:15:41 +0200459 /* Populate compatible string */
460 rcar_get_board_type(&board_type, &board_rev);
461 switch (board_type) {
462 case BOARD_SALVATOR_X:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100463 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200464 "renesas,salvator-x");
465 break;
466 case BOARD_SALVATOR_XS:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100467 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200468 "renesas,salvator-xs");
469 break;
470 case BOARD_STARTER_KIT:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100471 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200472 "renesas,m3ulcb");
473 break;
474 case BOARD_STARTER_KIT_PRE:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100475 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200476 "renesas,h3ulcb");
477 break;
Valentine Barshakf2184142018-10-30 02:06:17 +0300478 case BOARD_EAGLE:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100479 ret = fdt_setprop_string(dt, 0, "compatible",
Valentine Barshakf2184142018-10-30 02:06:17 +0300480 "renesas,eagle");
481 break;
Marek Vasuta987b002018-10-11 16:15:41 +0200482 case BOARD_EBISU:
483 case BOARD_EBISU_4D:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100484 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200485 "renesas,ebisu");
486 break;
Marek Vasut4ae342c2019-01-05 13:56:03 +0100487 case BOARD_DRAAK:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100488 ret = fdt_setprop_string(dt, 0, "compatible",
Marek Vasut4ae342c2019-01-05 13:56:03 +0100489 "renesas,draak");
490 break;
Marek Vasuta987b002018-10-11 16:15:41 +0200491 default:
492 NOTICE("BL2: Cannot set compatible string, board unsupported\n");
493 panic();
494 }
495
496 if (ret < 0) {
497 NOTICE("BL2: Cannot set compatible string (ret=%i)\n", ret);
498 panic();
499 }
500
501 reg = mmio_read_32(RCAR_PRR);
Marek Vasut9cadc782019-08-06 19:13:22 +0200502 switch (reg & PRR_PRODUCT_MASK) {
503 case PRR_PRODUCT_H3:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100504 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200505 "renesas,r8a7795");
506 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200507 case PRR_PRODUCT_M3:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100508 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200509 "renesas,r8a7796");
510 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200511 case PRR_PRODUCT_M3N:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100512 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200513 "renesas,r8a77965");
514 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200515 case PRR_PRODUCT_V3M:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100516 ret = fdt_appendprop_string(dt, 0, "compatible",
Valentine Barshakf2184142018-10-30 02:06:17 +0300517 "renesas,r8a77970");
518 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200519 case PRR_PRODUCT_E3:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100520 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasuta987b002018-10-11 16:15:41 +0200521 "renesas,r8a77990");
522 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200523 case PRR_PRODUCT_D3:
Justin Chadwell7d0e3ba2019-09-17 15:21:50 +0100524 ret = fdt_appendprop_string(dt, 0, "compatible",
Marek Vasut4ae342c2019-01-05 13:56:03 +0100525 "renesas,r8a77995");
526 break;
Marek Vasuta987b002018-10-11 16:15:41 +0200527 default:
528 NOTICE("BL2: Cannot set compatible string, SoC unsupported\n");
529 panic();
530 }
531
532 if (ret < 0) {
533 NOTICE("BL2: Cannot set compatible string (ret=%i)\n", ret);
534 panic();
535 }
536}
537
Marek Vasut6a6881a2018-10-02 20:43:09 +0200538static void bl2_advertise_dram_entries(uint64_t dram_config[8])
539{
Marek Vasut93c85fc2018-10-02 20:45:18 +0200540 char nodename[32] = { 0 };
Marek Vasut6a6881a2018-10-02 20:43:09 +0200541 uint64_t start, size;
Marek Vasut93c85fc2018-10-02 20:45:18 +0200542 uint64_t fdtsize;
543 int ret, node, chan;
Marek Vasut6a6881a2018-10-02 20:43:09 +0200544
545 for (chan = 0; chan < 4; chan++) {
546 start = dram_config[2 * chan];
547 size = dram_config[2 * chan + 1];
548 if (!size)
549 continue;
550
Marek Vasut89c17512019-03-30 04:01:41 +0100551 NOTICE("BL2: CH%d: %llx - %llx, %lld %siB\n",
552 chan, start, start + size - 1,
553 (size >> 30) ? : size >> 20,
554 (size >> 30) ? "G" : "M");
Marek Vasut6a6881a2018-10-02 20:43:09 +0200555 }
Marek Vasut93c85fc2018-10-02 20:45:18 +0200556
557 /*
558 * We add the DT nodes in reverse order here. The fdt_add_subnode()
559 * adds the DT node before the first existing DT node, so we have
560 * to add them in reverse order to get nodes sorted by address in
561 * the resulting DT.
562 */
563 for (chan = 3; chan >= 0; chan--) {
564 start = dram_config[2 * chan];
565 size = dram_config[2 * chan + 1];
566 if (!size)
567 continue;
568
569 /*
570 * Channel 0 is mapped in 32bit space and the first
571 * 128 MiB are reserved
572 */
573 if (chan == 0) {
574 start = 0x48000000;
575 size -= 0x8000000;
576 }
577
578 fdtsize = cpu_to_fdt64(size);
579
580 snprintf(nodename, sizeof(nodename), "memory@");
581 unsigned_num_print(start, 16, nodename + strlen(nodename));
582 node = ret = fdt_add_subnode(fdt, 0, nodename);
583 if (ret < 0)
584 goto err;
585
586 ret = fdt_setprop_string(fdt, node, "device_type", "memory");
587 if (ret < 0)
588 goto err;
589
590 ret = fdt_setprop_u64(fdt, node, "reg", start);
591 if (ret < 0)
592 goto err;
593
594 ret = fdt_appendprop(fdt, node, "reg", &fdtsize,
595 sizeof(fdtsize));
596 if (ret < 0)
597 goto err;
598 }
599
600 return;
601err:
602 NOTICE("BL2: Cannot add memory node to FDT (ret=%i)\n", ret);
603 panic();
Marek Vasut6a6881a2018-10-02 20:43:09 +0200604}
605
Marek Vasutb0e13592018-10-02 14:53:27 +0200606static void bl2_advertise_dram_size(uint32_t product)
Marek Vasut673bc322018-10-02 13:33:32 +0200607{
Marek Vasut6a6881a2018-10-02 20:43:09 +0200608 uint64_t dram_config[8] = {
609 [0] = 0x400000000ULL,
610 [2] = 0x500000000ULL,
611 [4] = 0x600000000ULL,
612 [6] = 0x700000000ULL,
613 };
614
Marek Vasut9963f702018-10-02 15:09:04 +0200615 switch (product) {
Marek Vasut9cadc782019-08-06 19:13:22 +0200616 case PRR_PRODUCT_H3:
Marek Vasut673bc322018-10-02 13:33:32 +0200617#if (RCAR_DRAM_LPDDR4_MEMCONF == 0)
618 /* 4GB(1GBx4) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200619 dram_config[1] = 0x40000000ULL;
620 dram_config[3] = 0x40000000ULL;
621 dram_config[5] = 0x40000000ULL;
622 dram_config[7] = 0x40000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200623#elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && \
624 (RCAR_DRAM_CHANNEL == 5) && \
625 (RCAR_DRAM_SPLIT == 2)
626 /* 4GB(2GBx2 2ch split) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200627 dram_config[1] = 0x80000000ULL;
628 dram_config[3] = 0x80000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200629#elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && (RCAR_DRAM_CHANNEL == 15)
630 /* 8GB(2GBx4: default) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200631 dram_config[1] = 0x80000000ULL;
632 dram_config[3] = 0x80000000ULL;
633 dram_config[5] = 0x80000000ULL;
634 dram_config[7] = 0x80000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200635#endif /* RCAR_DRAM_LPDDR4_MEMCONF == 0 */
Marek Vasut9963f702018-10-02 15:09:04 +0200636 break;
Marek Vasut673bc322018-10-02 13:33:32 +0200637
Marek Vasut9cadc782019-08-06 19:13:22 +0200638 case PRR_PRODUCT_M3:
Marek Vasut0208c942019-03-09 16:10:59 +0100639#if (RCAR_GEN3_ULCB == 1)
640 /* 2GB(1GBx2 2ch split) */
641 dram_config[1] = 0x40000000ULL;
642 dram_config[5] = 0x40000000ULL;
643#else
Marek Vasut9963f702018-10-02 15:09:04 +0200644 /* 4GB(2GBx2 2ch split) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200645 dram_config[1] = 0x80000000ULL;
646 dram_config[5] = 0x80000000ULL;
Marek Vasut0208c942019-03-09 16:10:59 +0100647#endif
Marek Vasut9963f702018-10-02 15:09:04 +0200648 break;
649
Marek Vasut9cadc782019-08-06 19:13:22 +0200650 case PRR_PRODUCT_M3N:
Marek Vasut9963f702018-10-02 15:09:04 +0200651 /* 2GB(1GBx2) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200652 dram_config[1] = 0x80000000ULL;
Marek Vasut9963f702018-10-02 15:09:04 +0200653 break;
654
Marek Vasut9cadc782019-08-06 19:13:22 +0200655 case PRR_PRODUCT_V3M:
Valentine Barshakf2184142018-10-30 02:06:17 +0300656 /* 1GB(512MBx2) */
657 dram_config[1] = 0x40000000ULL;
658 break;
659
Marek Vasut9cadc782019-08-06 19:13:22 +0200660 case PRR_PRODUCT_E3:
Marek Vasut673bc322018-10-02 13:33:32 +0200661#if (RCAR_DRAM_DDR3L_MEMCONF == 0)
662 /* 1GB(512MBx2) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200663 dram_config[1] = 0x40000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200664#elif (RCAR_DRAM_DDR3L_MEMCONF == 1)
665 /* 2GB(512MBx4) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200666 dram_config[1] = 0x80000000ULL;
Marek Vasut8cb12ec2018-10-02 13:51:19 +0200667#elif (RCAR_DRAM_DDR3L_MEMCONF == 2)
668 /* 4GB(1GBx4) */
Marek Vasut6a6881a2018-10-02 20:43:09 +0200669 dram_config[1] = 0x100000000ULL;
Marek Vasut673bc322018-10-02 13:33:32 +0200670#endif /* RCAR_DRAM_DDR3L_MEMCONF == 0 */
Marek Vasut9963f702018-10-02 15:09:04 +0200671 break;
Marek Vasut4ae342c2019-01-05 13:56:03 +0100672
Marek Vasut9cadc782019-08-06 19:13:22 +0200673 case PRR_PRODUCT_D3:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100674 /* 512MB */
675 dram_config[1] = 0x20000000ULL;
676 break;
Marek Vasut673bc322018-10-02 13:33:32 +0200677 }
Marek Vasut6a6881a2018-10-02 20:43:09 +0200678
679 bl2_advertise_dram_entries(dram_config);
Marek Vasut673bc322018-10-02 13:33:32 +0200680}
681
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200682void bl2_el3_early_platform_setup(u_register_t arg1, u_register_t arg2,
683 u_register_t arg3, u_register_t arg4)
684{
685 uint32_t reg, midr, lcs, boot_dev, boot_cpu, sscg, type, rev;
Marek Vasutb0e13592018-10-02 14:53:27 +0200686 uint32_t product, product_cut, major, minor;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200687 int32_t ret;
688 const char *str;
689 const char *unknown = "unknown";
690 const char *cpu_ca57 = "CA57";
691 const char *cpu_ca53 = "CA53";
692 const char *product_m3n = "M3N";
693 const char *product_h3 = "H3";
694 const char *product_m3 = "M3";
695 const char *product_e3 = "E3";
Marek Vasut4ae342c2019-01-05 13:56:03 +0100696 const char *product_d3 = "D3";
Valentine Barshakf2184142018-10-30 02:06:17 +0300697 const char *product_v3m = "V3M";
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200698 const char *lcs_secure = "SE";
699 const char *lcs_cm = "CM";
700 const char *lcs_dm = "DM";
701 const char *lcs_sd = "SD";
702 const char *lcs_fa = "FA";
703 const char *sscg_off = "PLL1 nonSSCG Clock select";
704 const char *sscg_on = "PLL1 SSCG Clock select";
705 const char *boot_hyper80 = "HyperFlash(80MHz)";
706 const char *boot_qspi40 = "QSPI Flash(40MHz)";
707 const char *boot_qspi80 = "QSPI Flash(80MHz)";
708 const char *boot_emmc25x1 = "eMMC(25MHz x1)";
709 const char *boot_emmc50x8 = "eMMC(50MHz x8)";
Marek Vasut4ae342c2019-01-05 13:56:03 +0100710#if (RCAR_LSI == RCAR_E3) || (RCAR_LSI == RCAR_D3)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200711 const char *boot_hyper160 = "HyperFlash(150MHz)";
712#else
713 const char *boot_hyper160 = "HyperFlash(160MHz)";
714#endif
Marek Vasut4d693c22018-10-11 16:53:58 +0200715#if (RCAR_LOSSY_ENABLE == 1)
716 int fcnlnode;
717#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200718
Marek Vasut1eca7782018-12-28 20:12:13 +0100719 bl2_init_generic_timer();
720
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200721 reg = mmio_read_32(RCAR_MODEMR);
722 boot_dev = reg & MODEMR_BOOT_DEV_MASK;
723 boot_cpu = reg & MODEMR_BOOT_CPU_MASK;
724
725 bl2_cpg_init();
726
727 if (boot_cpu == MODEMR_BOOT_CPU_CA57 ||
728 boot_cpu == MODEMR_BOOT_CPU_CA53) {
729 rcar_pfc_init();
Marek Vasut0aa268e2019-05-18 19:29:16 +0200730 rcar_console_boot_init();
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200731 }
732
733 plat_rcar_gic_driver_init();
734 plat_rcar_gic_init();
735 rcar_swdt_init();
736
737 /* FIQ interrupts are taken to EL3 */
738 write_scr_el3(read_scr_el3() | SCR_FIQ_BIT);
739
740 write_daifclr(DAIF_FIQ_BIT);
741
742 reg = read_midr();
743 midr = reg & (MIDR_PN_MASK << MIDR_PN_SHIFT);
744 switch (midr) {
745 case MIDR_CA57:
746 str = cpu_ca57;
747 break;
748 case MIDR_CA53:
749 str = cpu_ca53;
750 break;
751 default:
752 str = unknown;
753 break;
754 }
755
756 NOTICE("BL2: R-Car Gen3 Initial Program Loader(%s) Rev.%s\n", str,
757 version_of_renesas);
758
759 reg = mmio_read_32(RCAR_PRR);
Marek Vasut9cadc782019-08-06 19:13:22 +0200760 product_cut = reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK);
761 product = reg & PRR_PRODUCT_MASK;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200762
763 switch (product) {
Marek Vasut9cadc782019-08-06 19:13:22 +0200764 case PRR_PRODUCT_H3:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200765 str = product_h3;
766 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200767 case PRR_PRODUCT_M3:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200768 str = product_m3;
769 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200770 case PRR_PRODUCT_M3N:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200771 str = product_m3n;
772 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200773 case PRR_PRODUCT_V3M:
Valentine Barshakf2184142018-10-30 02:06:17 +0300774 str = product_v3m;
775 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200776 case PRR_PRODUCT_E3:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200777 str = product_e3;
778 break;
Marek Vasut9cadc782019-08-06 19:13:22 +0200779 case PRR_PRODUCT_D3:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100780 str = product_d3;
781 break;
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200782 default:
783 str = unknown;
784 break;
785 }
786
Marek Vasut9cadc782019-08-06 19:13:22 +0200787 if ((PRR_PRODUCT_M3 == product) &&
788 (PRR_PRODUCT_20 == (reg & RCAR_MAJOR_MASK))) {
789 if (RCAR_M3_CUT_VER11 == (reg & PRR_CUT_MASK)) {
Marek Vasut3af20052019-02-25 14:57:08 +0100790 /* M3 Ver.1.1 or Ver.1.2 */
791 NOTICE("BL2: PRR is R-Car %s Ver.1.1 / Ver.1.2\n",
792 str);
793 } else {
794 NOTICE("BL2: PRR is R-Car %s Ver.1.%d\n",
795 str,
796 (reg & RCAR_MINOR_MASK) + RCAR_M3_MINOR_OFFSET);
797 }
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200798 } else {
799 major = (reg & RCAR_MAJOR_MASK) >> RCAR_MAJOR_SHIFT;
800 major = major + RCAR_MAJOR_OFFSET;
801 minor = reg & RCAR_MINOR_MASK;
802 NOTICE("BL2: PRR is R-Car %s Ver.%d.%d\n", str, major, minor);
803 }
804
Marek Vasut9cadc782019-08-06 19:13:22 +0200805 if (product == PRR_PRODUCT_E3) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200806 reg = mmio_read_32(RCAR_MODEMR);
807 sscg = reg & RCAR_SSCG_MASK;
808 str = sscg == RCAR_SSCG_ENABLE ? sscg_on : sscg_off;
809 NOTICE("BL2: %s\n", str);
810 }
811
812 rcar_get_board_type(&type, &rev);
813
814 switch (type) {
815 case BOARD_SALVATOR_X:
816 case BOARD_KRIEK:
817 case BOARD_STARTER_KIT:
818 case BOARD_SALVATOR_XS:
819 case BOARD_EBISU:
820 case BOARD_STARTER_KIT_PRE:
821 case BOARD_EBISU_4D:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100822 case BOARD_DRAAK:
Valentine Barshakf2184142018-10-30 02:06:17 +0300823 case BOARD_EAGLE:
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200824 break;
825 default:
826 type = BOARD_UNKNOWN;
827 break;
828 }
829
830 if (type == BOARD_UNKNOWN || rev == BOARD_REV_UNKNOWN)
831 NOTICE("BL2: Board is %s Rev.---\n", GET_BOARD_NAME(type));
832 else {
833 NOTICE("BL2: Board is %s Rev.%d.%d\n",
834 GET_BOARD_NAME(type),
835 GET_BOARD_MAJOR(rev), GET_BOARD_MINOR(rev));
836 }
837
838#if RCAR_LSI != RCAR_AUTO
839 if (product != TARGET_PRODUCT) {
840 ERROR("BL2: IPL was been built for the %s.\n", TARGET_NAME);
841 ERROR("BL2: Please write the correct IPL to flash memory.\n");
842 panic();
843 }
844#endif
845 rcar_avs_init();
846 rcar_avs_setting();
847
848 switch (boot_dev) {
849 case MODEMR_BOOT_DEV_HYPERFLASH160:
850 str = boot_hyper160;
851 break;
852 case MODEMR_BOOT_DEV_HYPERFLASH80:
853 str = boot_hyper80;
854 break;
855 case MODEMR_BOOT_DEV_QSPI_FLASH40:
856 str = boot_qspi40;
857 break;
858 case MODEMR_BOOT_DEV_QSPI_FLASH80:
859 str = boot_qspi80;
860 break;
861 case MODEMR_BOOT_DEV_EMMC_25X1:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100862#if RCAR_LSI == RCAR_D3
863 ERROR("BL2: Failed to Initialize. eMMC is not supported.\n");
864 panic();
865#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200866 str = boot_emmc25x1;
867 break;
868 case MODEMR_BOOT_DEV_EMMC_50X8:
Marek Vasut4ae342c2019-01-05 13:56:03 +0100869#if RCAR_LSI == RCAR_D3
870 ERROR("BL2: Failed to Initialize. eMMC is not supported.\n");
871 panic();
872#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200873 str = boot_emmc50x8;
874 break;
875 default:
876 str = unknown;
877 break;
878 }
879 NOTICE("BL2: Boot device is %s\n", str);
880
881 rcar_avs_setting();
882 reg = rcar_rom_get_lcs(&lcs);
883 if (reg) {
884 str = unknown;
885 goto lcm_state;
886 }
887
888 switch (lcs) {
889 case LCS_CM:
890 str = lcs_cm;
891 break;
892 case LCS_DM:
893 str = lcs_dm;
894 break;
895 case LCS_SD:
896 str = lcs_sd;
897 break;
898 case LCS_SE:
899 str = lcs_secure;
900 break;
901 case LCS_FA:
902 str = lcs_fa;
903 break;
904 default:
905 str = unknown;
906 break;
907 }
908
909lcm_state:
910 NOTICE("BL2: LCM state is %s\n", str);
911
912 rcar_avs_end();
913 is_ddr_backup_mode();
914
915 bl2_tzram_layout.total_base = BL31_BASE;
916 bl2_tzram_layout.total_size = BL31_LIMIT - BL31_BASE;
917
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200918 if (boot_cpu == MODEMR_BOOT_CPU_CA57 ||
919 boot_cpu == MODEMR_BOOT_CPU_CA53) {
920 ret = rcar_dram_init();
921 if (ret) {
922 NOTICE("BL2: Failed to DRAM initialize (%d).\n", ret);
923 panic();
924 }
925 rcar_qos_init();
926 }
927
Marek Vasut93c85fc2018-10-02 20:45:18 +0200928 /* Set up FDT */
929 ret = fdt_create_empty_tree(fdt, sizeof(fdt_blob));
930 if (ret) {
931 NOTICE("BL2: Cannot allocate FDT for U-Boot (ret=%i)\n", ret);
932 panic();
933 }
934
Marek Vasuta987b002018-10-11 16:15:41 +0200935 /* Add platform compatible string */
936 bl2_populate_compatible_string(fdt);
937
Marek Vasut63659fd2018-10-02 15:12:15 +0200938 /* Print DRAM layout */
939 bl2_advertise_dram_size(product);
940
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200941 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
942 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8) {
943 if (rcar_emmc_init() != EMMC_SUCCESS) {
944 NOTICE("BL2: Failed to eMMC driver initialize.\n");
945 panic();
946 }
947 rcar_emmc_memcard_power(EMMC_POWER_ON);
948 if (rcar_emmc_mount() != EMMC_SUCCESS) {
949 NOTICE("BL2: Failed to eMMC mount operation.\n");
950 panic();
951 }
952 } else {
953 rcar_rpc_init();
954 rcar_dma_init();
955 }
956
957 reg = mmio_read_32(RST_WDTRSTCR);
958 reg &= ~WDTRSTCR_RWDT_RSTMSK;
959 reg |= WDTRSTCR_PASSWORD;
960 mmio_write_32(RST_WDTRSTCR, reg);
961
962 mmio_write_32(CPG_CPGWPR, CPGWPR_PASSWORD);
963 mmio_write_32(CPG_CPGWPCR, CPGWPCR_PASSWORD);
964
965 reg = mmio_read_32(RCAR_PRR);
966 if ((reg & RCAR_CPU_MASK_CA57) == RCAR_CPU_HAVE_CA57)
967 mmio_write_32(CPG_CA57DBGRCR,
968 DBGCPUPREN | mmio_read_32(CPG_CA57DBGRCR));
969
970 if ((reg & RCAR_CPU_MASK_CA53) == RCAR_CPU_HAVE_CA53)
971 mmio_write_32(CPG_CA53DBGRCR,
972 DBGCPUPREN | mmio_read_32(CPG_CA53DBGRCR));
973
Marek Vasut9cadc782019-08-06 19:13:22 +0200974 if (product_cut == PRR_PRODUCT_H3_CUT10) {
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200975 reg = mmio_read_32(CPG_PLL2CR);
976 reg &= ~((uint32_t) 1 << 5);
977 mmio_write_32(CPG_PLL2CR, reg);
978
979 reg = mmio_read_32(CPG_PLL4CR);
980 reg &= ~((uint32_t) 1 << 5);
981 mmio_write_32(CPG_PLL4CR, reg);
982
983 reg = mmio_read_32(CPG_PLL0CR);
984 reg &= ~((uint32_t) 1 << 12);
985 mmio_write_32(CPG_PLL0CR, reg);
986 }
987#if (RCAR_LOSSY_ENABLE == 1)
988 NOTICE("BL2: Lossy Decomp areas\n");
Marek Vasut4d693c22018-10-11 16:53:58 +0200989
990 fcnlnode = fdt_add_subnode(fdt, 0, "reserved-memory");
991 if (fcnlnode < 0) {
992 NOTICE("BL2: Cannot create reserved mem node (ret=%i)\n",
993 fcnlnode);
994 panic();
995 }
996
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200997 bl2_lossy_setting(0, LOSSY_ST_ADDR0, LOSSY_END_ADDR0,
Marek Vasut4d693c22018-10-11 16:53:58 +0200998 LOSSY_FMT0, LOSSY_ENA_DIS0, fcnlnode);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +0200999 bl2_lossy_setting(1, LOSSY_ST_ADDR1, LOSSY_END_ADDR1,
Marek Vasut4d693c22018-10-11 16:53:58 +02001000 LOSSY_FMT1, LOSSY_ENA_DIS1, fcnlnode);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02001001 bl2_lossy_setting(2, LOSSY_ST_ADDR2, LOSSY_END_ADDR2,
Marek Vasut4d693c22018-10-11 16:53:58 +02001002 LOSSY_FMT2, LOSSY_ENA_DIS2, fcnlnode);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02001003#endif
1004
Marek Vasut93c85fc2018-10-02 20:45:18 +02001005 fdt_pack(fdt);
1006 NOTICE("BL2: FDT at %p\n", fdt);
1007
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02001008 if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 ||
1009 boot_dev == MODEMR_BOOT_DEV_EMMC_50X8)
1010 rcar_io_emmc_setup();
1011 else
1012 rcar_io_setup();
1013}
1014
1015void bl2_el3_plat_arch_setup(void)
1016{
1017#if RCAR_BL2_DCACHE == 1
1018 NOTICE("BL2: D-Cache enable\n");
1019 rcar_configure_mmu_el3(BL2_BASE,
Marek Vasut2e032c02018-12-26 15:57:08 +01001020 BL2_END - BL2_BASE,
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02001021 BL2_RO_BASE, BL2_RO_LIMIT
1022#if USE_COHERENT_MEM
1023 , BL2_COHERENT_RAM_BASE, BL2_COHERENT_RAM_LIMIT
1024#endif
1025 );
1026#endif
1027}
1028
1029void bl2_platform_setup(void)
1030{
1031
1032}
Marek Vasut1eca7782018-12-28 20:12:13 +01001033
1034static void bl2_init_generic_timer(void)
1035{
Valentine Barshakf2184142018-10-30 02:06:17 +03001036/* FIXME: V3M 16.666 MHz ? */
Marek Vasut4ae342c2019-01-05 13:56:03 +01001037#if RCAR_LSI == RCAR_D3
1038 uint32_t reg_cntfid = EXTAL_DRAAK;
1039#elif RCAR_LSI == RCAR_E3
Marek Vasut1eca7782018-12-28 20:12:13 +01001040 uint32_t reg_cntfid = EXTAL_EBISU;
1041#else /* RCAR_LSI == RCAR_E3 */
1042 uint32_t reg;
1043 uint32_t reg_cntfid;
1044 uint32_t modemr;
1045 uint32_t modemr_pll;
1046 uint32_t board_type;
1047 uint32_t board_rev;
1048 uint32_t pll_table[] = {
1049 EXTAL_MD14_MD13_TYPE_0, /* MD14/MD13 : 0b00 */
1050 EXTAL_MD14_MD13_TYPE_1, /* MD14/MD13 : 0b01 */
1051 EXTAL_MD14_MD13_TYPE_2, /* MD14/MD13 : 0b10 */
1052 EXTAL_MD14_MD13_TYPE_3 /* MD14/MD13 : 0b11 */
1053 };
1054
1055 modemr = mmio_read_32(RCAR_MODEMR);
1056 modemr_pll = (modemr & MODEMR_BOOT_PLL_MASK);
1057
1058 /* Set frequency data in CNTFID0 */
1059 reg_cntfid = pll_table[modemr_pll >> MODEMR_BOOT_PLL_SHIFT];
Marek Vasut9cadc782019-08-06 19:13:22 +02001060 reg = mmio_read_32(RCAR_PRR) & (PRR_PRODUCT_MASK | PRR_CUT_MASK);
Marek Vasut1eca7782018-12-28 20:12:13 +01001061 switch (modemr_pll) {
1062 case MD14_MD13_TYPE_0:
1063 rcar_get_board_type(&board_type, &board_rev);
1064 if (BOARD_SALVATOR_XS == board_type) {
1065 reg_cntfid = EXTAL_SALVATOR_XS;
1066 }
1067 break;
1068 case MD14_MD13_TYPE_3:
Marek Vasut9cadc782019-08-06 19:13:22 +02001069 if (PRR_PRODUCT_H3_CUT10 == reg) {
Marek Vasut1eca7782018-12-28 20:12:13 +01001070 reg_cntfid = reg_cntfid >> 1U;
1071 }
1072 break;
1073 default:
1074 /* none */
1075 break;
1076 }
1077#endif /* RCAR_LSI == RCAR_E3 */
1078 /* Update memory mapped and register based freqency */
1079 write_cntfrq_el0((u_register_t )reg_cntfid);
1080 mmio_write_32(ARM_SYS_CNTCTL_BASE + (uintptr_t)CNTFID_OFF, reg_cntfid);
1081 /* Enable counter */
1082 mmio_setbits_32(RCAR_CNTC_BASE + (uintptr_t)CNTCR_OFF,
1083 (uint32_t)CNTCR_EN);
1084}