Michal Simek | 76316a3 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 Michal Simek |
| 3 | * |
| 4 | * Michal SIMEK <monstr@monstr.eu> |
| 5 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 76316a3 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /* This is a board specific file. It's OK to include board specific |
| 10 | * header files */ |
| 11 | |
| 12 | #include <common.h> |
Michal Simek | 342cd09 | 2007-03-30 22:52:09 +0200 | [diff] [blame] | 13 | #include <config.h> |
Michal Simek | e945f6d | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 14 | #include <fdtdec.h> |
Michal Simek | 2380b8f | 2012-07-04 13:12:37 +0200 | [diff] [blame] | 15 | #include <asm/processor.h> |
Michal Simek | 19bf1fb | 2007-05-07 19:33:51 +0200 | [diff] [blame] | 16 | #include <asm/microblaze_intc.h> |
| 17 | #include <asm/asm.h> |
Michal Simek | 4e779ad | 2013-04-24 10:01:20 +0200 | [diff] [blame] | 18 | #include <asm/gpio.h> |
| 19 | |
Michal Simek | e945f6d | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Michal Simek | 4e779ad | 2013-04-24 10:01:20 +0200 | [diff] [blame] | 22 | #ifdef CONFIG_XILINX_GPIO |
| 23 | static int reset_pin = -1; |
| 24 | #endif |
Michal Simek | 76316a3 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 25 | |
Michal Simek | e945f6d | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 26 | ulong ram_base; |
| 27 | |
| 28 | void 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 | |
| 34 | int 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 Simek | e945f6d | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 59 | |
Mike Frysinger | 882b7d7 | 2010-10-20 03:41:17 -0400 | [diff] [blame] | 60 | int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Michal Simek | 76316a3 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 61 | { |
Michal Simek | b5e9b9a | 2015-12-09 11:53:25 +0100 | [diff] [blame] | 62 | #ifndef CONFIG_SPL_BUILD |
Michal Simek | 4e779ad | 2013-04-24 10:01:20 +0200 | [diff] [blame] | 63 | #ifdef CONFIG_XILINX_GPIO |
| 64 | if (reset_pin != -1) |
| 65 | gpio_direction_output(reset_pin, 1); |
Michal Simek | 76316a3 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 66 | #endif |
Michal Simek | b364727 | 2012-11-02 09:33:05 +0100 | [diff] [blame] | 67 | |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 68 | #ifdef CONFIG_XILINX_TB_WATCHDOG |
| 69 | hw_watchdog_disable(); |
| 70 | #endif |
Michal Simek | b5e9b9a | 2015-12-09 11:53:25 +0100 | [diff] [blame] | 71 | #endif |
Michal Simek | 76316a3 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 72 | puts ("Reseting board\n"); |
Michal Simek | 8848668 | 2012-11-07 15:27:39 +0100 | [diff] [blame] | 73 | __asm__ __volatile__ (" mts rmsr, r0;" \ |
| 74 | "bra r0"); |
Michal Simek | b364727 | 2012-11-02 09:33:05 +0100 | [diff] [blame] | 75 | |
Mike Frysinger | 882b7d7 | 2010-10-20 03:41:17 -0400 | [diff] [blame] | 76 | return 0; |
Michal Simek | 76316a3 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Michal Simek | 38c4761 | 2015-12-11 15:01:28 +0100 | [diff] [blame] | 79 | static int gpio_init(void) |
Michal Simek | 76316a3 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 80 | { |
Michal Simek | 4e779ad | 2013-04-24 10:01:20 +0200 | [diff] [blame] | 81 | #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 Simek | 76316a3 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 85 | #endif |
| 86 | return 0; |
| 87 | } |
Michal Simek | 19bf1fb | 2007-05-07 19:33:51 +0200 | [diff] [blame] | 88 | |
Michal Simek | 38c4761 | 2015-12-11 15:01:28 +0100 | [diff] [blame] | 89 | int board_late_init(void) |
Michal Simek | 2380b8f | 2012-07-04 13:12:37 +0200 | [diff] [blame] | 90 | { |
| 91 | gpio_init(); |
Michal Simek | 38c4761 | 2015-12-11 15:01:28 +0100 | [diff] [blame] | 92 | |
| 93 | return 0; |
Michal Simek | 2380b8f | 2012-07-04 13:12:37 +0200 | [diff] [blame] | 94 | } |