Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 2 | /* |
Hao Zhang | e595107 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 3 | * Keystone : Board initialization |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 4 | * |
Hao Zhang | e595107 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 5 | * (C) Copyright 2014 |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 6 | * Texas Instruments Incorporated, <www.ti.com> |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Vitaly Andrianov | b8dafa2 | 2016-03-11 08:23:04 -0500 | [diff] [blame] | 10 | #include "board.h" |
Simon Glass | 7b51b57 | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 11 | #include <env.h> |
Hao Zhang | 5ec66b1 | 2014-10-22 16:32:31 +0300 | [diff] [blame] | 12 | #include <spl.h> |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 13 | #include <exports.h> |
| 14 | #include <fdt_support.h> |
Khoronzhuk, Ivan | 0b86858 | 2014-07-09 19:48:40 +0300 | [diff] [blame] | 15 | #include <asm/arch/ddr3.h> |
Khoronzhuk, Ivan | 497e9e0 | 2014-09-29 22:17:24 +0300 | [diff] [blame] | 16 | #include <asm/arch/psc_defs.h> |
Lokesh Vutla | 8626cb8 | 2015-10-08 11:31:47 +0530 | [diff] [blame] | 17 | #include <asm/arch/clock.h> |
Khoronzhuk, Ivan | 909ea9a | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 18 | #include <asm/ti-common/ti-aemif.h> |
Khoronzhuk, Ivan | 0935cac | 2014-09-29 22:17:22 +0300 | [diff] [blame] | 19 | #include <asm/ti-common/keystone_net.h> |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Lokesh Vutla | 8f69523 | 2016-04-13 09:50:59 +0530 | [diff] [blame] | 23 | #if defined(CONFIG_TI_AEMIF) |
Khoronzhuk, Ivan | 909ea9a | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 24 | static struct aemif_config aemif_configs[] = { |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 25 | { /* CS0 */ |
Khoronzhuk, Ivan | 909ea9a | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 26 | .mode = AEMIF_MODE_NAND, |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 27 | .wr_setup = 0xf, |
| 28 | .wr_strobe = 0x3f, |
| 29 | .wr_hold = 7, |
| 30 | .rd_setup = 0xf, |
| 31 | .rd_strobe = 0x3f, |
| 32 | .rd_hold = 7, |
| 33 | .turn_around = 3, |
Khoronzhuk, Ivan | 909ea9a | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 34 | .width = AEMIF_WIDTH_8, |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 35 | }, |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 36 | }; |
Lokesh Vutla | 8f69523 | 2016-04-13 09:50:59 +0530 | [diff] [blame] | 37 | #endif |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 38 | |
| 39 | int dram_init(void) |
| 40 | { |
Vitaly Andrianov | 66c98a0 | 2015-02-11 14:07:58 -0500 | [diff] [blame] | 41 | u32 ddr3_size; |
| 42 | |
| 43 | ddr3_size = ddr3_init(); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 44 | |
| 45 | gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, |
| 46 | CONFIG_MAX_RAM_BANK_SIZE); |
Lokesh Vutla | 8f69523 | 2016-04-13 09:50:59 +0530 | [diff] [blame] | 47 | #if defined(CONFIG_TI_AEMIF) |
Cooper Jr., Franklin | e66a5da | 2017-06-16 17:25:25 -0500 | [diff] [blame] | 48 | if (!board_is_k2g_ice()) |
| 49 | aemif_init(ARRAY_SIZE(aemif_configs), aemif_configs); |
Lokesh Vutla | 8f69523 | 2016-04-13 09:50:59 +0530 | [diff] [blame] | 50 | #endif |
| 51 | |
Cooper Jr., Franklin | e66a5da | 2017-06-16 17:25:25 -0500 | [diff] [blame] | 52 | if (!board_is_k2g_ice()) { |
| 53 | if (ddr3_size) |
| 54 | ddr3_init_ecc(KS2_DDR3A_EMIF_CTRL_BASE, ddr3_size); |
| 55 | else |
| 56 | ddr3_init_ecc(KS2_DDR3A_EMIF_CTRL_BASE, |
| 57 | gd->ram_size >> 30); |
| 58 | } |
Lokesh Vutla | e92a6b2 | 2016-08-27 17:19:15 +0530 | [diff] [blame] | 59 | |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 60 | return 0; |
| 61 | } |
| 62 | |
Keerthy | 3b074fb | 2018-11-27 17:52:41 +0530 | [diff] [blame] | 63 | struct image_header *spl_get_load_buffer(ssize_t offset, size_t size) |
| 64 | { |
| 65 | return (struct image_header *)(CONFIG_SYS_TEXT_BASE); |
| 66 | } |
| 67 | |
Hao Zhang | e595107 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 68 | int board_init(void) |
| 69 | { |
Jean-Jacques Hiblot | c9d5220 | 2018-12-04 11:12:57 +0100 | [diff] [blame] | 70 | #if CONFIG_IS_ENABLED(DM_USB) |
| 71 | int rc = psc_enable_module(KS2_LPSC_USB); |
| 72 | |
| 73 | if (rc) |
| 74 | puts("Cannot enable USB0 module"); |
| 75 | #ifdef KS2_LPSC_USB_1 |
| 76 | rc = psc_enable_module(KS2_LPSC_USB_1); |
| 77 | if (rc) |
| 78 | puts("Cannot enable USB1 module"); |
| 79 | #endif |
| 80 | #endif |
| 81 | |
Nishanth Menon | 59d4cd2 | 2015-07-22 18:05:43 -0500 | [diff] [blame] | 82 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Karicheri, Muralidharan | fc9a8e8 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 83 | |
Hao Zhang | e595107 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
Hao Zhang | 5ec66b1 | 2014-10-22 16:32:31 +0300 | [diff] [blame] | 87 | #ifdef CONFIG_SPL_BUILD |
| 88 | void spl_board_init(void) |
| 89 | { |
| 90 | spl_init_keystone_plls(); |
| 91 | preloader_console_init(); |
| 92 | } |
| 93 | |
| 94 | u32 spl_boot_device(void) |
| 95 | { |
| 96 | #if defined(CONFIG_SPL_SPI_LOAD) |
| 97 | return BOOT_DEVICE_SPI; |
| 98 | #else |
| 99 | puts("Unknown boot device\n"); |
| 100 | hang(); |
| 101 | #endif |
| 102 | } |
| 103 | #endif |
| 104 | |
Robert P. J. Day | 7ffe3cd | 2016-05-19 15:23:12 -0400 | [diff] [blame] | 105 | #ifdef CONFIG_OF_BOARD_SETUP |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 106 | int ft_board_setup(void *blob, bd_t *bd) |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 107 | { |
Hao Zhang | e595107 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 108 | int lpae; |
| 109 | char *env; |
| 110 | char *endp; |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 111 | int nbanks; |
Hao Zhang | e595107 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 112 | u64 size[2]; |
| 113 | u64 start[2]; |
Hao Zhang | e595107 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 114 | u32 ddr3a_size; |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 115 | |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 116 | env = env_get("mem_lpae"); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 117 | lpae = env && simple_strtol(env, NULL, 0); |
| 118 | |
| 119 | ddr3a_size = 0; |
| 120 | if (lpae) { |
Vitaly Andrianov | 8efc243 | 2016-03-04 10:36:43 -0600 | [diff] [blame] | 121 | ddr3a_size = ddr3_get_size(); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 122 | if ((ddr3a_size != 8) && (ddr3a_size != 4)) |
| 123 | ddr3a_size = 0; |
| 124 | } |
| 125 | |
| 126 | nbanks = 1; |
| 127 | start[0] = bd->bi_dram[0].start; |
| 128 | size[0] = bd->bi_dram[0].size; |
| 129 | |
| 130 | /* adjust memory start address for LPAE */ |
| 131 | if (lpae) { |
Hao Zhang | e595107 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 132 | start[0] -= CONFIG_SYS_SDRAM_BASE; |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 133 | start[0] += CONFIG_SYS_LPAE_SDRAM_BASE; |
| 134 | } |
| 135 | |
| 136 | if ((size[0] == 0x80000000) && (ddr3a_size != 0)) { |
| 137 | size[1] = ((u64)ddr3a_size - 2) << 30; |
| 138 | start[1] = 0x880000000; |
| 139 | nbanks++; |
| 140 | } |
| 141 | |
| 142 | /* reserve memory at start of bank */ |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 143 | env = env_get("mem_reserve_head"); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 144 | if (env) { |
| 145 | start[0] += ustrtoul(env, &endp, 0); |
| 146 | size[0] -= ustrtoul(env, &endp, 0); |
| 147 | } |
| 148 | |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 149 | env = env_get("mem_reserve"); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 150 | if (env) |
| 151 | size[0] -= ustrtoul(env, &endp, 0); |
| 152 | |
| 153 | fdt_fixup_memory_banks(blob, start, size, nbanks); |
| 154 | |
Nicholas Faustini | 442faf6 | 2018-10-03 12:58:49 +0200 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | void ft_board_setup_ex(void *blob, bd_t *bd) |
| 159 | { |
| 160 | int lpae; |
| 161 | u64 size; |
| 162 | char *env; |
| 163 | u64 *reserve_start; |
| 164 | int unitrd_fixup = 0; |
| 165 | |
| 166 | env = env_get("mem_lpae"); |
| 167 | lpae = env && simple_strtol(env, NULL, 0); |
| 168 | env = env_get("uinitrd_fixup"); |
| 169 | unitrd_fixup = env && simple_strtol(env, NULL, 0); |
| 170 | |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 171 | /* Fix up the initrd */ |
Murali Karicheri | 0bedbb8 | 2014-07-09 23:44:45 +0300 | [diff] [blame] | 172 | if (lpae && unitrd_fixup) { |
Nicholas Faustini | 442faf6 | 2018-10-03 12:58:49 +0200 | [diff] [blame] | 173 | int nodeoffset; |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 174 | int err; |
Nicholas Faustini | 442faf6 | 2018-10-03 12:58:49 +0200 | [diff] [blame] | 175 | u64 *prop1, *prop2; |
Hao Zhang | e595107 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 176 | u64 initrd_start, initrd_end; |
Murali Karicheri | 0bedbb8 | 2014-07-09 23:44:45 +0300 | [diff] [blame] | 177 | |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 178 | nodeoffset = fdt_path_offset(blob, "/chosen"); |
| 179 | if (nodeoffset >= 0) { |
Nicholas Faustini | 442faf6 | 2018-10-03 12:58:49 +0200 | [diff] [blame] | 180 | prop1 = (u64 *)fdt_getprop(blob, nodeoffset, |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 181 | "linux,initrd-start", NULL); |
Nicholas Faustini | 442faf6 | 2018-10-03 12:58:49 +0200 | [diff] [blame] | 182 | prop2 = (u64 *)fdt_getprop(blob, nodeoffset, |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 183 | "linux,initrd-end", NULL); |
| 184 | if (prop1 && prop2) { |
Nicholas Faustini | 442faf6 | 2018-10-03 12:58:49 +0200 | [diff] [blame] | 185 | initrd_start = __be64_to_cpu(*prop1); |
Hao Zhang | e595107 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 186 | initrd_start -= CONFIG_SYS_SDRAM_BASE; |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 187 | initrd_start += CONFIG_SYS_LPAE_SDRAM_BASE; |
| 188 | initrd_start = __cpu_to_be64(initrd_start); |
Nicholas Faustini | 442faf6 | 2018-10-03 12:58:49 +0200 | [diff] [blame] | 189 | initrd_end = __be64_to_cpu(*prop2); |
Hao Zhang | e595107 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 190 | initrd_end -= CONFIG_SYS_SDRAM_BASE; |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 191 | initrd_end += CONFIG_SYS_LPAE_SDRAM_BASE; |
| 192 | initrd_end = __cpu_to_be64(initrd_end); |
| 193 | |
| 194 | err = fdt_delprop(blob, nodeoffset, |
| 195 | "linux,initrd-start"); |
| 196 | if (err < 0) |
| 197 | puts("error deleting initrd-start\n"); |
| 198 | |
| 199 | err = fdt_delprop(blob, nodeoffset, |
| 200 | "linux,initrd-end"); |
| 201 | if (err < 0) |
| 202 | puts("error deleting initrd-end\n"); |
| 203 | |
| 204 | err = fdt_setprop(blob, nodeoffset, |
| 205 | "linux,initrd-start", |
| 206 | &initrd_start, |
| 207 | sizeof(initrd_start)); |
| 208 | if (err < 0) |
| 209 | puts("error adding initrd-start\n"); |
| 210 | |
| 211 | err = fdt_setprop(blob, nodeoffset, |
| 212 | "linux,initrd-end", |
| 213 | &initrd_end, |
| 214 | sizeof(initrd_end)); |
| 215 | if (err < 0) |
| 216 | puts("error adding linux,initrd-end\n"); |
| 217 | } |
| 218 | } |
| 219 | } |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 220 | |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 221 | if (lpae) { |
| 222 | /* |
| 223 | * the initrd and other reserved memory areas are |
| 224 | * embedded in in the DTB itslef. fix up these addresses |
| 225 | * to 36 bit format |
| 226 | */ |
| 227 | reserve_start = (u64 *)((char *)blob + |
| 228 | fdt_off_mem_rsvmap(blob)); |
| 229 | while (1) { |
| 230 | *reserve_start = __cpu_to_be64(*reserve_start); |
| 231 | size = __cpu_to_be64(*(reserve_start + 1)); |
| 232 | if (size) { |
Hao Zhang | e595107 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 233 | *reserve_start -= CONFIG_SYS_SDRAM_BASE; |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 234 | *reserve_start += |
| 235 | CONFIG_SYS_LPAE_SDRAM_BASE; |
| 236 | *reserve_start = |
| 237 | __cpu_to_be64(*reserve_start); |
| 238 | } else { |
| 239 | break; |
| 240 | } |
| 241 | reserve_start += 2; |
| 242 | } |
| 243 | } |
Vitaly Andrianov | 89f44bb | 2014-10-22 17:47:58 +0300 | [diff] [blame] | 244 | |
| 245 | ddr3_check_ecc_int(KS2_DDR3A_EMIF_CTRL_BASE); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 246 | } |
Robert P. J. Day | 7ffe3cd | 2016-05-19 15:23:12 -0400 | [diff] [blame] | 247 | #endif /* CONFIG_OF_BOARD_SETUP */ |
Cooper Jr., Franklin | 5f48da9 | 2017-06-16 17:25:15 -0500 | [diff] [blame] | 248 | |
| 249 | #if defined(CONFIG_DTB_RESELECT) |
| 250 | int __weak embedded_dtb_select(void) |
| 251 | { |
| 252 | return 0; |
| 253 | } |
| 254 | #endif |