Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 1 | /* |
Marek Vasut | 0aa268e | 2019-05-18 19:29:16 +0200 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, Renesas Electronics Corporation. All rights reserved. |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 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) |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 68 | #define TARGET_PRODUCT PRR_PRODUCT_H3 |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 69 | #define TARGET_NAME "R-Car H3" |
| 70 | #elif RCAR_LSI == RCAR_M3 |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 71 | #define TARGET_PRODUCT PRR_PRODUCT_M3 |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 72 | #define TARGET_NAME "R-Car M3" |
| 73 | #elif RCAR_LSI == RCAR_M3N |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 74 | #define TARGET_PRODUCT PRR_PRODUCT_M3N |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 75 | #define TARGET_NAME "R-Car M3N" |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 76 | #elif RCAR_LSI == RCAR_V3M |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 77 | #define TARGET_PRODUCT PRR_PRODUCT_V3M |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 78 | #define TARGET_NAME "R-Car V3M" |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 79 | #elif RCAR_LSI == RCAR_E3 |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 80 | #define TARGET_PRODUCT PRR_PRODUCT_E3 |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 81 | #define TARGET_NAME "R-Car E3" |
Marek Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 82 | #elif RCAR_LSI == RCAR_D3 |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 83 | #define TARGET_PRODUCT PRR_PRODUCT_D3 |
Marek Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 84 | #define TARGET_NAME "R-Car D3" |
Marek Vasut | 94cc0f8 | 2018-12-28 20:11:26 +0100 | [diff] [blame] | 85 | #elif RCAR_LSI == RCAR_AUTO |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 86 | #define TARGET_NAME "R-Car H3/M3/M3N/V3M" |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 87 | #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 | |
| 97 | CASSERT((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 | |
| 101 | static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE); |
| 102 | |
Marek Vasut | 93c85fc | 2018-10-02 20:45:18 +0200 | [diff] [blame] | 103 | /* FDT with DRAM configuration */ |
| 104 | uint64_t fdt_blob[PAGE_SIZE_4KB / sizeof(uint64_t)]; |
| 105 | static void *fdt = (void *)fdt_blob; |
| 106 | |
| 107 | static 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-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 129 | #if (RCAR_LOSSY_ENABLE == 1) |
| 130 | typedef struct bl2_lossy_info { |
| 131 | uint32_t magic; |
| 132 | uint32_t a0; |
| 133 | uint32_t b0; |
| 134 | } bl2_lossy_info_t; |
| 135 | |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 136 | static 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-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 196 | static void bl2_lossy_setting(uint32_t no, uint64_t start_addr, |
| 197 | uint64_t end_addr, uint32_t format, |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 198 | uint32_t enable, int fcnlnode) |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 199 | { |
| 200 | bl2_lossy_info_t info; |
| 201 | uint32_t reg; |
| 202 | |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 203 | bl2_lossy_gen_fdt(no, start_addr, end_addr, format, enable, fcnlnode); |
| 204 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 205 | 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 | |
| 224 | void 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 Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 241 | product_cut = reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK); |
| 242 | product = reg & PRR_PRODUCT_MASK; |
| 243 | cut = reg & PRR_CUT_MASK; |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 244 | |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 245 | if (product == PRR_PRODUCT_M3 && PRR_PRODUCT_30 > cut) |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 246 | goto tlb; |
| 247 | |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 248 | if (product == PRR_PRODUCT_H3 && PRR_PRODUCT_20 > cut) |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 249 | goto tlb; |
| 250 | |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 251 | if (product == PRR_PRODUCT_D3) |
Marek Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 252 | goto tlb; |
| 253 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 254 | /* Disable MFIS write protection */ |
| 255 | mmio_write_32(MFISWPCNTR, MFISWPCNTR_PASSWORD | 1); |
| 256 | |
| 257 | tlb: |
| 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 Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 264 | if (product_cut == PRR_PRODUCT_H3_CUT20) { |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 265 | 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 Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 271 | } else if (product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_10) || |
| 272 | product_cut == (PRR_PRODUCT_M3N | PRR_PRODUCT_11)) { |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 273 | mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE); |
| 274 | mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE); |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 275 | } else if ((product_cut == (PRR_PRODUCT_E3 | PRR_PRODUCT_10)) || |
| 276 | (product_cut == (PRR_PRODUCT_E3 | PRR_PRODUCT_11))) { |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 277 | mmio_write_32(IPMMUVI0_IMSCTLR, IMSCTLR_DISCACHE); |
Marek Vasut | e620801 | 2018-12-31 16:48:04 +0100 | [diff] [blame] | 278 | mmio_write_32(IPMMUVP0_IMSCTLR, IMSCTLR_DISCACHE); |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 279 | mmio_write_32(IPMMUPV0_IMSCTLR, IMSCTLR_DISCACHE); |
| 280 | } |
| 281 | |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 282 | 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-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 286 | 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 | |
| 294 | mmu: |
| 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 | |
| 316 | static 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 | |
| 349 | int 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 | |
| 371 | cold_boot: |
| 372 | *boot_kind = RCAR_COLD_BOOT; |
| 373 | flush_dcache_range(BOOT_KIND_BASE, sizeof(*boot_kind)); |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | int 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(¶ms->bl32_ep_info, &bl_mem_params->ep_info, |
| 395 | sizeof(entry_point_info_t)); |
| 396 | break; |
| 397 | case BL33_IMAGE_ID: |
| 398 | memcpy(¶ms->bl33_ep_info, &bl_mem_params->ep_info, |
| 399 | sizeof(entry_point_info_t)); |
| 400 | break; |
| 401 | } |
| 402 | |
| 403 | return 0; |
| 404 | } |
| 405 | |
Marek Vasut | c7077c6 | 2018-12-26 15:57:08 +0100 | [diff] [blame] | 406 | struct meminfo *bl2_plat_sec_mem_layout(void) |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 407 | { |
| 408 | return &bl2_tzram_layout; |
| 409 | } |
| 410 | |
Marek Vasut | a987b00 | 2018-10-11 16:15:41 +0200 | [diff] [blame] | 411 | static void bl2_populate_compatible_string(void *fdt) |
| 412 | { |
| 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: |
| 422 | ret = fdt_setprop_string(fdt, 0, "compatible", |
| 423 | "renesas,salvator-x"); |
| 424 | break; |
| 425 | case BOARD_SALVATOR_XS: |
| 426 | ret = fdt_setprop_string(fdt, 0, "compatible", |
| 427 | "renesas,salvator-xs"); |
| 428 | break; |
| 429 | case BOARD_STARTER_KIT: |
| 430 | ret = fdt_setprop_string(fdt, 0, "compatible", |
| 431 | "renesas,m3ulcb"); |
| 432 | break; |
| 433 | case BOARD_STARTER_KIT_PRE: |
| 434 | ret = fdt_setprop_string(fdt, 0, "compatible", |
| 435 | "renesas,h3ulcb"); |
| 436 | break; |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 437 | case BOARD_EAGLE: |
| 438 | ret = fdt_setprop_string(fdt, 0, "compatible", |
| 439 | "renesas,eagle"); |
| 440 | break; |
Marek Vasut | a987b00 | 2018-10-11 16:15:41 +0200 | [diff] [blame] | 441 | case BOARD_EBISU: |
| 442 | case BOARD_EBISU_4D: |
| 443 | ret = fdt_setprop_string(fdt, 0, "compatible", |
| 444 | "renesas,ebisu"); |
| 445 | break; |
Marek Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 446 | case BOARD_DRAAK: |
| 447 | ret = fdt_setprop_string(fdt, 0, "compatible", |
| 448 | "renesas,draak"); |
| 449 | break; |
Marek Vasut | a987b00 | 2018-10-11 16:15:41 +0200 | [diff] [blame] | 450 | 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 Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 461 | switch (reg & PRR_PRODUCT_MASK) { |
| 462 | case PRR_PRODUCT_H3: |
Marek Vasut | a987b00 | 2018-10-11 16:15:41 +0200 | [diff] [blame] | 463 | ret = fdt_appendprop_string(fdt, 0, "compatible", |
| 464 | "renesas,r8a7795"); |
| 465 | break; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 466 | case PRR_PRODUCT_M3: |
Marek Vasut | a987b00 | 2018-10-11 16:15:41 +0200 | [diff] [blame] | 467 | ret = fdt_appendprop_string(fdt, 0, "compatible", |
| 468 | "renesas,r8a7796"); |
| 469 | break; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 470 | case PRR_PRODUCT_M3N: |
Marek Vasut | a987b00 | 2018-10-11 16:15:41 +0200 | [diff] [blame] | 471 | ret = fdt_appendprop_string(fdt, 0, "compatible", |
| 472 | "renesas,r8a77965"); |
| 473 | break; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 474 | case PRR_PRODUCT_V3M: |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 475 | ret = fdt_appendprop_string(fdt, 0, "compatible", |
| 476 | "renesas,r8a77970"); |
| 477 | break; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 478 | case PRR_PRODUCT_E3: |
Marek Vasut | a987b00 | 2018-10-11 16:15:41 +0200 | [diff] [blame] | 479 | ret = fdt_appendprop_string(fdt, 0, "compatible", |
| 480 | "renesas,r8a77990"); |
| 481 | break; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 482 | case PRR_PRODUCT_D3: |
Marek Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 483 | ret = fdt_appendprop_string(fdt, 0, "compatible", |
| 484 | "renesas,r8a77995"); |
| 485 | break; |
Marek Vasut | a987b00 | 2018-10-11 16:15:41 +0200 | [diff] [blame] | 486 | 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 Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 497 | static void bl2_advertise_dram_entries(uint64_t dram_config[8]) |
| 498 | { |
Marek Vasut | 93c85fc | 2018-10-02 20:45:18 +0200 | [diff] [blame] | 499 | char nodename[32] = { 0 }; |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 500 | uint64_t start, size; |
Marek Vasut | 93c85fc | 2018-10-02 20:45:18 +0200 | [diff] [blame] | 501 | uint64_t fdtsize; |
| 502 | int ret, node, chan; |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 503 | |
| 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 Vasut | 89c1751 | 2019-03-30 04:01:41 +0100 | [diff] [blame] | 510 | 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 Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 514 | } |
Marek Vasut | 93c85fc | 2018-10-02 20:45:18 +0200 | [diff] [blame] | 515 | |
| 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; |
| 560 | err: |
| 561 | NOTICE("BL2: Cannot add memory node to FDT (ret=%i)\n", ret); |
| 562 | panic(); |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 563 | } |
| 564 | |
Marek Vasut | b0e1359 | 2018-10-02 14:53:27 +0200 | [diff] [blame] | 565 | static void bl2_advertise_dram_size(uint32_t product) |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 566 | { |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 567 | uint64_t dram_config[8] = { |
| 568 | [0] = 0x400000000ULL, |
| 569 | [2] = 0x500000000ULL, |
| 570 | [4] = 0x600000000ULL, |
| 571 | [6] = 0x700000000ULL, |
| 572 | }; |
| 573 | |
Marek Vasut | 9963f70 | 2018-10-02 15:09:04 +0200 | [diff] [blame] | 574 | switch (product) { |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 575 | case PRR_PRODUCT_H3: |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 576 | #if (RCAR_DRAM_LPDDR4_MEMCONF == 0) |
| 577 | /* 4GB(1GBx4) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 578 | dram_config[1] = 0x40000000ULL; |
| 579 | dram_config[3] = 0x40000000ULL; |
| 580 | dram_config[5] = 0x40000000ULL; |
| 581 | dram_config[7] = 0x40000000ULL; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 582 | #elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && \ |
| 583 | (RCAR_DRAM_CHANNEL == 5) && \ |
| 584 | (RCAR_DRAM_SPLIT == 2) |
| 585 | /* 4GB(2GBx2 2ch split) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 586 | dram_config[1] = 0x80000000ULL; |
| 587 | dram_config[3] = 0x80000000ULL; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 588 | #elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && (RCAR_DRAM_CHANNEL == 15) |
| 589 | /* 8GB(2GBx4: default) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 590 | dram_config[1] = 0x80000000ULL; |
| 591 | dram_config[3] = 0x80000000ULL; |
| 592 | dram_config[5] = 0x80000000ULL; |
| 593 | dram_config[7] = 0x80000000ULL; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 594 | #endif /* RCAR_DRAM_LPDDR4_MEMCONF == 0 */ |
Marek Vasut | 9963f70 | 2018-10-02 15:09:04 +0200 | [diff] [blame] | 595 | break; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 596 | |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 597 | case PRR_PRODUCT_M3: |
Marek Vasut | 0208c94 | 2019-03-09 16:10:59 +0100 | [diff] [blame] | 598 | #if (RCAR_GEN3_ULCB == 1) |
| 599 | /* 2GB(1GBx2 2ch split) */ |
| 600 | dram_config[1] = 0x40000000ULL; |
| 601 | dram_config[5] = 0x40000000ULL; |
| 602 | #else |
Marek Vasut | 9963f70 | 2018-10-02 15:09:04 +0200 | [diff] [blame] | 603 | /* 4GB(2GBx2 2ch split) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 604 | dram_config[1] = 0x80000000ULL; |
| 605 | dram_config[5] = 0x80000000ULL; |
Marek Vasut | 0208c94 | 2019-03-09 16:10:59 +0100 | [diff] [blame] | 606 | #endif |
Marek Vasut | 9963f70 | 2018-10-02 15:09:04 +0200 | [diff] [blame] | 607 | break; |
| 608 | |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 609 | case PRR_PRODUCT_M3N: |
Marek Vasut | 9963f70 | 2018-10-02 15:09:04 +0200 | [diff] [blame] | 610 | /* 2GB(1GBx2) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 611 | dram_config[1] = 0x80000000ULL; |
Marek Vasut | 9963f70 | 2018-10-02 15:09:04 +0200 | [diff] [blame] | 612 | break; |
| 613 | |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 614 | case PRR_PRODUCT_V3M: |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 615 | /* 1GB(512MBx2) */ |
| 616 | dram_config[1] = 0x40000000ULL; |
| 617 | break; |
| 618 | |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 619 | case PRR_PRODUCT_E3: |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 620 | #if (RCAR_DRAM_DDR3L_MEMCONF == 0) |
| 621 | /* 1GB(512MBx2) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 622 | dram_config[1] = 0x40000000ULL; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 623 | #elif (RCAR_DRAM_DDR3L_MEMCONF == 1) |
| 624 | /* 2GB(512MBx4) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 625 | dram_config[1] = 0x80000000ULL; |
Marek Vasut | 8cb12ec | 2018-10-02 13:51:19 +0200 | [diff] [blame] | 626 | #elif (RCAR_DRAM_DDR3L_MEMCONF == 2) |
| 627 | /* 4GB(1GBx4) */ |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 628 | dram_config[1] = 0x100000000ULL; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 629 | #endif /* RCAR_DRAM_DDR3L_MEMCONF == 0 */ |
Marek Vasut | 9963f70 | 2018-10-02 15:09:04 +0200 | [diff] [blame] | 630 | break; |
Marek Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 631 | |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 632 | case PRR_PRODUCT_D3: |
Marek Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 633 | /* 512MB */ |
| 634 | dram_config[1] = 0x20000000ULL; |
| 635 | break; |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 636 | } |
Marek Vasut | 6a6881a | 2018-10-02 20:43:09 +0200 | [diff] [blame] | 637 | |
| 638 | bl2_advertise_dram_entries(dram_config); |
Marek Vasut | 673bc32 | 2018-10-02 13:33:32 +0200 | [diff] [blame] | 639 | } |
| 640 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 641 | void 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 Vasut | b0e1359 | 2018-10-02 14:53:27 +0200 | [diff] [blame] | 645 | uint32_t product, product_cut, major, minor; |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 646 | 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 Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 655 | const char *product_d3 = "D3"; |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 656 | const char *product_v3m = "V3M"; |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 657 | 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 Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 669 | #if (RCAR_LSI == RCAR_E3) || (RCAR_LSI == RCAR_D3) |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 670 | const char *boot_hyper160 = "HyperFlash(150MHz)"; |
| 671 | #else |
| 672 | const char *boot_hyper160 = "HyperFlash(160MHz)"; |
| 673 | #endif |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 674 | #if (RCAR_LOSSY_ENABLE == 1) |
| 675 | int fcnlnode; |
| 676 | #endif |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 677 | |
Marek Vasut | 1eca778 | 2018-12-28 20:12:13 +0100 | [diff] [blame] | 678 | bl2_init_generic_timer(); |
| 679 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 680 | 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 Vasut | 0aa268e | 2019-05-18 19:29:16 +0200 | [diff] [blame] | 689 | rcar_console_boot_init(); |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 690 | } |
| 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 Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 719 | product_cut = reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK); |
| 720 | product = reg & PRR_PRODUCT_MASK; |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 721 | |
| 722 | switch (product) { |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 723 | case PRR_PRODUCT_H3: |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 724 | str = product_h3; |
| 725 | break; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 726 | case PRR_PRODUCT_M3: |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 727 | str = product_m3; |
| 728 | break; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 729 | case PRR_PRODUCT_M3N: |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 730 | str = product_m3n; |
| 731 | break; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 732 | case PRR_PRODUCT_V3M: |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 733 | str = product_v3m; |
| 734 | break; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 735 | case PRR_PRODUCT_E3: |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 736 | str = product_e3; |
| 737 | break; |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 738 | case PRR_PRODUCT_D3: |
Marek Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 739 | str = product_d3; |
| 740 | break; |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 741 | default: |
| 742 | str = unknown; |
| 743 | break; |
| 744 | } |
| 745 | |
Marek Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 746 | if ((PRR_PRODUCT_M3 == product) && |
| 747 | (PRR_PRODUCT_20 == (reg & RCAR_MAJOR_MASK))) { |
| 748 | if (RCAR_M3_CUT_VER11 == (reg & PRR_CUT_MASK)) { |
Marek Vasut | 3af2005 | 2019-02-25 14:57:08 +0100 | [diff] [blame] | 749 | /* 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-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 757 | } 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 Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 764 | if (product == PRR_PRODUCT_E3) { |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 765 | 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 Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 781 | case BOARD_DRAAK: |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 782 | case BOARD_EAGLE: |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 783 | 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 Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 821 | #if RCAR_LSI == RCAR_D3 |
| 822 | ERROR("BL2: Failed to Initialize. eMMC is not supported.\n"); |
| 823 | panic(); |
| 824 | #endif |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 825 | str = boot_emmc25x1; |
| 826 | break; |
| 827 | case MODEMR_BOOT_DEV_EMMC_50X8: |
Marek Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 828 | #if RCAR_LSI == RCAR_D3 |
| 829 | ERROR("BL2: Failed to Initialize. eMMC is not supported.\n"); |
| 830 | panic(); |
| 831 | #endif |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 832 | 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 | |
| 868 | lcm_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-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 877 | 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 Vasut | 93c85fc | 2018-10-02 20:45:18 +0200 | [diff] [blame] | 887 | /* 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 Vasut | a987b00 | 2018-10-11 16:15:41 +0200 | [diff] [blame] | 894 | /* Add platform compatible string */ |
| 895 | bl2_populate_compatible_string(fdt); |
| 896 | |
Marek Vasut | 63659fd | 2018-10-02 15:12:15 +0200 | [diff] [blame] | 897 | /* Print DRAM layout */ |
| 898 | bl2_advertise_dram_size(product); |
| 899 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 900 | 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 Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 933 | if (product_cut == PRR_PRODUCT_H3_CUT10) { |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 934 | 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 Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 948 | |
| 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-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 956 | bl2_lossy_setting(0, LOSSY_ST_ADDR0, LOSSY_END_ADDR0, |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 957 | LOSSY_FMT0, LOSSY_ENA_DIS0, fcnlnode); |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 958 | bl2_lossy_setting(1, LOSSY_ST_ADDR1, LOSSY_END_ADDR1, |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 959 | LOSSY_FMT1, LOSSY_ENA_DIS1, fcnlnode); |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 960 | bl2_lossy_setting(2, LOSSY_ST_ADDR2, LOSSY_END_ADDR2, |
Marek Vasut | 4d693c2 | 2018-10-11 16:53:58 +0200 | [diff] [blame] | 961 | LOSSY_FMT2, LOSSY_ENA_DIS2, fcnlnode); |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 962 | #endif |
| 963 | |
Marek Vasut | 93c85fc | 2018-10-02 20:45:18 +0200 | [diff] [blame] | 964 | fdt_pack(fdt); |
| 965 | NOTICE("BL2: FDT at %p\n", fdt); |
| 966 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 967 | 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 | |
| 974 | void 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 Vasut | 2e032c0 | 2018-12-26 15:57:08 +0100 | [diff] [blame] | 979 | BL2_END - BL2_BASE, |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 980 | 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 | |
| 988 | void bl2_platform_setup(void) |
| 989 | { |
| 990 | |
| 991 | } |
Marek Vasut | 1eca778 | 2018-12-28 20:12:13 +0100 | [diff] [blame] | 992 | |
| 993 | static void bl2_init_generic_timer(void) |
| 994 | { |
Valentine Barshak | f218414 | 2018-10-30 02:06:17 +0300 | [diff] [blame] | 995 | /* FIXME: V3M 16.666 MHz ? */ |
Marek Vasut | 4ae342c | 2019-01-05 13:56:03 +0100 | [diff] [blame] | 996 | #if RCAR_LSI == RCAR_D3 |
| 997 | uint32_t reg_cntfid = EXTAL_DRAAK; |
| 998 | #elif RCAR_LSI == RCAR_E3 |
Marek Vasut | 1eca778 | 2018-12-28 20:12:13 +0100 | [diff] [blame] | 999 | 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 Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 1019 | reg = mmio_read_32(RCAR_PRR) & (PRR_PRODUCT_MASK | PRR_CUT_MASK); |
Marek Vasut | 1eca778 | 2018-12-28 20:12:13 +0100 | [diff] [blame] | 1020 | 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 Vasut | 9cadc78 | 2019-08-06 19:13:22 +0200 | [diff] [blame] | 1028 | if (PRR_PRODUCT_H3_CUT10 == reg) { |
Marek Vasut | 1eca778 | 2018-12-28 20:12:13 +0100 | [diff] [blame] | 1029 | 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 | } |