2 * U-boot - board.c First C file to be called contains init routines
4 * Copyright (c) 2005-2007 Analog Devices Inc.
6 * (C) Copyright 2000-2004
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 * See file CREDITS for list of people who contributed to this
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.
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.
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., 51 Franklin St, Fifth Floor, Boston,
34 #include <environment.h>
36 #include "blackfin_board.h"
38 #include "../drivers/net/smc91111.h"
40 #if defined(CONFIG_POST)
45 DECLARE_GLOBAL_DATA_PTR;
48 extern flash_info_t flash_info[];
51 static inline u_long get_vco(void)
56 msel = (*pPLL_CTL >> 9) & 0x3F;
60 vco = CONFIG_CLKIN_HZ;
61 vco >>= (1 & *pPLL_CTL); /* DF bit */
66 /*Get the Core clock*/
71 return CONFIG_CLKIN_HZ;
74 csel = ((ssel >> 4) & 0x03);
76 if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
77 return get_vco() / ssel;
78 return get_vco() >> csel;
81 /* Get the System clock */
87 return CONFIG_CLKIN_HZ;
89 ssel = (*pPLL_DIV & 0xf);
91 return get_vco() / ssel;
94 static void mem_malloc_init(void)
96 mem_malloc_start = CFG_MALLOC_BASE;
97 mem_malloc_end = (CFG_MALLOC_BASE + CFG_MALLOC_LEN);
98 mem_malloc_brk = mem_malloc_start;
99 memset((void *)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
102 void *sbrk(ptrdiff_t increment)
104 ulong old = mem_malloc_brk;
105 ulong new = old + increment;
107 if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
110 mem_malloc_brk = new;
112 return ((void *)old);
115 static int display_banner(void)
117 sprintf(version_string, VERSION_STRING_FORMAT, VERSION_STRING);
118 printf("%s\n", version_string);
119 printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " (Detected Rev: 0.%d)\n", bfin_revid());
123 static void display_flash_config(ulong size)
126 print_size(size, "\n");
130 static int init_baudrate(void)
133 int i = getenv_r("baudrate", tmp, sizeof(tmp));
134 gd->bd->bi_baudrate = gd->baudrate = (i > 0)
135 ? (int)simple_strtoul(tmp, NULL, 10)
141 static void display_global_data(void)
145 printf("--flags:%x\n", gd->flags);
146 printf("--board_type:%x\n", gd->board_type);
147 printf("--baudrate:%x\n", gd->baudrate);
148 printf("--have_console:%x\n", gd->have_console);
149 printf("--ram_size:%x\n", gd->ram_size);
150 printf("--reloc_off:%x\n", gd->reloc_off);
151 printf("--env_addr:%x\n", gd->env_addr);
152 printf("--env_valid:%x\n", gd->env_valid);
153 printf("--bd:%x %x\n", gd->bd, bd);
154 printf("---bi_baudrate:%x\n", bd->bi_baudrate);
155 printf("---bi_ip_addr:%x\n", bd->bi_ip_addr);
156 printf("---bi_enetaddr:%x %x %x %x %x %x\n",
160 bd->bi_enetaddr[3], bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
161 printf("---bi_arch_number:%x\n", bd->bi_arch_number);
162 printf("---bi_boot_params:%x\n", bd->bi_boot_params);
163 printf("---bi_memstart:%x\n", bd->bi_memstart);
164 printf("---bi_memsize:%x\n", bd->bi_memsize);
165 printf("---bi_flashstart:%x\n", bd->bi_flashstart);
166 printf("---bi_flashsize:%x\n", bd->bi_flashsize);
167 printf("---bi_flashoffset:%x\n", bd->bi_flashoffset);
168 printf("--jt:%x *:%x\n", gd->jt, *(gd->jt));
172 /* we cover everything with 4 meg pages, and need an extra for L1 */
173 unsigned int icplb_table[page_descriptor_table_size][2];
174 unsigned int dcplb_table[page_descriptor_table_size][2];
176 void init_cplbtables(void)
181 icplb_table[j][0] = 0xFFA00000;
182 icplb_table[j][1] = L1_IMEMORY;
185 for (i = 0; i < CONFIG_MEM_SIZE / 4; i++) {
186 icplb_table[j][0] = (i * 4 * 1024 * 1024);
187 if (i * 4 * 1024 * 1024 <= CFG_MONITOR_BASE
188 && (i + 1) * 4 * 1024 * 1024 >= CFG_MONITOR_BASE) {
189 icplb_table[j][1] = SDRAM_IKERNEL;
191 icplb_table[j][1] = SDRAM_IGENERIC;
195 icplb_table[j][0] = 0x20000000;
196 icplb_table[j][1] = SDRAM_INON_CHBL;
198 dcplb_table[j][0] = 0xFF800000;
199 dcplb_table[j][1] = L1_DMEMORY;
202 for (i = 0; i < CONFIG_MEM_SIZE / 4; i++) {
203 dcplb_table[j][0] = (i * 4 * 1024 * 1024);
204 if (i * 4 * 1024 * 1024 <= CFG_MONITOR_BASE
205 && (i + 1) * 4 * 1024 * 1024 >= CFG_MONITOR_BASE) {
206 dcplb_table[j][1] = SDRAM_DKERNEL;
208 dcplb_table[j][1] = SDRAM_DGENERIC;
213 dcplb_table[j][0] = 0x20000000;
214 dcplb_table[j][1] = SDRAM_EBIU;
218 * All attempts to come up with a "common" initialization sequence
219 * that works for all boards and architectures failed: some of the
220 * requirements are just _too_ different. To get rid of the resulting
221 * mess of board dependend #ifdef'ed code we now make the whole
222 * initialization sequence configurable to the user.
224 * The requirements for any new initalization function is simple: it
225 * receives a pointer to the "global data" structure as it's only
226 * argument, and returns an integer return code, where 0 means
227 * "continue" and != 0 means "fatal error, hang the system".
230 void board_init_f(ulong bootflag)
238 gd = (gd_t *) (CFG_GBL_DATA_ADDR);
239 memset((void *)gd, 0, sizeof(gd_t));
241 /* Board data initialization */
242 addr = (CFG_GBL_DATA_ADDR + sizeof(gd_t));
244 /* Align to 4 byte boundary */
248 memset((void *)bd, 0, sizeof(bd_t));
252 env_init(); /* initialize environment */
253 init_baudrate(); /* initialze baudrate settings */
254 serial_init(); /* serial communications setup */
256 #ifdef CONFIG_ICACHE_ON
259 #ifdef CONFIG_DCACHE_ON
262 display_banner(); /* say that we are here */
264 for (i = 0; i < page_descriptor_table_size; i++) {
266 ("data (%02i)= 0x%08x : 0x%08x intr = 0x%08x : 0x%08x\n",
267 i, dcplb_table[i][0], dcplb_table[i][1], icplb_table[i][0],
272 #if defined(CONFIG_RTC_BF533) && defined(CONFIG_CMD_DATE)
276 printf("Clock: VCO: %lu MHz, Core: %lu MHz, System: %lu MHz\n",
277 get_vco() / 1000000, get_cclk() / 1000000, get_sclk() / 1000000);
279 print_size(initdram(0), "\n");
280 #if defined(CONFIG_POST)
282 post_bootmode_init();
283 post_run(NULL, POST_ROM | post_bootmode_get(0));
285 board_init_r((gd_t *) gd, 0x20000010);
288 #if defined(CONFIG_SOFT_I2C) || defined(CONFIG_HARD_I2C)
289 static int init_func_i2c(void)
292 i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE);
298 void board_init_r(gd_t * id, ulong dest_addr)
301 extern void malloc_bin_reloc(void);
306 gd->flags |= GD_FLG_RELOC; /* tell others: relocation done */
309 #if defined(CONFIG_POST)
310 post_output_backlog();
314 #if !defined(CFG_NO_FLASH)
315 /* There are some other pointer constants we must deal with */
316 /* configure available FLASH banks */
318 display_flash_config(size);
319 flash_protect(FLAG_PROTECT_SET, CFG_FLASH_BASE,
320 CFG_FLASH_BASE + 0x1ffff, &flash_info[0]);
321 bd->bi_flashstart = CFG_FLASH_BASE;
322 bd->bi_flashsize = size;
323 bd->bi_flashoffset = 0;
325 bd->bi_flashstart = 0;
326 bd->bi_flashsize = 0;
327 bd->bi_flashoffset = 0;
329 /* initialize malloc() area */
334 # if ! defined(CFG_ENV_IS_IN_EEPROM)
340 /* relocate environment function pointers etc. */
343 /* board MAC address */
344 s = getenv("ethaddr");
345 for (i = 0; i < 6; ++i) {
346 bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
348 s = (*e) ? e + 1 : e;
352 bd->bi_ip_addr = getenv_IPaddr("ipaddr");
354 /* Initialize devices */
358 /* Initialize the console (after the relocation and devices init) */
361 /* Initialize from environment */
362 if ((s = getenv("loadaddr")) != NULL) {
363 load_addr = simple_strtoul(s, NULL, 16);
365 #if defined(CONFIG_CMD_NET)
366 if ((s = getenv("bootfile")) != NULL) {
367 copy_filename(BootFile, s, sizeof(BootFile));
371 #if defined(CONFIG_CMD_NAND)
373 nand_init(); /* go init the NAND */
376 #if defined(CONFIG_MISC_INIT_R)
377 /* miscellaneous platform dependent initialisations */
381 #ifdef CONFIG_CMD_NET
386 #ifdef CONFIG_DRIVER_SMC91111
387 #ifdef SHARED_RESOURCES
388 /* Switch to Ethernet */
391 if ((SMC_inw(BANK_SELECT) & UPPER_BYTE_MASK) != SMC_IDENT) {
392 printf("ERROR: Can't find SMC91111 at address %x\n",
395 printf("Net: SMC91111 at 0x%08X\n", SMC_BASE_ADDRESS);
398 #ifdef SHARED_RESOURCES
402 #if defined(CONFIG_SOFT_I2C) || defined(CONFIG_HARD_I2C)
407 display_global_data();
410 #if defined(CONFIG_POST)
412 post_run(NULL, POST_RAM | post_bootmode_get(0));
415 /* main_loop() can return to retry autoboot, if so just run it again. */
423 puts("### ERROR ### Please RESET the board ###\n");