xref: /openbmc/u-boot/arch/sh/lib/board.c (revision 0edd82e2)
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 <console.h>
11 #include <malloc.h>
12 #include <stdio_dev.h>
13 #include <version.h>
14 #include <watchdog.h>
15 #include <net.h>
16 #include <mmc.h>
17 #include <environment.h>
18 
19 #ifdef CONFIG_BITBANGMII
20 #include <miiphy.h>
21 #endif
22 
23 DECLARE_GLOBAL_DATA_PTR;
24 
25 extern int cpu_init(void);
26 extern int board_init(void);
27 extern int dram_init(void);
28 extern int timer_init(void);
29 
30 unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN;
31 
32 #ifndef CONFIG_SYS_NO_FLASH
33 static int sh_flash_init(void)
34 {
35 	gd->bd->bi_flashsize = flash_init();
36 
37 	if (gd->bd->bi_flashsize >= (1024 * 1024))
38 		printf("Flash: %ldMB\n", gd->bd->bi_flashsize / (1024*1024));
39 	else
40 		printf("Flash: %ldKB\n", gd->bd->bi_flashsize / 1024);
41 
42 	return 0;
43 }
44 #endif /* CONFIG_SYS_NO_FLASH */
45 
46 #if defined(CONFIG_CMD_NAND)
47 # include <nand.h>
48 # define INIT_FUNC_NAND_INIT nand_init,
49 #else
50 # define INIT_FUNC_NAND_INIT
51 #endif /* CONFIG_CMD_NAND */
52 
53 #if defined(CONFIG_WATCHDOG)
54 extern int watchdog_init(void);
55 extern int watchdog_disable(void);
56 # undef INIT_FUNC_WATCHDOG_INIT
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 
64 #if defined(CONFIG_CMD_IDE)
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 */
70 
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 
83 static int sh_mem_env_init(void)
84 {
85 	mem_malloc_init(CONFIG_SYS_TEXT_BASE - GENERATED_GBL_DATA_SIZE -
86 			CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN - 16);
87 	env_relocate();
88 	jumptable_init();
89 	return 0;
90 }
91 
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 
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 */
107 	interrupt_init,	/* set up exceptions */
108 	env_init,		/* event init */
109 	serial_init,	/* SCIF init */
110 	INIT_FUNC_WATCHDOG_INIT	/* watchdog init */
111 	console_init_f,
112 	display_options,
113 	checkcpu,
114 	checkboard,		/* Check support board */
115 	dram_init,		/* SDRAM init */
116 	timer_init,		/* SuperH Timer (TCNT0 only) init */
117 	sh_mem_env_init,
118 #ifndef CONFIG_SYS_NO_FLASH
119 	sh_flash_init,	/* Flash memory init*/
120 #endif
121 	INIT_FUNC_NAND_INIT/* Flash memory (NAND) init */
122 	INIT_FUNC_PCI_INIT	/* PCI init */
123 	stdio_init,
124 	console_init_r,
125 	interrupt_init,
126 #ifdef CONFIG_BOARD_LATE_INIT
127 	board_late_init,
128 #endif
129 #if defined(CONFIG_CMD_MMC)
130 	sh_mmc_init,
131 #endif
132 	NULL			/* Terminate this list */
133 };
134 
135 void sh_generic_init(void)
136 {
137 	bd_t *bd;
138 	init_fnc_t **init_fnc_ptr;
139 
140 	memset(gd, 0, GENERATED_GBL_DATA_SIZE);
141 
142 	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */
143 
144 	gd->bd = (bd_t *)(gd + 1);	/* At end of global data */
145 	gd->baudrate = CONFIG_BAUDRATE;
146 
147 	gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
148 
149 	bd = gd->bd;
150 	bd->bi_memstart	= CONFIG_SYS_SDRAM_BASE;
151 	bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
152 #ifndef CONFIG_SYS_NO_FLASH
153 	bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
154 #endif
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;
158 #endif
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();
183 #endif /* CONFIG_CMD_NET */
184 
185 	while (1) {
186 		WATCHDOG_RESET();
187 		main_loop();
188 	}
189 }
190