Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 1 | /* |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 2 | * Keystone : Board initialization |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 3 | * |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 4 | * (C) Copyright 2014 |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 5 | * Texas Instruments Incorporated, <www.ti.com> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 10 | #include "board.h" |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 11 | #include <common.h> |
Hao Zhang | 9594820 | 2014-10-22 16:32:31 +0300 | [diff] [blame^] | 12 | #include <spl.h> |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 13 | #include <exports.h> |
| 14 | #include <fdt_support.h> |
Khoronzhuk, Ivan | 50df5cc | 2014-07-09 19:48:40 +0300 | [diff] [blame] | 15 | #include <asm/arch/ddr3.h> |
Karicheri, Muralidharan | 657f6b5 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 16 | #include <asm/arch/emac_defs.h> |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 17 | #include <asm/ti-common/ti-aemif.h> |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 21 | static struct aemif_config aemif_configs[] = { |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 22 | { /* CS0 */ |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 23 | .mode = AEMIF_MODE_NAND, |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 24 | .wr_setup = 0xf, |
| 25 | .wr_strobe = 0x3f, |
| 26 | .wr_hold = 7, |
| 27 | .rd_setup = 0xf, |
| 28 | .rd_strobe = 0x3f, |
| 29 | .rd_hold = 7, |
| 30 | .turn_around = 3, |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 31 | .width = AEMIF_WIDTH_8, |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 32 | }, |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | int dram_init(void) |
| 36 | { |
Khoronzhuk, Ivan | 50df5cc | 2014-07-09 19:48:40 +0300 | [diff] [blame] | 37 | ddr3_init(); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 38 | |
| 39 | gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, |
| 40 | CONFIG_MAX_RAM_BANK_SIZE); |
Khoronzhuk, Ivan | 8062b05 | 2014-06-07 05:10:49 +0300 | [diff] [blame] | 41 | aemif_init(ARRAY_SIZE(aemif_configs), aemif_configs); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 42 | return 0; |
| 43 | } |
| 44 | |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 45 | int board_init(void) |
| 46 | { |
| 47 | gd->bd->bi_boot_params = CONFIG_LINUX_BOOT_PARAM_ADDR; |
| 48 | |
| 49 | return 0; |
| 50 | } |
Karicheri, Muralidharan | 657f6b5 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 51 | |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 52 | #ifdef CONFIG_DRIVER_TI_KEYSTONE_NET |
Karicheri, Muralidharan | 657f6b5 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 53 | int get_eth_env_param(char *env_name) |
| 54 | { |
| 55 | char *env; |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 56 | int res = -1; |
Karicheri, Muralidharan | 657f6b5 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 57 | |
| 58 | env = getenv(env_name); |
| 59 | if (env) |
| 60 | res = simple_strtol(env, NULL, 0); |
| 61 | |
| 62 | return res; |
| 63 | } |
| 64 | |
| 65 | int board_eth_init(bd_t *bis) |
| 66 | { |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 67 | int j; |
| 68 | int res; |
| 69 | int port_num; |
| 70 | char link_type_name[32]; |
Karicheri, Muralidharan | 657f6b5 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 71 | |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 72 | port_num = get_num_eth_ports(); |
| 73 | |
| 74 | for (j = 0; j < port_num; j++) { |
Karicheri, Muralidharan | 657f6b5 | 2014-04-01 15:01:13 -0400 | [diff] [blame] | 75 | sprintf(link_type_name, "sgmii%d_link_type", j); |
| 76 | res = get_eth_env_param(link_type_name); |
| 77 | if (res >= 0) |
| 78 | eth_priv_cfg[j].sgmii_link_type = res; |
| 79 | |
| 80 | keystone2_emac_initialize(ð_priv_cfg[j]); |
| 81 | } |
| 82 | |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| 85 | #endif |
| 86 | |
Hao Zhang | 9594820 | 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 | |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 105 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 106 | void ft_board_setup(void *blob, bd_t *bd) |
| 107 | { |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 108 | int lpae; |
| 109 | char *env; |
| 110 | char *endp; |
| 111 | int nbanks; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 112 | u64 size[2]; |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 113 | u64 start[2]; |
| 114 | char name[32]; |
| 115 | int nodeoffset; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 116 | u32 ddr3a_size; |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 117 | int unitrd_fixup = 0; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 118 | |
| 119 | env = getenv("mem_lpae"); |
| 120 | lpae = env && simple_strtol(env, NULL, 0); |
Murali Karicheri | 1b84532 | 2014-07-09 23:44:45 +0300 | [diff] [blame] | 121 | env = getenv("uinitrd_fixup"); |
| 122 | unitrd_fixup = env && simple_strtol(env, NULL, 0); |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 123 | |
| 124 | ddr3a_size = 0; |
| 125 | if (lpae) { |
| 126 | env = getenv("ddr3a_size"); |
| 127 | if (env) |
| 128 | ddr3a_size = simple_strtol(env, NULL, 10); |
| 129 | if ((ddr3a_size != 8) && (ddr3a_size != 4)) |
| 130 | ddr3a_size = 0; |
| 131 | } |
| 132 | |
| 133 | nbanks = 1; |
| 134 | start[0] = bd->bi_dram[0].start; |
| 135 | size[0] = bd->bi_dram[0].size; |
| 136 | |
| 137 | /* adjust memory start address for LPAE */ |
| 138 | if (lpae) { |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 139 | start[0] -= CONFIG_SYS_SDRAM_BASE; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 140 | start[0] += CONFIG_SYS_LPAE_SDRAM_BASE; |
| 141 | } |
| 142 | |
| 143 | if ((size[0] == 0x80000000) && (ddr3a_size != 0)) { |
| 144 | size[1] = ((u64)ddr3a_size - 2) << 30; |
| 145 | start[1] = 0x880000000; |
| 146 | nbanks++; |
| 147 | } |
| 148 | |
| 149 | /* reserve memory at start of bank */ |
| 150 | sprintf(name, "mem_reserve_head"); |
| 151 | env = getenv(name); |
| 152 | if (env) { |
| 153 | start[0] += ustrtoul(env, &endp, 0); |
| 154 | size[0] -= ustrtoul(env, &endp, 0); |
| 155 | } |
| 156 | |
| 157 | sprintf(name, "mem_reserve"); |
| 158 | env = getenv(name); |
| 159 | if (env) |
| 160 | size[0] -= ustrtoul(env, &endp, 0); |
| 161 | |
| 162 | fdt_fixup_memory_banks(blob, start, size, nbanks); |
| 163 | |
| 164 | /* Fix up the initrd */ |
Murali Karicheri | 1b84532 | 2014-07-09 23:44:45 +0300 | [diff] [blame] | 165 | if (lpae && unitrd_fixup) { |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 166 | int err; |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 167 | u32 *prop1, *prop2; |
| 168 | u64 initrd_start, initrd_end; |
Murali Karicheri | 1b84532 | 2014-07-09 23:44:45 +0300 | [diff] [blame] | 169 | |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 170 | nodeoffset = fdt_path_offset(blob, "/chosen"); |
| 171 | if (nodeoffset >= 0) { |
| 172 | prop1 = (u32 *)fdt_getprop(blob, nodeoffset, |
| 173 | "linux,initrd-start", NULL); |
| 174 | prop2 = (u32 *)fdt_getprop(blob, nodeoffset, |
| 175 | "linux,initrd-end", NULL); |
| 176 | if (prop1 && prop2) { |
| 177 | initrd_start = __be32_to_cpu(*prop1); |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 178 | initrd_start -= CONFIG_SYS_SDRAM_BASE; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 179 | initrd_start += CONFIG_SYS_LPAE_SDRAM_BASE; |
| 180 | initrd_start = __cpu_to_be64(initrd_start); |
| 181 | initrd_end = __be32_to_cpu(*prop2); |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 182 | initrd_end -= CONFIG_SYS_SDRAM_BASE; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 183 | initrd_end += CONFIG_SYS_LPAE_SDRAM_BASE; |
| 184 | initrd_end = __cpu_to_be64(initrd_end); |
| 185 | |
| 186 | err = fdt_delprop(blob, nodeoffset, |
| 187 | "linux,initrd-start"); |
| 188 | if (err < 0) |
| 189 | puts("error deleting initrd-start\n"); |
| 190 | |
| 191 | err = fdt_delprop(blob, nodeoffset, |
| 192 | "linux,initrd-end"); |
| 193 | if (err < 0) |
| 194 | puts("error deleting initrd-end\n"); |
| 195 | |
| 196 | err = fdt_setprop(blob, nodeoffset, |
| 197 | "linux,initrd-start", |
| 198 | &initrd_start, |
| 199 | sizeof(initrd_start)); |
| 200 | if (err < 0) |
| 201 | puts("error adding initrd-start\n"); |
| 202 | |
| 203 | err = fdt_setprop(blob, nodeoffset, |
| 204 | "linux,initrd-end", |
| 205 | &initrd_end, |
| 206 | sizeof(initrd_end)); |
| 207 | if (err < 0) |
| 208 | puts("error adding linux,initrd-end\n"); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | void ft_board_setup_ex(void *blob, bd_t *bd) |
| 215 | { |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 216 | int lpae; |
| 217 | u64 size; |
| 218 | char *env; |
| 219 | u64 *reserve_start; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 220 | |
| 221 | env = getenv("mem_lpae"); |
| 222 | lpae = env && simple_strtol(env, NULL, 0); |
| 223 | |
| 224 | if (lpae) { |
| 225 | /* |
| 226 | * the initrd and other reserved memory areas are |
| 227 | * embedded in in the DTB itslef. fix up these addresses |
| 228 | * to 36 bit format |
| 229 | */ |
| 230 | reserve_start = (u64 *)((char *)blob + |
| 231 | fdt_off_mem_rsvmap(blob)); |
| 232 | while (1) { |
| 233 | *reserve_start = __cpu_to_be64(*reserve_start); |
| 234 | size = __cpu_to_be64(*(reserve_start + 1)); |
| 235 | if (size) { |
Hao Zhang | 8e697a0 | 2014-07-09 23:44:46 +0300 | [diff] [blame] | 236 | *reserve_start -= CONFIG_SYS_SDRAM_BASE; |
Vitaly Andrianov | 7bcf4d6 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 237 | *reserve_start += |
| 238 | CONFIG_SYS_LPAE_SDRAM_BASE; |
| 239 | *reserve_start = |
| 240 | __cpu_to_be64(*reserve_start); |
| 241 | } else { |
| 242 | break; |
| 243 | } |
| 244 | reserve_start += 2; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | #endif |