efi_loader: abort on unsupported relocation type
[platform/kernel/u-boot.git] / board / mpl / mip405 / mip405.c
index d8279e8..4d8671f 100644 (file)
@@ -2,24 +2,7 @@
  * (C) Copyright 2001
  * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * 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
- *
+ * SPDX-License-Identifier:    GPL-2.0+
  *
  * TODO: clean-up
  */
@@ -65,7 +48,8 @@
 #include <common.h>
 #include "mip405.h"
 #include <asm/processor.h>
-#include <4xx_i2c.h>
+#include <asm/ppc4xx.h>
+#include <asm/ppc4xx-i2c.h>
 #include <miiphy.h>
 #include "../common/common_util.h"
 #include <stdio_dev.h>
@@ -76,8 +60,6 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #undef SDRAM_DEBUG
 #define ENABLE_ECC /* for ecc boards */
-#define FALSE           0
-#define TRUE            1
 
 /* stdlib.h causes some compatibility problems; should fixe these! -- wd */
 #ifndef __ldiv_t_defined
@@ -110,7 +92,7 @@ typedef struct {
        unsigned char sz;               /* log binary => Size = (4MByte<<sz) 5 = 128, 4 = 64, 3 = 32, 2 = 16, 1=8 */
        unsigned char ecc;              /* if true, ecc is enabled */
 } sdram_t;
-#if defined(CONFIG_MIP405T)
+#if defined(CONFIG_TARGET_MIP405T)
 const sdram_t sdram_table[] = {
        { 0x0F, /* MIP405T Rev A, 64MByte -1 Board */
                3,      /* Case Latenty = 3 */
@@ -186,7 +168,7 @@ const sdram_t sdram_table[] = {
          0xff,
          0xff }
 };
-#endif /*CONFIG_MIP405T */
+#endif /*CONFIG_TARGET_MIP405T */
 void SDRAM_err (const char *s)
 {
 #ifndef SDRAM_DEBUG
@@ -245,8 +227,7 @@ int init_sdram (void)
        unsigned char   trp_clocks,
                        trcd_clocks,
                        tras_clocks,
-                       trc_clocks,
-                       tctp_clocks;
+                       trc_clocks;
        unsigned char   cal_val;
        unsigned char   bc;
        unsigned long   sdram_tim, sdram_bank;
@@ -281,7 +262,7 @@ int init_sdram (void)
 #endif
        /* check board */
        bc = in8 (PLD_PART_REG);
-#if defined(CONFIG_MIP405T)
+#if defined(CONFIG_TARGET_MIP405T)
        if((bc & 0x80)==0)
                SDRAM_err ("U-Boot configured for a MIP405T not for a MIP405!!!\n");
 #else
@@ -344,11 +325,10 @@ int init_sdram (void)
        trcd_clocks = sdram_table[i].trcd;      /* 20ns /7.5 ns (datain[29]) */
        tras_clocks = sdram_table[i].tras;      /* 44ns /7.5 ns  (datain[30]) */
        /* ctp = ((trp + tras) - trp - trcd) => tras - trcd */
-       tctp_clocks = sdram_table[i].tctp;      /* 44 - 20ns = 24ns */
        /* trc_clocks is sum of trp_clocks + tras_clocks */
        trc_clocks = trp_clocks + tras_clocks;
        /* get SDRAM timing register */
-       mtdcr (SDRAM0_CFGADDR, mem_sdtr1);
+       mtdcr (SDRAM0_CFGADDR, SDRAM0_TR);
        sdram_tim = mfdcr (SDRAM0_CFGDATA) & ~0x018FC01F;
        /* insert CASL value */
        sdram_tim |= ((unsigned long) (cal_val)) << 23;
@@ -369,7 +349,7 @@ int init_sdram (void)
        /* insert SZ value; */
        tmp |= ((unsigned long) sdram_table[i].sz << 17);
        /* get SDRAM bank 0 register */
-       mtdcr (SDRAM0_CFGADDR, mem_mb0cf);
+       mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR);
        sdram_bank = mfdcr (SDRAM0_CFGDATA) & ~0xFFCEE001;
        sdram_bank |= (baseaddr | tmp | 0x01);
 
@@ -380,7 +360,7 @@ int init_sdram (void)
 #endif
 
        /* write SDRAM timing register */
-       mtdcr (SDRAM0_CFGADDR, mem_sdtr1);
+       mtdcr (SDRAM0_CFGADDR, SDRAM0_TR);
        mtdcr (SDRAM0_CFGDATA, sdram_tim);
 
 #ifdef SDRAM_DEBUG
@@ -390,22 +370,22 @@ int init_sdram (void)
 #endif
 
        /* write SDRAM bank 0 register */
-       mtdcr (SDRAM0_CFGADDR, mem_mb0cf);
+       mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR);
        mtdcr (SDRAM0_CFGDATA, sdram_bank);
 
        if (get_bus_freq (tmp) > 110000000) {   /* > 110MHz */
                /* get SDRAM refresh interval register */
-               mtdcr (SDRAM0_CFGADDR, mem_rtr);
+               mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR);
                tmp = mfdcr (SDRAM0_CFGDATA) & ~0x3FF80000;
                tmp |= 0x07F00000;
        } else {
                /* get SDRAM refresh interval register */
-               mtdcr (SDRAM0_CFGADDR, mem_rtr);
+               mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR);
                tmp = mfdcr (SDRAM0_CFGDATA) & ~0x3FF80000;
                tmp |= 0x05F00000;
        }
        /* write SDRAM refresh interval register */
-       mtdcr (SDRAM0_CFGADDR, mem_rtr);
+       mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR);
        mtdcr (SDRAM0_CFGDATA, tmp);
        /* enable ECC if used */
 #if defined(ENABLE_ECC) && !defined(CONFIG_BOOT_PCI)
@@ -415,18 +395,18 @@ int init_sdram (void)
 #ifdef SDRAM_DEBUG
                serial_puts ("disable ECC.. ");
 #endif
-               mtdcr (SDRAM0_CFGADDR, mem_ecccf);
+               mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
                tmp = mfdcr (SDRAM0_CFGDATA);
                tmp &= 0xff0fffff;              /* disable all banks */
-               mtdcr (SDRAM0_CFGADDR, mem_ecccf);
+               mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
                /* set up SDRAM Controller with ECC enabled */
 #ifdef SDRAM_DEBUG
                serial_puts ("setup SDRAM Controller.. ");
 #endif
                mtdcr (SDRAM0_CFGDATA, tmp);
-               mtdcr (SDRAM0_CFGADDR, mem_mcopt1);
+               mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
                tmp = (mfdcr (SDRAM0_CFGDATA) & ~0xFFE00000) | 0x90800000;
-               mtdcr (SDRAM0_CFGADDR, mem_mcopt1);
+               mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
                mtdcr (SDRAM0_CFGDATA, tmp);
                udelay (600);
 #ifdef SDRAM_DEBUG
@@ -447,7 +427,7 @@ int init_sdram (void)
                serial_puts ("enable ECC\n");
 #endif
                udelay (400);
-               mtdcr (SDRAM0_CFGADDR, mem_ecccf);
+               mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
                tmp = mfdcr (SDRAM0_CFGDATA);
                tmp |= 0x00800000;              /* enable bank 0 */
                mtdcr (SDRAM0_CFGDATA, tmp);
@@ -456,9 +436,9 @@ int init_sdram (void)
 #endif
        {
                /* enable SDRAM controller with no ECC, 32-bit SDRAM width, 16 byte burst */
-               mtdcr (SDRAM0_CFGADDR, mem_mcopt1);
+               mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
                tmp = (mfdcr (SDRAM0_CFGDATA) & ~0xFFE00000) | 0x80C00000;
-               mtdcr (SDRAM0_CFGADDR, mem_mcopt1);
+               mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
                mtdcr (SDRAM0_CFGDATA, tmp);
                udelay (400);
        }
@@ -489,16 +469,37 @@ int board_early_init_f (void)
    |       caused the interrupt.
    |
    +-------------------------------------------------------------------------*/
-       mtdcr (uicsr, 0xFFFFFFFF);      /* clear all ints */
-       mtdcr (uicer, 0x00000000);      /* disable all ints */
-       mtdcr (uiccr, 0x00000000);      /* set all to be non-critical (for now) */
-       mtdcr (uicpr, 0xFFFFFF80);      /* set int polarities */
-       mtdcr (uictr, 0x10000000);      /* set int trigger levels */
-       mtdcr (uicvcr, 0x00000001);     /* set vect base=0,INT0 highest priority */
-       mtdcr (uicsr, 0xFFFFFFFF);      /* clear all ints */
+       mtdcr (UIC0SR, 0xFFFFFFFF);     /* clear all ints */
+       mtdcr (UIC0ER, 0x00000000);     /* disable all ints */
+       mtdcr (UIC0CR, 0x00000000);     /* set all to be non-critical (for now) */
+       mtdcr (UIC0PR, 0xFFFFFF80);     /* set int polarities */
+       mtdcr (UIC0TR, 0x10000000);     /* set int trigger levels */
+       mtdcr (UIC0VCR, 0x00000001);    /* set vect base=0,INT0 highest priority */
+       mtdcr (UIC0SR, 0xFFFFFFFF);     /* clear all ints */
        return 0;
 }
 
+int board_early_init_r(void)
+{
+       int mode;
+
+       /*
+        * since we are relocated, we can finally enable i-cache
+        * and set up the flash CS correctly
+        */
+       icache_enable();
+       setup_cs_reloc();
+       /* get and display boot mode */
+       mode = get_boot_mode();
+       if (mode & BOOT_PCI)
+               printf("PCI Boot %s Map\n", (mode & BOOT_MPS) ?
+                       "MPS" : "Flash");
+       else
+               printf("%s Boot\n", (mode & BOOT_MPS) ?
+                       "MPS" : "Flash");
+
+       return 0;
+}
 
 /*
  * Get some PLD Registers
@@ -542,7 +543,7 @@ void ide_set_reset (int idereset)
 
 void get_pcbrev_var(unsigned char *pcbrev, unsigned char *var)
 {
-#if !defined(CONFIG_MIP405T)
+#if !defined(CONFIG_TARGET_MIP405T)
        unsigned char bc,rc,tmp;
        int i;
 
@@ -574,7 +575,7 @@ void get_pcbrev_var(unsigned char *pcbrev, unsigned char *var)
  * Check Board Identity:
  */
 /* serial String: "MIP405_1000" OR "MIP405T_1000" */
-#if !defined(CONFIG_MIP405T)
+#if !defined(CONFIG_TARGET_MIP405T)
 #define BOARD_NAME     "MIP405"
 #else
 #define BOARD_NAME     "MIP405T"
@@ -589,7 +590,7 @@ int checkboard (void)
 
        puts ("Board: ");
        get_pcbrev_var(&bc,&var);
-       i = getenv_("serial#", (char *)s, 32);
+       i = getenv_f("serial#", (char *)s, 32);
        if ((i == 0) || strncmp ((char *)s, BOARD_NAME,sizeof(BOARD_NAME))) {
                get_backup_values (b);
                if (strncmp (b->signature, "MPL\0", 4) != 0) {
@@ -614,30 +615,29 @@ int checkboard (void)
 /* ------------------------------------------------------------------------- */
 /* ------------------------------------------------------------------------- */
 /*
-  initdram(int board_type) reads EEPROM via I2c. EEPROM contains all of
+  dram_init() reads EEPROM via I2c. EEPROM contains all of
   the necessary info for SDRAM controller configuration
 */
 /* ------------------------------------------------------------------------- */
 /* ------------------------------------------------------------------------- */
 static int test_dram (unsigned long ramsize);
 
-phys_size_t initdram (int board_type)
+int dram_init(void)
 {
 
        unsigned long bank_reg[4], tmp, bank_size;
-       int i, ds;
+       int i;
        unsigned long TotalSize;
 
-       ds = 0;
        /* since the DRAM controller is allready set up, calculate the size with the
           bank registers    */
-       mtdcr (SDRAM0_CFGADDR, mem_mb0cf);
+       mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR);
        bank_reg[0] = mfdcr (SDRAM0_CFGDATA);
-       mtdcr (SDRAM0_CFGADDR, mem_mb1cf);
+       mtdcr (SDRAM0_CFGADDR, SDRAM0_B1CR);
        bank_reg[1] = mfdcr (SDRAM0_CFGDATA);
-       mtdcr (SDRAM0_CFGADDR, mem_mb2cf);
+       mtdcr (SDRAM0_CFGADDR, SDRAM0_B2CR);
        bank_reg[2] = mfdcr (SDRAM0_CFGDATA);
-       mtdcr (SDRAM0_CFGADDR, mem_mb3cf);
+       mtdcr (SDRAM0_CFGADDR, SDRAM0_B3CR);
        bank_reg[3] = mfdcr (SDRAM0_CFGDATA);
        TotalSize = 0;
        for (i = 0; i < 4; i++) {
@@ -645,10 +645,9 @@ phys_size_t initdram (int board_type)
                        tmp = (bank_reg[i] >> 17) & 0x7;
                        bank_size = 4 << tmp;
                        TotalSize += bank_size;
-               } else
-                       ds = 1;
+               }
        }
-       mtdcr (SDRAM0_CFGADDR, mem_ecccf);
+       mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
        tmp = mfdcr (SDRAM0_CFGDATA);
 
        if (!tmp)
@@ -656,7 +655,9 @@ phys_size_t initdram (int board_type)
        printf ("ECC ");
 
        test_dram (TotalSize * MEGA_BYTE);
-       return (TotalSize * MEGA_BYTE);
+       gd->ram_size = TotalSize * MEGA_BYTE;
+
+       return 0;
 }
 
 /* ------------------------------------------------------------------------- */
@@ -674,7 +675,6 @@ static int test_dram (unsigned long ramsize)
 /* used to check if the time in RTC is valid */
 static unsigned long start;
 static struct rtc_time tm;
-extern flash_info_t flash_info[];      /* info for FLASH chips */
 
 int misc_init_r (void)
 {
@@ -706,18 +706,6 @@ void print_mip405_rev (void)
 }
 
 
-#ifdef CONFIG_POST
-/*
- * Returns 1 if keys pressed to start the power-on long-running tests
- * Called from board_init_f().
- */
-int post_hotkeys_pressed(void)
-{
-       return 0;       /* No hotkeys supported */
-}
-#endif
-
-extern void mem_test_reloc(void);
 extern int mk_date (char *, struct rtc_time *);
 
 int last_stage_init (void)
@@ -725,7 +713,7 @@ int last_stage_init (void)
        unsigned long stop;
        struct rtc_time newtm;
        char *s;
-       mem_test_reloc();
+
        /* write correct LED configuration */
        if (miiphy_write("ppc_4xx_eth0", 0x1, 0x14, 0x2402) != 0) {
                printf ("Error writing to the PHY\n");
@@ -766,7 +754,8 @@ int last_stage_init (void)
 
 int overwrite_console (void)
 {
-       return ((in8 (PLD_EXT_CONF_REG) & 0x1)==0);     /* return TRUE if console should be overwritten */
+       /* return true if console should be overwritten */
+       return ((in8(PLD_EXT_CONF_REG) & 0x1) == 0);
 }
 
 
@@ -790,7 +779,7 @@ void print_mip405_info (void)
                        (cfg >> 1) & 0x1, (cfg >> 2) & 0x1, (cfg >> 3) & 0x1);
        printf ("User LED %s\n", (com_mode & 0x4) ? "on" : "off");
        printf ("UART Clocks %d\n", (com_mode >> 4) & 0x3);
-#if !defined(CONFIG_MIP405T)
+#if !defined(CONFIG_TARGET_MIP405T)
        printf ("User Config Switch %d %d %d %d %d %d %d %d\n",
                        (ext) & 0x1, (ext >> 1) & 0x1, (ext >> 2) & 0x1,
                        (ext >> 3) & 0x1, (ext >> 4) & 0x1, (ext >> 5) & 0x1,
@@ -806,7 +795,7 @@ void print_mip405_info (void)
        printf ("IDE Reset %s\n", (ext & 0x01) ? "asserted" : "not asserted");
        printf ("IRQs:\n");
        printf ("  PIIX INTR: %s\n", (irq_reg & 0x80) ? "inactive" : "active");
-#if !defined(CONFIG_MIP405T)
+#if !defined(CONFIG_TARGET_MIP405T)
        printf ("  UART0 IRQ: %s\n", (irq_reg & 0x40) ? "inactive" : "active");
        printf ("  UART1 IRQ: %s\n", (irq_reg & 0x20) ? "inactive" : "active");
 #endif