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