blob: 614d93c082a6867eab005bbf5dde8f1d28c23bc5 [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>
11#include <mmc.h>
Michal Simekc07b2252018-06-08 13:45:14 +020012#include <watchdog.h>
Michal Simek309ef802018-02-21 17:04:28 +010013#include <wdt.h>
Michal Simek15d654c2013-04-22 15:43:02 +020014#include <zynqpl.h>
Michal Simek242192b2013-04-12 16:33:08 +020015#include <asm/arch/hardware.h>
16#include <asm/arch/sys_proto.h>
Michal Simekaf482d52012-09-28 09:56:37 +000017
18DECLARE_GLOBAL_DATA_PTR;
19
Michal Simek309ef802018-02-21 17:04:28 +010020#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT)
21static struct udevice *watchdog_dev;
22#endif
23
24#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_BOARD_EARLY_INIT_F)
25int board_early_init_f(void)
26{
27# if defined(CONFIG_WDT)
28 /* bss is not cleared at time when watchdog_reset() is called */
29 watchdog_dev = NULL;
30# endif
31
32 return 0;
33}
34#endif
35
Michal Simekaf482d52012-09-28 09:56:37 +000036int board_init(void)
37{
Michal Simek309ef802018-02-21 17:04:28 +010038#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT)
Michal Simek41e905b2018-07-11 08:35:22 +020039 if (uclass_get_device_by_seq(UCLASS_WDT, 0, &watchdog_dev)) {
40 debug("Watchdog: Not found by seq!\n");
41 if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) {
42 puts("Watchdog: Not found!\n");
43 return 0;
44 }
Michal Simek309ef802018-02-21 17:04:28 +010045 }
Michal Simek41e905b2018-07-11 08:35:22 +020046
47 wdt_start(watchdog_dev, 0, 0);
48 puts("Watchdog: Started\n");
Michal Simek309ef802018-02-21 17:04:28 +010049# endif
50
Michal Simekaf482d52012-09-28 09:56:37 +000051 return 0;
52}
53
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053054int board_late_init(void)
55{
56 switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) {
Michal Simek19356712016-12-16 13:16:14 +010057 case ZYNQ_BM_QSPI:
Simon Glass6a38e412017-08-03 12:22:09 -060058 env_set("modeboot", "qspiboot");
Michal Simek19356712016-12-16 13:16:14 +010059 break;
60 case ZYNQ_BM_NAND:
Simon Glass6a38e412017-08-03 12:22:09 -060061 env_set("modeboot", "nandboot");
Michal Simek19356712016-12-16 13:16:14 +010062 break;
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053063 case ZYNQ_BM_NOR:
Simon Glass6a38e412017-08-03 12:22:09 -060064 env_set("modeboot", "norboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053065 break;
66 case ZYNQ_BM_SD:
Simon Glass6a38e412017-08-03 12:22:09 -060067 env_set("modeboot", "sdboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053068 break;
69 case ZYNQ_BM_JTAG:
Simon Glass6a38e412017-08-03 12:22:09 -060070 env_set("modeboot", "jtagboot");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053071 break;
72 default:
Simon Glass6a38e412017-08-03 12:22:09 -060073 env_set("modeboot", "");
Jagannadha Sutradharudu Teki11704c22014-01-09 01:48:21 +053074 break;
75 }
76
77 return 0;
78}
Michal Simekaf482d52012-09-28 09:56:37 +000079
Joe Hershberger7f4e5552016-01-26 11:57:03 -060080int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
81{
82#if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
83 defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET)
84 if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
85 CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
86 ethaddr, 6))
87 printf("I2C EEPROM MAC address read failed\n");
88#endif
89
90 return 0;
91}
92
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
Michal Simek309ef802018-02-21 17:04:28 +0100119
120#if defined(CONFIG_WATCHDOG)
121/* Called by macro WATCHDOG_RESET */
122void watchdog_reset(void)
123{
124# if !defined(CONFIG_SPL_BUILD)
125 static ulong next_reset;
126 ulong now;
127
128 if (!watchdog_dev)
129 return;
130
131 now = timer_get_us();
132
133 /* Do not reset the watchdog too often */
134 if (now > next_reset) {
135 wdt_reset(watchdog_dev);
136 next_reset = now + 1000;
137 }
138# endif
139}
140#endif