blob: 8a216ed619bf51a819111a2be939d288cf9fa5c6 [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
22int board_init(void)
23{
Michal Simekf22651c2012-09-28 09:56:37 +000024 return 0;
25}
26
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053027int board_late_init(void)
28{
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053029 int env_targets_len = 0;
30 const char *mode;
31 char *new_targets;
32 char *env_targets;
33
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053034 switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
Michal Simek085b2b82016-12-16 13:16:14 +010035 case ZYNQ_BM_QSPI:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053036 mode = "qspi";
Simon Glass382bee52017-08-03 12:22:09 -060037 env_set("modeboot", "qspiboot");
Michal Simek085b2b82016-12-16 13:16:14 +010038 break;
39 case ZYNQ_BM_NAND:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053040 mode = "nand";
Simon Glass382bee52017-08-03 12:22:09 -060041 env_set("modeboot", "nandboot");
Michal Simek085b2b82016-12-16 13:16:14 +010042 break;
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053043 case ZYNQ_BM_NOR:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053044 mode = "nor";
Simon Glass382bee52017-08-03 12:22:09 -060045 env_set("modeboot", "norboot");
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053046 break;
47 case ZYNQ_BM_SD:
Michal Simek7712fb12019-09-11 12:51:49 +020048 mode = "mmc0";
Simon Glass382bee52017-08-03 12:22:09 -060049 env_set("modeboot", "sdboot");
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053050 break;
51 case ZYNQ_BM_JTAG:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053052 mode = "pxe dhcp";
Simon Glass382bee52017-08-03 12:22:09 -060053 env_set("modeboot", "jtagboot");
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053054 break;
55 default:
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053056 mode = "";
Simon Glass382bee52017-08-03 12:22:09 -060057 env_set("modeboot", "");
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053058 break;
59 }
60
Siva Durga Prasad Paladugu3c7b4c32019-01-25 17:06:06 +053061 /*
62 * One terminating char + one byte for space between mode
63 * and default boot_targets
64 */
65 env_targets = env_get("boot_targets");
66 if (env_targets)
67 env_targets_len = strlen(env_targets);
68
69 new_targets = calloc(1, strlen(mode) + env_targets_len + 2);
70 if (!new_targets)
71 return -ENOMEM;
72
73 sprintf(new_targets, "%s %s", mode,
74 env_targets ? env_targets : "");
75
76 env_set("boot_targets", new_targets);
77
Jagannadha Sutradharudu Tekib3de9242014-01-09 01:48:21 +053078 return 0;
79}
Michal Simekf22651c2012-09-28 09:56:37 +000080
Michal Simek758f29d2016-04-01 15:56:33 +020081#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass76b00ac2017-03-31 08:40:32 -060082int dram_init_banksize(void)
Tom Rini361a8792016-12-09 07:56:54 -050083{
Michal Simekda3f0032017-11-03 15:25:51 +010084 return fdtdec_setup_memory_banksize();
Michal Simek758f29d2016-04-01 15:56:33 +020085}
86
Michal Simek8a5db0a2016-12-06 16:31:53 +010087int dram_init(void)
88{
Siva Durga Prasad Paladugu12308b12018-07-16 15:56:11 +053089 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rosside9bf1b2016-12-19 00:03:34 +100090 return -EINVAL;
Michal Simek8a5db0a2016-12-06 16:31:53 +010091
92 zynq_ddrc_init();
93
94 return 0;
95}
Michal Simek758f29d2016-04-01 15:56:33 +020096#else
97int dram_init(void)
98{
Michal Simek61dc92a2018-04-11 16:12:28 +020099 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
100 CONFIG_SYS_SDRAM_SIZE);
Michal Simek758f29d2016-04-01 15:56:33 +0200101
102 zynq_ddrc_init();
103
104 return 0;
105}
106#endif