xref: /openbmc/u-boot/arch/sh/lib/board.c (revision 344c8376)
1 /*
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 
22 DECLARE_GLOBAL_DATA_PTR;
23 
24 extern int cpu_init(void);
25 extern int board_init(void);
26 extern int dram_init(void);
27 extern int timer_init(void);
28 
29 unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
30 
31 #ifndef CONFIG_SYS_NO_FLASH
32 static 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)
53 extern int watchdog_init(void);
54 extern 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>
72 static 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 
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 
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 
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 */
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 
134 void 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 
159 	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
160 		WATCHDOG_RESET();
161 		if ((*init_fnc_ptr) () != 0)
162 			hang();
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();
172 	}
173 #endif /* CONFIG_WATCHDOG*/
174 
175 
176 #ifdef CONFIG_BITBANGMII
177 	bb_miiphy_init();
178 #endif
179 #if defined(CONFIG_CMD_NET)
180 	puts("Net:   ");
181 	eth_initialize();
182 #endif /* CONFIG_CMD_NET */
183 
184 	while (1) {
185 		WATCHDOG_RESET();
186 		main_loop();
187 	}
188 }
189