blob: cffabe825a201528c867e04355a40ffc065201f0 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simekf22651c2012-09-28 09:56:37 +00002/*
3 * (C) Copyright 2012 Michal Simek <monstr@monstr.eu>
Michal Simek3e1b61d2018-01-17 07:37:47 +01004 * (C) Copyright 2013 - 2018 Xilinx, Inc.
Michal Simekf22651c2012-09-28 09:56:37 +00005 */
6
7#include <common.h>
Simon Glass52559322019-11-14 12:57:46 -07008#include <init.h>
Michal Simeke6cc3b22018-02-21 17:04:28 +01009#include <dm/uclass.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060010#include <env.h>
Michal Simek9e0e37a2014-02-24 11:16:32 +010011#include <fdtdec.h>
Michal Simek5b73caf2014-04-25 13:51:17 +020012#include <fpga.h>
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053013#include <malloc.h>
Michal Simek5b73caf2014-04-25 13:51:17 +020014#include <mmc.h>
Michal Simek0ecd14e2018-06-08 13:45:14 +020015#include <watchdog.h>
Michal Simeke6cc3b22018-02-21 17:04:28 +010016#include <wdt.h>
Michal Simekd5dae852013-04-22 15:43:02 +020017#include <zynqpl.h>
Michal Simek71936532013-04-12 16:33:08 +020018#include <asm/arch/hardware.h>
19#include <asm/arch/sys_proto.h>
Michal Simekf22651c2012-09-28 09:56:37 +000020
21DECLARE_GLOBAL_DATA_PTR;
22
23int board_init(void)
24{
Michal Simekf22651c2012-09-28 09:56:37 +000025 return 0;
26}
27
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053028int board_late_init(void)
29{
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053030 int env_targets_len = 0;
31 const char *mode;
32 char *new_targets;
33 char *env_targets;
34
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053035 switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
Michal Simek085b2b82016-12-16 13:16:14 +010036 case ZYNQ_BM_QSPI:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053037 mode = "qspi";
Simon Glass382bee52017-08-03 12:22:09 -060038 env_set("modeboot", "qspiboot");
Michal Simek085b2b82016-12-16 13:16:14 +010039 break;
40 case ZYNQ_BM_NAND:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053041 mode = "nand";
Simon Glass382bee52017-08-03 12:22:09 -060042 env_set("modeboot", "nandboot");
Michal Simek085b2b82016-12-16 13:16:14 +010043 break;
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053044 case ZYNQ_BM_NOR:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053045 mode = "nor";
Simon Glass382bee52017-08-03 12:22:09 -060046 env_set("modeboot", "norboot");
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053047 break;
48 case ZYNQ_BM_SD:
Michal Simek7712fb12019-09-11 12:51:49 +020049 mode = "mmc0";
Simon Glass382bee52017-08-03 12:22:09 -060050 env_set("modeboot", "sdboot");
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053051 break;
52 case ZYNQ_BM_JTAG:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053053 mode = "pxe dhcp";
Simon Glass382bee52017-08-03 12:22:09 -060054 env_set("modeboot", "jtagboot");
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053055 break;
56 default:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053057 mode = "";
Simon Glass382bee52017-08-03 12:22:09 -060058 env_set("modeboot", "");
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053059 break;
60 }
61
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053062 /*
63 * One terminating char + one byte for space between mode
64 * and default boot_targets
65 */
66 env_targets = env_get("boot_targets");
67 if (env_targets)
68 env_targets_len = strlen(env_targets);
69
70 new_targets = calloc(1, strlen(mode) + env_targets_len + 2);
71 if (!new_targets)
72 return -ENOMEM;
73
74 sprintf(new_targets, "%s %s", mode,
75 env_targets ? env_targets : "");
76
77 env_set("boot_targets", new_targets);
78
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053079 return 0;
80}
Michal Simekf22651c2012-09-28 09:56:37 +000081
Michal Simek758f29d2016-04-01 15:56:33 +020082#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass76b00ac2017-03-31 08:40:32 -060083int dram_init_banksize(void)
Tom Rini361a8792016-12-09 07:56:54 -050084{
Michal Simekda3f0032017-11-03 15:25:51 +010085 return fdtdec_setup_memory_banksize();
Michal Simek758f29d2016-04-01 15:56:33 +020086}
87
Michal Simek8a5db0a2016-12-06 16:31:53 +010088int dram_init(void)
89{
Siva Durga Prasad Paladugu12308b12018-07-16 15:56:11 +053090 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rosside9bf1b2016-12-19 00:03:34 +100091 return -EINVAL;
Michal Simek8a5db0a2016-12-06 16:31:53 +010092
93 zynq_ddrc_init();
94
95 return 0;
96}
Michal Simek758f29d2016-04-01 15:56:33 +020097#else
98int dram_init(void)
99{
Michal Simek61dc92a2018-04-11 16:12:28 +0200100 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
101 CONFIG_SYS_SDRAM_SIZE);
Michal Simek758f29d2016-04-01 15:56:33 +0200102
103 zynq_ddrc_init();
104
105 return 0;
106}
107#endif