blob: ccd4ec955b5b74f6d55ec95c50d2828e1b55c589 [file] [log] [blame]
Michal Simek76316a32007-03-11 13:42:58 +01001/*
2 * (C) Copyright 2007 Michal Simek
3 *
4 * Michal SIMEK <monstr@monstr.eu>
5 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02006 * SPDX-License-Identifier: GPL-2.0+
Michal Simek76316a32007-03-11 13:42:58 +01007 */
8
9/* This is a board specific file. It's OK to include board specific
10 * header files */
11
12#include <common.h>
Michal Simek342cd092007-03-30 22:52:09 +020013#include <config.h>
Michal Simeke945f6d2014-05-08 16:08:44 +020014#include <fdtdec.h>
Michal Simek2380b8f2012-07-04 13:12:37 +020015#include <asm/processor.h>
Michal Simek19bf1fb2007-05-07 19:33:51 +020016#include <asm/microblaze_intc.h>
17#include <asm/asm.h>
Michal Simek4e779ad2013-04-24 10:01:20 +020018#include <asm/gpio.h>
19
Michal Simeke945f6d2014-05-08 16:08:44 +020020DECLARE_GLOBAL_DATA_PTR;
21
Michal Simek4e779ad2013-04-24 10:01:20 +020022#ifdef CONFIG_XILINX_GPIO
23static int reset_pin = -1;
24#endif
Michal Simek76316a32007-03-11 13:42:58 +010025
Michal Simeke945f6d2014-05-08 16:08:44 +020026ulong ram_base;
27
28void dram_init_banksize(void)
29{
30 gd->bd->bi_dram[0].start = ram_base;
31 gd->bd->bi_dram[0].size = get_effective_memsize();
32}
33
34int dram_init(void)
35{
36 int node;
37 fdt_addr_t addr;
38 fdt_size_t size;
39 const void *blob = gd->fdt_blob;
40
41 node = fdt_node_offset_by_prop_value(blob, -1, "device_type",
42 "memory", 7);
43 if (node == -FDT_ERR_NOTFOUND) {
44 debug("DRAM: Can't get memory node\n");
45 return 1;
46 }
47 addr = fdtdec_get_addr_size(blob, node, "reg", &size);
48 if (addr == FDT_ADDR_T_NONE || size == 0) {
49 debug("DRAM: Can't get base address or size\n");
50 return 1;
51 }
52 ram_base = addr;
53
54 gd->ram_top = addr; /* In setup_dest_addr() is done +ram_size */
55 gd->ram_size = size;
56
57 return 0;
58};
Michal Simeke945f6d2014-05-08 16:08:44 +020059
Mike Frysinger882b7d72010-10-20 03:41:17 -040060int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Michal Simek76316a32007-03-11 13:42:58 +010061{
Michal Simekb5e9b9a2015-12-09 11:53:25 +010062#ifndef CONFIG_SPL_BUILD
Michal Simek4e779ad2013-04-24 10:01:20 +020063#ifdef CONFIG_XILINX_GPIO
64 if (reset_pin != -1)
65 gpio_direction_output(reset_pin, 1);
Michal Simek76316a32007-03-11 13:42:58 +010066#endif
Michal Simekb3647272012-11-02 09:33:05 +010067
Michal Simek0f21f982013-04-22 11:23:16 +020068#ifdef CONFIG_XILINX_TB_WATCHDOG
69 hw_watchdog_disable();
70#endif
Michal Simekb5e9b9a2015-12-09 11:53:25 +010071#endif
Michal Simek76316a32007-03-11 13:42:58 +010072 puts ("Reseting board\n");
Michal Simek88486682012-11-07 15:27:39 +010073 __asm__ __volatile__ (" mts rmsr, r0;" \
74 "bra r0");
Michal Simekb3647272012-11-02 09:33:05 +010075
Mike Frysinger882b7d72010-10-20 03:41:17 -040076 return 0;
Michal Simek76316a32007-03-11 13:42:58 +010077}
78
Michal Simek38c47612015-12-11 15:01:28 +010079static int gpio_init(void)
Michal Simek76316a32007-03-11 13:42:58 +010080{
Michal Simek4e779ad2013-04-24 10:01:20 +020081#ifdef CONFIG_XILINX_GPIO
82 reset_pin = gpio_alloc(CONFIG_SYS_GPIO_0_ADDR, "reset", 1);
83 if (reset_pin != -1)
84 gpio_request(reset_pin, "reset_pin");
Michal Simek76316a32007-03-11 13:42:58 +010085#endif
86 return 0;
87}
Michal Simek19bf1fb2007-05-07 19:33:51 +020088
Michal Simek38c47612015-12-11 15:01:28 +010089int board_late_init(void)
Michal Simek2380b8f2012-07-04 13:12:37 +020090{
91 gpio_init();
Michal Simek38c47612015-12-11 15:01:28 +010092
93 return 0;
Michal Simek2380b8f2012-07-04 13:12:37 +020094}