]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - lib_blackfin/board.c
Fix linker scripts: add NOLOAD atribute to .bss/.sbss sections
[karo-tx-uboot.git] / lib_blackfin / board.c
index 55d13fad8cc99cea6664f6b07b32a0c0c5d536e5..86a3b67c9899b2cba04c3979435f13e2d30cd5b9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * U-boot - board.c First C file to be called contains init routines
  *
- * Copyright (c) 2005 blackfin.uclinux.org
+ * Copyright (c) 2005-2007 Analog Devices Inc.
  *
  * (C) Copyright 2000-2004
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
@@ -21,8 +21,8 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ * MA 02110-1301 USA
  */
 
 #include <common.h>
 #include <version.h>
 #include <net.h>
 #include <environment.h>
+#include <i2c.h>
 #include "blackfin_board.h"
-#include "../drivers/smc91111.h"
+#include <asm/cplb.h>
+#include "../drivers/net/smc91111.h"
 
+#if defined(CONFIG_BF537)&&defined(CONFIG_POST)
+#include <post.h>
+int post_flag;
+#endif
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#ifndef CFG_NO_FLASH
 extern flash_info_t flash_info[];
+#endif
+
+static inline u_long get_vco(void)
+{
+       u_long msel;
+       u_long vco;
+
+       msel = (*pPLL_CTL >> 9) & 0x3F;
+       if (0 == msel)
+               msel = 64;
+
+       vco = CONFIG_CLKIN_HZ;
+       vco >>= (1 & *pPLL_CTL);        /* DF bit */
+       vco = msel * vco;
+       return vco;
+}
+
+/*Get the Core clock*/
+u_long get_cclk(void)
+{
+       u_long csel, ssel;
+       if (*pPLL_STAT & 0x1)
+               return CONFIG_CLKIN_HZ;
+
+       ssel = *pPLL_DIV;
+       csel = ((ssel >> 4) & 0x03);
+       ssel &= 0xf;
+       if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */
+               return get_vco() / ssel;
+       return get_vco() >> csel;
+}
+
+/* Get the System clock */
+u_long get_sclk(void)
+{
+       u_long ssel;
+
+       if (*pPLL_STAT & 0x1)
+               return CONFIG_CLKIN_HZ;
 
+       ssel = (*pPLL_DIV & 0xf);
+
+       return get_vco() / ssel;
+}
 
 static void mem_malloc_init(void)
 {
        mem_malloc_start = CFG_MALLOC_BASE;
        mem_malloc_end = (CFG_MALLOC_BASE + CFG_MALLOC_LEN);
        mem_malloc_brk = mem_malloc_start;
-       memset((void *) mem_malloc_start, 0,
-       mem_malloc_end - mem_malloc_start);
+       memset((void *)mem_malloc_start, 0, mem_malloc_end - mem_malloc_start);
 }
 
 void *sbrk(ptrdiff_t increment)
@@ -57,7 +109,7 @@ void *sbrk(ptrdiff_t increment)
        }
        mem_malloc_brk = new;
 
-       return ((void *) old);
+       return ((void *)old);
 }
 
 static int display_banner(void)
@@ -76,20 +128,17 @@ static void display_flash_config(ulong size)
 
 static int init_baudrate(void)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
-       uchar tmp[64];
+       char tmp[64];
        int i = getenv_r("baudrate", tmp, sizeof(tmp));
        gd->bd->bi_baudrate = gd->baudrate = (i > 0)
-               ? (int) simple_strtoul(tmp, NULL, 10)
-               : CONFIG_BAUDRATE;
+           ? (int)simple_strtoul(tmp, NULL, 10)
+           : CONFIG_BAUDRATE;
        return (0);
 }
 
 #ifdef DEBUG
 static void display_global_data(void)
 {
-       DECLARE_GLOBAL_DATA_PTR;
        bd_t *bd;
        bd = gd->bd;
        printf("--flags:%x\n", gd->flags);
@@ -104,12 +153,10 @@ static void display_global_data(void)
        printf("---bi_baudrate:%x\n", bd->bi_baudrate);
        printf("---bi_ip_addr:%x\n", bd->bi_ip_addr);
        printf("---bi_enetaddr:%x %x %x %x %x %x\n",
-                               bd->bi_enetaddr[0],
-                               bd->bi_enetaddr[1],
-                               bd->bi_enetaddr[2],
-                               bd->bi_enetaddr[3],
-                               bd->bi_enetaddr[4],
-                               bd->bi_enetaddr[5]);
+              bd->bi_enetaddr[0],
+              bd->bi_enetaddr[1],
+              bd->bi_enetaddr[2],
+              bd->bi_enetaddr[3], bd->bi_enetaddr[4], bd->bi_enetaddr[5]);
        printf("---bi_arch_number:%x\n", bd->bi_arch_number);
        printf("---bi_boot_params:%x\n", bd->bi_boot_params);
        printf("---bi_memstart:%x\n", bd->bi_memstart);
@@ -121,6 +168,78 @@ static void display_global_data(void)
 }
 #endif
 
+/* we cover everything with 4 meg pages, and need an extra for L1 */
+unsigned int icplb_table[page_descriptor_table_size][2];
+unsigned int dcplb_table[page_descriptor_table_size][2];
+
+void init_cplbtables(void)
+{
+       int i, j;
+
+       j = 0;
+       icplb_table[j][0] = 0xFFA00000;
+       icplb_table[j][1] = L1_IMEMORY;
+       j++;
+
+       for (i = 0; i < CONFIG_MEM_SIZE / 4; i++) {
+               icplb_table[j][0] = (i * 4 * 1024 * 1024);
+               if (i * 4 * 1024 * 1024 <= CFG_MONITOR_BASE
+                   && (i + 1) * 4 * 1024 * 1024 >= CFG_MONITOR_BASE) {
+                       icplb_table[j][1] = SDRAM_IKERNEL;
+               } else {
+                       icplb_table[j][1] = SDRAM_IGENERIC;
+               }
+               j++;
+       }
+#if defined(CONFIG_BF561)
+       /* MAC space */
+       icplb_table[j][0] = 0x2C000000;
+       icplb_table[j][1] = SDRAM_INON_CHBL;
+       j++;
+       /* Async Memory space */
+       for (i = 0; i < 3; i++) {
+               icplb_table[j][0] = 0x20000000 + i * 4 * 1024 * 1024;
+               icplb_table[j][1] = SDRAM_INON_CHBL;
+               j++;
+       }
+#else
+       icplb_table[j][0] = 0x20000000;
+       icplb_table[j][1] = SDRAM_INON_CHBL;
+#endif
+       j = 0;
+       dcplb_table[j][0] = 0xFF800000;
+       dcplb_table[j][1] = L1_DMEMORY;
+       j++;
+
+       for (i = 0; i < CONFIG_MEM_SIZE / 4; i++) {
+               dcplb_table[j][0] = (i * 4 * 1024 * 1024);
+               if (i * 4 * 1024 * 1024 <= CFG_MONITOR_BASE
+                   && (i + 1) * 4 * 1024 * 1024 >= CFG_MONITOR_BASE) {
+                       dcplb_table[j][1] = SDRAM_DKERNEL;
+               } else {
+                       dcplb_table[j][1] = SDRAM_DGENERIC;
+               }
+               j++;
+       }
+
+#if defined(CONFIG_BF561)
+       /* MAC space */
+       dcplb_table[j][0] = 0x2C000000;
+       dcplb_table[j][1] = SDRAM_EBIU;
+       j++;
+
+       /* Flash space */
+       for (i = 0; i < 3; i++) {
+               dcplb_table[j][0] = 0x20000000 + i * 4 * 1024 * 1024;
+               dcplb_table[j][1] = SDRAM_EBIU;
+               j++;
+       }
+#else
+       dcplb_table[j][0] = 0x20000000;
+       dcplb_table[j][1] = SDRAM_EBIU;
+#endif
+}
+
 /*
  * All attempts to come up with a "common" initialization sequence
  * that works for all boards and architectures failed: some of the
@@ -136,21 +255,23 @@ static void display_global_data(void)
 
 void board_init_f(ulong bootflag)
 {
-       DECLARE_GLOBAL_DATA_PTR;
        ulong addr;
        bd_t *bd;
+       int i;
+
+       init_cplbtables();
 
        gd = (gd_t *) (CFG_GBL_DATA_ADDR);
-       memset((void *) gd, 0, sizeof(gd_t));
+       memset((void *)gd, 0, sizeof(gd_t));
 
        /* Board data initialization */
        addr = (CFG_GBL_DATA_ADDR + sizeof(gd_t));
 
        /* Align to 4 byte boundary */
        addr &= ~(4 - 1);
-       bd = (bd_t*)addr;
+       bd = (bd_t *) addr;
        gd->bd = bd;
-       memset((void *) bd, 0, sizeof(bd_t));
+       memset((void *)bd, 0, sizeof(bd_t));
 
        /* Initialize */
        init_IRQ();
@@ -158,22 +279,50 @@ void board_init_f(ulong bootflag)
        init_baudrate();        /* initialze baudrate settings */
        serial_init();          /* serial communications setup */
        console_init_f();
+#ifdef CONFIG_ICACHE_ON
+       icache_enable();
+#endif
+#ifdef CONFIG_DCACHE_ON
+       dcache_enable();
+#endif
        display_banner();       /* say that we are here */
+
+       for (i = 0; i < page_descriptor_table_size; i++) {
+               debug
+                   ("data (%02i)= 0x%08x : 0x%08x    intr = 0x%08x : 0x%08x\n",
+                    i, dcplb_table[i][0], dcplb_table[i][1], icplb_table[i][0],
+                    icplb_table[i][1]);
+       }
+
        checkboard();
-#if defined(CONFIG_RTC_BF533) && (CONFIG_COMMANDS & CFG_CMD_DATE)
+#if defined(CONFIG_RTC_BF533) && defined(CONFIG_CMD_DATE)
        rtc_init();
 #endif
        timer_init();
-       printf("Clock: VCO: %lu MHz, Core: %lu MHz, System: %lu MHz\n", \
-       CONFIG_VCO_HZ/1000000, CONFIG_CCLK_HZ/1000000, CONFIG_SCLK_HZ/1000000);
+       printf("Clock: VCO: %lu MHz, Core: %lu MHz, System: %lu MHz\n",
+              get_vco() / 1000000, get_cclk() / 1000000, get_sclk() / 1000000);
        printf("SDRAM: ");
        print_size(initdram(0), "\n");
+#if defined(CONFIG_BF537)&&defined(CONFIG_POST)
+       post_init_f();
+       post_bootmode_init();
+       post_run(NULL, POST_ROM | post_bootmode_get(0));
+#endif
        board_init_r((gd_t *) gd, 0x20000010);
 }
 
+#if defined(CONFIG_SOFT_I2C) || defined(CONFIG_HARD_I2C)
+static int init_func_i2c(void)
+{
+       puts("I2C:   ");
+       i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE);
+       puts("ready\n");
+       return (0);
+}
+#endif
+
 void board_init_r(gd_t * id, ulong dest_addr)
 {
-       DECLARE_GLOBAL_DATA_PTR;
        ulong size;
        extern void malloc_bin_reloc(void);
        char *s, *e;
@@ -183,12 +332,18 @@ void board_init_r(gd_t * id, ulong dest_addr)
        gd->flags |= GD_FLG_RELOC;      /* tell others: relocation done */
        bd = gd->bd;
 
-#if    CONFIG_STAMP
+#if    defined(CONFIG_BF537) && defined(CONFIG_POST)
+       post_output_backlog();
+       post_reloc();
+#endif
+
+#if    (CONFIG_STAMP || CONFIG_BF537 || CONFIG_EZKIT561) && !defined(CFG_NO_FLASH)
        /* There are some other pointer constants we must deal with */
        /* configure available FLASH banks */
        size = flash_init();
        display_flash_config(size);
-       flash_protect(FLAG_PROTECT_SET, CFG_FLASH_BASE, CFG_FLASH_BASE + 0x1ffff, &flash_info[0]);
+       flash_protect(FLAG_PROTECT_SET, CFG_FLASH_BASE,
+                     CFG_FLASH_BASE + 0x1ffff, &flash_info[0]);
        bd->bi_flashstart = CFG_FLASH_BASE;
        bd->bi_flashsize = size;
        bd->bi_flashoffset = 0;
@@ -201,6 +356,13 @@ void board_init_r(gd_t * id, ulong dest_addr)
        mem_malloc_init();
        malloc_bin_reloc();
 
+#ifdef CONFIG_SPI
+# if ! defined(CFG_ENV_IS_IN_EEPROM)
+       spi_init_f();
+# endif
+       spi_init_r();
+#endif
+
        /* relocate environment function pointers etc. */
        env_relocate();
 
@@ -226,23 +388,35 @@ void board_init_r(gd_t * id, ulong dest_addr)
        if ((s = getenv("loadaddr")) != NULL) {
                load_addr = simple_strtoul(s, NULL, 16);
        }
-#if (CONFIG_COMMANDS & CFG_CMD_NET)
+#if defined(CONFIG_CMD_NET)
        if ((s = getenv("bootfile")) != NULL) {
                copy_filename(BootFile, s, sizeof(BootFile));
        }
 #endif
+
+#if defined(CONFIG_CMD_NAND)
+       puts("NAND:  ");
+       nand_init();            /* go init the NAND */
+#endif
+
 #if defined(CONFIG_MISC_INIT_R)
        /* miscellaneous platform dependent initialisations */
        misc_init_r();
 #endif
 
+#if ((BFIN_CPU == ADSP_BF537) || (BFIN_CPU == ADSP_BF536))
+       printf("Net:    ");
+       eth_initialize(bd);
+#endif
+
 #ifdef CONFIG_DRIVER_SMC91111
 #ifdef SHARED_RESOURCES
        /* Switch to Ethernet */
        swap_to(ETHERNET);
 #endif
-       if  ( (SMC_inw(BANK_SELECT) & UPPER_BYTE_MASK) != SMC_IDENT ) {
-               printf("ERROR: Can't find SMC91111 at address %x\n", SMC_BASE_ADDRESS);
+       if ((SMC_inw(BANK_SELECT) & UPPER_BYTE_MASK) != SMC_IDENT) {
+               printf("ERROR: Can't find SMC91111 at address %x\n",
+                      SMC_BASE_ADDRESS);
        } else {
                printf("Net:   SMC91111 at 0x%08X\n", SMC_BASE_ADDRESS);
        }
@@ -251,12 +425,17 @@ void board_init_r(gd_t * id, ulong dest_addr)
        swap_to(FLASH);
 #endif
 #endif
-#ifdef CONFIG_SOFT_I2C
+#if defined(CONFIG_SOFT_I2C) || defined(CONFIG_HARD_I2C)
        init_func_i2c();
 #endif
 
 #ifdef DEBUG
-       display_global_data(void);
+       display_global_data();
+#endif
+
+#if defined(CONFIG_BF537) && defined(CONFIG_POST)
+       if (post_flag)
+               post_run(NULL, POST_RAM | post_bootmode_get(0));
 #endif
 
        /* main_loop() can return to retry autoboot, if so just run it again. */
@@ -265,18 +444,8 @@ void board_init_r(gd_t * id, ulong dest_addr)
        }
 }
 
-#ifdef CONFIG_SOFT_I2C
-static int init_func_i2c (void)
-{
-       puts ("I2C:   ");
-       i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
-       puts ("ready\n");
-       return (0);
-}
-#endif
-
 void hang(void)
 {
        puts("### ERROR ### Please RESET the board ###\n");
-       for (;;);
+       for (;;) ;
 }