Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2007 Michal Simek |
| 4 | * |
| 5 | * Michal SIMEK <monstr@monstr.eu> |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 8 | /* |
| 9 | * This is a board specific file. It's OK to include board specific |
| 10 | * header files |
| 11 | */ |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 12 | |
| 13 | #include <common.h> |
Michal Simek | dda9bd8 | 2007-03-30 22:52:09 +0200 | [diff] [blame] | 14 | #include <config.h> |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 15 | #include <fdtdec.h> |
Michal Simek | 9cabb36 | 2012-07-04 13:12:37 +0200 | [diff] [blame] | 16 | #include <asm/processor.h> |
Michal Simek | 9c817f8 | 2007-05-07 19:33:51 +0200 | [diff] [blame] | 17 | #include <asm/microblaze_intc.h> |
| 18 | #include <asm/asm.h> |
Michal Simek | 23ccda0 | 2013-04-24 10:01:20 +0200 | [diff] [blame] | 19 | #include <asm/gpio.h> |
Shreenidhi Shedi | 1f8fcbb | 2018-07-15 02:05:40 +0530 | [diff] [blame] | 20 | #include <dm/uclass.h> |
| 21 | #include <wdt.h> |
Michal Simek | 23ccda0 | 2013-04-24 10:01:20 +0200 | [diff] [blame] | 22 | |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Michal Simek | 23ccda0 | 2013-04-24 10:01:20 +0200 | [diff] [blame] | 25 | #ifdef CONFIG_XILINX_GPIO |
| 26 | static int reset_pin = -1; |
| 27 | #endif |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 28 | |
Shreenidhi Shedi | 1f8fcbb | 2018-07-15 02:05:40 +0530 | [diff] [blame] | 29 | #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT) |
| 30 | static struct udevice *watchdog_dev; |
| 31 | #endif /* !CONFIG_SPL_BUILD && CONFIG_WDT */ |
| 32 | |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 33 | ulong ram_base; |
| 34 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 35 | int dram_init_banksize(void) |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 36 | { |
| 37 | gd->bd->bi_dram[0].start = ram_base; |
| 38 | gd->bd->bi_dram[0].size = get_effective_memsize(); |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 39 | |
| 40 | return 0; |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | int dram_init(void) |
| 44 | { |
| 45 | int node; |
| 46 | fdt_addr_t addr; |
| 47 | fdt_size_t size; |
| 48 | const void *blob = gd->fdt_blob; |
| 49 | |
| 50 | node = fdt_node_offset_by_prop_value(blob, -1, "device_type", |
| 51 | "memory", 7); |
| 52 | if (node == -FDT_ERR_NOTFOUND) { |
| 53 | debug("DRAM: Can't get memory node\n"); |
| 54 | return 1; |
| 55 | } |
| 56 | addr = fdtdec_get_addr_size(blob, node, "reg", &size); |
| 57 | if (addr == FDT_ADDR_T_NONE || size == 0) { |
| 58 | debug("DRAM: Can't get base address or size\n"); |
| 59 | return 1; |
| 60 | } |
| 61 | ram_base = addr; |
| 62 | |
| 63 | gd->ram_top = addr; /* In setup_dest_addr() is done +ram_size */ |
| 64 | gd->ram_size = size; |
| 65 | |
| 66 | return 0; |
| 67 | }; |
Michal Simek | 65e915c | 2014-05-08 16:08:44 +0200 | [diff] [blame] | 68 | |
Michal Simek | cda7d20 | 2018-06-28 10:30:05 +0200 | [diff] [blame] | 69 | #if !defined(CONFIG_SYSRESET) || defined(CONFIG_SPL_BUILD) |
Mike Frysinger | 6d1f698 | 2010-10-20 03:41:17 -0400 | [diff] [blame] | 70 | int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 71 | { |
Michal Simek | 8cd2491 | 2015-12-09 11:53:25 +0100 | [diff] [blame] | 72 | #ifndef CONFIG_SPL_BUILD |
Michal Simek | 23ccda0 | 2013-04-24 10:01:20 +0200 | [diff] [blame] | 73 | #ifdef CONFIG_XILINX_GPIO |
| 74 | if (reset_pin != -1) |
| 75 | gpio_direction_output(reset_pin, 1); |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 76 | #endif |
Michal Simek | 8cd2491 | 2015-12-09 11:53:25 +0100 | [diff] [blame] | 77 | #endif |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 78 | puts("Resetting board\n"); |
Michal Simek | c944687 | 2012-11-07 15:27:39 +0100 | [diff] [blame] | 79 | __asm__ __volatile__ (" mts rmsr, r0;" \ |
| 80 | "bra r0"); |
Michal Simek | 25d20af | 2012-11-02 09:33:05 +0100 | [diff] [blame] | 81 | |
Mike Frysinger | 6d1f698 | 2010-10-20 03:41:17 -0400 | [diff] [blame] | 82 | return 0; |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 83 | } |
Michal Simek | cda7d20 | 2018-06-28 10:30:05 +0200 | [diff] [blame] | 84 | #endif |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 85 | |
Michal Simek | 0152524 | 2015-12-11 15:01:28 +0100 | [diff] [blame] | 86 | static int gpio_init(void) |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 87 | { |
Michal Simek | 23ccda0 | 2013-04-24 10:01:20 +0200 | [diff] [blame] | 88 | #ifdef CONFIG_XILINX_GPIO |
| 89 | reset_pin = gpio_alloc(CONFIG_SYS_GPIO_0_ADDR, "reset", 1); |
| 90 | if (reset_pin != -1) |
| 91 | gpio_request(reset_pin, "reset_pin"); |
Michal Simek | 952d514 | 2007-03-11 13:42:58 +0100 | [diff] [blame] | 92 | #endif |
| 93 | return 0; |
| 94 | } |
Shreenidhi Shedi | 1f8fcbb | 2018-07-15 02:05:40 +0530 | [diff] [blame] | 95 | |
| 96 | #ifdef CONFIG_WDT |
| 97 | /* Called by macro WATCHDOG_RESET */ |
| 98 | void watchdog_reset(void) |
| 99 | { |
| 100 | #if !defined(CONFIG_SPL_BUILD) |
| 101 | ulong now; |
| 102 | static ulong next_reset; |
| 103 | |
| 104 | if (!watchdog_dev) |
| 105 | return; |
| 106 | |
| 107 | now = timer_get_us(); |
| 108 | |
| 109 | /* Do not reset the watchdog too often */ |
| 110 | if (now > next_reset) { |
| 111 | wdt_reset(watchdog_dev); |
| 112 | next_reset = now + 1000; |
| 113 | } |
| 114 | #endif /* !CONFIG_SPL_BUILD */ |
| 115 | } |
| 116 | #endif /* CONFIG_WDT */ |
Michal Simek | 9c817f8 | 2007-05-07 19:33:51 +0200 | [diff] [blame] | 117 | |
Michal Simek | 0152524 | 2015-12-11 15:01:28 +0100 | [diff] [blame] | 118 | int board_late_init(void) |
Michal Simek | 9cabb36 | 2012-07-04 13:12:37 +0200 | [diff] [blame] | 119 | { |
| 120 | gpio_init(); |
Michal Simek | 0152524 | 2015-12-11 15:01:28 +0100 | [diff] [blame] | 121 | |
Shreenidhi Shedi | 1f8fcbb | 2018-07-15 02:05:40 +0530 | [diff] [blame] | 122 | #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_WDT) |
| 123 | watchdog_dev = NULL; |
| 124 | |
| 125 | if (uclass_get_device_by_seq(UCLASS_WDT, 0, &watchdog_dev)) { |
| 126 | debug("Watchdog: Not found by seq!\n"); |
| 127 | if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) { |
| 128 | puts("Watchdog: Not found!\n"); |
| 129 | return 0; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | wdt_start(watchdog_dev, 0, 0); |
| 134 | puts("Watchdog: Started\n"); |
| 135 | #endif /* !CONFIG_SPL_BUILD && CONFIG_WDT */ |
| 136 | |
Michal Simek | 0152524 | 2015-12-11 15:01:28 +0100 | [diff] [blame] | 137 | return 0; |
Michal Simek | 9cabb36 | 2012-07-04 13:12:37 +0200 | [diff] [blame] | 138 | } |