889695f80e052d552ffde026bf7a4a96a3c4d920
[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 /* This is a board specific file.  It's OK to include board specific
9  * header files */
10
11 #include <common.h>
12 #include <config.h>
13 #include <fdtdec.h>
14 #include <asm/processor.h>
15 #include <asm/microblaze_intc.h>
16 #include <asm/asm.h>
17 #include <asm/gpio.h>
18
19 DECLARE_GLOBAL_DATA_PTR;
20
21 #ifdef CONFIG_XILINX_GPIO
22 static int reset_pin = -1;
23 #endif
24
25 ulong ram_base;
26
27 int dram_init_banksize(void)
28 {
29         gd->bd->bi_dram[0].start = ram_base;
30         gd->bd->bi_dram[0].size = get_effective_memsize();
31
32         return 0;
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
61 #if !defined(CONFIG_SYSRESET) || defined(CONFIG_SPL_BUILD)
62 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
63 {
64 #ifndef CONFIG_SPL_BUILD
65 #ifdef CONFIG_XILINX_GPIO
66         if (reset_pin != -1)
67                 gpio_direction_output(reset_pin, 1);
68 #endif
69
70 #ifdef CONFIG_XILINX_TB_WATCHDOG
71         hw_watchdog_disable();
72 #endif
73 #endif
74         puts ("Reseting board\n");
75         __asm__ __volatile__ (" mts rmsr, r0;" \
76                                 "bra r0");
77
78         return 0;
79 }
80 #endif
81
82 static int gpio_init(void)
83 {
84 #ifdef CONFIG_XILINX_GPIO
85         reset_pin = gpio_alloc(CONFIG_SYS_GPIO_0_ADDR, "reset", 1);
86         if (reset_pin != -1)
87                 gpio_request(reset_pin, "reset_pin");
88 #endif
89         return 0;
90 }
91
92 int board_late_init(void)
93 {
94         gpio_init();
95
96         return 0;
97 }