blob: 8498153d4ea3ec26ad4d8e77744cd9453be5e7f2 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/*
2 * Copyright (C) 2007, 2008, 2010
3 * Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <command.h>
10#include <malloc.h>
11#include <stdio_dev.h>
12#include <version.h>
13#include <watchdog.h>
14#include <net.h>
15#include <mmc.h>
16#include <environment.h>
17
18#ifdef CONFIG_BITBANGMII
19#include <miiphy.h>
20#endif
21
22DECLARE_GLOBAL_DATA_PTR;
23
24extern int cpu_init(void);
25extern int board_init(void);
26extern int dram_init(void);
27extern int timer_init(void);
28
29unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
30
31#ifndef CONFIG_SYS_NO_FLASH
32static int sh_flash_init(void)
33{
34 gd->bd->bi_flashsize = flash_init();
35
36 if (gd->bd->bi_flashsize >= (1024 * 1024))
37 printf("Flash: %ldMB\n", gd->bd->bi_flashsize / (1024*1024));
38 else
39 printf("Flash: %ldKB\n", gd->bd->bi_flashsize / 1024);
40
41 return 0;
42}
43#endif /* CONFIG_SYS_NO_FLASH */
44
45#if defined(CONFIG_CMD_NAND)
46# include <nand.h>
47# define INIT_FUNC_NAND_INIT nand_init,
48#else
49# define INIT_FUNC_NAND_INIT
50#endif /* CONFIG_CMD_NAND */
51
52#if defined(CONFIG_WATCHDOG)
53extern int watchdog_init(void);
54extern int watchdog_disable(void);
55# undef INIT_FUNC_WATCHDOG_INIT
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
63#if defined(CONFIG_CMD_IDE)
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 */
69
70#if defined(CONFIG_PCI)
71#include <pci.h>
72static int sh_pci_init(void)
73{
74 pci_init();
75 return 0;
76}
77# define INIT_FUNC_PCI_INIT sh_pci_init,
78#else
79# define INIT_FUNC_PCI_INIT
80#endif /* CONFIG_PCI */
81
82static 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
91#if defined(CONFIG_CMD_MMC)
92static int sh_mmc_init(void)
93{
94 puts("MMC: ");
95 mmc_initialize(gd->bd);
96 return 0;
97}
98#endif
99
100typedef int (init_fnc_t) (void);
101
102init_fnc_t *init_sequence[] =
103{
104 cpu_init, /* basic cpu dependent setup */
105 board_init, /* basic board dependent setup */
106 interrupt_init, /* set up exceptions */
107 env_init, /* event init */
108 serial_init, /* SCIF init */
109 INIT_FUNC_WATCHDOG_INIT /* watchdog init */
110 console_init_f,
111 display_options,
112 checkcpu,
113 checkboard, /* Check support board */
114 dram_init, /* SDRAM init */
115 timer_init, /* SuperH Timer (TCNT0 only) init */
116 sh_mem_env_init,
117#ifndef CONFIG_SYS_NO_FLASH
118 sh_flash_init, /* Flash memory init*/
119#endif
120 INIT_FUNC_NAND_INIT/* Flash memory (NAND) init */
121 INIT_FUNC_PCI_INIT /* PCI init */
122 stdio_init,
123 console_init_r,
124 interrupt_init,
125#ifdef CONFIG_BOARD_LATE_INIT
126 board_late_init,
127#endif
128#if defined(CONFIG_CMD_MMC)
129 sh_mmc_init,
130#endif
131 NULL /* Terminate this list */
132};
133
134void sh_generic_init(void)
135{
136 bd_t *bd;
137 init_fnc_t **init_fnc_ptr;
138
139 memset(gd, 0, GENERATED_GBL_DATA_SIZE);
140
141 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
142
143 gd->bd = (bd_t *)(gd + 1); /* At end of global data */
144 gd->baudrate = CONFIG_BAUDRATE;
145
146 gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
147
148 bd = gd->bd;
149 bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
150 bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
151#ifndef CONFIG_SYS_NO_FLASH
152 bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
153#endif
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;
157#endif
158 bd->bi_baudrate = CONFIG_BAUDRATE;
159
160 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
161 WATCHDOG_RESET();
162 if ((*init_fnc_ptr) () != 0)
163 hang();
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();
173 }
174#endif /* CONFIG_WATCHDOG*/
175
176
177#ifdef CONFIG_BITBANGMII
178 bb_miiphy_init();
179#endif
180#if defined(CONFIG_CMD_NET)
181 puts("Net: ");
182 eth_initialize(gd->bd);
183#endif /* CONFIG_CMD_NET */
184
185 while (1) {
186 WATCHDOG_RESET();
187 main_loop();
188 }
189}