blob: ea26aad16f841ab7170bf057c266dbb1051a1053 [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>
Michal Simek309ef802018-02-21 17:04:28 +01008#include <dm/uclass.h>
Michal Simek65ef52f2014-02-24 11:16:32 +01009#include <fdtdec.h>
Michal Simek0f796702014-04-25 13:51:17 +020010#include <fpga.h>
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053011#include <malloc.h>
Michal Simek0f796702014-04-25 13:51:17 +020012#include <mmc.h>
Michal Simekc07b2252018-06-08 13:45:14 +020013#include <watchdog.h>
Michal Simek309ef802018-02-21 17:04:28 +010014#include <wdt.h>
Michal Simek15d654c2013-04-22 15:43:02 +020015#include <zynqpl.h>
Michal Simek242192b2013-04-12 16:33:08 +020016#include <asm/arch/hardware.h>
17#include <asm/arch/sys_proto.h>
Michal Simekaf482d52012-09-28 09:56:37 +000018
19DECLARE_GLOBAL_DATA_PTR;
20
Michal Simek309ef802018-02-21 17:04:28 +010021#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT)
Stefan Roesef3170d12019-04-03 09:12:48 +020022static struct udevice *watchdog_dev __attribute__((section(".data"))) = NULL;
Michal Simek309ef802018-02-21 17:04:28 +010023#endif
24
25#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_BOARD_EARLY_INIT_F)
26int board_early_init_f(void)
27{
Michal Simek309ef802018-02-21 17:04:28 +010028 return 0;
29}
30#endif
31
Michal Simekaf482d52012-09-28 09:56:37 +000032int board_init(void)
33{
Michal Simek309ef802018-02-21 17:04:28 +010034#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT)
Michal Simek41e905b2018-07-11 08:35:22 +020035 if (uclass_get_device_by_seq(UCLASS_WDT, 0, &watchdog_dev)) {
36 debug("Watchdog: Not found by seq!\n");
37 if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) {
38 puts("Watchdog: Not found!\n");
39 return 0;
40 }
Michal Simek309ef802018-02-21 17:04:28 +010041 }
Michal Simek41e905b2018-07-11 08:35:22 +020042
43 wdt_start(watchdog_dev, 0, 0);
44 puts("Watchdog: Started\n");
Michal Simek309ef802018-02-21 17:04:28 +010045# endif
46
Michal Simekaf482d52012-09-28 09:56:37 +000047 return 0;
48}
49
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053050int board_late_init(void)
51{
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053052 int env_targets_len = 0;
53 const char *mode;
54 char *new_targets;
55 char *env_targets;
56
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053057 switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
Michal Simek19356712016-12-16 13:16:14 +010058 case ZYNQ_BM_QSPI:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053059 mode = "qspi";
Simon Glass6a38e412017-08-03 12:22:09 -060060 env_set("modeboot", "qspiboot");
Michal Simek19356712016-12-16 13:16:14 +010061 break;
62 case ZYNQ_BM_NAND:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053063 mode = "nand";
Simon Glass6a38e412017-08-03 12:22:09 -060064 env_set("modeboot", "nandboot");
Michal Simek19356712016-12-16 13:16:14 +010065 break;
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053066 case ZYNQ_BM_NOR:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053067 mode = "nor";
Simon Glass6a38e412017-08-03 12:22:09 -060068 env_set("modeboot", "norboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053069 break;
70 case ZYNQ_BM_SD:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053071 mode = "mmc";
Simon Glass6a38e412017-08-03 12:22:09 -060072 env_set("modeboot", "sdboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053073 break;
74 case ZYNQ_BM_JTAG:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053075 mode = "pxe dhcp";
Simon Glass6a38e412017-08-03 12:22:09 -060076 env_set("modeboot", "jtagboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053077 break;
78 default:
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053079 mode = "";
Simon Glass6a38e412017-08-03 12:22:09 -060080 env_set("modeboot", "");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053081 break;
82 }
83
Siva Durga Prasad Paladugubd75bc12019-01-25 17:06:06 +053084 /*
85 * One terminating char + one byte for space between mode
86 * and default boot_targets
87 */
88 env_targets = env_get("boot_targets");
89 if (env_targets)
90 env_targets_len = strlen(env_targets);
91
92 new_targets = calloc(1, strlen(mode) + env_targets_len + 2);
93 if (!new_targets)
94 return -ENOMEM;
95
96 sprintf(new_targets, "%s %s", mode,
97 env_targets ? env_targets : "");
98
99 env_set("boot_targets", new_targets);
100
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +0530101 return 0;
102}
Michal Simekaf482d52012-09-28 09:56:37 +0000103
Michal Simekf4780a72016-04-01 15:56:33 +0200104#if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE)
Simon Glass2f949c32017-03-31 08:40:32 -0600105int dram_init_banksize(void)
Nathan Rossic12892b2016-12-04 19:33:22 +1000106{
Michal Simekd5b7de62017-11-03 15:25:51 +0100107 return fdtdec_setup_memory_banksize();
Tom Riniedcfdbd2016-12-09 07:56:54 -0500108}
Michal Simekf4780a72016-04-01 15:56:33 +0200109
Tom Riniedcfdbd2016-12-09 07:56:54 -0500110int dram_init(void)
111{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530112 if (fdtdec_setup_mem_size_base() != 0)
Nathan Rossi58ea0d82016-12-19 00:03:34 +1000113 return -EINVAL;
Tom Riniedcfdbd2016-12-09 07:56:54 -0500114
115 zynq_ddrc_init();
116
117 return 0;
Michal Simekf4780a72016-04-01 15:56:33 +0200118}
Michal Simekf4780a72016-04-01 15:56:33 +0200119#else
120int dram_init(void)
121{
Michal Simek1b846212018-04-11 16:12:28 +0200122 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
123 CONFIG_SYS_SDRAM_SIZE);
Michal Simekf4780a72016-04-01 15:56:33 +0200124
Michal Simekf5ff7bc2013-06-17 14:37:01 +0200125 zynq_ddrc_init();
126
Michal Simekaf482d52012-09-28 09:56:37 +0000127 return 0;
128}
Michal Simekf4780a72016-04-01 15:56:33 +0200129#endif
Michal Simek309ef802018-02-21 17:04:28 +0100130
131#if defined(CONFIG_WATCHDOG)
132/* Called by macro WATCHDOG_RESET */
133void watchdog_reset(void)
134{
135# if !defined(CONFIG_SPL_BUILD)
136 static ulong next_reset;
137 ulong now;
138
139 if (!watchdog_dev)
140 return;
141
142 now = timer_get_us();
143
144 /* Do not reset the watchdog too often */
145 if (now > next_reset) {
146 wdt_reset(watchdog_dev);
147 next_reset = now + 1000;
148 }
149# endif
150}
151#endif