Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 1 | /* |
Nobuhiro Iwamatsu | c4176c4 | 2010-10-26 20:23:53 +0900 | [diff] [blame] | 2 | * Copyright (C) 2007, 2008, 2010 |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 3 | * Nobuhiro Iwamatsu <iwamatsu@nigauri.org> |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Nobuhiro Iwamatsu | 0b135cf | 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 | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 11 | #include <stdio_dev.h> |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 12 | #include <version.h> |
Nobuhiro Iwamatsu | 4a065ab | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 13 | #include <watchdog.h> |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 14 | #include <net.h> |
Nobuhiro Iwamatsu | e1bc28f | 2012-03-21 14:48:34 +0900 | [diff] [blame] | 15 | #include <mmc.h> |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 16 | #include <environment.h> |
| 17 | |
Luigi 'Comio' Mantellini | 310cecb | 2009-10-10 12:42:21 +0200 | [diff] [blame] | 18 | #ifdef CONFIG_BITBANGMII |
| 19 | #include <miiphy.h> |
| 20 | #endif |
| 21 | |
John Rigby | 2956532 | 2010-12-20 18:27:51 -0700 | [diff] [blame] | 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Nobuhiro Iwamatsu | 0b135cf | 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 | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 27 | extern int timer_init(void); |
| 28 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 29 | unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN; |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 30 | |
Nobuhiro Iwamatsu | 40c4770 | 2011-03-07 11:21:40 +0900 | [diff] [blame] | 31 | #ifndef CONFIG_SYS_NO_FLASH |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 32 | static int sh_flash_init(void) |
| 33 | { |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 34 | gd->bd->bi_flashsize = flash_init(); |
Nobuhiro Iwamatsu | c4176c4 | 2010-10-26 20:23:53 +0900 | [diff] [blame] | 35 | |
| 36 | if (gd->bd->bi_flashsize >= (1024 * 1024)) |
Peter Tyser | eddf52b | 2010-12-28 18:12:05 -0600 | [diff] [blame] | 37 | printf("Flash: %ldMB\n", gd->bd->bi_flashsize / (1024*1024)); |
Nobuhiro Iwamatsu | c4176c4 | 2010-10-26 20:23:53 +0900 | [diff] [blame] | 38 | else |
Peter Tyser | eddf52b | 2010-12-28 18:12:05 -0600 | [diff] [blame] | 39 | printf("Flash: %ldKB\n", gd->bd->bi_flashsize / 1024); |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 40 | |
| 41 | return 0; |
| 42 | } |
Nobuhiro Iwamatsu | 40c4770 | 2011-03-07 11:21:40 +0900 | [diff] [blame] | 43 | #endif /* CONFIG_SYS_NO_FLASH */ |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 44 | |
| 45 | #if defined(CONFIG_CMD_NAND) |
Nobuhiro Iwamatsu | 4a065ab | 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 | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 50 | #endif /* CONFIG_CMD_NAND */ |
| 51 | |
Nobuhiro Iwamatsu | 4a065ab | 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 | a6741bc | 2013-03-05 14:39:42 +0000 | [diff] [blame] | 55 | # undef INIT_FUNC_WATCHDOG_INIT |
Nobuhiro Iwamatsu | 4a065ab | 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 | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 63 | #if defined(CONFIG_CMD_IDE) |
Nobuhiro Iwamatsu | 4a065ab | 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 | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 69 | |
Yusuke Goda | 1a2334a | 2008-03-05 14:30:02 +0900 | [diff] [blame] | 70 | #if defined(CONFIG_PCI) |
Nobuhiro Iwamatsu | 4a065ab | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 71 | #include <pci.h> |
Yusuke Goda | 1a2334a | 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 | 4a065ab | 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 | 1a2334a | 2008-03-05 14:30:02 +0900 | [diff] [blame] | 80 | #endif /* CONFIG_PCI */ |
| 81 | |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 82 | static int sh_mem_env_init(void) |
| 83 | { |
Wolfgang Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 84 | mem_malloc_init(CONFIG_SYS_TEXT_BASE - GENERATED_GBL_DATA_SIZE - |
Peter Tyser | a483a16 | 2009-08-21 23:05:20 -0500 | [diff] [blame] | 85 | CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN - 16); |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 86 | env_relocate(); |
| 87 | jumptable_init(); |
| 88 | return 0; |
| 89 | } |
| 90 | |
Yoshihiro Shimoda | fe0ddff | 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 | 0b135cf | 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 | 4a065ab | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 106 | interrupt_init, /* set up exceptions */ |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 107 | env_init, /* event init */ |
Nobuhiro Iwamatsu | 4a065ab | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 108 | serial_init, /* SCIF init */ |
| 109 | INIT_FUNC_WATCHDOG_INIT /* watchdog init */ |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 110 | console_init_f, |
| 111 | display_options, |
| 112 | checkcpu, |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 113 | checkboard, /* Check support board */ |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 114 | dram_init, /* SDRAM init */ |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 115 | timer_init, /* SuperH Timer (TCNT0 only) init */ |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 116 | sh_mem_env_init, |
Nobuhiro Iwamatsu | 40c4770 | 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 | 4a065ab | 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 | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 122 | stdio_init, |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 123 | console_init_r, |
| 124 | interrupt_init, |
Helmut Raiger | 9660e44 | 2011-10-20 04:19:47 +0000 | [diff] [blame] | 125 | #ifdef CONFIG_BOARD_LATE_INIT |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 126 | board_late_init, |
| 127 | #endif |
Yoshihiro Shimoda | fe0ddff | 2011-07-05 17:18:38 +0900 | [diff] [blame] | 128 | #if defined(CONFIG_CMD_MMC) |
| 129 | sh_mmc_init, |
| 130 | #endif |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 131 | NULL /* Terminate this list */ |
| 132 | }; |
| 133 | |
Nobuhiro Iwamatsu | 4a065ab | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 134 | void sh_generic_init(void) |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 135 | { |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 136 | bd_t *bd; |
| 137 | init_fnc_t **init_fnc_ptr; |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 138 | |
Wolfgang Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 139 | memset(gd, 0, GENERATED_GBL_DATA_SIZE); |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 140 | |
| 141 | gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */ |
| 142 | |
Nobuhiro Iwamatsu | 4a065ab | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 143 | gd->bd = (bd_t *)(gd + 1); /* At end of global data */ |
Nobuhiro Iwamatsu | 0b135cf | 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 | 6d0f6bc | 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 | 40c4770 | 2011-03-07 11:21:40 +0900 | [diff] [blame] | 151 | #ifndef CONFIG_SYS_NO_FLASH |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 152 | bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; |
Nobuhiro Iwamatsu | 40c4770 | 2011-03-07 11:21:40 +0900 | [diff] [blame] | 153 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 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 | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 157 | #endif |
| 158 | bd->bi_baudrate = CONFIG_BAUDRATE; |
| 159 | |
Nobuhiro Iwamatsu | 4a065ab | 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 | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 163 | hang(); |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 164 | } |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 165 | |
Nobuhiro Iwamatsu | 4a065ab | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 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(); |
| 173 | } |
| 174 | #endif /* CONFIG_WATCHDOG*/ |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 175 | |
Nobuhiro Iwamatsu | 4a065ab | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 176 | |
Luigi 'Comio' Mantellini | 310cecb | 2009-10-10 12:42:21 +0200 | [diff] [blame] | 177 | #ifdef CONFIG_BITBANGMII |
| 178 | bb_miiphy_init(); |
| 179 | #endif |
Nobuhiro Iwamatsu | 4a065ab | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 180 | #if defined(CONFIG_CMD_NET) |
Mike Frysinger | de30122 | 2012-04-04 18:53:41 +0000 | [diff] [blame] | 181 | puts("Net: "); |
| 182 | eth_initialize(gd->bd); |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 183 | #endif /* CONFIG_CMD_NET */ |
| 184 | |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 185 | while (1) { |
Nobuhiro Iwamatsu | 4a065ab | 2008-09-18 19:04:26 +0900 | [diff] [blame] | 186 | WATCHDOG_RESET(); |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 187 | main_loop(); |
| 188 | } |
| 189 | } |