blob: 9be2cceca70544202b9910505a295785ab488d35 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek952d5142007-03-11 13:42:58 +01002/*
3 * (C) Copyright 2007 Michal Simek
4 *
5 * Michal SIMEK <monstr@monstr.eu>
Michal Simek952d5142007-03-11 13:42:58 +01006 */
7
Shreenidhi Shediffced402018-07-15 02:34:35 +05308/*
9 * This is a board specific file. It's OK to include board specific
10 * header files
11 */
Michal Simek952d5142007-03-11 13:42:58 +010012
13#include <common.h>
Michal Simekdda9bd82007-03-30 22:52:09 +020014#include <config.h>
Michal Simek65e915c2014-05-08 16:08:44 +020015#include <fdtdec.h>
Michal Simek9cabb362012-07-04 13:12:37 +020016#include <asm/processor.h>
Michal Simek9c817f82007-05-07 19:33:51 +020017#include <asm/microblaze_intc.h>
18#include <asm/asm.h>
Michal Simek23ccda02013-04-24 10:01:20 +020019#include <asm/gpio.h>
20
Michal Simek65e915c2014-05-08 16:08:44 +020021DECLARE_GLOBAL_DATA_PTR;
22
Michal Simek23ccda02013-04-24 10:01:20 +020023#ifdef CONFIG_XILINX_GPIO
24static int reset_pin = -1;
25#endif
Michal Simek952d5142007-03-11 13:42:58 +010026
Michal Simek65e915c2014-05-08 16:08:44 +020027ulong ram_base;
28
Simon Glass2f949c32017-03-31 08:40:32 -060029int dram_init_banksize(void)
Michal Simek65e915c2014-05-08 16:08:44 +020030{
31 gd->bd->bi_dram[0].start = ram_base;
32 gd->bd->bi_dram[0].size = get_effective_memsize();
Simon Glass2f949c32017-03-31 08:40:32 -060033
34 return 0;
Michal Simek65e915c2014-05-08 16:08:44 +020035}
36
37int 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};
Michal Simek65e915c2014-05-08 16:08:44 +020062
Michal Simekcda7d202018-06-28 10:30:05 +020063#if !defined(CONFIG_SYSRESET) || defined(CONFIG_SPL_BUILD)
Mike Frysinger6d1f6982010-10-20 03:41:17 -040064int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Michal Simek952d5142007-03-11 13:42:58 +010065{
Michal Simek8cd24912015-12-09 11:53:25 +010066#ifndef CONFIG_SPL_BUILD
Michal Simek23ccda02013-04-24 10:01:20 +020067#ifdef CONFIG_XILINX_GPIO
68 if (reset_pin != -1)
69 gpio_direction_output(reset_pin, 1);
Michal Simek952d5142007-03-11 13:42:58 +010070#endif
Michal Simek25d20af2012-11-02 09:33:05 +010071
Michal Simek80e045f2013-04-22 11:23:16 +020072#ifdef CONFIG_XILINX_TB_WATCHDOG
73 hw_watchdog_disable();
74#endif
Michal Simek8cd24912015-12-09 11:53:25 +010075#endif
Shreenidhi Shediffced402018-07-15 02:34:35 +053076 puts("Resetting board\n");
Michal Simekc9446872012-11-07 15:27:39 +010077 __asm__ __volatile__ (" mts rmsr, r0;" \
78 "bra r0");
Michal Simek25d20af2012-11-02 09:33:05 +010079
Mike Frysinger6d1f6982010-10-20 03:41:17 -040080 return 0;
Michal Simek952d5142007-03-11 13:42:58 +010081}
Michal Simekcda7d202018-06-28 10:30:05 +020082#endif
Michal Simek952d5142007-03-11 13:42:58 +010083
Michal Simek01525242015-12-11 15:01:28 +010084static int gpio_init(void)
Michal Simek952d5142007-03-11 13:42:58 +010085{
Michal Simek23ccda02013-04-24 10:01:20 +020086#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");
Michal Simek952d5142007-03-11 13:42:58 +010090#endif
91 return 0;
92}
Michal Simek9c817f82007-05-07 19:33:51 +020093
Michal Simek01525242015-12-11 15:01:28 +010094int board_late_init(void)
Michal Simek9cabb362012-07-04 13:12:37 +020095{
96 gpio_init();
Michal Simek01525242015-12-11 15:01:28 +010097
98 return 0;
Michal Simek9cabb362012-07-04 13:12:37 +020099}