]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/sparc/lib/board.c
arm: mxs: video: Enable MXS LCDIF on M28EVK
[karo-tx-uboot.git] / arch / sparc / lib / board.c
1 /* SPARC Board initialization
2  *
3  * (C) Copyright 2000-2006
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  *
6  * (C) Copyright 2007
7  * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  */
27
28 #include <common.h>
29 #include <command.h>
30 #include <malloc.h>
31 #include <stdio_dev.h>
32 #include <config.h>
33 #if defined(CONFIG_CMD_IDE)
34 #include <ide.h>
35 #endif
36 #ifdef CONFIG_STATUS_LED
37 #include <status_led.h>
38 #endif
39 #include <net.h>
40 #include <serial.h>
41 #include <version.h>
42 #if defined(CONFIG_POST)
43 #include <post.h>
44 #endif
45 #ifdef CONFIG_PS2KBD
46 #include <keyboard.h>
47 #endif
48 #ifdef CONFIG_CMD_AMBAPP
49 #include <ambapp.h>
50 #endif
51
52 #ifdef CONFIG_BITBANGMII
53 #include <miiphy.h>
54 #endif
55
56 DECLARE_GLOBAL_DATA_PTR;
57
58 /* Debug options
59 #define DEBUG_INIT_SEQUENCE
60 #define DEBUG_MEM_LAYOUT
61 #define DEBUG_COMMANDS
62 */
63
64 extern void timer_interrupt_init(void);
65 extern int do_ambapp_print(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]);
66 extern int prom_init(void);
67
68 #if defined(CONFIG__CMD_DOC)
69 void doc_init(void);
70 #endif
71
72 #if !defined(CONFIG_SYS_NO_FLASH)
73 static char *failed = "*** failed ***\n";
74 #endif
75
76 #include <environment.h>
77
78 ulong monitor_flash_len;
79
80 /************************************************************************
81  * Init Utilities                                                       *
82  ************************************************************************
83  * Some of this code should be moved into the core functions,
84  * but let's get it working (again) first...
85  */
86
87 static int init_baudrate(void)
88 {
89         gd->baudrate = getenv_ulong("baudrate", 10, CONFIG_BAUDRATE);
90         return 0;
91 }
92
93 /***********************************************************************/
94
95 /*
96  * All attempts to come up with a "common" initialization sequence
97  * that works for all boards and architectures failed: some of the
98  * requirements are just _too_ different. To get rid of the resulting
99  * mess of board dependend #ifdef'ed code we now make the whole
100  * initialization sequence configurable to the user.
101  *
102  * The requirements for any new initalization function is simple: it
103  * receives a pointer to the "global data" structure as it's only
104  * argument, and returns an integer return code, where 0 means
105  * "continue" and != 0 means "fatal error, hang the system".
106  */
107 typedef int (init_fnc_t) (void);
108
109 #define WATCHDOG_RESET(x)
110
111 /************************************************************************
112  * Initialization sequence                                              *
113  ************************************************************************
114  */
115
116 init_fnc_t *init_sequence[] = {
117
118 #if defined(CONFIG_BOARD_EARLY_INIT_F)
119         board_early_init_f,
120 #endif
121         serial_init,
122
123         init_timebase,
124
125 #if defined(CONFIG_CMD_AMBAPP)
126         ambapp_init_reloc,
127 #endif
128
129         env_init,
130
131         init_baudrate,
132
133         console_init_f,
134         display_options,
135
136         checkcpu,
137         checkboard,
138 #if defined(CONFIG_MISC_INIT_F)
139         misc_init_f,
140 #endif
141
142 #ifdef CONFIG_POST
143         post_init_f,
144 #endif
145
146         NULL,                   /* Terminate this list,
147                                  * beware: this list will be relocated
148                                  * which means that NULL will become
149                                  * NULL+RELOC_OFFSET. We simply make
150                                  * NULL be -RELOC_OFFSET instead.
151                                  */
152 };
153
154 /************************************************************************
155  *
156  * This is the SPARC board initialization routine, running from RAM.
157  *
158  ************************************************************************
159  */
160 #ifdef DEBUG_INIT_SEQUENCE
161 char *str_init_seq = "INIT_SEQ 00\n";
162 char *str_init_seq_done = "\n\rInit sequence done...\r\n\r\n";
163 #endif
164
165 void board_init_f(ulong bootflag)
166 {
167         bd_t *bd;
168         init_fnc_t **init_fnc_ptr;
169         int j;
170
171 #ifndef CONFIG_SYS_NO_FLASH
172         ulong flash_size;
173 #endif
174
175         gd = (gd_t *) (CONFIG_SYS_GBL_DATA_OFFSET);
176
177         /* Clear initial global data */
178         memset((void *)gd, 0, sizeof(gd_t));
179
180         gd->bd = (bd_t *) (gd + 1);     /* At end of global data */
181         gd->baudrate = CONFIG_BAUDRATE;
182         gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
183
184         bd = gd->bd;
185         bd->bi_memstart = CONFIG_SYS_RAM_BASE;
186         bd->bi_memsize = CONFIG_SYS_RAM_SIZE;
187         bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
188 #if     defined(CONFIG_SYS_SRAM_BASE) && defined(CONFIG_SYS_SRAM_SIZE)
189         bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;
190         bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;
191 #endif
192         bd->bi_baudrate = CONFIG_BAUDRATE;
193         bd->bi_bootflags = bootflag;    /* boot / reboot flag (for LynxOS)    */
194
195         gd->flags |= GD_FLG_RELOC;      /* tell others: relocation done */
196         gd->reloc_off = CONFIG_SYS_RELOC_MONITOR_BASE - CONFIG_SYS_MONITOR_BASE;
197
198         for (init_fnc_ptr = init_sequence, j = 0; *init_fnc_ptr;
199              ++init_fnc_ptr, j++) {
200 #ifdef DEBUG_INIT_SEQUENCE
201                 if (j > 9)
202                         str_init_seq[9] = '0' + (j / 10);
203                 str_init_seq[10] = '0' + (j - (j / 10) * 10);
204                 serial_puts(str_init_seq);
205 #endif
206                 if ((*init_fnc_ptr + gd->reloc_off) () != 0) {
207                         hang();
208                 }
209         }
210 #ifdef DEBUG_INIT_SEQUENCE
211         serial_puts(str_init_seq_done);
212 #endif
213
214         /*
215          * Now that we have DRAM mapped and working, we can
216          * relocate the code and continue running from DRAM.
217          *
218          * Reserve memory at end of RAM for (top down in that order):
219          *  - kernel log buffer
220          *  - protected RAM
221          *  - LCD framebuffer
222          *  - monitor code
223          *  - board info struct
224          */
225 #ifdef DEBUG_MEM_LAYOUT
226         printf("CONFIG_SYS_MONITOR_BASE:       0x%lx\n", CONFIG_SYS_MONITOR_BASE);
227         printf("CONFIG_ENV_ADDR:           0x%lx\n", CONFIG_ENV_ADDR);
228         printf("CONFIG_SYS_RELOC_MONITOR_BASE: 0x%lx (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE,
229                CONFIG_SYS_MONITOR_LEN);
230         printf("CONFIG_SYS_MALLOC_BASE:        0x%lx (%d)\n", CONFIG_SYS_MALLOC_BASE,
231                CONFIG_SYS_MALLOC_LEN);
232         printf("CONFIG_SYS_INIT_SP_OFFSET:     0x%lx (%d)\n", CONFIG_SYS_INIT_SP_OFFSET,
233                CONFIG_SYS_STACK_SIZE);
234         printf("CONFIG_SYS_PROM_OFFSET:        0x%lx (%d)\n", CONFIG_SYS_PROM_OFFSET,
235                CONFIG_SYS_PROM_SIZE);
236         printf("CONFIG_SYS_GBL_DATA_OFFSET:    0x%lx (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET,
237                GENERATED_GBL_DATA_SIZE);
238 #endif
239
240 #ifdef CONFIG_POST
241         post_bootmode_init();
242         post_run(NULL, POST_ROM | post_bootmode_get(0));
243 #endif
244
245 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
246         /*
247          * We have to relocate the command table manually
248          */
249         fixup_cmdtable(ll_entry_start(cmd_tbl_t, cmd),
250                         ll_entry_count(cmd_tbl_t, cmd));
251 #endif /* defined(CONFIG_NEEDS_MANUAL_RELOC) */
252
253 #if defined(CONFIG_CMD_AMBAPP) && defined(CONFIG_SYS_AMBAPP_PRINT_ON_STARTUP)
254         puts("AMBA:\n");
255         do_ambapp_print(NULL, 0, 0, NULL);
256 #endif
257
258         /* initialize higher level parts of CPU like time base and timers */
259         cpu_init_r();
260
261         /* start timer */
262         timer_interrupt_init();
263
264         /*
265          * Enable Interrupts before any calls to udelay,
266          * the flash driver may use udelay resulting in
267          * a hang if not timer0 IRQ is enabled.
268          */
269         interrupt_init();
270
271         /* The Malloc area is immediately below the monitor copy in RAM */
272         mem_malloc_init(CONFIG_SYS_MALLOC_BASE,
273                         CONFIG_SYS_MALLOC_END - CONFIG_SYS_MALLOC_BASE);
274
275 #if !defined(CONFIG_SYS_NO_FLASH)
276         puts("Flash: ");
277
278         if ((flash_size = flash_init()) > 0) {
279 # ifdef CONFIG_SYS_FLASH_CHECKSUM
280                 print_size(flash_size, "");
281                 /*
282                  * Compute and print flash CRC if flashchecksum is set to 'y'
283                  *
284                  * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
285                  */
286                 if (getenv_yesno("flashchecksum") == 1) {
287                         printf("  CRC: %08lX",
288                                crc32(0, (const unsigned char *)CONFIG_SYS_FLASH_BASE,
289                                      flash_size)
290                             );
291                 }
292                 putc('\n');
293 # else                          /* !CONFIG_SYS_FLASH_CHECKSUM */
294                 print_size(flash_size, "\n");
295 # endif                         /* CONFIG_SYS_FLASH_CHECKSUM */
296         } else {
297                 puts(failed);
298                 hang();
299         }
300
301         bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;      /* update start of FLASH memory    */
302         bd->bi_flashsize = flash_size;  /* size of FLASH memory (final value) */
303 #if CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
304         bd->bi_flashoffset = monitor_flash_len; /* reserved area for startup monitor  */
305 #else
306         bd->bi_flashoffset = 0;
307 #endif
308 #else                           /* CONFIG_SYS_NO_FLASH */
309         bd->bi_flashsize = 0;
310         bd->bi_flashstart = 0;
311         bd->bi_flashoffset = 0;
312 #endif                          /* !CONFIG_SYS_NO_FLASH */
313
314 #ifdef CONFIG_SPI
315 # if !defined(CONFIG_ENV_IS_IN_EEPROM)
316         spi_init_f();
317 # endif
318         spi_init_r();
319 #endif
320
321         /* relocate environment function pointers etc. */
322         env_relocate();
323
324 #if defined(CONFIG_BOARD_LATE_INIT)
325         board_late_init();
326 #endif
327
328 #ifdef CONFIG_ID_EEPROM
329         mac_read_from_eeprom();
330 #endif
331
332 #if defined(CONFIG_PCI)
333         /*
334          * Do pci configuration
335          */
336         pci_init();
337 #endif
338
339         /* Initialize stdio devices */
340         stdio_init();
341
342         /* Initialize the jump table for applications */
343         jumptable_init();
344
345         /* Initialize the console (after the relocation and devices init) */
346         console_init_r();
347
348 #ifdef CONFIG_STATUS_LED
349         status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
350 #endif
351
352         udelay(20);
353
354         /* Initialize from environment */
355         load_addr = getenv_ulong("loadaddr", 16, load_addr);
356
357         WATCHDOG_RESET();
358
359 #if defined(CONFIG_CMD_DOC)
360         WATCHDOG_RESET();
361         puts("DOC:   ");
362         doc_init();
363 #endif
364
365 #ifdef CONFIG_BITBANGMII
366         bb_miiphy_init();
367 #endif
368 #if defined(CONFIG_CMD_NET)
369         WATCHDOG_RESET();
370         puts("Net:   ");
371         eth_initialize(bd);
372 #endif
373
374 #if defined(CONFIG_CMD_NET) && defined(CONFIG_RESET_PHY_R)
375         WATCHDOG_RESET();
376         debug("Reset Ethernet PHY\n");
377         reset_phy();
378 #endif
379
380 #ifdef CONFIG_POST
381         post_run(NULL, POST_RAM | post_bootmode_get(0));
382 #endif
383
384 #if defined(CONFIG_CMD_IDE)
385         WATCHDOG_RESET();
386         puts("IDE:   ");
387         ide_init();
388 #endif /* CONFIG_CMD_IDE */
389
390 #ifdef CONFIG_LAST_STAGE_INIT
391         WATCHDOG_RESET();
392         /*
393          * Some parts can be only initialized if all others (like
394          * Interrupts) are up and running (i.e. the PC-style ISA
395          * keyboard).
396          */
397         last_stage_init();
398 #endif
399
400 #ifdef CONFIG_PS2KBD
401         puts("PS/2:  ");
402         kbd_init();
403 #endif
404         prom_init();
405
406         /* main_loop */
407         for (;;) {
408                 WATCHDOG_RESET();
409                 main_loop();
410         }
411
412 }
413
414 void hang(void)
415 {
416         puts("### ERROR ### Please RESET the board ###\n");
417 #ifdef CONFIG_SHOW_BOOT_PROGRESS
418         bootstage_error(BOOTSTAGE_ID_NEED_RESET);
419 #endif
420         for (;;) ;
421 }
422
423 /************************************************************************/