blob: 2acf80047fe0f98b197a9eb9b36fe46b4a0fd718 [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>
Simon Glassdec3c012014-04-10 20:01:25 -060010#include <cli.h>
wdenke69b4b82002-09-17 21:26:59 +000011#include <linux/ctype.h>
12#include <pci.h>
13#include <net.h>
14#include "srom.h"
15
16/* imports */
wdenke69b4b82002-09-17 21:26:59 +000017extern int l2_cache_enable (int l2control);
wdenke65527f2004-02-12 00:47:09 +000018extern int eepro100_write_eeprom (struct eth_device *dev, int location,
19 int addr_len, unsigned short data);
20extern int read_eeprom (struct eth_device *dev, int location, int addr_len);
wdenke69b4b82002-09-17 21:26:59 +000021
22/*----------------------------------------------------------------------------*/
23/*
24 * read/write to nvram is only byte access
25 */
wdenke65527f2004-02-12 00:47:09 +000026void *nvram_read (void *dest, const long src, size_t count)
wdenke69b4b82002-09-17 21:26:59 +000027{
wdenke65527f2004-02-12 00:47:09 +000028 uchar *d = (uchar *) dest;
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +020029 uchar *s = (uchar *) (CONFIG_ENV_MAP_ADRS + src);
wdenke69b4b82002-09-17 21:26:59 +000030
wdenke65527f2004-02-12 00:47:09 +000031 while (count--)
32 *d++ = *s++;
wdenke69b4b82002-09-17 21:26:59 +000033
wdenke65527f2004-02-12 00:47:09 +000034 return dest;
wdenke69b4b82002-09-17 21:26:59 +000035}
36
wdenke65527f2004-02-12 00:47:09 +000037void nvram_write (long dest, const void *src, size_t count)
wdenke69b4b82002-09-17 21:26:59 +000038{
Jean-Christophe PLAGNIOL-VILLARD7e1cda62008-09-10 22:48:06 +020039 uchar *d = (uchar *) (CONFIG_ENV_MAP_ADRS + dest);
wdenke65527f2004-02-12 00:47:09 +000040 uchar *s = (uchar *) src;
wdenke69b4b82002-09-17 21:26:59 +000041
wdenke65527f2004-02-12 00:47:09 +000042 while (count--)
43 *d++ = *s++;
wdenke69b4b82002-09-17 21:26:59 +000044}
45
46/*----------------------------------------------------------------------------*/
47/*
48 * handle sroms on ELPPC
49 * fix ether address
50 * set serial console as default
51 */
52int misc_init_r (void)
53{
wdenke65527f2004-02-12 00:47:09 +000054 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 };
wdenke69b4b82002-09-17 21:26:59 +000061
wdenke65527f2004-02-12 00:47:09 +000062 /* Clock setting for MPC107 i2c */
63 mpc107_i2c_init (MPC107_EUMB_ADDR, 0x2b);
wdenke69b4b82002-09-17 21:26:59 +000064
wdenke65527f2004-02-12 00:47:09 +000065 /* 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 */
wdenke69b4b82002-09-17 21:26:59 +000070
wdenke65527f2004-02-12 00:47:09 +000071 /*
72 * Check/Remake revision info
73 */
74 initSrom = 0;
75 copyNv = 0;
wdenke69b4b82002-09-17 21:26:59 +000076
wdenke65527f2004-02-12 00:47:09 +000077 /* read out current revision srom contens */
78 mpc107_srom_load (0x0000, (u_char *) & eerev, sizeof (revinfo),
79 SECOND_DEVICE, FIRST_BLOCK);
wdenke69b4b82002-09-17 21:26:59 +000080
wdenke65527f2004-02-12 00:47:09 +000081 /* read out current nvram shadow image */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020082 nvram_read (buf, CONFIG_SYS_NV_SROM_COPY_ADDR, CONFIG_SYS_SROM_SIZE);
wdenke69b4b82002-09-17 21:26:59 +000083
wdenke65527f2004-02-12 00:47:09 +000084 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;
wdenke69b4b82002-09-17 21:26:59 +000094
wdenke65527f2004-02-12 00:47:09 +000095 /* 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;
wdenke69b4b82002-09-17 21:26:59 +0000102
wdenke65527f2004-02-12 00:47:09 +0000103 /* cache config word for ELPPC */
Anatolij Gustschinf8e4ba52011-12-20 07:51:09 +0000104 memset(&eerev.res[0], 0, 4);
wdenke69b4b82002-09-17 21:26:59 +0000105
wdenke65527f2004-02-12 00:47:09 +0000106 initSrom = 1; /* force dialog */
107 copyNv = 1; /* copy to nvram */
wdenk57b2d802003-06-27 21:31:46 +0000108 }
wdenke69b4b82002-09-17 21:26:59 +0000109
wdenke65527f2004-02-12 00:47:09 +0000110 if ((copyNv == 0)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200111 && (el_srom_checksum ((u_char *) & eerev, CONFIG_SYS_SROM_SIZE) !=
112 el_srom_checksum ((u_char *) buf, CONFIG_SYS_SROM_SIZE))) {
wdenke65527f2004-02-12 00:47:09 +0000113 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 Glassbe6aafc2014-04-10 20:01:27 -0600117 if (0 != cli_readline(NULL)) {
wdenke65527f2004-02-12 00:47:09 +0000118 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 }
wdenk57b2d802003-06-27 21:31:46 +0000128 }
wdenke69b4b82002-09-17 21:26:59 +0000129
wdenke65527f2004-02-12 00:47:09 +0000130 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 Glassbe6aafc2014-04-10 20:01:27 -0600134 if (0 != cli_readline(NULL)) {
wdenke65527f2004-02-12 00:47:09 +0000135 eerev.revision[0][0] =
136 (char) toupper (console_buffer[0]);
137 memcpy (&eerev.revision[1][0], buf, 12); /* shift rest of rev info */
138 }
wdenke69b4b82002-09-17 21:26:59 +0000139
wdenke65527f2004-02-12 00:47:09 +0000140 printf ("Enter revision character (A-Z): %c ",
141 eerev.revision[0][1]);
Simon Glassbe6aafc2014-04-10 20:01:27 -0600142 if (1 == cli_readline(NULL)) {
wdenke65527f2004-02-12 00:47:09 +0000143 eerev.revision[0][1] =
144 (char) toupper (console_buffer[0]);
145 }
wdenke69b4b82002-09-17 21:26:59 +0000146
wdenke65527f2004-02-12 00:47:09 +0000147 printf ("Enter board name (V-XXXX-XXXX): %s ",
148 (char *) &eerev.board);
Simon Glassbe6aafc2014-04-10 20:01:27 -0600149 if (11 == cli_readline(NULL)) {
wdenke65527f2004-02-12 00:47:09 +0000150 for (i = 0; i < 11; i++)
151 eerev.board[i] =
152 (char) toupper (console_buffer[i]);
153 eerev.board[11] = '\0';
154 }
wdenke69b4b82002-09-17 21:26:59 +0000155
wdenke65527f2004-02-12 00:47:09 +0000156 printf ("Enter serial number: %s ", (char *) &eerev.serial);
Simon Glassbe6aafc2014-04-10 20:01:27 -0600157 if (6 == cli_readline(NULL)) {
wdenke65527f2004-02-12 00:47:09 +0000158 for (i = 0; i < 6; i++)
159 eerev.serial[i] = console_buffer[i];
160 eerev.serial[6] = '\0';
161 }
wdenke69b4b82002-09-17 21:26:59 +0000162
wdenke65527f2004-02-12 00:47:09 +0000163 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 Glassbe6aafc2014-04-10 20:01:27 -0600164 if (12 == cli_readline(NULL)) {
wdenke65527f2004-02-12 00:47:09 +0000165 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 }
wdenke69b4b82002-09-17 21:26:59 +0000175
wdenke65527f2004-02-12 00:47:09 +0000176 l = strlen ((char *) &eerev.text);
177 printf ("Add to text section (max 64 chr): %s ",
178 (char *) &eerev.text);
Simon Glassbe6aafc2014-04-10 20:01:27 -0600179 if (0 != cli_readline(NULL)) {
wdenke65527f2004-02-12 00:47:09 +0000180 for (i = l; i < 63; i++)
181 eerev.text[i] = console_buffer[i - l];
182 eerev.text[63] = '\0';
183 }
wdenke69b4b82002-09-17 21:26:59 +0000184
wdenke65527f2004-02-12 00:47:09 +0000185 /* prepare network eeprom */
186 memset (buf, 0, 128);
wdenke69b4b82002-09-17 21:26:59 +0000187
wdenke65527f2004-02-12 00:47:09 +0000188 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];
wdenke69b4b82002-09-17 21:26:59 +0000194
Wolfgang Denk7323ec82013-06-14 10:20:44 +0200195 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;
wdenke69b4b82002-09-17 21:26:59 +0000203
wdenke65527f2004-02-12 00:47:09 +0000204 printf ("\nSRom: Writing i82559 info ........ ");
205 if (eepro100_srom_store ((unsigned short *) buf) == -1)
206 printf ("FAILED\n");
207 else
208 printf ("OK\n");
wdenke69b4b82002-09-17 21:26:59 +0000209
wdenke65527f2004-02-12 00:47:09 +0000210 /* update CRC */
211 eerev.crc =
212 el_srom_checksum ((u_char *) eerev.board, eerev.size);
wdenke69b4b82002-09-17 21:26:59 +0000213
wdenke65527f2004-02-12 00:47:09 +0000214 /* 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");
wdenke69b4b82002-09-17 21:26:59 +0000222
wdenke65527f2004-02-12 00:47:09 +0000223 /* write new values as shadow image to nvram */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200224 nvram_write (CONFIG_SYS_NV_SROM_COPY_ADDR, (void *) &eerev,
225 CONFIG_SYS_SROM_SIZE);
wdenke69b4b82002-09-17 21:26:59 +0000226
wdenke65527f2004-02-12 00:47:09 +0000227 }
228
229 /*if (initSrom) */
230 /* copy current values as shadow image to nvram */
231 if (initSrom == 0 && copyNv == 1)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200232 nvram_write (CONFIG_SYS_NV_SROM_COPY_ADDR, (void *) &eerev,
233 CONFIG_SYS_SROM_SIZE);
wdenke69b4b82002-09-17 21:26:59 +0000234
wdenke65527f2004-02-12 00:47:09 +0000235 /* 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);
wdenke69b4b82002-09-17 21:26:59 +0000241
wdenke65527f2004-02-12 00:47:09 +0000242 /* 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]);
wdenke69b4b82002-09-17 21:26:59 +0000246
wdenke65527f2004-02-12 00:47:09 +0000247 return (0);
wdenke69b4b82002-09-17 21:26:59 +0000248}
249
250/*----------------------------------------------------------------------------*/