]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - lib_mips/board.c
AT91: Use AT91_CPU_CLOCK in displays
[karo-tx-uboot.git] / lib_mips / board.c
index 072709553498a37a43fe6702dec02dfb61d4a410..77e1cc8e3c34aa32d3b5d9b56cc5f8eac1e284bf 100644 (file)
 #include <version.h>
 #include <net.h>
 #include <environment.h>
+#include <nand.h>
+#include <spi.h>
 
-#if ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \
-      (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \
-    defined(CFG_ENV_IS_IN_NVRAM)
-#define        TOTAL_MALLOC_LEN        (CFG_MALLOC_LEN + CFG_ENV_SIZE)
+DECLARE_GLOBAL_DATA_PTR;
+
+#if ( ((CONFIG_ENV_ADDR+CONFIG_ENV_SIZE) < CONFIG_SYS_MONITOR_BASE) || \
+      (CONFIG_ENV_ADDR >= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)) ) || \
+    defined(CONFIG_ENV_IS_IN_NVRAM)
+#define        TOTAL_MALLOC_LEN        (CONFIG_SYS_MALLOC_LEN + CONFIG_ENV_SIZE)
 #else
-#define        TOTAL_MALLOC_LEN        CFG_MALLOC_LEN
+#define        TOTAL_MALLOC_LEN        CONFIG_SYS_MALLOC_LEN
 #endif
 
 #undef DEBUG
@@ -60,15 +64,18 @@ static ulong mem_malloc_start;
 static ulong mem_malloc_end;
 static ulong mem_malloc_brk;
 
+/*
+ * mips_io_port_base is the begin of the address space to which x86 style
+ * I/O ports are mapped.
+ */
+unsigned long mips_io_port_base = -1;
 
 /*
  * The Malloc area is immediately below the monitor copy in DRAM
  */
 static void mem_malloc_init (void)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
-       ulong dest_addr = CFG_MONITOR_BASE + gd->reloc_off;
+       ulong dest_addr = CONFIG_SYS_MONITOR_BASE + gd->reloc_off;
 
        mem_malloc_end = dest_addr;
        mem_malloc_start = dest_addr - TOTAL_MALLOC_LEN;
@@ -94,8 +101,6 @@ void *sbrk (ptrdiff_t increment)
 
 static int init_func_ram (void)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
 #ifdef CONFIG_BOARD_TYPES
        int board_type = gd->board_type;
 #else
@@ -118,18 +123,17 @@ static int display_banner(void)
        return (0);
 }
 
+#ifndef CONFIG_SYS_NO_FLASH
 static void display_flash_config(ulong size)
 {
        puts ("Flash: ");
        print_size (size, "\n");
 }
-
+#endif
 
 static int init_baudrate (void)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
-       uchar tmp[64];  /* long enough for environment variables */
+       char tmp[64];   /* long enough for environment variables */
        int i = getenv_r ("baudrate", tmp, sizeof (tmp));
 
        gd->baudrate = (i > 0)
@@ -180,19 +184,21 @@ init_fnc_t *init_sequence[] = {
 
 void board_init_f(ulong bootflag)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        gd_t gd_data, *id;
        bd_t *bd;
        init_fnc_t **init_fnc_ptr;
-       ulong addr, addr_sp, len = (ulong)&uboot_end - CFG_MONITOR_BASE;
+       ulong addr, addr_sp, len = (ulong)&uboot_end - CONFIG_SYS_MONITOR_BASE;
+       ulong *s;
 #ifdef CONFIG_PURPLE
        void copy_code (ulong);
 #endif
 
-               /* Pointer is writable since we allocated a register for it.
-                */
+       /* Pointer is writable since we allocated a register for it.
+        */
        gd = &gd_data;
+       /* compiler optimization barrier needed for GCC >= 3.4 */
+       __asm__ __volatile__("": : :"memory");
+
        memset ((void *)gd, 0, sizeof (gd_t));
 
        for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
@@ -205,35 +211,29 @@ void board_init_f(ulong bootflag)
         * Now that we have DRAM mapped and working, we can
         * relocate the code and continue running from DRAM.
         */
-       addr = CFG_SDRAM_BASE + gd->ram_size;
+       addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
 
-               /* We can reserve some RAM "on top" here.
-                */
+       /* We can reserve some RAM "on top" here.
+        */
 
-               /* round down to next 4 kB limit.
-                */
+       /* round down to next 4 kB limit.
+        */
        addr &= ~(4096 - 1);
-#ifdef DEBUG
-       printf ("Top of RAM usable for U-Boot at: %08lx\n", addr);
-#endif
+       debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
 
-               /* Reserve memory for U-Boot code, data & bss
-                * round down to next 16 kB limit
-                */
+       /* Reserve memory for U-Boot code, data & bss
+        * round down to next 16 kB limit
+        */
        addr -= len;
        addr &= ~(16 * 1024 - 1);
 
-#ifdef DEBUG
-       printf ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
-#endif
+       debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);
 
-               /* Reserve memory for malloc() arena.
-                */
+        /* Reserve memory for malloc() arena.
+        */
        addr_sp = addr - TOTAL_MALLOC_LEN;
-#ifdef DEBUG
-       printf ("Reserving %dk for malloc() at: %08lx\n",
+       debug ("Reserving %dk for malloc() at: %08lx\n",
                        TOTAL_MALLOC_LEN >> 10, addr_sp);
-#endif
 
        /*
         * (permanently) allocate a Board Info struct
@@ -242,25 +242,20 @@ void board_init_f(ulong bootflag)
        addr_sp -= sizeof(bd_t);
        bd = (bd_t *)addr_sp;
        gd->bd = bd;
-#ifdef DEBUG
-       printf ("Reserving %d Bytes for Board Info at: %08lx\n",
+       debug ("Reserving %zu Bytes for Board Info at: %08lx\n",
                        sizeof(bd_t), addr_sp);
-#endif
+
        addr_sp -= sizeof(gd_t);
        id = (gd_t *)addr_sp;
-#ifdef DEBUG
-       printf ("Reserving %d Bytes for Global Data at: %08lx\n",
+       debug ("Reserving %zu Bytes for Global Data at: %08lx\n",
                        sizeof (gd_t), addr_sp);
-#endif
 
-               /* Reserve memory for boot params.
-                */
-       addr_sp -= CFG_BOOTPARAMS_LEN;
+       /* Reserve memory for boot params.
+        */
+       addr_sp -= CONFIG_SYS_BOOTPARAMS_LEN;
        bd->bi_boot_params = addr_sp;
-#ifdef DEBUG
-       printf ("Reserving %dk for malloc() at: %08lx\n",
-                       CFG_BOOTPARAMS_LEN >> 10, addr_sp);
-#endif
+       debug ("Reserving %dk for boot params() at: %08lx\n",
+                       CONFIG_SYS_BOOTPARAMS_LEN >> 10, addr_sp);
 
        /*
         * Finally, we set up a new (bigger) stack.
@@ -270,15 +265,16 @@ void board_init_f(ulong bootflag)
         */
        addr_sp -= 16;
        addr_sp &= ~0xF;
-       *((ulong *) addr_sp)-- = 0;
-       *((ulong *) addr_sp)-- = 0;
-#ifdef DEBUG
-       printf ("Stack Pointer at: %08lx\n", addr_sp);
-#endif
+       s = (ulong *)addr_sp;
+       *s-- = 0;
+       *s-- = 0;
+       addr_sp = (ulong)s;
+       debug ("Stack Pointer at: %08lx\n", addr_sp);
+
        /*
         * Save local variables to board info struct
         */
-       bd->bi_memstart = CFG_SDRAM_BASE;       /* start of  DRAM memory */
+       bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;        /* start of  DRAM memory */
        bd->bi_memsize  = gd->ram_size;         /* size  of  DRAM memory in bytes */
        bd->bi_baudrate = gd->baudrate;         /* Console Baudrate */
 
@@ -307,11 +303,12 @@ void board_init_f(ulong bootflag)
 
 void board_init_r (gd_t *id, ulong dest_addr)
 {
-       DECLARE_GLOBAL_DATA_PTR;
        cmd_tbl_t *cmdtp;
+#ifndef CONFIG_SYS_NO_FLASH
        ulong size;
+#endif
        extern void malloc_bin_reloc (void);
-#ifndef CFG_ENV_IS_NOWHERE
+#ifndef CONFIG_ENV_IS_NOWHERE
        extern char * env_name_spec;
 #endif
        char *s, *e;
@@ -321,18 +318,16 @@ void board_init_r (gd_t *id, ulong dest_addr)
        gd = id;
        gd->flags |= GD_FLG_RELOC;      /* tell others: relocation done */
 
-#ifdef DEBUG
-       printf ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
-#endif
+       debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
 
-       gd->reloc_off = dest_addr - CFG_MONITOR_BASE;
+       gd->reloc_off = dest_addr - CONFIG_SYS_MONITOR_BASE;
 
        monitor_flash_len = (ulong)&uboot_end_data - dest_addr;
 
        /*
         * We have to relocate the command table manually
         */
-       for (cmdtp = &__u_boot_cmd_start; cmdtp !=  &__u_boot_cmd_end; cmdtp++) {
+       for (cmdtp = &__u_boot_cmd_start; cmdtp !=  &__u_boot_cmd_end; cmdtp++) {
                ulong addr;
 
                addr = (ulong) (cmdtp->cmd) + gd->reloc_off;
@@ -350,7 +345,7 @@ void board_init_r (gd_t *id, ulong dest_addr)
                        addr = (ulong)(cmdtp->usage) + gd->reloc_off;
                        cmdtp->usage = (char *)addr;
                }
-#ifdef CFG_LONGHELP
+#ifdef CONFIG_SYS_LONGHELP
                if (cmdtp->help) {
                        addr = (ulong)(cmdtp->help) + gd->reloc_off;
                        cmdtp->help = (char *)addr;
@@ -358,18 +353,21 @@ void board_init_r (gd_t *id, ulong dest_addr)
 #endif
        }
        /* there are some other pointer constants we must deal with */
-#ifndef CFG_ENV_IS_NOWHERE
+#ifndef CONFIG_ENV_IS_NOWHERE
        env_name_spec += gd->reloc_off;
 #endif
 
+       bd = gd->bd;
+
+#ifndef CONFIG_SYS_NO_FLASH
        /* configure available FLASH banks */
        size = flash_init();
        display_flash_config (size);
-
-       bd = gd->bd;
-       bd->bi_flashstart = CFG_FLASH_BASE;
        bd->bi_flashsize = size;
-#if CFG_MONITOR_BASE == CFG_FLASH_BASE
+#endif
+
+       bd->bi_flashstart = CONFIG_SYS_FLASH_BASE;
+#if CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
        bd->bi_flashoffset = monitor_flash_len; /* reserved area for U-Boot */
 #else
        bd->bi_flashoffset = 0;
@@ -393,6 +391,13 @@ void board_init_r (gd_t *id, ulong dest_addr)
        /* IP Address */
        bd->bi_ip_addr = getenv_IPaddr("ipaddr");
 
+#if defined(CONFIG_PCI)
+       /*
+        * Do pci configuration
+        */
+       pci_init();
+#endif
+
 /** leave this here (after malloc(), environment and PCI are working) **/
        /* Initialize devices */
        devices_init ();
@@ -407,19 +412,32 @@ 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 /* CFG_CMD_NET */
+#endif
+
+#ifdef CONFIG_CMD_NAND
+       puts ("NAND:  ");
+       nand_init ();           /* go init the NAND */
+#endif
+
+#ifdef CONFIG_CMD_SPI
+       puts ("SPI:   ");
+       spi_init ();            /* go init the SPI */
+       puts ("ready\n");
+#endif
 
 #if defined(CONFIG_MISC_INIT_R)
        /* miscellaneous platform dependent initialisations */
        misc_init_r ();
 #endif
 
-#if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)
+#if defined(CONFIG_CMD_NET)
+#if defined(CONFIG_NET_MULTI)
        puts ("Net:   ");
+#endif
        eth_initialize(gd->bd);
 #endif