wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 ELTEC Elektronik AG |
| 3 | * Frank Gottschling <fgottschling@eltec.de> |
| 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 | /* includes */ |
| 25 | #include <common.h> |
| 26 | #include <linux/ctype.h> |
| 27 | #include <pci.h> |
| 28 | #include <net.h> |
| 29 | #include "srom.h" |
| 30 | |
| 31 | /* imports */ |
| 32 | extern char console_buffer[CFG_CBSIZE]; |
| 33 | extern int l2_cache_enable (int l2control); |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 34 | extern int eepro100_write_eeprom (struct eth_device *dev, int location, |
| 35 | int addr_len, unsigned short data); |
| 36 | extern int read_eeprom (struct eth_device *dev, int location, int addr_len); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 37 | |
| 38 | /*----------------------------------------------------------------------------*/ |
| 39 | /* |
| 40 | * read/write to nvram is only byte access |
| 41 | */ |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 42 | void *nvram_read (void *dest, const long src, size_t count) |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 43 | { |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 44 | uchar *d = (uchar *) dest; |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame^] | 45 | uchar *s = (uchar *) (CONFIG_ENV_MAP_ADRS + src); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 46 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 47 | while (count--) |
| 48 | *d++ = *s++; |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 49 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 50 | return dest; |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 51 | } |
| 52 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 53 | void nvram_write (long dest, const void *src, size_t count) |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 54 | { |
Jean-Christophe PLAGNIOL-VILLARD | 7e1cda6 | 2008-09-10 22:48:06 +0200 | [diff] [blame^] | 55 | uchar *d = (uchar *) (CONFIG_ENV_MAP_ADRS + dest); |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 56 | uchar *s = (uchar *) src; |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 57 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 58 | while (count--) |
| 59 | *d++ = *s++; |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /*----------------------------------------------------------------------------*/ |
| 63 | /* |
| 64 | * handle sroms on ELPPC |
| 65 | * fix ether address |
| 66 | * set serial console as default |
| 67 | */ |
| 68 | int misc_init_r (void) |
| 69 | { |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 70 | revinfo eerev; |
| 71 | u_char *ptr; |
| 72 | u_int i, l, initSrom, copyNv; |
| 73 | char buf[256]; |
| 74 | char hex[23] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, |
| 75 | 0, 0, 0, 0, 10, 11, 12, 13, 14, 15 |
| 76 | }; |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 77 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 78 | /* Clock setting for MPC107 i2c */ |
| 79 | mpc107_i2c_init (MPC107_EUMB_ADDR, 0x2b); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 80 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 81 | /* Reset the EPIC */ |
| 82 | out32r (MPC107_EUMB_GCR, 0xa0000000); |
| 83 | while (in32r (MPC107_EUMB_GCR) & 0x80000000); /* Wait for reset to complete */ |
| 84 | out32r (MPC107_EUMB_GCR, 0x20000000); /* Put into into mixed mode */ |
| 85 | while (in32r (MPC107_EUMB_IACKR) != 0xff); /* Clear all pending interrupts */ |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 86 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 87 | /* |
| 88 | * Check/Remake revision info |
| 89 | */ |
| 90 | initSrom = 0; |
| 91 | copyNv = 0; |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 92 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 93 | /* read out current revision srom contens */ |
| 94 | mpc107_srom_load (0x0000, (u_char *) & eerev, sizeof (revinfo), |
| 95 | SECOND_DEVICE, FIRST_BLOCK); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 96 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 97 | /* read out current nvram shadow image */ |
| 98 | nvram_read (buf, CFG_NV_SROM_COPY_ADDR, CFG_SROM_SIZE); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 99 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 100 | if (strcmp (eerev.magic, "ELTEC") != 0) { |
| 101 | /* srom is not initialized -> create a default revision info */ |
| 102 | for (i = 0, ptr = (u_char *) & eerev; i < sizeof (revinfo); |
| 103 | i++) |
| 104 | *ptr++ = 0x00; |
| 105 | strcpy (eerev.magic, "ELTEC"); |
| 106 | eerev.revrev[0] = 1; |
| 107 | eerev.revrev[1] = 0; |
| 108 | eerev.size = 0x00E0; |
| 109 | eerev.category[0] = 0x01; |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 110 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 111 | /* node id from dead e128 as default */ |
| 112 | eerev.etheraddr[0] = 0x00; |
| 113 | eerev.etheraddr[1] = 0x00; |
| 114 | eerev.etheraddr[2] = 0x5B; |
| 115 | eerev.etheraddr[3] = 0x00; |
| 116 | eerev.etheraddr[4] = 0x2E; |
| 117 | eerev.etheraddr[5] = 0x4D; |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 118 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 119 | /* cache config word for ELPPC */ |
| 120 | *(int *) &eerev.res[0] = 0; |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 121 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 122 | initSrom = 1; /* force dialog */ |
| 123 | copyNv = 1; /* copy to nvram */ |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 124 | } |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 125 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 126 | if ((copyNv == 0) |
| 127 | && (el_srom_checksum ((u_char *) & eerev, CFG_SROM_SIZE) != |
| 128 | el_srom_checksum ((u_char *) buf, CFG_SROM_SIZE))) { |
| 129 | printf ("Invalid revision info copy in nvram !\n"); |
| 130 | printf ("Press key:\n <c> to copy current revision info to nvram.\n"); |
| 131 | printf (" <r> to reenter revision info.\n"); |
| 132 | printf ("=> "); |
| 133 | if (0 != readline (NULL)) { |
| 134 | switch ((char) toupper (console_buffer[0])) { |
| 135 | case 'C': |
| 136 | copyNv = 1; |
| 137 | break; |
| 138 | case 'R': |
| 139 | copyNv = 1; |
| 140 | initSrom = 1; |
| 141 | break; |
| 142 | } |
| 143 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 144 | } |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 145 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 146 | if (initSrom) { |
| 147 | memcpy (buf, &eerev.revision[0][0], 14); /* save all revision info */ |
| 148 | printf ("Enter revision number (0-9): %c ", |
| 149 | eerev.revision[0][0]); |
| 150 | if (0 != readline (NULL)) { |
| 151 | eerev.revision[0][0] = |
| 152 | (char) toupper (console_buffer[0]); |
| 153 | memcpy (&eerev.revision[1][0], buf, 12); /* shift rest of rev info */ |
| 154 | } |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 155 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 156 | printf ("Enter revision character (A-Z): %c ", |
| 157 | eerev.revision[0][1]); |
| 158 | if (1 == readline (NULL)) { |
| 159 | eerev.revision[0][1] = |
| 160 | (char) toupper (console_buffer[0]); |
| 161 | } |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 162 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 163 | printf ("Enter board name (V-XXXX-XXXX): %s ", |
| 164 | (char *) &eerev.board); |
| 165 | if (11 == readline (NULL)) { |
| 166 | for (i = 0; i < 11; i++) |
| 167 | eerev.board[i] = |
| 168 | (char) toupper (console_buffer[i]); |
| 169 | eerev.board[11] = '\0'; |
| 170 | } |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 171 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 172 | printf ("Enter serial number: %s ", (char *) &eerev.serial); |
| 173 | if (6 == readline (NULL)) { |
| 174 | for (i = 0; i < 6; i++) |
| 175 | eerev.serial[i] = console_buffer[i]; |
| 176 | eerev.serial[6] = '\0'; |
| 177 | } |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 178 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 179 | printf ("Enter ether node ID with leading zero (HEX): %02x%02x%02x%02x%02x%02x ", eerev.etheraddr[0], eerev.etheraddr[1], eerev.etheraddr[2], eerev.etheraddr[3], eerev.etheraddr[4], eerev.etheraddr[5]); |
| 180 | if (12 == readline (NULL)) { |
| 181 | for (i = 0; i < 12; i += 2) |
| 182 | eerev.etheraddr[i >> 1] = |
| 183 | (char) (16 * |
| 184 | hex[toupper |
| 185 | (console_buffer[i]) - |
| 186 | '0'] + |
| 187 | hex[toupper |
| 188 | (console_buffer[i + 1]) - |
| 189 | '0']); |
| 190 | } |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 191 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 192 | l = strlen ((char *) &eerev.text); |
| 193 | printf ("Add to text section (max 64 chr): %s ", |
| 194 | (char *) &eerev.text); |
| 195 | if (0 != readline (NULL)) { |
| 196 | for (i = l; i < 63; i++) |
| 197 | eerev.text[i] = console_buffer[i - l]; |
| 198 | eerev.text[63] = '\0'; |
| 199 | } |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 200 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 201 | /* prepare network eeprom */ |
| 202 | memset (buf, 0, 128); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 203 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 204 | buf[0] = eerev.etheraddr[1]; |
| 205 | buf[1] = eerev.etheraddr[0]; |
| 206 | buf[2] = eerev.etheraddr[3]; |
| 207 | buf[3] = eerev.etheraddr[2]; |
| 208 | buf[4] = eerev.etheraddr[5]; |
| 209 | buf[5] = eerev.etheraddr[4]; |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 210 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 211 | *(unsigned short *) &buf[20] = 0x48B2; |
| 212 | *(unsigned short *) &buf[22] = 0x0004; |
| 213 | *(unsigned short *) &buf[24] = 0x1433; |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 214 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 215 | printf ("\nSRom: Writing i82559 info ........ "); |
| 216 | if (eepro100_srom_store ((unsigned short *) buf) == -1) |
| 217 | printf ("FAILED\n"); |
| 218 | else |
| 219 | printf ("OK\n"); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 220 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 221 | /* update CRC */ |
| 222 | eerev.crc = |
| 223 | el_srom_checksum ((u_char *) eerev.board, eerev.size); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 224 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 225 | /* write new values */ |
| 226 | printf ("\nSRom: Writing revision info ...... "); |
| 227 | if (mpc107_srom_store |
| 228 | ((BLOCK_SIZE - sizeof (revinfo)), (u_char *) & eerev, |
| 229 | sizeof (revinfo), SECOND_DEVICE, FIRST_BLOCK) == -1) |
| 230 | printf ("FAILED\n\n"); |
| 231 | else |
| 232 | printf ("OK\n\n"); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 233 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 234 | /* write new values as shadow image to nvram */ |
| 235 | nvram_write (CFG_NV_SROM_COPY_ADDR, (void *) &eerev, |
| 236 | CFG_SROM_SIZE); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 237 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /*if (initSrom) */ |
| 241 | /* copy current values as shadow image to nvram */ |
| 242 | if (initSrom == 0 && copyNv == 1) |
| 243 | nvram_write (CFG_NV_SROM_COPY_ADDR, (void *) &eerev, |
| 244 | CFG_SROM_SIZE); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 245 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 246 | /* update environment */ |
| 247 | sprintf (buf, "%02x:%02x:%02x:%02x:%02x:%02x", |
| 248 | eerev.etheraddr[0], eerev.etheraddr[1], |
| 249 | eerev.etheraddr[2], eerev.etheraddr[3], |
| 250 | eerev.etheraddr[4], eerev.etheraddr[5]); |
| 251 | setenv ("ethaddr", buf); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 252 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 253 | /* print actual board identification */ |
| 254 | printf ("Ident: %s Ser %s Rev %c%c\n", |
| 255 | eerev.board, (char *) &eerev.serial, |
| 256 | eerev.revision[0][0], eerev.revision[0][1]); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 257 | |
wdenk | e65527f | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 258 | return (0); |
wdenk | e69b4b8 | 2002-09-17 21:26:59 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /*----------------------------------------------------------------------------*/ |