Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 1 | /* |
Nobuhiro Iwamatsu | 0db11c2 | 2010-10-26 20:23:53 +0900 | [diff] [blame] | 2 | * Copyright (C) 2007, 2008, 2010 |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 3 | * Nobuhiro Iwamatsu <iwamatsu@nigauri.org> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
| 10 | #include <malloc.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 11 | #include <stdio_dev.h> |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 12 | #include <version.h> |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 13 | #include <watchdog.h> |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 14 | #include <net.h> |
Nobuhiro Iwamatsu | 2ba44e1 | 2012-03-21 14:48:34 +0900 | [diff] [blame] | 15 | #include <mmc.h> |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 16 | #include <environment.h> |
| 17 | |
Luigi 'Comio' Mantellini | 01db155 | 2009-10-10 12:42:21 +0200 | [diff] [blame] | 18 | #ifdef CONFIG_BITBANGMII |
| 19 | #include <miiphy.h> |
| 20 | #endif |
| 21 | |
John Rigby | 0d21ed0 | 2010-12-20 18:27:51 -0700 | [diff] [blame] | 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 24 | extern int cpu_init(void); |
| 25 | extern int board_init(void); |
| 26 | extern int dram_init(void); |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 27 | extern int timer_init(void); |
| 28 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 29 | unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN; |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 30 | |
Nobuhiro Iwamatsu | e657167 | 2011-03-07 11:21:40 +0900 | [diff] [blame] | 31 | #ifndef CONFIG_SYS_NO_FLASH |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 32 | static int sh_flash_init(void) |
| 33 | { |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 34 | gd->bd->bi_flashsize = flash_init(); |
Nobuhiro Iwamatsu | 0db11c2 | 2010-10-26 20:23:53 +0900 | [diff] [blame] | 35 | |
| 36 | if (gd->bd->bi_flashsize >= (1024 * 1024)) |
Peter Tyser | 0b5a263 | 2010-12-28 18:12:05 -0600 | [diff] [blame] | 37 | printf("Flash: %ldMB\n", gd->bd->bi_flashsize / (1024*1024)); |
Nobuhiro Iwamatsu | 0db11c2 | 2010-10-26 20:23:53 +0900 | [diff] [blame] | 38 | else |
Peter Tyser | 0b5a263 | 2010-12-28 18:12:05 -0600 | [diff] [blame] | 39 | printf("Flash: %ldKB\n", gd->bd->bi_flashsize / 1024); |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 40 | |
| 41 | return 0; |
| 42 | } |
Nobuhiro Iwamatsu | e657167 | 2011-03-07 11:21:40 +0900 | [diff] [blame] | 43 | #endif /* CONFIG_SYS_NO_FLASH */ |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 44 | |
| 45 | #if defined(CONFIG_CMD_NAND) |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 46 | # include <nand.h> |
| 47 | # define INIT_FUNC_NAND_INIT nand_init, |
| 48 | #else |
| 49 | # define INIT_FUNC_NAND_INIT |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 50 | #endif /* CONFIG_CMD_NAND */ |
| 51 | |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 52 | #if defined(CONFIG_WATCHDOG) |
| 53 | extern int watchdog_init(void); |
| 54 | extern int watchdog_disable(void); |
Simon Glass | 6f98490 | 2013-03-05 14:39:42 +0000 | [diff] [blame] | 55 | # undef INIT_FUNC_WATCHDOG_INIT |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 56 | # define INIT_FUNC_WATCHDOG_INIT watchdog_init, |
| 57 | # define WATCHDOG_DISABLE watchdog_disable |
| 58 | #else |
| 59 | # define INIT_FUNC_WATCHDOG_INIT |
| 60 | # define WATCHDOG_DISABLE |
| 61 | #endif /* CONFIG_WATCHDOG */ |
| 62 | |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 63 | #if defined(CONFIG_CMD_IDE) |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 64 | # include <ide.h> |
| 65 | # define INIT_FUNC_IDE_INIT ide_init, |
| 66 | #else |
| 67 | # define INIT_FUNC_IDE_INIT |
| 68 | #endif /* CONFIG_CMD_IDE */ |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 69 | |
Yusuke Goda | c77aa17 | 2008-03-05 14:30:02 +0900 | [diff] [blame] | 70 | #if defined(CONFIG_PCI) |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 71 | #include <pci.h> |
Yusuke Goda | c77aa17 | 2008-03-05 14:30:02 +0900 | [diff] [blame] | 72 | static int sh_pci_init(void) |
| 73 | { |
| 74 | pci_init(); |
| 75 | return 0; |
| 76 | } |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 77 | # define INIT_FUNC_PCI_INIT sh_pci_init, |
| 78 | #else |
| 79 | # define INIT_FUNC_PCI_INIT |
Yusuke Goda | c77aa17 | 2008-03-05 14:30:02 +0900 | [diff] [blame] | 80 | #endif /* CONFIG_PCI */ |
| 81 | |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 82 | static int sh_mem_env_init(void) |
| 83 | { |
Wolfgang Denk | 0191e47 | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 84 | mem_malloc_init(CONFIG_SYS_TEXT_BASE - GENERATED_GBL_DATA_SIZE - |
Peter Tyser | ed52770 | 2009-08-21 23:05:20 -0500 | [diff] [blame] | 85 | CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN - 16); |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 86 | env_relocate(); |
| 87 | jumptable_init(); |
| 88 | return 0; |
| 89 | } |
| 90 | |
Yoshihiro Shimoda | 062fbbf | 2011-07-05 17:18:38 +0900 | [diff] [blame] | 91 | #if defined(CONFIG_CMD_MMC) |
| 92 | static int sh_mmc_init(void) |
| 93 | { |
| 94 | puts("MMC: "); |
| 95 | mmc_initialize(gd->bd); |
| 96 | return 0; |
| 97 | } |
| 98 | #endif |
| 99 | |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 100 | typedef int (init_fnc_t) (void); |
| 101 | |
| 102 | init_fnc_t *init_sequence[] = |
| 103 | { |
| 104 | cpu_init, /* basic cpu dependent setup */ |
| 105 | board_init, /* basic board dependent setup */ |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 106 | interrupt_init, /* set up exceptions */ |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 107 | env_init, /* event init */ |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 108 | serial_init, /* SCIF init */ |
| 109 | INIT_FUNC_WATCHDOG_INIT /* watchdog init */ |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 110 | console_init_f, |
| 111 | display_options, |
| 112 | checkcpu, |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 113 | checkboard, /* Check support board */ |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 114 | dram_init, /* SDRAM init */ |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 115 | timer_init, /* SuperH Timer (TCNT0 only) init */ |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 116 | sh_mem_env_init, |
Nobuhiro Iwamatsu | e657167 | 2011-03-07 11:21:40 +0900 | [diff] [blame] | 117 | #ifndef CONFIG_SYS_NO_FLASH |
| 118 | sh_flash_init, /* Flash memory init*/ |
| 119 | #endif |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 120 | INIT_FUNC_NAND_INIT/* Flash memory (NAND) init */ |
| 121 | INIT_FUNC_PCI_INIT /* PCI init */ |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 122 | stdio_init, |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 123 | console_init_r, |
| 124 | interrupt_init, |
Helmut Raiger | d5a184b | 2011-10-20 04:19:47 +0000 | [diff] [blame] | 125 | #ifdef CONFIG_BOARD_LATE_INIT |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 126 | board_late_init, |
| 127 | #endif |
Yoshihiro Shimoda | 062fbbf | 2011-07-05 17:18:38 +0900 | [diff] [blame] | 128 | #if defined(CONFIG_CMD_MMC) |
| 129 | sh_mmc_init, |
| 130 | #endif |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 131 | NULL /* Terminate this list */ |
| 132 | }; |
| 133 | |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 134 | void sh_generic_init(void) |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 135 | { |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 136 | bd_t *bd; |
| 137 | init_fnc_t **init_fnc_ptr; |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 138 | |
Wolfgang Denk | 0191e47 | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 139 | memset(gd, 0, GENERATED_GBL_DATA_SIZE); |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 140 | |
| 141 | gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ |
| 142 | |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 143 | gd->bd = (bd_t *)(gd + 1); /* At end of global data */ |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 144 | gd->baudrate = CONFIG_BAUDRATE; |
| 145 | |
| 146 | gd->cpu_clk = CONFIG_SYS_CLK_FREQ; |
| 147 | |
| 148 | bd = gd->bd; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 149 | bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; |
| 150 | bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE; |
Nobuhiro Iwamatsu | e657167 | 2011-03-07 11:21:40 +0900 | [diff] [blame] | 151 | #ifndef CONFIG_SYS_NO_FLASH |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 152 | bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; |
Nobuhiro Iwamatsu | e657167 | 2011-03-07 11:21:40 +0900 | [diff] [blame] | 153 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 154 | #if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE) |
| 155 | bd->bi_sramstart = CONFIG_SYS_SRAM_BASE; |
| 156 | bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE; |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 157 | #endif |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 158 | |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 159 | for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { |
| 160 | WATCHDOG_RESET(); |
| 161 | if ((*init_fnc_ptr) () != 0) |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 162 | hang(); |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | #ifdef CONFIG_WATCHDOG |
| 166 | /* disable watchdog if environment is set */ |
| 167 | { |
| 168 | char *s = getenv("watchdog"); |
| 169 | if (s != NULL) |
| 170 | if (strncmp(s, "off", 3) == 0) |
| 171 | WATCHDOG_DISABLE(); |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 172 | } |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 173 | #endif /* CONFIG_WATCHDOG*/ |
| 174 | |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 175 | |
Luigi 'Comio' Mantellini | 01db155 | 2009-10-10 12:42:21 +0200 | [diff] [blame] | 176 | #ifdef CONFIG_BITBANGMII |
| 177 | bb_miiphy_init(); |
| 178 | #endif |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 179 | #if defined(CONFIG_CMD_NET) |
Mike Frysinger | 36fe7db | 2012-04-04 18:53:41 +0000 | [diff] [blame] | 180 | puts("Net: "); |
Joe Hershberger | 3dbe17e | 2015-03-22 17:09:06 -0500 | [diff] [blame] | 181 | eth_initialize(); |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 182 | #endif /* CONFIG_CMD_NET */ |
| 183 | |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 184 | while (1) { |
Nobuhiro Iwamatsu | 4c9c109 | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 185 | WATCHDOG_RESET(); |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 186 | main_loop(); |
| 187 | } |
| 188 | } |