blob: f74dcbbb624000bf6a75ce1f74c72d908f2571e6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
maxims@google.com899b40f2017-01-18 13:44:57 -08002/*
3 * Copyright (c) 2016 Google, Inc
maxims@google.com899b40f2017-01-18 13:44:57 -08004 */
5#include <common.h>
6#include <dm.h>
Simon Glass97589732020-05-10 11:40:02 -06007#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
maxims@google.com899b40f2017-01-18 13:44:57 -08009#include <ram.h>
10#include <timer.h>
11#include <asm/io.h>
12#include <asm/arch/timer.h>
13#include <asm/arch/wdt.h>
14#include <linux/err.h>
15#include <dm/uclass.h>
16
17/*
18 * Second Watchdog Timer by default is configured
19 * to trigger secondary boot source.
20 */
21#define AST_2ND_BOOT_WDT 1
22
23/*
24 * Third Watchdog Timer by default is configured
25 * to toggle Flash address mode switch before reset.
26 */
27#define AST_FLASH_ADDR_DETECT_WDT 2
28
29DECLARE_GLOBAL_DATA_PTR;
30
31void lowlevel_init(void)
32{
33 /*
34 * These two watchdogs need to be stopped as soon as possible,
35 * otherwise the board might hang. By default they are set to
36 * a very short timeout and even simple debug write to serial
37 * console early in the init process might cause them to fire.
38 */
39 struct ast_wdt *flash_addr_wdt =
40 (struct ast_wdt *)(WDT_BASE +
41 sizeof(struct ast_wdt) *
42 AST_FLASH_ADDR_DETECT_WDT);
43
44 clrbits_le32(&flash_addr_wdt->ctrl, WDT_CTRL_EN);
45
46#ifndef CONFIG_FIRMWARE_2ND_BOOT
47 struct ast_wdt *sec_boot_wdt =
48 (struct ast_wdt *)(WDT_BASE +
49 sizeof(struct ast_wdt) *
50 AST_2ND_BOOT_WDT);
51
52 clrbits_le32(&sec_boot_wdt->ctrl, WDT_CTRL_EN);
53#endif
54}
55
56int board_init(void)
57{
58 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
59
60 return 0;
61}
62
63int dram_init(void)
64{
65 struct udevice *dev;
66 struct ram_info ram;
67 int ret;
68
69 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
70 if (ret) {
71 debug("DRAM FAIL1\r\n");
72 return ret;
73 }
74
75 ret = ram_get_info(dev, &ram);
76 if (ret) {
77 debug("DRAM FAIL2\r\n");
78 return ret;
79 }
80
81 gd->ram_size = ram.size;
82
83 return 0;
84}