2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-04-04 17:16:53 +00:00
|
|
|
/*
|
2014-07-09 20:44:46 +00:00
|
|
|
* Keystone : Board initialization
|
2014-04-04 17:16:53 +00:00
|
|
|
*
|
2014-07-09 20:44:46 +00:00
|
|
|
* (C) Copyright 2014
|
2014-04-04 17:16:53 +00:00
|
|
|
* Texas Instruments Incorporated, <www.ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2016-03-11 13:23:04 +00:00
|
|
|
#include "board.h"
|
2019-08-01 15:46:52 +00:00
|
|
|
#include <env.h>
|
2019-12-28 17:45:07 +00:00
|
|
|
#include <hang.h>
|
2020-05-10 17:40:01 +00:00
|
|
|
#include <image.h>
|
2019-12-28 17:45:05 +00:00
|
|
|
#include <init.h>
|
2014-10-22 13:32:31 +00:00
|
|
|
#include <spl.h>
|
2014-04-04 17:16:53 +00:00
|
|
|
#include <exports.h>
|
|
|
|
#include <fdt_support.h>
|
2014-07-09 16:48:40 +00:00
|
|
|
#include <asm/arch/ddr3.h>
|
2014-09-29 19:17:24 +00:00
|
|
|
#include <asm/arch/psc_defs.h>
|
2015-10-08 06:01:47 +00:00
|
|
|
#include <asm/arch/clock.h>
|
2014-06-07 02:10:49 +00:00
|
|
|
#include <asm/ti-common/ti-aemif.h>
|
2014-09-29 19:17:22 +00:00
|
|
|
#include <asm/ti-common/keystone_net.h>
|
2014-04-04 17:16:53 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2016-04-13 04:20:59 +00:00
|
|
|
#if defined(CONFIG_TI_AEMIF)
|
2014-06-07 02:10:49 +00:00
|
|
|
static struct aemif_config aemif_configs[] = {
|
2014-04-04 17:16:53 +00:00
|
|
|
{ /* CS0 */
|
2014-06-07 02:10:49 +00:00
|
|
|
.mode = AEMIF_MODE_NAND,
|
2014-04-04 17:16:53 +00:00
|
|
|
.wr_setup = 0xf,
|
|
|
|
.wr_strobe = 0x3f,
|
|
|
|
.wr_hold = 7,
|
|
|
|
.rd_setup = 0xf,
|
|
|
|
.rd_strobe = 0x3f,
|
|
|
|
.rd_hold = 7,
|
|
|
|
.turn_around = 3,
|
2014-06-07 02:10:49 +00:00
|
|
|
.width = AEMIF_WIDTH_8,
|
2014-04-04 17:16:53 +00:00
|
|
|
},
|
|
|
|
};
|
2016-04-13 04:20:59 +00:00
|
|
|
#endif
|
2014-04-04 17:16:53 +00:00
|
|
|
|
|
|
|
int dram_init(void)
|
|
|
|
{
|
2015-02-11 19:07:58 +00:00
|
|
|
u32 ddr3_size;
|
|
|
|
|
|
|
|
ddr3_size = ddr3_init();
|
2014-04-04 17:16:53 +00:00
|
|
|
|
2022-11-16 18:10:37 +00:00
|
|
|
gd->ram_size = get_ram_size((long *)CFG_SYS_SDRAM_BASE,
|
2014-04-04 17:16:53 +00:00
|
|
|
CONFIG_MAX_RAM_BANK_SIZE);
|
2016-04-13 04:20:59 +00:00
|
|
|
#if defined(CONFIG_TI_AEMIF)
|
2020-12-17 17:28:07 +00:00
|
|
|
if (!(board_is_k2g_ice() || board_is_k2g_i1()))
|
2017-06-16 22:25:25 +00:00
|
|
|
aemif_init(ARRAY_SIZE(aemif_configs), aemif_configs);
|
2016-04-13 04:20:59 +00:00
|
|
|
#endif
|
|
|
|
|
2020-12-17 17:28:07 +00:00
|
|
|
if (!(board_is_k2g_ice() || board_is_k2g_i1())) {
|
2017-06-16 22:25:25 +00:00
|
|
|
if (ddr3_size)
|
|
|
|
ddr3_init_ecc(KS2_DDR3A_EMIF_CTRL_BASE, ddr3_size);
|
|
|
|
else
|
|
|
|
ddr3_init_ecc(KS2_DDR3A_EMIF_CTRL_BASE,
|
|
|
|
gd->ram_size >> 30);
|
|
|
|
}
|
2016-08-27 11:49:15 +00:00
|
|
|
|
2014-04-04 17:16:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-09-07 02:26:52 +00:00
|
|
|
struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size)
|
2018-11-27 12:22:41 +00:00
|
|
|
{
|
2022-10-21 00:22:39 +00:00
|
|
|
return (struct legacy_img_hdr *)(CONFIG_TEXT_BASE);
|
2018-11-27 12:22:41 +00:00
|
|
|
}
|
|
|
|
|
2014-07-09 20:44:46 +00:00
|
|
|
int board_init(void)
|
|
|
|
{
|
2022-11-16 18:10:37 +00:00
|
|
|
gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100;
|
2014-07-09 20:44:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-04-01 19:01:13 +00:00
|
|
|
|
2014-10-22 13:32:31 +00:00
|
|
|
#ifdef CONFIG_SPL_BUILD
|
|
|
|
void spl_board_init(void)
|
|
|
|
{
|
|
|
|
spl_init_keystone_plls();
|
|
|
|
preloader_console_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 spl_boot_device(void)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_SPL_SPI_LOAD)
|
|
|
|
return BOOT_DEVICE_SPI;
|
|
|
|
#else
|
|
|
|
puts("Unknown boot device\n");
|
|
|
|
hang();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-05-19 19:23:12 +00:00
|
|
|
#ifdef CONFIG_OF_BOARD_SETUP
|
2020-06-26 06:13:33 +00:00
|
|
|
int ft_board_setup(void *blob, struct bd_info *bd)
|
2014-04-04 17:16:53 +00:00
|
|
|
{
|
2014-07-09 20:44:46 +00:00
|
|
|
int lpae;
|
|
|
|
char *env;
|
|
|
|
char *endp;
|
|
|
|
int nbanks;
|
2014-04-04 17:16:53 +00:00
|
|
|
u64 size[2];
|
2014-07-09 20:44:46 +00:00
|
|
|
u64 start[2];
|
2014-04-04 17:16:53 +00:00
|
|
|
u32 ddr3a_size;
|
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
env = env_get("mem_lpae");
|
2014-04-04 17:16:53 +00:00
|
|
|
lpae = env && simple_strtol(env, NULL, 0);
|
|
|
|
|
|
|
|
ddr3a_size = 0;
|
|
|
|
if (lpae) {
|
2016-03-04 16:36:43 +00:00
|
|
|
ddr3a_size = ddr3_get_size();
|
2014-04-04 17:16:53 +00:00
|
|
|
if ((ddr3a_size != 8) && (ddr3a_size != 4))
|
|
|
|
ddr3a_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nbanks = 1;
|
|
|
|
start[0] = bd->bi_dram[0].start;
|
|
|
|
size[0] = bd->bi_dram[0].size;
|
|
|
|
|
|
|
|
/* adjust memory start address for LPAE */
|
|
|
|
if (lpae) {
|
2022-11-16 18:10:37 +00:00
|
|
|
start[0] -= CFG_SYS_SDRAM_BASE;
|
2022-11-16 18:10:41 +00:00
|
|
|
start[0] += CFG_SYS_LPAE_SDRAM_BASE;
|
2014-04-04 17:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((size[0] == 0x80000000) && (ddr3a_size != 0)) {
|
|
|
|
size[1] = ((u64)ddr3a_size - 2) << 30;
|
|
|
|
start[1] = 0x880000000;
|
|
|
|
nbanks++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reserve memory at start of bank */
|
2017-08-03 18:22:12 +00:00
|
|
|
env = env_get("mem_reserve_head");
|
2014-04-04 17:16:53 +00:00
|
|
|
if (env) {
|
|
|
|
start[0] += ustrtoul(env, &endp, 0);
|
|
|
|
size[0] -= ustrtoul(env, &endp, 0);
|
|
|
|
}
|
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
env = env_get("mem_reserve");
|
2014-04-04 17:16:53 +00:00
|
|
|
if (env)
|
|
|
|
size[0] -= ustrtoul(env, &endp, 0);
|
|
|
|
|
|
|
|
fdt_fixup_memory_banks(blob, start, size, nbanks);
|
|
|
|
|
2018-10-03 10:58:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-26 06:13:33 +00:00
|
|
|
void ft_board_setup_ex(void *blob, struct bd_info *bd)
|
2018-10-03 10:58:49 +00:00
|
|
|
{
|
|
|
|
int lpae;
|
|
|
|
u64 size;
|
|
|
|
char *env;
|
|
|
|
u64 *reserve_start;
|
|
|
|
int unitrd_fixup = 0;
|
|
|
|
|
|
|
|
env = env_get("mem_lpae");
|
|
|
|
lpae = env && simple_strtol(env, NULL, 0);
|
|
|
|
env = env_get("uinitrd_fixup");
|
|
|
|
unitrd_fixup = env && simple_strtol(env, NULL, 0);
|
|
|
|
|
2014-04-04 17:16:53 +00:00
|
|
|
/* Fix up the initrd */
|
2014-07-09 20:44:45 +00:00
|
|
|
if (lpae && unitrd_fixup) {
|
2018-10-03 10:58:49 +00:00
|
|
|
int nodeoffset;
|
2014-04-04 17:16:53 +00:00
|
|
|
int err;
|
2018-10-03 10:58:49 +00:00
|
|
|
u64 *prop1, *prop2;
|
2014-07-09 20:44:46 +00:00
|
|
|
u64 initrd_start, initrd_end;
|
2014-07-09 20:44:45 +00:00
|
|
|
|
2014-04-04 17:16:53 +00:00
|
|
|
nodeoffset = fdt_path_offset(blob, "/chosen");
|
|
|
|
if (nodeoffset >= 0) {
|
2018-10-03 10:58:49 +00:00
|
|
|
prop1 = (u64 *)fdt_getprop(blob, nodeoffset,
|
2014-04-04 17:16:53 +00:00
|
|
|
"linux,initrd-start", NULL);
|
2018-10-03 10:58:49 +00:00
|
|
|
prop2 = (u64 *)fdt_getprop(blob, nodeoffset,
|
2014-04-04 17:16:53 +00:00
|
|
|
"linux,initrd-end", NULL);
|
|
|
|
if (prop1 && prop2) {
|
2018-10-03 10:58:49 +00:00
|
|
|
initrd_start = __be64_to_cpu(*prop1);
|
2022-11-16 18:10:37 +00:00
|
|
|
initrd_start -= CFG_SYS_SDRAM_BASE;
|
2022-11-16 18:10:41 +00:00
|
|
|
initrd_start += CFG_SYS_LPAE_SDRAM_BASE;
|
2014-04-04 17:16:53 +00:00
|
|
|
initrd_start = __cpu_to_be64(initrd_start);
|
2018-10-03 10:58:49 +00:00
|
|
|
initrd_end = __be64_to_cpu(*prop2);
|
2022-11-16 18:10:37 +00:00
|
|
|
initrd_end -= CFG_SYS_SDRAM_BASE;
|
2022-11-16 18:10:41 +00:00
|
|
|
initrd_end += CFG_SYS_LPAE_SDRAM_BASE;
|
2014-04-04 17:16:53 +00:00
|
|
|
initrd_end = __cpu_to_be64(initrd_end);
|
|
|
|
|
|
|
|
err = fdt_delprop(blob, nodeoffset,
|
|
|
|
"linux,initrd-start");
|
|
|
|
if (err < 0)
|
|
|
|
puts("error deleting initrd-start\n");
|
|
|
|
|
|
|
|
err = fdt_delprop(blob, nodeoffset,
|
|
|
|
"linux,initrd-end");
|
|
|
|
if (err < 0)
|
|
|
|
puts("error deleting initrd-end\n");
|
|
|
|
|
|
|
|
err = fdt_setprop(blob, nodeoffset,
|
|
|
|
"linux,initrd-start",
|
|
|
|
&initrd_start,
|
|
|
|
sizeof(initrd_start));
|
|
|
|
if (err < 0)
|
|
|
|
puts("error adding initrd-start\n");
|
|
|
|
|
|
|
|
err = fdt_setprop(blob, nodeoffset,
|
|
|
|
"linux,initrd-end",
|
|
|
|
&initrd_end,
|
|
|
|
sizeof(initrd_end));
|
|
|
|
if (err < 0)
|
|
|
|
puts("error adding linux,initrd-end\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-24 00:58:47 +00:00
|
|
|
|
2014-04-04 17:16:53 +00:00
|
|
|
if (lpae) {
|
|
|
|
/*
|
|
|
|
* the initrd and other reserved memory areas are
|
|
|
|
* embedded in in the DTB itslef. fix up these addresses
|
|
|
|
* to 36 bit format
|
|
|
|
*/
|
|
|
|
reserve_start = (u64 *)((char *)blob +
|
|
|
|
fdt_off_mem_rsvmap(blob));
|
|
|
|
while (1) {
|
|
|
|
*reserve_start = __cpu_to_be64(*reserve_start);
|
|
|
|
size = __cpu_to_be64(*(reserve_start + 1));
|
|
|
|
if (size) {
|
2022-11-16 18:10:37 +00:00
|
|
|
*reserve_start -= CFG_SYS_SDRAM_BASE;
|
2014-04-04 17:16:53 +00:00
|
|
|
*reserve_start +=
|
2022-11-16 18:10:41 +00:00
|
|
|
CFG_SYS_LPAE_SDRAM_BASE;
|
2014-04-04 17:16:53 +00:00
|
|
|
*reserve_start =
|
|
|
|
__cpu_to_be64(*reserve_start);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
reserve_start += 2;
|
|
|
|
}
|
|
|
|
}
|
2014-10-22 14:47:58 +00:00
|
|
|
|
|
|
|
ddr3_check_ecc_int(KS2_DDR3A_EMIF_CTRL_BASE);
|
2014-04-04 17:16:53 +00:00
|
|
|
}
|
2016-05-19 19:23:12 +00:00
|
|
|
#endif /* CONFIG_OF_BOARD_SETUP */
|
2017-06-16 22:25:15 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_DTB_RESELECT)
|
|
|
|
int __weak embedded_dtb_select(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|