blob: 35191b2f813b36a583fbec1ab79fb6846e6dee31 [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>
Michal Simeke6cc3b22018-02-21 17:04:28 +01008#include <dm/uclass.h>
Simon Glass9fb625c2019-08-01 09:46:51 -06009#include <env.h>
Michal Simek9e0e37a2014-02-24 11:16:32 +010010#include <fdtdec.h>
Michal Simek5b73caf2014-04-25 13:51:17 +020011#include <fpga.h>
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053012#include <malloc.h>
Michal Simek5b73caf2014-04-25 13:51:17 +020013#include <mmc.h>
Michal Simek0ecd14e2018-06-08 13:45:14 +020014#include <watchdog.h>
Michal Simeke6cc3b22018-02-21 17:04:28 +010015#include <wdt.h>
Michal Simekd5dae852013-04-22 15:43:02 +020016#include <zynqpl.h>
Michal Simek71936532013-04-12 16:33:08 +020017#include <asm/arch/hardware.h>
18#include <asm/arch/sys_proto.h>
Michal Simekf22651c2012-09-28 09:56:37 +000019
20DECLARE_GLOBAL_DATA_PTR;
21
Michal Simeke6cc3b22018-02-21 17:04:28 +010022#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_BOARD_EARLY_INIT_F)
23int board_early_init_f(void)
24{
Michal Simeke6cc3b22018-02-21 17:04:28 +010025 return 0;
26}
27#endif
28
Michal Simekf22651c2012-09-28 09:56:37 +000029int board_init(void)
30{
Michal Simekf22651c2012-09-28 09:56:37 +000031 return 0;
32}
33
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053034int board_late_init(void)
35{
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053036 int env_targets_len = 0;
37 const char *mode;
38 char *new_targets;
39 char *env_targets;
40
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053041 switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
Michal Simek085b2b82016-12-16 13:16:14 +010042 case ZYNQ_BM_QSPI:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053043 mode = "qspi";
Simon Glass382bee52017-08-03 12:22:09 -060044 env_set("modeboot", "qspiboot");
Michal Simek085b2b82016-12-16 13:16:14 +010045 break;
46 case ZYNQ_BM_NAND:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053047 mode = "nand";
Simon Glass382bee52017-08-03 12:22:09 -060048 env_set("modeboot", "nandboot");
Michal Simek085b2b82016-12-16 13:16:14 +010049 break;
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053050 case ZYNQ_BM_NOR:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053051 mode = "nor";
Simon Glass382bee52017-08-03 12:22:09 -060052 env_set("modeboot", "norboot");
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053053 break;
54 case ZYNQ_BM_SD:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053055 mode = "mmc";
Simon Glass382bee52017-08-03 12:22:09 -060056 env_set("modeboot", "sdboot");
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053057 break;
58 case ZYNQ_BM_JTAG:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053059 mode = "pxe dhcp";
Simon Glass382bee52017-08-03 12:22:09 -060060 env_set("modeboot", "jtagboot");
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053061 break;
62 default:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053063 mode = "";
Simon Glass382bee52017-08-03 12:22:09 -060064 env_set("modeboot", "");
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053065 break;
66 }
67
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053068 /*
69 * One terminating char + one byte for space between mode
70 * and default boot_targets
71 */
72 env_targets = env_get("boot_targets");
73 if (env_targets)
74 env_targets_len = strlen(env_targets);
75
76 new_targets = calloc(1, strlen(mode) + env_targets_len + 2);
77 if (!new_targets)
78 return -ENOMEM;
79
80 sprintf(new_targets, "%s %s", mode,
81 env_targets ? env_targets : "");
82
83 env_set("boot_targets", new_targets);
84
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053085 return 0;
86}
Michal Simekf22651c2012-09-28 09:56:37 +000087
Michal Simek758f29d2016-04-01 15:56:33 +020088#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass76b00ac2017-03-31 08:40:32 -060089int dram_init_banksize(void)
Tom Rini361a8792016-12-09 07:56:54 -050090{
Michal Simekda3f0032017-11-03 15:25:51 +010091 return fdtdec_setup_memory_banksize();
Michal Simek758f29d2016-04-01 15:56:33 +020092}
93
Michal Simek8a5db0a2016-12-06 16:31:53 +010094int dram_init(void)
95{
Siva Durga Prasad Paladugu12308b12018-07-16 15:56:11 +053096 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rosside9bf1b2016-12-19 00:03:34 +100097 return -EINVAL;
Michal Simek8a5db0a2016-12-06 16:31:53 +010098
99 zynq_ddrc_init();
100
101 return 0;
102}
Michal Simek758f29d2016-04-01 15:56:33 +0200103#else
104int dram_init(void)
105{
Michal Simek61dc92a2018-04-11 16:12:28 +0200106 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
107 CONFIG_SYS_SDRAM_SIZE);
Michal Simek758f29d2016-04-01 15:56:33 +0200108
109 zynq_ddrc_init();
110
111 return 0;
112}
113#endif