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