]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - board/freescale/mpc8349itx/mpc8349itx.c
Merge branch 'master' of git://git.denx.de/u-boot-i2c
[karo-tx-uboot.git] / board / freescale / mpc8349itx / mpc8349itx.c
index 972361fd68c7ce4a20d9bdd13b57f4ac177d625c..803d722806046ab3fc296631b6094d0641e9895a 100644 (file)
@@ -1,23 +1,7 @@
 /*
- * Copyright (C) Freescale Semiconductor, Inc. 2006. All rights reserved.
+ * Copyright (C) Freescale Semiconductor, Inc. 2006.
  *
- * 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+
  */
 
 #include <common.h>
@@ -25,6 +9,7 @@
 #include <mpc83xx.h>
 #include <i2c.h>
 #include <miiphy.h>
+#include <vsc7385.h>
 #ifdef CONFIG_PCI
 #include <asm/mpc8349_pci.h>
 #include <pci.h>
  ************************************************************************/
 int fixed_sdram(void)
 {
-       volatile immap_t *im = (immap_t *) CFG_IMMR;
-       u32 ddr_size;           /* The size of RAM, in bytes */
-       u32 ddr_size_log2 = 0;
-
-       for (ddr_size = CFG_DDR_SIZE * 0x100000; ddr_size > 1; ddr_size >>= 1) {
-               if (ddr_size & 1) {
-                       return -1;
-               }
-               ddr_size_log2++;
-       }
+       volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
+       /* The size of RAM, in bytes */
+       u32 ddr_size = CONFIG_SYS_DDR_SIZE << 20;
+       u32 ddr_size_log2 = __ilog2(ddr_size);
 
        im->sysconf.ddrlaw[0].ar =
            LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
-       im->sysconf.ddrlaw[0].bar = (CFG_DDR_SDRAM_BASE >> 12) & 0xfffff;
+       im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
+
+#if ((CONFIG_SYS_DDR_SDRAM_BASE & 0x00FFFFFF) != 0)
+#warning Chip select bounds is only configurable in 16MB increments
+#endif
+       im->ddr.csbnds[0].csbnds =
+               ((CONFIG_SYS_DDR_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
+               (((CONFIG_SYS_DDR_SDRAM_BASE + ddr_size - 1) >>
+                               CSBNDS_EA_SHIFT) & CSBNDS_EA);
+       im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
 
-       /* Only one CS0 for DDR */
-       im->ddr.csbnds[0].csbnds = 0x0000000f;
-       im->ddr.cs_config[0] = CFG_DDR_CONFIG;
+       /* Only one CS for DDR */
+       im->ddr.cs_config[1] = 0;
+       im->ddr.cs_config[2] = 0;
+       im->ddr.cs_config[3] = 0;
 
        debug("cs0_bnds = 0x%08x\n", im->ddr.csbnds[0].csbnds);
        debug("cs0_config = 0x%08x\n", im->ddr.cs_config[0]);
@@ -66,15 +55,15 @@ int fixed_sdram(void)
        debug("DDR:bar=0x%08x\n", im->sysconf.ddrlaw[0].bar);
        debug("DDR:ar=0x%08x\n", im->sysconf.ddrlaw[0].ar);
 
-       im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
-       im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;/* Was "2 << TIMING_CFG2_WR_DATA_DELAY_SHIFT" */
+       im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
+       im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;/* Was "2 << TIMING_CFG2_WR_DATA_DELAY_SHIFT" */
        im->ddr.sdram_cfg = SDRAM_CFG_SREN | SDRAM_CFG_SDRAM_TYPE_DDR1;
        im->ddr.sdram_mode =
            (0x0000 << SDRAM_MODE_ESD_SHIFT) | (0x0032 << SDRAM_MODE_SD_SHIFT);
        im->ddr.sdram_interval =
            (0x0410 << SDRAM_INTERVAL_REFINT_SHIFT) | (0x0100 <<
                                                       SDRAM_INTERVAL_BSTOPRE_SHIFT);
-       im->ddr.sdram_clk_cntl = CFG_DDR_SDRAM_CLK_CNTL;
+       im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
 
        udelay(200);
 
@@ -86,7 +75,7 @@ int fixed_sdram(void)
        debug("DDR:sdram_interval=0x%08x\n", im->ddr.sdram_interval);
        debug("DDR:sdram_cfg=0x%08x\n", im->ddr.sdram_cfg);
 
-       return CFG_DDR_SIZE;
+       return CONFIG_SYS_DDR_SIZE;
 }
 #endif
 
@@ -127,9 +116,9 @@ volatile static struct pci_controller hose[] = {
 };
 #endif                         /* CONFIG_PCI */
 
-long int initdram(int board_type)
+phys_size_t initdram(int board_type)
 {
-       volatile immap_t *im = (immap_t *) CFG_IMMR;
+       volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
        u32 msize = 0;
 #ifdef CONFIG_DDR_ECC
        volatile ddr83xx_t *ddr = &im->ddr;
@@ -139,7 +128,7 @@ long int initdram(int board_type)
                return -1;
 
        /* DDR SDRAM - Main SODIMM */
-       im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
+       im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
 #ifdef CONFIG_SPD_EEPROM
        msize = spd_sdram();
 #else
@@ -177,7 +166,7 @@ int checkboard(void)
  */
 int misc_init_f(void)
 {
-#ifdef CONFIG_VSC7385
+#ifdef CONFIG_VSC7385_ENET
        volatile u32 *vsc7385_cpuctrl;
 
        /* 0x1c0c0 is the VSC7385 CPU Control (CPUCTRL) Register.  The power up
@@ -195,7 +184,7 @@ int misc_init_f(void)
           don't enable compact flash for U-Boot.
         */
 
-       vsc7385_cpuctrl = (volatile u32 *)(CFG_VSC7385_BASE + 0x1c0c0);
+       vsc7385_cpuctrl = (volatile u32 *)(CONFIG_SYS_VSC7385_BASE + 0x1c0c0);
        *vsc7385_cpuctrl |= 0x0c;
 #endif
 
@@ -219,16 +208,15 @@ int misc_init_f(void)
                0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
                0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01
        };
-       volatile immap_t *immap = (immap_t *) CFG_IMMR;
-       volatile lbus83xx_t *lbus = &immap->lbus;
+       volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
 
-       lbus->bank[3].br = CFG_BR3_PRELIM;
-       lbus->bank[3].or = CFG_OR3_PRELIM;
+       set_lbc_br(3, CONFIG_SYS_BR3_PRELIM);
+       set_lbc_or(3, CONFIG_SYS_OR3_PRELIM);
 
        /* Program the MAMR. RFEN=0, OP=00, UWPL=1, AM=000, DS=01, G0CL=000,
           GPL4=0, RLF=0001, WLF=0001, TLF=0001, MAD=000000
         */
-       lbus->mamr = 0x08404440;
+       immap->im_lbc.mamr = 0x08404440;
 
        upmconfig(0, UPMATable, sizeof(UPMATable) / sizeof(UPMATable[0]));
 
@@ -239,6 +227,8 @@ int misc_init_f(void)
 }
 
 /*
+ * Miscellaneous late-boot configurations
+ *
  * Make sure the EEPROM has the HRCW correctly programmed.
  * Make sure the RTC is correctly programmed.
  *
@@ -250,36 +240,37 @@ int misc_init_f(void)
  *
  * This function makes sure that the I2C EEPROM is programmed
  * correctly.
+ *
+ * If a VSC7385 microcode image is present, then upload it.
  */
 int misc_init_r(void)
 {
        int rc = 0;
 
-#ifdef CONFIG_HARD_I2C
-
+#if defined(CONFIG_SYS_I2C)
        unsigned int orig_bus = i2c_get_bus_num();
        u8 i2c_data;
 
-#ifdef CFG_I2C_RTC_ADDR
+#ifdef CONFIG_SYS_I2C_RTC_ADDR
        u8 ds1339_data[17];
 #endif
 
-#ifdef CFG_I2C_EEPROM_ADDR
+#ifdef CONFIG_SYS_I2C_EEPROM_ADDR
        static u8 eeprom_data[] =       /* HRCW data */
        {
                0xAA, 0x55, 0xAA,       /* Preamble */
-               0x7C,                   /* ACS=0, BYTE_EN=1111, CONT=1 */
-               0x02, 0x40,             /* RCWL ADDR=0x0_0900 */
-               (CFG_HRCW_LOW >> 24) & 0xFF,
-               (CFG_HRCW_LOW >> 16) & 0xFF,
-               (CFG_HRCW_LOW >> 8) & 0xFF,
-               CFG_HRCW_LOW & 0xFF,
-               0x7C,                   /* ACS=0, BYTE_EN=1111, CONT=1 */
+               0x7C,                   /* ACS=0, BYTE_EN=1111, CONT=1 */
+               0x02, 0x40,             /* RCWL ADDR=0x0_0900 */
+               (CONFIG_SYS_HRCW_LOW >> 24) & 0xFF,
+               (CONFIG_SYS_HRCW_LOW >> 16) & 0xFF,
+               (CONFIG_SYS_HRCW_LOW >> 8) & 0xFF,
+               CONFIG_SYS_HRCW_LOW & 0xFF,
+               0x7C,                   /* ACS=0, BYTE_EN=1111, CONT=1 */
                0x02, 0x41,             /* RCWH ADDR=0x0_0904 */
-               (CFG_HRCW_HIGH >> 24) & 0xFF,
-               (CFG_HRCW_HIGH >> 16) & 0xFF,
-               (CFG_HRCW_HIGH >> 8) & 0xFF,
-               CFG_HRCW_HIGH & 0xFF
+               (CONFIG_SYS_HRCW_HIGH >> 24) & 0xFF,
+               (CONFIG_SYS_HRCW_HIGH >> 16) & 0xFF,
+               (CONFIG_SYS_HRCW_HIGH >> 8) & 0xFF,
+               CONFIG_SYS_HRCW_HIGH & 0xFF
        };
 
        u8 data[sizeof(eeprom_data)];
@@ -287,22 +278,22 @@ int misc_init_r(void)
 
        printf("Board revision: ");
        i2c_set_bus_num(1);
-       if (i2c_read(CFG_I2C_8574A_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
+       if (i2c_read(CONFIG_SYS_I2C_8574A_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
                printf("%u.%u (PCF8475A)\n", (i2c_data & 0x02) >> 1, i2c_data & 0x01);
-       else if (i2c_read(CFG_I2C_8574_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
+       else if (i2c_read(CONFIG_SYS_I2C_8574_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
                printf("%u.%u (PCF8475)\n",  (i2c_data & 0x02) >> 1, i2c_data & 0x01);
        else {
                printf("Unknown\n");
                rc = 1;
        }
 
-#ifdef CFG_I2C_EEPROM_ADDR
+#ifdef CONFIG_SYS_I2C_EEPROM_ADDR
        i2c_set_bus_num(0);
 
-       if (i2c_read(CFG_I2C_EEPROM_ADDR, 0, 2, data, sizeof(data)) == 0) {
+       if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, data, sizeof(data)) == 0) {
                if (memcmp(data, eeprom_data, sizeof(data)) != 0) {
                        if (i2c_write
-                           (CFG_I2C_EEPROM_ADDR, 0, 2, eeprom_data,
+                           (CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, eeprom_data,
                             sizeof(eeprom_data)) != 0) {
                                puts("Failure writing the HRCW to EEPROM via I2C.\n");
                                rc = 1;
@@ -314,10 +305,10 @@ int misc_init_r(void)
        }
 #endif
 
-#ifdef CFG_I2C_RTC_ADDR
+#ifdef CONFIG_SYS_I2C_RTC_ADDR
        i2c_set_bus_num(1);
 
-       if (i2c_read(CFG_I2C_RTC_ADDR, 0, 1, ds1339_data, sizeof(ds1339_data))
+       if (i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, ds1339_data, sizeof(ds1339_data))
            == 0) {
 
                /* Work-around for MPC8349E-mITX bug #13601.
@@ -361,7 +352,7 @@ int misc_init_r(void)
                 */
 
                if (i2c_write
-                   (CFG_I2C_RTC_ADDR, 0, 1, ds1339_data,
+                   (CONFIG_SYS_I2C_RTC_ADDR, 0, 1, ds1339_data,
                     sizeof(ds1339_data))) {
                        puts("Failure writing to the RTC via I2C.\n");
                        rc = 1;
@@ -375,6 +366,14 @@ int misc_init_r(void)
        i2c_set_bus_num(orig_bus);
 #endif
 
+#ifdef CONFIG_VSC7385_IMAGE
+       if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
+               CONFIG_VSC7385_IMAGE_SIZE)) {
+               puts("Failure uploading VSC7385 microcode.\n");
+               rc = 1;
+       }
+#endif
+
        return rc;
 }