]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/blackfin/lib/board.c
2 * U-boot - board.c First C file to be called contains init routines
4 * Copyright (c) 2005-2008 Analog Devices Inc.
6 * (C) Copyright 2000-2004
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 * Licensed under the GPL-2 or later.
14 #include <stdio_dev.h>
16 #include <environment.h>
20 #include <status_led.h>
24 #include <asm/mach-common/bits/mpu.h>
27 #ifdef CONFIG_CMD_NAND
28 #include <nand.h> /* cannot even include nand.h if it isnt configured */
31 #ifdef CONFIG_BITBANGMII
35 #if defined(CONFIG_POST)
40 #if defined(CONFIG_SYS_I2C)
44 DECLARE_GLOBAL_DATA_PTR
;
46 __attribute__((always_inline
))
47 static inline void serial_early_puts(const char *s
)
49 #ifdef CONFIG_DEBUG_EARLY_SERIAL
50 serial_puts("Early: ");
55 static int display_banner(void)
58 printf("CPU: ADSP %s "
59 "(Detected Rev: 0.%d) "
63 get_bfin_boot_mode(CONFIG_BFIN_BOOT_MODE
));
67 static int init_baudrate(void)
69 gd
->baudrate
= getenv_ulong("baudrate", 10, CONFIG_BAUDRATE
);
73 static void display_global_data(void)
77 #ifndef CONFIG_DEBUG_EARLY_SERIAL
82 printf(" gd: %p\n", gd
);
83 printf(" |-flags: %lx\n", gd
->flags
);
84 printf(" |-board_type: %lx\n", gd
->arch
.board_type
);
85 printf(" |-baudrate: %u\n", gd
->baudrate
);
86 printf(" |-have_console: %lx\n", gd
->have_console
);
87 printf(" |-ram_size: %lx\n", gd
->ram_size
);
88 printf(" |-env_addr: %lx\n", gd
->env_addr
);
89 printf(" |-env_valid: %lx\n", gd
->env_valid
);
90 printf(" |-jt(%p): %p\n", gd
->jt
, *(gd
->jt
));
91 printf(" \\-bd: %p\n", gd
->bd
);
92 printf(" |-bi_baudrate: %x\n", bd
->bi_baudrate
);
93 printf(" |-bi_boot_params: %lx\n", bd
->bi_boot_params
);
94 printf(" |-bi_memstart: %lx\n", bd
->bi_memstart
);
95 printf(" |-bi_memsize: %lx\n", bd
->bi_memsize
);
96 printf(" |-bi_flashstart: %lx\n", bd
->bi_flashstart
);
97 printf(" |-bi_flashsize: %lx\n", bd
->bi_flashsize
);
98 printf(" \\-bi_flashoffset: %lx\n", bd
->bi_flashoffset
);
101 #define CPLB_PAGE_SIZE (4 * 1024 * 1024)
102 #define CPLB_PAGE_MASK (~(CPLB_PAGE_SIZE - 1))
103 #if defined(__ADSPBF60x__)
104 #define CPLB_EX_PAGE_SIZE (16 * 1024 * 1024)
105 #define CPLB_EX_PAGE_MASK (~(CPLB_EX_PAGE_SIZE - 1))
107 #define CPLB_EX_PAGE_SIZE CPLB_PAGE_SIZE
108 #define CPLB_EX_PAGE_MASK CPLB_PAGE_MASK
110 void init_cplbtables(void)
112 volatile uint32_t *ICPLB_ADDR
, *ICPLB_DATA
;
113 volatile uint32_t *DCPLB_ADDR
, *DCPLB_DATA
;
114 uint32_t extern_memory
;
117 void icplb_add(uint32_t addr
, uint32_t data
)
119 *(ICPLB_ADDR
+ i
) = addr
;
120 *(ICPLB_DATA
+ i
) = data
;
122 void dcplb_add(uint32_t addr
, uint32_t data
)
124 *(DCPLB_ADDR
+ i
) = addr
;
125 *(DCPLB_DATA
+ i
) = data
;
128 /* populate a few common entries ... we'll let
129 * the memory map and cplb exception handler do
130 * the rest of the work.
133 ICPLB_ADDR
= (uint32_t *)ICPLB_ADDR0
;
134 ICPLB_DATA
= (uint32_t *)ICPLB_DATA0
;
135 DCPLB_ADDR
= (uint32_t *)DCPLB_ADDR0
;
136 DCPLB_DATA
= (uint32_t *)DCPLB_DATA0
;
138 icplb_add(0xFFA00000, L1_IMEMORY
);
139 dcplb_add(0xFF800000, L1_DMEMORY
);
141 #if defined(__ADSPBF60x__)
143 dcplb_add(CONFIG_SYS_FLASH_BASE
, SDRAM_EBIU
);
147 if (CONFIG_MEM_SIZE
) {
148 uint32_t mbase
= CONFIG_SYS_MONITOR_BASE
;
149 uint32_t mend
= mbase
+ CONFIG_SYS_MONITOR_LEN
;
150 mbase
&= CPLB_PAGE_MASK
;
151 mend
&= CPLB_PAGE_MASK
;
153 icplb_add(mbase
, SDRAM_IKERNEL
);
154 dcplb_add(mbase
, SDRAM_DKERNEL
);
158 * If the monitor crosses a 4 meg boundary, we'll need
159 * to lock two entries for it. We assume it doesn't
160 * cross two 4 meg boundaries ...
163 icplb_add(mend
, SDRAM_IKERNEL
);
164 dcplb_add(mend
, SDRAM_DKERNEL
);
169 #ifndef __ADSPBF60x__
170 icplb_add(0x20000000, SDRAM_INON_CHBL
);
171 dcplb_add(0x20000000, SDRAM_EBIU
);
175 /* Add entries for the rest of external RAM up to the bootrom */
178 #ifdef CONFIG_DEBUG_NULL_PTR
179 icplb_add(extern_memory
, (SDRAM_IKERNEL
& ~PAGE_SIZE_MASK
) | PAGE_SIZE_1KB
);
180 dcplb_add(extern_memory
, (SDRAM_DKERNEL
& ~PAGE_SIZE_MASK
) | PAGE_SIZE_1KB
);
182 icplb_add(extern_memory
, SDRAM_IKERNEL
);
183 dcplb_add(extern_memory
, SDRAM_DKERNEL
);
184 extern_memory
+= CPLB_PAGE_SIZE
;
188 while (i
< 16 && extern_memory
<
189 (CONFIG_SYS_MONITOR_BASE
& CPLB_EX_PAGE_MASK
)) {
190 icplb_add(extern_memory
, SDRAM_IGENERIC
);
191 dcplb_add(extern_memory
, SDRAM_DGENERIC
);
192 extern_memory
+= CPLB_EX_PAGE_SIZE
;
202 static int global_board_data_init(void)
204 #ifndef CONFIG_SYS_GBL_DATA_ADDR
205 # define CONFIG_SYS_GBL_DATA_ADDR 0
207 #ifndef CONFIG_SYS_BD_INFO_ADDR
208 # define CONFIG_SYS_BD_INFO_ADDR 0
213 if (CONFIG_SYS_GBL_DATA_ADDR
) {
214 gd
= (gd_t
*) (CONFIG_SYS_GBL_DATA_ADDR
);
215 memset((void *)gd
, 0, GENERATED_GBL_DATA_SIZE
);
217 static gd_t _bfin_gd
;
221 if (CONFIG_SYS_BD_INFO_ADDR
) {
222 bd
= (bd_t
*) (CONFIG_SYS_BD_INFO_ADDR
);
223 memset(bd
, 0, GENERATED_BD_INFO_SIZE
);
225 static bd_t _bfin_bd
;
230 bd
->bi_r_version
= version_string
;
231 bd
->bi_cpu
= __stringify(CONFIG_BFIN_CPU
);
232 bd
->bi_board_name
= BFIN_BOARD_NAME
;
233 bd
->bi_vco
= get_vco();
234 bd
->bi_cclk
= get_cclk();
235 bd
->bi_sclk
= get_sclk();
236 bd
->bi_memstart
= CONFIG_SYS_SDRAM_BASE
;
237 bd
->bi_memsize
= CONFIG_SYS_MAX_RAM_SIZE
;
238 bd
->bi_baudrate
= (gd
->baudrate
> 0)
239 ? simple_strtoul(gd
->baudrate
, NULL
, 10) : CONFIG_BAUDRATE
;
245 * All attempts to come up with a "common" initialization sequence
246 * that works for all boards and architectures failed: some of the
247 * requirements are just _too_ different. To get rid of the resulting
248 * mess of board dependend #ifdef'ed code we now make the whole
249 * initialization sequence configurable to the user.
251 * The requirements for any new initalization function is simple: it
252 * receives a pointer to the "global data" structure as it's only
253 * argument, and returns an integer return code, where 0 means
254 * "continue" and != 0 means "fatal error, hang the system".
257 extern int watchdog_init(void);
258 extern int exception_init(void);
259 extern int irq_init(void);
260 extern int timer_init(void);
262 void board_init_f(ulong bootflag
)
266 #ifdef CONFIG_BOARD_EARLY_INIT_F
267 serial_early_puts("Board early init flash\n");
268 board_early_init_f();
271 serial_early_puts("Init CPLB tables\n");
274 serial_early_puts("Exceptions setup\n");
277 #ifndef CONFIG_ICACHE_OFF
278 serial_early_puts("Turn on ICACHE\n");
281 #ifndef CONFIG_DCACHE_OFF
282 serial_early_puts("Turn on DCACHE\n");
286 #ifdef CONFIG_HW_WATCHDOG
287 serial_early_puts("Setting up external watchdog\n");
292 if (GENERATED_GBL_DATA_SIZE
< sizeof(*gd
))
295 serial_early_puts("Init global data\n");
297 global_board_data_init();
300 serial_early_puts("IRQ init\n");
302 serial_early_puts("Environment init\n");
304 serial_early_puts("Baudrate init\n");
306 serial_early_puts("Serial init\n");
309 serial_early_puts("Console init flash\n");
311 serial_early_puts("End of early debugging\n");
317 printf("Clock: VCO: %s MHz, ", strmhz(buf
, get_vco()));
318 printf("Core: %s MHz, ", strmhz(buf
, get_cclk()));
319 #if defined(__ADSPBF60x__)
320 printf("System0: %s MHz, ", strmhz(buf
, get_sclk0()));
321 printf("System1: %s MHz, ", strmhz(buf
, get_sclk1()));
322 printf("Dclk: %s MHz\n", strmhz(buf
, get_dclk()));
324 printf("System: %s MHz\n", strmhz(buf
, get_sclk()));
327 if (CONFIG_MEM_SIZE
) {
329 print_size(gd
->bd
->bi_memsize
, "\n");
332 #if defined(CONFIG_POST)
334 post_bootmode_init();
335 post_run(NULL
, POST_ROM
| post_bootmode_get(0));
338 board_init_r((gd_t
*) gd
, 0x20000010);
341 static void board_net_init_r(bd_t
*bd
)
343 #ifdef CONFIG_BITBANGMII
346 #ifdef CONFIG_CMD_NET
352 void board_init_r(gd_t
* id
, ulong dest_addr
)
356 gd
->flags
|= GD_FLG_RELOC
; /* tell others: relocation done */
359 #if defined(CONFIG_POST)
360 post_output_backlog();
363 /* initialize malloc() area */
364 mem_malloc_init(CONFIG_SYS_MALLOC_BASE
, CONFIG_SYS_MALLOC_LEN
);
366 #if !defined(CONFIG_SYS_NO_FLASH)
367 /* Initialize the flash and protect u-boot by default */
368 extern flash_info_t flash_info
[];
370 ulong size
= flash_init();
371 print_size(size
, "\n");
372 flash_protect(FLAG_PROTECT_SET
, CONFIG_SYS_FLASH_BASE
,
373 CONFIG_SYS_FLASH_BASE
+ CONFIG_SYS_MONITOR_LEN
- 1,
375 bd
->bi_flashstart
= CONFIG_SYS_FLASH_BASE
;
376 bd
->bi_flashsize
= size
;
377 bd
->bi_flashoffset
= 0;
379 bd
->bi_flashstart
= 0;
380 bd
->bi_flashsize
= 0;
381 bd
->bi_flashoffset
= 0;
384 #ifdef CONFIG_CMD_NAND
386 nand_init(); /* go init the NAND */
389 #ifdef CONFIG_GENERIC_MMC
394 #if defined(CONFIG_SYS_I2C)
397 /* relocate environment function pointers etc. */
400 /* Initialize stdio devices */
404 /* Initialize the console (after the relocation and devices init) */
407 #ifdef CONFIG_CMD_KGDB
412 #ifdef CONFIG_STATUS_LED
413 status_led_set(STATUS_LED_BOOT
, STATUS_LED_BLINKING
);
414 status_led_set(STATUS_LED_CRASH
, STATUS_LED_OFF
);
417 /* Initialize from environment */
418 load_addr
= getenv_ulong("loadaddr", 16, load_addr
);
420 #if defined(CONFIG_MISC_INIT_R)
421 /* miscellaneous platform dependent initialisations */
425 board_net_init_r(bd
);
427 display_global_data();
429 #if defined(CONFIG_POST)
431 post_run(NULL
, POST_RAM
| post_bootmode_get(0));
434 if (CONFIG_MEM_SIZE
&& bfin_os_log_check()) {
435 puts("\nLog buffer from operating system:\n");
440 /* main_loop() can return to retry autoboot, if so just run it again. */