blob: 49ff3f0dc0e91852bc080bcbeaaa1b7eca783008 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simekaf482d52012-09-28 09:56:37 +00002/*
3 * (C) Copyright 2012 Michal Simek <monstr@monstr.eu>
Michal Simek98d0f1f2018-01-17 07:37:47 +01004 * (C) Copyright 2013 - 2018 Xilinx, Inc.
Michal Simekaf482d52012-09-28 09:56:37 +00005 */
6
7#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -07008#include <init.h>
Michal Simekbab07b62020-07-28 12:45:47 +02009#include <log.h>
Michal Simek309ef802018-02-21 17:04:28 +010010#include <dm/uclass.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060011#include <env.h>
Michal Simek65ef52f2014-02-24 11:16:32 +010012#include <fdtdec.h>
Michal Simek0f796702014-04-25 13:51:17 +020013#include <fpga.h>
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053014#include <malloc.h>
Michal Simek0f796702014-04-25 13:51:17 +020015#include <mmc.h>
Michal Simekc07b2252018-06-08 13:45:14 +020016#include <watchdog.h>
Michal Simek309ef802018-02-21 17:04:28 +010017#include <wdt.h>
Michal Simek15d654c2013-04-22 15:43:02 +020018#include <zynqpl.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060019#include <asm/global_data.h>
Michal Simek242192b2013-04-12 16:33:08 +020020#include <asm/arch/hardware.h>
21#include <asm/arch/sys_proto.h>
Michal Simek705d44a2020-03-31 12:39:37 +020022#include "../common/board.h"
Michal Simekaf482d52012-09-28 09:56:37 +000023
24DECLARE_GLOBAL_DATA_PTR;
25
26int board_init(void)
27{
Michal Simekaf482d52012-09-28 09:56:37 +000028 return 0;
29}
30
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053031int board_late_init(void)
32{
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053033 int env_targets_len = 0;
34 const char *mode;
35 char *new_targets;
36 char *env_targets;
37
Michal Simekbab07b62020-07-28 12:45:47 +020038 if (!(gd->flags & GD_FLG_ENV_DEFAULT)) {
39 debug("Saved variables - Skipping\n");
40 return 0;
41 }
42
43 if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG))
44 return 0;
45
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053046 switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
Michal Simek19356712016-12-16 13:16:14 +010047 case ZYNQ_BM_QSPI:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053048 mode = "qspi";
Simon Glass6a38e412017-08-03 12:22:09 -060049 env_set("modeboot", "qspiboot");
Michal Simek19356712016-12-16 13:16:14 +010050 break;
51 case ZYNQ_BM_NAND:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053052 mode = "nand";
Simon Glass6a38e412017-08-03 12:22:09 -060053 env_set("modeboot", "nandboot");
Michal Simek19356712016-12-16 13:16:14 +010054 break;
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053055 case ZYNQ_BM_NOR:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053056 mode = "nor";
Simon Glass6a38e412017-08-03 12:22:09 -060057 env_set("modeboot", "norboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053058 break;
59 case ZYNQ_BM_SD:
Michal Simek9541d0b2019-09-11 12:51:49 +020060 mode = "mmc0";
Simon Glass6a38e412017-08-03 12:22:09 -060061 env_set("modeboot", "sdboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053062 break;
63 case ZYNQ_BM_JTAG:
T Karthik Reddy6c28c292019-11-13 21:13:44 -070064 mode = "jtag pxe dhcp";
Simon Glass6a38e412017-08-03 12:22:09 -060065 env_set("modeboot", "jtagboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053066 break;
67 default:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053068 mode = "";
Simon Glass6a38e412017-08-03 12:22:09 -060069 env_set("modeboot", "");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053070 break;
71 }
72
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053073 /*
74 * One terminating char + one byte for space between mode
75 * and default boot_targets
76 */
77 env_targets = env_get("boot_targets");
78 if (env_targets)
79 env_targets_len = strlen(env_targets);
80
81 new_targets = calloc(1, strlen(mode) + env_targets_len + 2);
82 if (!new_targets)
83 return -ENOMEM;
84
85 sprintf(new_targets, "%s %s", mode,
86 env_targets ? env_targets : "");
87
88 env_set("boot_targets", new_targets);
89
Michal Simek705d44a2020-03-31 12:39:37 +020090 return board_late_init_xilinx();
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053091}
Michal Simekaf482d52012-09-28 09:56:37 +000092
Michal Simekf4780a72016-04-01 15:56:33 +020093#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -060094int dram_init_banksize(void)
Nathan Rossic12892b2016-12-04 19:33:22 +100095{
Michal Simekd5b7de62017-11-03 15:25:51 +010096 return fdtdec_setup_memory_banksize();
Tom Riniedcfdbd2016-12-09 07:56:54 -050097}
Michal Simekf4780a72016-04-01 15:56:33 +020098
Tom Riniedcfdbd2016-12-09 07:56:54 -050099int dram_init(void)
100{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530101 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossi58ea0d82016-12-19 00:03:34 +1000102 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500103
104 zynq_ddrc_init();
105
106 return 0;
Michal Simekf4780a72016-04-01 15:56:33 +0200107}
Michal Simekf4780a72016-04-01 15:56:33 +0200108#else
109int dram_init(void)
110{
Michal Simek1b846212018-04-11 16:12:28 +0200111 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
112 CONFIG_SYS_SDRAM_SIZE);
Michal Simekf4780a72016-04-01 15:56:33 +0200113
Michal Simekf5ff7bc2013-06-17 14:37:01 +0200114 zynq_ddrc_init();
115
Michal Simekaf482d52012-09-28 09:56:37 +0000116 return 0;
117}
Michal Simekf4780a72016-04-01 15:56:33 +0200118#endif