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