]> git.ipfire.org Git - people/ms/u-boot.git/blob - board/eltec/elppc/misc.c
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.git] / board / eltec / elppc / misc.c
1 /*
2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
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 */
16 extern int l2_cache_enable (int l2control);
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);
20
21 /*----------------------------------------------------------------------------*/
22 /*
23 * read/write to nvram is only byte access
24 */
25 void *nvram_read (void *dest, const long src, size_t count)
26 {
27 uchar *d = (uchar *) dest;
28 uchar *s = (uchar *) (CONFIG_ENV_MAP_ADRS + src);
29
30 while (count--)
31 *d++ = *s++;
32
33 return dest;
34 }
35
36 void nvram_write (long dest, const void *src, size_t count)
37 {
38 uchar *d = (uchar *) (CONFIG_ENV_MAP_ADRS + dest);
39 uchar *s = (uchar *) src;
40
41 while (count--)
42 *d++ = *s++;
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 {
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 };
60
61 /* Clock setting for MPC107 i2c */
62 mpc107_i2c_init (MPC107_EUMB_ADDR, 0x2b);
63
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 */
69
70 /*
71 * Check/Remake revision info
72 */
73 initSrom = 0;
74 copyNv = 0;
75
76 /* read out current revision srom contens */
77 mpc107_srom_load (0x0000, (u_char *) & eerev, sizeof (revinfo),
78 SECOND_DEVICE, FIRST_BLOCK);
79
80 /* read out current nvram shadow image */
81 nvram_read (buf, CONFIG_SYS_NV_SROM_COPY_ADDR, CONFIG_SYS_SROM_SIZE);
82
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;
93
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;
101
102 /* cache config word for ELPPC */
103 memset(&eerev.res[0], 0, 4);
104
105 initSrom = 1; /* force dialog */
106 copyNv = 1; /* copy to nvram */
107 }
108
109 if ((copyNv == 0)
110 && (el_srom_checksum ((u_char *) & eerev, CONFIG_SYS_SROM_SIZE) !=
111 el_srom_checksum ((u_char *) buf, CONFIG_SYS_SROM_SIZE))) {
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 }
127 }
128
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
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;
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 */
223 nvram_write (CONFIG_SYS_NV_SROM_COPY_ADDR, (void *) &eerev,
224 CONFIG_SYS_SROM_SIZE);
225
226 }
227
228 /*if (initSrom) */
229 /* copy current values as shadow image to nvram */
230 if (initSrom == 0 && copyNv == 1)
231 nvram_write (CONFIG_SYS_NV_SROM_COPY_ADDR, (void *) &eerev,
232 CONFIG_SYS_SROM_SIZE);
233
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);
240
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]);
245
246 return (0);
247 }
248
249 /*----------------------------------------------------------------------------*/