wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 25 | #include <command.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 26 | #include "w7o.h" |
| 27 | #include <asm/processor.h> |
| 28 | |
| 29 | #include "vpd.h" |
| 30 | #include "errors.h" |
| 31 | #include <watchdog.h> |
| 32 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 33 | unsigned long get_dram_size (void); |
Stefan Roese | cdb0470 | 2008-06-02 17:37:28 +0200 | [diff] [blame] | 34 | void sdram_init(void); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 35 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 36 | /* ------------------------------------------------------------------------- */ |
| 37 | |
wdenk | da55c6e | 2004-01-20 23:12:12 +0000 | [diff] [blame] | 38 | int board_early_init_f (void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 39 | { |
| 40 | #if defined(CONFIG_W7OLMG) |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 41 | /* |
| 42 | * Setup GPIO pins - reset devices. |
| 43 | */ |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 44 | out32 (PPC405GP_GPIO0_ODR, 0x10000000); /* one open drain pin */ |
| 45 | out32 (PPC405GP_GPIO0_OR, 0x3E000000); /* set output pins to default */ |
| 46 | out32 (PPC405GP_GPIO0_TCR, 0x7f800000); /* setup for output */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 47 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 48 | /* |
| 49 | * IRQ 0-15 405GP internally generated; active high; level sensitive |
| 50 | * IRQ 16 405GP internally generated; active low; level sensitive |
| 51 | * IRQ 17-24 RESERVED |
| 52 | * IRQ 25 (EXT IRQ 0) XILINX; active low; level sensitive |
| 53 | * IRQ 26 (EXT IRQ 1) PCI INT A; active low; level sensitive |
| 54 | * IRQ 27 (EXT IRQ 2) PCI INT B; active low; level sensitive |
| 55 | * IRQ 28 (EXT IRQ 3) SAM 2; active low; level sensitive |
| 56 | * IRQ 29 (EXT IRQ 4) Battery Bad; active low; level sensitive |
| 57 | * IRQ 30 (EXT IRQ 5) Level One PHY; active low; level sensitive |
| 58 | * IRQ 31 (EXT IRQ 6) SAM 1; active high; level sensitive |
| 59 | */ |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 60 | mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 61 | mtdcr (UIC0ER, 0x00000000); /* disable all ints */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 62 | |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 63 | mtdcr (UIC0CR, 0x00000000); /* set all to be non-critical */ |
| 64 | mtdcr (UIC0PR, 0xFFFFFF80); /* set int polarities */ |
| 65 | mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */ |
| 66 | mtdcr (UIC0VCR, 0x00000001); /* set vect base=0, |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 67 | INT0 highest priority */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 68 | |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 69 | mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 70 | |
| 71 | #elif defined(CONFIG_W7OLMC) |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 72 | /* |
| 73 | * Setup GPIO pins |
| 74 | */ |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 75 | out32 (PPC405GP_GPIO0_ODR, 0x01800000); /* XCV Done Open Drain */ |
| 76 | out32 (PPC405GP_GPIO0_OR, 0x03800000); /* set out pins to default */ |
| 77 | out32 (PPC405GP_GPIO0_TCR, 0x66C00000); /* setup for output */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 78 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 79 | /* |
| 80 | * IRQ 0-15 405GP internally generated; active high; level sensitive |
| 81 | * IRQ 16 405GP internally generated; active low; level sensitive |
| 82 | * IRQ 17-24 RESERVED |
| 83 | * IRQ 25 (EXT IRQ 0) DBE 0; active low; level sensitive |
| 84 | * IRQ 26 (EXT IRQ 1) DBE 1; active low; level sensitive |
| 85 | * IRQ 27 (EXT IRQ 2) DBE 2; active low; level sensitive |
| 86 | * IRQ 28 (EXT IRQ 3) DBE Common; active low; level sensitive |
| 87 | * IRQ 29 (EXT IRQ 4) PCI; active low; level sensitive |
| 88 | * IRQ 30 (EXT IRQ 5) RCMM Reset; active low; level sensitive |
| 89 | * IRQ 31 (EXT IRQ 6) PHY; active high; level sensitive |
| 90 | */ |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 91 | mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 92 | mtdcr (UIC0ER, 0x00000000); /* disable all ints */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 93 | |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 94 | mtdcr (UIC0CR, 0x00000000); /* set all to be non-critical */ |
| 95 | mtdcr (UIC0PR, 0xFFFFFF80); /* set int polarities */ |
| 96 | mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */ |
| 97 | mtdcr (UIC0VCR, 0x00000001); /* set vect base=0, |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 98 | INT0 highest priority */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 99 | |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 100 | mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 101 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 102 | #else /* Unknown */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 103 | # error "Unknown W7O board configuration" |
| 104 | #endif |
| 105 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 106 | WATCHDOG_RESET (); /* Reset the watchdog */ |
| 107 | temp_uart_init (); /* init the uart for debug */ |
| 108 | WATCHDOG_RESET (); /* Reset the watchdog */ |
| 109 | test_led (); /* test the LEDs */ |
| 110 | test_sdram (get_dram_size ()); /* test the dram */ |
| 111 | log_stat (ERR_POST1); /* log status,post1 complete */ |
| 112 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | |
| 116 | /* ------------------------------------------------------------------------- */ |
| 117 | |
| 118 | /* |
| 119 | * Check Board Identity: |
| 120 | */ |
| 121 | int checkboard (void) |
| 122 | { |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 123 | VPD vpd; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 124 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 125 | puts ("Board: "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 126 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 127 | /* VPD data present in I2C EEPROM */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 128 | if (vpd_get_data (CONFIG_SYS_DEF_EEPROM_ADDR, &vpd) == 0) { |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 129 | /* |
| 130 | * Known board type. |
| 131 | */ |
| 132 | if (vpd.productId[0] && |
| 133 | ((strncmp (vpd.productId, "GMM", 3) == 0) || |
| 134 | (strncmp (vpd.productId, "CMM", 3) == 0))) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 135 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 136 | /* Output board information on startup */ |
| 137 | printf ("\"%s\", revision '%c', serial# %ld, manufacturer %u\n", vpd.productId, vpd.revisionId, vpd.serialNum, vpd.manuID); |
| 138 | return (0); |
| 139 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 140 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 141 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 142 | puts ("### Unknown HW ID - assuming NOTHING\n"); |
| 143 | return (0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /* ------------------------------------------------------------------------- */ |
| 147 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 148 | phys_size_t initdram (int board_type) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 149 | { |
Stefan Roese | cdb0470 | 2008-06-02 17:37:28 +0200 | [diff] [blame] | 150 | /* |
| 151 | * ToDo: Move the asm init routine sdram_init() to this C file, |
| 152 | * or even better use some common ppc4xx code available |
Stefan Roese | 88fbf93 | 2010-04-15 16:07:28 +0200 | [diff] [blame] | 153 | * in arch/powerpc/cpu/ppc4xx |
Stefan Roese | cdb0470 | 2008-06-02 17:37:28 +0200 | [diff] [blame] | 154 | */ |
| 155 | sdram_init(); |
| 156 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 157 | return get_dram_size (); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | unsigned long get_dram_size (void) |
| 161 | { |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 162 | int tmp, i, regs[4]; |
| 163 | int size = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 164 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 165 | /* Get bank Size registers */ |
Stefan Roese | 6987e65 | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 166 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR); /* get bank 0 config reg */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 167 | regs[0] = mfdcr (SDRAM0_CFGDATA); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 168 | |
Stefan Roese | 6987e65 | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 169 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B1CR); /* get bank 1 config reg */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 170 | regs[1] = mfdcr (SDRAM0_CFGDATA); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 171 | |
Stefan Roese | 6987e65 | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 172 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B2CR); /* get bank 2 config reg */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 173 | regs[2] = mfdcr (SDRAM0_CFGDATA); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 174 | |
Stefan Roese | 6987e65 | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 175 | mtdcr (SDRAM0_CFGADDR, SDRAM0_B3CR); /* get bank 3 config reg */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 176 | regs[3] = mfdcr (SDRAM0_CFGDATA); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 177 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 178 | /* compute the size, add each bank if enabled */ |
| 179 | for (i = 0; i < 4; i++) { |
| 180 | if (regs[i] & 0x0001) { /* if enabled, */ |
| 181 | tmp = ((regs[i] >> (31 - 14)) & 0x7); /* get size bits */ |
| 182 | tmp = 0x400000 << tmp; /* Size bits X 4MB = size */ |
| 183 | size += tmp; |
| 184 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 185 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 186 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 187 | return size; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | int misc_init_f (void) |
| 191 | { |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 192 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 193 | } |
| 194 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 195 | static void w7o_env_init (VPD * vpd) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 196 | { |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 197 | /* |
| 198 | * Read VPD |
| 199 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 200 | if (vpd_get_data (CONFIG_SYS_DEF_EEPROM_ADDR, vpd) != 0) |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 201 | return; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 202 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 203 | /* |
| 204 | * Known board type. |
| 205 | */ |
| 206 | if (vpd->productId[0] && |
| 207 | ((strncmp (vpd->productId, "GMM", 3) == 0) || |
| 208 | (strncmp (vpd->productId, "CMM", 3) == 0))) { |
| 209 | char buf[30]; |
| 210 | char *eth; |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 211 | char *serial = getenv ("serial#"); |
| 212 | char *ethaddr = getenv ("ethaddr"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 213 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 214 | /* Set 'serial#' envvar if serial# isn't set */ |
| 215 | if (!serial) { |
| 216 | sprintf (buf, "%s-%ld", vpd->productId, |
| 217 | vpd->serialNum); |
| 218 | setenv ("serial#", buf); |
| 219 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 220 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 221 | /* Set 'ethaddr' envvar if 'ethaddr' envvar is the default */ |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 222 | eth = (char *)(vpd->ethAddrs[0]); |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 223 | if (ethaddr |
Marek Vasut | 0b3176c | 2012-09-23 17:41:24 +0200 | [diff] [blame] | 224 | && (strcmp(ethaddr, __stringify(CONFIG_ETHADDR)) == 0)) { |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 225 | /* Now setup ethaddr */ |
| 226 | sprintf (buf, "%02x:%02x:%02x:%02x:%02x:%02x", |
| 227 | eth[0], eth[1], eth[2], eth[3], eth[4], |
| 228 | eth[5]); |
| 229 | setenv ("ethaddr", buf); |
| 230 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 231 | } |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 232 | } /* w7o_env_init() */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 233 | |
| 234 | |
| 235 | int misc_init_r (void) |
| 236 | { |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 237 | VPD vpd; /* VPD information */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 238 | |
| 239 | #if defined(CONFIG_W7OLMG) |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 240 | unsigned long greg; /* GPIO Register */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 241 | |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 242 | greg = in32 (PPC405GP_GPIO0_OR); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 243 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 244 | /* |
| 245 | * XXX - Unreset devices - this should be moved into VxWorks driver code |
| 246 | */ |
| 247 | greg |= 0x41800000L; /* SAM, PHY, Galileo */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 248 | |
Wolfgang Denk | 0ee7077 | 2005-09-23 11:05:55 +0200 | [diff] [blame] | 249 | out32 (PPC405GP_GPIO0_OR, greg); /* set output pins to default */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 250 | #endif /* CONFIG_W7OLMG */ |
| 251 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 252 | /* |
| 253 | * Initialize W7O environment variables |
| 254 | */ |
| 255 | w7o_env_init (&vpd); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 256 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 257 | /* |
| 258 | * Initialize the FPGA(s). |
| 259 | */ |
| 260 | if (init_fpga () == 0) |
| 261 | test_fpga ((unsigned short *) CONFIG_FPGAS_BASE); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 262 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 263 | /* More POST testing. */ |
| 264 | post2 (); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 265 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 266 | /* Done with hardware initialization and POST. */ |
| 267 | log_stat (ERR_POSTOK); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 268 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 269 | /* Call silly, fail safe boot init routine */ |
| 270 | init_fsboot (); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 271 | |
| 272 | return (0); |
| 273 | } |