blob: d80eaba2d0a4d7e362af254650da05f44475c6a5 [file] [log] [blame]
wdenke69b4b82002-09-17 21:26:59 +00001/*
2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenke69b4b82002-09-17 21:26:59 +00006 */
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 */
wdenke69b4b82002-09-17 21:26:59 +000016extern int l2_cache_enable (int l2control);
wdenke65527f2004-02-12 00:47:09 +000017extern int eepro100_write_eeprom (struct eth_device *dev, int location,
18 int addr_len, unsigned short data);
19extern int read_eeprom (struct eth_device *dev, int location, int addr_len);
wdenke69b4b82002-09-17 21:26:59 +000020
21/*----------------------------------------------------------------------------*/
22/*
23 * read/write to nvram is only byte access
24 */
wdenke65527f2004-02-12 00:47:09 +000025void *nvram_read (void *dest, const long src, size_t count)
wdenke69b4b82002-09-17 21:26:59 +000026{
wdenke65527f2004-02-12 00:47:09 +000027 uchar *d = (uchar *) dest;
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +020028 uchar *s = (uchar *) (CONFIG_ENV_MAP_ADRS + src);
wdenke69b4b82002-09-17 21:26:59 +000029
wdenke65527f2004-02-12 00:47:09 +000030 while (count--)
31 *d++ = *s++;
wdenke69b4b82002-09-17 21:26:59 +000032
wdenke65527f2004-02-12 00:47:09 +000033 return dest;
wdenke69b4b82002-09-17 21:26:59 +000034}
35
wdenke65527f2004-02-12 00:47:09 +000036void nvram_write (long dest, const void *src, size_t count)
wdenke69b4b82002-09-17 21:26:59 +000037{
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +020038 uchar *d = (uchar *) (CONFIG_ENV_MAP_ADRS + dest);
wdenke65527f2004-02-12 00:47:09 +000039 uchar *s = (uchar *) src;
wdenke69b4b82002-09-17 21:26:59 +000040
wdenke65527f2004-02-12 00:47:09 +000041 while (count--)
42 *d++ = *s++;
wdenke69b4b82002-09-17 21:26:59 +000043}
44
45/*----------------------------------------------------------------------------*/
46/*
47 * handle sroms on ELPPC
48 * fix ether address
49 * set serial console as default
50 */
51int misc_init_r (void)
52{
wdenke65527f2004-02-12 00:47:09 +000053 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 };
wdenke69b4b82002-09-17 21:26:59 +000060
wdenke65527f2004-02-12 00:47:09 +000061 /* Clock setting for MPC107 i2c */
62 mpc107_i2c_init (MPC107_EUMB_ADDR, 0x2b);
wdenke69b4b82002-09-17 21:26:59 +000063
wdenke65527f2004-02-12 00:47:09 +000064 /* 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 */
wdenke69b4b82002-09-17 21:26:59 +000069
wdenke65527f2004-02-12 00:47:09 +000070 /*
71 * Check/Remake revision info
72 */
73 initSrom = 0;
74 copyNv = 0;
wdenke69b4b82002-09-17 21:26:59 +000075
wdenke65527f2004-02-12 00:47:09 +000076 /* read out current revision srom contens */
77 mpc107_srom_load (0x0000, (u_char *) & eerev, sizeof (revinfo),
78 SECOND_DEVICE, FIRST_BLOCK);
wdenke69b4b82002-09-17 21:26:59 +000079
wdenke65527f2004-02-12 00:47:09 +000080 /* read out current nvram shadow image */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020081 nvram_read (buf, CONFIG_SYS_NV_SROM_COPY_ADDR, CONFIG_SYS_SROM_SIZE);
wdenke69b4b82002-09-17 21:26:59 +000082
wdenke65527f2004-02-12 00:47:09 +000083 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;
wdenke69b4b82002-09-17 21:26:59 +000093
wdenke65527f2004-02-12 00:47:09 +000094 /* 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;
wdenke69b4b82002-09-17 21:26:59 +0000101
wdenke65527f2004-02-12 00:47:09 +0000102 /* cache config word for ELPPC */
Anatolij Gustschinf8e4ba52011-12-20 07:51:09 +0000103 memset(&eerev.res[0], 0, 4);
wdenke69b4b82002-09-17 21:26:59 +0000104
wdenke65527f2004-02-12 00:47:09 +0000105 initSrom = 1; /* force dialog */
106 copyNv = 1; /* copy to nvram */
wdenk57b2d802003-06-27 21:31:46 +0000107 }
wdenke69b4b82002-09-17 21:26:59 +0000108
wdenke65527f2004-02-12 00:47:09 +0000109 if ((copyNv == 0)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200110 && (el_srom_checksum ((u_char *) & eerev, CONFIG_SYS_SROM_SIZE) !=
111 el_srom_checksum ((u_char *) buf, CONFIG_SYS_SROM_SIZE))) {
wdenke65527f2004-02-12 00:47:09 +0000112 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 }
wdenk57b2d802003-06-27 21:31:46 +0000127 }
wdenke69b4b82002-09-17 21:26:59 +0000128
wdenke65527f2004-02-12 00:47:09 +0000129 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 }
wdenke69b4b82002-09-17 21:26:59 +0000138
wdenke65527f2004-02-12 00:47:09 +0000139 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 }
wdenke69b4b82002-09-17 21:26:59 +0000145
wdenke65527f2004-02-12 00:47:09 +0000146 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 }
wdenke69b4b82002-09-17 21:26:59 +0000154
wdenke65527f2004-02-12 00:47:09 +0000155 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 }
wdenke69b4b82002-09-17 21:26:59 +0000161
wdenke65527f2004-02-12 00:47:09 +0000162 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 }
wdenke69b4b82002-09-17 21:26:59 +0000174
wdenke65527f2004-02-12 00:47:09 +0000175 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 }
wdenke69b4b82002-09-17 21:26:59 +0000183
wdenke65527f2004-02-12 00:47:09 +0000184 /* prepare network eeprom */
185 memset (buf, 0, 128);
wdenke69b4b82002-09-17 21:26:59 +0000186
wdenke65527f2004-02-12 00:47:09 +0000187 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];
wdenke69b4b82002-09-17 21:26:59 +0000193
Wolfgang Denk7323ec82013-06-14 10:20:44 +0200194 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;
wdenke69b4b82002-09-17 21:26:59 +0000202
wdenke65527f2004-02-12 00:47:09 +0000203 printf ("\nSRom: Writing i82559 info ........ ");
204 if (eepro100_srom_store ((unsigned short *) buf) == -1)
205 printf ("FAILED\n");
206 else
207 printf ("OK\n");
wdenke69b4b82002-09-17 21:26:59 +0000208
wdenke65527f2004-02-12 00:47:09 +0000209 /* update CRC */
210 eerev.crc =
211 el_srom_checksum ((u_char *) eerev.board, eerev.size);
wdenke69b4b82002-09-17 21:26:59 +0000212
wdenke65527f2004-02-12 00:47:09 +0000213 /* 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");
wdenke69b4b82002-09-17 21:26:59 +0000221
wdenke65527f2004-02-12 00:47:09 +0000222 /* write new values as shadow image to nvram */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200223 nvram_write (CONFIG_SYS_NV_SROM_COPY_ADDR, (void *) &eerev,
224 CONFIG_SYS_SROM_SIZE);
wdenke69b4b82002-09-17 21:26:59 +0000225
wdenke65527f2004-02-12 00:47:09 +0000226 }
227
228 /*if (initSrom) */
229 /* copy current values as shadow image to nvram */
230 if (initSrom == 0 && copyNv == 1)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200231 nvram_write (CONFIG_SYS_NV_SROM_COPY_ADDR, (void *) &eerev,
232 CONFIG_SYS_SROM_SIZE);
wdenke69b4b82002-09-17 21:26:59 +0000233
wdenke65527f2004-02-12 00:47:09 +0000234 /* 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);
wdenke69b4b82002-09-17 21:26:59 +0000240
wdenke65527f2004-02-12 00:47:09 +0000241 /* 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]);
wdenke69b4b82002-09-17 21:26:59 +0000245
wdenke65527f2004-02-12 00:47:09 +0000246 return (0);
wdenke69b4b82002-09-17 21:26:59 +0000247}
248
249/*----------------------------------------------------------------------------*/