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