xref: /rk3399_rockchip-uboot/board/xilinx/microblaze-generic/microblaze-generic.c (revision d538ee1b54b78295dbc3bd0d8c5d5fafa5c9e343)
1 /*
2  * (C) Copyright 2007 Michal Simek
3  *
4  * Michal  SIMEK <monstr@monstr.eu>
5  *
6  * SPDX-License-Identifier:	GPL-2.0+
7  */
8 
9 /* This is a board specific file.  It's OK to include board specific
10  * header files */
11 
12 #include <common.h>
13 #include <config.h>
14 #include <fdtdec.h>
15 #include <asm/processor.h>
16 #include <asm/microblaze_intc.h>
17 #include <asm/asm.h>
18 #include <asm/gpio.h>
19 
20 DECLARE_GLOBAL_DATA_PTR;
21 
22 #ifdef CONFIG_XILINX_GPIO
23 static int reset_pin = -1;
24 #endif
25 
26 #if CONFIG_IS_ENABLED(OF_CONTROL)
27 ulong ram_base;
28 
29 void dram_init_banksize(void)
30 {
31 	gd->bd->bi_dram[0].start = ram_base;
32 	gd->bd->bi_dram[0].size = get_effective_memsize();
33 }
34 
35 int dram_init(void)
36 {
37 	int node;
38 	fdt_addr_t addr;
39 	fdt_size_t size;
40 	const void *blob = gd->fdt_blob;
41 
42 	node = fdt_node_offset_by_prop_value(blob, -1, "device_type",
43 					     "memory", 7);
44 	if (node == -FDT_ERR_NOTFOUND) {
45 		debug("DRAM: Can't get memory node\n");
46 		return 1;
47 	}
48 	addr = fdtdec_get_addr_size(blob, node, "reg", &size);
49 	if (addr == FDT_ADDR_T_NONE || size == 0) {
50 		debug("DRAM: Can't get base address or size\n");
51 		return 1;
52 	}
53 	ram_base = addr;
54 
55 	gd->ram_top = addr; /* In setup_dest_addr() is done +ram_size */
56 	gd->ram_size = size;
57 
58 	return 0;
59 };
60 #else
61 int dram_init(void)
62 {
63 	gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
64 
65 	return 0;
66 }
67 #endif
68 
69 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
70 {
71 #ifndef CONFIG_SPL_BUILD
72 #ifdef CONFIG_XILINX_GPIO
73 	if (reset_pin != -1)
74 		gpio_direction_output(reset_pin, 1);
75 #endif
76 
77 #ifdef CONFIG_XILINX_TB_WATCHDOG
78 	hw_watchdog_disable();
79 #endif
80 #endif
81 	puts ("Reseting board\n");
82 	__asm__ __volatile__ ("	mts rmsr, r0;" \
83 				"bra r0");
84 
85 	return 0;
86 }
87 
88 int gpio_init (void)
89 {
90 #ifdef CONFIG_XILINX_GPIO
91 	reset_pin = gpio_alloc(CONFIG_SYS_GPIO_0_ADDR, "reset", 1);
92 	if (reset_pin != -1)
93 		gpio_request(reset_pin, "reset_pin");
94 #endif
95 	return 0;
96 }
97 
98 void board_init(void)
99 {
100 	gpio_init();
101 }
102