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