Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, Renesas Electronics Corporation. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #include <string.h> |
| 8 | |
Marek Vasut | 93c85fc | 2018-10-02 20:45:18 +0200 | [diff] [blame] | 9 | #include <libfdt.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 11 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | |
| 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-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 22 | |
| 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 | |
| 42 | IMPORT_SYM(unsigned long, __RO_START__, BL2_RO_BASE) |
| 43 | IMPORT_SYM(unsigned long, __RO_END__, BL2_RO_LIMIT) |
| 44 | |
| 45 | #if USE_COHERENT_MEM |
| 46 | IMPORT_SYM(unsigned long, __COHERENT_RAM_START__, BL2_COHERENT_RAM_BASE) |
| 47 | IMPORT_SYM(unsigned long, __COHERENT_RAM_END__, BL2_COHERENT_RAM_LIMIT) |
| 48 | #endif |
| 49 | |
| 50 | extern void plat_rcar_gic_driver_init(void); |
| 51 | extern void plat_rcar_gic_init(void); |
| 52 | extern void bl2_enter_bl31(const struct entry_point_info *bl_ep_info); |
| 53 | extern void bl2_system_cpg_init(void); |
| 54 | extern void bl2_secure_setting(void); |
| 55 | extern void bl2_cpg_init(void); |
| 56 | extern void rcar_io_emmc_setup(void); |
| 57 | extern void rcar_io_setup(void); |
| 58 | extern void rcar_swdt_release(void); |
| 59 | extern void rcar_swdt_init(void); |
| 60 | extern void rcar_rpc_init(void); |
| 61 | extern void rcar_pfc_init(void); |
| 62 | extern void rcar_dma_init(void); |
| 63 | |
Marek Vasut | 1eca778 | 2018-12-28 20:12:13 +0100 | [diff] [blame] | 64 | static void bl2_init_generic_timer(void); |
| 65 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 66 | /* R-Car Gen3 product check */ |
| 67 | #if (RCAR_LSI == RCAR_H3) || (RCAR_LSI == RCAR_H3N) |
| 68 | #define TARGET_PRODUCT RCAR_PRODUCT_H3 |
| 69 | #define TARGET_NAME "R-Car H3" |
| 70 | #elif RCAR_LSI == RCAR_M3 |
| 71 | #define TARGET_PRODUCT RCAR_PRODUCT_M3 |
| 72 | #define TARGET_NAME "R-Car M3" |
| 73 | #elif RCAR_LSI == RCAR_M3N |
| 74 | #define TARGET_PRODUCT RCAR_PRODUCT_M3N |
| 75 | #define TARGET_NAME "R-Car M3N" |
| 76 | #elif RCAR_LSI == RCAR_E3 |
| 77 | #define TARGET_PRODUCT RCAR_PRODUCT_E3 |
| 78 | #define TARGET_NAME "R-Car E3" |
Marek Vasut | 94cc0f8 | 2018-12-28 20:11:26 +0100 | [diff] [blame] | 79 | #elif RCAR_LSI == RCAR_AUTO |
| 80 | #define TARGET_NAME "R-Car H3/M3/M3N" |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 81 | #endif |
| 82 | |
| 83 | #if (RCAR_LSI == RCAR_E3) |
| 84 | #define GPIO_INDT (GPIO_INDT6) |
| 85 | #define GPIO_BKUP_TRG_SHIFT ((uint32_t)1U<<13U) |
| 86 | #else |
| 87 | #define GPIO_INDT (GPIO_INDT1) |
| 88 | #define GPIO_BKUP_TRG_SHIFT ((uint32_t)1U<<8U) |
| 89 | #endif |
| 90 | |
| 91 | CASSERT((PARAMS_BASE + sizeof(bl2_to_bl31_params_mem_t) + 0x100) |
| 92 | < (RCAR_SHARED_MEM_BASE + RCAR_SHARED_MEM_SIZE), |
| 93 | assert_bl31_params_do_not_fit_in_shared_memory); |
| 94 | |
| 95 | static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE); |
| 96 | |
Marek Vasut | 93c85fc | 2018-10-02 20:45:18 +0200 | [diff] [blame] | 97 | /* FDT with DRAM configuration */ |
| 98 | uint64_t fdt_blob[PAGE_SIZE_4KB / sizeof(uint64_t)]; |
| 99 | static void *fdt = (void *)fdt_blob; |
| 100 | |
| 101 | static void unsigned_num_print(unsigned long long int unum, unsigned int radix, |
| 102 | char *string) |
| 103 | { |
| 104 | /* Just need enough space to store 64 bit decimal integer */ |
| 105 | char num_buf[20]; |
| 106 | int i = 0; |
| 107 | unsigned int rem; |
| 108 | |
| 109 | do { |
| 110 | rem = unum % radix; |
| 111 | if (rem < 0xa) |
| 112 | num_buf[i] = '0' + rem; |
| 113 | else |
| 114 | num_buf[i] = 'a' + (rem - 0xa); |
| 115 | i++; |
| 116 | unum /= radix; |
| 117 | } while (unum > 0U); |
| 118 | |
| 119 | while (--i >= 0) |
| 120 | *string++ = num_buf[i]; |
| 121 | } |
| 122 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 123 | #if (RCAR_LOSSY_ENABLE == 1) |
| 124 | typedef struct bl2_lossy_info { |
| 125 | uint32_t magic; |
| 126 | uint32_t a0; |
| 127 | uint32_t b0; |
| 128 | } bl2_lossy_info_t; |
| 129 | |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 130 | static void bl2_lossy_gen_fdt(uint32_t no, uint64_t start_addr, |
| 131 | uint64_t end_addr, uint32_t format, |
| 132 | uint32_t enable, int fcnlnode) |
| 133 | { |
| 134 | const uint64_t fcnlsize = cpu_to_fdt64(end_addr - start_addr); |
| 135 | char nodename[40] = { 0 }; |
| 136 | int ret, node; |
| 137 | |
| 138 | /* Ignore undefined addresses */ |
| 139 | if (start_addr == 0 && end_addr == 0) |
| 140 | return; |
| 141 | |
| 142 | snprintf(nodename, sizeof(nodename), "lossy-decompression@"); |
| 143 | unsigned_num_print(start_addr, 16, nodename + strlen(nodename)); |
| 144 | |
| 145 | node = ret = fdt_add_subnode(fdt, fcnlnode, nodename); |
| 146 | if (ret < 0) { |
| 147 | NOTICE("BL2: Cannot create FCNL node (ret=%i)\n", ret); |
| 148 | panic(); |
| 149 | } |
| 150 | |
| 151 | ret = fdt_setprop_string(fdt, node, "compatible", |
| 152 | "renesas,lossy-decompression"); |
| 153 | if (ret < 0) { |
| 154 | NOTICE("BL2: Cannot add FCNL compat string (ret=%i)\n", ret); |
| 155 | panic(); |
| 156 | } |
| 157 | |
| 158 | ret = fdt_appendprop_string(fdt, node, "compatible", |
| 159 | "shared-dma-pool"); |
| 160 | if (ret < 0) { |
| 161 | NOTICE("BL2: Cannot append FCNL compat string (ret=%i)\n", ret); |
| 162 | panic(); |
| 163 | } |
| 164 | |
| 165 | ret = fdt_setprop_u64(fdt, node, "reg", start_addr); |
| 166 | if (ret < 0) { |
| 167 | NOTICE("BL2: Cannot add FCNL reg prop (ret=%i)\n", ret); |
| 168 | panic(); |
| 169 | } |
| 170 | |
| 171 | ret = fdt_appendprop(fdt, node, "reg", &fcnlsize, sizeof(fcnlsize)); |
| 172 | if (ret < 0) { |
| 173 | NOTICE("BL2: Cannot append FCNL reg size prop (ret=%i)\n", ret); |
| 174 | panic(); |
| 175 | } |
| 176 | |
| 177 | ret = fdt_setprop(fdt, node, "no-map", NULL, 0); |
| 178 | if (ret < 0) { |
| 179 | NOTICE("BL2: Cannot add FCNL no-map prop (ret=%i)\n", ret); |
| 180 | panic(); |
| 181 | } |
| 182 | |
| 183 | ret = fdt_setprop_u32(fdt, node, "renesas,formats", format); |
| 184 | if (ret < 0) { |
| 185 | NOTICE("BL2: Cannot add FCNL formats prop (ret=%i)\n", ret); |
| 186 | panic(); |
| 187 | } |
| 188 | } |
| 189 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 190 | static void bl2_lossy_setting(uint32_t no, uint64_t start_addr, |
| 191 | uint64_t end_addr, uint32_t format, |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 192 | uint32_t enable, int fcnlnode) |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 193 | { |
| 194 | bl2_lossy_info_t info; |
| 195 | uint32_t reg; |
| 196 | |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 197 | bl2_lossy_gen_fdt(no, start_addr, end_addr, format, enable, fcnlnode); |
| 198 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 199 | reg = format | (start_addr >> 20); |
| 200 | mmio_write_32(AXI_DCMPAREACRA0 + 0x8 * no, reg); |
| 201 | mmio_write_32(AXI_DCMPAREACRB0 + 0x8 * no, end_addr >> 20); |
| 202 | mmio_write_32(AXI_DCMPAREACRA0 + 0x8 * no, reg | enable); |
| 203 | |
| 204 | info.magic = 0x12345678U; |
| 205 | info.a0 = mmio_read_32(AXI_DCMPAREACRA0 + 0x8 * no); |
| 206 | info.b0 = mmio_read_32(AXI_DCMPAREACRB0 + 0x8 * no); |
| 207 | |
| 208 | mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no, info.magic); |
| 209 | mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no + 0x4, info.a0); |
| 210 | mmio_write_32(LOSSY_PARAMS_BASE + sizeof(info) * no + 0x8, info.b0); |
| 211 | |
| 212 | NOTICE(" Entry %d: DCMPAREACRAx:0x%x DCMPAREACRBx:0x%x\n", no, |
| 213 | mmio_read_32(AXI_DCMPAREACRA0 + 0x8 * no), |
| 214 | mmio_read_32(AXI_DCMPAREACRB0 + 0x8 * no)); |
| 215 | } |
| 216 | #endif |
| 217 | |
| 218 | void bl2_plat_flush_bl31_params(void) |
| 219 | { |
| 220 | uint32_t product_cut, product, cut; |
| 221 | uint32_t boot_dev, boot_cpu; |
| 222 | uint32_t lcs, reg, val; |
| 223 | |
| 224 | reg = mmio_read_32(RCAR_MODEMR); |
| 225 | boot_dev = reg & MODEMR_BOOT_DEV_MASK; |
| 226 | |
| 227 | if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 || |
| 228 | boot_dev == MODEMR_BOOT_DEV_EMMC_50X8) |
| 229 | emmc_terminate(); |
| 230 | |
| 231 | if ((reg & MODEMR_BOOT_CPU_MASK) != MODEMR_BOOT_CPU_CR7) |
| 232 | bl2_secure_setting(); |
| 233 | |
| 234 | reg = mmio_read_32(RCAR_PRR); |
| 235 | product_cut = reg & (RCAR_PRODUCT_MASK | RCAR_CUT_MASK); |
| 236 | product = reg & RCAR_PRODUCT_MASK; |
| 237 | cut = reg & RCAR_CUT_MASK; |
| 238 | |
Marek Vasut | 3af2005 | 2019-02-25 14:57:08 +0100 | [diff] [blame] | 239 | if (product == RCAR_PRODUCT_M3 && RCAR_CUT_VER30 > cut) |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 240 | goto tlb; |
| 241 | |
| 242 | if (product == RCAR_PRODUCT_H3 && RCAR_CUT_VER20 > cut) |
| 243 | goto tlb; |
| 244 | |
| 245 | /* Disable MFIS write protection */ |
| 246 | mmio_write_32(MFISWPCNTR, MFISWPCNTR_PASSWORD | 1); |
| 247 | |
| 248 | tlb: |
| 249 | reg = mmio_read_32(RCAR_MODEMR); |
| 250 | boot_cpu = reg & MODEMR_BOOT_CPU_MASK; |
| 251 | if (boot_cpu != MODEMR_BOOT_CPU_CA57 && |
| 252 | boot_cpu != MODEMR_BOOT_CPU_CA53) |
| 253 | goto mmu; |
| 254 | |
| 255 | if (product_cut == RCAR_PRODUCT_H3_CUT20) { |
| 256 | mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE); |
| 257 | mmio_write_32(IPMMUVI1_IMSCTLR, IMSCTLR_DISCACHE); |
| 258 | mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE); |
| 259 | mmio_write_32(IPMMUPV1_IMSCTLR, IMSCTLR_DISCACHE); |
| 260 | mmio_write_32(IPMMUPV2_IMSCTLR, IMSCTLR_DISCACHE); |
| 261 | mmio_write_32(IPMMUPV3_IMSCTLR, IMSCTLR_DISCACHE); |
| 262 | } else if (product_cut == (RCAR_PRODUCT_M3N | RCAR_CUT_VER10) || |
| 263 | product_cut == (RCAR_PRODUCT_M3N | RCAR_CUT_VER11)) { |
| 264 | mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE); |
| 265 | mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE); |
Marek Vasut | 87613d1 | 2018-12-28 20:11:38 +0100 | [diff] [blame] | 266 | } else if ((product_cut == (RCAR_PRODUCT_E3 | RCAR_CUT_VER10)) || |
| 267 | (product_cut == (RCAR_PRODUCT_E3 | RCAR_CUT_VER11))) { |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 268 | mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE); |
Marek Vasut | e620801 | 2018-12-31 16:48:04 +0100 | [diff] [blame] | 269 | mmio_write_32(IPMMUVP0_IMSCTLR, IMSCTLR_DISCACHE); |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 270 | mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE); |
| 271 | } |
| 272 | |
| 273 | if (product_cut == (RCAR_PRODUCT_H3_CUT20) || |
| 274 | product_cut == (RCAR_PRODUCT_M3N | RCAR_CUT_VER10) || |
| 275 | product_cut == (RCAR_PRODUCT_M3N | RCAR_CUT_VER11) || |
| 276 | product_cut == (RCAR_PRODUCT_E3 | RCAR_CUT_VER10)) { |
| 277 | mmio_write_32(IPMMUHC_IMSCTLR, IMSCTLR_DISCACHE); |
| 278 | mmio_write_32(IPMMURT_IMSCTLR, IMSCTLR_DISCACHE); |
| 279 | mmio_write_32(IPMMUMP_IMSCTLR, IMSCTLR_DISCACHE); |
| 280 | |
| 281 | mmio_write_32(IPMMUDS0_IMSCTLR, IMSCTLR_DISCACHE); |
| 282 | mmio_write_32(IPMMUDS1_IMSCTLR, IMSCTLR_DISCACHE); |
| 283 | } |
| 284 | |
| 285 | mmu: |
| 286 | mmio_write_32(IPMMUMM_IMSCTLR, IPMMUMM_IMSCTLR_ENABLE); |
| 287 | mmio_write_32(IPMMUMM_IMAUXCTLR, IPMMUMM_IMAUXCTLR_NMERGE40_BIT); |
| 288 | |
| 289 | val = rcar_rom_get_lcs(&lcs); |
| 290 | if (val) { |
| 291 | ERROR("BL2: Failed to get the LCS. (%d)\n", val); |
| 292 | panic(); |
| 293 | } |
| 294 | |
| 295 | if (lcs == LCS_SE) |
| 296 | mmio_clrbits_32(P_ARMREG_SEC_CTRL, P_ARMREG_SEC_CTRL_PROT); |
| 297 | |
| 298 | rcar_swdt_release(); |
| 299 | bl2_system_cpg_init(); |
| 300 | |
| 301 | #if RCAR_BL2_DCACHE == 1 |
| 302 | /* Disable data cache (clean and invalidate) */ |
| 303 | disable_mmu_el3(); |
| 304 | #endif |
| 305 | } |
| 306 | |
| 307 | static uint32_t is_ddr_backup_mode(void) |
| 308 | { |
| 309 | #if RCAR_SYSTEM_SUSPEND |
| 310 | static uint32_t reason = RCAR_COLD_BOOT; |
| 311 | static uint32_t once; |
| 312 | |
| 313 | #if PMIC_ROHM_BD9571 && RCAR_SYSTEM_RESET_KEEPON_DDR |
| 314 | uint8_t data; |
| 315 | #endif |
| 316 | if (once) |
| 317 | return reason; |
| 318 | |
| 319 | once = 1; |
| 320 | if ((mmio_read_32(GPIO_INDT) & GPIO_BKUP_TRG_SHIFT) == 0) |
| 321 | return reason; |
| 322 | |
| 323 | #if PMIC_ROHM_BD9571 && RCAR_SYSTEM_RESET_KEEPON_DDR |
| 324 | if (rcar_iic_dvfs_receive(PMIC, REG_KEEP10, &data)) { |
| 325 | ERROR("BL2: REG Keep10 READ ERROR.\n"); |
| 326 | panic(); |
| 327 | } |
| 328 | |
| 329 | if (KEEP10_MAGIC != data) |
| 330 | reason = RCAR_WARM_BOOT; |
| 331 | #else |
| 332 | reason = RCAR_WARM_BOOT; |
| 333 | #endif |
| 334 | return reason; |
| 335 | #else |
| 336 | return RCAR_COLD_BOOT; |
| 337 | #endif |
| 338 | } |
| 339 | |
| 340 | int bl2_plat_handle_pre_image_load(unsigned int image_id) |
| 341 | { |
| 342 | u_register_t *boot_kind = (void *) BOOT_KIND_BASE; |
| 343 | bl_mem_params_node_t *bl_mem_params; |
| 344 | |
| 345 | if (image_id != BL31_IMAGE_ID) |
| 346 | return 0; |
| 347 | |
| 348 | bl_mem_params = get_bl_mem_params_node(image_id); |
| 349 | |
| 350 | if (is_ddr_backup_mode() == RCAR_COLD_BOOT) |
| 351 | goto cold_boot; |
| 352 | |
| 353 | *boot_kind = RCAR_WARM_BOOT; |
| 354 | flush_dcache_range(BOOT_KIND_BASE, sizeof(*boot_kind)); |
| 355 | |
| 356 | console_flush(); |
| 357 | bl2_plat_flush_bl31_params(); |
| 358 | |
| 359 | /* will not return */ |
| 360 | bl2_enter_bl31(&bl_mem_params->ep_info); |
| 361 | |
| 362 | cold_boot: |
| 363 | *boot_kind = RCAR_COLD_BOOT; |
| 364 | flush_dcache_range(BOOT_KIND_BASE, sizeof(*boot_kind)); |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | int bl2_plat_handle_post_image_load(unsigned int image_id) |
| 370 | { |
| 371 | static bl2_to_bl31_params_mem_t *params; |
| 372 | bl_mem_params_node_t *bl_mem_params; |
| 373 | |
| 374 | if (!params) { |
| 375 | params = (bl2_to_bl31_params_mem_t *) PARAMS_BASE; |
| 376 | memset((void *)PARAMS_BASE, 0, sizeof(*params)); |
| 377 | } |
| 378 | |
| 379 | bl_mem_params = get_bl_mem_params_node(image_id); |
| 380 | |
| 381 | switch (image_id) { |
| 382 | case BL31_IMAGE_ID: |
| 383 | break; |
| 384 | case BL32_IMAGE_ID: |
| 385 | memcpy(¶ms->bl32_ep_info, &bl_mem_params->ep_info, |
| 386 | sizeof(entry_point_info_t)); |
| 387 | break; |
| 388 | case BL33_IMAGE_ID: |
| 389 | memcpy(¶ms->bl33_ep_info, &bl_mem_params->ep_info, |
| 390 | sizeof(entry_point_info_t)); |
| 391 | break; |
| 392 | } |
| 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
Marek Vasut | c7077c6 | 2018-12-26 15:57:08 +0100 | [diff] [blame] | 397 | struct meminfo *bl2_plat_sec_mem_layout(void) |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 398 | { |
| 399 | return &bl2_tzram_layout; |
| 400 | } |
| 401 | |
Marek Vasut | a987b00 | 2018-10-11 16:15:41 +0200 | [diff] [blame] | 402 | static void bl2_populate_compatible_string(void *fdt) |
| 403 | { |
| 404 | uint32_t board_type; |
| 405 | uint32_t board_rev; |
| 406 | uint32_t reg; |
| 407 | int ret; |
| 408 | |
| 409 | /* Populate compatible string */ |
| 410 | rcar_get_board_type(&board_type, &board_rev); |
| 411 | switch (board_type) { |
| 412 | case BOARD_SALVATOR_X: |
| 413 | ret = fdt_setprop_string(fdt, 0, "compatible", |
| 414 | "renesas,salvator-x"); |
| 415 | break; |
| 416 | case BOARD_SALVATOR_XS: |
| 417 | ret = fdt_setprop_string(fdt, 0, "compatible", |
| 418 | "renesas,salvator-xs"); |
| 419 | break; |
| 420 | case BOARD_STARTER_KIT: |
| 421 | ret = fdt_setprop_string(fdt, 0, "compatible", |
| 422 | "renesas,m3ulcb"); |
| 423 | break; |
| 424 | case BOARD_STARTER_KIT_PRE: |
| 425 | ret = fdt_setprop_string(fdt, 0, "compatible", |
| 426 | "renesas,h3ulcb"); |
| 427 | break; |
| 428 | case BOARD_EBISU: |
| 429 | case BOARD_EBISU_4D: |
| 430 | ret = fdt_setprop_string(fdt, 0, "compatible", |
| 431 | "renesas,ebisu"); |
| 432 | break; |
| 433 | default: |
| 434 | NOTICE("BL2: Cannot set compatible string, board unsupported\n"); |
| 435 | panic(); |
| 436 | } |
| 437 | |
| 438 | if (ret < 0) { |
| 439 | NOTICE("BL2: Cannot set compatible string (ret=%i)\n", ret); |
| 440 | panic(); |
| 441 | } |
| 442 | |
| 443 | reg = mmio_read_32(RCAR_PRR); |
| 444 | switch (reg & RCAR_PRODUCT_MASK) { |
| 445 | case RCAR_PRODUCT_H3: |
| 446 | ret = fdt_appendprop_string(fdt, 0, "compatible", |
| 447 | "renesas,r8a7795"); |
| 448 | break; |
| 449 | case RCAR_PRODUCT_M3: |
| 450 | ret = fdt_appendprop_string(fdt, 0, "compatible", |
| 451 | "renesas,r8a7796"); |
| 452 | break; |
| 453 | case RCAR_PRODUCT_M3N: |
| 454 | ret = fdt_appendprop_string(fdt, 0, "compatible", |
| 455 | "renesas,r8a77965"); |
| 456 | break; |
| 457 | case RCAR_PRODUCT_E3: |
| 458 | ret = fdt_appendprop_string(fdt, 0, "compatible", |
| 459 | "renesas,r8a77990"); |
| 460 | break; |
| 461 | default: |
| 462 | NOTICE("BL2: Cannot set compatible string, SoC unsupported\n"); |
| 463 | panic(); |
| 464 | } |
| 465 | |
| 466 | if (ret < 0) { |
| 467 | NOTICE("BL2: Cannot set compatible string (ret=%i)\n", ret); |
| 468 | panic(); |
| 469 | } |
| 470 | } |
| 471 | |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 472 | static void bl2_advertise_dram_entries(uint64_t dram_config[8]) |
| 473 | { |
Marek Vasut | 93c85fc | 2018-10-02 20:45:18 +0200 | [diff] [blame] | 474 | char nodename[32] = { 0 }; |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 475 | uint64_t start, size; |
Marek Vasut | 93c85fc | 2018-10-02 20:45:18 +0200 | [diff] [blame] | 476 | uint64_t fdtsize; |
| 477 | int ret, node, chan; |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 478 | |
| 479 | for (chan = 0; chan < 4; chan++) { |
| 480 | start = dram_config[2 * chan]; |
| 481 | size = dram_config[2 * chan + 1]; |
| 482 | if (!size) |
| 483 | continue; |
| 484 | |
| 485 | NOTICE("BL2: CH%d: %llx - %llx, %lld GiB\n", |
| 486 | chan, start, start + size - 1, size >> 30); |
| 487 | } |
Marek Vasut | 93c85fc | 2018-10-02 20:45:18 +0200 | [diff] [blame] | 488 | |
| 489 | /* |
| 490 | * We add the DT nodes in reverse order here. The fdt_add_subnode() |
| 491 | * adds the DT node before the first existing DT node, so we have |
| 492 | * to add them in reverse order to get nodes sorted by address in |
| 493 | * the resulting DT. |
| 494 | */ |
| 495 | for (chan = 3; chan >= 0; chan--) { |
| 496 | start = dram_config[2 * chan]; |
| 497 | size = dram_config[2 * chan + 1]; |
| 498 | if (!size) |
| 499 | continue; |
| 500 | |
| 501 | /* |
| 502 | * Channel 0 is mapped in 32bit space and the first |
| 503 | * 128 MiB are reserved |
| 504 | */ |
| 505 | if (chan == 0) { |
| 506 | start = 0x48000000; |
| 507 | size -= 0x8000000; |
| 508 | } |
| 509 | |
| 510 | fdtsize = cpu_to_fdt64(size); |
| 511 | |
| 512 | snprintf(nodename, sizeof(nodename), "memory@"); |
| 513 | unsigned_num_print(start, 16, nodename + strlen(nodename)); |
| 514 | node = ret = fdt_add_subnode(fdt, 0, nodename); |
| 515 | if (ret < 0) |
| 516 | goto err; |
| 517 | |
| 518 | ret = fdt_setprop_string(fdt, node, "device_type", "memory"); |
| 519 | if (ret < 0) |
| 520 | goto err; |
| 521 | |
| 522 | ret = fdt_setprop_u64(fdt, node, "reg", start); |
| 523 | if (ret < 0) |
| 524 | goto err; |
| 525 | |
| 526 | ret = fdt_appendprop(fdt, node, "reg", &fdtsize, |
| 527 | sizeof(fdtsize)); |
| 528 | if (ret < 0) |
| 529 | goto err; |
| 530 | } |
| 531 | |
| 532 | return; |
| 533 | err: |
| 534 | NOTICE("BL2: Cannot add memory node to FDT (ret=%i)\n", ret); |
| 535 | panic(); |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 536 | } |
| 537 | |
Marek Vasut | b0e1359 | 2018-10-02 14:53:27 +0200 | [diff] [blame] | 538 | static void bl2_advertise_dram_size(uint32_t product) |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 539 | { |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 540 | uint64_t dram_config[8] = { |
| 541 | [0] = 0x400000000ULL, |
| 542 | [2] = 0x500000000ULL, |
| 543 | [4] = 0x600000000ULL, |
| 544 | [6] = 0x700000000ULL, |
| 545 | }; |
| 546 | |
Marek Vasut | 9963f70 | 2018-10-02 15:09:04 +0200 | [diff] [blame] | 547 | switch (product) { |
| 548 | case RCAR_PRODUCT_H3: |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 549 | #if (RCAR_DRAM_LPDDR4_MEMCONF == 0) |
| 550 | /* 4GB(1GBx4) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 551 | dram_config[1] = 0x40000000ULL; |
| 552 | dram_config[3] = 0x40000000ULL; |
| 553 | dram_config[5] = 0x40000000ULL; |
| 554 | dram_config[7] = 0x40000000ULL; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 555 | #elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && \ |
| 556 | (RCAR_DRAM_CHANNEL == 5) && \ |
| 557 | (RCAR_DRAM_SPLIT == 2) |
| 558 | /* 4GB(2GBx2 2ch split) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 559 | dram_config[1] = 0x80000000ULL; |
| 560 | dram_config[3] = 0x80000000ULL; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 561 | #elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && (RCAR_DRAM_CHANNEL == 15) |
| 562 | /* 8GB(2GBx4: default) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 563 | dram_config[1] = 0x80000000ULL; |
| 564 | dram_config[3] = 0x80000000ULL; |
| 565 | dram_config[5] = 0x80000000ULL; |
| 566 | dram_config[7] = 0x80000000ULL; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 567 | #endif /* RCAR_DRAM_LPDDR4_MEMCONF == 0 */ |
Marek Vasut | 9963f70 | 2018-10-02 15:09:04 +0200 | [diff] [blame] | 568 | break; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 569 | |
Marek Vasut | 9963f70 | 2018-10-02 15:09:04 +0200 | [diff] [blame] | 570 | case RCAR_PRODUCT_M3: |
| 571 | /* 4GB(2GBx2 2ch split) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 572 | dram_config[1] = 0x80000000ULL; |
| 573 | dram_config[5] = 0x80000000ULL; |
Marek Vasut | 9963f70 | 2018-10-02 15:09:04 +0200 | [diff] [blame] | 574 | break; |
| 575 | |
| 576 | case RCAR_PRODUCT_M3N: |
| 577 | /* 2GB(1GBx2) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 578 | dram_config[1] = 0x80000000ULL; |
Marek Vasut | 9963f70 | 2018-10-02 15:09:04 +0200 | [diff] [blame] | 579 | break; |
| 580 | |
| 581 | case RCAR_PRODUCT_E3: |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 582 | #if (RCAR_DRAM_DDR3L_MEMCONF == 0) |
| 583 | /* 1GB(512MBx2) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 584 | dram_config[1] = 0x40000000ULL; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 585 | #elif (RCAR_DRAM_DDR3L_MEMCONF == 1) |
| 586 | /* 2GB(512MBx4) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 587 | dram_config[1] = 0x80000000ULL; |
Marek Vasut | 8cb12ec | 2018-10-02 13:51:19 +0200 | [diff] [blame] | 588 | #elif (RCAR_DRAM_DDR3L_MEMCONF == 2) |
| 589 | /* 4GB(1GBx4) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 590 | dram_config[1] = 0x100000000ULL; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 591 | #endif /* RCAR_DRAM_DDR3L_MEMCONF == 0 */ |
Marek Vasut | 9963f70 | 2018-10-02 15:09:04 +0200 | [diff] [blame] | 592 | break; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 593 | } |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 594 | |
| 595 | bl2_advertise_dram_entries(dram_config); |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 596 | } |
| 597 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 598 | void bl2_el3_early_platform_setup(u_register_t arg1, u_register_t arg2, |
| 599 | u_register_t arg3, u_register_t arg4) |
| 600 | { |
| 601 | uint32_t reg, midr, lcs, boot_dev, boot_cpu, sscg, type, rev; |
Marek Vasut | b0e1359 | 2018-10-02 14:53:27 +0200 | [diff] [blame] | 602 | uint32_t product, product_cut, major, minor; |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 603 | int32_t ret; |
| 604 | const char *str; |
| 605 | const char *unknown = "unknown"; |
| 606 | const char *cpu_ca57 = "CA57"; |
| 607 | const char *cpu_ca53 = "CA53"; |
| 608 | const char *product_m3n = "M3N"; |
| 609 | const char *product_h3 = "H3"; |
| 610 | const char *product_m3 = "M3"; |
| 611 | const char *product_e3 = "E3"; |
| 612 | const char *lcs_secure = "SE"; |
| 613 | const char *lcs_cm = "CM"; |
| 614 | const char *lcs_dm = "DM"; |
| 615 | const char *lcs_sd = "SD"; |
| 616 | const char *lcs_fa = "FA"; |
| 617 | const char *sscg_off = "PLL1 nonSSCG Clock select"; |
| 618 | const char *sscg_on = "PLL1 SSCG Clock select"; |
| 619 | const char *boot_hyper80 = "HyperFlash(80MHz)"; |
| 620 | const char *boot_qspi40 = "QSPI Flash(40MHz)"; |
| 621 | const char *boot_qspi80 = "QSPI Flash(80MHz)"; |
| 622 | const char *boot_emmc25x1 = "eMMC(25MHz x1)"; |
| 623 | const char *boot_emmc50x8 = "eMMC(50MHz x8)"; |
| 624 | #if RCAR_LSI == RCAR_E3 |
| 625 | const char *boot_hyper160 = "HyperFlash(150MHz)"; |
| 626 | #else |
| 627 | const char *boot_hyper160 = "HyperFlash(160MHz)"; |
| 628 | #endif |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 629 | #if (RCAR_LOSSY_ENABLE == 1) |
| 630 | int fcnlnode; |
| 631 | #endif |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 632 | |
Marek Vasut | 1eca778 | 2018-12-28 20:12:13 +0100 | [diff] [blame] | 633 | bl2_init_generic_timer(); |
| 634 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 635 | reg = mmio_read_32(RCAR_MODEMR); |
| 636 | boot_dev = reg & MODEMR_BOOT_DEV_MASK; |
| 637 | boot_cpu = reg & MODEMR_BOOT_CPU_MASK; |
| 638 | |
| 639 | bl2_cpg_init(); |
| 640 | |
| 641 | if (boot_cpu == MODEMR_BOOT_CPU_CA57 || |
| 642 | boot_cpu == MODEMR_BOOT_CPU_CA53) { |
| 643 | rcar_pfc_init(); |
| 644 | /* console configuration (platform specific) done in driver */ |
| 645 | console_init(0, 0, 0); |
| 646 | } |
| 647 | |
| 648 | plat_rcar_gic_driver_init(); |
| 649 | plat_rcar_gic_init(); |
| 650 | rcar_swdt_init(); |
| 651 | |
| 652 | /* FIQ interrupts are taken to EL3 */ |
| 653 | write_scr_el3(read_scr_el3() | SCR_FIQ_BIT); |
| 654 | |
| 655 | write_daifclr(DAIF_FIQ_BIT); |
| 656 | |
| 657 | reg = read_midr(); |
| 658 | midr = reg & (MIDR_PN_MASK << MIDR_PN_SHIFT); |
| 659 | switch (midr) { |
| 660 | case MIDR_CA57: |
| 661 | str = cpu_ca57; |
| 662 | break; |
| 663 | case MIDR_CA53: |
| 664 | str = cpu_ca53; |
| 665 | break; |
| 666 | default: |
| 667 | str = unknown; |
| 668 | break; |
| 669 | } |
| 670 | |
| 671 | NOTICE("BL2: R-Car Gen3 Initial Program Loader(%s) Rev.%s\n", str, |
| 672 | version_of_renesas); |
| 673 | |
| 674 | reg = mmio_read_32(RCAR_PRR); |
| 675 | product_cut = reg & (RCAR_PRODUCT_MASK | RCAR_CUT_MASK); |
| 676 | product = reg & RCAR_PRODUCT_MASK; |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 677 | |
| 678 | switch (product) { |
| 679 | case RCAR_PRODUCT_H3: |
| 680 | str = product_h3; |
| 681 | break; |
| 682 | case RCAR_PRODUCT_M3: |
| 683 | str = product_m3; |
| 684 | break; |
| 685 | case RCAR_PRODUCT_M3N: |
| 686 | str = product_m3n; |
| 687 | break; |
| 688 | case RCAR_PRODUCT_E3: |
| 689 | str = product_e3; |
| 690 | break; |
| 691 | default: |
| 692 | str = unknown; |
| 693 | break; |
| 694 | } |
| 695 | |
Marek Vasut | 3af2005 | 2019-02-25 14:57:08 +0100 | [diff] [blame] | 696 | if ((RCAR_PRODUCT_M3 == product) && |
| 697 | (RCAR_CUT_VER20 == (reg & RCAR_MAJOR_MASK))) { |
| 698 | if (RCAR_M3_CUT_VER11 == (reg & RCAR_CUT_MASK)) { |
| 699 | /* M3 Ver.1.1 or Ver.1.2 */ |
| 700 | NOTICE("BL2: PRR is R-Car %s Ver.1.1 / Ver.1.2\n", |
| 701 | str); |
| 702 | } else { |
| 703 | NOTICE("BL2: PRR is R-Car %s Ver.1.%d\n", |
| 704 | str, |
| 705 | (reg & RCAR_MINOR_MASK) + RCAR_M3_MINOR_OFFSET); |
| 706 | } |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 707 | } else { |
| 708 | major = (reg & RCAR_MAJOR_MASK) >> RCAR_MAJOR_SHIFT; |
| 709 | major = major + RCAR_MAJOR_OFFSET; |
| 710 | minor = reg & RCAR_MINOR_MASK; |
| 711 | NOTICE("BL2: PRR is R-Car %s Ver.%d.%d\n", str, major, minor); |
| 712 | } |
| 713 | |
| 714 | if (product == RCAR_PRODUCT_E3) { |
| 715 | reg = mmio_read_32(RCAR_MODEMR); |
| 716 | sscg = reg & RCAR_SSCG_MASK; |
| 717 | str = sscg == RCAR_SSCG_ENABLE ? sscg_on : sscg_off; |
| 718 | NOTICE("BL2: %s\n", str); |
| 719 | } |
| 720 | |
| 721 | rcar_get_board_type(&type, &rev); |
| 722 | |
| 723 | switch (type) { |
| 724 | case BOARD_SALVATOR_X: |
| 725 | case BOARD_KRIEK: |
| 726 | case BOARD_STARTER_KIT: |
| 727 | case BOARD_SALVATOR_XS: |
| 728 | case BOARD_EBISU: |
| 729 | case BOARD_STARTER_KIT_PRE: |
| 730 | case BOARD_EBISU_4D: |
| 731 | break; |
| 732 | default: |
| 733 | type = BOARD_UNKNOWN; |
| 734 | break; |
| 735 | } |
| 736 | |
| 737 | if (type == BOARD_UNKNOWN || rev == BOARD_REV_UNKNOWN) |
| 738 | NOTICE("BL2: Board is %s Rev.---\n", GET_BOARD_NAME(type)); |
| 739 | else { |
| 740 | NOTICE("BL2: Board is %s Rev.%d.%d\n", |
| 741 | GET_BOARD_NAME(type), |
| 742 | GET_BOARD_MAJOR(rev), GET_BOARD_MINOR(rev)); |
| 743 | } |
| 744 | |
| 745 | #if RCAR_LSI != RCAR_AUTO |
| 746 | if (product != TARGET_PRODUCT) { |
| 747 | ERROR("BL2: IPL was been built for the %s.\n", TARGET_NAME); |
| 748 | ERROR("BL2: Please write the correct IPL to flash memory.\n"); |
| 749 | panic(); |
| 750 | } |
| 751 | #endif |
| 752 | rcar_avs_init(); |
| 753 | rcar_avs_setting(); |
| 754 | |
| 755 | switch (boot_dev) { |
| 756 | case MODEMR_BOOT_DEV_HYPERFLASH160: |
| 757 | str = boot_hyper160; |
| 758 | break; |
| 759 | case MODEMR_BOOT_DEV_HYPERFLASH80: |
| 760 | str = boot_hyper80; |
| 761 | break; |
| 762 | case MODEMR_BOOT_DEV_QSPI_FLASH40: |
| 763 | str = boot_qspi40; |
| 764 | break; |
| 765 | case MODEMR_BOOT_DEV_QSPI_FLASH80: |
| 766 | str = boot_qspi80; |
| 767 | break; |
| 768 | case MODEMR_BOOT_DEV_EMMC_25X1: |
| 769 | str = boot_emmc25x1; |
| 770 | break; |
| 771 | case MODEMR_BOOT_DEV_EMMC_50X8: |
| 772 | str = boot_emmc50x8; |
| 773 | break; |
| 774 | default: |
| 775 | str = unknown; |
| 776 | break; |
| 777 | } |
| 778 | NOTICE("BL2: Boot device is %s\n", str); |
| 779 | |
| 780 | rcar_avs_setting(); |
| 781 | reg = rcar_rom_get_lcs(&lcs); |
| 782 | if (reg) { |
| 783 | str = unknown; |
| 784 | goto lcm_state; |
| 785 | } |
| 786 | |
| 787 | switch (lcs) { |
| 788 | case LCS_CM: |
| 789 | str = lcs_cm; |
| 790 | break; |
| 791 | case LCS_DM: |
| 792 | str = lcs_dm; |
| 793 | break; |
| 794 | case LCS_SD: |
| 795 | str = lcs_sd; |
| 796 | break; |
| 797 | case LCS_SE: |
| 798 | str = lcs_secure; |
| 799 | break; |
| 800 | case LCS_FA: |
| 801 | str = lcs_fa; |
| 802 | break; |
| 803 | default: |
| 804 | str = unknown; |
| 805 | break; |
| 806 | } |
| 807 | |
| 808 | lcm_state: |
| 809 | NOTICE("BL2: LCM state is %s\n", str); |
| 810 | |
| 811 | rcar_avs_end(); |
| 812 | is_ddr_backup_mode(); |
| 813 | |
| 814 | bl2_tzram_layout.total_base = BL31_BASE; |
| 815 | bl2_tzram_layout.total_size = BL31_LIMIT - BL31_BASE; |
| 816 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 817 | if (boot_cpu == MODEMR_BOOT_CPU_CA57 || |
| 818 | boot_cpu == MODEMR_BOOT_CPU_CA53) { |
| 819 | ret = rcar_dram_init(); |
| 820 | if (ret) { |
| 821 | NOTICE("BL2: Failed to DRAM initialize (%d).\n", ret); |
| 822 | panic(); |
| 823 | } |
| 824 | rcar_qos_init(); |
| 825 | } |
| 826 | |
Marek Vasut | 93c85fc | 2018-10-02 20:45:18 +0200 | [diff] [blame] | 827 | /* Set up FDT */ |
| 828 | ret = fdt_create_empty_tree(fdt, sizeof(fdt_blob)); |
| 829 | if (ret) { |
| 830 | NOTICE("BL2: Cannot allocate FDT for U-Boot (ret=%i)\n", ret); |
| 831 | panic(); |
| 832 | } |
| 833 | |
Marek Vasut | a987b00 | 2018-10-11 16:15:41 +0200 | [diff] [blame] | 834 | /* Add platform compatible string */ |
| 835 | bl2_populate_compatible_string(fdt); |
| 836 | |
Marek Vasut | 63659fd | 2018-10-02 15:12:15 +0200 | [diff] [blame] | 837 | /* Print DRAM layout */ |
| 838 | bl2_advertise_dram_size(product); |
| 839 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 840 | if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 || |
| 841 | boot_dev == MODEMR_BOOT_DEV_EMMC_50X8) { |
| 842 | if (rcar_emmc_init() != EMMC_SUCCESS) { |
| 843 | NOTICE("BL2: Failed to eMMC driver initialize.\n"); |
| 844 | panic(); |
| 845 | } |
| 846 | rcar_emmc_memcard_power(EMMC_POWER_ON); |
| 847 | if (rcar_emmc_mount() != EMMC_SUCCESS) { |
| 848 | NOTICE("BL2: Failed to eMMC mount operation.\n"); |
| 849 | panic(); |
| 850 | } |
| 851 | } else { |
| 852 | rcar_rpc_init(); |
| 853 | rcar_dma_init(); |
| 854 | } |
| 855 | |
| 856 | reg = mmio_read_32(RST_WDTRSTCR); |
| 857 | reg &= ~WDTRSTCR_RWDT_RSTMSK; |
| 858 | reg |= WDTRSTCR_PASSWORD; |
| 859 | mmio_write_32(RST_WDTRSTCR, reg); |
| 860 | |
| 861 | mmio_write_32(CPG_CPGWPR, CPGWPR_PASSWORD); |
| 862 | mmio_write_32(CPG_CPGWPCR, CPGWPCR_PASSWORD); |
| 863 | |
| 864 | reg = mmio_read_32(RCAR_PRR); |
| 865 | if ((reg & RCAR_CPU_MASK_CA57) == RCAR_CPU_HAVE_CA57) |
| 866 | mmio_write_32(CPG_CA57DBGRCR, |
| 867 | DBGCPUPREN | mmio_read_32(CPG_CA57DBGRCR)); |
| 868 | |
| 869 | if ((reg & RCAR_CPU_MASK_CA53) == RCAR_CPU_HAVE_CA53) |
| 870 | mmio_write_32(CPG_CA53DBGRCR, |
| 871 | DBGCPUPREN | mmio_read_32(CPG_CA53DBGRCR)); |
| 872 | |
| 873 | if (product_cut == RCAR_PRODUCT_H3_CUT10) { |
| 874 | reg = mmio_read_32(CPG_PLL2CR); |
| 875 | reg &= ~((uint32_t) 1 << 5); |
| 876 | mmio_write_32(CPG_PLL2CR, reg); |
| 877 | |
| 878 | reg = mmio_read_32(CPG_PLL4CR); |
| 879 | reg &= ~((uint32_t) 1 << 5); |
| 880 | mmio_write_32(CPG_PLL4CR, reg); |
| 881 | |
| 882 | reg = mmio_read_32(CPG_PLL0CR); |
| 883 | reg &= ~((uint32_t) 1 << 12); |
| 884 | mmio_write_32(CPG_PLL0CR, reg); |
| 885 | } |
| 886 | #if (RCAR_LOSSY_ENABLE == 1) |
| 887 | NOTICE("BL2: Lossy Decomp areas\n"); |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 888 | |
| 889 | fcnlnode = fdt_add_subnode(fdt, 0, "reserved-memory"); |
| 890 | if (fcnlnode < 0) { |
| 891 | NOTICE("BL2: Cannot create reserved mem node (ret=%i)\n", |
| 892 | fcnlnode); |
| 893 | panic(); |
| 894 | } |
| 895 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 896 | bl2_lossy_setting(0, LOSSY_ST_ADDR0, LOSSY_END_ADDR0, |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 897 | LOSSY_FMT0, LOSSY_ENA_DIS0, fcnlnode); |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 898 | bl2_lossy_setting(1, LOSSY_ST_ADDR1, LOSSY_END_ADDR1, |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 899 | LOSSY_FMT1, LOSSY_ENA_DIS1, fcnlnode); |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 900 | bl2_lossy_setting(2, LOSSY_ST_ADDR2, LOSSY_END_ADDR2, |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 901 | LOSSY_FMT2, LOSSY_ENA_DIS2, fcnlnode); |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 902 | #endif |
| 903 | |
Marek Vasut | 93c85fc | 2018-10-02 20:45:18 +0200 | [diff] [blame] | 904 | fdt_pack(fdt); |
| 905 | NOTICE("BL2: FDT at %p\n", fdt); |
| 906 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 907 | if (boot_dev == MODEMR_BOOT_DEV_EMMC_25X1 || |
| 908 | boot_dev == MODEMR_BOOT_DEV_EMMC_50X8) |
| 909 | rcar_io_emmc_setup(); |
| 910 | else |
| 911 | rcar_io_setup(); |
| 912 | } |
| 913 | |
| 914 | void bl2_el3_plat_arch_setup(void) |
| 915 | { |
| 916 | #if RCAR_BL2_DCACHE == 1 |
| 917 | NOTICE("BL2: D-Cache enable\n"); |
| 918 | rcar_configure_mmu_el3(BL2_BASE, |
Marek Vasut | 2e032c0 | 2018-12-26 15:57:08 +0100 | [diff] [blame] | 919 | BL2_END - BL2_BASE, |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 920 | BL2_RO_BASE, BL2_RO_LIMIT |
| 921 | #if USE_COHERENT_MEM |
| 922 | , BL2_COHERENT_RAM_BASE, BL2_COHERENT_RAM_LIMIT |
| 923 | #endif |
| 924 | ); |
| 925 | #endif |
| 926 | } |
| 927 | |
| 928 | void bl2_platform_setup(void) |
| 929 | { |
| 930 | |
| 931 | } |
Marek Vasut | 1eca778 | 2018-12-28 20:12:13 +0100 | [diff] [blame] | 932 | |
| 933 | static void bl2_init_generic_timer(void) |
| 934 | { |
| 935 | #if RCAR_LSI == RCAR_E3 |
| 936 | uint32_t reg_cntfid = EXTAL_EBISU; |
| 937 | #else /* RCAR_LSI == RCAR_E3 */ |
| 938 | uint32_t reg; |
| 939 | uint32_t reg_cntfid; |
| 940 | uint32_t modemr; |
| 941 | uint32_t modemr_pll; |
| 942 | uint32_t board_type; |
| 943 | uint32_t board_rev; |
| 944 | uint32_t pll_table[] = { |
| 945 | EXTAL_MD14_MD13_TYPE_0, /* MD14/MD13 : 0b00 */ |
| 946 | EXTAL_MD14_MD13_TYPE_1, /* MD14/MD13 : 0b01 */ |
| 947 | EXTAL_MD14_MD13_TYPE_2, /* MD14/MD13 : 0b10 */ |
| 948 | EXTAL_MD14_MD13_TYPE_3 /* MD14/MD13 : 0b11 */ |
| 949 | }; |
| 950 | |
| 951 | modemr = mmio_read_32(RCAR_MODEMR); |
| 952 | modemr_pll = (modemr & MODEMR_BOOT_PLL_MASK); |
| 953 | |
| 954 | /* Set frequency data in CNTFID0 */ |
| 955 | reg_cntfid = pll_table[modemr_pll >> MODEMR_BOOT_PLL_SHIFT]; |
| 956 | reg = mmio_read_32(RCAR_PRR) & (RCAR_PRODUCT_MASK | RCAR_CUT_MASK); |
| 957 | switch (modemr_pll) { |
| 958 | case MD14_MD13_TYPE_0: |
| 959 | rcar_get_board_type(&board_type, &board_rev); |
| 960 | if (BOARD_SALVATOR_XS == board_type) { |
| 961 | reg_cntfid = EXTAL_SALVATOR_XS; |
| 962 | } |
| 963 | break; |
| 964 | case MD14_MD13_TYPE_3: |
| 965 | if (RCAR_PRODUCT_H3_CUT10 == reg) { |
| 966 | reg_cntfid = reg_cntfid >> 1U; |
| 967 | } |
| 968 | break; |
| 969 | default: |
| 970 | /* none */ |
| 971 | break; |
| 972 | } |
| 973 | #endif /* RCAR_LSI == RCAR_E3 */ |
| 974 | /* Update memory mapped and register based freqency */ |
| 975 | write_cntfrq_el0((u_register_t )reg_cntfid); |
| 976 | mmio_write_32(ARM_SYS_CNTCTL_BASE + (uintptr_t)CNTFID_OFF, reg_cntfid); |
| 977 | /* Enable counter */ |
| 978 | mmio_setbits_32(RCAR_CNTC_BASE + (uintptr_t)CNTCR_OFF, |
| 979 | (uint32_t)CNTCR_EN); |
| 980 | } |