board.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright (C) 2007, 2008, 2010
  3. * Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #include <common.h>
  21. #include <command.h>
  22. #include <malloc.h>
  23. #include <stdio_dev.h>
  24. #include <version.h>
  25. #include <watchdog.h>
  26. #include <net.h>
  27. #include <mmc.h>
  28. #include <environment.h>
  29. #ifdef CONFIG_BITBANGMII
  30. #include <miiphy.h>
  31. #endif
  32. DECLARE_GLOBAL_DATA_PTR;
  33. extern int cpu_init(void);
  34. extern int board_init(void);
  35. extern int dram_init(void);
  36. extern int timer_init(void);
  37. unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
  38. #ifndef CONFIG_SYS_NO_FLASH
  39. static int sh_flash_init(void)
  40. {
  41. gd->bd->bi_flashsize = flash_init();
  42. if (gd->bd->bi_flashsize >= (1024 * 1024))
  43. printf("Flash: %ldMB\n", gd->bd->bi_flashsize / (1024*1024));
  44. else
  45. printf("Flash: %ldKB\n", gd->bd->bi_flashsize / 1024);
  46. return 0;
  47. }
  48. #endif /* CONFIG_SYS_NO_FLASH */
  49. #if defined(CONFIG_CMD_NAND)
  50. # include <nand.h>
  51. # define INIT_FUNC_NAND_INIT nand_init,
  52. #else
  53. # define INIT_FUNC_NAND_INIT
  54. #endif /* CONFIG_CMD_NAND */
  55. #if defined(CONFIG_WATCHDOG)
  56. extern int watchdog_init(void);
  57. extern int watchdog_disable(void);
  58. # undef INIT_FUNC_WATCHDOG_INIT
  59. # define INIT_FUNC_WATCHDOG_INIT watchdog_init,
  60. # define WATCHDOG_DISABLE watchdog_disable
  61. #else
  62. # define INIT_FUNC_WATCHDOG_INIT
  63. # define WATCHDOG_DISABLE
  64. #endif /* CONFIG_WATCHDOG */
  65. #if defined(CONFIG_CMD_IDE)
  66. # include <ide.h>
  67. # define INIT_FUNC_IDE_INIT ide_init,
  68. #else
  69. # define INIT_FUNC_IDE_INIT
  70. #endif /* CONFIG_CMD_IDE */
  71. #if defined(CONFIG_PCI)
  72. #include <pci.h>
  73. static int sh_pci_init(void)
  74. {
  75. pci_init();
  76. return 0;
  77. }
  78. # define INIT_FUNC_PCI_INIT sh_pci_init,
  79. #else
  80. # define INIT_FUNC_PCI_INIT
  81. #endif /* CONFIG_PCI */
  82. static int sh_mem_env_init(void)
  83. {
  84. mem_malloc_init(CONFIG_SYS_TEXT_BASE - GENERATED_GBL_DATA_SIZE -
  85. CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN - 16);
  86. env_relocate();
  87. jumptable_init();
  88. return 0;
  89. }
  90. #if defined(CONFIG_CMD_MMC)
  91. static int sh_mmc_init(void)
  92. {
  93. puts("MMC: ");
  94. mmc_initialize(gd->bd);
  95. return 0;
  96. }
  97. #endif
  98. typedef int (init_fnc_t) (void);
  99. init_fnc_t *init_sequence[] =
  100. {
  101. cpu_init, /* basic cpu dependent setup */
  102. board_init, /* basic board dependent setup */
  103. interrupt_init, /* set up exceptions */
  104. env_init, /* event init */
  105. serial_init, /* SCIF init */
  106. INIT_FUNC_WATCHDOG_INIT /* watchdog init */
  107. console_init_f,
  108. display_options,
  109. checkcpu,
  110. checkboard, /* Check support board */
  111. dram_init, /* SDRAM init */
  112. timer_init, /* SuperH Timer (TCNT0 only) init */
  113. sh_mem_env_init,
  114. #ifndef CONFIG_SYS_NO_FLASH
  115. sh_flash_init, /* Flash memory init*/
  116. #endif
  117. INIT_FUNC_NAND_INIT/* Flash memory (NAND) init */
  118. INIT_FUNC_PCI_INIT /* PCI init */
  119. stdio_init,
  120. console_init_r,
  121. interrupt_init,
  122. #ifdef CONFIG_BOARD_LATE_INIT
  123. board_late_init,
  124. #endif
  125. #if defined(CONFIG_CMD_MMC)
  126. sh_mmc_init,
  127. #endif
  128. NULL /* Terminate this list */
  129. };
  130. void sh_generic_init(void)
  131. {
  132. bd_t *bd;
  133. init_fnc_t **init_fnc_ptr;
  134. memset(gd, 0, GENERATED_GBL_DATA_SIZE);
  135. gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
  136. gd->bd = (bd_t *)(gd + 1); /* At end of global data */
  137. gd->baudrate = CONFIG_BAUDRATE;
  138. gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
  139. bd = gd->bd;
  140. bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
  141. bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
  142. #ifndef CONFIG_SYS_NO_FLASH
  143. bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
  144. #endif
  145. #if defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
  146. bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
  147. bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
  148. #endif
  149. bd->bi_baudrate = CONFIG_BAUDRATE;
  150. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  151. WATCHDOG_RESET();
  152. if ((*init_fnc_ptr) () != 0)
  153. hang();
  154. }
  155. #ifdef CONFIG_WATCHDOG
  156. /* disable watchdog if environment is set */
  157. {
  158. char *s = getenv("watchdog");
  159. if (s != NULL)
  160. if (strncmp(s, "off", 3) == 0)
  161. WATCHDOG_DISABLE();
  162. }
  163. #endif /* CONFIG_WATCHDOG*/
  164. #ifdef CONFIG_BITBANGMII
  165. bb_miiphy_init();
  166. #endif
  167. #if defined(CONFIG_CMD_NET)
  168. puts("Net: ");
  169. eth_initialize(gd->bd);
  170. #endif /* CONFIG_CMD_NET */
  171. while (1) {
  172. WATCHDOG_RESET();
  173. main_loop();
  174. }
  175. }