fix remaining pci problems with brcm-2.6 (fixes #132)
[openwrt.git] / target / linux / linux-2.6 / patches / brcm / 001-bcm947xx.patch
1 diff -urN linux.old/arch/mips/Kconfig linux.dev/arch/mips/Kconfig
2 --- linux.old/arch/mips/Kconfig 2005-12-15 13:26:49.758027500 +0100
3 +++ linux.dev/arch/mips/Kconfig 2005-12-15 12:57:27.889182500 +0100
4 @@ -244,6 +244,17 @@
5 Members include the Acer PICA, MIPS Magnum 4000, MIPS Millenium and
6 Olivetti M700-10 workstations.
7
8 +config BCM947XX
9 + bool "Support for BCM947xx based boards"
10 + select DMA_NONCOHERENT
11 + select HW_HAS_PCI
12 + select IRQ_CPU
13 + select SYS_HAS_CPU_MIPS32_R1
14 + select SYS_SUPPORTS_32BIT_KERNEL
15 + select SYS_SUPPORTS_LITTLE_ENDIAN
16 + help
17 + Support for BCM947xx based boards
18 +
19 config LASAT
20 bool "Support for LASAT Networks platforms"
21 select DMA_NONCOHERENT
22 diff -urN linux.old/arch/mips/Makefile linux.dev/arch/mips/Makefile
23 --- linux.old/arch/mips/Makefile 2005-12-15 13:26:49.766024000 +0100
24 +++ linux.dev/arch/mips/Makefile 2005-12-15 12:57:27.921168500 +0100
25 @@ -689,6 +689,13 @@
26 load-$(CONFIG_SIBYTE_BIGSUR) := 0xffffffff80100000
27
28 #
29 +# Broadcom BCM47XX boards
30 +#
31 +core-$(CONFIG_BCM947XX) += arch/mips/bcm947xx/ arch/mips/bcm947xx/broadcom/
32 +cflags-$(CONFIG_BCM947XX) += -Iarch/mips/bcm947xx/include
33 +load-$(CONFIG_BCM947XX) := 0xffffffff80001000
34 +
35 +#
36 # SNI RM200 PCI
37 #
38 core-$(CONFIG_SNI_RM200_PCI) += arch/mips/sni/
39 diff -urN linux.old/arch/mips/bcm947xx/Makefile linux.dev/arch/mips/bcm947xx/Makefile
40 --- linux.old/arch/mips/bcm947xx/Makefile 1970-01-01 01:00:00.000000000 +0100
41 +++ linux.dev/arch/mips/bcm947xx/Makefile 2005-12-15 14:32:03.580639500 +0100
42 @@ -0,0 +1,6 @@
43 +#
44 +# Makefile for the BCM47xx specific kernel interface routines
45 +# under Linux.
46 +#
47 +
48 +obj-y := irq.o int-handler.o prom.o setup.o time.o pci.o
49 diff -urN linux.old/arch/mips/bcm947xx/broadcom/Makefile linux.dev/arch/mips/bcm947xx/broadcom/Makefile
50 --- linux.old/arch/mips/bcm947xx/broadcom/Makefile 1970-01-01 01:00:00.000000000 +0100
51 +++ linux.dev/arch/mips/bcm947xx/broadcom/Makefile 2005-12-15 16:59:40.571216500 +0100
52 @@ -0,0 +1,6 @@
53 +#
54 +# Makefile for the BCM47xx specific kernel interface routines
55 +# under Linux.
56 +#
57 +
58 +obj-y := sbutils.o linux_osl.o bcmsrom.o bcmutils.o sbmips.o sbpci.o sflash.o nvram.o
59 diff -urN linux.old/arch/mips/bcm947xx/broadcom/bcmsrom.c linux.dev/arch/mips/bcm947xx/broadcom/bcmsrom.c
60 --- linux.old/arch/mips/bcm947xx/broadcom/bcmsrom.c 1970-01-01 01:00:00.000000000 +0100
61 +++ linux.dev/arch/mips/bcm947xx/broadcom/bcmsrom.c 2005-12-15 17:35:21.719238750 +0100
62 @@ -0,0 +1,483 @@
63 +/*
64 + * Misc useful routines to access NIC SROM/OTP .
65 + *
66 + * Copyright 2005, Broadcom Corporation
67 + * All Rights Reserved.
68 + *
69 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
70 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
71 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
72 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
73 + * $Id$
74 + */
75 +
76 +#include <typedefs.h>
77 +#include <osl.h>
78 +#include <bcmutils.h>
79 +#include <bcmsrom.h>
80 +#include <bcmdevs.h>
81 +#include <bcmendian.h>
82 +#include <pcicfg.h>
83 +#include <sbutils.h>
84 +
85 +#include <proto/ethernet.h> /* for sprom content groking */
86 +
87 +#define VARS_MAX 4096 /* should be reduced */
88 +
89 +#define WRITE_ENABLE_DELAY 500 /* 500 ms after write enable/disable toggle */
90 +#define WRITE_WORD_DELAY 20 /* 20 ms between each word write */
91 +
92 +static int initvars_srom_pci(void *sbh, void *curmap, char **vars, int *count);
93 +static int sprom_read_pci(uint16 *sprom, uint wordoff, uint16 *buf, uint nwords, bool check_crc);
94 +
95 +static int initvars_table(osl_t *osh, char *start, char *end, char **vars, uint *count);
96 +
97 +/*
98 + * Initialize local vars from the right source for this platform.
99 + * Return 0 on success, nonzero on error.
100 + */
101 +int
102 +srom_var_init(void *sbh, uint bustype, void *curmap, osl_t *osh, char **vars, int *count)
103 +{
104 + ASSERT(bustype == BUSTYPE(bustype));
105 + if (vars == NULL || count == NULL)
106 + return (0);
107 +
108 + switch (BUSTYPE(bustype)) {
109 +
110 + case PCI_BUS:
111 + ASSERT(curmap); /* can not be NULL */
112 + return initvars_srom_pci(sbh, curmap, vars, count);
113 +
114 + default:
115 + return 0;
116 + }
117 + return (-1);
118 +}
119 +
120 +/* support only 16-bit word read from srom */
121 +int
122 +srom_read(uint bustype, void *curmap, osl_t *osh, uint byteoff, uint nbytes, uint16 *buf)
123 +{
124 + void *srom;
125 + uint off, nw;
126 +
127 + ASSERT(bustype == BUSTYPE(bustype));
128 +
129 + /* check input - 16-bit access only */
130 + if (byteoff & 1 || nbytes & 1 || (byteoff + nbytes) > (SPROM_SIZE * 2))
131 + return 1;
132 +
133 + off = byteoff / 2;
134 + nw = nbytes / 2;
135 +
136 + if (BUSTYPE(bustype) == PCI_BUS) {
137 + if (!curmap)
138 + return 1;
139 + srom = (uchar*)curmap + PCI_BAR0_SPROM_OFFSET;
140 + if (sprom_read_pci(srom, off, buf, nw, FALSE))
141 + return 1;
142 + } else {
143 + return 1;
144 + }
145 +
146 + return 0;
147 +}
148 +
149 +/* support only 16-bit word write into srom */
150 +int
151 +srom_write(uint bustype, void *curmap, osl_t *osh, uint byteoff, uint nbytes, uint16 *buf)
152 +{
153 + uint16 *srom;
154 + uint i, off, nw, crc_range;
155 + uint16 image[SPROM_SIZE], *p;
156 + uint8 crc;
157 + volatile uint32 val32;
158 +
159 + ASSERT(bustype == BUSTYPE(bustype));
160 +
161 + /* check input - 16-bit access only */
162 + if (byteoff & 1 || nbytes & 1 || (byteoff + nbytes) > (SPROM_SIZE * 2))
163 + return 1;
164 +
165 + crc_range = (((BUSTYPE(bustype) == SDIO_BUS)) ? SPROM_SIZE : SPROM_CRC_RANGE) * 2;
166 +
167 + /* if changes made inside crc cover range */
168 + if (byteoff < crc_range) {
169 + nw = (((byteoff + nbytes) > crc_range) ? byteoff + nbytes : crc_range) / 2;
170 + /* read data including entire first 64 words from srom */
171 + if (srom_read(bustype, curmap, osh, 0, nw * 2, image))
172 + return 1;
173 + /* make changes */
174 + bcopy((void*)buf, (void*)&image[byteoff / 2], nbytes);
175 + /* calculate crc */
176 + htol16_buf(image, crc_range);
177 + crc = ~hndcrc8((uint8 *)image, crc_range - 1, CRC8_INIT_VALUE);
178 + ltoh16_buf(image, crc_range);
179 + image[(crc_range / 2) - 1] = (crc << 8) | (image[(crc_range / 2) - 1] & 0xff);
180 + p = image;
181 + off = 0;
182 + } else {
183 + p = buf;
184 + off = byteoff / 2;
185 + nw = nbytes / 2;
186 + }
187 +
188 + if (BUSTYPE(bustype) == PCI_BUS) {
189 + srom = (uint16*)((uchar*)curmap + PCI_BAR0_SPROM_OFFSET);
190 + /* enable writes to the SPROM */
191 + val32 = OSL_PCI_READ_CONFIG(osh, PCI_SPROM_CONTROL, sizeof(uint32));
192 + val32 |= SPROM_WRITEEN;
193 + OSL_PCI_WRITE_CONFIG(osh, PCI_SPROM_CONTROL, sizeof(uint32), val32);
194 + bcm_mdelay(WRITE_ENABLE_DELAY);
195 + /* write srom */
196 + for (i = 0; i < nw; i++) {
197 + W_REG(&srom[off + i], p[i]);
198 + bcm_mdelay(WRITE_WORD_DELAY);
199 + }
200 + /* disable writes to the SPROM */
201 + OSL_PCI_WRITE_CONFIG(osh, PCI_SPROM_CONTROL, sizeof(uint32), val32 & ~SPROM_WRITEEN);
202 + } else {
203 + return 1;
204 + }
205 +
206 + bcm_mdelay(WRITE_ENABLE_DELAY);
207 + return 0;
208 +}
209 +
210 +
211 +/*
212 + * Read in and validate sprom.
213 + * Return 0 on success, nonzero on error.
214 + */
215 +static int
216 +sprom_read_pci(uint16 *sprom, uint wordoff, uint16 *buf, uint nwords, bool check_crc)
217 +{
218 + int err = 0;
219 + uint i;
220 +
221 + /* read the sprom */
222 + for (i = 0; i < nwords; i++)
223 + buf[i] = R_REG(&sprom[wordoff + i]);
224 +
225 + if (check_crc) {
226 + /* fixup the endianness so crc8 will pass */
227 + htol16_buf(buf, nwords * 2);
228 + if (hndcrc8((uint8*)buf, nwords * 2, CRC8_INIT_VALUE) != CRC8_GOOD_VALUE)
229 + err = 1;
230 + /* now correct the endianness of the byte array */
231 + ltoh16_buf(buf, nwords * 2);
232 + }
233 +
234 + return err;
235 +}
236 +
237 +/*
238 +* Create variable table from memory.
239 +* Return 0 on success, nonzero on error.
240 +*/
241 +static int
242 +initvars_table(osl_t *osh, char *start, char *end, char **vars, uint *count)
243 +{
244 + int c = (int)(end - start);
245 +
246 + /* do it only when there is more than just the null string */
247 + if (c > 1) {
248 + char *vp = MALLOC(osh, c);
249 + ASSERT(vp);
250 + if (!vp)
251 + return BCME_NOMEM;
252 + bcopy(start, vp, c);
253 + *vars = vp;
254 + *count = c;
255 + }
256 + else {
257 + *vars = NULL;
258 + *count = 0;
259 + }
260 +
261 + return 0;
262 +}
263 +
264 +/*
265 + * Initialize nonvolatile variable table from sprom.
266 + * Return 0 on success, nonzero on error.
267 + */
268 +static int
269 +initvars_srom_pci(void *sbh, void *curmap, char **vars, int *count)
270 +{
271 + uint16 w, b[64];
272 + uint8 sromrev;
273 + struct ether_addr ea;
274 + char eabuf[32];
275 + uint32 w32;
276 + int woff, i;
277 + char *vp, *base;
278 + osl_t *osh = sb_osh(sbh);
279 + char name[SB_DEVPATH_BUFSZ+16], *value;
280 + char devpath[SB_DEVPATH_BUFSZ];
281 + int err;
282 +
283 + /*
284 + * Apply CRC over SROM content regardless SROM is present or not,
285 + * and use variable <devpath>sromrev's existance in flash to decide
286 + * if we should return an error when CRC fails or read SROM variables
287 + * from flash.
288 + */
289 + sprom_read_pci((void*)((int8*)curmap + PCI_BAR0_SPROM_OFFSET), 0, b, sizeof(b)/sizeof(b[0]), TRUE);
290 +
291 + /* top word of sprom contains version and crc8 */
292 + sromrev = b[63] & 0xff;
293 + /* bcm4401 sroms misprogrammed */
294 + if (sromrev == 0x10)
295 + sromrev = 1;
296 +
297 + /* srom version check */
298 + if (sromrev > 3)
299 + return (-2);
300 +
301 + ASSERT(vars);
302 + ASSERT(count);
303 +
304 + base = vp = MALLOC(osh, VARS_MAX);
305 + ASSERT(vp);
306 + if (!vp)
307 + return -2;
308 +
309 + vp += sprintf(vp, "sromrev=%d", sromrev);
310 + vp++;
311 +
312 + if (sromrev >= 3) {
313 + /* New section takes over the 3th hardware function space */
314 +
315 + /* Words 22+23 are 11a (mid) ofdm power offsets */
316 + w32 = ((uint32)b[23] << 16) | b[22];
317 + vp += sprintf(vp, "ofdmapo=%d", w32);
318 + vp++;
319 +
320 + /* Words 24+25 are 11a (low) ofdm power offsets */
321 + w32 = ((uint32)b[25] << 16) | b[24];
322 + vp += sprintf(vp, "ofdmalpo=%d", w32);
323 + vp++;
324 +
325 + /* Words 26+27 are 11a (high) ofdm power offsets */
326 + w32 = ((uint32)b[27] << 16) | b[26];
327 + vp += sprintf(vp, "ofdmahpo=%d", w32);
328 + vp++;
329 +
330 + /*GPIO LED Powersave duty cycle (oncount >> 24) (offcount >> 8)*/
331 + w32 = ((uint32)b[43] << 24) | ((uint32)b[42] << 8);
332 + vp += sprintf(vp, "gpiotimerval=%d", w32);
333 +
334 + /*GPIO LED Powersave duty cycle (oncount >> 24) (offcount >> 8)*/
335 + w32 = ((uint32)((unsigned char)(b[21] >> 8) & 0xFF) << 24) | /* oncount*/
336 + ((uint32)((unsigned char)(b[21] & 0xFF)) << 8); /* offcount */
337 + vp += sprintf(vp, "gpiotimerval=%d", w32);
338 +
339 + vp++;
340 + }
341 +
342 + if (sromrev >= 2) {
343 + /* New section takes over the 4th hardware function space */
344 +
345 + /* Word 29 is max power 11a high/low */
346 + w = b[29];
347 + vp += sprintf(vp, "pa1himaxpwr=%d", w & 0xff);
348 + vp++;
349 + vp += sprintf(vp, "pa1lomaxpwr=%d", (w >> 8) & 0xff);
350 + vp++;
351 +
352 + /* Words 30-32 set the 11alow pa settings,
353 + * 33-35 are the 11ahigh ones.
354 + */
355 + for (i = 0; i < 3; i++) {
356 + vp += sprintf(vp, "pa1lob%d=%d", i, b[30 + i]);
357 + vp++;
358 + vp += sprintf(vp, "pa1hib%d=%d", i, b[33 + i]);
359 + vp++;
360 + }
361 + w = b[59];
362 + if (w == 0)
363 + vp += sprintf(vp, "ccode=");
364 + else
365 + vp += sprintf(vp, "ccode=%c%c", (w >> 8), (w & 0xff));
366 + vp++;
367 +
368 + }
369 +
370 + /* parameter section of sprom starts at byte offset 72 */
371 + woff = 72/2;
372 +
373 + /* first 6 bytes are il0macaddr */
374 + ea.octet[0] = (b[woff] >> 8) & 0xff;
375 + ea.octet[1] = b[woff] & 0xff;
376 + ea.octet[2] = (b[woff+1] >> 8) & 0xff;
377 + ea.octet[3] = b[woff+1] & 0xff;
378 + ea.octet[4] = (b[woff+2] >> 8) & 0xff;
379 + ea.octet[5] = b[woff+2] & 0xff;
380 + woff += ETHER_ADDR_LEN/2 ;
381 + bcm_ether_ntoa((uchar*)&ea, eabuf);
382 + vp += sprintf(vp, "il0macaddr=%s", eabuf);
383 + vp++;
384 +
385 + /* next 6 bytes are et0macaddr */
386 + ea.octet[0] = (b[woff] >> 8) & 0xff;
387 + ea.octet[1] = b[woff] & 0xff;
388 + ea.octet[2] = (b[woff+1] >> 8) & 0xff;
389 + ea.octet[3] = b[woff+1] & 0xff;
390 + ea.octet[4] = (b[woff+2] >> 8) & 0xff;
391 + ea.octet[5] = b[woff+2] & 0xff;
392 + woff += ETHER_ADDR_LEN/2 ;
393 + bcm_ether_ntoa((uchar*)&ea, eabuf);
394 + vp += sprintf(vp, "et0macaddr=%s", eabuf);
395 + vp++;
396 +
397 + /* next 6 bytes are et1macaddr */
398 + ea.octet[0] = (b[woff] >> 8) & 0xff;
399 + ea.octet[1] = b[woff] & 0xff;
400 + ea.octet[2] = (b[woff+1] >> 8) & 0xff;
401 + ea.octet[3] = b[woff+1] & 0xff;
402 + ea.octet[4] = (b[woff+2] >> 8) & 0xff;
403 + ea.octet[5] = b[woff+2] & 0xff;
404 + woff += ETHER_ADDR_LEN/2 ;
405 + bcm_ether_ntoa((uchar*)&ea, eabuf);
406 + vp += sprintf(vp, "et1macaddr=%s", eabuf);
407 + vp++;
408 +
409 + /*
410 + * Enet phy settings one or two singles or a dual
411 + * Bits 4-0 : MII address for enet0 (0x1f for not there)
412 + * Bits 9-5 : MII address for enet1 (0x1f for not there)
413 + * Bit 14 : Mdio for enet0
414 + * Bit 15 : Mdio for enet1
415 + */
416 + w = b[woff];
417 + vp += sprintf(vp, "et0phyaddr=%d", (w & 0x1f));
418 + vp++;
419 + vp += sprintf(vp, "et1phyaddr=%d", ((w >> 5) & 0x1f));
420 + vp++;
421 + vp += sprintf(vp, "et0mdcport=%d", ((w >> 14) & 0x1));
422 + vp++;
423 + vp += sprintf(vp, "et1mdcport=%d", ((w >> 15) & 0x1));
424 + vp++;
425 +
426 + /* Word 46 has board rev, antennas 0/1 & Country code/control */
427 + w = b[46];
428 + vp += sprintf(vp, "boardrev=%d", w & 0xff);
429 + vp++;
430 +
431 + if (sromrev > 1)
432 + vp += sprintf(vp, "cctl=%d", (w >> 8) & 0xf);
433 + else
434 + vp += sprintf(vp, "cc=%d", (w >> 8) & 0xf);
435 + vp++;
436 +
437 + vp += sprintf(vp, "aa0=%d", (w >> 12) & 0x3);
438 + vp++;
439 +
440 + vp += sprintf(vp, "aa1=%d", (w >> 14) & 0x3);
441 + vp++;
442 +
443 + /* Words 47-49 set the (wl) pa settings */
444 + woff = 47;
445 +
446 + for (i = 0; i < 3; i++) {
447 + vp += sprintf(vp, "pa0b%d=%d", i, b[woff+i]);
448 + vp++;
449 + vp += sprintf(vp, "pa1b%d=%d", i, b[woff+i+6]);
450 + vp++;
451 + }
452 +
453 + /*
454 + * Words 50-51 set the customer-configured wl led behavior.
455 + * 8 bits/gpio pin. High bit: activehi=0, activelo=1;
456 + * LED behavior values defined in wlioctl.h .
457 + */
458 + w = b[50];
459 + if ((w != 0) && (w != 0xffff)) {
460 + /* gpio0 */
461 + vp += sprintf(vp, "wl0gpio0=%d", (w & 0xff));
462 + vp++;
463 +
464 + /* gpio1 */
465 + vp += sprintf(vp, "wl0gpio1=%d", (w >> 8) & 0xff);
466 + vp++;
467 + }
468 + w = b[51];
469 + if ((w != 0) && (w != 0xffff)) {
470 + /* gpio2 */
471 + vp += sprintf(vp, "wl0gpio2=%d", w & 0xff);
472 + vp++;
473 +
474 + /* gpio3 */
475 + vp += sprintf(vp, "wl0gpio3=%d", (w >> 8) & 0xff);
476 + vp++;
477 + }
478 +
479 + /* Word 52 is max power 0/1 */
480 + w = b[52];
481 + vp += sprintf(vp, "pa0maxpwr=%d", w & 0xff);
482 + vp++;
483 + vp += sprintf(vp, "pa1maxpwr=%d", (w >> 8) & 0xff);
484 + vp++;
485 +
486 + /* Word 56 is idle tssi target 0/1 */
487 + w = b[56];
488 + vp += sprintf(vp, "pa0itssit=%d", w & 0xff);
489 + vp++;
490 + vp += sprintf(vp, "pa1itssit=%d", (w >> 8) & 0xff);
491 + vp++;
492 +
493 + /* Word 57 is boardflags, if not programmed make it zero */
494 + w32 = (uint32)b[57];
495 + if (w32 == 0xffff) w32 = 0;
496 + if (sromrev > 1) {
497 + /* Word 28 is the high bits of boardflags */
498 + w32 |= (uint32)b[28] << 16;
499 + }
500 + vp += sprintf(vp, "boardflags=%d", w32);
501 + vp++;
502 +
503 + /* Word 58 is antenna gain 0/1 */
504 + w = b[58];
505 + vp += sprintf(vp, "ag0=%d", w & 0xff);
506 + vp++;
507 +
508 + vp += sprintf(vp, "ag1=%d", (w >> 8) & 0xff);
509 + vp++;
510 +
511 + if (sromrev == 1) {
512 + /* set the oem string */
513 + vp += sprintf(vp, "oem=%02x%02x%02x%02x%02x%02x%02x%02x",
514 + ((b[59] >> 8) & 0xff), (b[59] & 0xff),
515 + ((b[60] >> 8) & 0xff), (b[60] & 0xff),
516 + ((b[61] >> 8) & 0xff), (b[61] & 0xff),
517 + ((b[62] >> 8) & 0xff), (b[62] & 0xff));
518 + vp++;
519 + } else if (sromrev == 2) {
520 + /* Word 60 OFDM tx power offset from CCK level */
521 + /* OFDM Power Offset - opo */
522 + vp += sprintf(vp, "opo=%d", b[60] & 0xff);
523 + vp++;
524 + } else {
525 + /* Word 60: cck power offsets */
526 + vp += sprintf(vp, "cckpo=%d", b[60]);
527 + vp++;
528 +
529 + /* Words 61+62: 11g ofdm power offsets */
530 + w32 = ((uint32)b[62] << 16) | b[61];
531 + vp += sprintf(vp, "ofdmgpo=%d", w32);
532 + vp++;
533 + }
534 +
535 + /* final nullbyte terminator */
536 + *vp++ = '\0';
537 +
538 + ASSERT((vp - base) <= VARS_MAX);
539 +
540 + err = initvars_table(osh, base, vp, vars, count);
541 +
542 + MFREE(osh, base, VARS_MAX);
543 + return err;
544 +}
545 +
546 diff -urN linux.old/arch/mips/bcm947xx/broadcom/bcmutils.c linux.dev/arch/mips/bcm947xx/broadcom/bcmutils.c
547 --- linux.old/arch/mips/bcm947xx/broadcom/bcmutils.c 1970-01-01 01:00:00.000000000 +0100
548 +++ linux.dev/arch/mips/bcm947xx/broadcom/bcmutils.c 2005-12-15 20:14:31.420035750 +0100
549 @@ -0,0 +1,358 @@
550 +/*
551 + * Misc useful OS-independent routines.
552 + *
553 + * Copyright 2005, Broadcom Corporation
554 + * All Rights Reserved.
555 + *
556 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
557 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
558 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
559 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
560 + * $Id$
561 + */
562 +
563 +#include <typedefs.h>
564 +#include <osl.h>
565 +#include <sbutils.h>
566 +#include <bcmnvram.h>
567 +#include <bcmutils.h>
568 +#include <bcmendian.h>
569 +#include <bcmdevs.h>
570 +
571 +unsigned char bcm_ctype[] = {
572 + _BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C, /* 0-7 */
573 + _BCM_C,_BCM_C|_BCM_S,_BCM_C|_BCM_S,_BCM_C|_BCM_S,_BCM_C|_BCM_S,_BCM_C|_BCM_S,_BCM_C,_BCM_C, /* 8-15 */
574 + _BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C, /* 16-23 */
575 + _BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C,_BCM_C, /* 24-31 */
576 + _BCM_S|_BCM_SP,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P, /* 32-39 */
577 + _BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P, /* 40-47 */
578 + _BCM_D,_BCM_D,_BCM_D,_BCM_D,_BCM_D,_BCM_D,_BCM_D,_BCM_D, /* 48-55 */
579 + _BCM_D,_BCM_D,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P, /* 56-63 */
580 + _BCM_P,_BCM_U|_BCM_X,_BCM_U|_BCM_X,_BCM_U|_BCM_X,_BCM_U|_BCM_X,_BCM_U|_BCM_X,_BCM_U|_BCM_X,_BCM_U, /* 64-71 */
581 + _BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U, /* 72-79 */
582 + _BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U, /* 80-87 */
583 + _BCM_U,_BCM_U,_BCM_U,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P, /* 88-95 */
584 + _BCM_P,_BCM_L|_BCM_X,_BCM_L|_BCM_X,_BCM_L|_BCM_X,_BCM_L|_BCM_X,_BCM_L|_BCM_X,_BCM_L|_BCM_X,_BCM_L, /* 96-103 */
585 + _BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L, /* 104-111 */
586 + _BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L, /* 112-119 */
587 + _BCM_L,_BCM_L,_BCM_L,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_C, /* 120-127 */
588 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */
589 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */
590 + _BCM_S|_BCM_SP,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P, /* 160-175 */
591 + _BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P,_BCM_P, /* 176-191 */
592 + _BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U, /* 192-207 */
593 + _BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_P,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_U,_BCM_L, /* 208-223 */
594 + _BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L, /* 224-239 */
595 + _BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_P,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L,_BCM_L /* 240-255 */
596 +};
597 +
598 +uchar
599 +bcm_toupper(uchar c)
600 +{
601 + if (bcm_islower(c))
602 + c -= 'a'-'A';
603 + return (c);
604 +}
605 +
606 +ulong
607 +bcm_strtoul(char *cp, char **endp, uint base)
608 +{
609 + ulong result, value;
610 + bool minus;
611 +
612 + minus = FALSE;
613 +
614 + while (bcm_isspace(*cp))
615 + cp++;
616 +
617 + if (cp[0] == '+')
618 + cp++;
619 + else if (cp[0] == '-') {
620 + minus = TRUE;
621 + cp++;
622 + }
623 +
624 + if (base == 0) {
625 + if (cp[0] == '0') {
626 + if ((cp[1] == 'x') || (cp[1] == 'X')) {
627 + base = 16;
628 + cp = &cp[2];
629 + } else {
630 + base = 8;
631 + cp = &cp[1];
632 + }
633 + } else
634 + base = 10;
635 + } else if (base == 16 && (cp[0] == '0') && ((cp[1] == 'x') || (cp[1] == 'X'))) {
636 + cp = &cp[2];
637 + }
638 +
639 + result = 0;
640 +
641 + while (bcm_isxdigit(*cp) &&
642 + (value = bcm_isdigit(*cp) ? *cp-'0' : bcm_toupper(*cp)-'A'+10) < base) {
643 + result = result*base + value;
644 + cp++;
645 + }
646 +
647 + if (minus)
648 + result = (ulong)(result * -1);
649 +
650 + if (endp)
651 + *endp = (char *)cp;
652 +
653 + return (result);
654 +}
655 +
656 +uint
657 +bcm_atoi(char *s)
658 +{
659 + uint n;
660 +
661 + n = 0;
662 +
663 + while (bcm_isdigit(*s))
664 + n = (n * 10) + *s++ - '0';
665 + return (n);
666 +}
667 +
668 +/* return pointer to location of substring 'needle' in 'haystack' */
669 +char*
670 +bcmstrstr(char *haystack, char *needle)
671 +{
672 + int len, nlen;
673 + int i;
674 +
675 + if ((haystack == NULL) || (needle == NULL))
676 + return (haystack);
677 +
678 + nlen = strlen(needle);
679 + len = strlen(haystack) - nlen + 1;
680 +
681 + for (i = 0; i < len; i++)
682 + if (bcmp(needle, &haystack[i], nlen) == 0)
683 + return (&haystack[i]);
684 + return (NULL);
685 +}
686 +
687 +char*
688 +bcmstrcat(char *dest, const char *src)
689 +{
690 + strcpy(&dest[strlen(dest)], src);
691 + return (dest);
692 +}
693 +
694 +
695 +char*
696 +bcm_ether_ntoa(char *ea, char *buf)
697 +{
698 + sprintf(buf,"%02x:%02x:%02x:%02x:%02x:%02x",
699 + (uchar)ea[0]&0xff, (uchar)ea[1]&0xff, (uchar)ea[2]&0xff,
700 + (uchar)ea[3]&0xff, (uchar)ea[4]&0xff, (uchar)ea[5]&0xff);
701 + return (buf);
702 +}
703 +
704 +/* parse a xx:xx:xx:xx:xx:xx format ethernet address */
705 +int
706 +bcm_ether_atoe(char *p, char *ea)
707 +{
708 + int i = 0;
709 +
710 + for (;;) {
711 + ea[i++] = (char) bcm_strtoul(p, &p, 16);
712 + if (!*p++ || i == 6)
713 + break;
714 + }
715 +
716 + return (i == 6);
717 +}
718 +
719 +void
720 +bcm_mdelay(uint ms)
721 +{
722 + uint i;
723 +
724 + for (i = 0; i < ms; i++) {
725 + OSL_DELAY(1000);
726 + }
727 +}
728 +
729 +/*
730 + * Search the name=value vars for a specific one and return its value.
731 + * Returns NULL if not found.
732 + */
733 +char*
734 +getvar(char *vars, char *name)
735 +{
736 + char *s;
737 + int len;
738 +
739 + len = strlen(name);
740 +
741 + /* first look in vars[] */
742 + for (s = vars; s && *s; ) {
743 + if ((bcmp(s, name, len) == 0) && (s[len] == '='))
744 + return (&s[len+1]);
745 +
746 + while (*s++)
747 + ;
748 + }
749 +
750 + /* then query nvram */
751 + return (BCMINIT(nvram_get)(name));
752 +}
753 +
754 +/*
755 + * Search the vars for a specific one and return its value as
756 + * an integer. Returns 0 if not found.
757 + */
758 +int
759 +getintvar(char *vars, char *name)
760 +{
761 + char *val;
762 +
763 + if ((val = getvar(vars, name)) == NULL)
764 + return (0);
765 +
766 + return (bcm_strtoul(val, NULL, 0));
767 +}
768 +
769 +
770 +/* Search for token in comma separated token-string */
771 +static int
772 +findmatch(char *string, char *name)
773 +{
774 + uint len;
775 + char *c;
776 +
777 + len = strlen(name);
778 + while ((c = strchr(string, ',')) != NULL) {
779 + if (len == (uint)(c - string) && !strncmp(string, name, len))
780 + return 1;
781 + string = c + 1;
782 + }
783 +
784 + return (!strcmp(string, name));
785 +}
786 +
787 +/* Return gpio pin number assigned to the named pin */
788 +/*
789 +* Variable should be in format:
790 +*
791 +* gpio<N>=pin_name,pin_name
792 +*
793 +* This format allows multiple features to share the gpio with mutual
794 +* understanding.
795 +*
796 +* 'def_pin' is returned if a specific gpio is not defined for the requested functionality
797 +* and if def_pin is not used by others.
798 +*/
799 +uint
800 +getgpiopin(char *vars, char *pin_name, uint def_pin)
801 +{
802 + char name[] = "gpioXXXX";
803 + char *val;
804 + uint pin;
805 +
806 + /* Go thru all possibilities till a match in pin name */
807 + for (pin = 0; pin < GPIO_NUMPINS; pin ++) {
808 + sprintf(name, "gpio%d", pin);
809 + val = getvar(vars, name);
810 + if (val && findmatch(val, pin_name))
811 + return pin;
812 + }
813 +
814 + if (def_pin != GPIO_PIN_NOTDEFINED) {
815 + /* make sure the default pin is not used by someone else */
816 + sprintf(name, "gpio%d", def_pin);
817 + if (getvar(vars, name)) {
818 + def_pin = GPIO_PIN_NOTDEFINED;
819 + }
820 + }
821 +
822 + return def_pin;
823 +}
824 +
825 +
826 +/*******************************************************************************
827 + * crc8
828 + *
829 + * Computes a crc8 over the input data using the polynomial:
830 + *
831 + * x^8 + x^7 +x^6 + x^4 + x^2 + 1
832 + *
833 + * The caller provides the initial value (either CRC8_INIT_VALUE
834 + * or the previous returned value) to allow for processing of
835 + * discontiguous blocks of data. When generating the CRC the
836 + * caller is responsible for complementing the final return value
837 + * and inserting it into the byte stream. When checking, a final
838 + * return value of CRC8_GOOD_VALUE indicates a valid CRC.
839 + *
840 + * Reference: Dallas Semiconductor Application Note 27
841 + * Williams, Ross N., "A Painless Guide to CRC Error Detection Algorithms",
842 + * ver 3, Aug 1993, ross@guest.adelaide.edu.au, Rocksoft Pty Ltd.,
843 + * ftp://ftp.rocksoft.com/clients/rocksoft/papers/crc_v3.txt
844 + *
845 + ******************************************************************************/
846 +
847 +static uint8 crc8_table[256] = {
848 + 0x00, 0xF7, 0xB9, 0x4E, 0x25, 0xD2, 0x9C, 0x6B,
849 + 0x4A, 0xBD, 0xF3, 0x04, 0x6F, 0x98, 0xD6, 0x21,
850 + 0x94, 0x63, 0x2D, 0xDA, 0xB1, 0x46, 0x08, 0xFF,
851 + 0xDE, 0x29, 0x67, 0x90, 0xFB, 0x0C, 0x42, 0xB5,
852 + 0x7F, 0x88, 0xC6, 0x31, 0x5A, 0xAD, 0xE3, 0x14,
853 + 0x35, 0xC2, 0x8C, 0x7B, 0x10, 0xE7, 0xA9, 0x5E,
854 + 0xEB, 0x1C, 0x52, 0xA5, 0xCE, 0x39, 0x77, 0x80,
855 + 0xA1, 0x56, 0x18, 0xEF, 0x84, 0x73, 0x3D, 0xCA,
856 + 0xFE, 0x09, 0x47, 0xB0, 0xDB, 0x2C, 0x62, 0x95,
857 + 0xB4, 0x43, 0x0D, 0xFA, 0x91, 0x66, 0x28, 0xDF,
858 + 0x6A, 0x9D, 0xD3, 0x24, 0x4F, 0xB8, 0xF6, 0x01,
859 + 0x20, 0xD7, 0x99, 0x6E, 0x05, 0xF2, 0xBC, 0x4B,
860 + 0x81, 0x76, 0x38, 0xCF, 0xA4, 0x53, 0x1D, 0xEA,
861 + 0xCB, 0x3C, 0x72, 0x85, 0xEE, 0x19, 0x57, 0xA0,
862 + 0x15, 0xE2, 0xAC, 0x5B, 0x30, 0xC7, 0x89, 0x7E,
863 + 0x5F, 0xA8, 0xE6, 0x11, 0x7A, 0x8D, 0xC3, 0x34,
864 + 0xAB, 0x5C, 0x12, 0xE5, 0x8E, 0x79, 0x37, 0xC0,
865 + 0xE1, 0x16, 0x58, 0xAF, 0xC4, 0x33, 0x7D, 0x8A,
866 + 0x3F, 0xC8, 0x86, 0x71, 0x1A, 0xED, 0xA3, 0x54,
867 + 0x75, 0x82, 0xCC, 0x3B, 0x50, 0xA7, 0xE9, 0x1E,
868 + 0xD4, 0x23, 0x6D, 0x9A, 0xF1, 0x06, 0x48, 0xBF,
869 + 0x9E, 0x69, 0x27, 0xD0, 0xBB, 0x4C, 0x02, 0xF5,
870 + 0x40, 0xB7, 0xF9, 0x0E, 0x65, 0x92, 0xDC, 0x2B,
871 + 0x0A, 0xFD, 0xB3, 0x44, 0x2F, 0xD8, 0x96, 0x61,
872 + 0x55, 0xA2, 0xEC, 0x1B, 0x70, 0x87, 0xC9, 0x3E,
873 + 0x1F, 0xE8, 0xA6, 0x51, 0x3A, 0xCD, 0x83, 0x74,
874 + 0xC1, 0x36, 0x78, 0x8F, 0xE4, 0x13, 0x5D, 0xAA,
875 + 0x8B, 0x7C, 0x32, 0xC5, 0xAE, 0x59, 0x17, 0xE0,
876 + 0x2A, 0xDD, 0x93, 0x64, 0x0F, 0xF8, 0xB6, 0x41,
877 + 0x60, 0x97, 0xD9, 0x2E, 0x45, 0xB2, 0xFC, 0x0B,
878 + 0xBE, 0x49, 0x07, 0xF0, 0x9B, 0x6C, 0x22, 0xD5,
879 + 0xF4, 0x03, 0x4D, 0xBA, 0xD1, 0x26, 0x68, 0x9F
880 +};
881 +
882 +#define CRC_INNER_LOOP(n, c, x) \
883 + (c) = ((c) >> 8) ^ crc##n##_table[((c) ^ (x)) & 0xff]
884 +
885 +uint8
886 +hndcrc8(
887 + uint8 *pdata, /* pointer to array of data to process */
888 + uint nbytes, /* number of input data bytes to process */
889 + uint8 crc /* either CRC8_INIT_VALUE or previous return value */
890 +)
891 +{
892 + /* hard code the crc loop instead of using CRC_INNER_LOOP macro
893 + * to avoid the undefined and unnecessary (uint8 >> 8) operation. */
894 + while (nbytes-- > 0)
895 + crc = crc8_table[(crc ^ *pdata++) & 0xff];
896 +
897 + return crc;
898 +}
899 +
900 +#ifdef notdef
901 +#define CLEN 1499
902 +#define CBUFSIZ (CLEN+4)
903 +#define CNBUFS 5
904 +
905 +#endif
906 +
907 +
908 diff -urN linux.old/arch/mips/bcm947xx/broadcom/linux_osl.c linux.dev/arch/mips/bcm947xx/broadcom/linux_osl.c
909 --- linux.old/arch/mips/bcm947xx/broadcom/linux_osl.c 1970-01-01 01:00:00.000000000 +0100
910 +++ linux.dev/arch/mips/bcm947xx/broadcom/linux_osl.c 2005-12-15 17:11:05.818041750 +0100
911 @@ -0,0 +1,102 @@
912 +/*
913 + * Linux OS Independent Layer
914 + *
915 + * Copyright 2005, Broadcom Corporation
916 + * All Rights Reserved.
917 + *
918 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
919 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
920 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
921 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
922 + *
923 + * $Id$
924 + */
925 +
926 +#define LINUX_OSL
927 +
928 +#include <typedefs.h>
929 +#include <bcmendian.h>
930 +#include <linux/module.h>
931 +#include <linuxver.h>
932 +#include <osl.h>
933 +#include <bcmutils.h>
934 +#include <linux/delay.h>
935 +#ifdef mips
936 +#include <asm/paccess.h>
937 +#endif
938 +#include <pcicfg.h>
939 +
940 +#define PCI_CFG_RETRY 10
941 +
942 +#define OS_HANDLE_MAGIC 0x1234abcd
943 +#define BCM_MEM_FILENAME_LEN 24
944 +
945 +typedef struct bcm_mem_link {
946 + struct bcm_mem_link *prev;
947 + struct bcm_mem_link *next;
948 + uint size;
949 + int line;
950 + char file[BCM_MEM_FILENAME_LEN];
951 +} bcm_mem_link_t;
952 +
953 +struct os_handle {
954 + uint magic;
955 + void *pdev;
956 + uint malloced;
957 + uint failed;
958 + bcm_mem_link_t *dbgmem_list;
959 +};
960 +
961 +uint32
962 +osl_pci_read_config(osl_t *osh, uint offset, uint size)
963 +{
964 + uint val;
965 + uint retry=PCI_CFG_RETRY;
966 +
967 + ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
968 +
969 + /* only 4byte access supported */
970 + ASSERT(size == 4);
971 +
972 + do {
973 + pci_read_config_dword(osh->pdev, offset, &val);
974 + if (val != 0xffffffff)
975 + break;
976 + } while (retry--);
977 +
978 +
979 + return (val);
980 +}
981 +
982 +void
983 +osl_pci_write_config(osl_t *osh, uint offset, uint size, uint val)
984 +{
985 + uint retry=PCI_CFG_RETRY;
986 +
987 + ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
988 +
989 + /* only 4byte access supported */
990 + ASSERT(size == 4);
991 +
992 + do {
993 + pci_write_config_dword(osh->pdev, offset, val);
994 + if (offset!=PCI_BAR0_WIN)
995 + break;
996 + if (osl_pci_read_config(osh,offset,size) == val)
997 + break;
998 + } while (retry--);
999 +
1000 +}
1001 +
1002 +void
1003 +osl_delay(uint usec)
1004 +{
1005 + uint d;
1006 +
1007 + while (usec > 0) {
1008 + d = MIN(usec, 1000);
1009 + udelay(d);
1010 + usec -= d;
1011 + }
1012 +}
1013 +
1014 diff -urN linux.old/arch/mips/bcm947xx/broadcom/nvram.c linux.dev/arch/mips/bcm947xx/broadcom/nvram.c
1015 --- linux.old/arch/mips/bcm947xx/broadcom/nvram.c 1970-01-01 01:00:00.000000000 +0100
1016 +++ linux.dev/arch/mips/bcm947xx/broadcom/nvram.c 2005-12-15 17:36:23.151078000 +0100
1017 @@ -0,0 +1,145 @@
1018 +/*
1019 + * NVRAM variable manipulation (Linux kernel half)
1020 + *
1021 + * Copyright 2005, Broadcom Corporation
1022 + * All Rights Reserved.
1023 + *
1024 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
1025 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
1026 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
1027 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
1028 + *
1029 + * $Id$
1030 + */
1031 +
1032 +#include <linux/config.h>
1033 +#include <linux/init.h>
1034 +#include <linux/module.h>
1035 +#include <linux/kernel.h>
1036 +#include <linux/string.h>
1037 +#include <linux/interrupt.h>
1038 +#include <linux/spinlock.h>
1039 +#include <linux/slab.h>
1040 +#include <linux/bootmem.h>
1041 +#include <asm/addrspace.h>
1042 +#include <asm/io.h>
1043 +#include <asm/uaccess.h>
1044 +
1045 +#include <typedefs.h>
1046 +#include <bcmendian.h>
1047 +#include <bcmnvram.h>
1048 +#include <bcmutils.h>
1049 +#include <sbconfig.h>
1050 +#include <sbchipc.h>
1051 +#include <sbutils.h>
1052 +#include <sbmips.h>
1053 +#include <sflash.h>
1054 +
1055 +/* In BSS to minimize text size and page aligned so it can be mmap()-ed */
1056 +static char nvram_buf[NVRAM_SPACE] __attribute__((aligned(PAGE_SIZE)));
1057 +
1058 +/* Global SB handle */
1059 +extern void *sbh;
1060 +extern spinlock_t bcm947xx_sbh_lock;
1061 +
1062 +/* Convenience */
1063 +#define sbh_lock bcm947xx_sbh_lock
1064 +#define KB * 1024
1065 +#define MB * 1024 * 1024
1066 +
1067 +/* Probe for NVRAM header */
1068 +static void __init
1069 +early_nvram_init(void)
1070 +{
1071 + struct nvram_header *header;
1072 + chipcregs_t *cc;
1073 + struct sflash *info = NULL;
1074 + int i;
1075 + uint32 base, off, lim;
1076 + u32 *src, *dst;
1077 +
1078 + if ((cc = sb_setcore(sbh, SB_CC, 0)) != NULL) {
1079 + base = KSEG1ADDR(SB_FLASH2);
1080 + switch (readl(&cc->capabilities) & CAP_FLASH_MASK) {
1081 + case PFLASH:
1082 + lim = SB_FLASH2_SZ;
1083 + break;
1084 +
1085 + case SFLASH_ST:
1086 + case SFLASH_AT:
1087 + if ((info = sflash_init(cc)) == NULL)
1088 + return;
1089 + lim = info->size;
1090 + break;
1091 +
1092 + case FLASH_NONE:
1093 + default:
1094 + return;
1095 + }
1096 + } else {
1097 + /* extif assumed, Stop at 4 MB */
1098 + base = KSEG1ADDR(SB_FLASH1);
1099 + lim = SB_FLASH1_SZ;
1100 + }
1101 +
1102 + off = FLASH_MIN;
1103 + while (off <= lim) {
1104 + /* Windowed flash access */
1105 + header = (struct nvram_header *) KSEG1ADDR(base + off - NVRAM_SPACE);
1106 + if (header->magic == NVRAM_MAGIC)
1107 + goto found;
1108 + off <<= 1;
1109 + }
1110 +
1111 + /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
1112 + header = (struct nvram_header *) KSEG1ADDR(base + 4 KB);
1113 + if (header->magic == NVRAM_MAGIC)
1114 + goto found;
1115 +
1116 + header = (struct nvram_header *) KSEG1ADDR(base + 1 KB);
1117 + if (header->magic == NVRAM_MAGIC)
1118 + goto found;
1119 +
1120 + printk("early_nvram_init: NVRAM not found\n");
1121 + return;
1122 +
1123 +found:
1124 + src = (u32 *) header;
1125 + dst = (u32 *) nvram_buf;
1126 + for (i = 0; i < sizeof(struct nvram_header); i += 4)
1127 + *dst++ = *src++;
1128 + for (; i < header->len && i < NVRAM_SPACE; i += 4)
1129 + *dst++ = ltoh32(*src++);
1130 +}
1131 +
1132 +/* Early (before mm or mtd) read-only access to NVRAM */
1133 +char * __init nvram_get(const char *name)
1134 +{
1135 + char *var, *value, *end, *eq;
1136 +
1137 + if (!name)
1138 + return NULL;
1139 +
1140 + /* Too early? */
1141 + if (sbh == NULL)
1142 + return NULL;
1143 +
1144 + if (!nvram_buf[0])
1145 + early_nvram_init();
1146 +
1147 + /* Look for name=value and return value */
1148 + var = &nvram_buf[sizeof(struct nvram_header)];
1149 + end = nvram_buf + sizeof(nvram_buf) - 2;
1150 + end[0] = end[1] = '\0';
1151 + for (; *var; var = value + strlen(value) + 1) {
1152 + if (!(eq = strchr(var, '=')))
1153 + break;
1154 + value = eq + 1;
1155 + if ((eq - var) == strlen(name) && strncmp(var, name, (eq - var)) == 0)
1156 + return value;
1157 + }
1158 +
1159 + return NULL;
1160 +}
1161 +
1162 +EXPORT_SYMBOL(nvram_get);
1163 diff -urN linux.old/arch/mips/bcm947xx/broadcom/sbmips.c linux.dev/arch/mips/bcm947xx/broadcom/sbmips.c
1164 --- linux.old/arch/mips/bcm947xx/broadcom/sbmips.c 1970-01-01 01:00:00.000000000 +0100
1165 +++ linux.dev/arch/mips/bcm947xx/broadcom/sbmips.c 2005-12-15 16:46:31.122961250 +0100
1166 @@ -0,0 +1,1038 @@
1167 +/*
1168 + * BCM47XX Sonics SiliconBackplane MIPS core routines
1169 + *
1170 + * Copyright 2005, Broadcom Corporation
1171 + * All Rights Reserved.
1172 + *
1173 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
1174 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
1175 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
1176 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
1177 + *
1178 + * $Id$
1179 + */
1180 +
1181 +#include <typedefs.h>
1182 +#include <osl.h>
1183 +#include <sbutils.h>
1184 +#include <bcmdevs.h>
1185 +#include <bcmnvram.h>
1186 +#include <bcmutils.h>
1187 +#include <hndmips.h>
1188 +#include <sbconfig.h>
1189 +#include <sbextif.h>
1190 +#include <sbchipc.h>
1191 +#include <sbmemc.h>
1192 +#include <mipsinc.h>
1193 +#include <sbutils.h>
1194 +
1195 +/*
1196 + * Returns TRUE if an external UART exists at the given base
1197 + * register.
1198 + */
1199 +static bool
1200 +BCMINITFN(serial_exists)(uint8 *regs)
1201 +{
1202 + uint8 save_mcr, status1;
1203 +
1204 + save_mcr = R_REG(&regs[UART_MCR]);
1205 + W_REG(&regs[UART_MCR], UART_MCR_LOOP | 0x0a);
1206 + status1 = R_REG(&regs[UART_MSR]) & 0xf0;
1207 + W_REG(&regs[UART_MCR], save_mcr);
1208 +
1209 + return (status1 == 0x90);
1210 +}
1211 +
1212 +/*
1213 + * Initializes UART access. The callback function will be called once
1214 + * per found UART.
1215 + */
1216 +void
1217 +BCMINITFN(sb_serial_init)(sb_t *sbh, void (*add)(void *regs, uint irq, uint baud_base, uint reg_shift))
1218 +{
1219 + void *regs;
1220 + ulong base;
1221 + uint irq;
1222 + int i, n;
1223 +
1224 + if ((regs = sb_setcore(sbh, SB_EXTIF, 0))) {
1225 + extifregs_t *eir = (extifregs_t *) regs;
1226 + sbconfig_t *sb;
1227 +
1228 + /* Determine external UART register base */
1229 + sb = (sbconfig_t *)((ulong) eir + SBCONFIGOFF);
1230 + base = EXTIF_CFGIF_BASE(sb_base(R_REG(&sb->sbadmatch1)));
1231 +
1232 + /* Determine IRQ */
1233 + irq = sb_irq(sbh);
1234 +
1235 + /* Disable GPIO interrupt initially */
1236 + W_REG(&eir->gpiointpolarity, 0);
1237 + W_REG(&eir->gpiointmask, 0);
1238 +
1239 + /* Search for external UARTs */
1240 + n = 2;
1241 + for (i = 0; i < 2; i++) {
1242 + regs = (void *) REG_MAP(base + (i * 8), 8);
1243 + if (BCMINIT(serial_exists)(regs)) {
1244 + /* Set GPIO 1 to be the external UART IRQ */
1245 + W_REG(&eir->gpiointmask, 2);
1246 + if (add)
1247 + add(regs, irq, 13500000, 0);
1248 + }
1249 + }
1250 +
1251 + /* Add internal UART if enabled */
1252 + if (R_REG(&eir->corecontrol) & CC_UE)
1253 + if (add)
1254 + add((void *) &eir->uartdata, irq, sb_clock(sbh), 2);
1255 + } else if ((regs = sb_setcore(sbh, SB_CC, 0))) {
1256 + chipcregs_t *cc = (chipcregs_t *) regs;
1257 + uint32 rev, cap, pll, baud_base, div;
1258 +
1259 + /* Determine core revision and capabilities */
1260 + rev = sb_corerev(sbh);
1261 + cap = R_REG(&cc->capabilities);
1262 + pll = cap & CAP_PLL_MASK;
1263 +
1264 + /* Determine IRQ */
1265 + irq = sb_irq(sbh);
1266 +
1267 + if (pll == PLL_TYPE1) {
1268 + /* PLL clock */
1269 + baud_base = sb_clock_rate(pll,
1270 + R_REG(&cc->clockcontrol_n),
1271 + R_REG(&cc->clockcontrol_m2));
1272 + div = 1;
1273 + } else {
1274 + if (rev >= 11) {
1275 + /* Fixed ALP clock */
1276 + baud_base = 20000000;
1277 + div = 1;
1278 + /* Set the override bit so we don't divide it */
1279 + W_REG(&cc->corecontrol, CC_UARTCLKO);
1280 + } else if (rev >= 3) {
1281 + /* Internal backplane clock */
1282 + baud_base = sb_clock(sbh);
1283 + div = 2; /* Minimum divisor */
1284 + W_REG(&cc->clkdiv,
1285 + ((R_REG(&cc->clkdiv) & ~CLKD_UART) | div));
1286 + } else {
1287 + /* Fixed internal backplane clock */
1288 + baud_base = 88000000;
1289 + div = 48;
1290 + }
1291 +
1292 + /* Clock source depends on strapping if UartClkOverride is unset */
1293 + if ((rev > 0) &&
1294 + ((R_REG(&cc->corecontrol) & CC_UARTCLKO) == 0)) {
1295 + if ((cap & CAP_UCLKSEL) == CAP_UINTCLK) {
1296 + /* Internal divided backplane clock */
1297 + baud_base /= div;
1298 + } else {
1299 + /* Assume external clock of 1.8432 MHz */
1300 + baud_base = 1843200;
1301 + }
1302 + }
1303 + }
1304 +
1305 + /* Add internal UARTs */
1306 + n = cap & CAP_UARTS_MASK;
1307 + for (i = 0; i < n; i++) {
1308 + /* Register offset changed after revision 0 */
1309 + if (rev)
1310 + regs = (void *)((ulong) &cc->uart0data + (i * 256));
1311 + else
1312 + regs = (void *)((ulong) &cc->uart0data + (i * 8));
1313 +
1314 + if (add)
1315 + add(regs, irq, baud_base, 0);
1316 + }
1317 + }
1318 +}
1319 +
1320 +/*
1321 + * Initialize jtag master and return handle for
1322 + * jtag_rwreg. Returns NULL on failure.
1323 + */
1324 +void *
1325 +sb_jtagm_init(sb_t *sbh, uint clkd, bool exttap)
1326 +{
1327 + void *regs;
1328 +
1329 + if ((regs = sb_setcore(sbh, SB_CC, 0)) != NULL) {
1330 + chipcregs_t *cc = (chipcregs_t *) regs;
1331 + uint32 tmp;
1332 +
1333 + /*
1334 + * Determine jtagm availability from
1335 + * core revision and capabilities.
1336 + */
1337 + tmp = sb_corerev(sbh);
1338 + /*
1339 + * Corerev 10 has jtagm, but the only chip
1340 + * with it does not have a mips, and
1341 + * the layout of the jtagcmd register is
1342 + * different. We'll only accept >= 11.
1343 + */
1344 + if (tmp < 11)
1345 + return (NULL);
1346 +
1347 + tmp = R_REG(&cc->capabilities);
1348 + if ((tmp & CAP_JTAGP) == 0)
1349 + return (NULL);
1350 +
1351 + /* Set clock divider if requested */
1352 + if (clkd != 0) {
1353 + tmp = R_REG(&cc->clkdiv);
1354 + tmp = (tmp & ~CLKD_JTAG) |
1355 + ((clkd << CLKD_JTAG_SHIFT) & CLKD_JTAG);
1356 + W_REG(&cc->clkdiv, tmp);
1357 + }
1358 +
1359 + /* Enable jtagm */
1360 + tmp = JCTRL_EN | (exttap ? JCTRL_EXT_EN : 0);
1361 + W_REG(&cc->jtagctrl, tmp);
1362 + }
1363 +
1364 + return (regs);
1365 +}
1366 +
1367 +void
1368 +sb_jtagm_disable(void *h)
1369 +{
1370 + chipcregs_t *cc = (chipcregs_t *)h;
1371 +
1372 + W_REG(&cc->jtagctrl, R_REG(&cc->jtagctrl) & ~JCTRL_EN);
1373 +}
1374 +
1375 +/*
1376 + * Read/write a jtag register. Assumes a target with
1377 + * 8 bit IR and 32 bit DR.
1378 + */
1379 +#define IRWIDTH 8
1380 +#define DRWIDTH 32
1381 +uint32
1382 +jtag_rwreg(void *h, uint32 ir, uint32 dr)
1383 +{
1384 + chipcregs_t *cc = (chipcregs_t *) h;
1385 + uint32 tmp;
1386 +
1387 + W_REG(&cc->jtagir, ir);
1388 + W_REG(&cc->jtagdr, dr);
1389 + tmp = JCMD_START | JCMD_ACC_IRDR |
1390 + ((IRWIDTH - 1) << JCMD_IRW_SHIFT) |
1391 + (DRWIDTH - 1);
1392 + W_REG(&cc->jtagcmd, tmp);
1393 + while (((tmp = R_REG(&cc->jtagcmd)) & JCMD_BUSY) == JCMD_BUSY) {
1394 + /* OSL_DELAY(1); */
1395 + }
1396 +
1397 + tmp = R_REG(&cc->jtagdr);
1398 + return (tmp);
1399 +}
1400 +
1401 +/* Returns the SB interrupt flag of the current core. */
1402 +uint32
1403 +sb_flag(sb_t *sbh)
1404 +{
1405 + void *regs;
1406 + sbconfig_t *sb;
1407 +
1408 + regs = sb_coreregs(sbh);
1409 + sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
1410 +
1411 + return (R_REG(&sb->sbtpsflag) & SBTPS_NUM0_MASK);
1412 +}
1413 +
1414 +static const uint32 sbips_int_mask[] = {
1415 + 0,
1416 + SBIPS_INT1_MASK,
1417 + SBIPS_INT2_MASK,
1418 + SBIPS_INT3_MASK,
1419 + SBIPS_INT4_MASK
1420 +};
1421 +
1422 +static const uint32 sbips_int_shift[] = {
1423 + 0,
1424 + 0,
1425 + SBIPS_INT2_SHIFT,
1426 + SBIPS_INT3_SHIFT,
1427 + SBIPS_INT4_SHIFT
1428 +};
1429 +
1430 +/*
1431 + * Returns the MIPS IRQ assignment of the current core. If unassigned,
1432 + * 0 is returned.
1433 + */
1434 +uint
1435 +sb_irq(sb_t *sbh)
1436 +{
1437 + uint idx;
1438 + void *regs;
1439 + sbconfig_t *sb;
1440 + uint32 flag, sbipsflag;
1441 + uint irq = 0;
1442 +
1443 + flag = sb_flag(sbh);
1444 +
1445 + idx = sb_coreidx(sbh);
1446 +
1447 + if ((regs = sb_setcore(sbh, SB_MIPS, 0)) ||
1448 + (regs = sb_setcore(sbh, SB_MIPS33, 0))) {
1449 + sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
1450 +
1451 + /* sbipsflag specifies which core is routed to interrupts 1 to 4 */
1452 + sbipsflag = R_REG(&sb->sbipsflag);
1453 + for (irq = 1; irq <= 4; irq++) {
1454 + if (((sbipsflag & sbips_int_mask[irq]) >> sbips_int_shift[irq]) == flag)
1455 + break;
1456 + }
1457 + if (irq == 5)
1458 + irq = 0;
1459 + }
1460 +
1461 + sb_setcoreidx(sbh, idx);
1462 +
1463 + return irq;
1464 +}
1465 +
1466 +/* Clears the specified MIPS IRQ. */
1467 +static void
1468 +BCMINITFN(sb_clearirq)(sb_t *sbh, uint irq)
1469 +{
1470 + void *regs;
1471 + sbconfig_t *sb;
1472 +
1473 + if (!(regs = sb_setcore(sbh, SB_MIPS, 0)) &&
1474 + !(regs = sb_setcore(sbh, SB_MIPS33, 0)))
1475 + ASSERT(regs);
1476 + sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
1477 +
1478 + if (irq == 0)
1479 + W_REG(&sb->sbintvec, 0);
1480 + else
1481 + OR_REG(&sb->sbipsflag, sbips_int_mask[irq]);
1482 +}
1483 +
1484 +/*
1485 + * Assigns the specified MIPS IRQ to the specified core. Shared MIPS
1486 + * IRQ 0 may be assigned more than once.
1487 + */
1488 +static void
1489 +BCMINITFN(sb_setirq)(sb_t *sbh, uint irq, uint coreid, uint coreunit)
1490 +{
1491 + void *regs;
1492 + sbconfig_t *sb;
1493 + uint32 flag;
1494 +
1495 + regs = sb_setcore(sbh, coreid, coreunit);
1496 + ASSERT(regs);
1497 + flag = sb_flag(sbh);
1498 +
1499 + if (!(regs = sb_setcore(sbh, SB_MIPS, 0)) &&
1500 + !(regs = sb_setcore(sbh, SB_MIPS33, 0)))
1501 + ASSERT(regs);
1502 + sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
1503 +
1504 + if (irq == 0)
1505 + OR_REG(&sb->sbintvec, 1 << flag);
1506 + else {
1507 + flag <<= sbips_int_shift[irq];
1508 + ASSERT(!(flag & ~sbips_int_mask[irq]));
1509 + flag |= R_REG(&sb->sbipsflag) & ~sbips_int_mask[irq];
1510 + W_REG(&sb->sbipsflag, flag);
1511 + }
1512 +}
1513 +
1514 +/*
1515 + * Initializes clocks and interrupts. SB and NVRAM access must be
1516 + * initialized prior to calling.
1517 + */
1518 +void
1519 +BCMINITFN(sb_mips_init)(sb_t *sbh)
1520 +{
1521 + ulong hz, ns, tmp;
1522 + extifregs_t *eir;
1523 + chipcregs_t *cc;
1524 + char *value;
1525 + uint irq;
1526 +
1527 + /* Figure out current SB clock speed */
1528 + if ((hz = sb_clock(sbh)) == 0)
1529 + hz = 100000000;
1530 + ns = 1000000000 / hz;
1531 +
1532 + /* Setup external interface timing */
1533 + if ((eir = sb_setcore(sbh, SB_EXTIF, 0))) {
1534 + /* Initialize extif so we can get to the LEDs and external UART */
1535 + W_REG(&eir->prog_config, CF_EN);
1536 +
1537 + /* Set timing for the flash */
1538 + tmp = CEIL(10, ns) << FW_W3_SHIFT; /* W3 = 10nS */
1539 + tmp = tmp | (CEIL(40, ns) << FW_W1_SHIFT); /* W1 = 40nS */
1540 + tmp = tmp | CEIL(120, ns); /* W0 = 120nS */
1541 + W_REG(&eir->prog_waitcount, tmp); /* 0x01020a0c for a 100Mhz clock */
1542 +
1543 + /* Set programmable interface timing for external uart */
1544 + tmp = CEIL(10, ns) << FW_W3_SHIFT; /* W3 = 10nS */
1545 + tmp = tmp | (CEIL(20, ns) << FW_W2_SHIFT); /* W2 = 20nS */
1546 + tmp = tmp | (CEIL(100, ns) << FW_W1_SHIFT); /* W1 = 100nS */
1547 + tmp = tmp | CEIL(120, ns); /* W0 = 120nS */
1548 + W_REG(&eir->prog_waitcount, tmp); /* 0x01020a0c for a 100Mhz clock */
1549 + } else if ((cc = sb_setcore(sbh, SB_CC, 0))) {
1550 + /* Set timing for the flash */
1551 + tmp = CEIL(10, ns) << FW_W3_SHIFT; /* W3 = 10nS */
1552 + tmp |= CEIL(10, ns) << FW_W1_SHIFT; /* W1 = 10nS */
1553 + tmp |= CEIL(120, ns); /* W0 = 120nS */
1554 +
1555 + // Added by Chen-I for 5365
1556 + if (BCMINIT(sb_chip)(sbh) == BCM5365_DEVICE_ID)
1557 + {
1558 + W_REG(&cc->flash_waitcount, tmp);
1559 + W_REG(&cc->pcmcia_memwait, tmp);
1560 + }
1561 + else
1562 + {
1563 + if (sb_corerev(sbh) < 9)
1564 + W_REG(&cc->flash_waitcount, tmp);
1565 +
1566 + if ((sb_corerev(sbh) < 9) ||
1567 + ((BCMINIT(sb_chip)(sbh) == BCM5350_DEVICE_ID) && BCMINIT(sb_chiprev)(sbh) == 0)) {
1568 + W_REG(&cc->pcmcia_memwait, tmp);
1569 + }
1570 + }
1571 + }
1572 +
1573 + /* Chip specific initialization */
1574 + switch (BCMINIT(sb_chip)(sbh)) {
1575 + case BCM4710_DEVICE_ID:
1576 + /* Clear interrupt map */
1577 + for (irq = 0; irq <= 4; irq++)
1578 + BCMINIT(sb_clearirq)(sbh, irq);
1579 + BCMINIT(sb_setirq)(sbh, 0, SB_CODEC, 0);
1580 + BCMINIT(sb_setirq)(sbh, 0, SB_EXTIF, 0);
1581 + BCMINIT(sb_setirq)(sbh, 2, SB_ENET, 1);
1582 + BCMINIT(sb_setirq)(sbh, 3, SB_ILINE20, 0);
1583 + BCMINIT(sb_setirq)(sbh, 4, SB_PCI, 0);
1584 + ASSERT(eir);
1585 + value = BCMINIT(nvram_get)("et0phyaddr");
1586 + if (value && !strcmp(value, "31")) {
1587 + /* Enable internal UART */
1588 + W_REG(&eir->corecontrol, CC_UE);
1589 + /* Give USB its own interrupt */
1590 + BCMINIT(sb_setirq)(sbh, 1, SB_USB, 0);
1591 + } else {
1592 + /* Disable internal UART */
1593 + W_REG(&eir->corecontrol, 0);
1594 + /* Give Ethernet its own interrupt */
1595 + BCMINIT(sb_setirq)(sbh, 1, SB_ENET, 0);
1596 + BCMINIT(sb_setirq)(sbh, 0, SB_USB, 0);
1597 + }
1598 + break;
1599 + case BCM5350_DEVICE_ID:
1600 + /* Clear interrupt map */
1601 + for (irq = 0; irq <= 4; irq++)
1602 + BCMINIT(sb_clearirq)(sbh, irq);
1603 + BCMINIT(sb_setirq)(sbh, 0, SB_CC, 0);
1604 + BCMINIT(sb_setirq)(sbh, 1, SB_D11, 0);
1605 + BCMINIT(sb_setirq)(sbh, 2, SB_ENET, 0);
1606 + BCMINIT(sb_setirq)(sbh, 3, SB_PCI, 0);
1607 + BCMINIT(sb_setirq)(sbh, 4, SB_USB, 0);
1608 + break;
1609 + }
1610 +}
1611 +
1612 +uint32
1613 +BCMINITFN(sb_mips_clock)(sb_t *sbh)
1614 +{
1615 + extifregs_t *eir;
1616 + chipcregs_t *cc;
1617 + uint32 n, m;
1618 + uint idx;
1619 + uint32 pll_type, rate = 0;
1620 +
1621 + /* get index of the current core */
1622 + idx = sb_coreidx(sbh);
1623 + pll_type = PLL_TYPE1;
1624 +
1625 + /* switch to extif or chipc core */
1626 + if ((eir = (extifregs_t *) sb_setcore(sbh, SB_EXTIF, 0))) {
1627 + n = R_REG(&eir->clockcontrol_n);
1628 + m = R_REG(&eir->clockcontrol_sb);
1629 + } else if ((cc = (chipcregs_t *) sb_setcore(sbh, SB_CC, 0))) {
1630 + pll_type = R_REG(&cc->capabilities) & CAP_PLL_MASK;
1631 + n = R_REG(&cc->clockcontrol_n);
1632 + if ((pll_type == PLL_TYPE2) ||
1633 + (pll_type == PLL_TYPE4) ||
1634 + (pll_type == PLL_TYPE6) ||
1635 + (pll_type == PLL_TYPE7))
1636 + m = R_REG(&cc->clockcontrol_mips);
1637 + else if (pll_type == PLL_TYPE5) {
1638 + rate = 200000000;
1639 + goto out;
1640 + }
1641 + else if (pll_type == PLL_TYPE3) {
1642 + if (BCMINIT(sb_chip)(sbh) == BCM5365_DEVICE_ID) { /* 5365 is also type3 */
1643 + rate = 200000000;
1644 + goto out;
1645 + } else
1646 + m = R_REG(&cc->clockcontrol_m2); /* 5350 uses m2 to control mips */
1647 + } else
1648 + m = R_REG(&cc->clockcontrol_sb);
1649 + } else
1650 + goto out;
1651 +
1652 + // Added by Chen-I for 5365
1653 + if (BCMINIT(sb_chip)(sbh) == BCM5365_DEVICE_ID)
1654 + rate = 100000000;
1655 + else
1656 + /* calculate rate */
1657 + rate = sb_clock_rate(pll_type, n, m);
1658 +
1659 + if (pll_type == PLL_TYPE6)
1660 + rate = SB2MIPS_T6(rate);
1661 +
1662 +out:
1663 + /* switch back to previous core */
1664 + sb_setcoreidx(sbh, idx);
1665 +
1666 + return rate;
1667 +}
1668 +
1669 +#define ALLINTS (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4)
1670 +
1671 +static void
1672 +BCMINITFN(handler)(void)
1673 +{
1674 + /* Step 11 */
1675 + __asm__ (
1676 + ".set\tmips32\n\t"
1677 + "ssnop\n\t"
1678 + "ssnop\n\t"
1679 + /* Disable interrupts */
1680 + /* MTC0(C0_STATUS, 0, MFC0(C0_STATUS, 0) & ~(ALLINTS | STO_IE)); */
1681 + "mfc0 $15, $12\n\t"
1682 + /* Just a Hack to not to use reg 'at' which was causing problems on 4704 A2 */
1683 + "li $14, -31746\n\t"
1684 + "and $15, $15, $14\n\t"
1685 + "mtc0 $15, $12\n\t"
1686 + "eret\n\t"
1687 + "nop\n\t"
1688 + "nop\n\t"
1689 + ".set\tmips0"
1690 + );
1691 +}
1692 +
1693 +/* The following MUST come right after handler() */
1694 +static void
1695 +BCMINITFN(afterhandler)(void)
1696 +{
1697 +}
1698 +
1699 +/*
1700 + * Set the MIPS, backplane and PCI clocks as closely as possible.
1701 + */
1702 +bool
1703 +BCMINITFN(sb_mips_setclock)(sb_t *sbh, uint32 mipsclock, uint32 sbclock, uint32 pciclock)
1704 +{
1705 + extifregs_t *eir = NULL;
1706 + chipcregs_t *cc = NULL;
1707 + mipsregs_t *mipsr = NULL;
1708 + volatile uint32 *clockcontrol_n, *clockcontrol_sb, *clockcontrol_pci, *clockcontrol_m2;
1709 + uint32 orig_n, orig_sb, orig_pci, orig_m2, orig_mips, orig_ratio_parm, orig_ratio_cfg;
1710 + uint32 pll_type, sync_mode;
1711 + uint ic_size, ic_lsize;
1712 + uint idx, i;
1713 + typedef struct {
1714 + uint32 mipsclock;
1715 + uint16 n;
1716 + uint32 sb;
1717 + uint32 pci33;
1718 + uint32 pci25;
1719 + } n3m_table_t;
1720 + static n3m_table_t BCMINITDATA(type1_table)[] = {
1721 + { 96000000, 0x0303, 0x04020011, 0x11030011, 0x11050011 }, /* 96.000 32.000 24.000 */
1722 + { 100000000, 0x0009, 0x04020011, 0x11030011, 0x11050011 }, /* 100.000 33.333 25.000 */
1723 + { 104000000, 0x0802, 0x04020011, 0x11050009, 0x11090009 }, /* 104.000 31.200 24.960 */
1724 + { 108000000, 0x0403, 0x04020011, 0x11050009, 0x02000802 }, /* 108.000 32.400 24.923 */
1725 + { 112000000, 0x0205, 0x04020011, 0x11030021, 0x02000403 }, /* 112.000 32.000 24.889 */
1726 + { 115200000, 0x0303, 0x04020009, 0x11030011, 0x11050011 }, /* 115.200 32.000 24.000 */
1727 + { 120000000, 0x0011, 0x04020011, 0x11050011, 0x11090011 }, /* 120.000 30.000 24.000 */
1728 + { 124800000, 0x0802, 0x04020009, 0x11050009, 0x11090009 }, /* 124.800 31.200 24.960 */
1729 + { 128000000, 0x0305, 0x04020011, 0x11050011, 0x02000305 }, /* 128.000 32.000 24.000 */
1730 + { 132000000, 0x0603, 0x04020011, 0x11050011, 0x02000305 }, /* 132.000 33.000 24.750 */
1731 + { 136000000, 0x0c02, 0x04020011, 0x11090009, 0x02000603 }, /* 136.000 32.640 24.727 */
1732 + { 140000000, 0x0021, 0x04020011, 0x11050021, 0x02000c02 }, /* 140.000 30.000 24.706 */
1733 + { 144000000, 0x0405, 0x04020011, 0x01020202, 0x11090021 }, /* 144.000 30.857 24.686 */
1734 + { 150857142, 0x0605, 0x04020021, 0x02000305, 0x02000605 }, /* 150.857 33.000 24.000 */
1735 + { 152000000, 0x0e02, 0x04020011, 0x11050021, 0x02000e02 }, /* 152.000 32.571 24.000 */
1736 + { 156000000, 0x0802, 0x04020005, 0x11050009, 0x11090009 }, /* 156.000 31.200 24.960 */
1737 + { 160000000, 0x0309, 0x04020011, 0x11090011, 0x02000309 }, /* 160.000 32.000 24.000 */
1738 + { 163200000, 0x0c02, 0x04020009, 0x11090009, 0x02000603 }, /* 163.200 32.640 24.727 */
1739 + { 168000000, 0x0205, 0x04020005, 0x11030021, 0x02000403 }, /* 168.000 32.000 24.889 */
1740 + { 176000000, 0x0602, 0x04020003, 0x11050005, 0x02000602 }, /* 176.000 33.000 24.000 */
1741 + };
1742 + typedef struct {
1743 + uint32 mipsclock;
1744 + uint16 n;
1745 + uint32 m2; /* that is the clockcontrol_m2 */
1746 + } type3_table_t;
1747 + static type3_table_t type3_table[] = { /* for 5350, mips clock is always double sb clock */
1748 + { 150000000, 0x311, 0x4020005 },
1749 + { 200000000, 0x311, 0x4020003 },
1750 + };
1751 + typedef struct {
1752 + uint32 mipsclock;
1753 + uint32 sbclock;
1754 + uint16 n;
1755 + uint32 sb;
1756 + uint32 pci33;
1757 + uint32 m2;
1758 + uint32 m3;
1759 + uint32 ratio_cfg;
1760 + uint32 ratio_parm;
1761 + } n4m_table_t;
1762 +
1763 + static n4m_table_t BCMINITDATA(type2_table)[] = {
1764 + { 180000000, 80000000, 0x0403, 0x01010000, 0x01020300, 0x01020600, 0x05000100, 8, 0x012a00a9 },
1765 + { 180000000, 90000000, 0x0403, 0x01000100, 0x01020300, 0x01000100, 0x05000100, 11, 0x0aaa0555 },
1766 + { 200000000, 100000000, 0x0303, 0x02010000, 0x02040001, 0x02010000, 0x06000001, 11, 0x0aaa0555 },
1767 + { 211200000, 105600000, 0x0902, 0x01000200, 0x01030400, 0x01000200, 0x05000200, 11, 0x0aaa0555 },
1768 + { 220800000, 110400000, 0x1500, 0x01000200, 0x01030400, 0x01000200, 0x05000200, 11, 0x0aaa0555 },
1769 + { 230400000, 115200000, 0x0604, 0x01000200, 0x01020600, 0x01000200, 0x05000200, 11, 0x0aaa0555 },
1770 + { 234000000, 104000000, 0x0b01, 0x01010000, 0x01010700, 0x01020600, 0x05000100, 8, 0x012a00a9 },
1771 + { 240000000, 120000000, 0x0803, 0x01000200, 0x01020600, 0x01000200, 0x05000200, 11, 0x0aaa0555 },
1772 + { 252000000, 126000000, 0x0504, 0x01000100, 0x01020500, 0x01000100, 0x05000100, 11, 0x0aaa0555 },
1773 + { 264000000, 132000000, 0x0903, 0x01000200, 0x01020700, 0x01000200, 0x05000200, 11, 0x0aaa0555 },
1774 + { 270000000, 120000000, 0x0703, 0x01010000, 0x01030400, 0x01020600, 0x05000100, 8, 0x012a00a9 },
1775 + { 276000000, 122666666, 0x1500, 0x01010000, 0x01030400, 0x01020600, 0x05000100, 8, 0x012a00a9 },
1776 + { 280000000, 140000000, 0x0503, 0x01000000, 0x01010600, 0x01000000, 0x05000000, 11, 0x0aaa0555 },
1777 + { 288000000, 128000000, 0x0604, 0x01010000, 0x01030400, 0x01020600, 0x05000100, 8, 0x012a00a9 },
1778 + { 288000000, 144000000, 0x0404, 0x01000000, 0x01010600, 0x01000000, 0x05000000, 11, 0x0aaa0555 },
1779 + { 300000000, 133333333, 0x0803, 0x01010000, 0x01020600, 0x01020600, 0x05000100, 8, 0x012a00a9 },
1780 + { 300000000, 150000000, 0x0803, 0x01000100, 0x01020600, 0x01000100, 0x05000100, 11, 0x0aaa0555 }
1781 + };
1782 +
1783 + static n4m_table_t BCMINITDATA(type4_table)[] = {
1784 + { 192000000, 96000000, 0x0702, 0x04000011, 0x11030011, 0x04000011, 0x04000003, 11, 0x0aaa0555 },
1785 + { 198000000, 99000000, 0x0603, 0x11020005, 0x11030011, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
1786 + { 200000000, 100000000, 0x0009, 0x04020011, 0x11030011, 0x04020011, 0x04020003, 11, 0x0aaa0555 },
1787 + { 204000000, 102000000, 0x0c02, 0x11020005, 0x01030303, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
1788 + { 208000000, 104000000, 0x0802, 0x11030002, 0x11090005, 0x11030002, 0x04000003, 11, 0x0aaa0555 },
1789 + { 210000000, 105000000, 0x0209, 0x11020005, 0x01030303, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
1790 + { 216000000, 108000000, 0x0111, 0x11020005, 0x01030303, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
1791 + { 224000000, 112000000, 0x0205, 0x11030002, 0x02002103, 0x11030002, 0x04000003, 11, 0x0aaa0555 },
1792 + { 228000000, 101333333, 0x0e02, 0x11030003, 0x11210005, 0x01030305, 0x04000005, 8, 0x012a00a9 },
1793 + { 228000000, 114000000, 0x0e02, 0x11020005, 0x11210005, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
1794 + { 240000000, 102857143, 0x0109, 0x04000021, 0x01050203, 0x11030021, 0x04000003, 13, 0x254a14a9 },
1795 + { 240000000, 120000000, 0x0109, 0x11030002, 0x01050203, 0x11030002, 0x04000003, 11, 0x0aaa0555 },
1796 + { 252000000, 100800000, 0x0203, 0x04000009, 0x11050005, 0x02000209, 0x04000002, 9, 0x02520129 },
1797 + { 252000000, 126000000, 0x0203, 0x04000005, 0x11050005, 0x04000005, 0x04000002, 11, 0x0aaa0555 },
1798 + { 264000000, 132000000, 0x0602, 0x04000005, 0x11050005, 0x04000005, 0x04000002, 11, 0x0aaa0555 },
1799 + { 272000000, 116571428, 0x0c02, 0x04000021, 0x02000909, 0x02000221, 0x04000003, 13, 0x254a14a9 },
1800 + { 280000000, 120000000, 0x0209, 0x04000021, 0x01030303, 0x02000221, 0x04000003, 13, 0x254a14a9 },
1801 + { 288000000, 123428571, 0x0111, 0x04000021, 0x01030303, 0x02000221, 0x04000003, 13, 0x254a14a9 },
1802 + { 300000000, 120000000, 0x0009, 0x04000009, 0x01030203, 0x02000902, 0x04000002, 9, 0x02520129 },
1803 + { 300000000, 150000000, 0x0009, 0x04000005, 0x01030203, 0x04000005, 0x04000002, 11, 0x0aaa0555 }
1804 + };
1805 +
1806 + static n4m_table_t BCMINITDATA(type7_table)[] = {
1807 + { 183333333, 91666666, 0x0605, 0x04000011, 0x11030011, 0x04000011, 0x04000003, 11, 0x0aaa0555 },
1808 + { 187500000, 93750000, 0x0a03, 0x04000011, 0x11030011, 0x04000011, 0x04000003, 11, 0x0aaa0555 },
1809 + { 196875000, 98437500, 0x1003, 0x11020005, 0x11050011, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
1810 + { 200000000, 100000000, 0x0311, 0x04000011, 0x11030011, 0x04000009, 0x04000003, 11, 0x0aaa0555 },
1811 + { 200000000, 100000000, 0x0311, 0x04020011, 0x11030011, 0x04020011, 0x04020003, 11, 0x0aaa0555 },
1812 + { 206250000, 103125000, 0x1103, 0x11020005, 0x11050011, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
1813 + { 212500000, 106250000, 0x0c05, 0x11020005, 0x01030303, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
1814 + { 215625000, 107812500, 0x1203, 0x11090009, 0x11050005, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
1815 + { 216666666, 108333333, 0x0805, 0x11020003, 0x11030011, 0x11020003, 0x04000003, 11, 0x0aaa0555 },
1816 + { 225000000, 112500000, 0x0d03, 0x11020003, 0x11030011, 0x11020003, 0x04000003, 11, 0x0aaa0555 },
1817 + { 233333333, 116666666, 0x0905, 0x11020003, 0x11030011, 0x11020003, 0x04000003, 11, 0x0aaa0555 },
1818 + { 237500000, 118750000, 0x0e05, 0x11020005, 0x11210005, 0x11020005, 0x04000005, 11, 0x0aaa0555 },
1819 + { 240000000, 120000000, 0x0b11, 0x11020009, 0x11210009, 0x11020009, 0x04000009, 11, 0x0aaa0555 },
1820 + { 250000000, 125000000, 0x0f03, 0x11020003, 0x11210003, 0x11020003, 0x04000003, 11, 0x0aaa0555 }
1821 + };
1822 +
1823 + ulong start, end, dst;
1824 + bool ret = FALSE;
1825 +
1826 + /* get index of the current core */
1827 + idx = sb_coreidx(sbh);
1828 + clockcontrol_m2 = NULL;
1829 +
1830 + /* switch to extif or chipc core */
1831 + if ((eir = (extifregs_t *) sb_setcore(sbh, SB_EXTIF, 0))) {
1832 + pll_type = PLL_TYPE1;
1833 + clockcontrol_n = &eir->clockcontrol_n;
1834 + clockcontrol_sb = &eir->clockcontrol_sb;
1835 + clockcontrol_pci = &eir->clockcontrol_pci;
1836 + clockcontrol_m2 = &cc->clockcontrol_m2;
1837 + } else if ((cc = (chipcregs_t *) sb_setcore(sbh, SB_CC, 0))) {
1838 + pll_type = R_REG(&cc->capabilities) & CAP_PLL_MASK;
1839 + if (pll_type == PLL_TYPE6) {
1840 + clockcontrol_n = NULL;
1841 + clockcontrol_sb = NULL;
1842 + clockcontrol_pci = NULL;
1843 + } else {
1844 + clockcontrol_n = &cc->clockcontrol_n;
1845 + clockcontrol_sb = &cc->clockcontrol_sb;
1846 + clockcontrol_pci = &cc->clockcontrol_pci;
1847 + clockcontrol_m2 = &cc->clockcontrol_m2;
1848 + }
1849 + } else
1850 + goto done;
1851 +
1852 + if (pll_type == PLL_TYPE6) {
1853 + /* Silence compilers */
1854 + orig_n = orig_sb = orig_pci = 0;
1855 + } else {
1856 + /* Store the current clock register values */
1857 + orig_n = R_REG(clockcontrol_n);
1858 + orig_sb = R_REG(clockcontrol_sb);
1859 + orig_pci = R_REG(clockcontrol_pci);
1860 + }
1861 +
1862 + if (pll_type == PLL_TYPE1) {
1863 + /* Keep the current PCI clock if not specified */
1864 + if (pciclock == 0) {
1865 + pciclock = sb_clock_rate(pll_type, R_REG(clockcontrol_n), R_REG(clockcontrol_pci));
1866 + pciclock = (pciclock <= 25000000) ? 25000000 : 33000000;
1867 + }
1868 +
1869 + /* Search for the closest MIPS clock less than or equal to a preferred value */
1870 + for (i = 0; i < ARRAYSIZE(BCMINIT(type1_table)); i++) {
1871 + ASSERT(BCMINIT(type1_table)[i].mipsclock ==
1872 + sb_clock_rate(pll_type, BCMINIT(type1_table)[i].n, BCMINIT(type1_table)[i].sb));
1873 + if (BCMINIT(type1_table)[i].mipsclock > mipsclock)
1874 + break;
1875 + }
1876 + if (i == 0) {
1877 + ret = FALSE;
1878 + goto done;
1879 + } else {
1880 + ret = TRUE;
1881 + i--;
1882 + }
1883 + ASSERT(BCMINIT(type1_table)[i].mipsclock <= mipsclock);
1884 +
1885 + /* No PLL change */
1886 + if ((orig_n == BCMINIT(type1_table)[i].n) &&
1887 + (orig_sb == BCMINIT(type1_table)[i].sb) &&
1888 + (orig_pci == BCMINIT(type1_table)[i].pci33))
1889 + goto done;
1890 +
1891 + /* Set the PLL controls */
1892 + W_REG(clockcontrol_n, BCMINIT(type1_table)[i].n);
1893 + W_REG(clockcontrol_sb, BCMINIT(type1_table)[i].sb);
1894 + if (pciclock == 25000000)
1895 + W_REG(clockcontrol_pci, BCMINIT(type1_table)[i].pci25);
1896 + else
1897 + W_REG(clockcontrol_pci, BCMINIT(type1_table)[i].pci33);
1898 +
1899 + /* Reset */
1900 + sb_watchdog(sbh, 1);
1901 +
1902 + while (1);
1903 + } else if ((pll_type == PLL_TYPE3) &&
1904 + (BCMINIT(sb_chip)(sbh) != BCM5365_DEVICE_ID)) {
1905 + /* 5350 */
1906 + /* Search for the closest MIPS clock less than or equal to a preferred value */
1907 +
1908 + for (i = 0; i < ARRAYSIZE(type3_table); i++) {
1909 + if (type3_table[i].mipsclock > mipsclock)
1910 + break;
1911 + }
1912 + if (i == 0) {
1913 + ret = FALSE;
1914 + goto done;
1915 + } else {
1916 + ret = TRUE;
1917 + i--;
1918 + }
1919 + ASSERT(type3_table[i].mipsclock <= mipsclock);
1920 +
1921 + /* No PLL change */
1922 + orig_m2 = R_REG(&cc->clockcontrol_m2);
1923 + if ((orig_n == type3_table[i].n) &&
1924 + (orig_m2 == type3_table[i].m2)) {
1925 + goto done;
1926 + }
1927 +
1928 + /* Set the PLL controls */
1929 + W_REG(clockcontrol_n, type3_table[i].n);
1930 + W_REG(clockcontrol_m2, type3_table[i].m2);
1931 +
1932 + /* Reset */
1933 + sb_watchdog(sbh, 1);
1934 + while (1);
1935 + } else if ((pll_type == PLL_TYPE2) ||
1936 + (pll_type == PLL_TYPE4) ||
1937 + (pll_type == PLL_TYPE6) ||
1938 + (pll_type == PLL_TYPE7)) {
1939 + n4m_table_t *table = NULL, *te;
1940 + uint tabsz = 0;
1941 +
1942 + ASSERT(cc);
1943 +
1944 + orig_mips = R_REG(&cc->clockcontrol_mips);
1945 +
1946 + if (pll_type == PLL_TYPE6) {
1947 + uint32 new_mips = 0;
1948 +
1949 + ret = TRUE;
1950 + if (mipsclock <= SB2MIPS_T6(CC_T6_M1))
1951 + new_mips = CC_T6_MMASK;
1952 +
1953 + if (orig_mips == new_mips)
1954 + goto done;
1955 +
1956 + W_REG(&cc->clockcontrol_mips, new_mips);
1957 + goto end_fill;
1958 + }
1959 +
1960 + if (pll_type == PLL_TYPE2) {
1961 + table = BCMINIT(type2_table);
1962 + tabsz = ARRAYSIZE(BCMINIT(type2_table));
1963 + } else if (pll_type == PLL_TYPE4) {
1964 + table = BCMINIT(type4_table);
1965 + tabsz = ARRAYSIZE(BCMINIT(type4_table));
1966 + } else if (pll_type == PLL_TYPE7) {
1967 + table = BCMINIT(type7_table);
1968 + tabsz = ARRAYSIZE(BCMINIT(type7_table));
1969 + } else
1970 + ASSERT("No table for plltype" == NULL);
1971 +
1972 + /* Store the current clock register values */
1973 + orig_m2 = R_REG(&cc->clockcontrol_m2);
1974 + orig_ratio_parm = 0;
1975 + orig_ratio_cfg = 0;
1976 +
1977 + /* Look up current ratio */
1978 + for (i = 0; i < tabsz; i++) {
1979 + if ((orig_n == table[i].n) &&
1980 + (orig_sb == table[i].sb) &&
1981 + (orig_pci == table[i].pci33) &&
1982 + (orig_m2 == table[i].m2) &&
1983 + (orig_mips == table[i].m3)) {
1984 + orig_ratio_parm = table[i].ratio_parm;
1985 + orig_ratio_cfg = table[i].ratio_cfg;
1986 + break;
1987 + }
1988 + }
1989 +
1990 + /* Search for the closest MIPS clock greater or equal to a preferred value */
1991 + for (i = 0; i < tabsz; i++) {
1992 + ASSERT(table[i].mipsclock ==
1993 + sb_clock_rate(pll_type, table[i].n, table[i].m3));
1994 + if ((mipsclock <= table[i].mipsclock) &&
1995 + ((sbclock == 0) || (sbclock <= table[i].sbclock)))
1996 + break;
1997 + }
1998 + if (i == tabsz) {
1999 + ret = FALSE;
2000 + goto done;
2001 + } else {
2002 + te = &table[i];
2003 + ret = TRUE;
2004 + }
2005 +
2006 + /* No PLL change */
2007 + if ((orig_n == te->n) &&
2008 + (orig_sb == te->sb) &&
2009 + (orig_pci == te->pci33) &&
2010 + (orig_m2 == te->m2) &&
2011 + (orig_mips == te->m3))
2012 + goto done;
2013 +
2014 + /* Set the PLL controls */
2015 + W_REG(clockcontrol_n, te->n);
2016 + W_REG(clockcontrol_sb, te->sb);
2017 + W_REG(clockcontrol_pci, te->pci33);
2018 + W_REG(&cc->clockcontrol_m2, te->m2);
2019 + W_REG(&cc->clockcontrol_mips, te->m3);
2020 +
2021 + /* Set the chipcontrol bit to change mipsref to the backplane divider if needed */
2022 + if ((pll_type == PLL_TYPE7) &&
2023 + (te->sb != te->m2) &&
2024 + (sb_clock_rate(pll_type, te->n, te->m2) == 120000000))
2025 + W_REG(&cc->chipcontrol, R_REG(&cc->chipcontrol) | 0x100);
2026 +
2027 + /* No ratio change */
2028 + if (orig_ratio_parm == te->ratio_parm)
2029 + goto end_fill;
2030 +
2031 + icache_probe(MFC0(C0_CONFIG, 1), &ic_size, &ic_lsize);
2032 +
2033 + /* Preload the code into the cache */
2034 + start = ((ulong) &&start_fill) & ~(ic_lsize - 1);
2035 + end = ((ulong) &&end_fill + (ic_lsize - 1)) & ~(ic_lsize - 1);
2036 + while (start < end) {
2037 + cache_op(start, Fill_I);
2038 + start += ic_lsize;
2039 + }
2040 +
2041 + /* Copy the handler */
2042 + start = (ulong) &BCMINIT(handler);
2043 + end = (ulong) &BCMINIT(afterhandler);
2044 + dst = KSEG1ADDR(0x180);
2045 + for (i = 0; i < (end - start); i += 4)
2046 + *((ulong *)(dst + i)) = *((ulong *)(start + i));
2047 +
2048 + /* Preload handler into the cache one line at a time */
2049 + for (i = 0; i < (end - start); i += 4)
2050 + cache_op(dst + i, Fill_I);
2051 +
2052 + /* Clear BEV bit */
2053 + MTC0(C0_STATUS, 0, MFC0(C0_STATUS, 0) & ~ST0_BEV);
2054 +
2055 + /* Enable interrupts */
2056 + MTC0(C0_STATUS, 0, MFC0(C0_STATUS, 0) | (ALLINTS | ST0_IE));
2057 +
2058 + /* Enable MIPS timer interrupt */
2059 + if (!(mipsr = sb_setcore(sbh, SB_MIPS, 0)) &&
2060 + !(mipsr = sb_setcore(sbh, SB_MIPS33, 0)))
2061 + ASSERT(mipsr);
2062 + W_REG(&mipsr->intmask, 1);
2063 +
2064 + start_fill:
2065 + /* step 1, set clock ratios */
2066 + MTC0(C0_BROADCOM, 3, te->ratio_parm);
2067 + MTC0(C0_BROADCOM, 1, te->ratio_cfg);
2068 +
2069 + /* step 2: program timer intr */
2070 + W_REG(&mipsr->timer, 100);
2071 + (void) R_REG(&mipsr->timer);
2072 +
2073 + /* step 3, switch to async */
2074 + sync_mode = MFC0(C0_BROADCOM, 4);
2075 + MTC0(C0_BROADCOM, 4, 1 << 22);
2076 +
2077 + /* step 4, set cfg active */
2078 + MTC0(C0_BROADCOM, 2, 0x9);
2079 +
2080 +
2081 + /* steps 5 & 6 */
2082 + __asm__ __volatile__ (
2083 + ".set\tmips3\n\t"
2084 + "wait\n\t"
2085 + ".set\tmips0"
2086 + );
2087 +
2088 + /* step 7, clear cfg_active */
2089 + MTC0(C0_BROADCOM, 2, 0);
2090 +
2091 + /* Additional Step: set back to orig sync mode */
2092 + MTC0(C0_BROADCOM, 4, sync_mode);
2093 +
2094 + /* step 8, fake soft reset */
2095 + MTC0(C0_BROADCOM, 5, MFC0(C0_BROADCOM, 5) | 4);
2096 +
2097 + end_fill:
2098 + /* step 9 set watchdog timer */
2099 + sb_watchdog(sbh, 20);
2100 + (void) R_REG(&cc->chipid);
2101 +
2102 + /* step 11 */
2103 + __asm__ __volatile__ (
2104 + ".set\tmips3\n\t"
2105 + "sync\n\t"
2106 + "wait\n\t"
2107 + ".set\tmips0"
2108 + );
2109 + while (1);
2110 + }
2111 +
2112 +done:
2113 + /* switch back to previous core */
2114 + sb_setcoreidx(sbh, idx);
2115 +
2116 + return ret;
2117 +}
2118 +
2119 +/*
2120 + * This also must be run from the cache on 47xx
2121 + * so there are no mips core BIU ops in progress
2122 + * when the PFC is enabled.
2123 + */
2124 +
2125 +static void
2126 +BCMINITFN(_enable_pfc)(uint32 mode)
2127 +{
2128 + /* write range */
2129 + *(volatile uint32 *)PFC_CR1 = 0xffff0000;
2130 +
2131 + /* enable */
2132 + *(volatile uint32 *)PFC_CR0 = mode;
2133 +}
2134 +
2135 +void
2136 +BCMINITFN(enable_pfc)(uint32 mode)
2137 +{
2138 + ulong start, end;
2139 + int i;
2140 +
2141 + /* If auto then choose the correct mode for this
2142 + platform, currently we only ever select one mode */
2143 + if (mode == PFC_AUTO)
2144 + mode = PFC_INST;
2145 +
2146 + /* enable prefetch cache if available */
2147 + if (MFC0(C0_BROADCOM, 0) & BRCM_PFC_AVAIL) {
2148 + start = (ulong) &BCMINIT(_enable_pfc);
2149 + end = (ulong) &BCMINIT(enable_pfc);
2150 +
2151 + /* Preload handler into the cache one line at a time */
2152 + for (i = 0; i < (end - start); i += 4)
2153 + cache_op(start + i, Fill_I);
2154 +
2155 + BCMINIT(_enable_pfc)(mode);
2156 + }
2157 +}
2158 +
2159 +/* returns the ncdl value to be programmed into sdram_ncdl for calibration */
2160 +uint32
2161 +BCMINITFN(sb_memc_get_ncdl)(sb_t *sbh)
2162 +{
2163 + sbmemcregs_t *memc;
2164 + uint32 ret = 0;
2165 + uint32 config, rd, wr, misc, dqsg, cd, sm, sd;
2166 + uint idx, rev;
2167 +
2168 + idx = sb_coreidx(sbh);
2169 +
2170 + memc = (sbmemcregs_t *)sb_setcore(sbh, SB_MEMC, 0);
2171 + if (memc == 0)
2172 + goto out;
2173 +
2174 + rev = sb_corerev(sbh);
2175 +
2176 + config = R_REG(&memc->config);
2177 + wr = R_REG(&memc->wrncdlcor);
2178 + rd = R_REG(&memc->rdncdlcor);
2179 + misc = R_REG(&memc->miscdlyctl);
2180 + dqsg = R_REG(&memc->dqsgatencdl);
2181 +
2182 + rd &= MEMC_RDNCDLCOR_RD_MASK;
2183 + wr &= MEMC_WRNCDLCOR_WR_MASK;
2184 + dqsg &= MEMC_DQSGATENCDL_G_MASK;
2185 +
2186 + if (config & MEMC_CONFIG_DDR) {
2187 + ret = (wr << 16) | (rd << 8) | dqsg;
2188 + } else {
2189 + if (rev > 0)
2190 + cd = rd;
2191 + else
2192 + cd = (rd == MEMC_CD_THRESHOLD) ? rd : (wr + MEMC_CD_THRESHOLD);
2193 + sm = (misc & MEMC_MISC_SM_MASK) >> MEMC_MISC_SM_SHIFT;
2194 + sd = (misc & MEMC_MISC_SD_MASK) >> MEMC_MISC_SD_SHIFT;
2195 + ret = (sm << 16) | (sd << 8) | cd;
2196 + }
2197 +
2198 +out:
2199 + /* switch back to previous core */
2200 + sb_setcoreidx(sbh, idx);
2201 +
2202 + return ret;
2203 +}
2204 +
2205 diff -urN linux.old/arch/mips/bcm947xx/broadcom/sbpci.c linux.dev/arch/mips/bcm947xx/broadcom/sbpci.c
2206 --- linux.old/arch/mips/bcm947xx/broadcom/sbpci.c 1970-01-01 01:00:00.000000000 +0100
2207 +++ linux.dev/arch/mips/bcm947xx/broadcom/sbpci.c 2005-12-15 23:50:31.846688500 +0100
2208 @@ -0,0 +1,531 @@
2209 +/*
2210 + * Low-Level PCI and SB support for BCM47xx
2211 + *
2212 + * Copyright 2005, Broadcom Corporation
2213 + * All Rights Reserved.
2214 + *
2215 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
2216 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
2217 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
2218 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
2219 + *
2220 + * $Id$
2221 + */
2222 +
2223 +#include <typedefs.h>
2224 +#include <pcicfg.h>
2225 +#include <bcmdevs.h>
2226 +#include <sbconfig.h>
2227 +#include <osl.h>
2228 +#include <sbutils.h>
2229 +#include <sbpci.h>
2230 +#include <bcmendian.h>
2231 +#include <bcmutils.h>
2232 +#include <bcmnvram.h>
2233 +#include <hndmips.h>
2234 +
2235 +/* Can free sbpci_init() memory after boot */
2236 +#ifndef linux
2237 +#define __init
2238 +#endif
2239 +
2240 +/* Emulated configuration space */
2241 +static pci_config_regs sb_config_regs[SB_MAXCORES];
2242 +
2243 +/* Banned cores */
2244 +static uint16 pci_ban[32] = { 0 };
2245 +static uint pci_banned = 0;
2246 +
2247 +/* CardBus mode */
2248 +static bool cardbus = FALSE;
2249 +
2250 +/* Disable PCI host core */
2251 +static bool pci_disabled = FALSE;
2252 +
2253 +/*
2254 + * Functions for accessing external PCI configuration space
2255 + */
2256 +
2257 +/* Assume one-hot slot wiring */
2258 +#define PCI_SLOT_MAX 16
2259 +
2260 +static uint32
2261 +config_cmd(sb_t *sbh, uint bus, uint dev, uint func, uint off)
2262 +{
2263 + uint coreidx;
2264 + sbpciregs_t *regs;
2265 + uint32 addr = 0;
2266 +
2267 + /* CardBusMode supports only one device */
2268 + if (cardbus && dev > 1)
2269 + return 0;
2270 +
2271 + coreidx = sb_coreidx(sbh);
2272 + regs = (sbpciregs_t *) sb_setcore(sbh, SB_PCI, 0);
2273 +
2274 + /* Type 0 transaction */
2275 + if (bus == 1) {
2276 + /* Skip unwired slots */
2277 + if (dev < PCI_SLOT_MAX) {
2278 + /* Slide the PCI window to the appropriate slot */
2279 + W_REG(&regs->sbtopci1, SBTOPCI_CFG0 | ((1 << (dev + 16)) & SBTOPCI1_MASK));
2280 + addr = SB_PCI_CFG | ((1 << (dev + 16)) & ~SBTOPCI1_MASK) |
2281 + (func << 8) | (off & ~3);
2282 + }
2283 + }
2284 +
2285 + /* Type 1 transaction */
2286 + else {
2287 + W_REG(&regs->sbtopci1, SBTOPCI_CFG1);
2288 + addr = SB_PCI_CFG | (bus << 16) | (dev << 11) | (func << 8) | (off & ~3);
2289 + }
2290 +
2291 + sb_setcoreidx(sbh, coreidx);
2292 +
2293 + return addr;
2294 +}
2295 +
2296 +static int
2297 +extpci_read_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
2298 +{
2299 + uint32 addr, *reg = NULL, val;
2300 + int ret = 0;
2301 +
2302 + if (pci_disabled ||
2303 + !(addr = config_cmd(sbh, bus, dev, func, off)) ||
2304 + !(reg = (uint32 *) REG_MAP(addr, len)) ||
2305 + BUSPROBE(val, reg))
2306 + val = 0xffffffff;
2307 +
2308 + val >>= 8 * (off & 3);
2309 + if (len == 4)
2310 + *((uint32 *) buf) = val;
2311 + else if (len == 2)
2312 + *((uint16 *) buf) = (uint16) val;
2313 + else if (len == 1)
2314 + *((uint8 *) buf) = (uint8) val;
2315 + else
2316 + ret = -1;
2317 +
2318 + if (reg)
2319 + REG_UNMAP(reg);
2320 +
2321 + return ret;
2322 +}
2323 +
2324 +static int
2325 +extpci_write_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
2326 +{
2327 + uint32 addr, *reg = NULL, val;
2328 + int ret = 0;
2329 +
2330 + if (pci_disabled ||
2331 + !(addr = config_cmd(sbh, bus, dev, func, off)) ||
2332 + !(reg = (uint32 *) REG_MAP(addr, len)) ||
2333 + BUSPROBE(val, reg))
2334 + goto done;
2335 +
2336 + if (len == 4)
2337 + val = *((uint32 *) buf);
2338 + else if (len == 2) {
2339 + val &= ~(0xffff << (8 * (off & 3)));
2340 + val |= *((uint16 *) buf) << (8 * (off & 3));
2341 + } else if (len == 1) {
2342 + val &= ~(0xff << (8 * (off & 3)));
2343 + val |= *((uint8 *) buf) << (8 * (off & 3));
2344 + } else
2345 + ret = -1;
2346 +
2347 + W_REG(reg, val);
2348 +
2349 + done:
2350 + if (reg)
2351 + REG_UNMAP(reg);
2352 +
2353 + return ret;
2354 +}
2355 +
2356 +/*
2357 + * Functions for accessing translated SB configuration space
2358 + */
2359 +
2360 +static int
2361 +sb_read_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
2362 +{
2363 + pci_config_regs *cfg;
2364 +
2365 + if (dev >= SB_MAXCORES || (off + len) > sizeof(pci_config_regs))
2366 + return -1;
2367 + cfg = &sb_config_regs[dev];
2368 +
2369 + ASSERT(ISALIGNED(off, len));
2370 + ASSERT(ISALIGNED((uintptr)buf, len));
2371 +
2372 + if (len == 4)
2373 + *((uint32 *) buf) = ltoh32(*((uint32 *)((ulong) cfg + off)));
2374 + else if (len == 2)
2375 + *((uint16 *) buf) = ltoh16(*((uint16 *)((ulong) cfg + off)));
2376 + else if (len == 1)
2377 + *((uint8 *) buf) = *((uint8 *)((ulong) cfg + off));
2378 + else
2379 + return -1;
2380 +
2381 + return 0;
2382 +}
2383 +
2384 +static int
2385 +sb_write_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
2386 +{
2387 + uint coreidx, n;
2388 + void *regs;
2389 + sbconfig_t *sb;
2390 + pci_config_regs *cfg;
2391 +
2392 + if (dev >= SB_MAXCORES || (off + len) > sizeof(pci_config_regs))
2393 + return -1;
2394 + cfg = &sb_config_regs[dev];
2395 +
2396 + ASSERT(ISALIGNED(off, len));
2397 + ASSERT(ISALIGNED((uintptr)buf, len));
2398 +
2399 + /* Emulate BAR sizing */
2400 + if (off >= OFFSETOF(pci_config_regs, base[0]) && off <= OFFSETOF(pci_config_regs, base[3]) &&
2401 + len == 4 && *((uint32 *) buf) == ~0) {
2402 + coreidx = sb_coreidx(sbh);
2403 + if ((regs = sb_setcoreidx(sbh, dev))) {
2404 + sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
2405 + /* Highest numbered address match register */
2406 + n = (R_REG(&sb->sbidlow) & SBIDL_AR_MASK) >> SBIDL_AR_SHIFT;
2407 + if (off == OFFSETOF(pci_config_regs, base[0]))
2408 + cfg->base[0] = ~(sb_size(R_REG(&sb->sbadmatch0)) - 1);
2409 +#if 0
2410 + else if (off == OFFSETOF(pci_config_regs, base[1]) && n >= 1)
2411 + cfg->base[1] = ~(sb_size(R_REG(&sb->sbadmatch1)) - 1);
2412 + else if (off == OFFSETOF(pci_config_regs, base[2]) && n >= 2)
2413 + cfg->base[2] = ~(sb_size(R_REG(&sb->sbadmatch2)) - 1);
2414 + else if (off == OFFSETOF(pci_config_regs, base[3]) && n >= 3)
2415 + cfg->base[3] = ~(sb_size(R_REG(&sb->sbadmatch3)) - 1);
2416 +#endif
2417 + }
2418 + sb_setcoreidx(sbh, coreidx);
2419 + return 0;
2420 + }
2421 +
2422 + if (len == 4)
2423 + *((uint32 *)((ulong) cfg + off)) = htol32(*((uint32 *) buf));
2424 + else if (len == 2)
2425 + *((uint16 *)((ulong) cfg + off)) = htol16(*((uint16 *) buf));
2426 + else if (len == 1)
2427 + *((uint8 *)((ulong) cfg + off)) = *((uint8 *) buf);
2428 + else
2429 + return -1;
2430 +
2431 + return 0;
2432 +}
2433 +
2434 +int
2435 +sbpci_read_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
2436 +{
2437 + if (bus == 0)
2438 + return sb_read_config(sbh, bus, dev, func, off, buf, len);
2439 + else
2440 + return extpci_read_config(sbh, bus, dev, func, off, buf, len);
2441 +}
2442 +
2443 +int
2444 +sbpci_write_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len)
2445 +{
2446 + if (bus == 0)
2447 + return sb_write_config(sbh, bus, dev, func, off, buf, len);
2448 + else
2449 + return extpci_write_config(sbh, bus, dev, func, off, buf, len);
2450 +}
2451 +
2452 +void
2453 +sbpci_ban(uint16 core)
2454 +{
2455 + if (pci_banned < ARRAYSIZE(pci_ban))
2456 + pci_ban[pci_banned++] = core;
2457 +}
2458 +
2459 +static int
2460 +sbpci_init_pci(sb_t *sbh)
2461 +{
2462 + uint chip, chiprev, chippkg, host;
2463 + uint32 boardflags;
2464 + sbpciregs_t *pci;
2465 + sbconfig_t *sb;
2466 + uint32 val;
2467 +
2468 + chip = sb_chip(sbh);
2469 + chiprev = sb_chiprev(sbh);
2470 + chippkg = sb_chippkg(sbh);
2471 +
2472 + if (!(pci = (sbpciregs_t *) sb_setcore(sbh, SB_PCI, 0))) {
2473 + printf("PCI: no core\n");
2474 + pci_disabled = TRUE;
2475 + return -1;
2476 + }
2477 + sb_core_reset(sbh, 0);
2478 +
2479 + boardflags = (uint32) getintvar(NULL, "boardflags");
2480 +
2481 + if ((chip == BCM4310_DEVICE_ID) && (chiprev == 0))
2482 + pci_disabled = TRUE;
2483 +
2484 + /*
2485 + * The 200-pin BCM4712 package does not bond out PCI. Even when
2486 + * PCI is bonded out, some boards may leave the pins
2487 + * floating.
2488 + */
2489 + if (((chip == BCM4712_DEVICE_ID) &&
2490 + ((chippkg == BCM4712SMALL_PKG_ID) ||
2491 + (chippkg == BCM4712MID_PKG_ID))) ||
2492 + (boardflags & BFL_NOPCI))
2493 + pci_disabled = TRUE;
2494 +
2495 + /*
2496 + * If the PCI core should not be touched (disabled, not bonded
2497 + * out, or pins floating), do not even attempt to access core
2498 + * registers. Otherwise, try to determine if it is in host
2499 + * mode.
2500 + */
2501 + if (pci_disabled)
2502 + host = 0;
2503 + else
2504 + host = !BUSPROBE(val, &pci->control);
2505 +
2506 + if (!host) {
2507 + /* Disable PCI interrupts in client mode */
2508 + sb = (sbconfig_t *)((ulong) pci + SBCONFIGOFF);
2509 + W_REG(&sb->sbintvec, 0);
2510 +
2511 + /* Disable the PCI bridge in client mode */
2512 + sbpci_ban(SB_PCI);
2513 + printf("PCI: Disabled\n");
2514 + } else {
2515 + /* Reset the external PCI bus and enable the clock */
2516 + W_REG(&pci->control, 0x5); /* enable the tristate drivers */
2517 + W_REG(&pci->control, 0xd); /* enable the PCI clock */
2518 + OSL_DELAY(150); /* delay > 100 us */
2519 + W_REG(&pci->control, 0xf); /* deassert PCI reset */
2520 + W_REG(&pci->arbcontrol, PCI_INT_ARB); /* use internal arbiter */
2521 + OSL_DELAY(1); /* delay 1 us */
2522 +
2523 + /* Enable CardBusMode */
2524 + cardbus = nvram_match("cardbus", "1");
2525 + if (cardbus) {
2526 + printf("PCI: Enabling CardBus\n");
2527 + /* GPIO 1 resets the CardBus device on bcm94710ap */
2528 + sb_gpioout(sbh, 1, 1, GPIO_DRV_PRIORITY);
2529 + sb_gpioouten(sbh, 1, 1, GPIO_DRV_PRIORITY);
2530 + W_REG(&pci->sprom[0], R_REG(&pci->sprom[0]) | 0x400);
2531 + }
2532 +
2533 + /* 64 MB I/O access window */
2534 + W_REG(&pci->sbtopci0, SBTOPCI_IO);
2535 + /* 64 MB configuration access window */
2536 + W_REG(&pci->sbtopci1, SBTOPCI_CFG0);
2537 + /* 1 GB memory access window */
2538 + W_REG(&pci->sbtopci2, SBTOPCI_MEM | SB_PCI_DMA);
2539 +
2540 + /* Enable PCI bridge BAR0 prefetch and burst */
2541 + val = 6;
2542 + sbpci_write_config(sbh, 1, 0, 0, PCI_CFG_CMD, &val, sizeof(val));
2543 +
2544 + /* Enable PCI interrupts */
2545 + W_REG(&pci->intmask, PCI_INTA);
2546 + }
2547 +
2548 + return 0;
2549 +}
2550 +
2551 +static int
2552 +sbpci_init_cores(sb_t *sbh)
2553 +{
2554 + uint chip, chiprev, chippkg, coreidx, i;
2555 + sbconfig_t *sb;
2556 + pci_config_regs *cfg;
2557 + void *regs;
2558 + char varname[8];
2559 + uint wlidx = 0;
2560 + uint16 vendor, core;
2561 + uint8 class, subclass, progif;
2562 + uint32 val;
2563 + uint32 sbips_int_mask[] = { 0, SBIPS_INT1_MASK, SBIPS_INT2_MASK, SBIPS_INT3_MASK, SBIPS_INT4_MASK };
2564 + uint32 sbips_int_shift[] = { 0, 0, SBIPS_INT2_SHIFT, SBIPS_INT3_SHIFT, SBIPS_INT4_SHIFT };
2565 +
2566 + chip = sb_chip(sbh);
2567 + chiprev = sb_chiprev(sbh);
2568 + chippkg = sb_chippkg(sbh);
2569 + coreidx = sb_coreidx(sbh);
2570 +
2571 + /* Scan the SB bus */
2572 + bzero(sb_config_regs, sizeof(sb_config_regs));
2573 + for (cfg = sb_config_regs; cfg < &sb_config_regs[SB_MAXCORES]; cfg++) {
2574 + cfg->vendor = 0xffff;
2575 + if (!(regs = sb_setcoreidx(sbh, cfg - sb_config_regs)))
2576 + continue;
2577 + sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
2578 +
2579 + /* Read ID register and parse vendor and core */
2580 + val = R_REG(&sb->sbidhigh);
2581 + vendor = (val & SBIDH_VC_MASK) >> SBIDH_VC_SHIFT;
2582 + core = (val & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT;
2583 + progif = 0;
2584 +
2585 + /* Check if this core is banned */
2586 + for (i = 0; i < pci_banned; i++)
2587 + if (core == pci_ban[i])
2588 + break;
2589 + if (i < pci_banned)
2590 + continue;
2591 +
2592 + /* Known vendor translations */
2593 + switch (vendor) {
2594 + case SB_VEND_BCM:
2595 + vendor = VENDOR_BROADCOM;
2596 + break;
2597 + }
2598 +
2599 + /* Determine class based on known core codes */
2600 + switch (core) {
2601 + case SB_ILINE20:
2602 + class = PCI_CLASS_NET;
2603 + subclass = PCI_NET_ETHER;
2604 + core = BCM47XX_ILINE_ID;
2605 + break;
2606 + case SB_ILINE100:
2607 + class = PCI_CLASS_NET;
2608 + subclass = PCI_NET_ETHER;
2609 + core = BCM4610_ILINE_ID;
2610 + break;
2611 + case SB_ENET:
2612 + class = PCI_CLASS_NET;
2613 + subclass = PCI_NET_ETHER;
2614 + core = BCM47XX_ENET_ID;
2615 + break;
2616 + case SB_SDRAM:
2617 + case SB_MEMC:
2618 + class = PCI_CLASS_MEMORY;
2619 + subclass = PCI_MEMORY_RAM;
2620 + break;
2621 + case SB_PCI:
2622 + class = PCI_CLASS_BRIDGE;
2623 + subclass = PCI_BRIDGE_PCI;
2624 + break;
2625 + case SB_MIPS:
2626 + case SB_MIPS33:
2627 + class = PCI_CLASS_CPU;
2628 + subclass = PCI_CPU_MIPS;
2629 + break;
2630 + case SB_CODEC:
2631 + class = PCI_CLASS_COMM;
2632 + subclass = PCI_COMM_MODEM;
2633 + core = BCM47XX_V90_ID;
2634 + break;
2635 + case SB_USB:
2636 + class = PCI_CLASS_SERIAL;
2637 + subclass = PCI_SERIAL_USB;
2638 + progif = 0x10; /* OHCI */
2639 + core = BCM47XX_USB_ID;
2640 + break;
2641 + case SB_USB11H:
2642 + class = PCI_CLASS_SERIAL;
2643 + subclass = PCI_SERIAL_USB;
2644 + progif = 0x10; /* OHCI */
2645 + core = BCM47XX_USBH_ID;
2646 + break;
2647 + case SB_USB11D:
2648 + class = PCI_CLASS_SERIAL;
2649 + subclass = PCI_SERIAL_USB;
2650 + core = BCM47XX_USBD_ID;
2651 + break;
2652 + case SB_IPSEC:
2653 + class = PCI_CLASS_CRYPT;
2654 + subclass = PCI_CRYPT_NETWORK;
2655 + core = BCM47XX_IPSEC_ID;
2656 + break;
2657 + case SB_ROBO:
2658 + class = PCI_CLASS_NET;
2659 + subclass = PCI_NET_OTHER;
2660 + core = BCM47XX_ROBO_ID;
2661 + break;
2662 + case SB_EXTIF:
2663 + case SB_CC:
2664 + class = PCI_CLASS_MEMORY;
2665 + subclass = PCI_MEMORY_FLASH;
2666 + break;
2667 + case SB_D11:
2668 + class = PCI_CLASS_NET;
2669 + subclass = PCI_NET_OTHER;
2670 + /* Let an nvram variable override this */
2671 + sprintf(varname, "wl%did", wlidx);
2672 + wlidx++;
2673 + if ((core = getintvar(NULL, varname)) == 0) {
2674 + if (chip == BCM4712_DEVICE_ID) {
2675 + if (chippkg == BCM4712SMALL_PKG_ID)
2676 + core = BCM4306_D11G_ID;
2677 + else
2678 + core = BCM4306_D11DUAL_ID;
2679 + } else {
2680 + /* 4310 */
2681 + core = BCM4310_D11B_ID;
2682 + }
2683 + }
2684 + break;
2685 +
2686 + default:
2687 + class = subclass = progif = 0xff;
2688 + break;
2689 + }
2690 +
2691 + /* Supported translations */
2692 + cfg->vendor = htol16(vendor);
2693 + cfg->device = htol16(core);
2694 + cfg->rev_id = chiprev;
2695 + cfg->prog_if = progif;
2696 + cfg->sub_class = subclass;
2697 + cfg->base_class = class;
2698 + cfg->base[0] = htol32(sb_base(R_REG(&sb->sbadmatch0)));
2699 + cfg->base[1] = 0;//htol32(sb_base(R_REG(&sb->sbadmatch1)));
2700 + cfg->base[2] = 0;//htol32(sb_base(R_REG(&sb->sbadmatch2)));
2701 + cfg->base[3] = 0;//htol32(sb_base(R_REG(&sb->sbadmatch3)));
2702 + cfg->base[4] = 0;
2703 + cfg->base[5] = 0;
2704 + if (class == PCI_CLASS_BRIDGE && subclass == PCI_BRIDGE_PCI)
2705 + cfg->header_type = PCI_HEADER_BRIDGE;
2706 + else
2707 + cfg->header_type = PCI_HEADER_NORMAL;
2708 + /* Save core interrupt flag */
2709 + cfg->int_pin = R_REG(&sb->sbtpsflag) & SBTPS_NUM0_MASK;
2710 + /* Default to MIPS shared interrupt 0 */
2711 + cfg->int_line = 0;
2712 + /* MIPS sbipsflag maps core interrupt flags to interrupts 1 through 4 */
2713 + if ((regs = sb_setcore(sbh, SB_MIPS, 0)) ||
2714 + (regs = sb_setcore(sbh, SB_MIPS33, 0))) {
2715 + sb = (sbconfig_t *)((ulong) regs + SBCONFIGOFF);
2716 + val = R_REG(&sb->sbipsflag);
2717 + for (cfg->int_line = 1; cfg->int_line <= 4; cfg->int_line++) {
2718 + if (((val & sbips_int_mask[cfg->int_line]) >> sbips_int_shift[cfg->int_line]) == cfg->int_pin)
2719 + break;
2720 + }
2721 + if (cfg->int_line > 4)
2722 + cfg->int_line = 0;
2723 + }
2724 + /* Emulated core */
2725 + *((uint32 *) &cfg->sprom_control) = 0xffffffff;
2726 + }
2727 +
2728 + sb_setcoreidx(sbh, coreidx);
2729 + return 0;
2730 +}
2731 +
2732 +int __init
2733 +sbpci_init(sb_t *sbh)
2734 +{
2735 + sbpci_init_pci(sbh);
2736 + sbpci_init_cores(sbh);
2737 + return 0;
2738 +}
2739 +
2740 diff -urN linux.old/arch/mips/bcm947xx/broadcom/sbutils.c linux.dev/arch/mips/bcm947xx/broadcom/sbutils.c
2741 --- linux.old/arch/mips/bcm947xx/broadcom/sbutils.c 1970-01-01 01:00:00.000000000 +0100
2742 +++ linux.dev/arch/mips/bcm947xx/broadcom/sbutils.c 2005-12-15 17:31:12.211645500 +0100
2743 @@ -0,0 +1,2407 @@
2744 +/*
2745 + * Misc utility routines for accessing chip-specific features
2746 + * of the SiliconBackplane-based Broadcom chips.
2747 + *
2748 + * Copyright 2005, Broadcom Corporation
2749 + * All Rights Reserved.
2750 + *
2751 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
2752 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
2753 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
2754 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
2755 + * $Id$
2756 + */
2757 +
2758 +#include <typedefs.h>
2759 +#include <osl.h>
2760 +#include <sbutils.h>
2761 +#include <bcmutils.h>
2762 +#include <bcmdevs.h>
2763 +#include <sbconfig.h>
2764 +#include <sbchipc.h>
2765 +#include <sbpci.h>
2766 +#include <pcicfg.h>
2767 +#include <sbextif.h>
2768 +#include <bcmsrom.h>
2769 +
2770 +/* debug/trace */
2771 +#define SB_ERROR(args)
2772 +
2773 +
2774 +typedef uint32 (*sb_intrsoff_t)(void *intr_arg);
2775 +typedef void (*sb_intrsrestore_t)(void *intr_arg, uint32 arg);
2776 +typedef bool (*sb_intrsenabled_t)(void *intr_arg);
2777 +
2778 +/* misc sb info needed by some of the routines */
2779 +typedef struct sb_info {
2780 +
2781 + struct sb_pub sb; /* back plane public state(must be first field of sb_info */
2782 +
2783 + void *osh; /* osl os handle */
2784 + void *sdh; /* bcmsdh handle */
2785 +
2786 + void *curmap; /* current regs va */
2787 + void *regs[SB_MAXCORES]; /* other regs va */
2788 +
2789 + uint curidx; /* current core index */
2790 + uint dev_coreid; /* the core provides driver functions */
2791 +
2792 + uint gpioidx; /* gpio control core index */
2793 + uint gpioid; /* gpio control coretype */
2794 +
2795 + uint numcores; /* # discovered cores */
2796 + uint coreid[SB_MAXCORES]; /* id of each core */
2797 +
2798 + void *intr_arg; /* interrupt callback function arg */
2799 + sb_intrsoff_t intrsoff_fn; /* function turns chip interrupts off */
2800 + sb_intrsrestore_t intrsrestore_fn; /* function restore chip interrupts */
2801 + sb_intrsenabled_t intrsenabled_fn; /* function to check if chip interrupts are enabled */
2802 +
2803 +} sb_info_t;
2804 +
2805 +/* local prototypes */
2806 +static sb_info_t * BCMINIT(sb_doattach)(sb_info_t *si, uint devid, osl_t *osh, void *regs,
2807 + uint bustype, void *sdh, char **vars, int *varsz);
2808 +static void BCMINIT(sb_scan)(sb_info_t *si);
2809 +static uint sb_corereg(sb_info_t *si, uint coreidx, uint regoff, uint mask, uint val);
2810 +static uint _sb_coreidx(sb_info_t *si);
2811 +static uint sb_findcoreidx(sb_info_t *si, uint coreid, uint coreunit);
2812 +static uint BCMINIT(sb_pcidev2chip)(uint pcidev);
2813 +static uint BCMINIT(sb_chip2numcores)(uint chip);
2814 +static int sb_pci_fixcfg(sb_info_t *si);
2815 +
2816 +/* delay needed between the mdio control/ mdiodata register data access */
2817 +#define PR28829_DELAY() OSL_DELAY(10)
2818 +
2819 +
2820 +/* global variable to indicate reservation/release of gpio's*/
2821 +static uint32 sb_gpioreservation = 0;
2822 +
2823 +#define SB_INFO(sbh) (sb_info_t*)sbh
2824 +#define SET_SBREG(sbh, r, mask, val) W_SBREG((sbh), (r), ((R_SBREG((sbh), (r)) & ~(mask)) | (val)))
2825 +#define GOODCOREADDR(x) (((x) >= SB_ENUM_BASE) && ((x) <= SB_ENUM_LIM) && ISALIGNED((x), SB_CORE_SIZE))
2826 +#define GOODREGS(regs) ((regs) && ISALIGNED((uintptr)(regs), SB_CORE_SIZE))
2827 +#define REGS2SB(va) (sbconfig_t*) ((int8*)(va) + SBCONFIGOFF)
2828 +#define GOODIDX(idx) (((uint)idx) < SB_MAXCORES)
2829 +#define BADIDX (SB_MAXCORES+1)
2830 +#define NOREV -1
2831 +
2832 +#define PCI(si) ((BUSTYPE(si->sb.bustype) == PCI_BUS) && (si->sb.buscoretype == SB_PCI))
2833 +
2834 +/* sonicsrev */
2835 +#define SONICS_2_2 (SBIDL_RV_2_2 >> SBIDL_RV_SHIFT)
2836 +#define SONICS_2_3 (SBIDL_RV_2_3 >> SBIDL_RV_SHIFT)
2837 +
2838 +#define R_SBREG(sbh, sbr) sb_read_sbreg((sbh), (sbr))
2839 +#define W_SBREG(sbh, sbr, v) sb_write_sbreg((sbh), (sbr), (v))
2840 +#define AND_SBREG(sbh, sbr, v) W_SBREG((sbh), (sbr), (R_SBREG((sbh), (sbr)) & (v)))
2841 +#define OR_SBREG(sbh, sbr, v) W_SBREG((sbh), (sbr), (R_SBREG((sbh), (sbr)) | (v)))
2842 +
2843 +/*
2844 + * Macros to disable/restore function core(D11, ENET, ILINE20, etc) interrupts before/
2845 + * after core switching to avoid invalid register accesss inside ISR.
2846 + */
2847 +#define INTR_OFF(si, intr_val) \
2848 + if ((si)->intrsoff_fn && (si)->coreid[(si)->curidx] == (si)->dev_coreid) { \
2849 + intr_val = (*(si)->intrsoff_fn)((si)->intr_arg); }
2850 +#define INTR_RESTORE(si, intr_val) \
2851 + if ((si)->intrsrestore_fn && (si)->coreid[(si)->curidx] == (si)->dev_coreid) { \
2852 + (*(si)->intrsrestore_fn)((si)->intr_arg, intr_val); }
2853 +
2854 +/* dynamic clock control defines */
2855 +#define LPOMINFREQ 25000 /* low power oscillator min */
2856 +#define LPOMAXFREQ 43000 /* low power oscillator max */
2857 +#define XTALMINFREQ 19800000 /* 20 MHz - 1% */
2858 +#define XTALMAXFREQ 20200000 /* 20 MHz + 1% */
2859 +#define PCIMINFREQ 25000000 /* 25 MHz */
2860 +#define PCIMAXFREQ 34000000 /* 33 MHz + fudge */
2861 +
2862 +#define ILP_DIV_5MHZ 0 /* ILP = 5 MHz */
2863 +#define ILP_DIV_1MHZ 4 /* ILP = 1 MHz */
2864 +
2865 +#define MIN_DUMPBUFLEN 32 /* debug */
2866 +
2867 +/* GPIO Based LED powersave defines */
2868 +#define DEFAULT_GPIO_ONTIME 10
2869 +#define DEFAULT_GPIO_OFFTIME 90
2870 +
2871 +#define DEFAULT_GPIOTIMERVAL ((DEFAULT_GPIO_ONTIME << GPIO_ONTIME_SHIFT) | DEFAULT_GPIO_OFFTIME)
2872 +
2873 +static uint32
2874 +sb_read_sbreg(sb_info_t *si, volatile uint32 *sbr)
2875 +{
2876 + uint32 val = R_REG(sbr);
2877 +
2878 + return (val);
2879 +}
2880 +
2881 +static void
2882 +sb_write_sbreg(sb_info_t *si, volatile uint32 *sbr, uint32 v)
2883 +{
2884 + W_REG(sbr, v);
2885 +}
2886 +
2887 +/* Using sb_kattach depends on SB_BUS support, either implicit */
2888 +/* no limiting BCMBUSTYPE value) or explicit (value is SB_BUS). */
2889 +#if !defined(BCMBUSTYPE) || (BCMBUSTYPE == SB_BUS)
2890 +
2891 +/* global kernel resource */
2892 +static sb_info_t ksi;
2893 +
2894 +/* generic kernel variant of sb_attach() */
2895 +sb_t *
2896 +BCMINITFN(sb_kattach)()
2897 +{
2898 + uint32 *regs;
2899 +
2900 + if (ksi.curmap == NULL) {
2901 + uint32 cid;
2902 +
2903 + regs = (uint32 *)REG_MAP(SB_ENUM_BASE, SB_CORE_SIZE);
2904 + cid = R_REG((uint32 *)regs);
2905 + if (((cid & CID_ID_MASK) == BCM4712_DEVICE_ID) &&
2906 + ((cid & CID_PKG_MASK) != BCM4712LARGE_PKG_ID) &&
2907 + ((cid & CID_REV_MASK) <= (3 << CID_REV_SHIFT))) {
2908 + uint32 *scc, val;
2909 +
2910 + scc = (uint32 *)((uchar*)regs + OFFSETOF(chipcregs_t, slow_clk_ctl));
2911 + val = R_REG(scc);
2912 + SB_ERROR((" initial scc = 0x%x\n", val));
2913 + val |= SCC_SS_XTAL;
2914 + W_REG(scc, val);
2915 + }
2916 +
2917 + if (BCMINIT(sb_doattach)(&ksi, BCM4710_DEVICE_ID, NULL, (void*)regs,
2918 + SB_BUS, NULL, NULL, NULL) == NULL) {
2919 + return NULL;
2920 + }
2921 + }
2922 +
2923 + return (sb_t *)&ksi;
2924 +}
2925 +#endif
2926 +
2927 +static sb_info_t *
2928 +BCMINITFN(sb_doattach)(sb_info_t *si, uint devid, osl_t *osh, void *regs,
2929 + uint bustype, void *sdh, char **vars, int *varsz)
2930 +{
2931 + uint origidx;
2932 + chipcregs_t *cc;
2933 + sbconfig_t *sb;
2934 + uint32 w;
2935 +
2936 + ASSERT(GOODREGS(regs));
2937 +
2938 + bzero((uchar*)si, sizeof (sb_info_t));
2939 +
2940 + si->sb.buscoreidx = si->gpioidx = BADIDX;
2941 +
2942 + si->osh = osh;
2943 + si->curmap = regs;
2944 + si->sdh = sdh;
2945 +
2946 + /* check to see if we are a sb core mimic'ing a pci core */
2947 + if (bustype == PCI_BUS) {
2948 + if (OSL_PCI_READ_CONFIG(osh, PCI_SPROM_CONTROL, sizeof (uint32)) == 0xffffffff)
2949 + bustype = SB_BUS;
2950 + else
2951 + bustype = PCI_BUS;
2952 + }
2953 +
2954 + si->sb.bustype = bustype;
2955 + if (si->sb.bustype != BUSTYPE(si->sb.bustype)) {
2956 + SB_ERROR(("sb_doattach: bus type %d does not match configured bus type %d\n",
2957 + si->sb.bustype, BUSTYPE(si->sb.bustype)));
2958 + return NULL;
2959 + }
2960 +
2961 + /* kludge to enable the clock on the 4306 which lacks a slowclock */
2962 + if (BUSTYPE(si->sb.bustype) == PCI_BUS)
2963 + sb_clkctl_xtal(&si->sb, XTAL|PLL, ON);
2964 +
2965 + if (BUSTYPE(si->sb.bustype) == PCI_BUS) {
2966 + w = OSL_PCI_READ_CONFIG(osh, PCI_BAR0_WIN, sizeof (uint32));
2967 + if (!GOODCOREADDR(w))
2968 + OSL_PCI_WRITE_CONFIG(si->osh, PCI_BAR0_WIN, sizeof (uint32), SB_ENUM_BASE);
2969 + }
2970 +
2971 + /* initialize current core index value */
2972 + si->curidx = _sb_coreidx(si);
2973 +
2974 + if (si->curidx == BADIDX) {
2975 + SB_ERROR(("sb_doattach: bad core index\n"));
2976 + return NULL;
2977 + }
2978 +
2979 + /* get sonics backplane revision */
2980 + sb = REGS2SB(si->curmap);
2981 + si->sb.sonicsrev = (R_SBREG(si, &(sb)->sbidlow) & SBIDL_RV_MASK) >> SBIDL_RV_SHIFT;
2982 +
2983 + /* keep and reuse the initial register mapping */
2984 + origidx = si->curidx;
2985 + if (BUSTYPE(si->sb.bustype) == SB_BUS)
2986 + si->regs[origidx] = regs;
2987 +
2988 + /* is core-0 a chipcommon core? */
2989 + si->numcores = 1;
2990 + cc = (chipcregs_t*) sb_setcoreidx(&si->sb, 0);
2991 + if (sb_coreid(&si->sb) != SB_CC)
2992 + cc = NULL;
2993 +
2994 + /* determine chip id and rev */
2995 + if (cc) {
2996 + /* chip common core found! */
2997 + si->sb.chip = R_REG(&cc->chipid) & CID_ID_MASK;
2998 + si->sb.chiprev = (R_REG(&cc->chipid) & CID_REV_MASK) >> CID_REV_SHIFT;
2999 + si->sb.chippkg = (R_REG(&cc->chipid) & CID_PKG_MASK) >> CID_PKG_SHIFT;
3000 + } else {
3001 + /* no chip common core -- must convert device id to chip id */
3002 + if ((si->sb.chip = BCMINIT(sb_pcidev2chip)(devid)) == 0) {
3003 + SB_ERROR(("sb_doattach: unrecognized device id 0x%04x\n", devid));
3004 + sb_setcoreidx(&si->sb, origidx);
3005 + return NULL;
3006 + }
3007 + }
3008 +
3009 + /* get chipcommon rev */
3010 + si->sb.ccrev = cc ? (int)sb_corerev(&si->sb) : NOREV;
3011 +
3012 + /* determine numcores */
3013 + if (cc && ((si->sb.ccrev == 4) || (si->sb.ccrev >= 6)))
3014 + si->numcores = (R_REG(&cc->chipid) & CID_CC_MASK) >> CID_CC_SHIFT;
3015 + else
3016 + si->numcores = BCMINIT(sb_chip2numcores)(si->sb.chip);
3017 +
3018 + /* return to original core */
3019 + sb_setcoreidx(&si->sb, origidx);
3020 +
3021 + /* sanity checks */
3022 + ASSERT(si->sb.chip);
3023 +
3024 + /* scan for cores */
3025 + BCMINIT(sb_scan)(si);
3026 +
3027 + /* fixup necessary chip/core configurations */
3028 + if (BUSTYPE(si->sb.bustype) == PCI_BUS) {
3029 + if (sb_pci_fixcfg(si)) {
3030 + SB_ERROR(("sb_doattach: sb_pci_fixcfg failed\n"));
3031 + return NULL;
3032 + }
3033 + }
3034 +
3035 + /* srom_var_init() depends on sb_scan() info */
3036 + if (srom_var_init(si, si->sb.bustype, si->curmap, osh, vars, varsz)) {
3037 + SB_ERROR(("sb_doattach: srom_var_init failed: bad srom\n"));
3038 + return (NULL);
3039 + }
3040 +
3041 + if (cc == NULL) {
3042 + /*
3043 + * The chip revision number is hardwired into all
3044 + * of the pci function config rev fields and is
3045 + * independent from the individual core revision numbers.
3046 + * For example, the "A0" silicon of each chip is chip rev 0.
3047 + */
3048 + if (BUSTYPE(si->sb.bustype) == PCI_BUS) {
3049 + w = OSL_PCI_READ_CONFIG(osh, PCI_CFG_REV, sizeof (uint32));
3050 + si->sb.chiprev = w & 0xff;
3051 + } else
3052 + si->sb.chiprev = 0;
3053 + }
3054 +
3055 + /* gpio control core is required */
3056 + if (!GOODIDX(si->gpioidx)) {
3057 + SB_ERROR(("sb_doattach: gpio control core not found\n"));
3058 + return NULL;
3059 + }
3060 +
3061 + /* get boardtype and boardrev */
3062 + switch (BUSTYPE(si->sb.bustype)) {
3063 + case PCI_BUS:
3064 + /* do a pci config read to get subsystem id and subvendor id */
3065 + w = OSL_PCI_READ_CONFIG(osh, PCI_CFG_SVID, sizeof (uint32));
3066 + si->sb.boardvendor = w & 0xffff;
3067 + si->sb.boardtype = (w >> 16) & 0xffff;
3068 + break;
3069 +
3070 + case SB_BUS:
3071 + case JTAG_BUS:
3072 + si->sb.boardvendor = VENDOR_BROADCOM;
3073 + if ((si->sb.boardtype = getintvar(NULL, "boardtype")) == 0)
3074 + si->sb.boardtype = 0xffff;
3075 + break;
3076 + }
3077 +
3078 + if (si->sb.boardtype == 0) {
3079 + SB_ERROR(("sb_doattach: unknown board type\n"));
3080 + ASSERT(si->sb.boardtype);
3081 + }
3082 +
3083 + /* setup the GPIO based LED powersave register */
3084 + if (si->sb.ccrev >= 16) {
3085 + w = getintvar(*vars, "gpiotimerval");
3086 + if (!w)
3087 + w = DEFAULT_GPIOTIMERVAL;
3088 + sb_corereg(si, 0, OFFSETOF(chipcregs_t, gpiotimerval), ~0, w);
3089 + }
3090 +
3091 +
3092 + return (si);
3093 +}
3094 +
3095 +uint
3096 +sb_coreid(sb_t *sbh)
3097 +{
3098 + sb_info_t *si;
3099 + sbconfig_t *sb;
3100 +
3101 + si = SB_INFO(sbh);
3102 + sb = REGS2SB(si->curmap);
3103 +
3104 + return ((R_SBREG(si, &(sb)->sbidhigh) & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT);
3105 +}
3106 +
3107 +uint
3108 +sb_coreidx(sb_t *sbh)
3109 +{
3110 + sb_info_t *si;
3111 +
3112 + si = SB_INFO(sbh);
3113 + return (si->curidx);
3114 +}
3115 +
3116 +/* return current index of core */
3117 +static uint
3118 +_sb_coreidx(sb_info_t *si)
3119 +{
3120 + sbconfig_t *sb;
3121 + uint32 sbaddr = 0;
3122 +
3123 + ASSERT(si);
3124 +
3125 + switch (BUSTYPE(si->sb.bustype)) {
3126 + case SB_BUS:
3127 + sb = REGS2SB(si->curmap);
3128 + sbaddr = sb_base(R_SBREG(si, &sb->sbadmatch0));
3129 + break;
3130 +
3131 + case PCI_BUS:
3132 + sbaddr = OSL_PCI_READ_CONFIG(si->osh, PCI_BAR0_WIN, sizeof (uint32));
3133 + break;
3134 +
3135 +#ifdef BCMJTAG
3136 + case JTAG_BUS:
3137 + sbaddr = (uint32)si->curmap;
3138 + break;
3139 +#endif /* BCMJTAG */
3140 +
3141 + default:
3142 + ASSERT(0);
3143 + }
3144 +
3145 + if (!GOODCOREADDR(sbaddr))
3146 + return BADIDX;
3147 +
3148 + return ((sbaddr - SB_ENUM_BASE) / SB_CORE_SIZE);
3149 +}
3150 +
3151 +uint
3152 +sb_corevendor(sb_t *sbh)
3153 +{
3154 + sb_info_t *si;
3155 + sbconfig_t *sb;
3156 +
3157 + si = SB_INFO(sbh);
3158 + sb = REGS2SB(si->curmap);
3159 +
3160 + return ((R_SBREG(si, &(sb)->sbidhigh) & SBIDH_VC_MASK) >> SBIDH_VC_SHIFT);
3161 +}
3162 +
3163 +uint
3164 +sb_corerev(sb_t *sbh)
3165 +{
3166 + sb_info_t *si;
3167 + sbconfig_t *sb;
3168 + uint sbidh;
3169 +
3170 + si = SB_INFO(sbh);
3171 + sb = REGS2SB(si->curmap);
3172 + sbidh = R_SBREG(si, &(sb)->sbidhigh);
3173 +
3174 + return (SBCOREREV(sbidh));
3175 +}
3176 +
3177 +void *
3178 +sb_osh(sb_t *sbh)
3179 +{
3180 + sb_info_t *si;
3181 +
3182 + si = SB_INFO(sbh);
3183 + return si->osh;
3184 +}
3185 +
3186 +#define SBTML_ALLOW (SBTML_PE | SBTML_FGC | SBTML_FL_MASK)
3187 +
3188 +/* set/clear sbtmstatelow core-specific flags */
3189 +uint32
3190 +sb_coreflags(sb_t *sbh, uint32 mask, uint32 val)
3191 +{
3192 + sb_info_t *si;
3193 + sbconfig_t *sb;
3194 + uint32 w;
3195 +
3196 + si = SB_INFO(sbh);
3197 + sb = REGS2SB(si->curmap);
3198 +
3199 + ASSERT((val & ~mask) == 0);
3200 + ASSERT((mask & ~SBTML_ALLOW) == 0);
3201 +
3202 + /* mask and set */
3203 + if (mask || val) {
3204 + w = (R_SBREG(si, &sb->sbtmstatelow) & ~mask) | val;
3205 + W_SBREG(si, &sb->sbtmstatelow, w);
3206 + }
3207 +
3208 + /* return the new value */
3209 + return (R_SBREG(si, &sb->sbtmstatelow) & SBTML_ALLOW);
3210 +}
3211 +
3212 +/* set/clear sbtmstatehigh core-specific flags */
3213 +uint32
3214 +sb_coreflagshi(sb_t *sbh, uint32 mask, uint32 val)
3215 +{
3216 + sb_info_t *si;
3217 + sbconfig_t *sb;
3218 + uint32 w;
3219 +
3220 + si = SB_INFO(sbh);
3221 + sb = REGS2SB(si->curmap);
3222 +
3223 + ASSERT((val & ~mask) == 0);
3224 + ASSERT((mask & ~SBTMH_FL_MASK) == 0);
3225 +
3226 + /* mask and set */
3227 + if (mask || val) {
3228 + w = (R_SBREG(si, &sb->sbtmstatehigh) & ~mask) | val;
3229 + W_SBREG(si, &sb->sbtmstatehigh, w);
3230 + }
3231 +
3232 + /* return the new value */
3233 + return (R_SBREG(si, &sb->sbtmstatehigh) & SBTMH_FL_MASK);
3234 +}
3235 +
3236 +/* caller needs to take care of core-specific bist hazards */
3237 +int
3238 +sb_corebist(sb_t *sbh, uint coreid, uint coreunit)
3239 +{
3240 + uint32 sblo;
3241 + uint coreidx;
3242 + sb_info_t *si;
3243 + int result = 0;
3244 +
3245 + si = SB_INFO(sbh);
3246 +
3247 + coreidx = sb_findcoreidx(si, coreid, coreunit);
3248 + if (!GOODIDX(coreidx))
3249 + result = BCME_ERROR;
3250 + else {
3251 + sblo = sb_corereg(si, coreidx, SBCONFIGOFF + OFFSETOF(sbconfig_t, sbtmstatelow), 0, 0);
3252 + sb_corereg(si, coreidx, SBCONFIGOFF + OFFSETOF(sbconfig_t, sbtmstatelow), ~0, (sblo | SBTML_FGC | SBTML_BE));
3253 +
3254 + SPINWAIT(((sb_corereg(si, coreidx, SBCONFIGOFF + OFFSETOF(sbconfig_t, sbtmstatehigh), 0, 0) & SBTMH_BISTD) == 0), 100000);
3255 +
3256 + if (sb_corereg(si, coreidx, SBCONFIGOFF + OFFSETOF(sbconfig_t, sbtmstatehigh), 0, 0) & SBTMH_BISTF)
3257 + result = BCME_ERROR;
3258 +
3259 + sb_corereg(si, coreidx, SBCONFIGOFF + OFFSETOF(sbconfig_t, sbtmstatelow), ~0, sblo);
3260 + }
3261 +
3262 + return result;
3263 +}
3264 +
3265 +bool
3266 +sb_iscoreup(sb_t *sbh)
3267 +{
3268 + sb_info_t *si;
3269 + sbconfig_t *sb;
3270 +
3271 + si = SB_INFO(sbh);
3272 + sb = REGS2SB(si->curmap);
3273 +
3274 + return ((R_SBREG(si, &(sb)->sbtmstatelow) & (SBTML_RESET | SBTML_REJ_MASK | SBTML_CLK)) == SBTML_CLK);
3275 +}
3276 +
3277 +/*
3278 + * Switch to 'coreidx', issue a single arbitrary 32bit register mask&set operation,
3279 + * switch back to the original core, and return the new value.
3280 + */
3281 +static uint
3282 +sb_corereg(sb_info_t *si, uint coreidx, uint regoff, uint mask, uint val)
3283 +{
3284 + uint origidx;
3285 + uint32 *r;
3286 + uint w;
3287 + uint intr_val = 0;
3288 +
3289 + ASSERT(GOODIDX(coreidx));
3290 + ASSERT(regoff < SB_CORE_SIZE);
3291 + ASSERT((val & ~mask) == 0);
3292 +
3293 + INTR_OFF(si, intr_val);
3294 +
3295 + /* save current core index */
3296 + origidx = sb_coreidx(&si->sb);
3297 +
3298 + /* switch core */
3299 + r = (uint32*) ((uchar*) sb_setcoreidx(&si->sb, coreidx) + regoff);
3300 +
3301 + /* mask and set */
3302 + if (mask || val) {
3303 + if (regoff >= SBCONFIGOFF) {
3304 + w = (R_SBREG(si, r) & ~mask) | val;
3305 + W_SBREG(si, r, w);
3306 + } else {
3307 + w = (R_REG(r) & ~mask) | val;
3308 + W_REG(r, w);
3309 + }
3310 + }
3311 +
3312 + /* readback */
3313 + if (regoff >= SBCONFIGOFF)
3314 + w = R_SBREG(si, r);
3315 + else
3316 + w = R_REG(r);
3317 +
3318 + /* restore core index */
3319 + if (origidx != coreidx)
3320 + sb_setcoreidx(&si->sb, origidx);
3321 +
3322 + INTR_RESTORE(si, intr_val);
3323 + return (w);
3324 +}
3325 +
3326 +#define DWORD_ALIGN(x) (x & ~(0x03))
3327 +#define BYTE_POS(x) (x & 0x3)
3328 +#define WORD_POS(x) (x & 0x1)
3329 +
3330 +#define BYTE_SHIFT(x) (8 * BYTE_POS(x))
3331 +#define WORD_SHIFT(x) (16 * WORD_POS(x))
3332 +
3333 +#define BYTE_VAL(a, x) ((a >> BYTE_SHIFT(x)) & 0xFF)
3334 +#define WORD_VAL(a, x) ((a >> WORD_SHIFT(x)) & 0xFFFF)
3335 +
3336 +#define read_pci_cfg_byte(a) \
3337 + (BYTE_VAL(OSL_PCI_READ_CONFIG(si->osh, DWORD_ALIGN(a), 4), a) & 0xff)
3338 +
3339 +#define read_pci_cfg_write(a) \
3340 + (WORD_VAL(OSL_PCI_READ_CONFIG(si->osh, DWORD_ALIGN(a), 4), a) & 0xffff)
3341 +
3342 +
3343 +/* scan the sb enumerated space to identify all cores */
3344 +static void
3345 +BCMINITFN(sb_scan)(sb_info_t *si)
3346 +{
3347 + uint origidx;
3348 + uint i;
3349 + bool pci;
3350 + uint pciidx;
3351 + uint pcirev;
3352 +
3353 +
3354 +
3355 + /* numcores should already be set */
3356 + ASSERT((si->numcores > 0) && (si->numcores <= SB_MAXCORES));
3357 +
3358 + /* save current core index */
3359 + origidx = sb_coreidx(&si->sb);
3360 +
3361 + si->sb.buscorerev = NOREV;
3362 + si->sb.buscoreidx = BADIDX;
3363 +
3364 + si->gpioidx = BADIDX;
3365 +
3366 + pci = FALSE;
3367 + pcirev = NOREV;
3368 + pciidx = BADIDX;
3369 +
3370 + for (i = 0; i < si->numcores; i++) {
3371 + sb_setcoreidx(&si->sb, i);
3372 + si->coreid[i] = sb_coreid(&si->sb);
3373 +
3374 + if (si->coreid[i] == SB_PCI) {
3375 + pciidx = i;
3376 + pcirev = sb_corerev(&si->sb);
3377 + pci = TRUE;
3378 + }
3379 + }
3380 + if (pci) {
3381 + si->sb.buscoretype = SB_PCI;
3382 + si->sb.buscorerev = pcirev;
3383 + si->sb.buscoreidx = pciidx;
3384 + }
3385 +
3386 + /*
3387 + * Find the gpio "controlling core" type and index.
3388 + * Precedence:
3389 + * - if there's a chip common core - use that
3390 + * - else if there's a pci core (rev >= 2) - use that
3391 + * - else there had better be an extif core (4710 only)
3392 + */
3393 + if (GOODIDX(sb_findcoreidx(si, SB_CC, 0))) {
3394 + si->gpioidx = sb_findcoreidx(si, SB_CC, 0);
3395 + si->gpioid = SB_CC;
3396 + } else if (PCI(si) && (si->sb.buscorerev >= 2)) {
3397 + si->gpioidx = si->sb.buscoreidx;
3398 + si->gpioid = SB_PCI;
3399 + } else if (sb_findcoreidx(si, SB_EXTIF, 0)) {
3400 + si->gpioidx = sb_findcoreidx(si, SB_EXTIF, 0);
3401 + si->gpioid = SB_EXTIF;
3402 + } else
3403 + ASSERT(si->gpioidx != BADIDX);
3404 +
3405 + /* return to original core index */
3406 + sb_setcoreidx(&si->sb, origidx);
3407 +}
3408 +
3409 +/* may be called with core in reset */
3410 +void
3411 +sb_detach(sb_t *sbh)
3412 +{
3413 + sb_info_t *si;
3414 + uint idx;
3415 +
3416 + si = SB_INFO(sbh);
3417 +
3418 + if (si == NULL)
3419 + return;
3420 +
3421 + if (BUSTYPE(si->sb.bustype) == SB_BUS)
3422 + for (idx = 0; idx < SB_MAXCORES; idx++)
3423 + if (si->regs[idx]) {
3424 + REG_UNMAP(si->regs[idx]);
3425 + si->regs[idx] = NULL;
3426 + }
3427 +
3428 + if (si != &ksi)
3429 + MFREE(si->osh, si, sizeof (sb_info_t));
3430 +}
3431 +
3432 +/* use pci dev id to determine chip id for chips not having a chipcommon core */
3433 +static uint
3434 +BCMINITFN(sb_pcidev2chip)(uint pcidev)
3435 +{
3436 + if ((pcidev >= BCM4710_DEVICE_ID) && (pcidev <= BCM47XX_USB_ID))
3437 + return (BCM4710_DEVICE_ID);
3438 + if ((pcidev >= BCM4402_DEVICE_ID) && (pcidev <= BCM4402_V90_ID))
3439 + return (BCM4402_DEVICE_ID);
3440 + if (pcidev == BCM4401_ENET_ID)
3441 + return (BCM4402_DEVICE_ID);
3442 + if ((pcidev >= BCM4307_V90_ID) && (pcidev <= BCM4307_D11B_ID))
3443 + return (BCM4307_DEVICE_ID);
3444 + if (pcidev == BCM4301_DEVICE_ID)
3445 + return (BCM4301_DEVICE_ID);
3446 +
3447 + return (0);
3448 +}
3449 +
3450 +/* convert chip number to number of i/o cores */
3451 +static uint
3452 +BCMINITFN(sb_chip2numcores)(uint chip)
3453 +{
3454 + if (chip == BCM4710_DEVICE_ID)
3455 + return (9);
3456 + if (chip == BCM4402_DEVICE_ID)
3457 + return (3);
3458 + if ((chip == BCM4301_DEVICE_ID) || (chip == BCM4307_DEVICE_ID))
3459 + return (5);
3460 + if (chip == BCM4306_DEVICE_ID) /* < 4306c0 */
3461 + return (6);
3462 + if (chip == BCM4704_DEVICE_ID)
3463 + return (9);
3464 + if (chip == BCM5365_DEVICE_ID)
3465 + return (7);
3466 +
3467 + SB_ERROR(("sb_chip2numcores: unsupported chip 0x%x\n", chip));
3468 + ASSERT(0);
3469 + return (1);
3470 +}
3471 +
3472 +/* return index of coreid or BADIDX if not found */
3473 +static uint
3474 +sb_findcoreidx( sb_info_t *si, uint coreid, uint coreunit)
3475 +{
3476 + uint found;
3477 + uint i;
3478 +
3479 + found = 0;
3480 +
3481 + for (i = 0; i < si->numcores; i++)
3482 + if (si->coreid[i] == coreid) {
3483 + if (found == coreunit)
3484 + return (i);
3485 + found++;
3486 + }
3487 +
3488 + return (BADIDX);
3489 +}
3490 +
3491 +/*
3492 + * this function changes logical "focus" to the indiciated core,
3493 + * must be called with interrupt off.
3494 + * Moreover, callers should keep interrupts off during switching out of and back to d11 core
3495 + */
3496 +void*
3497 +sb_setcoreidx(sb_t *sbh, uint coreidx)
3498 +{
3499 + sb_info_t *si;
3500 + uint32 sbaddr;
3501 +
3502 + si = SB_INFO(sbh);
3503 +
3504 + if (coreidx >= si->numcores)
3505 + return (NULL);
3506 +
3507 + /*
3508 + * If the user has provided an interrupt mask enabled function,
3509 + * then assert interrupts are disabled before switching the core.
3510 + */
3511 + ASSERT((si->intrsenabled_fn == NULL) || !(*(si)->intrsenabled_fn)((si)->intr_arg));
3512 +
3513 + sbaddr = SB_ENUM_BASE + (coreidx * SB_CORE_SIZE);
3514 +
3515 + switch (BUSTYPE(si->sb.bustype)) {
3516 + case SB_BUS:
3517 + /* map new one */
3518 + if (!si->regs[coreidx]) {
3519 + si->regs[coreidx] = (void*)REG_MAP(sbaddr, SB_CORE_SIZE);
3520 + ASSERT(GOODREGS(si->regs[coreidx]));
3521 + }
3522 + si->curmap = si->regs[coreidx];
3523 + break;
3524 +
3525 + case PCI_BUS:
3526 + /* point bar0 window */
3527 + OSL_PCI_WRITE_CONFIG(si->osh, PCI_BAR0_WIN, 4, sbaddr);
3528 + break;
3529 +
3530 +#ifdef BCMJTAG
3531 + case JTAG_BUS:
3532 + /* map new one */
3533 + if (!si->regs[coreidx]) {
3534 + si->regs[coreidx] = (void *)sbaddr;
3535 + ASSERT(GOODREGS(si->regs[coreidx]));
3536 + }
3537 + si->curmap = si->regs[coreidx];
3538 + break;
3539 +#endif /* BCMJTAG */
3540 + }
3541 +
3542 + si->curidx = coreidx;
3543 +
3544 + return (si->curmap);
3545 +}
3546 +
3547 +/*
3548 + * this function changes logical "focus" to the indiciated core,
3549 + * must be called with interrupt off.
3550 + * Moreover, callers should keep interrupts off during switching out of and back to d11 core
3551 + */
3552 +void*
3553 +sb_setcore(sb_t *sbh, uint coreid, uint coreunit)
3554 +{
3555 + sb_info_t *si;
3556 + uint idx;
3557 +
3558 + si = SB_INFO(sbh);
3559 + idx = sb_findcoreidx(si, coreid, coreunit);
3560 + if (!GOODIDX(idx))
3561 + return (NULL);
3562 +
3563 + return (sb_setcoreidx(sbh, idx));
3564 +}
3565 +
3566 +/* return chip number */
3567 +uint
3568 +BCMINITFN(sb_chip)(sb_t *sbh)
3569 +{
3570 + sb_info_t *si;
3571 +
3572 + si = SB_INFO(sbh);
3573 + return (si->sb.chip);
3574 +}
3575 +
3576 +/* return chip revision number */
3577 +uint
3578 +BCMINITFN(sb_chiprev)(sb_t *sbh)
3579 +{
3580 + sb_info_t *si;
3581 +
3582 + si = SB_INFO(sbh);
3583 + return (si->sb.chiprev);
3584 +}
3585 +
3586 +/* return chip common revision number */
3587 +uint
3588 +BCMINITFN(sb_chipcrev)(sb_t *sbh)
3589 +{
3590 + sb_info_t *si;
3591 +
3592 + si = SB_INFO(sbh);
3593 + return (si->sb.ccrev);
3594 +}
3595 +
3596 +/* return chip package option */
3597 +uint
3598 +BCMINITFN(sb_chippkg)(sb_t *sbh)
3599 +{
3600 + sb_info_t *si;
3601 +
3602 + si = SB_INFO(sbh);
3603 + return (si->sb.chippkg);
3604 +}
3605 +
3606 +/* return PCI core rev. */
3607 +uint
3608 +BCMINITFN(sb_pcirev)(sb_t *sbh)
3609 +{
3610 + sb_info_t *si;
3611 +
3612 + si = SB_INFO(sbh);
3613 + return (si->sb.buscorerev);
3614 +}
3615 +
3616 +bool
3617 +BCMINITFN(sb_war16165)(sb_t *sbh)
3618 +{
3619 + sb_info_t *si;
3620 +
3621 + si = SB_INFO(sbh);
3622 +
3623 + return (PCI(si) && (si->sb.buscorerev <= 10));
3624 +}
3625 +
3626 +/* return board vendor id */
3627 +uint
3628 +BCMINITFN(sb_boardvendor)(sb_t *sbh)
3629 +{
3630 + sb_info_t *si;
3631 +
3632 + si = SB_INFO(sbh);
3633 + return (si->sb.boardvendor);
3634 +}
3635 +
3636 +/* return boardtype */
3637 +uint
3638 +BCMINITFN(sb_boardtype)(sb_t *sbh)
3639 +{
3640 + sb_info_t *si;
3641 + char *var;
3642 +
3643 + si = SB_INFO(sbh);
3644 +
3645 + if (BUSTYPE(si->sb.bustype) == SB_BUS && si->sb.boardtype == 0xffff) {
3646 + /* boardtype format is a hex string */
3647 + si->sb.boardtype = getintvar(NULL, "boardtype");
3648 +
3649 + /* backward compatibility for older boardtype string format */
3650 + if ((si->sb.boardtype == 0) && (var = getvar(NULL, "boardtype"))) {
3651 + if (!strcmp(var, "bcm94710dev"))
3652 + si->sb.boardtype = BCM94710D_BOARD;
3653 + else if (!strcmp(var, "bcm94710ap"))
3654 + si->sb.boardtype = BCM94710AP_BOARD;
3655 + else if (!strcmp(var, "bu4710"))
3656 + si->sb.boardtype = BU4710_BOARD;
3657 + else if (!strcmp(var, "bcm94702mn"))
3658 + si->sb.boardtype = BCM94702MN_BOARD;
3659 + else if (!strcmp(var, "bcm94710r1"))
3660 + si->sb.boardtype = BCM94710R1_BOARD;
3661 + else if (!strcmp(var, "bcm94710r4"))
3662 + si->sb.boardtype = BCM94710R4_BOARD;
3663 + else if (!strcmp(var, "bcm94702cpci"))
3664 + si->sb.boardtype = BCM94702CPCI_BOARD;
3665 + else if (!strcmp(var, "bcm95380_rr"))
3666 + si->sb.boardtype = BCM95380RR_BOARD;
3667 + }
3668 + }
3669 +
3670 + return (si->sb.boardtype);
3671 +}
3672 +
3673 +/* return bus type of sbh device */
3674 +uint
3675 +sb_bus(sb_t *sbh)
3676 +{
3677 + sb_info_t *si;
3678 +
3679 + si = SB_INFO(sbh);
3680 + return (si->sb.bustype);
3681 +}
3682 +
3683 +/* return bus core type */
3684 +uint
3685 +sb_buscoretype(sb_t *sbh)
3686 +{
3687 + sb_info_t *si;
3688 +
3689 + si = SB_INFO(sbh);
3690 +
3691 + return (si->sb.buscoretype);
3692 +}
3693 +
3694 +/* return bus core revision */
3695 +uint
3696 +sb_buscorerev(sb_t *sbh)
3697 +{
3698 + sb_info_t *si;
3699 + si = SB_INFO(sbh);
3700 +
3701 + return (si->sb.buscorerev);
3702 +}
3703 +
3704 +/* return list of found cores */
3705 +uint
3706 +sb_corelist(sb_t *sbh, uint coreid[])
3707 +{
3708 + sb_info_t *si;
3709 +
3710 + si = SB_INFO(sbh);
3711 +
3712 + bcopy((uchar*)si->coreid, (uchar*)coreid, (si->numcores * sizeof (uint)));
3713 + return (si->numcores);
3714 +}
3715 +
3716 +/* return current register mapping */
3717 +void *
3718 +sb_coreregs(sb_t *sbh)
3719 +{
3720 + sb_info_t *si;
3721 +
3722 + si = SB_INFO(sbh);
3723 + ASSERT(GOODREGS(si->curmap));
3724 +
3725 + return (si->curmap);
3726 +}
3727 +
3728 +
3729 +/* do buffered registers update */
3730 +void
3731 +sb_commit(sb_t *sbh)
3732 +{
3733 + sb_info_t *si;
3734 + uint origidx;
3735 + uint intr_val = 0;
3736 +
3737 + si = SB_INFO(sbh);
3738 +
3739 + origidx = si->curidx;
3740 + ASSERT(GOODIDX(origidx));
3741 +
3742 + INTR_OFF(si, intr_val);
3743 +
3744 + /* switch over to chipcommon core if there is one, else use pci */
3745 + if (si->sb.ccrev != NOREV) {
3746 + chipcregs_t *ccregs = (chipcregs_t *)sb_setcore(sbh, SB_CC, 0);
3747 +
3748 + /* do the buffer registers update */
3749 + W_REG(&ccregs->broadcastaddress, SB_COMMIT);
3750 + W_REG(&ccregs->broadcastdata, 0x0);
3751 + } else if (PCI(si)) {
3752 + sbpciregs_t *pciregs = (sbpciregs_t *)sb_setcore(sbh, SB_PCI, 0);
3753 +
3754 + /* do the buffer registers update */
3755 + W_REG(&pciregs->bcastaddr, SB_COMMIT);
3756 + W_REG(&pciregs->bcastdata, 0x0);
3757 + } else
3758 + ASSERT(0);
3759 +
3760 + /* restore core index */
3761 + sb_setcoreidx(sbh, origidx);
3762 + INTR_RESTORE(si, intr_val);
3763 +}
3764 +
3765 +/* reset and re-enable a core */
3766 +void
3767 +sb_core_reset(sb_t *sbh, uint32 bits)
3768 +{
3769 + sb_info_t *si;
3770 + sbconfig_t *sb;
3771 + volatile uint32 dummy;
3772 +
3773 + si = SB_INFO(sbh);
3774 + ASSERT(GOODREGS(si->curmap));
3775 + sb = REGS2SB(si->curmap);
3776 +
3777 + /*
3778 + * Must do the disable sequence first to work for arbitrary current core state.
3779 + */
3780 + sb_core_disable(sbh, bits);
3781 +
3782 + /*
3783 + * Now do the initialization sequence.
3784 + */
3785 +
3786 + /* set reset while enabling the clock and forcing them on throughout the core */
3787 + W_SBREG(si, &sb->sbtmstatelow, (SBTML_FGC | SBTML_CLK | SBTML_RESET | bits));
3788 + dummy = R_SBREG(si, &sb->sbtmstatelow);
3789 + OSL_DELAY(1);
3790 +
3791 + if (R_SBREG(si, &sb->sbtmstatehigh) & SBTMH_SERR) {
3792 + W_SBREG(si, &sb->sbtmstatehigh, 0);
3793 + }
3794 + if ((dummy = R_SBREG(si, &sb->sbimstate)) & (SBIM_IBE | SBIM_TO)) {
3795 + AND_SBREG(si, &sb->sbimstate, ~(SBIM_IBE | SBIM_TO));
3796 + }
3797 +
3798 + /* clear reset and allow it to propagate throughout the core */
3799 + W_SBREG(si, &sb->sbtmstatelow, (SBTML_FGC | SBTML_CLK | bits));
3800 + dummy = R_SBREG(si, &sb->sbtmstatelow);
3801 + OSL_DELAY(1);
3802 +
3803 + /* leave clock enabled */
3804 + W_SBREG(si, &sb->sbtmstatelow, (SBTML_CLK | bits));
3805 + dummy = R_SBREG(si, &sb->sbtmstatelow);
3806 + OSL_DELAY(1);
3807 +}
3808 +
3809 +void
3810 +sb_core_tofixup(sb_t *sbh)
3811 +{
3812 + sb_info_t *si;
3813 + sbconfig_t *sb;
3814 +
3815 + si = SB_INFO(sbh);
3816 +
3817 + if ( (BUSTYPE(si->sb.bustype) != PCI_BUS) || (PCI(si) && (si->sb.buscorerev >= 5)) )
3818 + return;
3819 +
3820 + ASSERT(GOODREGS(si->curmap));
3821 + sb = REGS2SB(si->curmap);
3822 +
3823 + if (BUSTYPE(si->sb.bustype) == SB_BUS) {
3824 + SET_SBREG(si, &sb->sbimconfiglow,
3825 + SBIMCL_RTO_MASK | SBIMCL_STO_MASK,
3826 + (0x5 << SBIMCL_RTO_SHIFT) | 0x3);
3827 + } else {
3828 + if (sb_coreid(sbh) == SB_PCI) {
3829 + SET_SBREG(si, &sb->sbimconfiglow,
3830 + SBIMCL_RTO_MASK | SBIMCL_STO_MASK,
3831 + (0x3 << SBIMCL_RTO_SHIFT) | 0x2);
3832 + } else {
3833 + SET_SBREG(si, &sb->sbimconfiglow, (SBIMCL_RTO_MASK | SBIMCL_STO_MASK), 0);
3834 + }
3835 + }
3836 +
3837 + sb_commit(sbh);
3838 +}
3839 +
3840 +/*
3841 + * Set the initiator timeout for the "master core".
3842 + * The master core is defined to be the core in control
3843 + * of the chip and so it issues accesses to non-memory
3844 + * locations (Because of dma *any* core can access memeory).
3845 + *
3846 + * The routine uses the bus to decide who is the master:
3847 + * SB_BUS => mips
3848 + * JTAG_BUS => chipc
3849 + * PCI_BUS => pci
3850 + *
3851 + * This routine exists so callers can disable initiator
3852 + * timeouts so accesses to very slow devices like otp
3853 + * won't cause an abort. The routine allows arbitrary
3854 + * settings of the service and request timeouts, though.
3855 + *
3856 + * Returns the timeout state before changing it or -1
3857 + * on error.
3858 + */
3859 +
3860 +#define TO_MASK (SBIMCL_RTO_MASK | SBIMCL_STO_MASK)
3861 +
3862 +uint32
3863 +sb_set_initiator_to(sb_t *sbh, uint32 to)
3864 +{
3865 + sb_info_t *si;
3866 + uint origidx, idx;
3867 + uint intr_val = 0;
3868 + uint32 tmp, ret = 0xffffffff;
3869 + sbconfig_t *sb;
3870 +
3871 + si = SB_INFO(sbh);
3872 +
3873 + if ((to & ~TO_MASK) != 0)
3874 + return ret;
3875 +
3876 + /* Figure out the master core */
3877 + idx = BADIDX;
3878 + switch (BUSTYPE(si->sb.bustype)) {
3879 + case PCI_BUS:
3880 + idx = si->sb.buscoreidx;
3881 + break;
3882 + case JTAG_BUS:
3883 + idx = SB_CC_IDX;
3884 + break;
3885 + case SB_BUS:
3886 + if ((idx = sb_findcoreidx(si, SB_MIPS33, 0)) == BADIDX)
3887 + idx = sb_findcoreidx(si, SB_MIPS, 0);
3888 + break;
3889 + default:
3890 + ASSERT(0);
3891 + }
3892 + if (idx == BADIDX)
3893 + return ret;
3894 +
3895 + INTR_OFF(si, intr_val);
3896 + origidx = sb_coreidx(sbh);
3897 +
3898 + sb = REGS2SB(sb_setcoreidx(sbh, idx));
3899 +
3900 + tmp = R_SBREG(si, &sb->sbimconfiglow);
3901 + ret = tmp & TO_MASK;
3902 + W_SBREG(si, &sb->sbimconfiglow, (tmp & ~TO_MASK) | to);
3903 +
3904 + sb_commit(sbh);
3905 + sb_setcoreidx(sbh, origidx);
3906 + INTR_RESTORE(si, intr_val);
3907 + return ret;
3908 +}
3909 +
3910 +void
3911 +sb_core_disable(sb_t *sbh, uint32 bits)
3912 +{
3913 + sb_info_t *si;
3914 + volatile uint32 dummy;
3915 + uint32 rej;
3916 + sbconfig_t *sb;
3917 +
3918 + si = SB_INFO(sbh);
3919 +
3920 + ASSERT(GOODREGS(si->curmap));
3921 + sb = REGS2SB(si->curmap);
3922 +
3923 + /* if core is already in reset, just return */
3924 + if (R_SBREG(si, &sb->sbtmstatelow) & SBTML_RESET)
3925 + return;
3926 +
3927 + /* reject value changed between sonics 2.2 and 2.3 */
3928 + if (si->sb.sonicsrev == SONICS_2_2)
3929 + rej = (1 << SBTML_REJ_SHIFT);
3930 + else
3931 + rej = (2 << SBTML_REJ_SHIFT);
3932 +
3933 + /* if clocks are not enabled, put into reset and return */
3934 + if ((R_SBREG(si, &sb->sbtmstatelow) & SBTML_CLK) == 0)
3935 + goto disable;
3936 +
3937 + /* set target reject and spin until busy is clear (preserve core-specific bits) */
3938 + OR_SBREG(si, &sb->sbtmstatelow, rej);
3939 + dummy = R_SBREG(si, &sb->sbtmstatelow);
3940 + OSL_DELAY(1);
3941 + SPINWAIT((R_SBREG(si, &sb->sbtmstatehigh) & SBTMH_BUSY), 100000);
3942 +
3943 + if (R_SBREG(si, &sb->sbidlow) & SBIDL_INIT) {
3944 + OR_SBREG(si, &sb->sbimstate, SBIM_RJ);
3945 + dummy = R_SBREG(si, &sb->sbimstate);
3946 + OSL_DELAY(1);
3947 + SPINWAIT((R_SBREG(si, &sb->sbimstate) & SBIM_BY), 100000);
3948 + }
3949 +
3950 + /* set reset and reject while enabling the clocks */
3951 + W_SBREG(si, &sb->sbtmstatelow, (bits | SBTML_FGC | SBTML_CLK | rej | SBTML_RESET));
3952 + dummy = R_SBREG(si, &sb->sbtmstatelow);
3953 + OSL_DELAY(10);
3954 +
3955 + /* don't forget to clear the initiator reject bit */
3956 + if (R_SBREG(si, &sb->sbidlow) & SBIDL_INIT)
3957 + AND_SBREG(si, &sb->sbimstate, ~SBIM_RJ);
3958 +
3959 +disable:
3960 + /* leave reset and reject asserted */
3961 + W_SBREG(si, &sb->sbtmstatelow, (bits | rej | SBTML_RESET));
3962 + OSL_DELAY(1);
3963 +}
3964 +
3965 +/* set chip watchdog reset timer to fire in 'ticks' backplane cycles */
3966 +void
3967 +sb_watchdog(sb_t *sbh, uint ticks)
3968 +{
3969 + sb_info_t *si = SB_INFO(sbh);
3970 +
3971 + /* instant NMI */
3972 + switch (si->gpioid) {
3973 + case SB_CC:
3974 + sb_corereg(si, 0, OFFSETOF(chipcregs_t, watchdog), ~0, ticks);
3975 + break;
3976 + case SB_EXTIF:
3977 + sb_corereg(si, si->gpioidx, OFFSETOF(extifregs_t, watchdog), ~0, ticks);
3978 + break;
3979 + }
3980 +}
3981 +
3982 +
3983 +/*
3984 + * Configure the pci core for pci client (NIC) action
3985 + * coremask is the bitvec of cores by index to be enabled.
3986 + */
3987 +void
3988 +sb_pci_setup(sb_t *sbh, uint coremask)
3989 +{
3990 + sb_info_t *si;
3991 + sbconfig_t *sb;
3992 + sbpciregs_t *pciregs;
3993 + uint32 sbflag;
3994 + uint32 w;
3995 + uint idx;
3996 +
3997 + si = SB_INFO(sbh);
3998 +
3999 + /* if not pci bus, we're done */
4000 + if (BUSTYPE(si->sb.bustype) != PCI_BUS)
4001 + return;
4002 +
4003 + ASSERT(PCI(si));
4004 + ASSERT(si->sb.buscoreidx != BADIDX);
4005 +
4006 + /* get current core index */
4007 + idx = si->curidx;
4008 +
4009 + /* we interrupt on this backplane flag number */
4010 + ASSERT(GOODREGS(si->curmap));
4011 + sb = REGS2SB(si->curmap);
4012 + sbflag = R_SBREG(si, &sb->sbtpsflag) & SBTPS_NUM0_MASK;
4013 +
4014 + /* switch over to pci core */
4015 + pciregs = (sbpciregs_t*) sb_setcoreidx(sbh, si->sb.buscoreidx);
4016 + sb = REGS2SB(pciregs);
4017 +
4018 + /*
4019 + * Enable sb->pci interrupts. Assume
4020 + * PCI rev 2.3 support was added in pci core rev 6 and things changed..
4021 + */
4022 + if ((PCI(si) && ((si->sb.buscorerev) >= 6))) {
4023 + /* pci config write to set this core bit in PCIIntMask */
4024 + w = OSL_PCI_READ_CONFIG(si->osh, PCI_INT_MASK, sizeof(uint32));
4025 + w |= (coremask << PCI_SBIM_SHIFT);
4026 + OSL_PCI_WRITE_CONFIG(si->osh, PCI_INT_MASK, sizeof(uint32), w);
4027 + } else {
4028 + /* set sbintvec bit for our flag number */
4029 + OR_SBREG(si, &sb->sbintvec, (1 << sbflag));
4030 + }
4031 +
4032 + if (PCI(si)) {
4033 + OR_REG(&pciregs->sbtopci2, (SBTOPCI_PREF|SBTOPCI_BURST));
4034 + if (si->sb.buscorerev >= 11)
4035 + OR_REG(&pciregs->sbtopci2, SBTOPCI_RC_READMULTI);
4036 + if (si->sb.buscorerev < 5) {
4037 + SET_SBREG(si, &sb->sbimconfiglow, SBIMCL_RTO_MASK | SBIMCL_STO_MASK,
4038 + (0x3 << SBIMCL_RTO_SHIFT) | 0x2);
4039 + sb_commit(sbh);
4040 + }
4041 + }
4042 +
4043 + /* switch back to previous core */
4044 + sb_setcoreidx(sbh, idx);
4045 +}
4046 +
4047 +uint32
4048 +sb_base(uint32 admatch)
4049 +{
4050 + uint32 base;
4051 + uint type;
4052 +
4053 + type = admatch & SBAM_TYPE_MASK;
4054 + ASSERT(type < 3);
4055 +
4056 + base = 0;
4057 +
4058 + if (type == 0) {
4059 + base = admatch & SBAM_BASE0_MASK;
4060 + } else if (type == 1) {
4061 + ASSERT(!(admatch & SBAM_ADNEG)); /* neg not supported */
4062 + base = admatch & SBAM_BASE1_MASK;
4063 + } else if (type == 2) {
4064 + ASSERT(!(admatch & SBAM_ADNEG)); /* neg not supported */
4065 + base = admatch & SBAM_BASE2_MASK;
4066 + }
4067 +
4068 + return (base);
4069 +}
4070 +
4071 +uint32
4072 +sb_size(uint32 admatch)
4073 +{
4074 + uint32 size;
4075 + uint type;
4076 +
4077 + type = admatch & SBAM_TYPE_MASK;
4078 + ASSERT(type < 3);
4079 +
4080 + size = 0;
4081 +
4082 + if (type == 0) {
4083 + size = 1 << (((admatch & SBAM_ADINT0_MASK) >> SBAM_ADINT0_SHIFT) + 1);
4084 + } else if (type == 1) {
4085 + ASSERT(!(admatch & SBAM_ADNEG)); /* neg not supported */
4086 + size = 1 << (((admatch & SBAM_ADINT1_MASK) >> SBAM_ADINT1_SHIFT) + 1);
4087 + } else if (type == 2) {
4088 + ASSERT(!(admatch & SBAM_ADNEG)); /* neg not supported */
4089 + size = 1 << (((admatch & SBAM_ADINT2_MASK) >> SBAM_ADINT2_SHIFT) + 1);
4090 + }
4091 +
4092 + return (size);
4093 +}
4094 +
4095 +/* return the core-type instantiation # of the current core */
4096 +uint
4097 +sb_coreunit(sb_t *sbh)
4098 +{
4099 + sb_info_t *si;
4100 + uint idx;
4101 + uint coreid;
4102 + uint coreunit;
4103 + uint i;
4104 +
4105 + si = SB_INFO(sbh);
4106 + coreunit = 0;
4107 +
4108 + idx = si->curidx;
4109 +
4110 + ASSERT(GOODREGS(si->curmap));
4111 + coreid = sb_coreid(sbh);
4112 +
4113 + /* count the cores of our type */
4114 + for (i = 0; i < idx; i++)
4115 + if (si->coreid[i] == coreid)
4116 + coreunit++;
4117 +
4118 + return (coreunit);
4119 +}
4120 +
4121 +static INLINE uint32
4122 +factor6(uint32 x)
4123 +{
4124 + switch (x) {
4125 + case CC_F6_2: return 2;
4126 + case CC_F6_3: return 3;
4127 + case CC_F6_4: return 4;
4128 + case CC_F6_5: return 5;
4129 + case CC_F6_6: return 6;
4130 + case CC_F6_7: return 7;
4131 + default: return 0;
4132 + }
4133 +}
4134 +
4135 +/* calculate the speed the SB would run at given a set of clockcontrol values */
4136 +uint32
4137 +sb_clock_rate(uint32 pll_type, uint32 n, uint32 m)
4138 +{
4139 + uint32 n1, n2, clock, m1, m2, m3, mc;
4140 +
4141 + n1 = n & CN_N1_MASK;
4142 + n2 = (n & CN_N2_MASK) >> CN_N2_SHIFT;
4143 +
4144 + if (pll_type == PLL_TYPE6) {
4145 + if (m & CC_T6_MMASK)
4146 + return CC_T6_M1;
4147 + else
4148 + return CC_T6_M0;
4149 + } else if ((pll_type == PLL_TYPE1) ||
4150 + (pll_type == PLL_TYPE3) ||
4151 + (pll_type == PLL_TYPE4) ||
4152 + (pll_type == PLL_TYPE7)) {
4153 + n1 = factor6(n1);
4154 + n2 += CC_F5_BIAS;
4155 + } else if (pll_type == PLL_TYPE2) {
4156 + n1 += CC_T2_BIAS;
4157 + n2 += CC_T2_BIAS;
4158 + ASSERT((n1 >= 2) && (n1 <= 7));
4159 + ASSERT((n2 >= 5) && (n2 <= 23));
4160 + } else if (pll_type == PLL_TYPE5) {
4161 + return (100000000);
4162 + } else
4163 + ASSERT(0);
4164 + /* PLL types 3 and 7 use BASE2 (25Mhz) */
4165 + if ((pll_type == PLL_TYPE3) ||
4166 + (pll_type == PLL_TYPE7)) {
4167 + clock = CC_CLOCK_BASE2 * n1 * n2;
4168 + }
4169 + else
4170 + clock = CC_CLOCK_BASE1 * n1 * n2;
4171 +
4172 + if (clock == 0)
4173 + return 0;
4174 +
4175 + m1 = m & CC_M1_MASK;
4176 + m2 = (m & CC_M2_MASK) >> CC_M2_SHIFT;
4177 + m3 = (m & CC_M3_MASK) >> CC_M3_SHIFT;
4178 + mc = (m & CC_MC_MASK) >> CC_MC_SHIFT;
4179 +
4180 + if ((pll_type == PLL_TYPE1) ||
4181 + (pll_type == PLL_TYPE3) ||
4182 + (pll_type == PLL_TYPE4) ||
4183 + (pll_type == PLL_TYPE7)) {
4184 + m1 = factor6(m1);
4185 + if ((pll_type == PLL_TYPE1) || (pll_type == PLL_TYPE3))
4186 + m2 += CC_F5_BIAS;
4187 + else
4188 + m2 = factor6(m2);
4189 + m3 = factor6(m3);
4190 +
4191 + switch (mc) {
4192 + case CC_MC_BYPASS: return (clock);
4193 + case CC_MC_M1: return (clock / m1);
4194 + case CC_MC_M1M2: return (clock / (m1 * m2));
4195 + case CC_MC_M1M2M3: return (clock / (m1 * m2 * m3));
4196 + case CC_MC_M1M3: return (clock / (m1 * m3));
4197 + default: return (0);
4198 + }
4199 + } else {
4200 + ASSERT(pll_type == PLL_TYPE2);
4201 +
4202 + m1 += CC_T2_BIAS;
4203 + m2 += CC_T2M2_BIAS;
4204 + m3 += CC_T2_BIAS;
4205 + ASSERT((m1 >= 2) && (m1 <= 7));
4206 + ASSERT((m2 >= 3) && (m2 <= 10));
4207 + ASSERT((m3 >= 2) && (m3 <= 7));
4208 +
4209 + if ((mc & CC_T2MC_M1BYP) == 0)
4210 + clock /= m1;
4211 + if ((mc & CC_T2MC_M2BYP) == 0)
4212 + clock /= m2;
4213 + if ((mc & CC_T2MC_M3BYP) == 0)
4214 + clock /= m3;
4215 +
4216 + return(clock);
4217 + }
4218 +}
4219 +
4220 +/* returns the current speed the SB is running at */
4221 +uint32
4222 +sb_clock(sb_t *sbh)
4223 +{
4224 + sb_info_t *si;
4225 + extifregs_t *eir;
4226 + chipcregs_t *cc;
4227 + uint32 n, m;
4228 + uint idx;
4229 + uint32 pll_type, rate;
4230 + uint intr_val = 0;
4231 +
4232 + si = SB_INFO(sbh);
4233 + idx = si->curidx;
4234 + pll_type = PLL_TYPE1;
4235 +
4236 + INTR_OFF(si, intr_val);
4237 +
4238 + /* switch to extif or chipc core */
4239 + if ((eir = (extifregs_t *) sb_setcore(sbh, SB_EXTIF, 0))) {
4240 + n = R_REG(&eir->clockcontrol_n);
4241 + m = R_REG(&eir->clockcontrol_sb);
4242 + } else if ((cc = (chipcregs_t *) sb_setcore(sbh, SB_CC, 0))) {
4243 + pll_type = R_REG(&cc->capabilities) & CAP_PLL_MASK;
4244 + n = R_REG(&cc->clockcontrol_n);
4245 + if (pll_type == PLL_TYPE6)
4246 + m = R_REG(&cc->clockcontrol_mips);
4247 + else if (pll_type == PLL_TYPE3)
4248 + {
4249 + // Added by Chen-I for 5365
4250 + if (BCMINIT(sb_chip)(sbh) == BCM5365_DEVICE_ID)
4251 + m = R_REG(&cc->clockcontrol_sb);
4252 + else
4253 + m = R_REG(&cc->clockcontrol_m2);
4254 + }
4255 + else
4256 + m = R_REG(&cc->clockcontrol_sb);
4257 + } else {
4258 + INTR_RESTORE(si, intr_val);
4259 + return 0;
4260 + }
4261 +
4262 + // Added by Chen-I for 5365
4263 + if (BCMINIT(sb_chip)(sbh) == BCM5365_DEVICE_ID)
4264 + {
4265 + rate = 100000000;
4266 + }
4267 + else
4268 + {
4269 + /* calculate rate */
4270 + rate = sb_clock_rate(pll_type, n, m);
4271 + if (pll_type == PLL_TYPE3)
4272 + rate = rate / 2;
4273 + }
4274 +
4275 + /* switch back to previous core */
4276 + sb_setcoreidx(sbh, idx);
4277 +
4278 + INTR_RESTORE(si, intr_val);
4279 +
4280 + return rate;
4281 +}
4282 +
4283 +/* change logical "focus" to the gpio core for optimized access */
4284 +void*
4285 +sb_gpiosetcore(sb_t *sbh)
4286 +{
4287 + sb_info_t *si;
4288 +
4289 + si = SB_INFO(sbh);
4290 +
4291 + return (sb_setcoreidx(sbh, si->gpioidx));
4292 +}
4293 +
4294 +/* mask&set gpiocontrol bits */
4295 +uint32
4296 +sb_gpiocontrol(sb_t *sbh, uint32 mask, uint32 val, uint8 priority)
4297 +{
4298 + sb_info_t *si;
4299 + uint regoff;
4300 +
4301 + si = SB_INFO(sbh);
4302 + regoff = 0;
4303 +
4304 + priority = GPIO_DRV_PRIORITY; /* compatibility hack */
4305 +
4306 + /* gpios could be shared on router platforms */
4307 + if ((BUSTYPE(si->sb.bustype) == SB_BUS) && (val || mask)) {
4308 + mask = priority ? (sb_gpioreservation & mask) :
4309 + ((sb_gpioreservation | mask) & ~(sb_gpioreservation));
4310 + val &= mask;
4311 + }
4312 +
4313 + switch (si->gpioid) {
4314 + case SB_CC:
4315 + regoff = OFFSETOF(chipcregs_t, gpiocontrol);
4316 + break;
4317 +
4318 + case SB_PCI:
4319 + regoff = OFFSETOF(sbpciregs_t, gpiocontrol);
4320 + break;
4321 +
4322 + case SB_EXTIF:
4323 + return (0);
4324 + }
4325 +
4326 + return (sb_corereg(si, si->gpioidx, regoff, mask, val));
4327 +}
4328 +
4329 +/* mask&set gpio output enable bits */
4330 +uint32
4331 +sb_gpioouten(sb_t *sbh, uint32 mask, uint32 val, uint8 priority)
4332 +{
4333 + sb_info_t *si;
4334 + uint regoff;
4335 +
4336 + si = SB_INFO(sbh);
4337 + regoff = 0;
4338 +
4339 + priority = GPIO_DRV_PRIORITY; /* compatibility hack */
4340 +
4341 + /* gpios could be shared on router platforms */
4342 + if ((BUSTYPE(si->sb.bustype) == SB_BUS) && (val || mask)) {
4343 + mask = priority ? (sb_gpioreservation & mask) :
4344 + ((sb_gpioreservation | mask) & ~(sb_gpioreservation));
4345 + val &= mask;
4346 + }
4347 +
4348 + switch (si->gpioid) {
4349 + case SB_CC:
4350 + regoff = OFFSETOF(chipcregs_t, gpioouten);
4351 + break;
4352 +
4353 + case SB_PCI:
4354 + regoff = OFFSETOF(sbpciregs_t, gpioouten);
4355 + break;
4356 +
4357 + case SB_EXTIF:
4358 + regoff = OFFSETOF(extifregs_t, gpio[0].outen);
4359 + break;
4360 + }
4361 +
4362 + return (sb_corereg(si, si->gpioidx, regoff, mask, val));
4363 +}
4364 +
4365 +/* mask&set gpio output bits */
4366 +uint32
4367 +sb_gpioout(sb_t *sbh, uint32 mask, uint32 val, uint8 priority)
4368 +{
4369 + sb_info_t *si;
4370 + uint regoff;
4371 +
4372 + si = SB_INFO(sbh);
4373 + regoff = 0;
4374 +
4375 + priority = GPIO_DRV_PRIORITY; /* compatibility hack */
4376 +
4377 + /* gpios could be shared on router platforms */
4378 + if ((BUSTYPE(si->sb.bustype) == SB_BUS) && (val || mask)) {
4379 + mask = priority ? (sb_gpioreservation & mask) :
4380 + ((sb_gpioreservation | mask) & ~(sb_gpioreservation));
4381 + val &= mask;
4382 + }
4383 +
4384 + switch (si->gpioid) {
4385 + case SB_CC:
4386 + regoff = OFFSETOF(chipcregs_t, gpioout);
4387 + break;
4388 +
4389 + case SB_PCI:
4390 + regoff = OFFSETOF(sbpciregs_t, gpioout);
4391 + break;
4392 +
4393 + case SB_EXTIF:
4394 + regoff = OFFSETOF(extifregs_t, gpio[0].out);
4395 + break;
4396 + }
4397 +
4398 + return (sb_corereg(si, si->gpioidx, regoff, mask, val));
4399 +}
4400 +
4401 +/* reserve one gpio */
4402 +uint32
4403 +sb_gpioreserve(sb_t *sbh, uint32 gpio_bitmask, uint8 priority)
4404 +{
4405 + sb_info_t *si;
4406 +
4407 + si = SB_INFO(sbh);
4408 +
4409 + priority = GPIO_DRV_PRIORITY; /* compatibility hack */
4410 +
4411 + /* only cores on SB_BUS share GPIO's and only applcation users need to reserve/release GPIO */
4412 + if ( (BUSTYPE(si->sb.bustype) != SB_BUS) || (!priority)) {
4413 + ASSERT((BUSTYPE(si->sb.bustype) == SB_BUS) && (priority));
4414 + return -1;
4415 + }
4416 + /* make sure only one bit is set */
4417 + if ((!gpio_bitmask) || ((gpio_bitmask) & (gpio_bitmask - 1))) {
4418 + ASSERT((gpio_bitmask) && !((gpio_bitmask) & (gpio_bitmask - 1)));
4419 + return -1;
4420 + }
4421 +
4422 + /* already reserved */
4423 + if (sb_gpioreservation & gpio_bitmask)
4424 + return -1;
4425 + /* set reservation */
4426 + sb_gpioreservation |= gpio_bitmask;
4427 +
4428 + return sb_gpioreservation;
4429 +}
4430 +
4431 +/* release one gpio */
4432 +/*
4433 + * releasing the gpio doesn't change the current value on the GPIO last write value
4434 + * persists till some one overwrites it
4435 +*/
4436 +
4437 +uint32
4438 +sb_gpiorelease(sb_t *sbh, uint32 gpio_bitmask, uint8 priority)
4439 +{
4440 + sb_info_t *si;
4441 +
4442 + si = SB_INFO(sbh);
4443 +
4444 + priority = GPIO_DRV_PRIORITY; /* compatibility hack */
4445 +
4446 + /* only cores on SB_BUS share GPIO's and only applcation users need to reserve/release GPIO */
4447 + if ( (BUSTYPE(si->sb.bustype) != SB_BUS) || (!priority)) {
4448 + ASSERT((BUSTYPE(si->sb.bustype) == SB_BUS) && (priority));
4449 + return -1;
4450 + }
4451 + /* make sure only one bit is set */
4452 + if ((!gpio_bitmask) || ((gpio_bitmask) & (gpio_bitmask - 1))) {
4453 + ASSERT((gpio_bitmask) && !((gpio_bitmask) & (gpio_bitmask - 1)));
4454 + return -1;
4455 + }
4456 +
4457 + /* already released */
4458 + if (!(sb_gpioreservation & gpio_bitmask))
4459 + return -1;
4460 +
4461 + /* clear reservation */
4462 + sb_gpioreservation &= ~gpio_bitmask;
4463 +
4464 + return sb_gpioreservation;
4465 +}
4466 +
4467 +/* return the current gpioin register value */
4468 +uint32
4469 +sb_gpioin(sb_t *sbh)
4470 +{
4471 + sb_info_t *si;
4472 + uint regoff;
4473 +
4474 + si = SB_INFO(sbh);
4475 + regoff = 0;
4476 +
4477 + switch (si->gpioid) {
4478 + case SB_CC:
4479 + regoff = OFFSETOF(chipcregs_t, gpioin);
4480 + break;
4481 +
4482 + case SB_PCI:
4483 + regoff = OFFSETOF(sbpciregs_t, gpioin);
4484 + break;
4485 +
4486 + case SB_EXTIF:
4487 + regoff = OFFSETOF(extifregs_t, gpioin);
4488 + break;
4489 + }
4490 +
4491 + return (sb_corereg(si, si->gpioidx, regoff, 0, 0));
4492 +}
4493 +
4494 +/* mask&set gpio interrupt polarity bits */
4495 +uint32
4496 +sb_gpiointpolarity(sb_t *sbh, uint32 mask, uint32 val, uint8 priority)
4497 +{
4498 + sb_info_t *si;
4499 + uint regoff;
4500 +
4501 + si = SB_INFO(sbh);
4502 + regoff = 0;
4503 +
4504 + priority = GPIO_DRV_PRIORITY; /* compatibility hack */
4505 +
4506 + /* gpios could be shared on router platforms */
4507 + if ((BUSTYPE(si->sb.bustype) == SB_BUS) && (val || mask)) {
4508 + mask = priority ? (sb_gpioreservation & mask) :
4509 + ((sb_gpioreservation | mask) & ~(sb_gpioreservation));
4510 + val &= mask;
4511 + }
4512 +
4513 + switch (si->gpioid) {
4514 + case SB_CC:
4515 + regoff = OFFSETOF(chipcregs_t, gpiointpolarity);
4516 + break;
4517 +
4518 + case SB_PCI:
4519 + /* pci gpio implementation does not support interrupt polarity */
4520 + ASSERT(0);
4521 + break;
4522 +
4523 + case SB_EXTIF:
4524 + regoff = OFFSETOF(extifregs_t, gpiointpolarity);
4525 + break;
4526 + }
4527 +
4528 + return (sb_corereg(si, si->gpioidx, regoff, mask, val));
4529 +}
4530 +
4531 +/* mask&set gpio interrupt mask bits */
4532 +uint32
4533 +sb_gpiointmask(sb_t *sbh, uint32 mask, uint32 val, uint8 priority)
4534 +{
4535 + sb_info_t *si;
4536 + uint regoff;
4537 +
4538 + si = SB_INFO(sbh);
4539 + regoff = 0;
4540 +
4541 + priority = GPIO_DRV_PRIORITY; /* compatibility hack */
4542 +
4543 + /* gpios could be shared on router platforms */
4544 + if ((BUSTYPE(si->sb.bustype) == SB_BUS) && (val || mask)) {
4545 + mask = priority ? (sb_gpioreservation & mask) :
4546 + ((sb_gpioreservation | mask) & ~(sb_gpioreservation));
4547 + val &= mask;
4548 + }
4549 +
4550 + switch (si->gpioid) {
4551 + case SB_CC:
4552 + regoff = OFFSETOF(chipcregs_t, gpiointmask);
4553 + break;
4554 +
4555 + case SB_PCI:
4556 + /* pci gpio implementation does not support interrupt mask */
4557 + ASSERT(0);
4558 + break;
4559 +
4560 + case SB_EXTIF:
4561 + regoff = OFFSETOF(extifregs_t, gpiointmask);
4562 + break;
4563 + }
4564 +
4565 + return (sb_corereg(si, si->gpioidx, regoff, mask, val));
4566 +}
4567 +
4568 +/* assign the gpio to an led */
4569 +uint32
4570 +sb_gpioled(sb_t *sbh, uint32 mask, uint32 val)
4571 +{
4572 + sb_info_t *si;
4573 +
4574 + si = SB_INFO(sbh);
4575 + if (si->sb.ccrev < 16)
4576 + return -1;
4577 +
4578 + /* gpio led powersave reg */
4579 + return(sb_corereg(si, 0, OFFSETOF(chipcregs_t, gpiotimeroutmask), mask, val));
4580 +}
4581 +
4582 +/* mask&set gpio timer val */
4583 +uint32
4584 +sb_gpiotimerval(sb_t *sbh, uint32 mask, uint32 gpiotimerval)
4585 +{
4586 + sb_info_t *si;
4587 + si = SB_INFO(sbh);
4588 +
4589 + if (si->sb.ccrev < 16)
4590 + return -1;
4591 +
4592 + return(sb_corereg(si, 0, OFFSETOF(chipcregs_t, gpiotimerval), mask, gpiotimerval));
4593 +}
4594 +
4595 +
4596 +/* return the slow clock source - LPO, XTAL, or PCI */
4597 +static uint
4598 +sb_slowclk_src(sb_info_t *si)
4599 +{
4600 + chipcregs_t *cc;
4601 +
4602 +
4603 + ASSERT(sb_coreid(&si->sb) == SB_CC);
4604 +
4605 + if (si->sb.ccrev < 6) {
4606 + if ((BUSTYPE(si->sb.bustype) == PCI_BUS)
4607 + && (OSL_PCI_READ_CONFIG(si->osh, PCI_GPIO_OUT, sizeof (uint32)) & PCI_CFG_GPIO_SCS))
4608 + return (SCC_SS_PCI);
4609 + else
4610 + return (SCC_SS_XTAL);
4611 + } else if (si->sb.ccrev < 10) {
4612 + cc = (chipcregs_t*) sb_setcoreidx(&si->sb, si->curidx);
4613 + return (R_REG(&cc->slow_clk_ctl) & SCC_SS_MASK);
4614 + } else /* Insta-clock */
4615 + return (SCC_SS_XTAL);
4616 +}
4617 +
4618 +/* return the ILP (slowclock) min or max frequency */
4619 +static uint
4620 +sb_slowclk_freq(sb_info_t *si, bool max)
4621 +{
4622 + chipcregs_t *cc;
4623 + uint32 slowclk;
4624 + uint div;
4625 +
4626 +
4627 + ASSERT(sb_coreid(&si->sb) == SB_CC);
4628 +
4629 + cc = (chipcregs_t*) sb_setcoreidx(&si->sb, si->curidx);
4630 +
4631 + /* shouldn't be here unless we've established the chip has dynamic clk control */
4632 + ASSERT(R_REG(&cc->capabilities) & CAP_PWR_CTL);
4633 +
4634 + slowclk = sb_slowclk_src(si);
4635 + if (si->sb.ccrev < 6) {
4636 + if (slowclk == SCC_SS_PCI)
4637 + return (max? (PCIMAXFREQ/64) : (PCIMINFREQ/64));
4638 + else
4639 + return (max? (XTALMAXFREQ/32) : (XTALMINFREQ/32));
4640 + } else if (si->sb.ccrev < 10) {
4641 + div = 4 * (((R_REG(&cc->slow_clk_ctl) & SCC_CD_MASK) >> SCC_CD_SHIFT) + 1);
4642 + if (slowclk == SCC_SS_LPO)
4643 + return (max? LPOMAXFREQ : LPOMINFREQ);
4644 + else if (slowclk == SCC_SS_XTAL)
4645 + return (max? (XTALMAXFREQ/div) : (XTALMINFREQ/div));
4646 + else if (slowclk == SCC_SS_PCI)
4647 + return (max? (PCIMAXFREQ/div) : (PCIMINFREQ/div));
4648 + else
4649 + ASSERT(0);
4650 + } else {
4651 + /* Chipc rev 10 is InstaClock */
4652 + div = R_REG(&cc->system_clk_ctl) >> SYCC_CD_SHIFT;
4653 + div = 4 * (div + 1);
4654 + return (max ? XTALMAXFREQ : (XTALMINFREQ/div));
4655 + }
4656 + return (0);
4657 +}
4658 +
4659 +static void
4660 +sb_clkctl_setdelay(sb_info_t *si, void *chipcregs)
4661 +{
4662 + chipcregs_t * cc;
4663 + uint slowmaxfreq, pll_delay, slowclk;
4664 + uint pll_on_delay, fref_sel_delay;
4665 +
4666 + pll_delay = PLL_DELAY;
4667 +
4668 + /* If the slow clock is not sourced by the xtal then add the xtal_on_delay
4669 + * since the xtal will also be powered down by dynamic clk control logic.
4670 + */
4671 + slowclk = sb_slowclk_src(si);
4672 + if (slowclk != SCC_SS_XTAL)
4673 + pll_delay += XTAL_ON_DELAY;
4674 +
4675 + /* Starting with 4318 it is ILP that is used for the delays */
4676 + slowmaxfreq = sb_slowclk_freq(si, (si->sb.ccrev >= 10) ? FALSE : TRUE);
4677 +
4678 + pll_on_delay = ((slowmaxfreq * pll_delay) + 999999) / 1000000;
4679 + fref_sel_delay = ((slowmaxfreq * FREF_DELAY) + 999999) / 1000000;
4680 +
4681 + cc = (chipcregs_t *)chipcregs;
4682 + W_REG(&cc->pll_on_delay, pll_on_delay);
4683 + W_REG(&cc->fref_sel_delay, fref_sel_delay);
4684 +}
4685 +
4686 +int
4687 +sb_pwrctl_slowclk(void *sbh, bool set, uint *div)
4688 +{
4689 + sb_info_t *si;
4690 + uint origidx;
4691 + chipcregs_t *cc;
4692 + uint intr_val = 0;
4693 + uint err = 0;
4694 +
4695 + si = SB_INFO(sbh);
4696 +
4697 + /* chipcommon cores prior to rev6 don't support slowclkcontrol */
4698 + if (si->sb.ccrev < 6)
4699 + return 1;
4700 +
4701 + /* chipcommon cores rev10 are a whole new ball game */
4702 + if (si->sb.ccrev >= 10)
4703 + return 1;
4704 +
4705 + if (set && ((*div % 4) || (*div < 4)))
4706 + return 2;
4707 +
4708 + INTR_OFF(si, intr_val);
4709 + origidx = si->curidx;
4710 + cc = (chipcregs_t*) sb_setcore(sbh, SB_CC, 0);
4711 + ASSERT(cc != NULL);
4712 +
4713 + if (!(R_REG(&cc->capabilities) & CAP_PWR_CTL)) {
4714 + err = 3;
4715 + goto done;
4716 + }
4717 +
4718 + if (set) {
4719 + SET_REG(&cc->slow_clk_ctl, SCC_CD_MASK, ((*div / 4 - 1) << SCC_CD_SHIFT));
4720 + sb_clkctl_setdelay(sbh, (void *)cc);
4721 + } else
4722 + *div = 4 * (((R_REG(&cc->slow_clk_ctl) & SCC_CD_MASK) >> SCC_CD_SHIFT) + 1);
4723 +
4724 +done:
4725 + sb_setcoreidx(sbh, origidx);
4726 + INTR_RESTORE(si, intr_val);
4727 + return err;
4728 +}
4729 +
4730 +/* initialize power control delay registers */
4731 +void sb_clkctl_init(sb_t *sbh)
4732 +{
4733 + sb_info_t *si;
4734 + uint origidx;
4735 + chipcregs_t *cc;
4736 +
4737 + si = SB_INFO(sbh);
4738 +
4739 + origidx = si->curidx;
4740 +
4741 + if ((cc = (chipcregs_t*) sb_setcore(sbh, SB_CC, 0)) == NULL)
4742 + return;
4743 +
4744 + if (!(R_REG(&cc->capabilities) & CAP_PWR_CTL))
4745 + goto done;
4746 +
4747 + /* set all Instaclk chip ILP to 1 MHz */
4748 + if (si->sb.ccrev >= 10)
4749 + SET_REG(&cc->system_clk_ctl, SYCC_CD_MASK, (ILP_DIV_1MHZ << SYCC_CD_SHIFT));
4750 +
4751 + sb_clkctl_setdelay(si, (void *)cc);
4752 +
4753 +done:
4754 + sb_setcoreidx(sbh, origidx);
4755 +}
4756 +void sb_pwrctl_init(sb_t *sbh)
4757 +{
4758 +sb_clkctl_init(sbh);
4759 +}
4760 +/* return the value suitable for writing to the dot11 core FAST_PWRUP_DELAY register */
4761 +uint16
4762 +sb_clkctl_fast_pwrup_delay(sb_t *sbh)
4763 +{
4764 + sb_info_t *si;
4765 + uint origidx;
4766 + chipcregs_t *cc;
4767 + uint slowminfreq;
4768 + uint16 fpdelay;
4769 + uint intr_val = 0;
4770 +
4771 + si = SB_INFO(sbh);
4772 + fpdelay = 0;
4773 + origidx = si->curidx;
4774 +
4775 + INTR_OFF(si, intr_val);
4776 +
4777 + if ((cc = (chipcregs_t*) sb_setcore(sbh, SB_CC, 0)) == NULL)
4778 + goto done;
4779 +
4780 + if (!(R_REG(&cc->capabilities) & CAP_PWR_CTL))
4781 + goto done;
4782 +
4783 + slowminfreq = sb_slowclk_freq(si, FALSE);
4784 + fpdelay = (((R_REG(&cc->pll_on_delay) + 2) * 1000000) + (slowminfreq - 1)) / slowminfreq;
4785 +
4786 +done:
4787 + sb_setcoreidx(sbh, origidx);
4788 + INTR_RESTORE(si, intr_val);
4789 + return (fpdelay);
4790 +}
4791 +uint16 sb_pwrctl_fast_pwrup_delay(sb_t *sbh)
4792 +{
4793 +return sb_clkctl_fast_pwrup_delay(sbh);
4794 +}
4795 +/* turn primary xtal and/or pll off/on */
4796 +int
4797 +sb_clkctl_xtal(sb_t *sbh, uint what, bool on)
4798 +{
4799 + sb_info_t *si;
4800 + uint32 in, out, outen;
4801 +
4802 + si = SB_INFO(sbh);
4803 +
4804 + switch (BUSTYPE(si->sb.bustype)) {
4805 + case PCI_BUS:
4806 +
4807 + in = OSL_PCI_READ_CONFIG(si->osh, PCI_GPIO_IN, sizeof (uint32));
4808 + out = OSL_PCI_READ_CONFIG(si->osh, PCI_GPIO_OUT, sizeof (uint32));
4809 + outen = OSL_PCI_READ_CONFIG(si->osh, PCI_GPIO_OUTEN, sizeof (uint32));
4810 +
4811 + /*
4812 + * Avoid glitching the clock if GPRS is already using it.
4813 + * We can't actually read the state of the PLLPD so we infer it
4814 + * by the value of XTAL_PU which *is* readable via gpioin.
4815 + */
4816 + if (on && (in & PCI_CFG_GPIO_XTAL))
4817 + return (0);
4818 +
4819 + if (what & XTAL)
4820 + outen |= PCI_CFG_GPIO_XTAL;
4821 + if (what & PLL)
4822 + outen |= PCI_CFG_GPIO_PLL;
4823 +
4824 + if (on) {
4825 + /* turn primary xtal on */
4826 + if (what & XTAL) {
4827 + out |= PCI_CFG_GPIO_XTAL;
4828 + if (what & PLL)
4829 + out |= PCI_CFG_GPIO_PLL;
4830 + OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUT, sizeof (uint32), out);
4831 + OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUTEN, sizeof (uint32), outen);
4832 + OSL_DELAY(XTAL_ON_DELAY);
4833 + }
4834 +
4835 + /* turn pll on */
4836 + if (what & PLL) {
4837 + out &= ~PCI_CFG_GPIO_PLL;
4838 + OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUT, sizeof (uint32), out);
4839 + OSL_DELAY(2000);
4840 + }
4841 + } else {
4842 + if (what & XTAL)
4843 + out &= ~PCI_CFG_GPIO_XTAL;
4844 + if (what & PLL)
4845 + out |= PCI_CFG_GPIO_PLL;
4846 + OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUT, sizeof (uint32), out);
4847 + OSL_PCI_WRITE_CONFIG(si->osh, PCI_GPIO_OUTEN, sizeof (uint32), outen);
4848 + }
4849 +
4850 + default:
4851 + return (-1);
4852 + }
4853 +
4854 + return (0);
4855 +}
4856 +
4857 +int sb_pwrctl_xtal(sb_t *sbh, uint what, bool on)
4858 +{
4859 +return sb_clkctl_xtal(sbh,what,on);
4860 +}
4861 +
4862 +/* set dynamic clk control mode (forceslow, forcefast, dynamic) */
4863 +/* returns true if ignore pll off is set and false if it is not */
4864 +bool
4865 +sb_clkctl_clk(sb_t *sbh, uint mode)
4866 +{
4867 + sb_info_t *si;
4868 + uint origidx;
4869 + chipcregs_t *cc;
4870 + uint32 scc;
4871 + bool forcefastclk=FALSE;
4872 + uint intr_val = 0;
4873 +
4874 + si = SB_INFO(sbh);
4875 +
4876 + /* chipcommon cores prior to rev6 don't support dynamic clock control */
4877 + if (si->sb.ccrev < 6)
4878 + return (FALSE);
4879 +
4880 + /* chipcommon cores rev10 are a whole new ball game */
4881 + if (si->sb.ccrev >= 10)
4882 + return (FALSE);
4883 +
4884 + INTR_OFF(si, intr_val);
4885 +
4886 + origidx = si->curidx;
4887 +
4888 + cc = (chipcregs_t*) sb_setcore(sbh, SB_CC, 0);
4889 + ASSERT(cc != NULL);
4890 +
4891 + if (!(R_REG(&cc->capabilities) & CAP_PWR_CTL))
4892 + goto done;
4893 +
4894 + switch (mode) {
4895 + case CLK_FAST: /* force fast (pll) clock */
4896 + /* don't forget to force xtal back on before we clear SCC_DYN_XTAL.. */
4897 + sb_clkctl_xtal(&si->sb, XTAL, ON);
4898 +
4899 + SET_REG(&cc->slow_clk_ctl, (SCC_XC | SCC_FS | SCC_IP), SCC_IP);
4900 + break;
4901 +
4902 + case CLK_DYNAMIC: /* enable dynamic clock control */
4903 + scc = R_REG(&cc->slow_clk_ctl);
4904 + scc &= ~(SCC_FS | SCC_IP | SCC_XC);
4905 + if ((scc & SCC_SS_MASK) != SCC_SS_XTAL)
4906 + scc |= SCC_XC;
4907 + W_REG(&cc->slow_clk_ctl, scc);
4908 +
4909 + /* for dynamic control, we have to release our xtal_pu "force on" */
4910 + if (scc & SCC_XC)
4911 + sb_clkctl_xtal(&si->sb, XTAL, OFF);
4912 + break;
4913 +
4914 + default:
4915 + ASSERT(0);
4916 + }
4917 +
4918 + /* Is the h/w forcing the use of the fast clk */
4919 + forcefastclk = (bool)((R_REG(&cc->slow_clk_ctl) & SCC_IP) == SCC_IP);
4920 +
4921 +done:
4922 + sb_setcoreidx(sbh, origidx);
4923 + INTR_RESTORE(si, intr_val);
4924 + return (forcefastclk);
4925 +}
4926 +
4927 +bool sb_pwrctl_clk(sb_t *sbh, uint mode)
4928 +{
4929 +return sb_clkctl_clk(sbh, mode);
4930 +}
4931 +/* register driver interrupt disabling and restoring callback functions */
4932 +void
4933 +sb_register_intr_callback(sb_t *sbh, void *intrsoff_fn, void *intrsrestore_fn, void *intrsenabled_fn, void *intr_arg)
4934 +{
4935 + sb_info_t *si;
4936 +
4937 + si = SB_INFO(sbh);
4938 + si->intr_arg = intr_arg;
4939 + si->intrsoff_fn = (sb_intrsoff_t)intrsoff_fn;
4940 + si->intrsrestore_fn = (sb_intrsrestore_t)intrsrestore_fn;
4941 + si->intrsenabled_fn = (sb_intrsenabled_t)intrsenabled_fn;
4942 + /* save current core id. when this function called, the current core
4943 + * must be the core which provides driver functions(il, et, wl, etc.)
4944 + */
4945 + si->dev_coreid = si->coreid[si->curidx];
4946 +}
4947 +
4948 +
4949 +void
4950 +sb_corepciid(sb_t *sbh, uint16 *pcivendor, uint16 *pcidevice,
4951 + uint8 *pciclass, uint8 *pcisubclass, uint8 *pciprogif)
4952 +{
4953 + uint vendor, core, unit;
4954 + uint chip, chippkg;
4955 + char varname[8];
4956 + uint8 class, subclass, progif;
4957 +
4958 + vendor = sb_corevendor(sbh);
4959 + core = sb_coreid(sbh);
4960 + unit = sb_coreunit(sbh);
4961 +
4962 + chip = BCMINIT(sb_chip)(sbh);
4963 + chippkg = BCMINIT(sb_chippkg)(sbh);
4964 +
4965 + progif = 0;
4966 +
4967 + /* Known vendor translations */
4968 + switch (vendor) {
4969 + case SB_VEND_BCM:
4970 + vendor = VENDOR_BROADCOM;
4971 + break;
4972 + }
4973 +
4974 + /* Determine class based on known core codes */
4975 + switch (core) {
4976 + case SB_ILINE20:
4977 + class = PCI_CLASS_NET;
4978 + subclass = PCI_NET_ETHER;
4979 + core = BCM47XX_ILINE_ID;
4980 + break;
4981 + case SB_ENET:
4982 + class = PCI_CLASS_NET;
4983 + subclass = PCI_NET_ETHER;
4984 + core = BCM47XX_ENET_ID;
4985 + break;
4986 + case SB_SDRAM:
4987 + case SB_MEMC:
4988 + class = PCI_CLASS_MEMORY;
4989 + subclass = PCI_MEMORY_RAM;
4990 + break;
4991 + case SB_PCI:
4992 + class = PCI_CLASS_BRIDGE;
4993 + subclass = PCI_BRIDGE_PCI;
4994 + break;
4995 + case SB_MIPS:
4996 + case SB_MIPS33:
4997 + class = PCI_CLASS_CPU;
4998 + subclass = PCI_CPU_MIPS;
4999 + break;
5000 + case SB_CODEC:
5001 + class = PCI_CLASS_COMM;
5002 + subclass = PCI_COMM_MODEM;
5003 + core = BCM47XX_V90_ID;
5004 + break;
5005 + case SB_USB:
5006 + class = PCI_CLASS_SERIAL;
5007 + subclass = PCI_SERIAL_USB;
5008 + progif = 0x10; /* OHCI */
5009 + core = BCM47XX_USB_ID;
5010 + break;
5011 + case SB_USB11H:
5012 + class = PCI_CLASS_SERIAL;
5013 + subclass = PCI_SERIAL_USB;
5014 + progif = 0x10; /* OHCI */
5015 + core = BCM47XX_USBH_ID;
5016 + break;
5017 + case SB_USB11D:
5018 + class = PCI_CLASS_SERIAL;
5019 + subclass = PCI_SERIAL_USB;
5020 + core = BCM47XX_USBD_ID;
5021 + break;
5022 + case SB_IPSEC:
5023 + class = PCI_CLASS_CRYPT;
5024 + subclass = PCI_CRYPT_NETWORK;
5025 + core = BCM47XX_IPSEC_ID;
5026 + break;
5027 + case SB_ROBO:
5028 + class = PCI_CLASS_NET;
5029 + subclass = PCI_NET_OTHER;
5030 + core = BCM47XX_ROBO_ID;
5031 + break;
5032 + case SB_EXTIF:
5033 + case SB_CC:
5034 + class = PCI_CLASS_MEMORY;
5035 + subclass = PCI_MEMORY_FLASH;
5036 + break;
5037 + case SB_D11:
5038 + class = PCI_CLASS_NET;
5039 + subclass = PCI_NET_OTHER;
5040 + /* Let an nvram variable override this */
5041 + sprintf(varname, "wl%did", unit);
5042 + if ((core = getintvar(NULL, varname)) == 0) {
5043 + if (chip == BCM4712_DEVICE_ID) {
5044 + if (chippkg == BCM4712SMALL_PKG_ID)
5045 + core = BCM4306_D11G_ID;
5046 + else
5047 + core = BCM4306_D11DUAL_ID;
5048 + }
5049 + }
5050 + break;
5051 +
5052 + default:
5053 + class = subclass = progif = 0xff;
5054 + break;
5055 + }
5056 +
5057 + *pcivendor = (uint16)vendor;
5058 + *pcidevice = (uint16)core;
5059 + *pciclass = class;
5060 + *pcisubclass = subclass;
5061 + *pciprogif = progif;
5062 +}
5063 +
5064 +#if 0
5065 +/* Build device path. Support SB, PCI, and JTAG for now. */
5066 +int
5067 +sb_devpath(sb_t *sbh, char *path, int size)
5068 +{
5069 + ASSERT(path);
5070 + ASSERT(size >= SB_DEVPATH_BUFSZ);
5071 +
5072 + switch (BUSTYPE((SB_INFO(sbh))->sb.bustype)) {
5073 + case SB_BUS:
5074 + case JTAG_BUS:
5075 + sprintf(path, "sb/%u/", sb_coreidx(sbh));
5076 + break;
5077 + case PCI_BUS:
5078 + ASSERT((SB_INFO(sbh))->osh);
5079 + sprintf(path, "pci/%u/%u/", OSL_PCI_BUS((SB_INFO(sbh))->osh),
5080 + PCI_SLOT(((struct pci_dev *)(SB_INFO(sbh))->osh)->pdev)->devfn);
5081 + break;
5082 + case SDIO_BUS:
5083 + SB_ERROR(("sb_devpath: device 0 assumed\n"));
5084 + sprintf(path, "sd/%u/", sb_coreidx(sbh));
5085 + break;
5086 + default:
5087 + ASSERT(0);
5088 + break;
5089 + }
5090 +
5091 + return 0;
5092 +}
5093 +#endif
5094 +
5095 +/* Fix chip's configuration. The current core may be changed upon return */
5096 +static int
5097 +sb_pci_fixcfg(sb_info_t *si)
5098 +{
5099 + uint origidx, pciidx;
5100 + sbpciregs_t *pciregs;
5101 + uint16 val16, *reg16;
5102 + char name[SB_DEVPATH_BUFSZ+16], *value;
5103 + char devpath[SB_DEVPATH_BUFSZ];
5104 +
5105 + ASSERT(BUSTYPE(si->sb.bustype) == PCI_BUS);
5106 +
5107 + /* Fix PCI(e) SROM shadow area */
5108 + /* save the current index */
5109 + origidx = sb_coreidx(&si->sb);
5110 +
5111 + if (si->sb.buscoretype == SB_PCI) {
5112 + pciregs = (sbpciregs_t *)sb_setcore(&si->sb, SB_PCI, 0);
5113 + ASSERT(pciregs);
5114 + reg16 = &pciregs->sprom[SRSH_PI_OFFSET];
5115 + }
5116 + else {
5117 + ASSERT(0);
5118 + return -1;
5119 + }
5120 + pciidx = sb_coreidx(&si->sb);
5121 + val16 = R_REG(reg16);
5122 + if (((val16 & SRSH_PI_MASK) >> SRSH_PI_SHIFT) != (uint16)pciidx) {
5123 + val16 = (uint16)(pciidx << SRSH_PI_SHIFT) | (val16 & ~SRSH_PI_MASK);
5124 + W_REG(reg16, val16);
5125 + }
5126 +
5127 + /* restore the original index */
5128 + sb_setcoreidx(&si->sb, origidx);
5129 +
5130 +#if 0
5131 + /* Fix bar0window */
5132 + /* !do it last, it changes the current core! */
5133 + if (sb_devpath(&si->sb, devpath, sizeof(devpath)))
5134 + return -1;
5135 + sprintf(name, "%sb0w", devpath);
5136 + if ((value = getvar(NULL, name))) {
5137 + OSL_PCI_WRITE_CONFIG(si->osh, PCI_BAR0_WIN, sizeof(uint32),
5138 + bcm_strtoul(value, NULL, 16));
5139 + /* update curidx since the current core is changed */
5140 + si->curidx = _sb_coreidx(si);
5141 + if (si->curidx == BADIDX) {
5142 + SB_ERROR(("sb_pci_fixcfg: bad core index\n"));
5143 + return -1;
5144 + }
5145 + }
5146 +#endif
5147 +
5148 + return 0;
5149 +}
5150 +
5151 diff -urN linux.old/arch/mips/bcm947xx/broadcom/sflash.c linux.dev/arch/mips/bcm947xx/broadcom/sflash.c
5152 --- linux.old/arch/mips/bcm947xx/broadcom/sflash.c 1970-01-01 01:00:00.000000000 +0100
5153 +++ linux.dev/arch/mips/bcm947xx/broadcom/sflash.c 2005-12-15 16:59:20.045933750 +0100
5154 @@ -0,0 +1,418 @@
5155 +/*
5156 + * Broadcom SiliconBackplane chipcommon serial flash interface
5157 + *
5158 + * Copyright 2005, Broadcom Corporation
5159 + * All Rights Reserved.
5160 + *
5161 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
5162 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
5163 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
5164 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
5165 + *
5166 + * $Id$
5167 + */
5168 +
5169 +#include <osl.h>
5170 +#include <typedefs.h>
5171 +#include <sbconfig.h>
5172 +#include <sbchipc.h>
5173 +#include <mipsinc.h>
5174 +#include <bcmutils.h>
5175 +#include <bcmdevs.h>
5176 +#include <sflash.h>
5177 +
5178 +/* Private global state */
5179 +static struct sflash sflash;
5180 +
5181 +/* Issue a serial flash command */
5182 +static INLINE void
5183 +sflash_cmd(chipcregs_t *cc, uint opcode)
5184 +{
5185 + W_REG(&cc->flashcontrol, SFLASH_START | opcode);
5186 + while (R_REG(&cc->flashcontrol) & SFLASH_BUSY);
5187 +}
5188 +
5189 +/* Initialize serial flash access */
5190 +struct sflash *
5191 +sflash_init(chipcregs_t *cc)
5192 +{
5193 + uint32 id, id2;
5194 +
5195 + bzero(&sflash, sizeof(sflash));
5196 +
5197 + sflash.type = R_REG(&cc->capabilities) & CAP_FLASH_MASK;
5198 +
5199 + switch (sflash.type) {
5200 + case SFLASH_ST:
5201 + /* Probe for ST chips */
5202 + sflash_cmd(cc, SFLASH_ST_DP);
5203 + sflash_cmd(cc, SFLASH_ST_RES);
5204 + id = R_REG(&cc->flashdata);
5205 + switch (id) {
5206 + case 0x11:
5207 + /* ST M25P20 2 Mbit Serial Flash */
5208 + sflash.blocksize = 64 * 1024;
5209 + sflash.numblocks = 4;
5210 + break;
5211 + case 0x12:
5212 + /* ST M25P40 4 Mbit Serial Flash */
5213 + sflash.blocksize = 64 * 1024;
5214 + sflash.numblocks = 8;
5215 + break;
5216 + case 0x13:
5217 + /* ST M25P80 8 Mbit Serial Flash */
5218 + sflash.blocksize = 64 * 1024;
5219 + sflash.numblocks = 16;
5220 + break;
5221 + case 0x14:
5222 + /* ST M25P16 16 Mbit Serial Flash */
5223 + sflash.blocksize = 64 * 1024;
5224 + sflash.numblocks = 32;
5225 + break;
5226 + case 0x15:
5227 + /* ST M25P32 32 Mbit Serial Flash */
5228 + sflash.blocksize = 64 * 1024;
5229 + sflash.numblocks = 64;
5230 + break;
5231 + case 0xbf:
5232 + W_REG(&cc->flashaddress, 1);
5233 + sflash_cmd(cc, SFLASH_ST_RES);
5234 + id2 = R_REG(&cc->flashdata);
5235 + if (id2 == 0x44) {
5236 + /* SST M25VF80 4 Mbit Serial Flash */
5237 + sflash.blocksize = 64 * 1024;
5238 + sflash.numblocks = 8;
5239 + }
5240 + break;
5241 + }
5242 + break;
5243 +
5244 + case SFLASH_AT:
5245 + /* Probe for Atmel chips */
5246 + sflash_cmd(cc, SFLASH_AT_STATUS);
5247 + id = R_REG(&cc->flashdata) & 0x3c;
5248 + switch (id) {
5249 + case 0xc:
5250 + /* Atmel AT45DB011 1Mbit Serial Flash */
5251 + sflash.blocksize = 256;
5252 + sflash.numblocks = 512;
5253 + break;
5254 + case 0x14:
5255 + /* Atmel AT45DB021 2Mbit Serial Flash */
5256 + sflash.blocksize = 256;
5257 + sflash.numblocks = 1024;
5258 + break;
5259 + case 0x1c:
5260 + /* Atmel AT45DB041 4Mbit Serial Flash */
5261 + sflash.blocksize = 256;
5262 + sflash.numblocks = 2048;
5263 + break;
5264 + case 0x24:
5265 + /* Atmel AT45DB081 8Mbit Serial Flash */
5266 + sflash.blocksize = 256;
5267 + sflash.numblocks = 4096;
5268 + break;
5269 + case 0x2c:
5270 + /* Atmel AT45DB161 16Mbit Serial Flash */
5271 + sflash.blocksize = 512;
5272 + sflash.numblocks = 4096;
5273 + break;
5274 + case 0x34:
5275 + /* Atmel AT45DB321 32Mbit Serial Flash */
5276 + sflash.blocksize = 512;
5277 + sflash.numblocks = 8192;
5278 + break;
5279 + case 0x3c:
5280 + /* Atmel AT45DB642 64Mbit Serial Flash */
5281 + sflash.blocksize = 1024;
5282 + sflash.numblocks = 8192;
5283 + break;
5284 + }
5285 + break;
5286 + }
5287 +
5288 + sflash.size = sflash.blocksize * sflash.numblocks;
5289 + return sflash.size ? &sflash : NULL;
5290 +}
5291 +
5292 +/* Read len bytes starting at offset into buf. Returns number of bytes read. */
5293 +int
5294 +sflash_read(chipcregs_t *cc, uint offset, uint len, uchar *buf)
5295 +{
5296 + int cnt;
5297 + uint32 *from, *to;
5298 +
5299 + if (!len)
5300 + return 0;
5301 +
5302 + if ((offset + len) > sflash.size)
5303 + return -22;
5304 +
5305 + if ((len >= 4) && (offset & 3))
5306 + cnt = 4 - (offset & 3);
5307 + else if ((len >= 4) && ((uint32)buf & 3))
5308 + cnt = 4 - ((uint32)buf & 3);
5309 + else
5310 + cnt = len;
5311 +
5312 + from = (uint32 *)KSEG1ADDR(SB_FLASH2 + offset);
5313 + to = (uint32 *)buf;
5314 +
5315 + if (cnt < 4) {
5316 + bcopy(from, to, cnt);
5317 + return cnt;
5318 + }
5319 +
5320 + while (cnt >= 4) {
5321 + *to++ = *from++;
5322 + cnt -= 4;
5323 + }
5324 +
5325 + return (len - cnt);
5326 +}
5327 +
5328 +/* Poll for command completion. Returns zero when complete. */
5329 +int
5330 +sflash_poll(chipcregs_t *cc, uint offset)
5331 +{
5332 + if (offset >= sflash.size)
5333 + return -22;
5334 +
5335 + switch (sflash.type) {
5336 + case SFLASH_ST:
5337 + /* Check for ST Write In Progress bit */
5338 + sflash_cmd(cc, SFLASH_ST_RDSR);
5339 + return R_REG(&cc->flashdata) & SFLASH_ST_WIP;
5340 + case SFLASH_AT:
5341 + /* Check for Atmel Ready bit */
5342 + sflash_cmd(cc, SFLASH_AT_STATUS);
5343 + return !(R_REG(&cc->flashdata) & SFLASH_AT_READY);
5344 + }
5345 +
5346 + return 0;
5347 +}
5348 +
5349 +/* Write len bytes starting at offset into buf. Returns number of bytes
5350 + * written. Caller should poll for completion.
5351 + */
5352 +int
5353 +sflash_write(chipcregs_t *cc, uint offset, uint len, const uchar *buf)
5354 +{
5355 + struct sflash *sfl;
5356 + int ret = 0;
5357 + bool is4712b0;
5358 + uint32 page, byte, mask;
5359 +
5360 + if (!len)
5361 + return 0;
5362 +
5363 + if ((offset + len) > sflash.size)
5364 + return -22;
5365 +
5366 + sfl = &sflash;
5367 + switch (sfl->type) {
5368 + case SFLASH_ST:
5369 + mask = R_REG(&cc->chipid);
5370 + is4712b0 = (((mask & CID_ID_MASK) == BCM4712_DEVICE_ID) &&
5371 + ((mask & CID_REV_MASK) == (3 << CID_REV_SHIFT)));
5372 + /* Enable writes */
5373 + sflash_cmd(cc, SFLASH_ST_WREN);
5374 + if (is4712b0) {
5375 + mask = 1 << 14;
5376 + W_REG(&cc->flashaddress, offset);
5377 + W_REG(&cc->flashdata, *buf++);
5378 + /* Set chip select */
5379 + OR_REG(&cc->gpioout, mask);
5380 + /* Issue a page program with the first byte */
5381 + sflash_cmd(cc, SFLASH_ST_PP);
5382 + ret = 1;
5383 + offset++;
5384 + len--;
5385 + while (len > 0) {
5386 + if ((offset & 255) == 0) {
5387 + /* Page boundary, drop cs and return */
5388 + AND_REG(&cc->gpioout, ~mask);
5389 + if (!sflash_poll(cc, offset)) {
5390 + /* Flash rejected command */
5391 + return -11;
5392 + }
5393 + return ret;
5394 + } else {
5395 + /* Write single byte */
5396 + sflash_cmd(cc, *buf++);
5397 + }
5398 + ret++;
5399 + offset++;
5400 + len--;
5401 + }
5402 + /* All done, drop cs if needed */
5403 + if ((offset & 255) != 1) {
5404 + /* Drop cs */
5405 + AND_REG(&cc->gpioout, ~mask);
5406 + if (!sflash_poll(cc, offset)) {
5407 + /* Flash rejected command */
5408 + return -12;
5409 + }
5410 + }
5411 + } else {
5412 + ret = 1;
5413 + W_REG(&cc->flashaddress, offset);
5414 + W_REG(&cc->flashdata, *buf);
5415 + /* Page program */
5416 + sflash_cmd(cc, SFLASH_ST_PP);
5417 + }
5418 + break;
5419 + case SFLASH_AT:
5420 + mask = sfl->blocksize - 1;
5421 + page = (offset & ~mask) << 1;
5422 + byte = offset & mask;
5423 + /* Read main memory page into buffer 1 */
5424 + if (byte || len < sfl->blocksize) {
5425 + W_REG(&cc->flashaddress, page);
5426 + sflash_cmd(cc, SFLASH_AT_BUF1_LOAD);
5427 + /* 250 us for AT45DB321B */
5428 + SPINWAIT(sflash_poll(cc, offset), 1000);
5429 + ASSERT(!sflash_poll(cc, offset));
5430 + }
5431 + /* Write into buffer 1 */
5432 + for (ret = 0; ret < len && byte < sfl->blocksize; ret++) {
5433 + W_REG(&cc->flashaddress, byte++);
5434 + W_REG(&cc->flashdata, *buf++);
5435 + sflash_cmd(cc, SFLASH_AT_BUF1_WRITE);
5436 + }
5437 + /* Write buffer 1 into main memory page */
5438 + W_REG(&cc->flashaddress, page);
5439 + sflash_cmd(cc, SFLASH_AT_BUF1_PROGRAM);
5440 + break;
5441 + }
5442 +
5443 + return ret;
5444 +}
5445 +
5446 +/* Erase a region. Returns number of bytes scheduled for erasure.
5447 + * Caller should poll for completion.
5448 + */
5449 +int
5450 +sflash_erase(chipcregs_t *cc, uint offset)
5451 +{
5452 + struct sflash *sfl;
5453 +
5454 + if (offset >= sflash.size)
5455 + return -22;
5456 +
5457 + sfl = &sflash;
5458 + switch (sfl->type) {
5459 + case SFLASH_ST:
5460 + sflash_cmd(cc, SFLASH_ST_WREN);
5461 + W_REG(&cc->flashaddress, offset);
5462 + sflash_cmd(cc, SFLASH_ST_SE);
5463 + return sfl->blocksize;
5464 + case SFLASH_AT:
5465 + W_REG(&cc->flashaddress, offset << 1);
5466 + sflash_cmd(cc, SFLASH_AT_PAGE_ERASE);
5467 + return sfl->blocksize;
5468 + }
5469 +
5470 + return 0;
5471 +}
5472 +
5473 +/*
5474 + * writes the appropriate range of flash, a NULL buf simply erases
5475 + * the region of flash
5476 + */
5477 +int
5478 +sflash_commit(chipcregs_t *cc, uint offset, uint len, const uchar *buf)
5479 +{
5480 + struct sflash *sfl;
5481 + uchar *block = NULL, *cur_ptr, *blk_ptr;
5482 + uint blocksize = 0, mask, cur_offset, cur_length, cur_retlen, remainder;
5483 + uint blk_offset, blk_len, copied;
5484 + int bytes, ret = 0;
5485 +
5486 + /* Check address range */
5487 + if (len <= 0)
5488 + return 0;
5489 +
5490 + sfl = &sflash;
5491 + if ((offset + len) > sfl->size)
5492 + return -1;
5493 +
5494 + blocksize = sfl->blocksize;
5495 + mask = blocksize - 1;
5496 +
5497 + /* Allocate a block of mem */
5498 + if (!(block = MALLOC(NULL, blocksize)))
5499 + return -1;
5500 +
5501 + while (len) {
5502 + /* Align offset */
5503 + cur_offset = offset & ~mask;
5504 + cur_length = blocksize;
5505 + cur_ptr = block;
5506 +
5507 + remainder = blocksize - (offset & mask);
5508 + if (len < remainder)
5509 + cur_retlen = len;
5510 + else
5511 + cur_retlen = remainder;
5512 +
5513 + /* buf == NULL means erase only */
5514 + if (buf) {
5515 + /* Copy existing data into holding block if necessary */
5516 + if ((offset & mask) || (len < blocksize)) {
5517 + blk_offset = cur_offset;
5518 + blk_len = cur_length;
5519 + blk_ptr = cur_ptr;
5520 +
5521 + /* Copy entire block */
5522 + while(blk_len) {
5523 + copied = sflash_read(cc, blk_offset, blk_len, blk_ptr);
5524 + blk_offset += copied;
5525 + blk_len -= copied;
5526 + blk_ptr += copied;
5527 + }
5528 + }
5529 +
5530 + /* Copy input data into holding block */
5531 + memcpy(cur_ptr + (offset & mask), buf, cur_retlen);
5532 + }
5533 +
5534 + /* Erase block */
5535 + if ((ret = sflash_erase(cc, (uint) cur_offset)) < 0)
5536 + goto done;
5537 + while (sflash_poll(cc, (uint) cur_offset));
5538 +
5539 + /* buf == NULL means erase only */
5540 + if (!buf) {
5541 + offset += cur_retlen;
5542 + len -= cur_retlen;
5543 + continue;
5544 + }
5545 +
5546 + /* Write holding block */
5547 + while (cur_length > 0) {
5548 + if ((bytes = sflash_write(cc,
5549 + (uint) cur_offset,
5550 + (uint) cur_length,
5551 + (uchar *) cur_ptr)) < 0) {
5552 + ret = bytes;
5553 + goto done;
5554 + }
5555 + while (sflash_poll(cc, (uint) cur_offset));
5556 + cur_offset += bytes;
5557 + cur_length -= bytes;
5558 + cur_ptr += bytes;
5559 + }
5560 +
5561 + offset += cur_retlen;
5562 + len -= cur_retlen;
5563 + buf += cur_retlen;
5564 + }
5565 +
5566 + ret = len;
5567 +done:
5568 + if (block)
5569 + MFREE(NULL, block, blocksize);
5570 + return ret;
5571 +}
5572 +
5573 diff -urN linux.old/arch/mips/bcm947xx/include/bcmdevs.h linux.dev/arch/mips/bcm947xx/include/bcmdevs.h
5574 --- linux.old/arch/mips/bcm947xx/include/bcmdevs.h 1970-01-01 01:00:00.000000000 +0100
5575 +++ linux.dev/arch/mips/bcm947xx/include/bcmdevs.h 2005-12-15 15:25:24.905340500 +0100
5576 @@ -0,0 +1,391 @@
5577 +/*
5578 + * Broadcom device-specific manifest constants.
5579 + *
5580 + * Copyright 2005, Broadcom Corporation
5581 + * All Rights Reserved.
5582 + *
5583 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
5584 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
5585 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
5586 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
5587 + * $Id$
5588 + */
5589 +
5590 +#ifndef _BCMDEVS_H
5591 +#define _BCMDEVS_H
5592 +
5593 +
5594 +/* Known PCI vendor Id's */
5595 +#define VENDOR_EPIGRAM 0xfeda
5596 +#define VENDOR_BROADCOM 0x14e4
5597 +#define VENDOR_3COM 0x10b7
5598 +#define VENDOR_NETGEAR 0x1385
5599 +#define VENDOR_DIAMOND 0x1092
5600 +#define VENDOR_DELL 0x1028
5601 +#define VENDOR_HP 0x0e11
5602 +#define VENDOR_APPLE 0x106b
5603 +
5604 +/* PCI Device Id's */
5605 +#define BCM4210_DEVICE_ID 0x1072 /* never used */
5606 +#define BCM4211_DEVICE_ID 0x4211
5607 +#define BCM4230_DEVICE_ID 0x1086 /* never used */
5608 +#define BCM4231_DEVICE_ID 0x4231
5609 +
5610 +#define BCM4410_DEVICE_ID 0x4410 /* bcm44xx family pci iline */
5611 +#define BCM4430_DEVICE_ID 0x4430 /* bcm44xx family cardbus iline */
5612 +#define BCM4412_DEVICE_ID 0x4412 /* bcm44xx family pci enet */
5613 +#define BCM4432_DEVICE_ID 0x4432 /* bcm44xx family cardbus enet */
5614 +
5615 +#define BCM3352_DEVICE_ID 0x3352 /* bcm3352 device id */
5616 +#define BCM3360_DEVICE_ID 0x3360 /* bcm3360 device id */
5617 +
5618 +#define EPI41210_DEVICE_ID 0xa0fa /* bcm4210 */
5619 +#define EPI41230_DEVICE_ID 0xa10e /* bcm4230 */
5620 +
5621 +#define BCM47XX_ILINE_ID 0x4711 /* 47xx iline20 */
5622 +#define BCM47XX_V90_ID 0x4712 /* 47xx v90 codec */
5623 +#define BCM47XX_ENET_ID 0x4713 /* 47xx enet */
5624 +#define BCM47XX_EXT_ID 0x4714 /* 47xx external i/f */
5625 +#define BCM47XX_USB_ID 0x4715 /* 47xx usb */
5626 +#define BCM47XX_USBH_ID 0x4716 /* 47xx usb host */
5627 +#define BCM47XX_USBD_ID 0x4717 /* 47xx usb device */
5628 +#define BCM47XX_IPSEC_ID 0x4718 /* 47xx ipsec */
5629 +#define BCM47XX_ROBO_ID 0x4719 /* 47xx/53xx roboswitch core */
5630 +#define BCM47XX_USB20H_ID 0x471a /* 47xx usb 2.0 host */
5631 +#define BCM47XX_USB20D_ID 0x471b /* 47xx usb 2.0 device */
5632 +
5633 +#define BCM4710_DEVICE_ID 0x4710 /* 4710 primary function 0 */
5634 +
5635 +#define BCM4610_DEVICE_ID 0x4610 /* 4610 primary function 0 */
5636 +#define BCM4610_ILINE_ID 0x4611 /* 4610 iline100 */
5637 +#define BCM4610_V90_ID 0x4612 /* 4610 v90 codec */
5638 +#define BCM4610_ENET_ID 0x4613 /* 4610 enet */
5639 +#define BCM4610_EXT_ID 0x4614 /* 4610 external i/f */
5640 +#define BCM4610_USB_ID 0x4615 /* 4610 usb */
5641 +
5642 +#define BCM4402_DEVICE_ID 0x4402 /* 4402 primary function 0 */
5643 +#define BCM4402_ENET_ID 0x4402 /* 4402 enet */
5644 +#define BCM4402_V90_ID 0x4403 /* 4402 v90 codec */
5645 +#define BCM4401_ENET_ID 0x170c /* 4401b0 production enet cards */
5646 +
5647 +#define BCM4301_DEVICE_ID 0x4301 /* 4301 primary function 0 */
5648 +#define BCM4301_D11B_ID 0x4301 /* 4301 802.11b */
5649 +
5650 +#define BCM4307_DEVICE_ID 0x4307 /* 4307 primary function 0 */
5651 +#define BCM4307_V90_ID 0x4305 /* 4307 v90 codec */
5652 +#define BCM4307_ENET_ID 0x4306 /* 4307 enet */
5653 +#define BCM4307_D11B_ID 0x4307 /* 4307 802.11b */
5654 +
5655 +#define BCM4306_DEVICE_ID 0x4306 /* 4306 chipcommon chipid */
5656 +#define BCM4306_D11G_ID 0x4320 /* 4306 802.11g */
5657 +#define BCM4306_D11G_ID2 0x4325
5658 +#define BCM4306_D11A_ID 0x4321 /* 4306 802.11a */
5659 +#define BCM4306_UART_ID 0x4322 /* 4306 uart */
5660 +#define BCM4306_V90_ID 0x4323 /* 4306 v90 codec */
5661 +#define BCM4306_D11DUAL_ID 0x4324 /* 4306 dual A+B */
5662 +
5663 +#define BCM4309_PKG_ID 1 /* 4309 package id */
5664 +
5665 +#define BCM4303_D11B_ID 0x4303 /* 4303 802.11b */
5666 +#define BCM4303_PKG_ID 2 /* 4303 package id */
5667 +
5668 +#define BCM4310_DEVICE_ID 0x4310 /* 4310 chipcommon chipid */
5669 +#define BCM4310_D11B_ID 0x4311 /* 4310 802.11b */
5670 +#define BCM4310_UART_ID 0x4312 /* 4310 uart */
5671 +#define BCM4310_ENET_ID 0x4313 /* 4310 enet */
5672 +#define BCM4310_USB_ID 0x4315 /* 4310 usb */
5673 +
5674 +#define BCMGPRS_UART_ID 0x4333 /* Uart id used by 4306/gprs card */
5675 +#define BCMGPRS2_UART_ID 0x4344 /* Uart id used by 4306/gprs card */
5676 +
5677 +
5678 +#define BCM4704_DEVICE_ID 0x4704 /* 4704 chipcommon chipid */
5679 +#define BCM4704_ENET_ID 0x4706 /* 4704 enet (Use 47XX_ENET_ID instead!) */
5680 +
5681 +#define BCM4317_DEVICE_ID 0x4317 /* 4317 chip common chipid */
5682 +
5683 +#define BCM4318_DEVICE_ID 0x4318 /* 4318 chip common chipid */
5684 +#define BCM4318_D11G_ID 0x4318 /* 4318 801.11b/g id */
5685 +#define BCM4318_D11DUAL_ID 0x4319 /* 4318 801.11a/b/g id */
5686 +#define BCM4318_JTAGM_ID 0x4331 /* 4318 jtagm device id */
5687 +
5688 +#define FPGA_JTAGM_ID 0x4330 /* ??? */
5689 +
5690 +/* Address map */
5691 +#define BCM4710_SDRAM 0x00000000 /* Physical SDRAM */
5692 +#define BCM4710_PCI_MEM 0x08000000 /* Host Mode PCI memory access space (64 MB) */
5693 +#define BCM4710_PCI_CFG 0x0c000000 /* Host Mode PCI configuration space (64 MB) */
5694 +#define BCM4710_PCI_DMA 0x40000000 /* Client Mode PCI memory access space (1 GB) */
5695 +#define BCM4710_SDRAM_SWAPPED 0x10000000 /* Byteswapped Physical SDRAM */
5696 +#define BCM4710_ENUM 0x18000000 /* Beginning of core enumeration space */
5697 +
5698 +/* Core register space */
5699 +#define BCM4710_REG_SDRAM 0x18000000 /* SDRAM core registers */
5700 +#define BCM4710_REG_ILINE20 0x18001000 /* InsideLine20 core registers */
5701 +#define BCM4710_REG_EMAC0 0x18002000 /* Ethernet MAC 0 core registers */
5702 +#define BCM4710_REG_CODEC 0x18003000 /* Codec core registers */
5703 +#define BCM4710_REG_USB 0x18004000 /* USB core registers */
5704 +#define BCM4710_REG_PCI 0x18005000 /* PCI core registers */
5705 +#define BCM4710_REG_MIPS 0x18006000 /* MIPS core registers */
5706 +#define BCM4710_REG_EXTIF 0x18007000 /* External Interface core registers */
5707 +#define BCM4710_REG_EMAC1 0x18008000 /* Ethernet MAC 1 core registers */
5708 +
5709 +#define BCM4710_EXTIF 0x1f000000 /* External Interface base address */
5710 +#define BCM4710_PCMCIA_MEM 0x1f000000 /* External Interface PCMCIA memory access */
5711 +#define BCM4710_PCMCIA_IO 0x1f100000 /* PCMCIA I/O access */
5712 +#define BCM4710_PCMCIA_CONF 0x1f200000 /* PCMCIA configuration */
5713 +#define BCM4710_PROG 0x1f800000 /* Programable interface */
5714 +#define BCM4710_FLASH 0x1fc00000 /* Flash */
5715 +
5716 +#define BCM4710_EJTAG 0xff200000 /* MIPS EJTAG space (2M) */
5717 +
5718 +#define BCM4710_UART (BCM4710_REG_EXTIF + 0x00000300)
5719 +
5720 +#define BCM4710_EUART (BCM4710_EXTIF + 0x00800000)
5721 +#define BCM4710_LED (BCM4710_EXTIF + 0x00900000)
5722 +
5723 +#define BCM4712_DEVICE_ID 0x4712 /* 4712 chipcommon chipid */
5724 +#define BCM4712_MIPS_ID 0x4720 /* 4712 base devid */
5725 +#define BCM4712LARGE_PKG_ID 0 /* 340pin 4712 package id */
5726 +#define BCM4712SMALL_PKG_ID 1 /* 200pin 4712 package id */
5727 +#define BCM4712MID_PKG_ID 2 /* 225pin 4712 package id */
5728 +
5729 +#define SDIOH_FPGA_ID 0x4380 /* sdio host fpga */
5730 +
5731 +#define BCM5365_DEVICE_ID 0x5365 /* 5365 chipcommon chipid */
5732 +#define BCM5350_DEVICE_ID 0x5350 /* bcm5350 chipcommon chipid */
5733 +#define BCM5352_DEVICE_ID 0x5352 /* bcm5352 chipcommon chipid */
5734 +
5735 +#define BCM4320_DEVICE_ID 0x4320 /* bcm4320 chipcommon chipid */
5736 +
5737 +/* PCMCIA vendor Id's */
5738 +
5739 +#define VENDOR_BROADCOM_PCMCIA 0x02d0
5740 +
5741 +/* SDIO vendor Id's */
5742 +#define VENDOR_BROADCOM_SDIO 0x00BF
5743 +
5744 +
5745 +/* boardflags */
5746 +#define BFL_BTCOEXIST 0x0001 /* This board implements Bluetooth coexistance */
5747 +#define BFL_PACTRL 0x0002 /* This board has gpio 9 controlling the PA */
5748 +#define BFL_AIRLINEMODE 0x0004 /* This board implements gpio13 radio disable indication */
5749 +#define BFL_ENETROBO 0x0010 /* This board has robo switch or core */
5750 +#define BFL_CCKHIPWR 0x0040 /* Can do high-power CCK transmission */
5751 +#define BFL_ENETADM 0x0080 /* This board has ADMtek switch */
5752 +#define BFL_ENETVLAN 0x0100 /* This board has vlan capability */
5753 +#define BFL_AFTERBURNER 0x0200 /* This board supports Afterburner mode */
5754 +#define BFL_NOPCI 0x0400 /* This board leaves PCI floating */
5755 +#define BFL_FEM 0x0800 /* This board supports the Front End Module */
5756 +#define BFL_EXTLNA 0x1000 /* This board has an external LNA */
5757 +#define BFL_HGPA 0x2000 /* This board has a high gain PA */
5758 +#define BFL_BTCMOD 0x4000 /* This board' BTCOEXIST is in the alternate gpios */
5759 +#define BFL_ALTIQ 0x8000 /* Alternate I/Q settings */
5760 +
5761 +/* board specific GPIO assignment, gpio 0-3 are also customer-configurable led */
5762 +#define BOARD_GPIO_HWRAD_B 0x010 /* bit 4 is HWRAD input on 4301 */
5763 +#define BOARD_GPIO_BTCMOD_IN 0x010 /* bit 4 is the alternate BT Coexistance Input */
5764 +#define BOARD_GPIO_BTCMOD_OUT 0x020 /* bit 5 is the alternate BT Coexistance Out */
5765 +#define BOARD_GPIO_BTC_IN 0x080 /* bit 7 is BT Coexistance Input */
5766 +#define BOARD_GPIO_BTC_OUT 0x100 /* bit 8 is BT Coexistance Out */
5767 +#define BOARD_GPIO_PACTRL 0x200 /* bit 9 controls the PA on new 4306 boards */
5768 +#define PCI_CFG_GPIO_SCS 0x10 /* PCI config space bit 4 for 4306c0 slow clock source */
5769 +#define PCI_CFG_GPIO_HWRAD 0x20 /* PCI config space GPIO 13 for hw radio disable */
5770 +#define PCI_CFG_GPIO_XTAL 0x40 /* PCI config space GPIO 14 for Xtal powerup */
5771 +#define PCI_CFG_GPIO_PLL 0x80 /* PCI config space GPIO 15 for PLL powerdown */
5772 +
5773 +/* Bus types */
5774 +#define SB_BUS 0 /* Silicon Backplane */
5775 +#define PCI_BUS 1 /* PCI target */
5776 +#define PCMCIA_BUS 2 /* PCMCIA target */
5777 +#define SDIO_BUS 3 /* SDIO target */
5778 +#define JTAG_BUS 4 /* JTAG */
5779 +
5780 +/* Allows optimization for single-bus support */
5781 +#ifdef BCMBUSTYPE
5782 +#define BUSTYPE(bus) (BCMBUSTYPE)
5783 +#else
5784 +#define BUSTYPE(bus) (bus)
5785 +#endif
5786 +
5787 +/* power control defines */
5788 +#define PLL_DELAY 150 /* us pll on delay */
5789 +#define FREF_DELAY 200 /* us fref change delay */
5790 +#define MIN_SLOW_CLK 32 /* us Slow clock period */
5791 +#define XTAL_ON_DELAY 1000 /* us crystal power-on delay */
5792 +
5793 +/* Reference Board Types */
5794 +
5795 +#define BU4710_BOARD 0x0400
5796 +#define VSIM4710_BOARD 0x0401
5797 +#define QT4710_BOARD 0x0402
5798 +
5799 +#define BU4610_BOARD 0x0403
5800 +#define VSIM4610_BOARD 0x0404
5801 +
5802 +#define BU4307_BOARD 0x0405
5803 +#define BCM94301CB_BOARD 0x0406
5804 +#define BCM94301PC_BOARD 0x0406 /* Pcmcia 5v card */
5805 +#define BCM94301MP_BOARD 0x0407
5806 +#define BCM94307MP_BOARD 0x0408
5807 +#define BCMAP4307_BOARD 0x0409
5808 +
5809 +#define BU4309_BOARD 0x040a
5810 +#define BCM94309CB_BOARD 0x040b
5811 +#define BCM94309MP_BOARD 0x040c
5812 +#define BCM4309AP_BOARD 0x040d
5813 +
5814 +#define BCM94302MP_BOARD 0x040e
5815 +
5816 +#define VSIM4310_BOARD 0x040f
5817 +#define BU4711_BOARD 0x0410
5818 +#define BCM94310U_BOARD 0x0411
5819 +#define BCM94310AP_BOARD 0x0412
5820 +#define BCM94310MP_BOARD 0x0414
5821 +
5822 +#define BU4306_BOARD 0x0416
5823 +#define BCM94306CB_BOARD 0x0417
5824 +#define BCM94306MP_BOARD 0x0418
5825 +
5826 +#define BCM94710D_BOARD 0x041a
5827 +#define BCM94710R1_BOARD 0x041b
5828 +#define BCM94710R4_BOARD 0x041c
5829 +#define BCM94710AP_BOARD 0x041d
5830 +
5831 +
5832 +#define BU2050_BOARD 0x041f
5833 +
5834 +
5835 +#define BCM94309G_BOARD 0x0421
5836 +
5837 +#define BCM94301PC3_BOARD 0x0422 /* Pcmcia 3.3v card */
5838 +
5839 +#define BU4704_BOARD 0x0423
5840 +#define BU4702_BOARD 0x0424
5841 +
5842 +#define BCM94306PC_BOARD 0x0425 /* pcmcia 3.3v 4306 card */
5843 +
5844 +#define BU4317_BOARD 0x0426
5845 +
5846 +
5847 +#define BCM94702MN_BOARD 0x0428
5848 +
5849 +/* BCM4702 1U CompactPCI Board */
5850 +#define BCM94702CPCI_BOARD 0x0429
5851 +
5852 +/* BCM4702 with BCM95380 VLAN Router */
5853 +#define BCM95380RR_BOARD 0x042a
5854 +
5855 +/* cb4306 with SiGe PA */
5856 +#define BCM94306CBSG_BOARD 0x042b
5857 +
5858 +/* mp4301 with 2050 radio */
5859 +#define BCM94301MPL_BOARD 0x042c
5860 +
5861 +/* cb4306 with SiGe PA */
5862 +#define PCSG94306_BOARD 0x042d
5863 +
5864 +/* bu4704 with sdram */
5865 +#define BU4704SD_BOARD 0x042e
5866 +
5867 +/* Dual 11a/11g Router */
5868 +#define BCM94704AGR_BOARD 0x042f
5869 +
5870 +/* 11a-only minipci */
5871 +#define BCM94308MP_BOARD 0x0430
5872 +
5873 +
5874 +
5875 +/* BCM94317 boards */
5876 +#define BCM94317CB_BOARD 0x0440
5877 +#define BCM94317MP_BOARD 0x0441
5878 +#define BCM94317PCMCIA_BOARD 0x0442
5879 +#define BCM94317SDIO_BOARD 0x0443
5880 +
5881 +#define BU4712_BOARD 0x0444
5882 +#define BU4712SD_BOARD 0x045d
5883 +#define BU4712L_BOARD 0x045f
5884 +
5885 +/* BCM4712 boards */
5886 +#define BCM94712AP_BOARD 0x0445
5887 +#define BCM94712P_BOARD 0x0446
5888 +
5889 +/* BCM4318 boards */
5890 +#define BU4318_BOARD 0x0447
5891 +#define CB4318_BOARD 0x0448
5892 +#define MPG4318_BOARD 0x0449
5893 +#define MP4318_BOARD 0x044a
5894 +#define SD4318_BOARD 0x044b
5895 +
5896 +/* BCM63XX boards */
5897 +#define BCM96338_BOARD 0x6338
5898 +#define BCM96345_BOARD 0x6345
5899 +#define BCM96348_BOARD 0x6348
5900 +
5901 +/* Another mp4306 with SiGe */
5902 +#define BCM94306P_BOARD 0x044c
5903 +
5904 +/* CF-like 4317 modules */
5905 +#define BCM94317CF_BOARD 0x044d
5906 +
5907 +/* mp4303 */
5908 +#define BCM94303MP_BOARD 0x044e
5909 +
5910 +/* mpsgh4306 */
5911 +#define BCM94306MPSGH_BOARD 0x044f
5912 +
5913 +/* BRCM 4306 w/ Front End Modules */
5914 +#define BCM94306MPM 0x0450
5915 +#define BCM94306MPL 0x0453
5916 +
5917 +/* 4712agr */
5918 +#define BCM94712AGR_BOARD 0x0451
5919 +
5920 +/* The real CF 4317 board */
5921 +#define CFI4317_BOARD 0x0452
5922 +
5923 +/* pcmcia 4303 */
5924 +#define PC4303_BOARD 0x0454
5925 +
5926 +/* 5350K */
5927 +#define BCM95350K_BOARD 0x0455
5928 +
5929 +/* 5350R */
5930 +#define BCM95350R_BOARD 0x0456
5931 +
5932 +/* 4306mplna */
5933 +#define BCM94306MPLNA_BOARD 0x0457
5934 +
5935 +/* 4320 boards */
5936 +#define BU4320_BOARD 0x0458
5937 +#define BU4320S_BOARD 0x0459
5938 +#define BCM94320PH_BOARD 0x045a
5939 +
5940 +/* 4306mph */
5941 +#define BCM94306MPH_BOARD 0x045b
5942 +
5943 +/* 4306pciv */
5944 +#define BCM94306PCIV_BOARD 0x045c
5945 +
5946 +#define BU4712SD_BOARD 0x045d
5947 +
5948 +#define BCM94320PFLSH_BOARD 0x045e
5949 +
5950 +#define BU4712L_BOARD 0x045f
5951 +#define BCM94712LGR_BOARD 0x0460
5952 +#define BCM94320R_BOARD 0x0461
5953 +
5954 +#define BU5352_BOARD 0x0462
5955 +
5956 +#define BCM94318MPGH_BOARD 0x0463
5957 +
5958 +
5959 +#define BCM95352GR_BOARD 0x0467
5960 +
5961 +/* bcm95351agr */
5962 +#define BCM95351AGR_BOARD 0x0470
5963 +
5964 +/* # of GPIO pins */
5965 +#define GPIO_NUMPINS 16
5966 +
5967 +#endif /* _BCMDEVS_H */
5968 diff -urN linux.old/arch/mips/bcm947xx/include/bcmendian.h linux.dev/arch/mips/bcm947xx/include/bcmendian.h
5969 --- linux.old/arch/mips/bcm947xx/include/bcmendian.h 1970-01-01 01:00:00.000000000 +0100
5970 +++ linux.dev/arch/mips/bcm947xx/include/bcmendian.h 2005-12-15 15:25:47.146730500 +0100
5971 @@ -0,0 +1,152 @@
5972 +/*
5973 + * local version of endian.h - byte order defines
5974 + *
5975 + * Copyright 2005, Broadcom Corporation
5976 + * All Rights Reserved.
5977 + *
5978 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
5979 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
5980 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
5981 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
5982 + *
5983 + * $Id$
5984 +*/
5985 +
5986 +#ifndef _BCMENDIAN_H_
5987 +#define _BCMENDIAN_H_
5988 +
5989 +#include <typedefs.h>
5990 +
5991 +/* Byte swap a 16 bit value */
5992 +#define BCMSWAP16(val) \
5993 + ((uint16)( \
5994 + (((uint16)(val) & (uint16)0x00ffU) << 8) | \
5995 + (((uint16)(val) & (uint16)0xff00U) >> 8) ))
5996 +
5997 +/* Byte swap a 32 bit value */
5998 +#define BCMSWAP32(val) \
5999 + ((uint32)( \
6000 + (((uint32)(val) & (uint32)0x000000ffUL) << 24) | \
6001 + (((uint32)(val) & (uint32)0x0000ff00UL) << 8) | \
6002 + (((uint32)(val) & (uint32)0x00ff0000UL) >> 8) | \
6003 + (((uint32)(val) & (uint32)0xff000000UL) >> 24) ))
6004 +
6005 +/* 2 Byte swap a 32 bit value */
6006 +#define BCMSWAP32BY16(val) \
6007 + ((uint32)( \
6008 + (((uint32)(val) & (uint32)0x0000ffffUL) << 16) | \
6009 + (((uint32)(val) & (uint32)0xffff0000UL) >> 16) ))
6010 +
6011 +
6012 +static INLINE uint16
6013 +bcmswap16(uint16 val)
6014 +{
6015 + return BCMSWAP16(val);
6016 +}
6017 +
6018 +static INLINE uint32
6019 +bcmswap32(uint32 val)
6020 +{
6021 + return BCMSWAP32(val);
6022 +}
6023 +
6024 +static INLINE uint32
6025 +bcmswap32by16(uint32 val)
6026 +{
6027 + return BCMSWAP32BY16(val);
6028 +}
6029 +
6030 +/* buf - start of buffer of shorts to swap */
6031 +/* len - byte length of buffer */
6032 +static INLINE void
6033 +bcmswap16_buf(uint16 *buf, uint len)
6034 +{
6035 + len = len/2;
6036 +
6037 + while(len--){
6038 + *buf = bcmswap16(*buf);
6039 + buf++;
6040 + }
6041 +}
6042 +
6043 +#ifndef hton16
6044 +#ifndef IL_BIGENDIAN
6045 +#define HTON16(i) BCMSWAP16(i)
6046 +#define hton16(i) bcmswap16(i)
6047 +#define hton32(i) bcmswap32(i)
6048 +#define ntoh16(i) bcmswap16(i)
6049 +#define ntoh32(i) bcmswap32(i)
6050 +#define ltoh16(i) (i)
6051 +#define ltoh32(i) (i)
6052 +#define htol16(i) (i)
6053 +#define htol32(i) (i)
6054 +#else
6055 +#define HTON16(i) (i)
6056 +#define hton16(i) (i)
6057 +#define hton32(i) (i)
6058 +#define ntoh16(i) (i)
6059 +#define ntoh32(i) (i)
6060 +#define ltoh16(i) bcmswap16(i)
6061 +#define ltoh32(i) bcmswap32(i)
6062 +#define htol16(i) bcmswap16(i)
6063 +#define htol32(i) bcmswap32(i)
6064 +#endif
6065 +#endif
6066 +
6067 +#ifndef IL_BIGENDIAN
6068 +#define ltoh16_buf(buf, i)
6069 +#define htol16_buf(buf, i)
6070 +#else
6071 +#define ltoh16_buf(buf, i) bcmswap16_buf((uint16*)buf, i)
6072 +#define htol16_buf(buf, i) bcmswap16_buf((uint16*)buf, i)
6073 +#endif
6074 +
6075 +/*
6076 +* load 16-bit value from unaligned little endian byte array.
6077 +*/
6078 +static INLINE uint16
6079 +ltoh16_ua(uint8 *bytes)
6080 +{
6081 + return (bytes[1]<<8)+bytes[0];
6082 +}
6083 +
6084 +/*
6085 +* load 32-bit value from unaligned little endian byte array.
6086 +*/
6087 +static INLINE uint32
6088 +ltoh32_ua(uint8 *bytes)
6089 +{
6090 + return (bytes[3]<<24)+(bytes[2]<<16)+(bytes[1]<<8)+bytes[0];
6091 +}
6092 +
6093 +/*
6094 +* load 16-bit value from unaligned big(network) endian byte array.
6095 +*/
6096 +static INLINE uint16
6097 +ntoh16_ua(uint8 *bytes)
6098 +{
6099 + return (bytes[0]<<8)+bytes[1];
6100 +}
6101 +
6102 +/*
6103 +* load 32-bit value from unaligned big(network) endian byte array.
6104 +*/
6105 +static INLINE uint32
6106 +ntoh32_ua(uint8 *bytes)
6107 +{
6108 + return (bytes[0]<<24)+(bytes[1]<<16)+(bytes[2]<<8)+bytes[3];
6109 +}
6110 +
6111 +#define ltoh_ua(ptr) ( \
6112 + sizeof(*(ptr)) == sizeof(uint8) ? *(uint8 *)ptr : \
6113 + sizeof(*(ptr)) == sizeof(uint16) ? (((uint8 *)ptr)[1]<<8)+((uint8 *)ptr)[0] : \
6114 + (((uint8 *)ptr)[3]<<24)+(((uint8 *)ptr)[2]<<16)+(((uint8 *)ptr)[1]<<8)+((uint8 *)ptr)[0] \
6115 +)
6116 +
6117 +#define ntoh_ua(ptr) ( \
6118 + sizeof(*(ptr)) == sizeof(uint8) ? *(uint8 *)ptr : \
6119 + sizeof(*(ptr)) == sizeof(uint16) ? (((uint8 *)ptr)[0]<<8)+((uint8 *)ptr)[1] : \
6120 + (((uint8 *)ptr)[0]<<24)+(((uint8 *)ptr)[1]<<16)+(((uint8 *)ptr)[2]<<8)+((uint8 *)ptr)[3] \
6121 +)
6122 +
6123 +#endif /* _BCMENDIAN_H_ */
6124 diff -urN linux.old/arch/mips/bcm947xx/include/bcmnvram.h linux.dev/arch/mips/bcm947xx/include/bcmnvram.h
6125 --- linux.old/arch/mips/bcm947xx/include/bcmnvram.h 1970-01-01 01:00:00.000000000 +0100
6126 +++ linux.dev/arch/mips/bcm947xx/include/bcmnvram.h 2005-12-15 16:04:35.850827500 +0100
6127 @@ -0,0 +1,87 @@
6128 +/*
6129 + * NVRAM variable manipulation
6130 + *
6131 + * Copyright 2005, Broadcom Corporation
6132 + * All Rights Reserved.
6133 + *
6134 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
6135 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
6136 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
6137 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
6138 + *
6139 + * $Id$
6140 + */
6141 +
6142 +#ifndef _bcmnvram_h_
6143 +#define _bcmnvram_h_
6144 +
6145 +#ifndef _LANGUAGE_ASSEMBLY
6146 +
6147 +#include <typedefs.h>
6148 +
6149 +struct nvram_header {
6150 + uint32 magic;
6151 + uint32 len;
6152 + uint32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
6153 + uint32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
6154 + uint32 config_ncdl; /* ncdl values for memc */
6155 +};
6156 +
6157 +struct nvram_tuple {
6158 + char *name;
6159 + char *value;
6160 + struct nvram_tuple *next;
6161 +};
6162 +
6163 +/*
6164 + * Get the value of an NVRAM variable. The pointer returned may be
6165 + * invalid after a set.
6166 + * @param name name of variable to get
6167 + * @return value of variable or NULL if undefined
6168 + */
6169 +extern char * __init nvram_get(const char *name);
6170 +
6171 +/*
6172 + * Get the value of an NVRAM variable.
6173 + * @param name name of variable to get
6174 + * @return value of variable or NUL if undefined
6175 + */
6176 +#define nvram_safe_get(name) (BCMINIT(nvram_get)(name) ? : "")
6177 +
6178 +/*
6179 + * Match an NVRAM variable.
6180 + * @param name name of variable to match
6181 + * @param match value to compare against value of variable
6182 + * @return TRUE if variable is defined and its value is string equal
6183 + * to match or FALSE otherwise
6184 + */
6185 +static inline int
6186 +nvram_match(char *name, char *match) {
6187 + const char *value = BCMINIT(nvram_get)(name);
6188 + return (value && !strcmp(value, match));
6189 +}
6190 +
6191 +/*
6192 + * Inversely match an NVRAM variable.
6193 + * @param name name of variable to match
6194 + * @param match value to compare against value of variable
6195 + * @return TRUE if variable is defined and its value is not string
6196 + * equal to invmatch or FALSE otherwise
6197 + */
6198 +static inline int
6199 +nvram_invmatch(char *name, char *invmatch) {
6200 + const char *value = BCMINIT(nvram_get)(name);
6201 + return (value && strcmp(value, invmatch));
6202 +}
6203 +
6204 +#endif /* _LANGUAGE_ASSEMBLY */
6205 +
6206 +#define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
6207 +#define NVRAM_VERSION 1
6208 +#define NVRAM_HEADER_SIZE 20
6209 +#define NVRAM_SPACE 0x8000
6210 +
6211 +#define NVRAM_MAX_VALUE_LEN 255
6212 +#define NVRAM_MAX_PARAM_LEN 64
6213 +
6214 +#endif /* _bcmnvram_h_ */
6215 diff -urN linux.old/arch/mips/bcm947xx/include/bcmsrom.h linux.dev/arch/mips/bcm947xx/include/bcmsrom.h
6216 --- linux.old/arch/mips/bcm947xx/include/bcmsrom.h 1970-01-01 01:00:00.000000000 +0100
6217 +++ linux.dev/arch/mips/bcm947xx/include/bcmsrom.h 2005-12-15 15:34:32.919589250 +0100
6218 @@ -0,0 +1,23 @@
6219 +/*
6220 + * Misc useful routines to access NIC local SROM/OTP .
6221 + *
6222 + * Copyright 2005, Broadcom Corporation
6223 + * All Rights Reserved.
6224 + *
6225 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
6226 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
6227 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
6228 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
6229 + *
6230 + * $Id$
6231 + */
6232 +
6233 +#ifndef _bcmsrom_h_
6234 +#define _bcmsrom_h_
6235 +
6236 +extern int srom_var_init(void *sbh, uint bus, void *curmap, osl_t *osh, char **vars, int *count);
6237 +
6238 +extern int srom_read(uint bus, void *curmap, osl_t *osh, uint byteoff, uint nbytes, uint16 *buf);
6239 +extern int srom_write(uint bus, void *curmap, osl_t *osh, uint byteoff, uint nbytes, uint16 *buf);
6240 +
6241 +#endif /* _bcmsrom_h_ */
6242 diff -urN linux.old/arch/mips/bcm947xx/include/bcmutils.h linux.dev/arch/mips/bcm947xx/include/bcmutils.h
6243 --- linux.old/arch/mips/bcm947xx/include/bcmutils.h 1970-01-01 01:00:00.000000000 +0100
6244 +++ linux.dev/arch/mips/bcm947xx/include/bcmutils.h 2005-12-15 16:44:25.619117750 +0100
6245 @@ -0,0 +1,308 @@
6246 +/*
6247 + * Misc useful os-independent macros and functions.
6248 + *
6249 + * Copyright 2005, Broadcom Corporation
6250 + * All Rights Reserved.
6251 + *
6252 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
6253 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
6254 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
6255 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
6256 + * $Id$
6257 + */
6258 +
6259 +#ifndef _bcmutils_h_
6260 +#define _bcmutils_h_
6261 +
6262 +/*** driver-only section ***/
6263 +#include <osl.h>
6264 +
6265 +#define _BCM_U 0x01 /* upper */
6266 +#define _BCM_L 0x02 /* lower */
6267 +#define _BCM_D 0x04 /* digit */
6268 +#define _BCM_C 0x08 /* cntrl */
6269 +#define _BCM_P 0x10 /* punct */
6270 +#define _BCM_S 0x20 /* white space (space/lf/tab) */
6271 +#define _BCM_X 0x40 /* hex digit */
6272 +#define _BCM_SP 0x80 /* hard space (0x20) */
6273 +
6274 +#define GPIO_PIN_NOTDEFINED 0x20
6275 +
6276 +extern unsigned char bcm_ctype[];
6277 +#define bcm_ismask(x) (bcm_ctype[(int)(unsigned char)(x)])
6278 +
6279 +#define bcm_isalnum(c) ((bcm_ismask(c)&(_BCM_U|_BCM_L|_BCM_D)) != 0)
6280 +#define bcm_isalpha(c) ((bcm_ismask(c)&(_BCM_U|_BCM_L)) != 0)
6281 +#define bcm_iscntrl(c) ((bcm_ismask(c)&(_BCM_C)) != 0)
6282 +#define bcm_isdigit(c) ((bcm_ismask(c)&(_BCM_D)) != 0)
6283 +#define bcm_isgraph(c) ((bcm_ismask(c)&(_BCM_P|_BCM_U|_BCM_L|_BCM_D)) != 0)
6284 +#define bcm_islower(c) ((bcm_ismask(c)&(_BCM_L)) != 0)
6285 +#define bcm_isprint(c) ((bcm_ismask(c)&(_BCM_P|_BCM_U|_BCM_L|_BCM_D|_BCM_SP)) != 0)
6286 +#define bcm_ispunct(c) ((bcm_ismask(c)&(_BCM_P)) != 0)
6287 +#define bcm_isspace(c) ((bcm_ismask(c)&(_BCM_S)) != 0)
6288 +#define bcm_isupper(c) ((bcm_ismask(c)&(_BCM_U)) != 0)
6289 +#define bcm_isxdigit(c) ((bcm_ismask(c)&(_BCM_D|_BCM_X)) != 0)
6290 +
6291 +/*
6292 + * Spin at most 'us' microseconds while 'exp' is true.
6293 + * Caller should explicitly test 'exp' when this completes
6294 + * and take appropriate error action if 'exp' is still true.
6295 + */
6296 +#define SPINWAIT(exp, us) { \
6297 + uint countdown = (us) + 9; \
6298 + while ((exp) && (countdown >= 10)) {\
6299 + OSL_DELAY(10); \
6300 + countdown -= 10; \
6301 + } \
6302 +}
6303 +
6304 +/* generic osl packet queue */
6305 +struct pktq {
6306 + void *head; /* first packet to dequeue */
6307 + void *tail; /* last packet to dequeue */
6308 + uint len; /* number of queued packets */
6309 + uint maxlen; /* maximum number of queued packets */
6310 + bool priority; /* enqueue by packet priority */
6311 + uint8 prio_map[MAXPRIO+1]; /* user priority to packet enqueue policy map */
6312 +};
6313 +#define DEFAULT_QLEN 128
6314 +
6315 +#define pktq_len(q) ((q)->len)
6316 +#define pktq_avail(q) ((q)->maxlen - (q)->len)
6317 +#define pktq_head(q) ((q)->head)
6318 +#define pktq_full(q) ((q)->len >= (q)->maxlen)
6319 +#define _pktq_pri(q, pri) ((q)->prio_map[pri])
6320 +#define pktq_tailpri(q) ((q)->tail ? _pktq_pri(q, PKTPRIO((q)->tail)) : _pktq_pri(q, 0))
6321 +
6322 +/* externs */
6323 +/* packet */
6324 +extern uint pktcopy(osl_t *osh, void *p, uint offset, int len, uchar *buf);
6325 +extern uint pkttotlen(osl_t *osh, void *);
6326 +extern void pktq_init(struct pktq *q, uint maxlen, const uint8 prio_map[]);
6327 +extern void pktenq(struct pktq *q, void *p, bool lifo);
6328 +extern void *pktdeq(struct pktq *q);
6329 +extern void *pktdeqtail(struct pktq *q);
6330 +/* string */
6331 +extern uint bcm_atoi(char *s);
6332 +extern uchar bcm_toupper(uchar c);
6333 +extern ulong bcm_strtoul(char *cp, char **endp, uint base);
6334 +extern char *bcmstrstr(char *haystack, char *needle);
6335 +extern char *bcmstrcat(char *dest, const char *src);
6336 +extern ulong wchar2ascii(char *abuf, ushort *wbuf, ushort wbuflen, ulong abuflen);
6337 +/* ethernet address */
6338 +extern char *bcm_ether_ntoa(char *ea, char *buf);
6339 +extern int bcm_ether_atoe(char *p, char *ea);
6340 +/* delay */
6341 +extern void bcm_mdelay(uint ms);
6342 +/* variable access */
6343 +extern char *getvar(char *vars, char *name);
6344 +extern int getintvar(char *vars, char *name);
6345 +extern uint getgpiopin(char *vars, char *pin_name, uint def_pin);
6346 +#define bcmlog(fmt, a1, a2)
6347 +#define bcmdumplog(buf, size) *buf = '\0'
6348 +#define bcmdumplogent(buf, idx) -1
6349 +
6350 +/*** driver/apps-shared section ***/
6351 +
6352 +#define BCME_STRLEN 64
6353 +#define VALID_BCMERROR(e) ((e <= 0) && (e >= BCME_LAST))
6354 +
6355 +
6356 +/*
6357 + * error codes could be added but the defined ones shouldn't be changed/deleted
6358 + * these error codes are exposed to the user code
6359 + * when ever a new error code is added to this list
6360 + * please update errorstring table with the related error string and
6361 + * update osl files with os specific errorcode map
6362 +*/
6363 +
6364 +#define BCME_ERROR -1 /* Error generic */
6365 +#define BCME_BADARG -2 /* Bad Argument */
6366 +#define BCME_BADOPTION -3 /* Bad option */
6367 +#define BCME_NOTUP -4 /* Not up */
6368 +#define BCME_NOTDOWN -5 /* Not down */
6369 +#define BCME_NOTAP -6 /* Not AP */
6370 +#define BCME_NOTSTA -7 /* Not STA */
6371 +#define BCME_BADKEYIDX -8 /* BAD Key Index */
6372 +#define BCME_RADIOOFF -9 /* Radio Off */
6373 +#define BCME_NOTBANDLOCKED -10 /* Not bandlocked */
6374 +#define BCME_NOCLK -11 /* No Clock*/
6375 +#define BCME_BADRATESET -12 /* BAD RateSet*/
6376 +#define BCME_BADBAND -13 /* BAD Band */
6377 +#define BCME_BUFTOOSHORT -14 /* Buffer too short */
6378 +#define BCME_BUFTOOLONG -15 /* Buffer too Long */
6379 +#define BCME_BUSY -16 /* Busy*/
6380 +#define BCME_NOTASSOCIATED -17 /* Not associated*/
6381 +#define BCME_BADSSIDLEN -18 /* BAD SSID Len */
6382 +#define BCME_OUTOFRANGECHAN -19 /* Out of Range Channel*/
6383 +#define BCME_BADCHAN -20 /* BAD Channel */
6384 +#define BCME_BADADDR -21 /* BAD Address*/
6385 +#define BCME_NORESOURCE -22 /* No resources*/
6386 +#define BCME_UNSUPPORTED -23 /* Unsupported*/
6387 +#define BCME_BADLEN -24 /* Bad Length*/
6388 +#define BCME_NOTREADY -25 /* Not ready Yet*/
6389 +#define BCME_EPERM -26 /* Not Permitted */
6390 +#define BCME_NOMEM -27 /* No Memory */
6391 +#define BCME_ASSOCIATED -28 /* Associated */
6392 +#define BCME_RANGE -29 /* Range Error*/
6393 +#define BCME_NOTFOUND -30 /* Not found */
6394 +#define BCME_LAST BCME_NOTFOUND
6395 +
6396 +#ifndef ABS
6397 +#define ABS(a) (((a)<0)?-(a):(a))
6398 +#endif
6399 +
6400 +#ifndef MIN
6401 +#define MIN(a, b) (((a)<(b))?(a):(b))
6402 +#endif
6403 +
6404 +#ifndef MAX
6405 +#define MAX(a, b) (((a)>(b))?(a):(b))
6406 +#endif
6407 +
6408 +#define CEIL(x, y) (((x) + ((y)-1)) / (y))
6409 +#define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y))
6410 +#define ISALIGNED(a, x) (((a) & ((x)-1)) == 0)
6411 +#define ISPOWEROF2(x) ((((x)-1)&(x))==0)
6412 +#define VALID_MASK(mask) !((mask) & ((mask) + 1))
6413 +#define OFFSETOF(type, member) ((uint)(uintptr)&((type *)0)->member)
6414 +#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
6415 +
6416 +/* bit map related macros */
6417 +#ifndef setbit
6418 +#define NBBY 8 /* 8 bits per byte */
6419 +#define setbit(a,i) (((uint8 *)a)[(i)/NBBY] |= 1<<((i)%NBBY))
6420 +#define clrbit(a,i) (((uint8 *)a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
6421 +#define isset(a,i) (((uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY)))
6422 +#define isclr(a,i) ((((uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
6423 +#endif
6424 +
6425 +#define NBITS(type) (sizeof(type) * 8)
6426 +#define NBITVAL(bits) (1 << (bits))
6427 +#define MAXBITVAL(bits) ((1 << (bits)) - 1)
6428 +
6429 +/* crc defines */
6430 +#define CRC8_INIT_VALUE 0xff /* Initial CRC8 checksum value */
6431 +#define CRC8_GOOD_VALUE 0x9f /* Good final CRC8 checksum value */
6432 +#define CRC16_INIT_VALUE 0xffff /* Initial CRC16 checksum value */
6433 +#define CRC16_GOOD_VALUE 0xf0b8 /* Good final CRC16 checksum value */
6434 +#define CRC32_INIT_VALUE 0xffffffff /* Initial CRC32 checksum value */
6435 +#define CRC32_GOOD_VALUE 0xdebb20e3 /* Good final CRC32 checksum value */
6436 +
6437 +/* bcm_format_flags() bit description structure */
6438 +typedef struct bcm_bit_desc {
6439 + uint32 bit;
6440 + char* name;
6441 +} bcm_bit_desc_t;
6442 +
6443 +/* tag_ID/length/value_buffer tuple */
6444 +typedef struct bcm_tlv {
6445 + uint8 id;
6446 + uint8 len;
6447 + uint8 data[1];
6448 +} bcm_tlv_t;
6449 +
6450 +/* Check that bcm_tlv_t fits into the given buflen */
6451 +#define bcm_valid_tlv(elt, buflen) ((buflen) >= 2 && (int)(buflen) >= (int)(2 + (elt)->len))
6452 +
6453 +/* buffer length for ethernet address from bcm_ether_ntoa() */
6454 +#define ETHER_ADDR_STR_LEN 18
6455 +
6456 +/* unaligned load and store macros */
6457 +#ifdef IL_BIGENDIAN
6458 +static INLINE uint32
6459 +load32_ua(uint8 *a)
6460 +{
6461 + return ((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]);
6462 +}
6463 +
6464 +static INLINE void
6465 +store32_ua(uint8 *a, uint32 v)
6466 +{
6467 + a[0] = (v >> 24) & 0xff;
6468 + a[1] = (v >> 16) & 0xff;
6469 + a[2] = (v >> 8) & 0xff;
6470 + a[3] = v & 0xff;
6471 +}
6472 +
6473 +static INLINE uint16
6474 +load16_ua(uint8 *a)
6475 +{
6476 + return ((a[0] << 8) | a[1]);
6477 +}
6478 +
6479 +static INLINE void
6480 +store16_ua(uint8 *a, uint16 v)
6481 +{
6482 + a[0] = (v >> 8) & 0xff;
6483 + a[1] = v & 0xff;
6484 +}
6485 +
6486 +#else
6487 +
6488 +static INLINE uint32
6489 +load32_ua(uint8 *a)
6490 +{
6491 + return ((a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]);
6492 +}
6493 +
6494 +static INLINE void
6495 +store32_ua(uint8 *a, uint32 v)
6496 +{
6497 + a[3] = (v >> 24) & 0xff;
6498 + a[2] = (v >> 16) & 0xff;
6499 + a[1] = (v >> 8) & 0xff;
6500 + a[0] = v & 0xff;
6501 +}
6502 +
6503 +static INLINE uint16
6504 +load16_ua(uint8 *a)
6505 +{
6506 + return ((a[1] << 8) | a[0]);
6507 +}
6508 +
6509 +static INLINE void
6510 +store16_ua(uint8 *a, uint16 v)
6511 +{
6512 + a[1] = (v >> 8) & 0xff;
6513 + a[0] = v & 0xff;
6514 +}
6515 +
6516 +#endif
6517 +
6518 +/* externs */
6519 +/* crc */
6520 +extern uint8 hndcrc8(uint8 *p, uint nbytes, uint8 crc);
6521 +/* format/print */
6522 +/* IE parsing */
6523 +extern bcm_tlv_t *bcm_next_tlv(bcm_tlv_t *elt, int *buflen);
6524 +extern bcm_tlv_t *bcm_parse_tlvs(void *buf, int buflen, uint key);
6525 +extern bcm_tlv_t *bcm_parse_ordered_tlvs(void *buf, int buflen, uint key);
6526 +
6527 +/* bcmerror*/
6528 +extern const char *bcmerrorstr(int bcmerror);
6529 +
6530 +/* multi-bool data type: set of bools, mbool is true if any is set */
6531 +typedef uint32 mbool;
6532 +#define mboolset(mb, bit) (mb |= bit) /* set one bool */
6533 +#define mboolclr(mb, bit) (mb &= ~bit) /* clear one bool */
6534 +#define mboolisset(mb, bit) ((mb & bit) != 0) /* TRUE if one bool is set */
6535 +#define mboolmaskset(mb, mask, val) ((mb) = (((mb) & ~(mask)) | (val)))
6536 +
6537 +/* power conversion */
6538 +extern uint16 bcm_qdbm_to_mw(uint8 qdbm);
6539 +extern uint8 bcm_mw_to_qdbm(uint16 mw);
6540 +
6541 +/* generic datastruct to help dump routines */
6542 +struct fielddesc {
6543 + char *nameandfmt;
6544 + uint32 offset;
6545 + uint32 len;
6546 +};
6547 +
6548 +typedef uint32 (*readreg_rtn)(void *arg0, void *arg1, uint32 offset);
6549 +extern uint bcmdumpfields(readreg_rtn func_ptr, void *arg0, void *arg1, struct fielddesc *str, char *buf, uint32 bufsize);
6550 +
6551 +extern uint bcm_mkiovar(char *name, char *data, uint datalen, char *buf, uint len);
6552 +
6553 +#endif /* _bcmutils_h_ */
6554 diff -urN linux.old/arch/mips/bcm947xx/include/bitfuncs.h linux.dev/arch/mips/bcm947xx/include/bitfuncs.h
6555 --- linux.old/arch/mips/bcm947xx/include/bitfuncs.h 1970-01-01 01:00:00.000000000 +0100
6556 +++ linux.dev/arch/mips/bcm947xx/include/bitfuncs.h 2005-12-15 15:34:40.268048500 +0100
6557 @@ -0,0 +1,85 @@
6558 +/*
6559 + * bit manipulation utility functions
6560 + *
6561 + * Copyright 2005, Broadcom Corporation
6562 + * All Rights Reserved.
6563 + *
6564 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
6565 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
6566 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
6567 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
6568 + * $Id$
6569 + */
6570 +
6571 +#ifndef _BITFUNCS_H
6572 +#define _BITFUNCS_H
6573 +
6574 +#include <typedefs.h>
6575 +
6576 +/* local prototypes */
6577 +static INLINE uint32 find_msbit(uint32 x);
6578 +
6579 +
6580 +/*
6581 + * find_msbit: returns index of most significant set bit in x, with index
6582 + * range defined as 0-31. NOTE: returns zero if input is zero.
6583 + */
6584 +
6585 +#if defined(USE_PENTIUM_BSR) && defined(__GNUC__)
6586 +
6587 +/*
6588 + * Implementation for Pentium processors and gcc. Note that this
6589 + * instruction is actually very slow on some processors (e.g., family 5,
6590 + * model 2, stepping 12, "Pentium 75 - 200"), so we use the generic
6591 + * implementation instead.
6592 + */
6593 +static INLINE uint32 find_msbit(uint32 x)
6594 +{
6595 + uint msbit;
6596 + __asm__("bsrl %1,%0"
6597 + :"=r" (msbit)
6598 + :"r" (x));
6599 + return msbit;
6600 +}
6601 +
6602 +#else
6603 +
6604 +/*
6605 + * Generic Implementation
6606 + */
6607 +
6608 +#define DB_POW_MASK16 0xffff0000
6609 +#define DB_POW_MASK8 0x0000ff00
6610 +#define DB_POW_MASK4 0x000000f0
6611 +#define DB_POW_MASK2 0x0000000c
6612 +#define DB_POW_MASK1 0x00000002
6613 +
6614 +static INLINE uint32 find_msbit(uint32 x)
6615 +{
6616 + uint32 temp_x = x;
6617 + uint msbit = 0;
6618 + if (temp_x & DB_POW_MASK16) {
6619 + temp_x >>= 16;
6620 + msbit = 16;
6621 + }
6622 + if (temp_x & DB_POW_MASK8) {
6623 + temp_x >>= 8;
6624 + msbit += 8;
6625 + }
6626 + if (temp_x & DB_POW_MASK4) {
6627 + temp_x >>= 4;
6628 + msbit += 4;
6629 + }
6630 + if (temp_x & DB_POW_MASK2) {
6631 + temp_x >>= 2;
6632 + msbit += 2;
6633 + }
6634 + if (temp_x & DB_POW_MASK1) {
6635 + msbit += 1;
6636 + }
6637 + return(msbit);
6638 +}
6639 +
6640 +#endif
6641 +
6642 +#endif /* _BITFUNCS_H */
6643 diff -urN linux.old/arch/mips/bcm947xx/include/flash.h linux.dev/arch/mips/bcm947xx/include/flash.h
6644 --- linux.old/arch/mips/bcm947xx/include/flash.h 1970-01-01 01:00:00.000000000 +0100
6645 +++ linux.dev/arch/mips/bcm947xx/include/flash.h 2005-12-15 15:34:44.280299250 +0100
6646 @@ -0,0 +1,188 @@
6647 +/*
6648 + * flash.h: Common definitions for flash access.
6649 + *
6650 + * Copyright 2005, Broadcom Corporation
6651 + * All Rights Reserved.
6652 + *
6653 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
6654 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
6655 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
6656 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
6657 + *
6658 + * $Id$
6659 + */
6660 +
6661 +/* Types of flashes we know about */
6662 +typedef enum _flash_type {OLD, BSC, SCS, AMD, SST, SFLASH} flash_type_t;
6663 +
6664 +/* Commands to write/erase the flases */
6665 +typedef struct _flash_cmds{
6666 + flash_type_t type;
6667 + bool need_unlock;
6668 + uint16 pre_erase;
6669 + uint16 erase_block;
6670 + uint16 erase_chip;
6671 + uint16 write_word;
6672 + uint16 write_buf;
6673 + uint16 clear_csr;
6674 + uint16 read_csr;
6675 + uint16 read_id;
6676 + uint16 confirm;
6677 + uint16 read_array;
6678 +} flash_cmds_t;
6679 +
6680 +#define UNLOCK_CMD_WORDS 2
6681 +
6682 +typedef struct _unlock_cmd {
6683 + uint addr[UNLOCK_CMD_WORDS];
6684 + uint16 cmd[UNLOCK_CMD_WORDS];
6685 +} unlock_cmd_t;
6686 +
6687 +/* Flash descriptors */
6688 +typedef struct _flash_desc {
6689 + uint16 mfgid; /* Manufacturer Id */
6690 + uint16 devid; /* Device Id */
6691 + uint size; /* Total size in bytes */
6692 + uint width; /* Device width in bytes */
6693 + flash_type_t type; /* Device type old, S, J */
6694 + uint bsize; /* Block size */
6695 + uint nb; /* Number of blocks */
6696 + uint ff; /* First full block */
6697 + uint lf; /* Last full block */
6698 + uint nsub; /* Number of subblocks */
6699 + uint *subblocks; /* Offsets for subblocks */
6700 + char *desc; /* Description */
6701 +} flash_desc_t;
6702 +
6703 +
6704 +#ifdef DECLARE_FLASHES
6705 +flash_cmds_t sflash_cmd_t =
6706 + { SFLASH, 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
6707 +
6708 +flash_cmds_t flash_cmds[] = {
6709 +/* type needu preera eraseb erasech write wbuf clcsr rdcsr rdid confrm read */
6710 + { BSC, 0, 0x00, 0x20, 0x00, 0x40, 0x00, 0x50, 0x70, 0x90, 0xd0, 0xff },
6711 + { SCS, 0, 0x00, 0x20, 0x00, 0x40, 0xe8, 0x50, 0x70, 0x90, 0xd0, 0xff },
6712 + { AMD, 1, 0x80, 0x30, 0x10, 0xa0, 0x00, 0x00, 0x00, 0x90, 0x00, 0xf0 },
6713 + { SST, 1, 0x80, 0x50, 0x10, 0xa0, 0x00, 0x00, 0x00, 0x90, 0x00, 0xf0 },
6714 + { 0 }
6715 +};
6716 +
6717 +unlock_cmd_t unlock_cmd_amd = {
6718 +#ifdef MIPSEB
6719 +/* addr: */ { 0x0aa8, 0x0556},
6720 +#else
6721 +/* addr: */ { 0x0aaa, 0x0554},
6722 +#endif
6723 +/* data: */ { 0xaa, 0x55}
6724 +};
6725 +
6726 +unlock_cmd_t unlock_cmd_sst = {
6727 +#ifdef MIPSEB
6728 +/* addr: */ { 0xaaa8, 0x5556},
6729 +#else
6730 +/* addr: */ { 0xaaaa, 0x5554},
6731 +#endif
6732 +/* data: */ { 0xaa, 0x55}
6733 +};
6734 +
6735 +#define AMD_CMD 0xaaa
6736 +#define SST_CMD 0xaaaa
6737 +
6738 +/* intel unlock block cmds */
6739 +#define INTEL_UNLOCK1 0x60
6740 +#define INTEL_UNLOCK2 0xD0
6741 +
6742 +/* Just eight blocks of 8KB byte each */
6743 +
6744 +uint blk8x8k[] = { 0x00000000,
6745 + 0x00002000,
6746 + 0x00004000,
6747 + 0x00006000,
6748 + 0x00008000,
6749 + 0x0000a000,
6750 + 0x0000c000,
6751 + 0x0000e000,
6752 + 0x00010000
6753 +};
6754 +
6755 +/* Funky AMD arrangement for 29xx800's */
6756 +uint amd800[] = { 0x00000000, /* 16KB */
6757 + 0x00004000, /* 32KB */
6758 + 0x0000c000, /* 8KB */
6759 + 0x0000e000, /* 8KB */
6760 + 0x00010000, /* 8KB */
6761 + 0x00012000, /* 8KB */
6762 + 0x00014000, /* 32KB */
6763 + 0x0001c000, /* 16KB */
6764 + 0x00020000
6765 +};
6766 +
6767 +/* AMD arrangement for 29xx160's */
6768 +uint amd4112[] = { 0x00000000, /* 32KB */
6769 + 0x00008000, /* 8KB */
6770 + 0x0000a000, /* 8KB */
6771 + 0x0000c000, /* 16KB */
6772 + 0x00010000
6773 +};
6774 +uint amd2114[] = { 0x00000000, /* 16KB */
6775 + 0x00004000, /* 8KB */
6776 + 0x00006000, /* 8KB */
6777 + 0x00008000, /* 32KB */
6778 + 0x00010000
6779 +};
6780 +
6781 +
6782 +flash_desc_t sflash_desc =
6783 + { 0, 0, 0, 0, SFLASH, 0, 0, 0, 0, 0, NULL, "SFLASH" };
6784 +
6785 +flash_desc_t flashes[] = {
6786 + { 0x00b0, 0x00d0, 0x0200000, 2, SCS, 0x10000, 32, 0, 31, 0, NULL, "Intel 28F160S3/5 1Mx16" },
6787 + { 0x00b0, 0x00d4, 0x0400000, 2, SCS, 0x10000, 64, 0, 63, 0, NULL, "Intel 28F320S3/5 2Mx16" },
6788 + { 0x0089, 0x8890, 0x0200000, 2, BSC, 0x10000, 32, 0, 30, 8, blk8x8k, "Intel 28F160B3 1Mx16 TopB" },
6789 + { 0x0089, 0x8891, 0x0200000, 2, BSC, 0x10000, 32, 1, 31, 8, blk8x8k, "Intel 28F160B3 1Mx16 BotB" },
6790 + { 0x0089, 0x8896, 0x0400000, 2, BSC, 0x10000, 64, 0, 62, 8, blk8x8k, "Intel 28F320B3 2Mx16 TopB" },
6791 + { 0x0089, 0x8897, 0x0400000, 2, BSC, 0x10000, 64, 1, 63, 8, blk8x8k, "Intel 28F320B3 2Mx16 BotB" },
6792 + { 0x0089, 0x8898, 0x0800000, 2, BSC, 0x10000, 128, 0, 126, 8, blk8x8k, "Intel 28F640B3 4Mx16 TopB" },
6793 + { 0x0089, 0x8899, 0x0800000, 2, BSC, 0x10000, 128, 1, 127, 8, blk8x8k, "Intel 28F640B3 4Mx16 BotB" },
6794 + { 0x0089, 0x88C2, 0x0200000, 2, BSC, 0x10000, 32, 0, 30, 8, blk8x8k, "Intel 28F160C3 1Mx16 TopB" },
6795 + { 0x0089, 0x88C3, 0x0200000, 2, BSC, 0x10000, 32, 1, 31, 8, blk8x8k, "Intel 28F160C3 1Mx16 BotB" },
6796 + { 0x0089, 0x88C4, 0x0400000, 2, BSC, 0x10000, 64, 0, 62, 8, blk8x8k, "Intel 28F320C3 2Mx16 TopB" },
6797 + { 0x0089, 0x88C5, 0x0400000, 2, BSC, 0x10000, 64, 1, 63, 8, blk8x8k, "Intel 28F320C3 2Mx16 BotB" },
6798 + { 0x0089, 0x88CC, 0x0800000, 2, BSC, 0x10000, 128, 0, 126, 8, blk8x8k, "Intel 28F640C3 4Mx16 TopB" },
6799 + { 0x0089, 0x88CD, 0x0800000, 2, BSC, 0x10000, 128, 1, 127, 8, blk8x8k, "Intel 28F640C3 4Mx16 BotB" },
6800 + { 0x0089, 0x0014, 0x0400000, 2, SCS, 0x20000, 32, 0, 31, 0, NULL, "Intel 28F320J5 2Mx16" },
6801 + { 0x0089, 0x0015, 0x0800000, 2, SCS, 0x20000, 64, 0, 63, 0, NULL, "Intel 28F640J5 4Mx16" },
6802 + { 0x0089, 0x0016, 0x0400000, 2, SCS, 0x20000, 32, 0, 31, 0, NULL, "Intel 28F320J3 2Mx16" },
6803 + { 0x0089, 0x0017, 0x0800000, 2, SCS, 0x20000, 64, 0, 63, 0, NULL, "Intel 28F640J3 4Mx16" },
6804 + { 0x0089, 0x0018, 0x1000000, 2, SCS, 0x20000, 128, 0, 127, 0, NULL, "Intel 28F128J3 8Mx16" },
6805 + { 0x00b0, 0x00e3, 0x0400000, 2, BSC, 0x10000, 64, 1, 63, 8, blk8x8k, "Sharp 28F320BJE 2Mx16 BotB" },
6806 + { 0x0001, 0x224a, 0x0100000, 2, AMD, 0x10000, 16, 0, 13, 8, amd800, "AMD 29DL800BT 512Kx16 TopB" },
6807 + { 0x0001, 0x22cb, 0x0100000, 2, AMD, 0x10000, 16, 2, 15, 8, amd800, "AMD 29DL800BB 512Kx16 BotB" },
6808 + { 0x0001, 0x22c4, 0x0200000, 2, AMD, 0x10000, 32, 0, 30, 4, amd2114, "AMD 29lv160DT 1Mx16 TopB" },
6809 + { 0x0001, 0x2249, 0x0200000, 2, AMD, 0x10000, 32, 1, 31, 4, amd4112, "AMD 29lv160DB 1Mx16 BotB" },
6810 + { 0x0001, 0x22f6, 0x0400000, 2, AMD, 0x10000, 64, 0, 62, 8, blk8x8k, "AMD 29lv320DT 2Mx16 TopB" },
6811 + { 0x0001, 0x22f9, 0x0400000, 2, AMD, 0x10000, 64, 1, 63, 8, blk8x8k, "AMD 29lv320DB 2Mx16 BotB" },
6812 + { 0x0001, 0x227e, 0x0400000, 2, AMD, 0x10000, 64, 0, 62, 8, blk8x8k, "AMD 29lv320MT 2Mx16 TopB" },
6813 + { 0x0001, 0x2200, 0x0400000, 2, AMD, 0x10000, 64, 1, 63, 8, blk8x8k, "AMD 29lv320MB 2Mx16 BotB" },
6814 + { 0x0020, 0x22CA, 0x0400000, 2, AMD, 0x10000, 64, 0, 62, 4, amd4112, "ST 29w320DT 2Mx16 TopB" },
6815 + { 0x0020, 0x22CB, 0x0400000, 2, AMD, 0x10000, 64, 1, 63, 4, amd2114, "ST 29w320DB 2Mx16 BotB" },
6816 + { 0x00C2, 0x00A7, 0x0400000, 2, AMD, 0x10000, 64, 0, 62, 4, amd4112, "MX29LV320T 2Mx16 TopB" },
6817 + { 0x00C2, 0x00A8, 0x0400000, 2, AMD, 0x10000, 64, 1, 63, 4, amd2114, "MX29LV320B 2Mx16 BotB" },
6818 + { 0x0004, 0x22F6, 0x0400000, 2, AMD, 0x10000, 64, 0, 62, 4, amd4112, "MBM29LV320TE 2Mx16 TopB" },
6819 + { 0x0004, 0x22F9, 0x0400000, 2, AMD, 0x10000, 64, 1, 63, 4, amd2114, "MBM29LV320BE 2Mx16 BotB" },
6820 + { 0x0098, 0x009A, 0x0400000, 2, AMD, 0x10000, 64, 0, 62, 4, amd4112, "TC58FVT321 2Mx16 TopB" },
6821 + { 0x0098, 0x009C, 0x0400000, 2, AMD, 0x10000, 64, 1, 63, 4, amd2114, "TC58FVB321 2Mx16 BotB" },
6822 + { 0x00C2, 0x22A7, 0x0400000, 2, AMD, 0x10000, 64, 0, 62, 4, amd4112, "MX29LV320T 2Mx16 TopB" },
6823 + { 0x00C2, 0x22A8, 0x0400000, 2, AMD, 0x10000, 64, 1, 63, 4, amd2114, "MX29LV320B 2Mx16 BotB" },
6824 + { 0x00BF, 0x2783, 0x0400000, 2, SST, 0x10000, 64, 0, 63, 0, NULL, "SST39VF320 2Mx16" },
6825 + { 0, 0, 0, 0, OLD, 0, 0, 0, 0, 0, NULL, NULL },
6826 +};
6827 +
6828 +#else
6829 +
6830 +extern flash_cmds_t flash_cmds[];
6831 +extern unlock_cmd_t unlock_cmd;
6832 +extern flash_desc_t flashes[];
6833 +
6834 +#endif
6835 diff -urN linux.old/arch/mips/bcm947xx/include/flashutl.h linux.dev/arch/mips/bcm947xx/include/flashutl.h
6836 --- linux.old/arch/mips/bcm947xx/include/flashutl.h 1970-01-01 01:00:00.000000000 +0100
6837 +++ linux.dev/arch/mips/bcm947xx/include/flashutl.h 2005-12-15 15:34:48.160541750 +0100
6838 @@ -0,0 +1,27 @@
6839 +/*
6840 + * BCM47XX FLASH driver interface
6841 + *
6842 + * Copyright 2005, Broadcom Corporation
6843 + * All Rights Reserved.
6844 + *
6845 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
6846 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
6847 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
6848 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
6849 + * $Id$
6850 + */
6851 +
6852 +#ifndef _flashutl_h_
6853 +#define _flashutl_h_
6854 +
6855 +
6856 +#ifndef _LANGUAGE_ASSEMBLY
6857 +
6858 +int sysFlashInit(char *flash_str);
6859 +int sysFlashRead(uint off, uchar *dst, uint bytes);
6860 +int sysFlashWrite(uint off, uchar *src, uint bytes);
6861 +void nvWrite(unsigned short *data, unsigned int len);
6862 +
6863 +#endif /* _LANGUAGE_ASSEMBLY */
6864 +
6865 +#endif /* _flashutl_h_ */
6866 diff -urN linux.old/arch/mips/bcm947xx/include/hndmips.h linux.dev/arch/mips/bcm947xx/include/hndmips.h
6867 --- linux.old/arch/mips/bcm947xx/include/hndmips.h 1970-01-01 01:00:00.000000000 +0100
6868 +++ linux.dev/arch/mips/bcm947xx/include/hndmips.h 2005-12-15 15:34:53.396869000 +0100
6869 @@ -0,0 +1,16 @@
6870 +/*
6871 + * Alternate include file for HND sbmips.h since CFE also ships with
6872 + * a sbmips.h.
6873 + *
6874 + * Copyright 2005, Broadcom Corporation
6875 + * All Rights Reserved.
6876 + *
6877 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
6878 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
6879 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
6880 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
6881 + *
6882 + * $Id$
6883 + */
6884 +
6885 +#include "sbmips.h"
6886 diff -urN linux.old/arch/mips/bcm947xx/include/linux_osl.h linux.dev/arch/mips/bcm947xx/include/linux_osl.h
6887 --- linux.old/arch/mips/bcm947xx/include/linux_osl.h 1970-01-01 01:00:00.000000000 +0100
6888 +++ linux.dev/arch/mips/bcm947xx/include/linux_osl.h 2005-12-15 17:23:39.225126750 +0100
6889 @@ -0,0 +1,331 @@
6890 +/*
6891 + * Linux OS Independent Layer
6892 + *
6893 + * Copyright 2005, Broadcom Corporation
6894 + * All Rights Reserved.
6895 + *
6896 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
6897 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
6898 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
6899 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
6900 + *
6901 + * $Id$
6902 + */
6903 +
6904 +#ifndef _linux_osl_h_
6905 +#define _linux_osl_h_
6906 +
6907 +#include <typedefs.h>
6908 +
6909 +/* use current 2.4.x calling conventions */
6910 +#include <linuxver.h>
6911 +
6912 +/* assert and panic */
6913 +#ifdef __GNUC__
6914 +#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
6915 +#if GCC_VERSION > 30100
6916 +#define ASSERT(exp) do {} while (0)
6917 +#else
6918 +/* ASSERT could causes segmentation fault on GCC3.1, use empty instead*/
6919 +#define ASSERT(exp)
6920 +#endif
6921 +#endif
6922 +
6923 +/* microsecond delay */
6924 +#define OSL_DELAY(usec) osl_delay(usec)
6925 +extern void osl_delay(uint usec);
6926 +
6927 +/* PCI configuration space access macros */
6928 +#define OSL_PCI_READ_CONFIG(osh, offset, size) \
6929 + osl_pci_read_config((osh), (offset), (size))
6930 +#define OSL_PCI_WRITE_CONFIG(osh, offset, size, val) \
6931 + osl_pci_write_config((osh), (offset), (size), (val))
6932 +extern uint32 osl_pci_read_config(osl_t *osh, uint size, uint offset);
6933 +extern void osl_pci_write_config(osl_t *osh, uint offset, uint size, uint val);
6934 +
6935 +/* PCI device bus # and slot # */
6936 +#define OSL_PCI_BUS(osh) osl_pci_bus(osh)
6937 +#define OSL_PCI_SLOT(osh) osl_pci_slot(osh)
6938 +extern uint osl_pci_bus(osl_t *osh);
6939 +extern uint osl_pci_slot(osl_t *osh);
6940 +
6941 +/* OSL initialization */
6942 +extern osl_t *osl_attach(void *pdev);
6943 +extern void osl_detach(osl_t *osh);
6944 +
6945 +/* host/bus architecture-specific byte swap */
6946 +#define BUS_SWAP32(v) (v)
6947 +
6948 +/* general purpose memory allocation */
6949 +
6950 +#define MALLOC(osh, size) kmalloc(size, GFP_ATOMIC)
6951 +#define MFREE(osh, addr, size) kfree(addr);
6952 +
6953 +#define MALLOC_FAILED(osh) osl_malloc_failed((osh))
6954 +
6955 +extern void *osl_malloc(osl_t *osh, uint size);
6956 +extern void osl_mfree(osl_t *osh, void *addr, uint size);
6957 +extern uint osl_malloced(osl_t *osh);
6958 +extern uint osl_malloc_failed(osl_t *osh);
6959 +
6960 +/* allocate/free shared (dma-able) consistent memory */
6961 +#define DMA_CONSISTENT_ALIGN PAGE_SIZE
6962 +#define DMA_ALLOC_CONSISTENT(osh, size, pap) \
6963 + osl_dma_alloc_consistent((osh), (size), (pap))
6964 +#define DMA_FREE_CONSISTENT(osh, va, size, pa) \
6965 + osl_dma_free_consistent((osh), (void*)(va), (size), (pa))
6966 +extern void *osl_dma_alloc_consistent(osl_t *osh, uint size, ulong *pap);
6967 +extern void osl_dma_free_consistent(osl_t *osh, void *va, uint size, ulong pa);
6968 +
6969 +/* map/unmap direction */
6970 +#define DMA_TX 1
6971 +#define DMA_RX 2
6972 +
6973 +/* register access macros */
6974 +#if defined(BCMJTAG)
6975 +#include <bcmjtag.h>
6976 +#define R_REG(r) bcmjtag_read(NULL, (uint32)(r), sizeof (*(r)))
6977 +#define W_REG(r, v) bcmjtag_write(NULL, (uint32)(r), (uint32)(v), sizeof (*(r)))
6978 +#endif
6979 +
6980 +/*
6981 + * BINOSL selects the slightly slower function-call-based binary compatible osl.
6982 + * Macros expand to calls to functions defined in linux_osl.c .
6983 + */
6984 +#ifndef BINOSL
6985 +
6986 +/* string library, kernel mode */
6987 +#define printf(fmt, args...) printk(fmt, ## args)
6988 +#include <linux/kernel.h>
6989 +#include <linux/string.h>
6990 +
6991 +/* register access macros */
6992 +#if !defined(BCMJTAG)
6993 +#ifndef IL_BIGENDIAN
6994 +#define R_REG(r) ( \
6995 + sizeof(*(r)) == sizeof(uint8) ? readb((volatile uint8*)(r)) : \
6996 + sizeof(*(r)) == sizeof(uint16) ? readw((volatile uint16*)(r)) : \
6997 + readl((volatile uint32*)(r)) \
6998 +)
6999 +#define W_REG(r, v) do { \
7000 + switch (sizeof(*(r))) { \
7001 + case sizeof(uint8): writeb((uint8)(v), (volatile uint8*)(r)); break; \
7002 + case sizeof(uint16): writew((uint16)(v), (volatile uint16*)(r)); break; \
7003 + case sizeof(uint32): writel((uint32)(v), (volatile uint32*)(r)); break; \
7004 + } \
7005 +} while (0)
7006 +#else /* IL_BIGENDIAN */
7007 +#define R_REG(r) ({ \
7008 + __typeof(*(r)) __osl_v; \
7009 + switch (sizeof(*(r))) { \
7010 + case sizeof(uint8): __osl_v = readb((volatile uint8*)((uint32)r^3)); break; \
7011 + case sizeof(uint16): __osl_v = readw((volatile uint16*)((uint32)r^2)); break; \
7012 + case sizeof(uint32): __osl_v = readl((volatile uint32*)(r)); break; \
7013 + } \
7014 + __osl_v; \
7015 +})
7016 +#define W_REG(r, v) do { \
7017 + switch (sizeof(*(r))) { \
7018 + case sizeof(uint8): writeb((uint8)(v), (volatile uint8*)((uint32)r^3)); break; \
7019 + case sizeof(uint16): writew((uint16)(v), (volatile uint16*)((uint32)r^2)); break; \
7020 + case sizeof(uint32): writel((uint32)(v), (volatile uint32*)(r)); break; \
7021 + } \
7022 +} while (0)
7023 +#endif
7024 +#endif
7025 +
7026 +#define AND_REG(r, v) W_REG((r), R_REG(r) & (v))
7027 +#define OR_REG(r, v) W_REG((r), R_REG(r) | (v))
7028 +
7029 +/* bcopy, bcmp, and bzero */
7030 +#define bcopy(src, dst, len) memcpy((dst), (src), (len))
7031 +#define bcmp(b1, b2, len) memcmp((b1), (b2), (len))
7032 +#define bzero(b, len) memset((b), '\0', (len))
7033 +
7034 +/* uncached virtual address */
7035 +#ifdef mips
7036 +#define OSL_UNCACHED(va) KSEG1ADDR((va))
7037 +#include <asm/addrspace.h>
7038 +#else
7039 +#define OSL_UNCACHED(va) (va)
7040 +#endif
7041 +
7042 +/* get processor cycle count */
7043 +#if defined(mips)
7044 +#define OSL_GETCYCLES(x) ((x) = read_c0_count() * 2)
7045 +#elif defined(__i386__)
7046 +#define OSL_GETCYCLES(x) rdtscl((x))
7047 +#else
7048 +#define OSL_GETCYCLES(x) ((x) = 0)
7049 +#endif
7050 +
7051 +/* dereference an address that may cause a bus exception */
7052 +#ifdef mips
7053 +#if defined(MODULE) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,17))
7054 +#define BUSPROBE(val, addr) panic("get_dbe() will not fixup a bus exception when compiled into a module")
7055 +#else
7056 +#define BUSPROBE(val, addr) get_dbe((val), (addr))
7057 +#include <asm/paccess.h>
7058 +#endif
7059 +#else
7060 +#define BUSPROBE(val, addr) ({ (val) = R_REG((addr)); 0; })
7061 +#endif
7062 +
7063 +/* map/unmap physical to virtual I/O */
7064 +#define REG_MAP(pa, size) ioremap_nocache((unsigned long)(pa), (unsigned long)(size))
7065 +#define REG_UNMAP(va) iounmap((void *)(va))
7066 +
7067 +/* shared (dma-able) memory access macros */
7068 +#define R_SM(r) *(r)
7069 +#define W_SM(r, v) (*(r) = (v))
7070 +#define BZERO_SM(r, len) memset((r), '\0', (len))
7071 +
7072 +/* packet primitives */
7073 +#define PKTGET(osh, len, send) osl_pktget((osh), (len), (send))
7074 +#define PKTFREE(osh, skb, send) osl_pktfree((skb))
7075 +#define PKTDATA(osh, skb) (((struct sk_buff*)(skb))->data)
7076 +#define PKTLEN(osh, skb) (((struct sk_buff*)(skb))->len)
7077 +#define PKTHEADROOM(osh, skb) (PKTDATA(osh,skb)-(((struct sk_buff*)(skb))->head))
7078 +#define PKTTAILROOM(osh, skb) ((((struct sk_buff*)(skb))->end)-(((struct sk_buff*)(skb))->tail))
7079 +#define PKTNEXT(osh, skb) (((struct sk_buff*)(skb))->next)
7080 +#define PKTSETNEXT(skb, x) (((struct sk_buff*)(skb))->next = (struct sk_buff*)(x))
7081 +#define PKTSETLEN(osh, skb, len) __skb_trim((struct sk_buff*)(skb), (len))
7082 +#define PKTPUSH(osh, skb, bytes) skb_push((struct sk_buff*)(skb), (bytes))
7083 +#define PKTPULL(osh, skb, bytes) skb_pull((struct sk_buff*)(skb), (bytes))
7084 +#define PKTDUP(osh, skb) skb_clone((struct sk_buff*)(skb), GFP_ATOMIC)
7085 +#define PKTCOOKIE(skb) ((void*)((struct sk_buff*)(skb))->csum)
7086 +#define PKTSETCOOKIE(skb, x) (((struct sk_buff*)(skb))->csum = (uint)(x))
7087 +#define PKTLINK(skb) (((struct sk_buff*)(skb))->prev)
7088 +#define PKTSETLINK(skb, x) (((struct sk_buff*)(skb))->prev = (struct sk_buff*)(x))
7089 +#define PKTPRIO(skb) (((struct sk_buff*)(skb))->priority)
7090 +#define PKTSETPRIO(skb, x) (((struct sk_buff*)(skb))->priority = (x))
7091 +extern void *osl_pktget(osl_t *osh, uint len, bool send);
7092 +extern void osl_pktfree(void *skb);
7093 +
7094 +#else /* BINOSL */
7095 +
7096 +/* string library */
7097 +#ifndef LINUX_OSL
7098 +#undef printf
7099 +#define printf(fmt, args...) osl_printf((fmt), ## args)
7100 +#undef sprintf
7101 +#define sprintf(buf, fmt, args...) osl_sprintf((buf), (fmt), ## args)
7102 +#undef strcmp
7103 +#define strcmp(s1, s2) osl_strcmp((s1), (s2))
7104 +#undef strncmp
7105 +#define strncmp(s1, s2, n) osl_strncmp((s1), (s2), (n))
7106 +#undef strlen
7107 +#define strlen(s) osl_strlen((s))
7108 +#undef strcpy
7109 +#define strcpy(d, s) osl_strcpy((d), (s))
7110 +#undef strncpy
7111 +#define strncpy(d, s, n) osl_strncpy((d), (s), (n))
7112 +#endif
7113 +extern int osl_printf(const char *format, ...);
7114 +extern int osl_sprintf(char *buf, const char *format, ...);
7115 +extern int osl_strcmp(const char *s1, const char *s2);
7116 +extern int osl_strncmp(const char *s1, const char *s2, uint n);
7117 +extern int osl_strlen(const char *s);
7118 +extern char* osl_strcpy(char *d, const char *s);
7119 +extern char* osl_strncpy(char *d, const char *s, uint n);
7120 +
7121 +/* register access macros */
7122 +#if !defined(BCMJTAG)
7123 +#define R_REG(r) ( \
7124 + sizeof(*(r)) == sizeof(uint8) ? osl_readb((volatile uint8*)(r)) : \
7125 + sizeof(*(r)) == sizeof(uint16) ? osl_readw((volatile uint16*)(r)) : \
7126 + osl_readl((volatile uint32*)(r)) \
7127 +)
7128 +#define W_REG(r, v) do { \
7129 + switch (sizeof(*(r))) { \
7130 + case sizeof(uint8): osl_writeb((uint8)(v), (volatile uint8*)(r)); break; \
7131 + case sizeof(uint16): osl_writew((uint16)(v), (volatile uint16*)(r)); break; \
7132 + case sizeof(uint32): osl_writel((uint32)(v), (volatile uint32*)(r)); break; \
7133 + } \
7134 +} while (0)
7135 +#endif
7136 +
7137 +#define AND_REG(r, v) W_REG((r), R_REG(r) & (v))
7138 +#define OR_REG(r, v) W_REG((r), R_REG(r) | (v))
7139 +extern uint8 osl_readb(volatile uint8 *r);
7140 +extern uint16 osl_readw(volatile uint16 *r);
7141 +extern uint32 osl_readl(volatile uint32 *r);
7142 +extern void osl_writeb(uint8 v, volatile uint8 *r);
7143 +extern void osl_writew(uint16 v, volatile uint16 *r);
7144 +extern void osl_writel(uint32 v, volatile uint32 *r);
7145 +
7146 +/* bcopy, bcmp, and bzero */
7147 +extern void bcopy(const void *src, void *dst, int len);
7148 +extern int bcmp(const void *b1, const void *b2, int len);
7149 +extern void bzero(void *b, int len);
7150 +
7151 +/* uncached virtual address */
7152 +#define OSL_UNCACHED(va) osl_uncached((va))
7153 +extern void *osl_uncached(void *va);
7154 +
7155 +/* get processor cycle count */
7156 +#define OSL_GETCYCLES(x) ((x) = osl_getcycles())
7157 +extern uint osl_getcycles(void);
7158 +
7159 +/* dereference an address that may target abort */
7160 +#define BUSPROBE(val, addr) osl_busprobe(&(val), (addr))
7161 +extern int osl_busprobe(uint32 *val, uint32 addr);
7162 +
7163 +/* map/unmap physical to virtual */
7164 +#define REG_MAP(pa, size) osl_reg_map((pa), (size))
7165 +#define REG_UNMAP(va) osl_reg_unmap((va))
7166 +extern void *osl_reg_map(uint32 pa, uint size);
7167 +extern void osl_reg_unmap(void *va);
7168 +
7169 +/* shared (dma-able) memory access macros */
7170 +#define R_SM(r) *(r)
7171 +#define W_SM(r, v) (*(r) = (v))
7172 +#define BZERO_SM(r, len) bzero((r), (len))
7173 +
7174 +/* packet primitives */
7175 +#define PKTGET(osh, len, send) osl_pktget((osh), (len), (send))
7176 +#define PKTFREE(osh, skb, send) osl_pktfree((skb))
7177 +#define PKTDATA(osh, skb) osl_pktdata((osh), (skb))
7178 +#define PKTLEN(osh, skb) osl_pktlen((osh), (skb))
7179 +#define PKTHEADROOM(osh, skb) osl_pktheadroom((osh), (skb))
7180 +#define PKTTAILROOM(osh, skb) osl_pkttailroom((osh), (skb))
7181 +#define PKTNEXT(osh, skb) osl_pktnext((osh), (skb))
7182 +#define PKTSETNEXT(skb, x) osl_pktsetnext((skb), (x))
7183 +#define PKTSETLEN(osh, skb, len) osl_pktsetlen((osh), (skb), (len))
7184 +#define PKTPUSH(osh, skb, bytes) osl_pktpush((osh), (skb), (bytes))
7185 +#define PKTPULL(osh, skb, bytes) osl_pktpull((osh), (skb), (bytes))
7186 +#define PKTDUP(osh, skb) osl_pktdup((osh), (skb))
7187 +#define PKTCOOKIE(skb) osl_pktcookie((skb))
7188 +#define PKTSETCOOKIE(skb, x) osl_pktsetcookie((skb), (x))
7189 +#define PKTLINK(skb) osl_pktlink((skb))
7190 +#define PKTSETLINK(skb, x) osl_pktsetlink((skb), (x))
7191 +#define PKTPRIO(skb) osl_pktprio((skb))
7192 +#define PKTSETPRIO(skb, x) osl_pktsetprio((skb), (x))
7193 +extern void *osl_pktget(osl_t *osh, uint len, bool send);
7194 +extern void osl_pktfree(void *skb);
7195 +extern uchar *osl_pktdata(osl_t *osh, void *skb);
7196 +extern uint osl_pktlen(osl_t *osh, void *skb);
7197 +extern uint osl_pktheadroom(osl_t *osh, void *skb);
7198 +extern uint osl_pkttailroom(osl_t *osh, void *skb);
7199 +extern void *osl_pktnext(osl_t *osh, void *skb);
7200 +extern void osl_pktsetnext(void *skb, void *x);
7201 +extern void osl_pktsetlen(osl_t *osh, void *skb, uint len);
7202 +extern uchar *osl_pktpush(osl_t *osh, void *skb, int bytes);
7203 +extern uchar *osl_pktpull(osl_t *osh, void *skb, int bytes);
7204 +extern void *osl_pktdup(osl_t *osh, void *skb);
7205 +extern void *osl_pktcookie(void *skb);
7206 +extern void osl_pktsetcookie(void *skb, void *x);
7207 +extern void *osl_pktlink(void *skb);
7208 +extern void osl_pktsetlink(void *skb, void *x);
7209 +extern uint osl_pktprio(void *skb);
7210 +extern void osl_pktsetprio(void *skb, uint x);
7211 +
7212 +#endif /* BINOSL */
7213 +
7214 +#define OSL_ERROR(bcmerror) osl_error(bcmerror)
7215 +extern int osl_error(int bcmerror);
7216 +
7217 +/* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
7218 +#define PKTBUFSZ 2048
7219 +
7220 +#endif /* _linux_osl_h_ */
7221 diff -urN linux.old/arch/mips/bcm947xx/include/linuxver.h linux.dev/arch/mips/bcm947xx/include/linuxver.h
7222 --- linux.old/arch/mips/bcm947xx/include/linuxver.h 1970-01-01 01:00:00.000000000 +0100
7223 +++ linux.dev/arch/mips/bcm947xx/include/linuxver.h 2005-12-15 16:02:45.467929000 +0100
7224 @@ -0,0 +1,389 @@
7225 +/*
7226 + * Linux-specific abstractions to gain some independence from linux kernel versions.
7227 + * Pave over some 2.2 versus 2.4 versus 2.6 kernel differences.
7228 + *
7229 + * Copyright 2005, Broadcom Corporation
7230 + * All Rights Reserved.
7231 + *
7232 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
7233 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
7234 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
7235 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
7236 + *
7237 + * $Id$
7238 + */
7239 +
7240 +#ifndef _linuxver_h_
7241 +#define _linuxver_h_
7242 +
7243 +#include <linux/config.h>
7244 +#include <linux/version.h>
7245 +
7246 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
7247 +/* __NO_VERSION__ must be defined for all linkables except one in 2.2 */
7248 +#ifdef __UNDEF_NO_VERSION__
7249 +#undef __NO_VERSION__
7250 +#else
7251 +#define __NO_VERSION__
7252 +#endif
7253 +#endif
7254 +
7255 +#if defined(MODULE) && defined(MODVERSIONS)
7256 +#include <linux/modversions.h>
7257 +#endif
7258 +
7259 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
7260 +#include <linux/moduleparam.h>
7261 +#endif
7262 +
7263 +
7264 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
7265 +#define module_param(_name_, _type_, _perm_) MODULE_PARM(_name_, "i")
7266 +#define module_param_string(_name_, _string_, _size_, _perm_) MODULE_PARM(_string_, "c" __MODULE_STRING(_size_))
7267 +#endif
7268 +
7269 +/* linux/malloc.h is deprecated, use linux/slab.h instead. */
7270 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,9))
7271 +#include <linux/malloc.h>
7272 +#else
7273 +#include <linux/slab.h>
7274 +#endif
7275 +
7276 +#include <linux/types.h>
7277 +#include <linux/init.h>
7278 +#include <linux/mm.h>
7279 +#include <linux/string.h>
7280 +#include <linux/pci.h>
7281 +#include <linux/interrupt.h>
7282 +#include <linux/netdevice.h>
7283 +#include <asm/io.h>
7284 +
7285 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41))
7286 +#include <linux/workqueue.h>
7287 +#else
7288 +#include <linux/tqueue.h>
7289 +#ifndef work_struct
7290 +#define work_struct tq_struct
7291 +#endif
7292 +#ifndef INIT_WORK
7293 +#define INIT_WORK(_work, _func, _data) INIT_TQUEUE((_work), (_func), (_data))
7294 +#endif
7295 +#ifndef schedule_work
7296 +#define schedule_work(_work) schedule_task((_work))
7297 +#endif
7298 +#ifndef flush_scheduled_work
7299 +#define flush_scheduled_work() flush_scheduled_tasks()
7300 +#endif
7301 +#endif
7302 +
7303 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
7304 +/* Some distributions have their own 2.6.x compatibility layers */
7305 +#ifndef IRQ_NONE
7306 +typedef void irqreturn_t;
7307 +#define IRQ_NONE
7308 +#define IRQ_HANDLED
7309 +#define IRQ_RETVAL(x)
7310 +#endif
7311 +#else
7312 +typedef irqreturn_t (*FN_ISR) (int irq, void *dev_id, struct pt_regs *ptregs);
7313 +#endif
7314 +
7315 +#ifndef __exit
7316 +#define __exit
7317 +#endif
7318 +#ifndef __devexit
7319 +#define __devexit
7320 +#endif
7321 +#ifndef __devinit
7322 +#define __devinit __init
7323 +#endif
7324 +#ifndef __devinitdata
7325 +#define __devinitdata
7326 +#endif
7327 +#ifndef __devexit_p
7328 +#define __devexit_p(x) x
7329 +#endif
7330 +
7331 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
7332 +
7333 +#define pci_get_drvdata(dev) (dev)->sysdata
7334 +#define pci_set_drvdata(dev, value) (dev)->sysdata=(value)
7335 +
7336 +/*
7337 + * New-style (2.4.x) PCI/hot-pluggable PCI/CardBus registration
7338 + */
7339 +
7340 +struct pci_device_id {
7341 + unsigned int vendor, device; /* Vendor and device ID or PCI_ANY_ID */
7342 + unsigned int subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
7343 + unsigned int class, class_mask; /* (class,subclass,prog-if) triplet */
7344 + unsigned long driver_data; /* Data private to the driver */
7345 +};
7346 +
7347 +struct pci_driver {
7348 + struct list_head node;
7349 + char *name;
7350 + const struct pci_device_id *id_table; /* NULL if wants all devices */
7351 + int (*probe)(struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
7352 + void (*remove)(struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */
7353 + void (*suspend)(struct pci_dev *dev); /* Device suspended */
7354 + void (*resume)(struct pci_dev *dev); /* Device woken up */
7355 +};
7356 +
7357 +#define MODULE_DEVICE_TABLE(type, name)
7358 +#define PCI_ANY_ID (~0)
7359 +
7360 +/* compatpci.c */
7361 +#define pci_module_init pci_register_driver
7362 +extern int pci_register_driver(struct pci_driver *drv);
7363 +extern void pci_unregister_driver(struct pci_driver *drv);
7364 +
7365 +#endif /* PCI registration */
7366 +
7367 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18))
7368 +#ifdef MODULE
7369 +#define module_init(x) int init_module(void) { return x(); }
7370 +#define module_exit(x) void cleanup_module(void) { x(); }
7371 +#else
7372 +#define module_init(x) __initcall(x);
7373 +#define module_exit(x) __exitcall(x);
7374 +#endif
7375 +#endif
7376 +
7377 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,48))
7378 +#define list_for_each(pos, head) \
7379 + for (pos = (head)->next; pos != (head); pos = pos->next)
7380 +#endif
7381 +
7382 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,13))
7383 +#define pci_resource_start(dev, bar) ((dev)->base_address[(bar)])
7384 +#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,44))
7385 +#define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
7386 +#endif
7387 +
7388 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,23))
7389 +#define pci_enable_device(dev) do { } while (0)
7390 +#endif
7391 +
7392 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,14))
7393 +#define net_device device
7394 +#endif
7395 +
7396 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,42))
7397 +
7398 +/*
7399 + * DMA mapping
7400 + *
7401 + * See linux/Documentation/DMA-mapping.txt
7402 + */
7403 +
7404 +#ifndef PCI_DMA_TODEVICE
7405 +#define PCI_DMA_TODEVICE 1
7406 +#define PCI_DMA_FROMDEVICE 2
7407 +#endif
7408 +
7409 +typedef u32 dma_addr_t;
7410 +
7411 +/* Pure 2^n version of get_order */
7412 +static inline int get_order(unsigned long size)
7413 +{
7414 + int order;
7415 +
7416 + size = (size-1) >> (PAGE_SHIFT-1);
7417 + order = -1;
7418 + do {
7419 + size >>= 1;
7420 + order++;
7421 + } while (size);
7422 + return order;
7423 +}
7424 +
7425 +static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
7426 + dma_addr_t *dma_handle)
7427 +{
7428 + void *ret;
7429 + int gfp = GFP_ATOMIC | GFP_DMA;
7430 +
7431 + ret = (void *)__get_free_pages(gfp, get_order(size));
7432 +
7433 + if (ret != NULL) {
7434 + memset(ret, 0, size);
7435 + *dma_handle = virt_to_bus(ret);
7436 + }
7437 + return ret;
7438 +}
7439 +static inline void pci_free_consistent(struct pci_dev *hwdev, size_t size,
7440 + void *vaddr, dma_addr_t dma_handle)
7441 +{
7442 + free_pages((unsigned long)vaddr, get_order(size));
7443 +}
7444 +#ifdef ILSIM
7445 +extern uint pci_map_single(void *dev, void *va, uint size, int direction);
7446 +extern void pci_unmap_single(void *dev, uint pa, uint size, int direction);
7447 +#else
7448 +#define pci_map_single(cookie, address, size, dir) virt_to_bus(address)
7449 +#define pci_unmap_single(cookie, address, size, dir)
7450 +#endif
7451 +
7452 +#endif /* DMA mapping */
7453 +
7454 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,43))
7455 +
7456 +#define dev_kfree_skb_any(a) dev_kfree_skb(a)
7457 +#define netif_down(dev) do { (dev)->start = 0; } while(0)
7458 +
7459 +/* pcmcia-cs provides its own netdevice compatibility layer */
7460 +#ifndef _COMPAT_NETDEVICE_H
7461 +
7462 +/*
7463 + * SoftNet
7464 + *
7465 + * For pre-softnet kernels we need to tell the upper layer not to
7466 + * re-enter start_xmit() while we are in there. However softnet
7467 + * guarantees not to enter while we are in there so there is no need
7468 + * to do the netif_stop_queue() dance unless the transmit queue really
7469 + * gets stuck. This should also improve performance according to tests
7470 + * done by Aman Singla.
7471 + */
7472 +
7473 +#define dev_kfree_skb_irq(a) dev_kfree_skb(a)
7474 +#define netif_wake_queue(dev) do { clear_bit(0, &(dev)->tbusy); mark_bh(NET_BH); } while(0)
7475 +#define netif_stop_queue(dev) set_bit(0, &(dev)->tbusy)
7476 +
7477 +static inline void netif_start_queue(struct net_device *dev)
7478 +{
7479 + dev->tbusy = 0;
7480 + dev->interrupt = 0;
7481 + dev->start = 1;
7482 +}
7483 +
7484 +#define netif_queue_stopped(dev) (dev)->tbusy
7485 +#define netif_running(dev) (dev)->start
7486 +
7487 +#endif /* _COMPAT_NETDEVICE_H */
7488 +
7489 +#define netif_device_attach(dev) netif_start_queue(dev)
7490 +#define netif_device_detach(dev) netif_stop_queue(dev)
7491 +
7492 +/* 2.4.x renamed bottom halves to tasklets */
7493 +#define tasklet_struct tq_struct
7494 +static inline void tasklet_schedule(struct tasklet_struct *tasklet)
7495 +{
7496 + queue_task(tasklet, &tq_immediate);
7497 + mark_bh(IMMEDIATE_BH);
7498 +}
7499 +
7500 +static inline void tasklet_init(struct tasklet_struct *tasklet,
7501 + void (*func)(unsigned long),
7502 + unsigned long data)
7503 +{
7504 + tasklet->next = NULL;
7505 + tasklet->sync = 0;
7506 + tasklet->routine = (void (*)(void *))func;
7507 + tasklet->data = (void *)data;
7508 +}
7509 +#define tasklet_kill(tasklet) {do{} while(0);}
7510 +
7511 +/* 2.4.x introduced del_timer_sync() */
7512 +#define del_timer_sync(timer) del_timer(timer)
7513 +
7514 +#else
7515 +
7516 +#define netif_down(dev)
7517 +
7518 +#endif /* SoftNet */
7519 +
7520 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3))
7521 +
7522 +/*
7523 + * Emit code to initialise a tq_struct's routine and data pointers
7524 + */
7525 +#define PREPARE_TQUEUE(_tq, _routine, _data) \
7526 + do { \
7527 + (_tq)->routine = _routine; \
7528 + (_tq)->data = _data; \
7529 + } while (0)
7530 +
7531 +/*
7532 + * Emit code to initialise all of a tq_struct
7533 + */
7534 +#define INIT_TQUEUE(_tq, _routine, _data) \
7535 + do { \
7536 + INIT_LIST_HEAD(&(_tq)->list); \
7537 + (_tq)->sync = 0; \
7538 + PREPARE_TQUEUE((_tq), (_routine), (_data)); \
7539 + } while (0)
7540 +
7541 +#endif
7542 +
7543 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6))
7544 +
7545 +/* Power management related routines */
7546 +
7547 +static inline int
7548 +pci_save_state(struct pci_dev *dev, u32 *buffer)
7549 +{
7550 + int i;
7551 + if (buffer) {
7552 + for (i = 0; i < 16; i++)
7553 + pci_read_config_dword(dev, i * 4,&buffer[i]);
7554 + }
7555 + return 0;
7556 +}
7557 +
7558 +static inline int
7559 +pci_restore_state(struct pci_dev *dev, u32 *buffer)
7560 +{
7561 + int i;
7562 +
7563 + if (buffer) {
7564 + for (i = 0; i < 16; i++)
7565 + pci_write_config_dword(dev,i * 4, buffer[i]);
7566 + }
7567 + /*
7568 + * otherwise, write the context information we know from bootup.
7569 + * This works around a problem where warm-booting from Windows
7570 + * combined with a D3(hot)->D0 transition causes PCI config
7571 + * header data to be forgotten.
7572 + */
7573 + else {
7574 + for (i = 0; i < 6; i ++)
7575 + pci_write_config_dword(dev,
7576 + PCI_BASE_ADDRESS_0 + (i * 4),
7577 + pci_resource_start(dev, i));
7578 + pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
7579 + }
7580 + return 0;
7581 +}
7582 +
7583 +#endif /* PCI power management */
7584 +
7585 +/* Old cp0 access macros deprecated in 2.4.19 */
7586 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19))
7587 +#define read_c0_count() read_32bit_cp0_register(CP0_COUNT)
7588 +#endif
7589 +
7590 +/* Module refcount handled internally in 2.6.x */
7591 +#ifndef SET_MODULE_OWNER
7592 +#define SET_MODULE_OWNER(dev) do {} while (0)
7593 +#define OLD_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
7594 +#define OLD_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
7595 +#else
7596 +#define OLD_MOD_INC_USE_COUNT do {} while (0)
7597 +#define OLD_MOD_DEC_USE_COUNT do {} while (0)
7598 +#endif
7599 +
7600 +#ifndef SET_NETDEV_DEV
7601 +#define SET_NETDEV_DEV(net, pdev) do {} while (0)
7602 +#endif
7603 +
7604 +#ifndef HAVE_FREE_NETDEV
7605 +#define free_netdev(dev) kfree(dev)
7606 +#endif
7607 +
7608 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
7609 +/* struct packet_type redefined in 2.6.x */
7610 +#define af_packet_priv data
7611 +#endif
7612 +
7613 +#endif /* _linuxver_h_ */
7614 diff -urN linux.old/arch/mips/bcm947xx/include/mipsinc.h linux.dev/arch/mips/bcm947xx/include/mipsinc.h
7615 --- linux.old/arch/mips/bcm947xx/include/mipsinc.h 1970-01-01 01:00:00.000000000 +0100
7616 +++ linux.dev/arch/mips/bcm947xx/include/mipsinc.h 2005-12-15 16:47:29.886633750 +0100
7617 @@ -0,0 +1,552 @@
7618 +/*
7619 + * HND Run Time Environment for standalone MIPS programs.
7620 + *
7621 + * Copyright 2005, Broadcom Corporation
7622 + * All Rights Reserved.
7623 + *
7624 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
7625 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
7626 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
7627 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
7628 + *
7629 + * $Id$
7630 + */
7631 +
7632 +#ifndef _MISPINC_H
7633 +#define _MISPINC_H
7634 +
7635 +
7636 +/* MIPS defines */
7637 +
7638 +#ifdef _LANGUAGE_ASSEMBLY
7639 +
7640 +/*
7641 + * Symbolic register names for 32 bit ABI
7642 + */
7643 +#define zero $0 /* wired zero */
7644 +#define AT $1 /* assembler temp - uppercase because of ".set at" */
7645 +#define v0 $2 /* return value */
7646 +#define v1 $3
7647 +#define a0 $4 /* argument registers */
7648 +#define a1 $5
7649 +#define a2 $6
7650 +#define a3 $7
7651 +#define t0 $8 /* caller saved */
7652 +#define t1 $9
7653 +#define t2 $10
7654 +#define t3 $11
7655 +#define t4 $12
7656 +#define t5 $13
7657 +#define t6 $14
7658 +#define t7 $15
7659 +#define s0 $16 /* callee saved */
7660 +#define s1 $17
7661 +#define s2 $18
7662 +#define s3 $19
7663 +#define s4 $20
7664 +#define s5 $21
7665 +#define s6 $22
7666 +#define s7 $23
7667 +#define t8 $24 /* caller saved */
7668 +#define t9 $25
7669 +#define jp $25 /* PIC jump register */
7670 +#define k0 $26 /* kernel scratch */
7671 +#define k1 $27
7672 +#define gp $28 /* global pointer */
7673 +#define sp $29 /* stack pointer */
7674 +#define fp $30 /* frame pointer */
7675 +#define s8 $30 /* same like fp! */
7676 +#define ra $31 /* return address */
7677 +
7678 +
7679 +/*
7680 + * CP0 Registers
7681 + */
7682 +
7683 +#define C0_INX $0
7684 +#define C0_RAND $1
7685 +#define C0_TLBLO0 $2
7686 +#define C0_TLBLO C0_TLBLO0
7687 +#define C0_TLBLO1 $3
7688 +#define C0_CTEXT $4
7689 +#define C0_PGMASK $5
7690 +#define C0_WIRED $6
7691 +#define C0_BADVADDR $8
7692 +#define C0_COUNT $9
7693 +#define C0_TLBHI $10
7694 +#define C0_COMPARE $11
7695 +#define C0_SR $12
7696 +#define C0_STATUS C0_SR
7697 +#define C0_CAUSE $13
7698 +#define C0_EPC $14
7699 +#define C0_PRID $15
7700 +#define C0_CONFIG $16
7701 +#define C0_LLADDR $17
7702 +#define C0_WATCHLO $18
7703 +#define C0_WATCHHI $19
7704 +#define C0_XCTEXT $20
7705 +#define C0_DIAGNOSTIC $22
7706 +#define C0_BROADCOM C0_DIAGNOSTIC
7707 +#define C0_PERFORMANCE $25
7708 +#define C0_ECC $26
7709 +#define C0_CACHEERR $27
7710 +#define C0_TAGLO $28
7711 +#define C0_TAGHI $29
7712 +#define C0_ERREPC $30
7713 +#define C0_DESAVE $31
7714 +
7715 +/*
7716 + * LEAF - declare leaf routine
7717 + */
7718 +#define LEAF(symbol) \
7719 + .globl symbol; \
7720 + .align 2; \
7721 + .type symbol,@function; \
7722 + .ent symbol,0; \
7723 +symbol: .frame sp,0,ra
7724 +
7725 +/*
7726 + * END - mark end of function
7727 + */
7728 +#define END(function) \
7729 + .end function; \
7730 + .size function,.-function
7731 +
7732 +#define _ULCAST_
7733 +
7734 +#else
7735 +
7736 +/*
7737 + * The following macros are especially useful for __asm__
7738 + * inline assembler.
7739 + */
7740 +#ifndef __STR
7741 +#define __STR(x) #x
7742 +#endif
7743 +#ifndef STR
7744 +#define STR(x) __STR(x)
7745 +#endif
7746 +
7747 +#define _ULCAST_ (unsigned long)
7748 +
7749 +
7750 +/*
7751 + * CP0 Registers
7752 + */
7753 +
7754 +#define C0_INX 0 /* CP0: TLB Index */
7755 +#define C0_RAND 1 /* CP0: TLB Random */
7756 +#define C0_TLBLO0 2 /* CP0: TLB EntryLo0 */
7757 +#define C0_TLBLO C0_TLBLO0 /* CP0: TLB EntryLo0 */
7758 +#define C0_TLBLO1 3 /* CP0: TLB EntryLo1 */
7759 +#define C0_CTEXT 4 /* CP0: Context */
7760 +#define C0_PGMASK 5 /* CP0: TLB PageMask */
7761 +#define C0_WIRED 6 /* CP0: TLB Wired */
7762 +#define C0_BADVADDR 8 /* CP0: Bad Virtual Address */
7763 +#define C0_COUNT 9 /* CP0: Count */
7764 +#define C0_TLBHI 10 /* CP0: TLB EntryHi */
7765 +#define C0_COMPARE 11 /* CP0: Compare */
7766 +#define C0_SR 12 /* CP0: Processor Status */
7767 +#define C0_STATUS C0_SR /* CP0: Processor Status */
7768 +#define C0_CAUSE 13 /* CP0: Exception Cause */
7769 +#define C0_EPC 14 /* CP0: Exception PC */
7770 +#define C0_PRID 15 /* CP0: Processor Revision Indentifier */
7771 +#define C0_CONFIG 16 /* CP0: Config */
7772 +#define C0_LLADDR 17 /* CP0: LLAddr */
7773 +#define C0_WATCHLO 18 /* CP0: WatchpointLo */
7774 +#define C0_WATCHHI 19 /* CP0: WatchpointHi */
7775 +#define C0_XCTEXT 20 /* CP0: XContext */
7776 +#define C0_DIAGNOSTIC 22 /* CP0: Diagnostic */
7777 +#define C0_BROADCOM C0_DIAGNOSTIC /* CP0: Broadcom Register */
7778 +#define C0_PERFORMANCE 25 /* CP0: Performance Counter/Control Registers */
7779 +#define C0_ECC 26 /* CP0: ECC */
7780 +#define C0_CACHEERR 27 /* CP0: CacheErr */
7781 +#define C0_TAGLO 28 /* CP0: TagLo */
7782 +#define C0_TAGHI 29 /* CP0: TagHi */
7783 +#define C0_ERREPC 30 /* CP0: ErrorEPC */
7784 +#define C0_DESAVE 31 /* CP0: DebugSave */
7785 +
7786 +#endif /* _LANGUAGE_ASSEMBLY */
7787 +
7788 +/*
7789 + * Memory segments (32bit kernel mode addresses)
7790 + */
7791 +#undef KUSEG
7792 +#undef KSEG0
7793 +#undef KSEG1
7794 +#undef KSEG2
7795 +#undef KSEG3
7796 +#define KUSEG 0x00000000
7797 +#define KSEG0 0x80000000
7798 +#define KSEG1 0xa0000000
7799 +#define KSEG2 0xc0000000
7800 +#define KSEG3 0xe0000000
7801 +#define PHYSADDR_MASK 0x1fffffff
7802 +
7803 +/*
7804 + * Map an address to a certain kernel segment
7805 + */
7806 +#undef PHYSADDR
7807 +#undef KSEG0ADDR
7808 +#undef KSEG1ADDR
7809 +#undef KSEG2ADDR
7810 +#undef KSEG3ADDR
7811 +
7812 +#define PHYSADDR(a) (_ULCAST_(a) & PHYSADDR_MASK)
7813 +#define KSEG0ADDR(a) ((_ULCAST_(a) & PHYSADDR_MASK) | KSEG0)
7814 +#define KSEG1ADDR(a) ((_ULCAST_(a) & PHYSADDR_MASK) | KSEG1)
7815 +#define KSEG2ADDR(a) ((_ULCAST_(a) & PHYSADDR_MASK) | KSEG2)
7816 +#define KSEG3ADDR(a) ((_ULCAST_(a) & PHYSADDR_MASK) | KSEG3)
7817 +
7818 +
7819 +#ifndef Index_Invalidate_I
7820 +/*
7821 + * Cache Operations
7822 + */
7823 +#define Index_Invalidate_I 0x00
7824 +#define Index_Writeback_Inv_D 0x01
7825 +#define Index_Invalidate_SI 0x02
7826 +#define Index_Writeback_Inv_SD 0x03
7827 +#define Index_Load_Tag_I 0x04
7828 +#define Index_Load_Tag_D 0x05
7829 +#define Index_Load_Tag_SI 0x06
7830 +#define Index_Load_Tag_SD 0x07
7831 +#define Index_Store_Tag_I 0x08
7832 +#define Index_Store_Tag_D 0x09
7833 +#define Index_Store_Tag_SI 0x0A
7834 +#define Index_Store_Tag_SD 0x0B
7835 +#define Create_Dirty_Excl_D 0x0d
7836 +#define Create_Dirty_Excl_SD 0x0f
7837 +#define Hit_Invalidate_I 0x10
7838 +#define Hit_Invalidate_D 0x11
7839 +#define Hit_Invalidate_SI 0x12
7840 +#define Hit_Invalidate_SD 0x13
7841 +#define Fill_I 0x14
7842 +#define Hit_Writeback_Inv_D 0x15
7843 + /* 0x16 is unused */
7844 +#define Hit_Writeback_Inv_SD 0x17
7845 +#define R5K_Page_Invalidate_S 0x17
7846 +#define Hit_Writeback_I 0x18
7847 +#define Hit_Writeback_D 0x19
7848 + /* 0x1a is unused */
7849 +#define Hit_Writeback_SD 0x1b
7850 + /* 0x1c is unused */
7851 + /* 0x1e is unused */
7852 +#define Hit_Set_Virtual_SI 0x1e
7853 +#define Hit_Set_Virtual_SD 0x1f
7854 +#endif
7855 +
7856 +
7857 +/*
7858 + * R4x00 interrupt enable / cause bits
7859 + */
7860 +#define IE_SW0 (_ULCAST_(1) << 8)
7861 +#define IE_SW1 (_ULCAST_(1) << 9)
7862 +#define IE_IRQ0 (_ULCAST_(1) << 10)
7863 +#define IE_IRQ1 (_ULCAST_(1) << 11)
7864 +#define IE_IRQ2 (_ULCAST_(1) << 12)
7865 +#define IE_IRQ3 (_ULCAST_(1) << 13)
7866 +#define IE_IRQ4 (_ULCAST_(1) << 14)
7867 +#define IE_IRQ5 (_ULCAST_(1) << 15)
7868 +
7869 +#ifndef ST0_UM
7870 +/*
7871 + * Bitfields in the mips32 cp0 status register
7872 + */
7873 +#define ST0_IE 0x00000001
7874 +#define ST0_EXL 0x00000002
7875 +#define ST0_ERL 0x00000004
7876 +#define ST0_UM 0x00000010
7877 +#define ST0_SWINT0 0x00000100
7878 +#define ST0_SWINT1 0x00000200
7879 +#define ST0_HWINT0 0x00000400
7880 +#define ST0_HWINT1 0x00000800
7881 +#define ST0_HWINT2 0x00001000
7882 +#define ST0_HWINT3 0x00002000
7883 +#define ST0_HWINT4 0x00004000
7884 +#define ST0_HWINT5 0x00008000
7885 +#define ST0_IM 0x0000ff00
7886 +#define ST0_NMI 0x00080000
7887 +#define ST0_SR 0x00100000
7888 +#define ST0_TS 0x00200000
7889 +#define ST0_BEV 0x00400000
7890 +#define ST0_RE 0x02000000
7891 +#define ST0_RP 0x08000000
7892 +#define ST0_CU 0xf0000000
7893 +#define ST0_CU0 0x10000000
7894 +#define ST0_CU1 0x20000000
7895 +#define ST0_CU2 0x40000000
7896 +#define ST0_CU3 0x80000000
7897 +#endif
7898 +
7899 +
7900 +/*
7901 + * Bitfields in the mips32 cp0 cause register
7902 + */
7903 +#define C_EXC 0x0000007c
7904 +#define C_EXC_SHIFT 2
7905 +#define C_INT 0x0000ff00
7906 +#define C_INT_SHIFT 8
7907 +#define C_SW0 (_ULCAST_(1) << 8)
7908 +#define C_SW1 (_ULCAST_(1) << 9)
7909 +#define C_IRQ0 (_ULCAST_(1) << 10)
7910 +#define C_IRQ1 (_ULCAST_(1) << 11)
7911 +#define C_IRQ2 (_ULCAST_(1) << 12)
7912 +#define C_IRQ3 (_ULCAST_(1) << 13)
7913 +#define C_IRQ4 (_ULCAST_(1) << 14)
7914 +#define C_IRQ5 (_ULCAST_(1) << 15)
7915 +#define C_WP 0x00400000
7916 +#define C_IV 0x00800000
7917 +#define C_CE 0x30000000
7918 +#define C_CE_SHIFT 28
7919 +#define C_BD 0x80000000
7920 +
7921 +/* Values in C_EXC */
7922 +#define EXC_INT 0
7923 +#define EXC_TLBM 1
7924 +#define EXC_TLBL 2
7925 +#define EXC_TLBS 3
7926 +#define EXC_AEL 4
7927 +#define EXC_AES 5
7928 +#define EXC_IBE 6
7929 +#define EXC_DBE 7
7930 +#define EXC_SYS 8
7931 +#define EXC_BPT 9
7932 +#define EXC_RI 10
7933 +#define EXC_CU 11
7934 +#define EXC_OV 12
7935 +#define EXC_TR 13
7936 +#define EXC_WATCH 23
7937 +#define EXC_MCHK 24
7938 +
7939 +
7940 +/*
7941 + * Bits in the cp0 config register.
7942 + */
7943 +#define CONF_CM_CACHABLE_NO_WA 0
7944 +#define CONF_CM_CACHABLE_WA 1
7945 +#define CONF_CM_UNCACHED 2
7946 +#define CONF_CM_CACHABLE_NONCOHERENT 3
7947 +#define CONF_CM_CACHABLE_CE 4
7948 +#define CONF_CM_CACHABLE_COW 5
7949 +#define CONF_CM_CACHABLE_CUW 6
7950 +#define CONF_CM_CACHABLE_ACCELERATED 7
7951 +#define CONF_CM_CMASK 7
7952 +#define CONF_CU (_ULCAST_(1) << 3)
7953 +#define CONF_DB (_ULCAST_(1) << 4)
7954 +#define CONF_IB (_ULCAST_(1) << 5)
7955 +#define CONF_SE (_ULCAST_(1) << 12)
7956 +#define CONF_SC (_ULCAST_(1) << 17)
7957 +#define CONF_AC (_ULCAST_(1) << 23)
7958 +#define CONF_HALT (_ULCAST_(1) << 25)
7959 +
7960 +
7961 +/*
7962 + * Bits in the cp0 config register select 1.
7963 + */
7964 +#define CONF1_FP 0x00000001 /* FPU present */
7965 +#define CONF1_EP 0x00000002 /* EJTAG present */
7966 +#define CONF1_CA 0x00000004 /* mips16 implemented */
7967 +#define CONF1_WR 0x00000008 /* Watch registers present */
7968 +#define CONF1_PC 0x00000010 /* Performance counters present */
7969 +#define CONF1_DA_SHIFT 7 /* D$ associativity */
7970 +#define CONF1_DA_MASK 0x00000380
7971 +#define CONF1_DA_BASE 1
7972 +#define CONF1_DL_SHIFT 10 /* D$ line size */
7973 +#define CONF1_DL_MASK 0x00001c00
7974 +#define CONF1_DL_BASE 2
7975 +#define CONF1_DS_SHIFT 13 /* D$ sets/way */
7976 +#define CONF1_DS_MASK 0x0000e000
7977 +#define CONF1_DS_BASE 64
7978 +#define CONF1_IA_SHIFT 16 /* I$ associativity */
7979 +#define CONF1_IA_MASK 0x00070000
7980 +#define CONF1_IA_BASE 1
7981 +#define CONF1_IL_SHIFT 19 /* I$ line size */
7982 +#define CONF1_IL_MASK 0x00380000
7983 +#define CONF1_IL_BASE 2
7984 +#define CONF1_IS_SHIFT 22 /* Instruction cache sets/way */
7985 +#define CONF1_IS_MASK 0x01c00000
7986 +#define CONF1_IS_BASE 64
7987 +#define CONF1_MS_MASK 0x7e000000 /* Number of tlb entries */
7988 +#define CONF1_MS_SHIFT 25
7989 +
7990 +/* PRID register */
7991 +#define PRID_COPT_MASK 0xff000000
7992 +#define PRID_COMP_MASK 0x00ff0000
7993 +#define PRID_IMP_MASK 0x0000ff00
7994 +#define PRID_REV_MASK 0x000000ff
7995 +
7996 +#define PRID_COMP_LEGACY 0x000000
7997 +#define PRID_COMP_MIPS 0x010000
7998 +#define PRID_COMP_BROADCOM 0x020000
7999 +#define PRID_COMP_ALCHEMY 0x030000
8000 +#define PRID_COMP_SIBYTE 0x040000
8001 +#define PRID_IMP_BCM4710 0x4000
8002 +#define PRID_IMP_BCM3302 0x9000
8003 +#define PRID_IMP_BCM3303 0x9100
8004 +
8005 +#define PRID_IMP_UNKNOWN 0xff00
8006 +
8007 +#define BCM330X(id) \
8008 + (((id & (PRID_COMP_MASK | PRID_IMP_MASK)) == (PRID_COMP_BROADCOM | PRID_IMP_BCM3302)) \
8009 + || ((id & (PRID_COMP_MASK | PRID_IMP_MASK)) == (PRID_COMP_BROADCOM | PRID_IMP_BCM3303)))
8010 +
8011 +/* Bits in C0_BROADCOM */
8012 +#define BRCM_PFC_AVAIL 0x20000000 /* PFC is available */
8013 +#define BRCM_DC_ENABLE 0x40000000 /* Enable Data $ */
8014 +#define BRCM_IC_ENABLE 0x80000000 /* Enable Instruction $ */
8015 +#define BRCM_PFC_ENABLE 0x00400000 /* Obsolete? Enable PFC (at least on 4310) */
8016 +
8017 +/* PreFetch Cache aka Read Ahead Cache */
8018 +
8019 +#define PFC_CR0 0xff400000 /* control reg 0 */
8020 +#define PFC_CR1 0xff400004 /* control reg 1 */
8021 +
8022 +/* PFC operations */
8023 +#define PFC_I 0x00000001 /* Enable PFC use for instructions */
8024 +#define PFC_D 0x00000002 /* Enable PFC use for data */
8025 +#define PFC_PFI 0x00000004 /* Enable seq. prefetch for instructions */
8026 +#define PFC_PFD 0x00000008 /* Enable seq. prefetch for data */
8027 +#define PFC_CINV 0x00000010 /* Enable selective (i/d) cacheop flushing */
8028 +#define PFC_NCH 0x00000020 /* Disable flushing based on cacheops */
8029 +#define PFC_DPF 0x00000040 /* Enable directional prefetching */
8030 +#define PFC_FLUSH 0x00000100 /* Flush the PFC */
8031 +#define PFC_BRR 0x40000000 /* Bus error indication */
8032 +#define PFC_PWR 0x80000000 /* Disable power saving (clock gating) */
8033 +
8034 +/* Handy defaults */
8035 +#define PFC_DISABLED 0
8036 +#define PFC_AUTO 0xffffffff /* auto select the default mode */
8037 +#define PFC_INST (PFC_I | PFC_PFI | PFC_CINV)
8038 +#define PFC_INST_NOPF (PFC_I | PFC_CINV)
8039 +#define PFC_DATA (PFC_D | PFC_PFD | PFC_CINV)
8040 +#define PFC_DATA_NOPF (PFC_D | PFC_CINV)
8041 +#define PFC_I_AND_D (PFC_INST | PFC_DATA)
8042 +#define PFC_I_AND_D_NOPF (PFC_INST_NOPF | PFC_DATA_NOPF)
8043 +
8044 +
8045 +/*
8046 + * These are the UART port assignments, expressed as offsets from the base
8047 + * register. These assignments should hold for any serial port based on
8048 + * a 8250, 16450, or 16550(A).
8049 + */
8050 +
8051 +#define UART_RX 0 /* In: Receive buffer (DLAB=0) */
8052 +#define UART_TX 0 /* Out: Transmit buffer (DLAB=0) */
8053 +#define UART_DLL 0 /* Out: Divisor Latch Low (DLAB=1) */
8054 +#define UART_DLM 1 /* Out: Divisor Latch High (DLAB=1) */
8055 +#define UART_LCR 3 /* Out: Line Control Register */
8056 +#define UART_MCR 4 /* Out: Modem Control Register */
8057 +#define UART_LSR 5 /* In: Line Status Register */
8058 +#define UART_MSR 6 /* In: Modem Status Register */
8059 +#define UART_SCR 7 /* I/O: Scratch Register */
8060 +#define UART_LCR_DLAB 0x80 /* Divisor latch access bit */
8061 +#define UART_LCR_WLEN8 0x03 /* Wordlength: 8 bits */
8062 +#define UART_MCR_LOOP 0x10 /* Enable loopback test mode */
8063 +#define UART_LSR_THRE 0x20 /* Transmit-hold-register empty */
8064 +#define UART_LSR_RXRDY 0x01 /* Receiver ready */
8065 +
8066 +
8067 +#ifndef _LANGUAGE_ASSEMBLY
8068 +
8069 +/*
8070 + * Macros to access the system control coprocessor
8071 + */
8072 +
8073 +#define MFC0(source, sel) \
8074 +({ \
8075 + int __res; \
8076 + __asm__ __volatile__( \
8077 + ".set\tnoreorder\n\t" \
8078 + ".set\tnoat\n\t" \
8079 + ".word\t"STR(0x40010000 | ((source)<<11) | (sel))"\n\t" \
8080 + "move\t%0,$1\n\t" \
8081 + ".set\tat\n\t" \
8082 + ".set\treorder" \
8083 + :"=r" (__res) \
8084 + : \
8085 + :"$1"); \
8086 + __res; \
8087 +})
8088 +
8089 +#define MTC0(source, sel, value) \
8090 +do { \
8091 + __asm__ __volatile__( \
8092 + ".set\tnoreorder\n\t" \
8093 + ".set\tnoat\n\t" \
8094 + "move\t$1,%z0\n\t" \
8095 + ".word\t"STR(0x40810000 | ((source)<<11) | (sel))"\n\t" \
8096 + ".set\tat\n\t" \
8097 + ".set\treorder" \
8098 + : \
8099 + :"jr" (value) \
8100 + :"$1"); \
8101 +} while (0)
8102 +
8103 +#define get_c0_count() \
8104 +({ \
8105 + int __res; \
8106 + __asm__ __volatile__( \
8107 + ".set\tnoreorder\n\t" \
8108 + ".set\tnoat\n\t" \
8109 + "mfc0\t%0,$9\n\t" \
8110 + ".set\tat\n\t" \
8111 + ".set\treorder" \
8112 + :"=r" (__res)); \
8113 + __res; \
8114 +})
8115 +
8116 +static INLINE void icache_probe(uint32 config1, uint *size, uint *lsize)
8117 +{
8118 + uint lsz, sets, ways;
8119 +
8120 + /* Instruction Cache Size = Associativity * Line Size * Sets Per Way */
8121 + if ((lsz = ((config1 & CONF1_IL_MASK) >> CONF1_IL_SHIFT)))
8122 + lsz = CONF1_IL_BASE << lsz;
8123 + sets = CONF1_IS_BASE << ((config1 & CONF1_IS_MASK) >> CONF1_IS_SHIFT);
8124 + ways = CONF1_IA_BASE + ((config1 & CONF1_IA_MASK) >> CONF1_IA_SHIFT);
8125 + *size = lsz * sets * ways;
8126 + *lsize = lsz;
8127 +}
8128 +
8129 +static INLINE void dcache_probe(uint32 config1, uint *size, uint *lsize)
8130 +{
8131 + uint lsz, sets, ways;
8132 +
8133 + /* Data Cache Size = Associativity * Line Size * Sets Per Way */
8134 + if ((lsz = ((config1 & CONF1_DL_MASK) >> CONF1_DL_SHIFT)))
8135 + lsz = CONF1_DL_BASE << lsz;
8136 + sets = CONF1_DS_BASE << ((config1 & CONF1_DS_MASK) >> CONF1_DS_SHIFT);
8137 + ways = CONF1_DA_BASE + ((config1 & CONF1_DA_MASK) >> CONF1_DA_SHIFT);
8138 + *size = lsz * sets * ways;
8139 + *lsize = lsz;
8140 +}
8141 +
8142 +#define cache_op(base, op) \
8143 + __asm__ __volatile__(" \
8144 + .set noreorder; \
8145 + .set mips3; \
8146 + cache %1, (%0); \
8147 + .set mips0; \
8148 + .set reorder" \
8149 + : \
8150 + : "r" (base), \
8151 + "i" (op));
8152 +
8153 +#define cache_unroll4(base, delta, op) \
8154 + __asm__ __volatile__(" \
8155 + .set noreorder; \
8156 + .set mips3; \
8157 + cache %1,0(%0); \
8158 + cache %1,delta(%0); \
8159 + cache %1,(2 * delta)(%0); \
8160 + cache %1,(3 * delta)(%0); \
8161 + .set mips0; \
8162 + .set reorder" \
8163 + : \
8164 + : "r" (base), \
8165 + "i" (op));
8166 +
8167 +#endif /* !_LANGUAGE_ASSEMBLY */
8168 +
8169 +#endif /* _MISPINC_H */
8170 diff -urN linux.old/arch/mips/bcm947xx/include/osl.h linux.dev/arch/mips/bcm947xx/include/osl.h
8171 --- linux.old/arch/mips/bcm947xx/include/osl.h 1970-01-01 01:00:00.000000000 +0100
8172 +++ linux.dev/arch/mips/bcm947xx/include/osl.h 2005-12-15 15:35:08.321801750 +0100
8173 @@ -0,0 +1,42 @@
8174 +/*
8175 + * OS Abstraction Layer
8176 + *
8177 + * Copyright 2005, Broadcom Corporation
8178 + * All Rights Reserved.
8179 + *
8180 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8181 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
8182 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
8183 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
8184 + * $Id$
8185 + */
8186 +
8187 +#ifndef _osl_h_
8188 +#define _osl_h_
8189 +
8190 +/* osl handle type forward declaration */
8191 +typedef struct os_handle osl_t;
8192 +
8193 +#if defined(linux)
8194 +#include <linux_osl.h>
8195 +#elif defined(NDIS)
8196 +#include <ndis_osl.h>
8197 +#elif defined(_CFE_)
8198 +#include <cfe_osl.h>
8199 +#elif defined(_HNDRTE_)
8200 +#include <hndrte_osl.h>
8201 +#elif defined(_MINOSL_)
8202 +#include <min_osl.h>
8203 +#elif PMON
8204 +#include <pmon_osl.h>
8205 +#elif defined(MACOSX)
8206 +#include <macosx_osl.h>
8207 +#else
8208 +#error "Unsupported OSL requested"
8209 +#endif
8210 +
8211 +/* handy */
8212 +#define SET_REG(r, mask, val) W_REG((r), ((R_REG(r) & ~(mask)) | (val)))
8213 +#define MAXPRIO 7 /* 0-7 */
8214 +
8215 +#endif /* _osl_h_ */
8216 diff -urN linux.old/arch/mips/bcm947xx/include/pcicfg.h linux.dev/arch/mips/bcm947xx/include/pcicfg.h
8217 --- linux.old/arch/mips/bcm947xx/include/pcicfg.h 1970-01-01 01:00:00.000000000 +0100
8218 +++ linux.dev/arch/mips/bcm947xx/include/pcicfg.h 2005-12-15 15:36:31.719013750 +0100
8219 @@ -0,0 +1,398 @@
8220 +/*
8221 + * pcicfg.h: PCI configuration constants and structures.
8222 + *
8223 + * Copyright 2005, Broadcom Corporation
8224 + * All Rights Reserved.
8225 + *
8226 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8227 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
8228 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
8229 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
8230 + *
8231 + * $Id$
8232 + */
8233 +
8234 +#ifndef _h_pci_
8235 +#define _h_pci_
8236 +
8237 +/* The following inside ifndef's so we don't collide with NTDDK.H */
8238 +#ifndef PCI_MAX_BUS
8239 +#define PCI_MAX_BUS 0x100
8240 +#endif
8241 +#ifndef PCI_MAX_DEVICES
8242 +#define PCI_MAX_DEVICES 0x20
8243 +#endif
8244 +#ifndef PCI_MAX_FUNCTION
8245 +#define PCI_MAX_FUNCTION 0x8
8246 +#endif
8247 +
8248 +#ifndef PCI_INVALID_VENDORID
8249 +#define PCI_INVALID_VENDORID 0xffff
8250 +#endif
8251 +#ifndef PCI_INVALID_DEVICEID
8252 +#define PCI_INVALID_DEVICEID 0xffff
8253 +#endif
8254 +
8255 +
8256 +/* Convert between bus-slot-function-register and config addresses */
8257 +
8258 +#define PCICFG_BUS_SHIFT 16 /* Bus shift */
8259 +#define PCICFG_SLOT_SHIFT 11 /* Slot shift */
8260 +#define PCICFG_FUN_SHIFT 8 /* Function shift */
8261 +#define PCICFG_OFF_SHIFT 0 /* Register shift */
8262 +
8263 +#define PCICFG_BUS_MASK 0xff /* Bus mask */
8264 +#define PCICFG_SLOT_MASK 0x1f /* Slot mask */
8265 +#define PCICFG_FUN_MASK 7 /* Function mask */
8266 +#define PCICFG_OFF_MASK 0xff /* Bus mask */
8267 +
8268 +#define PCI_CONFIG_ADDR(b, s, f, o) \
8269 + ((((b) & PCICFG_BUS_MASK) << PCICFG_BUS_SHIFT) \
8270 + | (((s) & PCICFG_SLOT_MASK) << PCICFG_SLOT_SHIFT) \
8271 + | (((f) & PCICFG_FUN_MASK) << PCICFG_FUN_SHIFT) \
8272 + | (((o) & PCICFG_OFF_MASK) << PCICFG_OFF_SHIFT))
8273 +
8274 +#define PCI_CONFIG_BUS(a) (((a) >> PCICFG_BUS_SHIFT) & PCICFG_BUS_MASK)
8275 +#define PCI_CONFIG_SLOT(a) (((a) >> PCICFG_SLOT_SHIFT) & PCICFG_SLOT_MASK)
8276 +#define PCI_CONFIG_FUN(a) (((a) >> PCICFG_FUN_SHIFT) & PCICFG_FUN_MASK)
8277 +#define PCI_CONFIG_OFF(a) (((a) >> PCICFG_OFF_SHIFT) & PCICFG_OFF_MASK)
8278 +
8279 +/* The actual config space */
8280 +
8281 +#define PCI_BAR_MAX 6
8282 +
8283 +#define PCI_ROM_BAR 8
8284 +
8285 +#define PCR_RSVDA_MAX 2
8286 +
8287 +/* pci config status reg has a bit to indicate that capability ptr is present*/
8288 +
8289 +#define PCI_CAPPTR_PRESENT 0x0010
8290 +
8291 +typedef struct _pci_config_regs {
8292 + unsigned short vendor;
8293 + unsigned short device;
8294 + unsigned short command;
8295 + unsigned short status;
8296 + unsigned char rev_id;
8297 + unsigned char prog_if;
8298 + unsigned char sub_class;
8299 + unsigned char base_class;
8300 + unsigned char cache_line_size;
8301 + unsigned char latency_timer;
8302 + unsigned char header_type;
8303 + unsigned char bist;
8304 + unsigned long base[PCI_BAR_MAX];
8305 + unsigned long cardbus_cis;
8306 + unsigned short subsys_vendor;
8307 + unsigned short subsys_id;
8308 + unsigned long baserom;
8309 + unsigned long rsvd_a[PCR_RSVDA_MAX];
8310 + unsigned char int_line;
8311 + unsigned char int_pin;
8312 + unsigned char min_gnt;
8313 + unsigned char max_lat;
8314 + unsigned char dev_dep[192];
8315 +} pci_config_regs;
8316 +
8317 +#define SZPCR (sizeof (pci_config_regs))
8318 +#define MINSZPCR 64 /* offsetof (dev_dep[0] */
8319 +
8320 +/* A structure for the config registers is nice, but in most
8321 + * systems the config space is not memory mapped, so we need
8322 + * filed offsetts. :-(
8323 + */
8324 +#define PCI_CFG_VID 0
8325 +#define PCI_CFG_DID 2
8326 +#define PCI_CFG_CMD 4
8327 +#define PCI_CFG_STAT 6
8328 +#define PCI_CFG_REV 8
8329 +#define PCI_CFG_PROGIF 9
8330 +#define PCI_CFG_SUBCL 0xa
8331 +#define PCI_CFG_BASECL 0xb
8332 +#define PCI_CFG_CLSZ 0xc
8333 +#define PCI_CFG_LATTIM 0xd
8334 +#define PCI_CFG_HDR 0xe
8335 +#define PCI_CFG_BIST 0xf
8336 +#define PCI_CFG_BAR0 0x10
8337 +#define PCI_CFG_BAR1 0x14
8338 +#define PCI_CFG_BAR2 0x18
8339 +#define PCI_CFG_BAR3 0x1c
8340 +#define PCI_CFG_BAR4 0x20
8341 +#define PCI_CFG_BAR5 0x24
8342 +#define PCI_CFG_CIS 0x28
8343 +#define PCI_CFG_SVID 0x2c
8344 +#define PCI_CFG_SSID 0x2e
8345 +#define PCI_CFG_ROMBAR 0x30
8346 +#define PCI_CFG_CAPPTR 0x34
8347 +#define PCI_CFG_INT 0x3c
8348 +#define PCI_CFG_PIN 0x3d
8349 +#define PCI_CFG_MINGNT 0x3e
8350 +#define PCI_CFG_MAXLAT 0x3f
8351 +
8352 +/* Classes and subclasses */
8353 +
8354 +typedef enum {
8355 + PCI_CLASS_OLD = 0,
8356 + PCI_CLASS_DASDI,
8357 + PCI_CLASS_NET,
8358 + PCI_CLASS_DISPLAY,
8359 + PCI_CLASS_MMEDIA,
8360 + PCI_CLASS_MEMORY,
8361 + PCI_CLASS_BRIDGE,
8362 + PCI_CLASS_COMM,
8363 + PCI_CLASS_BASE,
8364 + PCI_CLASS_INPUT,
8365 + PCI_CLASS_DOCK,
8366 + PCI_CLASS_CPU,
8367 + PCI_CLASS_SERIAL,
8368 + PCI_CLASS_INTELLIGENT = 0xe,
8369 + PCI_CLASS_SATELLITE,
8370 + PCI_CLASS_CRYPT,
8371 + PCI_CLASS_DSP,
8372 + PCI_CLASS_MAX
8373 +} pci_classes;
8374 +
8375 +typedef enum {
8376 + PCI_DASDI_SCSI,
8377 + PCI_DASDI_IDE,
8378 + PCI_DASDI_FLOPPY,
8379 + PCI_DASDI_IPI,
8380 + PCI_DASDI_RAID,
8381 + PCI_DASDI_OTHER = 0x80
8382 +} pci_dasdi_subclasses;
8383 +
8384 +typedef enum {
8385 + PCI_NET_ETHER,
8386 + PCI_NET_TOKEN,
8387 + PCI_NET_FDDI,
8388 + PCI_NET_ATM,
8389 + PCI_NET_OTHER = 0x80
8390 +} pci_net_subclasses;
8391 +
8392 +typedef enum {
8393 + PCI_DISPLAY_VGA,
8394 + PCI_DISPLAY_XGA,
8395 + PCI_DISPLAY_3D,
8396 + PCI_DISPLAY_OTHER = 0x80
8397 +} pci_display_subclasses;
8398 +
8399 +typedef enum {
8400 + PCI_MMEDIA_VIDEO,
8401 + PCI_MMEDIA_AUDIO,
8402 + PCI_MMEDIA_PHONE,
8403 + PCI_MEDIA_OTHER = 0x80
8404 +} pci_mmedia_subclasses;
8405 +
8406 +typedef enum {
8407 + PCI_MEMORY_RAM,
8408 + PCI_MEMORY_FLASH,
8409 + PCI_MEMORY_OTHER = 0x80
8410 +} pci_memory_subclasses;
8411 +
8412 +typedef enum {
8413 + PCI_BRIDGE_HOST,
8414 + PCI_BRIDGE_ISA,
8415 + PCI_BRIDGE_EISA,
8416 + PCI_BRIDGE_MC,
8417 + PCI_BRIDGE_PCI,
8418 + PCI_BRIDGE_PCMCIA,
8419 + PCI_BRIDGE_NUBUS,
8420 + PCI_BRIDGE_CARDBUS,
8421 + PCI_BRIDGE_RACEWAY,
8422 + PCI_BRIDGE_OTHER = 0x80
8423 +} pci_bridge_subclasses;
8424 +
8425 +typedef enum {
8426 + PCI_COMM_UART,
8427 + PCI_COMM_PARALLEL,
8428 + PCI_COMM_MULTIUART,
8429 + PCI_COMM_MODEM,
8430 + PCI_COMM_OTHER = 0x80
8431 +} pci_comm_subclasses;
8432 +
8433 +typedef enum {
8434 + PCI_BASE_PIC,
8435 + PCI_BASE_DMA,
8436 + PCI_BASE_TIMER,
8437 + PCI_BASE_RTC,
8438 + PCI_BASE_PCI_HOTPLUG,
8439 + PCI_BASE_OTHER = 0x80
8440 +} pci_base_subclasses;
8441 +
8442 +typedef enum {
8443 + PCI_INPUT_KBD,
8444 + PCI_INPUT_PEN,
8445 + PCI_INPUT_MOUSE,
8446 + PCI_INPUT_SCANNER,
8447 + PCI_INPUT_GAMEPORT,
8448 + PCI_INPUT_OTHER = 0x80
8449 +} pci_input_subclasses;
8450 +
8451 +typedef enum {
8452 + PCI_DOCK_GENERIC,
8453 + PCI_DOCK_OTHER = 0x80
8454 +} pci_dock_subclasses;
8455 +
8456 +typedef enum {
8457 + PCI_CPU_386,
8458 + PCI_CPU_486,
8459 + PCI_CPU_PENTIUM,
8460 + PCI_CPU_ALPHA = 0x10,
8461 + PCI_CPU_POWERPC = 0x20,
8462 + PCI_CPU_MIPS = 0x30,
8463 + PCI_CPU_COPROC = 0x40,
8464 + PCI_CPU_OTHER = 0x80
8465 +} pci_cpu_subclasses;
8466 +
8467 +typedef enum {
8468 + PCI_SERIAL_IEEE1394,
8469 + PCI_SERIAL_ACCESS,
8470 + PCI_SERIAL_SSA,
8471 + PCI_SERIAL_USB,
8472 + PCI_SERIAL_FIBER,
8473 + PCI_SERIAL_SMBUS,
8474 + PCI_SERIAL_OTHER = 0x80
8475 +} pci_serial_subclasses;
8476 +
8477 +typedef enum {
8478 + PCI_INTELLIGENT_I2O,
8479 +} pci_intelligent_subclasses;
8480 +
8481 +typedef enum {
8482 + PCI_SATELLITE_TV,
8483 + PCI_SATELLITE_AUDIO,
8484 + PCI_SATELLITE_VOICE,
8485 + PCI_SATELLITE_DATA,
8486 + PCI_SATELLITE_OTHER = 0x80
8487 +} pci_satellite_subclasses;
8488 +
8489 +typedef enum {
8490 + PCI_CRYPT_NETWORK,
8491 + PCI_CRYPT_ENTERTAINMENT,
8492 + PCI_CRYPT_OTHER = 0x80
8493 +} pci_crypt_subclasses;
8494 +
8495 +typedef enum {
8496 + PCI_DSP_DPIO,
8497 + PCI_DSP_OTHER = 0x80
8498 +} pci_dsp_subclasses;
8499 +
8500 +/* Header types */
8501 +typedef enum {
8502 + PCI_HEADER_NORMAL,
8503 + PCI_HEADER_BRIDGE,
8504 + PCI_HEADER_CARDBUS
8505 +} pci_header_types;
8506 +
8507 +
8508 +/* Overlay for a PCI-to-PCI bridge */
8509 +
8510 +#define PPB_RSVDA_MAX 2
8511 +#define PPB_RSVDD_MAX 8
8512 +
8513 +typedef struct _ppb_config_regs {
8514 + unsigned short vendor;
8515 + unsigned short device;
8516 + unsigned short command;
8517 + unsigned short status;
8518 + unsigned char rev_id;
8519 + unsigned char prog_if;
8520 + unsigned char sub_class;
8521 + unsigned char base_class;
8522 + unsigned char cache_line_size;
8523 + unsigned char latency_timer;
8524 + unsigned char header_type;
8525 + unsigned char bist;
8526 + unsigned long rsvd_a[PPB_RSVDA_MAX];
8527 + unsigned char prim_bus;
8528 + unsigned char sec_bus;
8529 + unsigned char sub_bus;
8530 + unsigned char sec_lat;
8531 + unsigned char io_base;
8532 + unsigned char io_lim;
8533 + unsigned short sec_status;
8534 + unsigned short mem_base;
8535 + unsigned short mem_lim;
8536 + unsigned short pf_mem_base;
8537 + unsigned short pf_mem_lim;
8538 + unsigned long pf_mem_base_hi;
8539 + unsigned long pf_mem_lim_hi;
8540 + unsigned short io_base_hi;
8541 + unsigned short io_lim_hi;
8542 + unsigned short subsys_vendor;
8543 + unsigned short subsys_id;
8544 + unsigned long rsvd_b;
8545 + unsigned char rsvd_c;
8546 + unsigned char int_pin;
8547 + unsigned short bridge_ctrl;
8548 + unsigned char chip_ctrl;
8549 + unsigned char diag_ctrl;
8550 + unsigned short arb_ctrl;
8551 + unsigned long rsvd_d[PPB_RSVDD_MAX];
8552 + unsigned char dev_dep[192];
8553 +} ppb_config_regs;
8554 +
8555 +
8556 +/* PCI CAPABILITY DEFINES */
8557 +#define PCI_CAP_POWERMGMTCAP_ID 0x01
8558 +#define PCI_CAP_MSICAP_ID 0x05
8559 +
8560 +/* Data structure to define the Message Signalled Interrupt facility
8561 + * Valid for PCI and PCIE configurations */
8562 +typedef struct _pciconfig_cap_msi {
8563 + unsigned char capID;
8564 + unsigned char nextptr;
8565 + unsigned short msgctrl;
8566 + unsigned int msgaddr;
8567 +} pciconfig_cap_msi;
8568 +
8569 +/* Data structure to define the Power managment facility
8570 + * Valid for PCI and PCIE configurations */
8571 +typedef struct _pciconfig_cap_pwrmgmt {
8572 + unsigned char capID;
8573 + unsigned char nextptr;
8574 + unsigned short pme_cap;
8575 + unsigned short pme_sts_ctrl;
8576 + unsigned char pme_bridge_ext;
8577 + unsigned char data;
8578 +} pciconfig_cap_pwrmgmt;
8579 +
8580 +/* Everything below is BRCM HND proprietary */
8581 +
8582 +#define PCI_BAR0_WIN 0x80 /* backplane addres space accessed by BAR0 */
8583 +#define PCI_BAR1_WIN 0x84 /* backplane addres space accessed by BAR1 */
8584 +#define PCI_SPROM_CONTROL 0x88 /* sprom property control */
8585 +#define PCI_BAR1_CONTROL 0x8c /* BAR1 region burst control */
8586 +#define PCI_INT_STATUS 0x90 /* PCI and other cores interrupts */
8587 +#define PCI_INT_MASK 0x94 /* mask of PCI and other cores interrupts */
8588 +#define PCI_TO_SB_MB 0x98 /* signal backplane interrupts */
8589 +#define PCI_BACKPLANE_ADDR 0xA0 /* address an arbitrary location on the system backplane */
8590 +#define PCI_BACKPLANE_DATA 0xA4 /* data at the location specified by above address register */
8591 +#define PCI_GPIO_IN 0xb0 /* pci config space gpio input (>=rev3) */
8592 +#define PCI_GPIO_OUT 0xb4 /* pci config space gpio output (>=rev3) */
8593 +#define PCI_GPIO_OUTEN 0xb8 /* pci config space gpio output enable (>=rev3) */
8594 +
8595 +#define PCI_BAR0_SPROM_OFFSET (4 * 1024) /* bar0 + 4K accesses external sprom */
8596 +#define PCI_BAR0_PCIREGS_OFFSET (6 * 1024) /* bar0 + 6K accesses pci core registers */
8597 +
8598 +/* PCI_INT_STATUS */
8599 +#define PCI_SBIM_STATUS_SERR 0x4 /* backplane SBErr interrupt status */
8600 +
8601 +/* PCI_INT_MASK */
8602 +#define PCI_SBIM_SHIFT 8 /* backplane core interrupt mask bits offset */
8603 +#define PCI_SBIM_MASK 0xff00 /* backplane core interrupt mask */
8604 +#define PCI_SBIM_MASK_SERR 0x4 /* backplane SBErr interrupt mask */
8605 +
8606 +/* PCI_SPROM_CONTROL */
8607 +#define SPROM_BLANK 0x04 /* indicating a blank sprom */
8608 +#define SPROM_WRITEEN 0x10 /* sprom write enable */
8609 +#define SPROM_BOOTROM_WE 0x20 /* external bootrom write enable */
8610 +
8611 +#define SPROM_SIZE 256 /* sprom size in 16-bit */
8612 +#define SPROM_CRC_RANGE 64 /* crc cover range in 16-bit */
8613 +
8614 +/* PCI_CFG_CMD_STAT */
8615 +#define PCI_CFG_CMD_STAT_TA 0x08000000 /* target abort status */
8616 +
8617 +#endif
8618 diff -urN linux.old/arch/mips/bcm947xx/include/proto/ethernet.h linux.dev/arch/mips/bcm947xx/include/proto/ethernet.h
8619 --- linux.old/arch/mips/bcm947xx/include/proto/ethernet.h 1970-01-01 01:00:00.000000000 +0100
8620 +++ linux.dev/arch/mips/bcm947xx/include/proto/ethernet.h 2005-12-15 12:57:27.869191250 +0100
8621 @@ -0,0 +1,145 @@
8622 +/*******************************************************************************
8623 + * $Id$
8624 + * Copyright 2001-2003, Broadcom Corporation
8625 + * All Rights Reserved.
8626 + *
8627 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8628 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
8629 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
8630 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
8631 + * From FreeBSD 2.2.7: Fundamental constants relating to ethernet.
8632 + ******************************************************************************/
8633 +
8634 +#ifndef _NET_ETHERNET_H_ /* use native BSD ethernet.h when available */
8635 +#define _NET_ETHERNET_H_
8636 +
8637 +#ifndef _TYPEDEFS_H_
8638 +#include "typedefs.h"
8639 +#endif
8640 +
8641 +#if defined(__GNUC__)
8642 +#define PACKED __attribute__((packed))
8643 +#else
8644 +#define PACKED
8645 +#endif
8646 +
8647 +/*
8648 + * The number of bytes in an ethernet (MAC) address.
8649 + */
8650 +#define ETHER_ADDR_LEN 6
8651 +
8652 +/*
8653 + * The number of bytes in the type field.
8654 + */
8655 +#define ETHER_TYPE_LEN 2
8656 +
8657 +/*
8658 + * The number of bytes in the trailing CRC field.
8659 + */
8660 +#define ETHER_CRC_LEN 4
8661 +
8662 +/*
8663 + * The length of the combined header.
8664 + */
8665 +#define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN)
8666 +
8667 +/*
8668 + * The minimum packet length.
8669 + */
8670 +#define ETHER_MIN_LEN 64
8671 +
8672 +/*
8673 + * The minimum packet user data length.
8674 + */
8675 +#define ETHER_MIN_DATA 46
8676 +
8677 +/*
8678 + * The maximum packet length.
8679 + */
8680 +#define ETHER_MAX_LEN 1518
8681 +
8682 +/*
8683 + * The maximum packet user data length.
8684 + */
8685 +#define ETHER_MAX_DATA 1500
8686 +
8687 +/*
8688 + * Used to uniquely identify a 802.1q VLAN-tagged header.
8689 + */
8690 +#define VLAN_TAG 0x8100
8691 +
8692 +/*
8693 + * Located after dest & src address in ether header.
8694 + */
8695 +#define VLAN_FIELDS_OFFSET (ETHER_ADDR_LEN * 2)
8696 +
8697 +/*
8698 + * 4 bytes of vlan field info.
8699 + */
8700 +#define VLAN_FIELDS_SIZE 4
8701 +
8702 +/* location of pri bits in 16-bit vlan fields */
8703 +#define VLAN_PRI_SHIFT 13
8704 +
8705 +/* 3 bits of priority */
8706 +#define VLAN_PRI_MASK 7
8707 +
8708 +/* 802.1X ethertype */
8709 +#define ETHER_TYPE_802_1X 0x888e
8710 +
8711 +/*
8712 + * A macro to validate a length with
8713 + */
8714 +#define ETHER_IS_VALID_LEN(foo) \
8715 + ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
8716 +
8717 +
8718 +#ifndef __INCif_etherh /* Quick and ugly hack for VxWorks */
8719 +/*
8720 + * Structure of a 10Mb/s Ethernet header.
8721 + */
8722 +struct ether_header {
8723 + uint8 ether_dhost[ETHER_ADDR_LEN];
8724 + uint8 ether_shost[ETHER_ADDR_LEN];
8725 + uint16 ether_type;
8726 +} PACKED ;
8727 +
8728 +/*
8729 + * Structure of a 48-bit Ethernet address.
8730 + */
8731 +struct ether_addr {
8732 + uint8 octet[ETHER_ADDR_LEN];
8733 +} PACKED ;
8734 +#endif
8735 +
8736 +/*
8737 + * Takes a pointer, returns true if a 48-bit multicast address
8738 + * (including broadcast, since it is all ones)
8739 + */
8740 +#define ETHER_ISMULTI(ea) (((uint8 *)(ea))[0] & 1)
8741 +
8742 +/*
8743 + * Takes a pointer, returns true if a 48-bit broadcast (all ones)
8744 + */
8745 +#define ETHER_ISBCAST(ea) ((((uint8 *)(ea))[0] & \
8746 + ((uint8 *)(ea))[1] & \
8747 + ((uint8 *)(ea))[2] & \
8748 + ((uint8 *)(ea))[3] & \
8749 + ((uint8 *)(ea))[4] & \
8750 + ((uint8 *)(ea))[5]) == 0xff)
8751 +
8752 +static const struct ether_addr ether_bcast = {{255, 255, 255, 255, 255, 255}};
8753 +
8754 +/*
8755 + * Takes a pointer, returns true if a 48-bit null address (all zeros)
8756 + */
8757 +#define ETHER_ISNULLADDR(ea) ((((uint8 *)(ea))[0] | \
8758 + ((uint8 *)(ea))[1] | \
8759 + ((uint8 *)(ea))[2] | \
8760 + ((uint8 *)(ea))[3] | \
8761 + ((uint8 *)(ea))[4] | \
8762 + ((uint8 *)(ea))[5]) == 0)
8763 +
8764 +#undef PACKED
8765 +
8766 +#endif /* _NET_ETHERNET_H_ */
8767 diff -urN linux.old/arch/mips/bcm947xx/include/s5.h linux.dev/arch/mips/bcm947xx/include/s5.h
8768 --- linux.old/arch/mips/bcm947xx/include/s5.h 1970-01-01 01:00:00.000000000 +0100
8769 +++ linux.dev/arch/mips/bcm947xx/include/s5.h 2005-12-15 12:57:27.869191250 +0100
8770 @@ -0,0 +1,103 @@
8771 +#ifndef _S5_H_
8772 +#define _S5_H_
8773 +/*
8774 + * Copyright 2003, Broadcom Corporation
8775 + * All Rights Reserved.
8776 + *
8777 + * Broadcom Sentry5 (S5) BCM5365, 53xx, BCM58xx SOC Internal Core
8778 + * and MIPS3301 (R4K) System Address Space
8779 + *
8780 + * This program is free software; you can redistribute it and/or
8781 + * modify it under the terms of the GNU General Public License as
8782 + * published by the Free Software Foundation, located in the file
8783 + * LICENSE.
8784 + *
8785 + * $Id: s5.h,v 1.3 2003/06/10 18:54:51 jfd Exp $
8786 + *
8787 + */
8788 +
8789 +/* BCM5365 Address map */
8790 +#define KSEG1ADDR(x) ( (x) | 0xa0000000)
8791 +#define BCM5365_SDRAM 0x00000000 /* 0-128MB Physical SDRAM */
8792 +#define BCM5365_PCI_MEM 0x08000000 /* Host Mode PCI mem space (64MB) */
8793 +#define BCM5365_PCI_CFG 0x0c000000 /* Host Mode PCI cfg space (64MB) */
8794 +#define BCM5365_PCI_DMA 0x40000000 /* Client Mode PCI mem space (1GB)*/
8795 +#define BCM5365_SDRAM_SWAPPED 0x10000000 /* Byteswapped Physical SDRAM */
8796 +#define BCM5365_ENUM 0x18000000 /* Beginning of core enum space */
8797 +
8798 +/* BCM5365 Core register space */
8799 +#define BCM5365_REG_CHIPC 0x18000000 /* Chipcommon registers */
8800 +#define BCM5365_REG_EMAC0 0x18001000 /* Ethernet MAC0 core registers */
8801 +#define BCM5365_REG_IPSEC 0x18002000 /* BCM582x CryptoCore registers */
8802 +#define BCM5365_REG_USB 0x18003000 /* USB core registers */
8803 +#define BCM5365_REG_PCI 0x18004000 /* PCI core registers */
8804 +#define BCM5365_REG_MIPS33 0x18005000 /* MIPS core registers */
8805 +#define BCM5365_REG_MEMC 0x18006000 /* MEMC core registers */
8806 +#define BCM5365_REG_UARTS (BCM5365_REG_CHIPC + 0x300) /* UART regs */
8807 +#define BCM5365_EJTAG 0xff200000 /* MIPS EJTAG space (2M) */
8808 +
8809 +/* COM Ports 1/2 */
8810 +#define BCM5365_UART (BCM5365_REG_UARTS)
8811 +#define BCM5365_UART_COM2 (BCM5365_REG_UARTS + 0x00000100)
8812 +
8813 +/* Registers common to MIPS33 Core used in 5365 */
8814 +#define MIPS33_FLASH_REGION 0x1fc00000 /* Boot FLASH Region */
8815 +#define MIPS33_EXTIF_REGION 0x1a000000 /* Chipcommon EXTIF region*/
8816 +#define BCM5365_EXTIF 0x1b000000 /* MISC_CS */
8817 +#define MIPS33_FLASH_REGION_AUX 0x1c000000 /* FLASH Region 2*/
8818 +
8819 +/* Internal Core Sonics Backplane Devices */
8820 +#define INTERNAL_UART_COM1 BCM5365_UART
8821 +#define INTERNAL_UART_COM2 BCM5365_UART_COM2
8822 +#define SB_REG_CHIPC BCM5365_REG_CHIPC
8823 +#define SB_REG_ENET0 BCM5365_REG_EMAC0
8824 +#define SB_REG_IPSEC BCM5365_REG_IPSEC
8825 +#define SB_REG_USB BCM5365_REG_USB
8826 +#define SB_REG_PCI BCM5365_REG_PCI
8827 +#define SB_REG_MIPS BCM5365_REG_MIPS33
8828 +#define SB_REG_MEMC BCM5365_REG_MEMC
8829 +#define SB_REG_MEMC_OFF 0x6000
8830 +#define SB_EXTIF_SPACE MIPS33_EXTIF_REGION
8831 +#define SB_FLASH_SPACE MIPS33_FLASH_REGION
8832 +
8833 +/*
8834 + * XXX
8835 + * 5365-specific backplane interrupt flag numbers. This should be done
8836 + * dynamically instead.
8837 + */
8838 +#define SBFLAG_PCI 0
8839 +#define SBFLAG_ENET0 1
8840 +#define SBFLAG_ILINE20 2
8841 +#define SBFLAG_CODEC 3
8842 +#define SBFLAG_USB 4
8843 +#define SBFLAG_EXTIF 5
8844 +#define SBFLAG_ENET1 6
8845 +
8846 +/* BCM95365 Local Bus devices */
8847 +#define BCM95365K_RESET_ADDR BCM5365_EXTIF
8848 +#define BCM95365K_BOARDID_ADDR (BCM5365_EXTIF | 0x4000)
8849 +#define BCM95365K_DOC_ADDR (BCM5365_EXTIF | 0x6000)
8850 +#define BCM95365K_LED_ADDR (BCM5365_EXTIF | 0xc000)
8851 +#define BCM95365K_TOD_REG_BASE (BCM95365K_NVRAM_ADDR | 0x1ff0)
8852 +#define BCM95365K_NVRAM_ADDR (BCM5365_EXTIF | 0xe000)
8853 +#define BCM95365K_NVRAM_SIZE 0x1ff0 /* 8K NVRAM : DS1743/STM48txx*/
8854 +
8855 +/* Write to DLR2416 VFD Display character RAM */
8856 +#define LED_REG(x) \
8857 + (*(volatile unsigned char *) (KSEG1ADDR(BCM95365K_LED_ADDR) + (x)))
8858 +
8859 +#ifdef CONFIG_VSIM
8860 +#define BCM5365_TRACE(trval) do { *((int *)0xa0002ff8) = (trval); \
8861 + } while (0)
8862 +#else
8863 +#define BCM5365_TRACE(trval) do { *((unsigned char *)\
8864 + KSEG1ADDR(BCM5365K_LED_ADDR)) = (trval); \
8865 + *((int *)0xa0002ff8) = (trval); } while (0)
8866 +#endif
8867 +
8868 +/* BCM9536R Local Bus devices */
8869 +#define BCM95365R_DOC_ADDR BCM5365_EXTIF
8870 +
8871 +
8872 +
8873 +#endif /*!_S5_H_ */
8874 diff -urN linux.old/arch/mips/bcm947xx/include/sbchipc.h linux.dev/arch/mips/bcm947xx/include/sbchipc.h
8875 --- linux.old/arch/mips/bcm947xx/include/sbchipc.h 1970-01-01 01:00:00.000000000 +0100
8876 +++ linux.dev/arch/mips/bcm947xx/include/sbchipc.h 2005-12-15 15:35:20.458560250 +0100
8877 @@ -0,0 +1,440 @@
8878 +/*
8879 + * SiliconBackplane Chipcommon core hardware definitions.
8880 + *
8881 + * The chipcommon core provides chip identification, SB control,
8882 + * jtag, 0/1/2 uarts, clock frequency control, a watchdog interrupt timer,
8883 + * gpio interface, extbus, and support for serial and parallel flashes.
8884 + *
8885 + * $Id$
8886 + * Copyright 2005, Broadcom Corporation
8887 + * All Rights Reserved.
8888 + *
8889 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8890 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
8891 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
8892 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
8893 + *
8894 + */
8895 +
8896 +#ifndef _SBCHIPC_H
8897 +#define _SBCHIPC_H
8898 +
8899 +
8900 +#ifndef _LANGUAGE_ASSEMBLY
8901 +
8902 +/* cpp contortions to concatenate w/arg prescan */
8903 +#ifndef PAD
8904 +#define _PADLINE(line) pad ## line
8905 +#define _XSTR(line) _PADLINE(line)
8906 +#define PAD _XSTR(__LINE__)
8907 +#endif /* PAD */
8908 +
8909 +typedef volatile struct {
8910 + uint32 chipid; /* 0x0 */
8911 + uint32 capabilities;
8912 + uint32 corecontrol; /* corerev >= 1 */
8913 + uint32 bist;
8914 +
8915 + /* OTP */
8916 + uint32 otpstatus; /* 0x10, corerev >= 10 */
8917 + uint32 otpcontrol;
8918 + uint32 otpprog;
8919 + uint32 PAD;
8920 +
8921 + /* Interrupt control */
8922 + uint32 intstatus; /* 0x20 */
8923 + uint32 intmask;
8924 + uint32 chipcontrol; /* 0x28, rev >= 11 */
8925 + uint32 chipstatus; /* 0x2c, rev >= 11 */
8926 +
8927 + /* Jtag Master */
8928 + uint32 jtagcmd; /* 0x30, rev >= 10 */
8929 + uint32 jtagir;
8930 + uint32 jtagdr;
8931 + uint32 jtagctrl;
8932 +
8933 + /* serial flash interface registers */
8934 + uint32 flashcontrol; /* 0x40 */
8935 + uint32 flashaddress;
8936 + uint32 flashdata;
8937 + uint32 PAD[1];
8938 +
8939 + /* Silicon backplane configuration broadcast control */
8940 + uint32 broadcastaddress; /* 0x50 */
8941 + uint32 broadcastdata;
8942 + uint32 PAD[2];
8943 +
8944 + /* gpio - cleared only by power-on-reset */
8945 + uint32 gpioin; /* 0x60 */
8946 + uint32 gpioout;
8947 + uint32 gpioouten;
8948 + uint32 gpiocontrol;
8949 + uint32 gpiointpolarity;
8950 + uint32 gpiointmask;
8951 + uint32 PAD[2];
8952 +
8953 + /* Watchdog timer */
8954 + uint32 watchdog; /* 0x80 */
8955 + uint32 PAD[1];
8956 +
8957 + /*GPIO based LED powersave registers corerev >= 16*/
8958 + uint32 gpiotimerval; /*0x88 */
8959 + uint32 gpiotimeroutmask;
8960 +
8961 + /* clock control */
8962 + uint32 clockcontrol_n; /* 0x90 */
8963 + uint32 clockcontrol_sb; /* aka m0 */
8964 + uint32 clockcontrol_pci; /* aka m1 */
8965 + uint32 clockcontrol_m2; /* mii/uart/mipsref */
8966 + uint32 clockcontrol_mips; /* aka m3 */
8967 + uint32 clkdiv; /* corerev >= 3 */
8968 + uint32 PAD[2];
8969 +
8970 + /* pll delay registers (corerev >= 4) */
8971 + uint32 pll_on_delay; /* 0xb0 */
8972 + uint32 fref_sel_delay;
8973 + uint32 slow_clk_ctl; /* 5 < corerev < 10 */
8974 + uint32 PAD[1];
8975 +
8976 + /* Instaclock registers (corerev >= 10) */
8977 + uint32 system_clk_ctl; /* 0xc0 */
8978 + uint32 clkstatestretch;
8979 + uint32 PAD[14];
8980 +
8981 + /* ExtBus control registers (corerev >= 3) */
8982 + uint32 pcmcia_config; /* 0x100 */
8983 + uint32 pcmcia_memwait;
8984 + uint32 pcmcia_attrwait;
8985 + uint32 pcmcia_iowait;
8986 + uint32 ide_config;
8987 + uint32 ide_memwait;
8988 + uint32 ide_attrwait;
8989 + uint32 ide_iowait;
8990 + uint32 prog_config;
8991 + uint32 prog_waitcount;
8992 + uint32 flash_config;
8993 + uint32 flash_waitcount;
8994 + uint32 PAD[116];
8995 +
8996 + /* uarts */
8997 + uint8 uart0data; /* 0x300 */
8998 + uint8 uart0imr;
8999 + uint8 uart0fcr;
9000 + uint8 uart0lcr;
9001 + uint8 uart0mcr;
9002 + uint8 uart0lsr;
9003 + uint8 uart0msr;
9004 + uint8 uart0scratch;
9005 + uint8 PAD[248]; /* corerev >= 1 */
9006 +
9007 + uint8 uart1data; /* 0x400 */
9008 + uint8 uart1imr;
9009 + uint8 uart1fcr;
9010 + uint8 uart1lcr;
9011 + uint8 uart1mcr;
9012 + uint8 uart1lsr;
9013 + uint8 uart1msr;
9014 + uint8 uart1scratch;
9015 +} chipcregs_t;
9016 +
9017 +#endif /* _LANGUAGE_ASSEMBLY */
9018 +
9019 +#define CC_CHIPID 0
9020 +#define CC_CAPABILITIES 4
9021 +#define CC_JTAGCMD 0x30
9022 +#define CC_JTAGIR 0x34
9023 +#define CC_JTAGDR 0x38
9024 +#define CC_JTAGCTRL 0x3c
9025 +#define CC_WATCHDOG 0x80
9026 +#define CC_CLKC_N 0x90
9027 +#define CC_CLKC_M0 0x94
9028 +#define CC_CLKC_M1 0x98
9029 +#define CC_CLKC_M2 0x9c
9030 +#define CC_CLKC_M3 0xa0
9031 +#define CC_CLKDIV 0xa4
9032 +#define CC_SYS_CLK_CTL 0xc0
9033 +#define CC_OTP 0x800
9034 +
9035 +/* chipid */
9036 +#define CID_ID_MASK 0x0000ffff /* Chip Id mask */
9037 +#define CID_REV_MASK 0x000f0000 /* Chip Revision mask */
9038 +#define CID_REV_SHIFT 16 /* Chip Revision shift */
9039 +#define CID_PKG_MASK 0x00f00000 /* Package Option mask */
9040 +#define CID_PKG_SHIFT 20 /* Package Option shift */
9041 +#define CID_CC_MASK 0x0f000000 /* CoreCount (corerev >= 4) */
9042 +#define CID_CC_SHIFT 24
9043 +
9044 +/* capabilities */
9045 +#define CAP_UARTS_MASK 0x00000003 /* Number of uarts */
9046 +#define CAP_MIPSEB 0x00000004 /* MIPS is in big-endian mode */
9047 +#define CAP_UCLKSEL 0x00000018 /* UARTs clock select */
9048 +#define CAP_UINTCLK 0x00000008 /* UARTs are driven by internal divided clock */
9049 +#define CAP_UARTGPIO 0x00000020 /* UARTs own Gpio's 15:12 */
9050 +#define CAP_EXTBUS 0x00000040 /* External bus present */
9051 +#define CAP_FLASH_MASK 0x00000700 /* Type of flash */
9052 +#define CAP_PLL_MASK 0x00038000 /* Type of PLL */
9053 +#define CAP_PWR_CTL 0x00040000 /* Power control */
9054 +#define CAP_OTPSIZE 0x00380000 /* OTP Size (0 = none) */
9055 +#define CAP_OTPSIZE_SHIFT 19 /* OTP Size shift */
9056 +#define CAP_OTPSIZE_BASE 5 /* OTP Size base */
9057 +#define CAP_JTAGP 0x00400000 /* JTAG Master Present */
9058 +#define CAP_ROM 0x00800000 /* Internal boot rom active */
9059 +
9060 +/* PLL type */
9061 +#define PLL_NONE 0x00000000
9062 +#define PLL_TYPE1 0x00010000 /* 48Mhz base, 3 dividers */
9063 +#define PLL_TYPE2 0x00020000 /* 48Mhz, 4 dividers */
9064 +#define PLL_TYPE3 0x00030000 /* 25Mhz, 2 dividers */
9065 +#define PLL_TYPE4 0x00008000 /* 48Mhz, 4 dividers */
9066 +#define PLL_TYPE5 0x00018000 /* 25Mhz, 4 dividers */
9067 +#define PLL_TYPE6 0x00028000 /* 100/200 or 120/240 only */
9068 +#define PLL_TYPE7 0x00038000 /* 25Mhz, 4 dividers */
9069 +
9070 +/* corecontrol */
9071 +#define CC_UARTCLKO 0x00000001 /* Drive UART with internal clock */
9072 +#define CC_SE 0x00000002 /* sync clk out enable (corerev >= 3) */
9073 +
9074 +/* Fields in the otpstatus register */
9075 +#define OTPS_PROGFAIL 0x80000000
9076 +#define OTPS_PROTECT 0x00000007
9077 +#define OTPS_HW_PROTECT 0x00000001
9078 +#define OTPS_SW_PROTECT 0x00000002
9079 +#define OTPS_CID_PROTECT 0x00000004
9080 +
9081 +/* Fields in the otpcontrol register */
9082 +#define OTPC_RECWAIT 0xff000000
9083 +#define OTPC_PROGWAIT 0x00ffff00
9084 +#define OTPC_PRW_SHIFT 8
9085 +#define OTPC_MAXFAIL 0x00000038
9086 +#define OTPC_VSEL 0x00000006
9087 +#define OTPC_SELVL 0x00000001
9088 +
9089 +/* Fields in otpprog */
9090 +#define OTPP_COL_MASK 0x000000ff
9091 +#define OTPP_ROW_MASK 0x0000ff00
9092 +#define OTPP_ROW_SHIFT 8
9093 +#define OTPP_READERR 0x10000000
9094 +#define OTPP_VALUE 0x20000000
9095 +#define OTPP_VALUE_SHIFT 29
9096 +#define OTPP_READ 0x40000000
9097 +#define OTPP_START 0x80000000
9098 +#define OTPP_BUSY 0x80000000
9099 +
9100 +/* jtagcmd */
9101 +#define JCMD_START 0x80000000
9102 +#define JCMD_BUSY 0x80000000
9103 +#define JCMD_PAUSE 0x40000000
9104 +#define JCMD0_ACC_MASK 0x0000f000
9105 +#define JCMD0_ACC_IRDR 0x00000000
9106 +#define JCMD0_ACC_DR 0x00001000
9107 +#define JCMD0_ACC_IR 0x00002000
9108 +#define JCMD0_ACC_RESET 0x00003000
9109 +#define JCMD0_ACC_IRPDR 0x00004000
9110 +#define JCMD0_ACC_PDR 0x00005000
9111 +#define JCMD0_IRW_MASK 0x00000f00
9112 +#define JCMD_ACC_MASK 0x000f0000 /* Changes for corerev 11 */
9113 +#define JCMD_ACC_IRDR 0x00000000
9114 +#define JCMD_ACC_DR 0x00010000
9115 +#define JCMD_ACC_IR 0x00020000
9116 +#define JCMD_ACC_RESET 0x00030000
9117 +#define JCMD_ACC_IRPDR 0x00040000
9118 +#define JCMD_ACC_PDR 0x00050000
9119 +#define JCMD_IRW_MASK 0x00001f00
9120 +#define JCMD_IRW_SHIFT 8
9121 +#define JCMD_DRW_MASK 0x0000003f
9122 +
9123 +/* jtagctrl */
9124 +#define JCTRL_FORCE_CLK 4 /* Force clock */
9125 +#define JCTRL_EXT_EN 2 /* Enable external targets */
9126 +#define JCTRL_EN 1 /* Enable Jtag master */
9127 +
9128 +/* Fields in clkdiv */
9129 +#define CLKD_SFLASH 0x0f000000
9130 +#define CLKD_SFLASH_SHIFT 24
9131 +#define CLKD_OTP 0x000f0000
9132 +#define CLKD_OTP_SHIFT 16
9133 +#define CLKD_JTAG 0x00000f00
9134 +#define CLKD_JTAG_SHIFT 8
9135 +#define CLKD_UART 0x000000ff
9136 +
9137 +/* intstatus/intmask */
9138 +#define CI_GPIO 0x00000001 /* gpio intr */
9139 +#define CI_EI 0x00000002 /* ro: ext intr pin (corerev >= 3) */
9140 +#define CI_WDRESET 0x80000000 /* watchdog reset occurred */
9141 +
9142 +/* slow_clk_ctl */
9143 +#define SCC_SS_MASK 0x00000007 /* slow clock source mask */
9144 +#define SCC_SS_LPO 0x00000000 /* source of slow clock is LPO */
9145 +#define SCC_SS_XTAL 0x00000001 /* source of slow clock is crystal */
9146 +#define SCC_SS_PCI 0x00000002 /* source of slow clock is PCI */
9147 +#define SCC_LF 0x00000200 /* LPOFreqSel, 1: 160Khz, 0: 32KHz */
9148 +#define SCC_LP 0x00000400 /* LPOPowerDown, 1: LPO is disabled, 0: LPO is enabled */
9149 +#define SCC_FS 0x00000800 /* ForceSlowClk, 1: sb/cores running on slow clock, 0: power logic control */
9150 +#define SCC_IP 0x00001000 /* IgnorePllOffReq, 1/0: power logic ignores/honors PLL clock disable requests from core */
9151 +#define SCC_XC 0x00002000 /* XtalControlEn, 1/0: power logic does/doesn't disable crystal when appropriate */
9152 +#define SCC_XP 0x00004000 /* XtalPU (RO), 1/0: crystal running/disabled */
9153 +#define SCC_CD_MASK 0xffff0000 /* ClockDivider (SlowClk = 1/(4+divisor)) */
9154 +#define SCC_CD_SHIFT 16
9155 +
9156 +/* system_clk_ctl */
9157 +#define SYCC_IE 0x00000001 /* ILPen: Enable Idle Low Power */
9158 +#define SYCC_AE 0x00000002 /* ALPen: Enable Active Low Power */
9159 +#define SYCC_FP 0x00000004 /* ForcePLLOn */
9160 +#define SYCC_AR 0x00000008 /* Force ALP (or HT if ALPen is not set */
9161 +#define SYCC_HR 0x00000010 /* Force HT */
9162 +#define SYCC_CD_MASK 0xffff0000 /* ClkDiv (ILP = 1/(4+divisor)) */
9163 +#define SYCC_CD_SHIFT 16
9164 +
9165 +/* gpiotimerval*/
9166 +#define GPIO_ONTIME_SHIFT 16
9167 +
9168 +/* clockcontrol_n */
9169 +#define CN_N1_MASK 0x3f /* n1 control */
9170 +#define CN_N2_MASK 0x3f00 /* n2 control */
9171 +#define CN_N2_SHIFT 8
9172 +#define CN_PLLC_MASK 0xf0000 /* pll control */
9173 +#define CN_PLLC_SHIFT 16
9174 +
9175 +/* clockcontrol_sb/pci/uart */
9176 +#define CC_M1_MASK 0x3f /* m1 control */
9177 +#define CC_M2_MASK 0x3f00 /* m2 control */
9178 +#define CC_M2_SHIFT 8
9179 +#define CC_M3_MASK 0x3f0000 /* m3 control */
9180 +#define CC_M3_SHIFT 16
9181 +#define CC_MC_MASK 0x1f000000 /* mux control */
9182 +#define CC_MC_SHIFT 24
9183 +
9184 +/* N3M Clock control magic field values */
9185 +#define CC_F6_2 0x02 /* A factor of 2 in */
9186 +#define CC_F6_3 0x03 /* 6-bit fields like */
9187 +#define CC_F6_4 0x05 /* N1, M1 or M3 */
9188 +#define CC_F6_5 0x09
9189 +#define CC_F6_6 0x11
9190 +#define CC_F6_7 0x21
9191 +
9192 +#define CC_F5_BIAS 5 /* 5-bit fields get this added */
9193 +
9194 +#define CC_MC_BYPASS 0x08
9195 +#define CC_MC_M1 0x04
9196 +#define CC_MC_M1M2 0x02
9197 +#define CC_MC_M1M2M3 0x01
9198 +#define CC_MC_M1M3 0x11
9199 +
9200 +/* Type 2 Clock control magic field values */
9201 +#define CC_T2_BIAS 2 /* n1, n2, m1 & m3 bias */
9202 +#define CC_T2M2_BIAS 3 /* m2 bias */
9203 +
9204 +#define CC_T2MC_M1BYP 1
9205 +#define CC_T2MC_M2BYP 2
9206 +#define CC_T2MC_M3BYP 4
9207 +
9208 +/* Type 6 Clock control magic field values */
9209 +#define CC_T6_MMASK 1 /* bits of interest in m */
9210 +#define CC_T6_M0 120000000 /* sb clock for m = 0 */
9211 +#define CC_T6_M1 100000000 /* sb clock for m = 1 */
9212 +#define SB2MIPS_T6(sb) (2 * (sb))
9213 +
9214 +/* Common clock base */
9215 +#define CC_CLOCK_BASE1 24000000 /* Half the clock freq */
9216 +#define CC_CLOCK_BASE2 12500000 /* Alternate crystal on some PLL's */
9217 +
9218 +/* Clock control values for 200Mhz in 5350 */
9219 +#define CLKC_5350_N 0x0311
9220 +#define CLKC_5350_M 0x04020009
9221 +
9222 +/* Flash types in the chipcommon capabilities register */
9223 +#define FLASH_NONE 0x000 /* No flash */
9224 +#define SFLASH_ST 0x100 /* ST serial flash */
9225 +#define SFLASH_AT 0x200 /* Atmel serial flash */
9226 +#define PFLASH 0x700 /* Parallel flash */
9227 +
9228 +/* Bits in the config registers */
9229 +#define CC_CFG_EN 0x0001 /* Enable */
9230 +#define CC_CFG_EM_MASK 0x000e /* Extif Mode */
9231 +#define CC_CFG_EM_ASYNC 0x0002 /* Async/Parallel flash */
9232 +#define CC_CFG_EM_SYNC 0x0004 /* Synchronous */
9233 +#define CC_CFG_EM_PCMCIA 0x0008 /* PCMCIA */
9234 +#define CC_CFG_EM_IDE 0x000a /* IDE */
9235 +#define CC_CFG_DS 0x0010 /* Data size, 0=8bit, 1=16bit */
9236 +#define CC_CFG_CD_MASK 0x0060 /* Sync: Clock divisor */
9237 +#define CC_CFG_CE 0x0080 /* Sync: Clock enable */
9238 +#define CC_CFG_SB 0x0100 /* Sync: Size/Bytestrobe */
9239 +
9240 +/* Start/busy bit in flashcontrol */
9241 +#define SFLASH_START 0x80000000
9242 +#define SFLASH_BUSY SFLASH_START
9243 +
9244 +/* flashcontrol opcodes for ST flashes */
9245 +#define SFLASH_ST_WREN 0x0006 /* Write Enable */
9246 +#define SFLASH_ST_WRDIS 0x0004 /* Write Disable */
9247 +#define SFLASH_ST_RDSR 0x0105 /* Read Status Register */
9248 +#define SFLASH_ST_WRSR 0x0101 /* Write Status Register */
9249 +#define SFLASH_ST_READ 0x0303 /* Read Data Bytes */
9250 +#define SFLASH_ST_PP 0x0302 /* Page Program */
9251 +#define SFLASH_ST_SE 0x02d8 /* Sector Erase */
9252 +#define SFLASH_ST_BE 0x00c7 /* Bulk Erase */
9253 +#define SFLASH_ST_DP 0x00b9 /* Deep Power-down */
9254 +#define SFLASH_ST_RES 0x03ab /* Read Electronic Signature */
9255 +
9256 +/* Status register bits for ST flashes */
9257 +#define SFLASH_ST_WIP 0x01 /* Write In Progress */
9258 +#define SFLASH_ST_WEL 0x02 /* Write Enable Latch */
9259 +#define SFLASH_ST_BP_MASK 0x1c /* Block Protect */
9260 +#define SFLASH_ST_BP_SHIFT 2
9261 +#define SFLASH_ST_SRWD 0x80 /* Status Register Write Disable */
9262 +
9263 +/* flashcontrol opcodes for Atmel flashes */
9264 +#define SFLASH_AT_READ 0x07e8
9265 +#define SFLASH_AT_PAGE_READ 0x07d2
9266 +#define SFLASH_AT_BUF1_READ
9267 +#define SFLASH_AT_BUF2_READ
9268 +#define SFLASH_AT_STATUS 0x01d7
9269 +#define SFLASH_AT_BUF1_WRITE 0x0384
9270 +#define SFLASH_AT_BUF2_WRITE 0x0387
9271 +#define SFLASH_AT_BUF1_ERASE_PROGRAM 0x0283
9272 +#define SFLASH_AT_BUF2_ERASE_PROGRAM 0x0286
9273 +#define SFLASH_AT_BUF1_PROGRAM 0x0288
9274 +#define SFLASH_AT_BUF2_PROGRAM 0x0289
9275 +#define SFLASH_AT_PAGE_ERASE 0x0281
9276 +#define SFLASH_AT_BLOCK_ERASE 0x0250
9277 +#define SFLASH_AT_BUF1_WRITE_ERASE_PROGRAM 0x0382
9278 +#define SFLASH_AT_BUF2_WRITE_ERASE_PROGRAM 0x0385
9279 +#define SFLASH_AT_BUF1_LOAD 0x0253
9280 +#define SFLASH_AT_BUF2_LOAD 0x0255
9281 +#define SFLASH_AT_BUF1_COMPARE 0x0260
9282 +#define SFLASH_AT_BUF2_COMPARE 0x0261
9283 +#define SFLASH_AT_BUF1_REPROGRAM 0x0258
9284 +#define SFLASH_AT_BUF2_REPROGRAM 0x0259
9285 +
9286 +/* Status register bits for Atmel flashes */
9287 +#define SFLASH_AT_READY 0x80
9288 +#define SFLASH_AT_MISMATCH 0x40
9289 +#define SFLASH_AT_ID_MASK 0x38
9290 +#define SFLASH_AT_ID_SHIFT 3
9291 +
9292 +/* OTP regions */
9293 +#define OTP_HW_REGION OTPS_HW_PROTECT
9294 +#define OTP_SW_REGION OTPS_SW_PROTECT
9295 +#define OTP_CID_REGION OTPS_CID_PROTECT
9296 +
9297 +/* OTP regions (Byte offsets from otp size) */
9298 +#define OTP_SWLIM_OFF (-8)
9299 +#define OTP_CIDBASE_OFF 0
9300 +#define OTP_CIDLIM_OFF 8
9301 +
9302 +/* Predefined OTP words (Word offset from otp size) */
9303 +#define OTP_BOUNDARY_OFF (-4)
9304 +#define OTP_HWSIGN_OFF (-3)
9305 +#define OTP_SWSIGN_OFF (-2)
9306 +#define OTP_CIDSIGN_OFF (-1)
9307 +
9308 +#define OTP_CID_OFF 0
9309 +#define OTP_PKG_OFF 1
9310 +#define OTP_FID_OFF 2
9311 +#define OTP_RSV_OFF 3
9312 +#define OTP_LIM_OFF 4
9313 +
9314 +#define OTP_SIGNATURE 0x578a
9315 +#define OTP_MAGIC 0x4e56
9316 +
9317 +#endif /* _SBCHIPC_H */
9318 diff -urN linux.old/arch/mips/bcm947xx/include/sbconfig.h linux.dev/arch/mips/bcm947xx/include/sbconfig.h
9319 --- linux.old/arch/mips/bcm947xx/include/sbconfig.h 1970-01-01 01:00:00.000000000 +0100
9320 +++ linux.dev/arch/mips/bcm947xx/include/sbconfig.h 2005-12-15 15:35:24.538815250 +0100
9321 @@ -0,0 +1,342 @@
9322 +/*
9323 + * Broadcom SiliconBackplane hardware register definitions.
9324 + *
9325 + * Copyright 2005, Broadcom Corporation
9326 + * All Rights Reserved.
9327 + *
9328 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
9329 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9330 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
9331 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
9332 + * $Id$
9333 + */
9334 +
9335 +#ifndef _SBCONFIG_H
9336 +#define _SBCONFIG_H
9337 +
9338 +/* cpp contortions to concatenate w/arg prescan */
9339 +#ifndef PAD
9340 +#define _PADLINE(line) pad ## line
9341 +#define _XSTR(line) _PADLINE(line)
9342 +#define PAD _XSTR(__LINE__)
9343 +#endif
9344 +
9345 +/*
9346 + * SiliconBackplane Address Map.
9347 + * All regions may not exist on all chips.
9348 + */
9349 +#define SB_SDRAM_BASE 0x00000000 /* Physical SDRAM */
9350 +#define SB_PCI_MEM 0x08000000 /* Host Mode sb2pcitranslation0 (64 MB) */
9351 +#define SB_PCI_CFG 0x0c000000 /* Host Mode sb2pcitranslation1 (64 MB) */
9352 +#define SB_SDRAM_SWAPPED 0x10000000 /* Byteswapped Physical SDRAM */
9353 +#define SB_ENUM_BASE 0x18000000 /* Enumeration space base */
9354 +#define SB_ENUM_LIM 0x18010000 /* Enumeration space limit */
9355 +
9356 +#define SB_FLASH2 0x1c000000 /* Flash Region 2 (region 1 shadowed here) */
9357 +#define SB_FLASH2_SZ 0x02000000 /* Size of Flash Region 2 */
9358 +
9359 +#define SB_EXTIF_BASE 0x1f000000 /* External Interface region base address */
9360 +#define SB_FLASH1 0x1fc00000 /* Flash Region 1 */
9361 +#define SB_FLASH1_SZ 0x00400000 /* Size of Flash Region 1 */
9362 +
9363 +#define SB_PCI_DMA 0x40000000 /* Client Mode sb2pcitranslation2 (1 GB) */
9364 +#define SB_PCI_DMA_SZ 0x40000000 /* Client Mode sb2pcitranslation2 size in bytes */
9365 +#define SB_PCIE_DMA_L32 0x00000000 /* PCIE Client Mode sb2pcitranslation2 (2 ZettaBytes), low 32 bits */
9366 +#define SB_PCIE_DMA_H32 0x80000000 /* PCIE Client Mode sb2pcitranslation2 (2 ZettaBytes), high 32 bits */
9367 +#define SB_EUART (SB_EXTIF_BASE + 0x00800000)
9368 +#define SB_LED (SB_EXTIF_BASE + 0x00900000)
9369 +
9370 +
9371 +/* enumeration space related defs */
9372 +#define SB_CORE_SIZE 0x1000 /* each core gets 4Kbytes for registers */
9373 +#define SB_MAXCORES ((SB_ENUM_LIM - SB_ENUM_BASE)/SB_CORE_SIZE)
9374 +#define SBCONFIGOFF 0xf00 /* core sbconfig regs are top 256bytes of regs */
9375 +#define SBCONFIGSIZE 256 /* sizeof (sbconfig_t) */
9376 +
9377 +/* mips address */
9378 +#define SB_EJTAG 0xff200000 /* MIPS EJTAG space (2M) */
9379 +
9380 +/*
9381 + * Sonics Configuration Space Registers.
9382 + */
9383 +#define SBIPSFLAG 0x08
9384 +#define SBTPSFLAG 0x18
9385 +#define SBTMERRLOGA 0x48 /* sonics >= 2.3 */
9386 +#define SBTMERRLOG 0x50 /* sonics >= 2.3 */
9387 +#define SBADMATCH3 0x60
9388 +#define SBADMATCH2 0x68
9389 +#define SBADMATCH1 0x70
9390 +#define SBIMSTATE 0x90
9391 +#define SBINTVEC 0x94
9392 +#define SBTMSTATELOW 0x98
9393 +#define SBTMSTATEHIGH 0x9c
9394 +#define SBBWA0 0xa0
9395 +#define SBIMCONFIGLOW 0xa8
9396 +#define SBIMCONFIGHIGH 0xac
9397 +#define SBADMATCH0 0xb0
9398 +#define SBTMCONFIGLOW 0xb8
9399 +#define SBTMCONFIGHIGH 0xbc
9400 +#define SBBCONFIG 0xc0
9401 +#define SBBSTATE 0xc8
9402 +#define SBACTCNFG 0xd8
9403 +#define SBFLAGST 0xe8
9404 +#define SBIDLOW 0xf8
9405 +#define SBIDHIGH 0xfc
9406 +
9407 +#ifndef _LANGUAGE_ASSEMBLY
9408 +
9409 +typedef volatile struct _sbconfig {
9410 + uint32 PAD[2];
9411 + uint32 sbipsflag; /* initiator port ocp slave flag */
9412 + uint32 PAD[3];
9413 + uint32 sbtpsflag; /* target port ocp slave flag */
9414 + uint32 PAD[11];
9415 + uint32 sbtmerrloga; /* (sonics >= 2.3) */
9416 + uint32 PAD;
9417 + uint32 sbtmerrlog; /* (sonics >= 2.3) */
9418 + uint32 PAD[3];
9419 + uint32 sbadmatch3; /* address match3 */
9420 + uint32 PAD;
9421 + uint32 sbadmatch2; /* address match2 */
9422 + uint32 PAD;
9423 + uint32 sbadmatch1; /* address match1 */
9424 + uint32 PAD[7];
9425 + uint32 sbimstate; /* initiator agent state */
9426 + uint32 sbintvec; /* interrupt mask */
9427 + uint32 sbtmstatelow; /* target state */
9428 + uint32 sbtmstatehigh; /* target state */
9429 + uint32 sbbwa0; /* bandwidth allocation table0 */
9430 + uint32 PAD;
9431 + uint32 sbimconfiglow; /* initiator configuration */
9432 + uint32 sbimconfighigh; /* initiator configuration */
9433 + uint32 sbadmatch0; /* address match0 */
9434 + uint32 PAD;
9435 + uint32 sbtmconfiglow; /* target configuration */
9436 + uint32 sbtmconfighigh; /* target configuration */
9437 + uint32 sbbconfig; /* broadcast configuration */
9438 + uint32 PAD;
9439 + uint32 sbbstate; /* broadcast state */
9440 + uint32 PAD[3];
9441 + uint32 sbactcnfg; /* activate configuration */
9442 + uint32 PAD[3];
9443 + uint32 sbflagst; /* current sbflags */
9444 + uint32 PAD[3];
9445 + uint32 sbidlow; /* identification */
9446 + uint32 sbidhigh; /* identification */
9447 +} sbconfig_t;
9448 +
9449 +#endif /* _LANGUAGE_ASSEMBLY */
9450 +
9451 +/* sbipsflag */
9452 +#define SBIPS_INT1_MASK 0x3f /* which sbflags get routed to mips interrupt 1 */
9453 +#define SBIPS_INT1_SHIFT 0
9454 +#define SBIPS_INT2_MASK 0x3f00 /* which sbflags get routed to mips interrupt 2 */
9455 +#define SBIPS_INT2_SHIFT 8
9456 +#define SBIPS_INT3_MASK 0x3f0000 /* which sbflags get routed to mips interrupt 3 */
9457 +#define SBIPS_INT3_SHIFT 16
9458 +#define SBIPS_INT4_MASK 0x3f000000 /* which sbflags get routed to mips interrupt 4 */
9459 +#define SBIPS_INT4_SHIFT 24
9460 +
9461 +/* sbtpsflag */
9462 +#define SBTPS_NUM0_MASK 0x3f /* interrupt sbFlag # generated by this core */
9463 +#define SBTPS_F0EN0 0x40 /* interrupt is always sent on the backplane */
9464 +
9465 +/* sbtmerrlog */
9466 +#define SBTMEL_CM 0x00000007 /* command */
9467 +#define SBTMEL_CI 0x0000ff00 /* connection id */
9468 +#define SBTMEL_EC 0x0f000000 /* error code */
9469 +#define SBTMEL_ME 0x80000000 /* multiple error */
9470 +
9471 +/* sbimstate */
9472 +#define SBIM_PC 0xf /* pipecount */
9473 +#define SBIM_AP_MASK 0x30 /* arbitration policy */
9474 +#define SBIM_AP_BOTH 0x00 /* use both timeslaces and token */
9475 +#define SBIM_AP_TS 0x10 /* use timesliaces only */
9476 +#define SBIM_AP_TK 0x20 /* use token only */
9477 +#define SBIM_AP_RSV 0x30 /* reserved */
9478 +#define SBIM_IBE 0x20000 /* inbanderror */
9479 +#define SBIM_TO 0x40000 /* timeout */
9480 +#define SBIM_BY 0x01800000 /* busy (sonics >= 2.3) */
9481 +#define SBIM_RJ 0x02000000 /* reject (sonics >= 2.3) */
9482 +
9483 +/* sbtmstatelow */
9484 +#define SBTML_RESET 0x1 /* reset */
9485 +#define SBTML_REJ_MASK 0x6 /* reject */
9486 +#define SBTML_REJ_SHIFT 1
9487 +#define SBTML_CLK 0x10000 /* clock enable */
9488 +#define SBTML_FGC 0x20000 /* force gated clocks on */
9489 +#define SBTML_FL_MASK 0x3ffc0000 /* core-specific flags */
9490 +#define SBTML_PE 0x40000000 /* pme enable */
9491 +#define SBTML_BE 0x80000000 /* bist enable */
9492 +
9493 +/* sbtmstatehigh */
9494 +#define SBTMH_SERR 0x1 /* serror */
9495 +#define SBTMH_INT 0x2 /* interrupt */
9496 +#define SBTMH_BUSY 0x4 /* busy */
9497 +#define SBTMH_TO 0x00000020 /* timeout (sonics >= 2.3) */
9498 +#define SBTMH_FL_MASK 0x1fff0000 /* core-specific flags */
9499 +#define SBTMH_DMA64 0x10000000 /* supports DMA with 64-bit addresses */
9500 +#define SBTMH_GCR 0x20000000 /* gated clock request */
9501 +#define SBTMH_BISTF 0x40000000 /* bist failed */
9502 +#define SBTMH_BISTD 0x80000000 /* bist done */
9503 +
9504 +
9505 +/* sbbwa0 */
9506 +#define SBBWA_TAB0_MASK 0xffff /* lookup table 0 */
9507 +#define SBBWA_TAB1_MASK 0xffff /* lookup table 1 */
9508 +#define SBBWA_TAB1_SHIFT 16
9509 +
9510 +/* sbimconfiglow */
9511 +#define SBIMCL_STO_MASK 0x7 /* service timeout */
9512 +#define SBIMCL_RTO_MASK 0x70 /* request timeout */
9513 +#define SBIMCL_RTO_SHIFT 4
9514 +#define SBIMCL_CID_MASK 0xff0000 /* connection id */
9515 +#define SBIMCL_CID_SHIFT 16
9516 +
9517 +/* sbimconfighigh */
9518 +#define SBIMCH_IEM_MASK 0xc /* inband error mode */
9519 +#define SBIMCH_TEM_MASK 0x30 /* timeout error mode */
9520 +#define SBIMCH_TEM_SHIFT 4
9521 +#define SBIMCH_BEM_MASK 0xc0 /* bus error mode */
9522 +#define SBIMCH_BEM_SHIFT 6
9523 +
9524 +/* sbadmatch0 */
9525 +#define SBAM_TYPE_MASK 0x3 /* address type */
9526 +#define SBAM_AD64 0x4 /* reserved */
9527 +#define SBAM_ADINT0_MASK 0xf8 /* type0 size */
9528 +#define SBAM_ADINT0_SHIFT 3
9529 +#define SBAM_ADINT1_MASK 0x1f8 /* type1 size */
9530 +#define SBAM_ADINT1_SHIFT 3
9531 +#define SBAM_ADINT2_MASK 0x1f8 /* type2 size */
9532 +#define SBAM_ADINT2_SHIFT 3
9533 +#define SBAM_ADEN 0x400 /* enable */
9534 +#define SBAM_ADNEG 0x800 /* negative decode */
9535 +#define SBAM_BASE0_MASK 0xffffff00 /* type0 base address */
9536 +#define SBAM_BASE0_SHIFT 8
9537 +#define SBAM_BASE1_MASK 0xfffff000 /* type1 base address for the core */
9538 +#define SBAM_BASE1_SHIFT 12
9539 +#define SBAM_BASE2_MASK 0xffff0000 /* type2 base address for the core */
9540 +#define SBAM_BASE2_SHIFT 16
9541 +
9542 +/* sbtmconfiglow */
9543 +#define SBTMCL_CD_MASK 0xff /* clock divide */
9544 +#define SBTMCL_CO_MASK 0xf800 /* clock offset */
9545 +#define SBTMCL_CO_SHIFT 11
9546 +#define SBTMCL_IF_MASK 0xfc0000 /* interrupt flags */
9547 +#define SBTMCL_IF_SHIFT 18
9548 +#define SBTMCL_IM_MASK 0x3000000 /* interrupt mode */
9549 +#define SBTMCL_IM_SHIFT 24
9550 +
9551 +/* sbtmconfighigh */
9552 +#define SBTMCH_BM_MASK 0x3 /* busy mode */
9553 +#define SBTMCH_RM_MASK 0x3 /* retry mode */
9554 +#define SBTMCH_RM_SHIFT 2
9555 +#define SBTMCH_SM_MASK 0x30 /* stop mode */
9556 +#define SBTMCH_SM_SHIFT 4
9557 +#define SBTMCH_EM_MASK 0x300 /* sb error mode */
9558 +#define SBTMCH_EM_SHIFT 8
9559 +#define SBTMCH_IM_MASK 0xc00 /* int mode */
9560 +#define SBTMCH_IM_SHIFT 10
9561 +
9562 +/* sbbconfig */
9563 +#define SBBC_LAT_MASK 0x3 /* sb latency */
9564 +#define SBBC_MAX0_MASK 0xf0000 /* maxccntr0 */
9565 +#define SBBC_MAX0_SHIFT 16
9566 +#define SBBC_MAX1_MASK 0xf00000 /* maxccntr1 */
9567 +#define SBBC_MAX1_SHIFT 20
9568 +
9569 +/* sbbstate */
9570 +#define SBBS_SRD 0x1 /* st reg disable */
9571 +#define SBBS_HRD 0x2 /* hold reg disable */
9572 +
9573 +/* sbidlow */
9574 +#define SBIDL_CS_MASK 0x3 /* config space */
9575 +#define SBIDL_AR_MASK 0x38 /* # address ranges supported */
9576 +#define SBIDL_AR_SHIFT 3
9577 +#define SBIDL_SYNCH 0x40 /* sync */
9578 +#define SBIDL_INIT 0x80 /* initiator */
9579 +#define SBIDL_MINLAT_MASK 0xf00 /* minimum backplane latency */
9580 +#define SBIDL_MINLAT_SHIFT 8
9581 +#define SBIDL_MAXLAT 0xf000 /* maximum backplane latency */
9582 +#define SBIDL_MAXLAT_SHIFT 12
9583 +#define SBIDL_FIRST 0x10000 /* this initiator is first */
9584 +#define SBIDL_CW_MASK 0xc0000 /* cycle counter width */
9585 +#define SBIDL_CW_SHIFT 18
9586 +#define SBIDL_TP_MASK 0xf00000 /* target ports */
9587 +#define SBIDL_TP_SHIFT 20
9588 +#define SBIDL_IP_MASK 0xf000000 /* initiator ports */
9589 +#define SBIDL_IP_SHIFT 24
9590 +#define SBIDL_RV_MASK 0xf0000000 /* sonics backplane revision code */
9591 +#define SBIDL_RV_SHIFT 28
9592 +#define SBIDL_RV_2_2 0x00000000 /* version 2.2 or earlier */
9593 +#define SBIDL_RV_2_3 0x10000000 /* version 2.3 */
9594 +
9595 +/* sbidhigh */
9596 +#define SBIDH_RC_MASK 0x000f /* revision code */
9597 +#define SBIDH_RCE_MASK 0x7000 /* revision code extension field */
9598 +#define SBIDH_RCE_SHIFT 8
9599 +#define SBCOREREV(sbidh) \
9600 + ((((sbidh) & SBIDH_RCE_MASK) >> SBIDH_RCE_SHIFT) | ((sbidh) & SBIDH_RC_MASK))
9601 +#define SBIDH_CC_MASK 0x8ff0 /* core code */
9602 +#define SBIDH_CC_SHIFT 4
9603 +#define SBIDH_VC_MASK 0xffff0000 /* vendor code */
9604 +#define SBIDH_VC_SHIFT 16
9605 +
9606 +#define SB_COMMIT 0xfd8 /* update buffered registers value */
9607 +
9608 +/* vendor codes */
9609 +#define SB_VEND_BCM 0x4243 /* Broadcom's SB vendor code */
9610 +
9611 +/* core codes */
9612 +#define SB_CC 0x800 /* chipcommon core */
9613 +#define SB_ILINE20 0x801 /* iline20 core */
9614 +#define SB_SDRAM 0x803 /* sdram core */
9615 +#define SB_PCI 0x804 /* pci core */
9616 +#define SB_MIPS 0x805 /* mips core */
9617 +#define SB_ENET 0x806 /* enet mac core */
9618 +#define SB_CODEC 0x807 /* v90 codec core */
9619 +#define SB_USB 0x808 /* usb 1.1 host/device core */
9620 +#define SB_ADSL 0x809 /* ADSL core */
9621 +#define SB_ILINE100 0x80a /* iline100 core */
9622 +#define SB_IPSEC 0x80b /* ipsec core */
9623 +#define SB_PCMCIA 0x80d /* pcmcia core */
9624 +#define SB_SOCRAM 0x80e /* internal memory core */
9625 +#define SB_MEMC 0x80f /* memc sdram core */
9626 +#define SB_EXTIF 0x811 /* external interface core */
9627 +#define SB_D11 0x812 /* 802.11 MAC core */
9628 +#define SB_MIPS33 0x816 /* mips3302 core */
9629 +#define SB_USB11H 0x817 /* usb 1.1 host core */
9630 +#define SB_USB11D 0x818 /* usb 1.1 device core */
9631 +#define SB_USB20H 0x819 /* usb 2.0 host core */
9632 +#define SB_USB20D 0x81a /* usb 2.0 device core */
9633 +#define SB_SDIOH 0x81b /* sdio host core */
9634 +#define SB_ROBO 0x81c /* roboswitch core */
9635 +#define SB_ATA100 0x81d /* parallel ATA core */
9636 +#define SB_SATAXOR 0x81e /* serial ATA & XOR DMA core */
9637 +#define SB_GIGETH 0x81f /* gigabit ethernet core */
9638 +#define SB_PCIE 0x820 /* pci express core */
9639 +#define SB_SRAMC 0x822 /* SRAM controller core */
9640 +#define SB_MINIMAC 0x823 /* MINI MAC/phy core */
9641 +
9642 +#define SB_CC_IDX 0 /* chipc, when present, is always core 0 */
9643 +
9644 +/* Not really related to Silicon Backplane, but a couple of software
9645 + * conventions for the use the flash space:
9646 + */
9647 +
9648 +/* Minumum amount of flash we support */
9649 +#define FLASH_MIN 0x00020000 /* Minimum flash size */
9650 +
9651 +/* A boot/binary may have an embedded block that describes its size */
9652 +#define BISZ_OFFSET 0x3e0 /* At this offset into the binary */
9653 +#define BISZ_MAGIC 0x4249535a /* Marked with this value: 'BISZ' */
9654 +#define BISZ_MAGIC_IDX 0 /* Word 0: magic */
9655 +#define BISZ_TXTST_IDX 1 /* 1: text start */
9656 +#define BISZ_TXTEND_IDX 2 /* 2: text start */
9657 +#define BISZ_DATAST_IDX 3 /* 3: text start */
9658 +#define BISZ_DATAEND_IDX 4 /* 4: text start */
9659 +#define BISZ_BSSST_IDX 5 /* 5: text start */
9660 +#define BISZ_BSSEND_IDX 6 /* 6: text start */
9661 +#define BISZ_SIZE 7 /* descriptor size in 32-bit intergers */
9662 +
9663 +#endif /* _SBCONFIG_H */
9664 diff -urN linux.old/arch/mips/bcm947xx/include/sbextif.h linux.dev/arch/mips/bcm947xx/include/sbextif.h
9665 --- linux.old/arch/mips/bcm947xx/include/sbextif.h 1970-01-01 01:00:00.000000000 +0100
9666 +++ linux.dev/arch/mips/bcm947xx/include/sbextif.h 2005-12-15 16:48:55.651993750 +0100
9667 @@ -0,0 +1,242 @@
9668 +/*
9669 + * Hardware-specific External Interface I/O core definitions
9670 + * for the BCM47xx family of SiliconBackplane-based chips.
9671 + *
9672 + * The External Interface core supports a total of three external chip selects
9673 + * supporting external interfaces. One of the external chip selects is
9674 + * used for Flash, one is used for PCMCIA, and the other may be
9675 + * programmed to support either a synchronous interface or an
9676 + * asynchronous interface. The asynchronous interface can be used to
9677 + * support external devices such as UARTs and the BCM2019 Bluetooth
9678 + * baseband processor.
9679 + * The external interface core also contains 2 on-chip 16550 UARTs, clock
9680 + * frequency control, a watchdog interrupt timer, and a GPIO interface.
9681 + *
9682 + * Copyright 2005, Broadcom Corporation
9683 + * All Rights Reserved.
9684 + *
9685 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
9686 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9687 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
9688 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
9689 + * $Id$
9690 + */
9691 +
9692 +#ifndef _SBEXTIF_H
9693 +#define _SBEXTIF_H
9694 +
9695 +/* external interface address space */
9696 +#define EXTIF_PCMCIA_MEMBASE(x) (x)
9697 +#define EXTIF_PCMCIA_IOBASE(x) ((x) + 0x100000)
9698 +#define EXTIF_PCMCIA_CFGBASE(x) ((x) + 0x200000)
9699 +#define EXTIF_CFGIF_BASE(x) ((x) + 0x800000)
9700 +#define EXTIF_FLASH_BASE(x) ((x) + 0xc00000)
9701 +
9702 +/* cpp contortions to concatenate w/arg prescan */
9703 +#ifndef PAD
9704 +#define _PADLINE(line) pad ## line
9705 +#define _XSTR(line) _PADLINE(line)
9706 +#define PAD _XSTR(__LINE__)
9707 +#endif /* PAD */
9708 +
9709 +/*
9710 + * The multiple instances of output and output enable registers
9711 + * are present to allow driver software for multiple cores to control
9712 + * gpio outputs without needing to share a single register pair.
9713 + */
9714 +struct gpiouser {
9715 + uint32 out;
9716 + uint32 outen;
9717 +};
9718 +#define NGPIOUSER 5
9719 +
9720 +typedef volatile struct {
9721 + uint32 corecontrol;
9722 + uint32 extstatus;
9723 + uint32 PAD[2];
9724 +
9725 + /* pcmcia control registers */
9726 + uint32 pcmcia_config;
9727 + uint32 pcmcia_memwait;
9728 + uint32 pcmcia_attrwait;
9729 + uint32 pcmcia_iowait;
9730 +
9731 + /* programmable interface control registers */
9732 + uint32 prog_config;
9733 + uint32 prog_waitcount;
9734 +
9735 + /* flash control registers */
9736 + uint32 flash_config;
9737 + uint32 flash_waitcount;
9738 + uint32 PAD[4];
9739 +
9740 + uint32 watchdog;
9741 +
9742 + /* clock control */
9743 + uint32 clockcontrol_n;
9744 + uint32 clockcontrol_sb;
9745 + uint32 clockcontrol_pci;
9746 + uint32 clockcontrol_mii;
9747 + uint32 PAD[3];
9748 +
9749 + /* gpio */
9750 + uint32 gpioin;
9751 + struct gpiouser gpio[NGPIOUSER];
9752 + uint32 PAD;
9753 + uint32 ejtagouten;
9754 + uint32 gpiointpolarity;
9755 + uint32 gpiointmask;
9756 + uint32 PAD[153];
9757 +
9758 + uint8 uartdata;
9759 + uint8 PAD[3];
9760 + uint8 uartimer;
9761 + uint8 PAD[3];
9762 + uint8 uartfcr;
9763 + uint8 PAD[3];
9764 + uint8 uartlcr;
9765 + uint8 PAD[3];
9766 + uint8 uartmcr;
9767 + uint8 PAD[3];
9768 + uint8 uartlsr;
9769 + uint8 PAD[3];
9770 + uint8 uartmsr;
9771 + uint8 PAD[3];
9772 + uint8 uartscratch;
9773 + uint8 PAD[3];
9774 +} extifregs_t;
9775 +
9776 +/* corecontrol */
9777 +#define CC_UE (1 << 0) /* uart enable */
9778 +
9779 +/* extstatus */
9780 +#define ES_EM (1 << 0) /* endian mode (ro) */
9781 +#define ES_EI (1 << 1) /* external interrupt pin (ro) */
9782 +#define ES_GI (1 << 2) /* gpio interrupt pin (ro) */
9783 +
9784 +/* gpio bit mask */
9785 +#define GPIO_BIT0 (1 << 0)
9786 +#define GPIO_BIT1 (1 << 1)
9787 +#define GPIO_BIT2 (1 << 2)
9788 +#define GPIO_BIT3 (1 << 3)
9789 +#define GPIO_BIT4 (1 << 4)
9790 +#define GPIO_BIT5 (1 << 5)
9791 +#define GPIO_BIT6 (1 << 6)
9792 +#define GPIO_BIT7 (1 << 7)
9793 +
9794 +
9795 +/* pcmcia/prog/flash_config */
9796 +#define CF_EN (1 << 0) /* enable */
9797 +#define CF_EM_MASK 0xe /* mode */
9798 +#define CF_EM_SHIFT 1
9799 +#define CF_EM_FLASH 0x0 /* flash/asynchronous mode */
9800 +#define CF_EM_SYNC 0x2 /* synchronous mode */
9801 +#define CF_EM_PCMCIA 0x4 /* pcmcia mode */
9802 +#define CF_DS (1 << 4) /* destsize: 0=8bit, 1=16bit */
9803 +#define CF_BS (1 << 5) /* byteswap */
9804 +#define CF_CD_MASK 0xc0 /* clock divider */
9805 +#define CF_CD_SHIFT 6
9806 +#define CF_CD_DIV2 0x0 /* backplane/2 */
9807 +#define CF_CD_DIV3 0x40 /* backplane/3 */
9808 +#define CF_CD_DIV4 0x80 /* backplane/4 */
9809 +#define CF_CE (1 << 8) /* clock enable */
9810 +#define CF_SB (1 << 9) /* size/bytestrobe (synch only) */
9811 +
9812 +/* pcmcia_memwait */
9813 +#define PM_W0_MASK 0x3f /* waitcount0 */
9814 +#define PM_W1_MASK 0x1f00 /* waitcount1 */
9815 +#define PM_W1_SHIFT 8
9816 +#define PM_W2_MASK 0x1f0000 /* waitcount2 */
9817 +#define PM_W2_SHIFT 16
9818 +#define PM_W3_MASK 0x1f000000 /* waitcount3 */
9819 +#define PM_W3_SHIFT 24
9820 +
9821 +/* pcmcia_attrwait */
9822 +#define PA_W0_MASK 0x3f /* waitcount0 */
9823 +#define PA_W1_MASK 0x1f00 /* waitcount1 */
9824 +#define PA_W1_SHIFT 8
9825 +#define PA_W2_MASK 0x1f0000 /* waitcount2 */
9826 +#define PA_W2_SHIFT 16
9827 +#define PA_W3_MASK 0x1f000000 /* waitcount3 */
9828 +#define PA_W3_SHIFT 24
9829 +
9830 +/* pcmcia_iowait */
9831 +#define PI_W0_MASK 0x3f /* waitcount0 */
9832 +#define PI_W1_MASK 0x1f00 /* waitcount1 */
9833 +#define PI_W1_SHIFT 8
9834 +#define PI_W2_MASK 0x1f0000 /* waitcount2 */
9835 +#define PI_W2_SHIFT 16
9836 +#define PI_W3_MASK 0x1f000000 /* waitcount3 */
9837 +#define PI_W3_SHIFT 24
9838 +
9839 +/* prog_waitcount */
9840 +#define PW_W0_MASK 0x0000001f /* waitcount0 */
9841 +#define PW_W1_MASK 0x00001f00 /* waitcount1 */
9842 +#define PW_W1_SHIFT 8
9843 +#define PW_W2_MASK 0x001f0000 /* waitcount2 */
9844 +#define PW_W2_SHIFT 16
9845 +#define PW_W3_MASK 0x1f000000 /* waitcount3 */
9846 +#define PW_W3_SHIFT 24
9847 +
9848 +#define PW_W0 0x0000000c
9849 +#define PW_W1 0x00000a00
9850 +#define PW_W2 0x00020000
9851 +#define PW_W3 0x01000000
9852 +
9853 +/* flash_waitcount */
9854 +#define FW_W0_MASK 0x1f /* waitcount0 */
9855 +#define FW_W1_MASK 0x1f00 /* waitcount1 */
9856 +#define FW_W1_SHIFT 8
9857 +#define FW_W2_MASK 0x1f0000 /* waitcount2 */
9858 +#define FW_W2_SHIFT 16
9859 +#define FW_W3_MASK 0x1f000000 /* waitcount3 */
9860 +#define FW_W3_SHIFT 24
9861 +
9862 +/* watchdog */
9863 +#define WATCHDOG_CLOCK 48000000 /* Hz */
9864 +
9865 +/* clockcontrol_n */
9866 +#define CN_N1_MASK 0x3f /* n1 control */
9867 +#define CN_N2_MASK 0x3f00 /* n2 control */
9868 +#define CN_N2_SHIFT 8
9869 +
9870 +/* clockcontrol_sb/pci/mii */
9871 +#define CC_M1_MASK 0x3f /* m1 control */
9872 +#define CC_M2_MASK 0x3f00 /* m2 control */
9873 +#define CC_M2_SHIFT 8
9874 +#define CC_M3_MASK 0x3f0000 /* m3 control */
9875 +#define CC_M3_SHIFT 16
9876 +#define CC_MC_MASK 0x1f000000 /* mux control */
9877 +#define CC_MC_SHIFT 24
9878 +
9879 +/* Clock control default values */
9880 +#define CC_DEF_N 0x0009 /* Default values for bcm4710 */
9881 +#define CC_DEF_100 0x04020011
9882 +#define CC_DEF_33 0x11030011
9883 +#define CC_DEF_25 0x11050011
9884 +
9885 +/* Clock control values for 125Mhz */
9886 +#define CC_125_N 0x0802
9887 +#define CC_125_M 0x04020009
9888 +#define CC_125_M25 0x11090009
9889 +#define CC_125_M33 0x11090005
9890 +
9891 +/* Clock control magic field values */
9892 +#define CC_F6_2 0x02 /* A factor of 2 in */
9893 +#define CC_F6_3 0x03 /* 6-bit fields like */
9894 +#define CC_F6_4 0x05 /* N1, M1 or M3 */
9895 +#define CC_F6_5 0x09
9896 +#define CC_F6_6 0x11
9897 +#define CC_F6_7 0x21
9898 +
9899 +#define CC_F5_BIAS 5 /* 5-bit fields get this added */
9900 +
9901 +#define CC_MC_BYPASS 0x08
9902 +#define CC_MC_M1 0x04
9903 +#define CC_MC_M1M2 0x02
9904 +#define CC_MC_M1M2M3 0x01
9905 +#define CC_MC_M1M3 0x11
9906 +
9907 +#define CC_CLOCK_BASE 24000000 /* Half the clock freq. in the 4710 */
9908 +
9909 +#endif /* _SBEXTIF_H */
9910 diff -urN linux.old/arch/mips/bcm947xx/include/sbmemc.h linux.dev/arch/mips/bcm947xx/include/sbmemc.h
9911 --- linux.old/arch/mips/bcm947xx/include/sbmemc.h 1970-01-01 01:00:00.000000000 +0100
9912 +++ linux.dev/arch/mips/bcm947xx/include/sbmemc.h 2005-12-15 15:35:31.567254500 +0100
9913 @@ -0,0 +1,148 @@
9914 +/*
9915 + * BCM47XX Sonics SiliconBackplane DDR/SDRAM controller core hardware definitions.
9916 + *
9917 + * Copyright 2005, Broadcom Corporation
9918 + * All Rights Reserved.
9919 + *
9920 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
9921 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9922 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
9923 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
9924 + *
9925 + * $Id$
9926 + */
9927 +
9928 +#ifndef _SBMEMC_H
9929 +#define _SBMEMC_H
9930 +
9931 +#ifdef _LANGUAGE_ASSEMBLY
9932 +
9933 +#define MEMC_CONTROL 0x00
9934 +#define MEMC_CONFIG 0x04
9935 +#define MEMC_REFRESH 0x08
9936 +#define MEMC_BISTSTAT 0x0c
9937 +#define MEMC_MODEBUF 0x10
9938 +#define MEMC_BKCLS 0x14
9939 +#define MEMC_PRIORINV 0x18
9940 +#define MEMC_DRAMTIM 0x1c
9941 +#define MEMC_INTSTAT 0x20
9942 +#define MEMC_INTMASK 0x24
9943 +#define MEMC_INTINFO 0x28
9944 +#define MEMC_NCDLCTL 0x30
9945 +#define MEMC_RDNCDLCOR 0x34
9946 +#define MEMC_WRNCDLCOR 0x38
9947 +#define MEMC_MISCDLYCTL 0x3c
9948 +#define MEMC_DQSGATENCDL 0x40
9949 +#define MEMC_SPARE 0x44
9950 +#define MEMC_TPADDR 0x48
9951 +#define MEMC_TPDATA 0x4c
9952 +#define MEMC_BARRIER 0x50
9953 +#define MEMC_CORE 0x54
9954 +
9955 +
9956 +#else
9957 +
9958 +/* Sonics side: MEMC core registers */
9959 +typedef volatile struct sbmemcregs {
9960 + uint32 control;
9961 + uint32 config;
9962 + uint32 refresh;
9963 + uint32 biststat;
9964 + uint32 modebuf;
9965 + uint32 bkcls;
9966 + uint32 priorinv;
9967 + uint32 dramtim;
9968 + uint32 intstat;
9969 + uint32 intmask;
9970 + uint32 intinfo;
9971 + uint32 reserved1;
9972 + uint32 ncdlctl;
9973 + uint32 rdncdlcor;
9974 + uint32 wrncdlcor;
9975 + uint32 miscdlyctl;
9976 + uint32 dqsgatencdl;
9977 + uint32 spare;
9978 + uint32 tpaddr;
9979 + uint32 tpdata;
9980 + uint32 barrier;
9981 + uint32 core;
9982 +} sbmemcregs_t;
9983 +
9984 +#endif
9985 +
9986 +/* MEMC Core Init values (OCP ID 0x80f) */
9987 +
9988 +/* For sdr: */
9989 +#define MEMC_SD_CONFIG_INIT 0x00048000
9990 +#define MEMC_SD_DRAMTIM2_INIT 0x000754d8
9991 +#define MEMC_SD_DRAMTIM3_INIT 0x000754da
9992 +#define MEMC_SD_RDNCDLCOR_INIT 0x00000000
9993 +#define MEMC_SD_WRNCDLCOR_INIT 0x49351200
9994 +#define MEMC_SD1_WRNCDLCOR_INIT 0x14500200 /* For corerev 1 (4712) */
9995 +#define MEMC_SD_MISCDLYCTL_INIT 0x00061c1b
9996 +#define MEMC_SD1_MISCDLYCTL_INIT 0x00021416 /* For corerev 1 (4712) */
9997 +#define MEMC_SD_CONTROL_INIT0 0x00000002
9998 +#define MEMC_SD_CONTROL_INIT1 0x00000008
9999 +#define MEMC_SD_CONTROL_INIT2 0x00000004
10000 +#define MEMC_SD_CONTROL_INIT3 0x00000010
10001 +#define MEMC_SD_CONTROL_INIT4 0x00000001
10002 +#define MEMC_SD_MODEBUF_INIT 0x00000000
10003 +#define MEMC_SD_REFRESH_INIT 0x0000840f
10004 +
10005 +
10006 +/* This is for SDRM8X8X4 */
10007 +#define MEMC_SDR_INIT 0x0008
10008 +#define MEMC_SDR_MODE 0x32
10009 +#define MEMC_SDR_NCDL 0x00020032
10010 +#define MEMC_SDR1_NCDL 0x0002020f /* For corerev 1 (4712) */
10011 +
10012 +/* For ddr: */
10013 +#define MEMC_CONFIG_INIT 0x00048000
10014 +#define MEMC_DRAMTIM2_INIT 0x000754d8
10015 +#define MEMC_DRAMTIM25_INIT 0x000754d9
10016 +#define MEMC_RDNCDLCOR_INIT 0x00000000
10017 +#define MEMC_RDNCDLCOR_SIMINIT 0xf6f6f6f6 /* For hdl sim */
10018 +#define MEMC_WRNCDLCOR_INIT 0x49351200
10019 +#define MEMC_1_WRNCDLCOR_INIT 0x14500200
10020 +#define MEMC_DQSGATENCDL_INIT 0x00030000
10021 +#define MEMC_MISCDLYCTL_INIT 0x21061c1b
10022 +#define MEMC_1_MISCDLYCTL_INIT 0x21021400
10023 +#define MEMC_NCDLCTL_INIT 0x00002001
10024 +#define MEMC_CONTROL_INIT0 0x00000002
10025 +#define MEMC_CONTROL_INIT1 0x00000008
10026 +#define MEMC_MODEBUF_INIT0 0x00004000
10027 +#define MEMC_CONTROL_INIT2 0x00000010
10028 +#define MEMC_MODEBUF_INIT1 0x00000100
10029 +#define MEMC_CONTROL_INIT3 0x00000010
10030 +#define MEMC_CONTROL_INIT4 0x00000008
10031 +#define MEMC_REFRESH_INIT 0x0000840f
10032 +#define MEMC_CONTROL_INIT5 0x00000004
10033 +#define MEMC_MODEBUF_INIT2 0x00000000
10034 +#define MEMC_CONTROL_INIT6 0x00000010
10035 +#define MEMC_CONTROL_INIT7 0x00000001
10036 +
10037 +
10038 +/* This is for DDRM16X16X2 */
10039 +#define MEMC_DDR_INIT 0x0009
10040 +#define MEMC_DDR_MODE 0x62
10041 +#define MEMC_DDR_NCDL 0x0005050a
10042 +#define MEMC_DDR1_NCDL 0x00000a0a /* For corerev 1 (4712) */
10043 +
10044 +/* mask for sdr/ddr calibration registers */
10045 +#define MEMC_RDNCDLCOR_RD_MASK 0x000000ff
10046 +#define MEMC_WRNCDLCOR_WR_MASK 0x000000ff
10047 +#define MEMC_DQSGATENCDL_G_MASK 0x000000ff
10048 +
10049 +/* masks for miscdlyctl registers */
10050 +#define MEMC_MISC_SM_MASK 0x30000000
10051 +#define MEMC_MISC_SM_SHIFT 28
10052 +#define MEMC_MISC_SD_MASK 0x0f000000
10053 +#define MEMC_MISC_SD_SHIFT 24
10054 +
10055 +/* hw threshhold for calculating wr/rd for sdr memc */
10056 +#define MEMC_CD_THRESHOLD 128
10057 +
10058 +/* Low bit of init register says if memc is ddr or sdr */
10059 +#define MEMC_CONFIG_DDR 0x00000001
10060 +
10061 +#endif /* _SBMEMC_H */
10062 diff -urN linux.old/arch/mips/bcm947xx/include/sbmips.h linux.dev/arch/mips/bcm947xx/include/sbmips.h
10063 --- linux.old/arch/mips/bcm947xx/include/sbmips.h 1970-01-01 01:00:00.000000000 +0100
10064 +++ linux.dev/arch/mips/bcm947xx/include/sbmips.h 2005-12-15 16:46:57.616617000 +0100
10065 @@ -0,0 +1,62 @@
10066 +/*
10067 + * Broadcom SiliconBackplane MIPS definitions
10068 + *
10069 + * SB MIPS cores are custom MIPS32 processors with SiliconBackplane
10070 + * OCP interfaces. The CP0 processor ID is 0x00024000, where bits
10071 + * 23:16 mean Broadcom and bits 15:8 mean a MIPS core with an OCP
10072 + * interface. The core revision is stored in the SB ID register in SB
10073 + * configuration space.
10074 + *
10075 + * Copyright 2005, Broadcom Corporation
10076 + * All Rights Reserved.
10077 + *
10078 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
10079 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
10080 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10081 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
10082 + *
10083 + * $Id$
10084 + */
10085 +
10086 +#ifndef _SBMIPS_H
10087 +#define _SBMIPS_H
10088 +
10089 +#include <mipsinc.h>
10090 +
10091 +#ifndef _LANGUAGE_ASSEMBLY
10092 +
10093 +/* cpp contortions to concatenate w/arg prescan */
10094 +#ifndef PAD
10095 +#define _PADLINE(line) pad ## line
10096 +#define _XSTR(line) _PADLINE(line)
10097 +#define PAD _XSTR(__LINE__)
10098 +#endif /* PAD */
10099 +
10100 +typedef volatile struct {
10101 + uint32 corecontrol;
10102 + uint32 PAD[2];
10103 + uint32 biststatus;
10104 + uint32 PAD[4];
10105 + uint32 intstatus;
10106 + uint32 intmask;
10107 + uint32 timer;
10108 +} mipsregs_t;
10109 +
10110 +extern uint32 sb_flag(sb_t *sbh);
10111 +extern uint sb_irq(sb_t *sbh);
10112 +
10113 +extern void BCMINIT(sb_serial_init)(sb_t *sbh, void (*add)(void *regs, uint irq, uint baud_base, uint reg_shift));
10114 +
10115 +extern void *sb_jtagm_init(sb_t *sbh, uint clkd, bool exttap);
10116 +extern void sb_jtagm_disable(void *h);
10117 +extern uint32 jtag_rwreg(void *h, uint32 ir, uint32 dr);
10118 +extern void BCMINIT(sb_mips_init)(sb_t *sbh);
10119 +extern uint32 BCMINIT(sb_mips_clock)(sb_t *sbh);
10120 +extern bool BCMINIT(sb_mips_setclock)(sb_t *sbh, uint32 mipsclock, uint32 sbclock, uint32 pciclock);
10121 +extern void BCMINIT(enable_pfc)(uint32 mode);
10122 +extern uint32 BCMINIT(sb_memc_get_ncdl)(sb_t *sbh);
10123 +
10124 +
10125 +#endif /* _LANGUAGE_ASSEMBLY */
10126 +
10127 +#endif /* _SBMIPS_H */
10128 diff -urN linux.old/arch/mips/bcm947xx/include/sbpci.h linux.dev/arch/mips/bcm947xx/include/sbpci.h
10129 --- linux.old/arch/mips/bcm947xx/include/sbpci.h 1970-01-01 01:00:00.000000000 +0100
10130 +++ linux.dev/arch/mips/bcm947xx/include/sbpci.h 2005-12-15 15:35:36.795581250 +0100
10131 @@ -0,0 +1,122 @@
10132 +/*
10133 + * BCM47XX Sonics SiliconBackplane PCI core hardware definitions.
10134 + *
10135 + * $Id$
10136 + * Copyright 2005, Broadcom Corporation
10137 + * All Rights Reserved.
10138 + *
10139 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
10140 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
10141 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10142 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
10143 + */
10144 +
10145 +#ifndef _SBPCI_H
10146 +#define _SBPCI_H
10147 +
10148 +/* cpp contortions to concatenate w/arg prescan */
10149 +#ifndef PAD
10150 +#define _PADLINE(line) pad ## line
10151 +#define _XSTR(line) _PADLINE(line)
10152 +#define PAD _XSTR(__LINE__)
10153 +#endif
10154 +
10155 +/* Sonics side: PCI core and host control registers */
10156 +typedef struct sbpciregs {
10157 + uint32 control; /* PCI control */
10158 + uint32 PAD[3];
10159 + uint32 arbcontrol; /* PCI arbiter control */
10160 + uint32 PAD[3];
10161 + uint32 intstatus; /* Interrupt status */
10162 + uint32 intmask; /* Interrupt mask */
10163 + uint32 sbtopcimailbox; /* Sonics to PCI mailbox */
10164 + uint32 PAD[9];
10165 + uint32 bcastaddr; /* Sonics broadcast address */
10166 + uint32 bcastdata; /* Sonics broadcast data */
10167 + uint32 PAD[2];
10168 + uint32 gpioin; /* ro: gpio input (>=rev2) */
10169 + uint32 gpioout; /* rw: gpio output (>=rev2) */
10170 + uint32 gpioouten; /* rw: gpio output enable (>= rev2) */
10171 + uint32 gpiocontrol; /* rw: gpio control (>= rev2) */
10172 + uint32 PAD[36];
10173 + uint32 sbtopci0; /* Sonics to PCI translation 0 */
10174 + uint32 sbtopci1; /* Sonics to PCI translation 1 */
10175 + uint32 sbtopci2; /* Sonics to PCI translation 2 */
10176 + uint32 PAD[445];
10177 + uint16 sprom[36]; /* SPROM shadow Area */
10178 + uint32 PAD[46];
10179 +} sbpciregs_t;
10180 +
10181 +/* PCI control */
10182 +#define PCI_RST_OE 0x01 /* When set, drives PCI_RESET out to pin */
10183 +#define PCI_RST 0x02 /* Value driven out to pin */
10184 +#define PCI_CLK_OE 0x04 /* When set, drives clock as gated by PCI_CLK out to pin */
10185 +#define PCI_CLK 0x08 /* Gate for clock driven out to pin */
10186 +
10187 +/* PCI arbiter control */
10188 +#define PCI_INT_ARB 0x01 /* When set, use an internal arbiter */
10189 +#define PCI_EXT_ARB 0x02 /* When set, use an external arbiter */
10190 +#define PCI_PARKID_MASK 0x06 /* Selects which agent is parked on an idle bus */
10191 +#define PCI_PARKID_SHIFT 1
10192 +#define PCI_PARKID_LAST 0 /* Last requestor */
10193 +#define PCI_PARKID_4710 1 /* 4710 */
10194 +#define PCI_PARKID_EXTREQ0 2 /* External requestor 0 */
10195 +#define PCI_PARKID_EXTREQ1 3 /* External requestor 1 */
10196 +
10197 +/* Interrupt status/mask */
10198 +#define PCI_INTA 0x01 /* PCI INTA# is asserted */
10199 +#define PCI_INTB 0x02 /* PCI INTB# is asserted */
10200 +#define PCI_SERR 0x04 /* PCI SERR# has been asserted (write one to clear) */
10201 +#define PCI_PERR 0x08 /* PCI PERR# has been asserted (write one to clear) */
10202 +#define PCI_PME 0x10 /* PCI PME# is asserted */
10203 +
10204 +/* (General) PCI/SB mailbox interrupts, two bits per pci function */
10205 +#define MAILBOX_F0_0 0x100 /* function 0, int 0 */
10206 +#define MAILBOX_F0_1 0x200 /* function 0, int 1 */
10207 +#define MAILBOX_F1_0 0x400 /* function 1, int 0 */
10208 +#define MAILBOX_F1_1 0x800 /* function 1, int 1 */
10209 +#define MAILBOX_F2_0 0x1000 /* function 2, int 0 */
10210 +#define MAILBOX_F2_1 0x2000 /* function 2, int 1 */
10211 +#define MAILBOX_F3_0 0x4000 /* function 3, int 0 */
10212 +#define MAILBOX_F3_1 0x8000 /* function 3, int 1 */
10213 +
10214 +/* Sonics broadcast address */
10215 +#define BCAST_ADDR_MASK 0xff /* Broadcast register address */
10216 +
10217 +/* Sonics to PCI translation types */
10218 +#define SBTOPCI0_MASK 0xfc000000
10219 +#define SBTOPCI1_MASK 0xfc000000
10220 +#define SBTOPCI2_MASK 0xc0000000
10221 +#define SBTOPCI_MEM 0
10222 +#define SBTOPCI_IO 1
10223 +#define SBTOPCI_CFG0 2
10224 +#define SBTOPCI_CFG1 3
10225 +#define SBTOPCI_PREF 0x4 /* prefetch enable */
10226 +#define SBTOPCI_BURST 0x8 /* burst enable */
10227 +#define SBTOPCI_RC_MASK 0x30 /* read command (>= rev11) */
10228 +#define SBTOPCI_RC_READ 0x00 /* memory read */
10229 +#define SBTOPCI_RC_READLINE 0x10 /* memory read line */
10230 +#define SBTOPCI_RC_READMULTI 0x20 /* memory read multiple */
10231 +
10232 +/* PCI core index in SROM shadow area */
10233 +#define SRSH_PI_OFFSET 0 /* first word */
10234 +#define SRSH_PI_MASK 0xf000 /* bit 15:12 */
10235 +#define SRSH_PI_SHIFT 12 /* bit 15:12 */
10236 +
10237 +/* PCI side: Reserved PCI configuration registers (see pcicfg.h) */
10238 +#define cap_list rsvd_a[0]
10239 +#define bar0_window dev_dep[0x80 - 0x40]
10240 +#define bar1_window dev_dep[0x84 - 0x40]
10241 +#define sprom_control dev_dep[0x88 - 0x40]
10242 +
10243 +#ifndef _LANGUAGE_ASSEMBLY
10244 +
10245 +extern int sbpci_read_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len);
10246 +extern int sbpci_write_config(sb_t *sbh, uint bus, uint dev, uint func, uint off, void *buf, int len);
10247 +extern void sbpci_ban(uint16 core);
10248 +extern int sbpci_init(sb_t *sbh);
10249 +extern void sbpci_check(sb_t *sbh);
10250 +
10251 +#endif /* !_LANGUAGE_ASSEMBLY */
10252 +
10253 +#endif /* _SBPCI_H */
10254 diff -urN linux.old/arch/mips/bcm947xx/include/sbsdram.h linux.dev/arch/mips/bcm947xx/include/sbsdram.h
10255 --- linux.old/arch/mips/bcm947xx/include/sbsdram.h 1970-01-01 01:00:00.000000000 +0100
10256 +++ linux.dev/arch/mips/bcm947xx/include/sbsdram.h 2005-12-15 15:35:40.175792500 +0100
10257 @@ -0,0 +1,75 @@
10258 +/*
10259 + * BCM47XX Sonics SiliconBackplane SDRAM controller core hardware definitions.
10260 + *
10261 + * Copyright 2005, Broadcom Corporation
10262 + * All Rights Reserved.
10263 + *
10264 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
10265 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
10266 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10267 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
10268 + * $Id$
10269 + */
10270 +
10271 +#ifndef _SBSDRAM_H
10272 +#define _SBSDRAM_H
10273 +
10274 +#ifndef _LANGUAGE_ASSEMBLY
10275 +
10276 +/* Sonics side: SDRAM core registers */
10277 +typedef volatile struct sbsdramregs {
10278 + uint32 initcontrol; /* Generates external SDRAM initialization sequence */
10279 + uint32 config; /* Initializes external SDRAM mode register */
10280 + uint32 refresh; /* Controls external SDRAM refresh rate */
10281 + uint32 pad1;
10282 + uint32 pad2;
10283 +} sbsdramregs_t;
10284 +
10285 +#endif
10286 +
10287 +/* SDRAM initialization control (initcontrol) register bits */
10288 +#define SDRAM_CBR 0x0001 /* Writing 1 generates refresh cycle and toggles bit */
10289 +#define SDRAM_PRE 0x0002 /* Writing 1 generates precharge cycle and toggles bit */
10290 +#define SDRAM_MRS 0x0004 /* Writing 1 generates mode register select cycle and toggles bit */
10291 +#define SDRAM_EN 0x0008 /* When set, enables access to SDRAM */
10292 +#define SDRAM_16Mb 0x0000 /* Use 16 Megabit SDRAM */
10293 +#define SDRAM_64Mb 0x0010 /* Use 64 Megabit SDRAM */
10294 +#define SDRAM_128Mb 0x0020 /* Use 128 Megabit SDRAM */
10295 +#define SDRAM_RSVMb 0x0030 /* Use special SDRAM */
10296 +#define SDRAM_RST 0x0080 /* Writing 1 causes soft reset of controller */
10297 +#define SDRAM_SELFREF 0x0100 /* Writing 1 enables self refresh mode */
10298 +#define SDRAM_PWRDOWN 0x0200 /* Writing 1 causes controller to power down */
10299 +#define SDRAM_32BIT 0x0400 /* When set, indicates 32 bit SDRAM interface */
10300 +#define SDRAM_9BITCOL 0x0800 /* When set, indicates 9 bit column */
10301 +
10302 +/* SDRAM configuration (config) register bits */
10303 +#define SDRAM_BURSTFULL 0x0000 /* Use full page bursts */
10304 +#define SDRAM_BURST8 0x0001 /* Use burst of 8 */
10305 +#define SDRAM_BURST4 0x0002 /* Use burst of 4 */
10306 +#define SDRAM_BURST2 0x0003 /* Use burst of 2 */
10307 +#define SDRAM_CAS3 0x0000 /* Use CAS latency of 3 */
10308 +#define SDRAM_CAS2 0x0004 /* Use CAS latency of 2 */
10309 +
10310 +/* SDRAM refresh control (refresh) register bits */
10311 +#define SDRAM_REF(p) (((p)&0xff) | SDRAM_REF_EN) /* Refresh period */
10312 +#define SDRAM_REF_EN 0x8000 /* Writing 1 enables periodic refresh */
10313 +
10314 +/* SDRAM Core default Init values (OCP ID 0x803) */
10315 +#define SDRAM_INIT MEM4MX16X2
10316 +#define SDRAM_CONFIG SDRAM_BURSTFULL
10317 +#define SDRAM_REFRESH SDRAM_REF(0x40)
10318 +
10319 +#define MEM1MX16 0x009 /* 2 MB */
10320 +#define MEM1MX16X2 0x409 /* 4 MB */
10321 +#define MEM2MX8X2 0x809 /* 4 MB */
10322 +#define MEM2MX8X4 0xc09 /* 8 MB */
10323 +#define MEM2MX32 0x439 /* 8 MB */
10324 +#define MEM4MX16 0x019 /* 8 MB */
10325 +#define MEM4MX16X2 0x419 /* 16 MB */
10326 +#define MEM8MX8X2 0x819 /* 16 MB */
10327 +#define MEM8MX16 0x829 /* 16 MB */
10328 +#define MEM4MX32 0x429 /* 16 MB */
10329 +#define MEM8MX8X4 0xc19 /* 32 MB */
10330 +#define MEM8MX16X2 0xc29 /* 32 MB */
10331 +
10332 +#endif /* _SBSDRAM_H */
10333 diff -urN linux.old/arch/mips/bcm947xx/include/sbutils.h linux.dev/arch/mips/bcm947xx/include/sbutils.h
10334 --- linux.old/arch/mips/bcm947xx/include/sbutils.h 1970-01-01 01:00:00.000000000 +0100
10335 +++ linux.dev/arch/mips/bcm947xx/include/sbutils.h 2005-12-15 16:00:47.404550500 +0100
10336 @@ -0,0 +1,136 @@
10337 +/*
10338 + * Misc utility routines for accessing chip-specific features
10339 + * of Broadcom HNBU SiliconBackplane-based chips.
10340 + *
10341 + * Copyright 2005, Broadcom Corporation
10342 + * All Rights Reserved.
10343 + *
10344 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
10345 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
10346 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10347 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
10348 + *
10349 + * $Id$
10350 + */
10351 +
10352 +#ifndef _sbutils_h_
10353 +#define _sbutils_h_
10354 +
10355 +/*
10356 + * Datastructure to export all chip specific common variables
10357 + * public (read-only) portion of sbutils handle returned by
10358 + * sb_attach()/sb_kattach()
10359 +*/
10360 +
10361 +struct sb_pub {
10362 +
10363 + uint bustype; /* SB_BUS, PCI_BUS */
10364 + uint buscoretype; /* SB_PCI, SB_PCMCIA, SB_PCIE*/
10365 + uint buscorerev; /* buscore rev */
10366 + uint buscoreidx; /* buscore index */
10367 + int ccrev; /* chip common core rev */
10368 + uint boardtype; /* board type */
10369 + uint boardvendor; /* board vendor */
10370 + uint chip; /* chip number */
10371 + uint chiprev; /* chip revision */
10372 + uint chippkg; /* chip package option */
10373 + uint sonicsrev; /* sonics backplane rev */
10374 +};
10375 +
10376 +typedef const struct sb_pub sb_t;
10377 +
10378 +/*
10379 + * Many of the routines below take an 'sbh' handle as their first arg.
10380 + * Allocate this by calling sb_attach(). Free it by calling sb_detach().
10381 + * At any one time, the sbh is logically focused on one particular sb core
10382 + * (the "current core").
10383 + * Use sb_setcore() or sb_setcoreidx() to change the association to another core.
10384 + */
10385 +
10386 +/* exported externs */
10387 +extern sb_t * BCMINIT(sb_attach)(uint pcidev, osl_t *osh, void *regs, uint bustype, void *sdh, char **vars, int *varsz);
10388 +extern sb_t * BCMINIT(sb_kattach)(void);
10389 +extern void sb_detach(sb_t *sbh);
10390 +extern uint BCMINIT(sb_chip)(sb_t *sbh);
10391 +extern uint BCMINIT(sb_chiprev)(sb_t *sbh);
10392 +extern uint BCMINIT(sb_chipcrev)(sb_t *sbh);
10393 +extern uint BCMINIT(sb_chippkg)(sb_t *sbh);
10394 +extern uint BCMINIT(sb_pcirev)(sb_t *sbh);
10395 +extern bool BCMINIT(sb_war16165)(sb_t *sbh);
10396 +extern uint BCMINIT(sb_boardvendor)(sb_t *sbh);
10397 +extern uint BCMINIT(sb_boardtype)(sb_t *sbh);
10398 +extern uint sb_bus(sb_t *sbh);
10399 +extern uint sb_buscoretype(sb_t *sbh);
10400 +extern uint sb_buscorerev(sb_t *sbh);
10401 +extern uint sb_corelist(sb_t *sbh, uint coreid[]);
10402 +extern uint sb_coreid(sb_t *sbh);
10403 +extern uint sb_coreidx(sb_t *sbh);
10404 +extern uint sb_coreunit(sb_t *sbh);
10405 +extern uint sb_corevendor(sb_t *sbh);
10406 +extern uint sb_corerev(sb_t *sbh);
10407 +extern void *sb_osh(sb_t *sbh);
10408 +extern void *sb_coreregs(sb_t *sbh);
10409 +extern uint32 sb_coreflags(sb_t *sbh, uint32 mask, uint32 val);
10410 +extern uint32 sb_coreflagshi(sb_t *sbh, uint32 mask, uint32 val);
10411 +extern bool sb_iscoreup(sb_t *sbh);
10412 +extern void *sb_setcoreidx(sb_t *sbh, uint coreidx);
10413 +extern void *sb_setcore(sb_t *sbh, uint coreid, uint coreunit);
10414 +extern int sb_corebist(sb_t *sbh, uint coreid, uint coreunit);
10415 +extern void sb_commit(sb_t *sbh);
10416 +extern uint32 sb_base(uint32 admatch);
10417 +extern uint32 sb_size(uint32 admatch);
10418 +extern void sb_core_reset(sb_t *sbh, uint32 bits);
10419 +extern void sb_core_tofixup(sb_t *sbh);
10420 +extern void sb_core_disable(sb_t *sbh, uint32 bits);
10421 +extern uint32 sb_clock_rate(uint32 pll_type, uint32 n, uint32 m);
10422 +extern uint32 sb_clock(sb_t *sbh);
10423 +extern void sb_pci_setup(sb_t *sbh, uint coremask);
10424 +extern void sb_watchdog(sb_t *sbh, uint ticks);
10425 +extern void *sb_gpiosetcore(sb_t *sbh);
10426 +extern uint32 sb_gpiocontrol(sb_t *sbh, uint32 mask, uint32 val, uint8 priority);
10427 +extern uint32 sb_gpioouten(sb_t *sbh, uint32 mask, uint32 val, uint8 priority);
10428 +extern uint32 sb_gpioout(sb_t *sbh, uint32 mask, uint32 val, uint8 priority);
10429 +extern uint32 sb_gpioin(sb_t *sbh);
10430 +extern uint32 sb_gpiointpolarity(sb_t *sbh, uint32 mask, uint32 val, uint8 priority);
10431 +extern uint32 sb_gpiointmask(sb_t *sbh, uint32 mask, uint32 val, uint8 priority);
10432 +extern uint32 sb_gpioled(sb_t *sbh, uint32 mask, uint32 val);
10433 +extern uint32 sb_gpioreserve(sb_t *sbh, uint32 gpio_num, uint8 priority);
10434 +extern uint32 sb_gpiorelease(sb_t *sbh, uint32 gpio_num, uint8 priority);
10435 +
10436 +extern void sb_clkctl_init(sb_t *sbh);
10437 +extern uint16 sb_clkctl_fast_pwrup_delay(sb_t *sbh);
10438 +extern bool sb_clkctl_clk(sb_t *sbh, uint mode);
10439 +extern int sb_clkctl_xtal(sb_t *sbh, uint what, bool on);
10440 +extern void sb_register_intr_callback(sb_t *sbh, void *intrsoff_fn,
10441 + void *intrsrestore_fn, void *intrsenabled_fn, void *intr_arg);
10442 +extern uint32 sb_set_initiator_to(sb_t *sbh, uint32 to);
10443 +extern void sb_corepciid(sb_t *sbh, uint16 *pcivendor, uint16 *pcidevice,
10444 + uint8 *pciclass, uint8 *pcisubclass, uint8 *pciprogif);
10445 +extern uint32 sb_gpiotimerval(sb_t *sbh, uint32 mask, uint32 val);
10446 +
10447 +
10448 +
10449 +/*
10450 +* Build device path. Path size must be >= SB_DEVPATH_BUFSZ.
10451 +* The returned path is NULL terminated and has trailing '/'.
10452 +* Return 0 on success, nonzero otherwise.
10453 +*/
10454 +extern int sb_devpath(sb_t *sbh, char *path, int size);
10455 +
10456 +/* clkctl xtal what flags */
10457 +#define XTAL 0x1 /* primary crystal oscillator (2050) */
10458 +#define PLL 0x2 /* main chip pll */
10459 +
10460 +/* clkctl clk mode */
10461 +#define CLK_FAST 0 /* force fast (pll) clock */
10462 +#define CLK_DYNAMIC 2 /* enable dynamic clock control */
10463 +
10464 +
10465 +/* GPIO usage priorities */
10466 +#define GPIO_DRV_PRIORITY 0
10467 +#define GPIO_APP_PRIORITY 1
10468 +
10469 +/* device path */
10470 +#define SB_DEVPATH_BUFSZ 16 /* min buffer size in bytes */
10471 +
10472 +#endif /* _sbutils_h_ */
10473 diff -urN linux.old/arch/mips/bcm947xx/include/sflash.h linux.dev/arch/mips/bcm947xx/include/sflash.h
10474 --- linux.old/arch/mips/bcm947xx/include/sflash.h 1970-01-01 01:00:00.000000000 +0100
10475 +++ linux.dev/arch/mips/bcm947xx/include/sflash.h 2005-12-15 16:49:23.001703000 +0100
10476 @@ -0,0 +1,36 @@
10477 +/*
10478 + * Broadcom SiliconBackplane chipcommon serial flash interface
10479 + *
10480 + * Copyright 2005, Broadcom Corporation
10481 + * All Rights Reserved.
10482 + *
10483 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
10484 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
10485 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10486 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
10487 + *
10488 + * $Id$
10489 + */
10490 +
10491 +#ifndef _sflash_h_
10492 +#define _sflash_h_
10493 +
10494 +#include <typedefs.h>
10495 +#include <sbchipc.h>
10496 +
10497 +struct sflash {
10498 + uint blocksize; /* Block size */
10499 + uint numblocks; /* Number of blocks */
10500 + uint32 type; /* Type */
10501 + uint size; /* Total size in bytes */
10502 +};
10503 +
10504 +/* Utility functions */
10505 +extern int sflash_poll(chipcregs_t *cc, uint offset);
10506 +extern int sflash_read(chipcregs_t *cc, uint offset, uint len, uchar *buf);
10507 +extern int sflash_write(chipcregs_t *cc, uint offset, uint len, const uchar *buf);
10508 +extern int sflash_erase(chipcregs_t *cc, uint offset);
10509 +extern int sflash_commit(chipcregs_t *cc, uint offset, uint len, const uchar *buf);
10510 +extern struct sflash * sflash_init(chipcregs_t *cc);
10511 +
10512 +#endif /* _sflash_h_ */
10513 diff -urN linux.old/arch/mips/bcm947xx/include/trxhdr.h linux.dev/arch/mips/bcm947xx/include/trxhdr.h
10514 --- linux.old/arch/mips/bcm947xx/include/trxhdr.h 1970-01-01 01:00:00.000000000 +0100
10515 +++ linux.dev/arch/mips/bcm947xx/include/trxhdr.h 2005-12-15 15:35:49.220357750 +0100
10516 @@ -0,0 +1,33 @@
10517 +/*
10518 + * TRX image file header format.
10519 + *
10520 + * Copyright 2005, Broadcom Corporation
10521 + * All Rights Reserved.
10522 + *
10523 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
10524 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
10525 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10526 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
10527 + *
10528 + * $Id$
10529 + */
10530 +
10531 +#include <typedefs.h>
10532 +
10533 +#define TRX_MAGIC 0x30524448 /* "HDR0" */
10534 +#define TRX_VERSION 1
10535 +#define TRX_MAX_LEN 0x3A0000
10536 +#define TRX_NO_HEADER 1 /* Do not write TRX header */
10537 +#define TRX_GZ_FILES 0x2 /* Contains up to TRX_MAX_OFFSET individual gzip files */
10538 +#define TRX_MAX_OFFSET 3
10539 +
10540 +struct trx_header {
10541 + uint32 magic; /* "HDR0" */
10542 + uint32 len; /* Length of file including header */
10543 + uint32 crc32; /* 32-bit CRC from flag_version to end of file */
10544 + uint32 flag_version; /* 0:15 flags, 16:31 version */
10545 + uint32 offsets[TRX_MAX_OFFSET]; /* Offsets of partitions from start of header */
10546 +};
10547 +
10548 +/* Compatibility */
10549 +typedef struct trx_header TRXHDR, *PTRXHDR;
10550 diff -urN linux.old/arch/mips/bcm947xx/include/typedefs.h linux.dev/arch/mips/bcm947xx/include/typedefs.h
10551 --- linux.old/arch/mips/bcm947xx/include/typedefs.h 1970-01-01 01:00:00.000000000 +0100
10552 +++ linux.dev/arch/mips/bcm947xx/include/typedefs.h 2005-12-15 15:35:52.436558750 +0100
10553 @@ -0,0 +1,326 @@
10554 +/*
10555 + * Copyright 2005, Broadcom Corporation
10556 + * All Rights Reserved.
10557 + *
10558 + * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
10559 + * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
10560 + * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10561 + * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
10562 + * $Id$
10563 + */
10564 +
10565 +#ifndef _TYPEDEFS_H_
10566 +#define _TYPEDEFS_H_
10567 +
10568 +
10569 +/* Define 'SITE_TYPEDEFS' in the compile to include a site specific
10570 + * typedef file "site_typedefs.h".
10571 + *
10572 + * If 'SITE_TYPEDEFS' is not defined, then the "Inferred Typedefs"
10573 + * section of this file makes inferences about the compile environment
10574 + * based on defined symbols and possibly compiler pragmas.
10575 + *
10576 + * Following these two sections is the "Default Typedefs"
10577 + * section. This section is only prcessed if 'USE_TYPEDEF_DEFAULTS' is
10578 + * defined. This section has a default set of typedefs and a few
10579 + * proprocessor symbols (TRUE, FALSE, NULL, ...).
10580 + */
10581 +
10582 +#ifdef SITE_TYPEDEFS
10583 +
10584 +/*******************************************************************************
10585 + * Site Specific Typedefs
10586 + *******************************************************************************/
10587 +
10588 +#include "site_typedefs.h"
10589 +
10590 +#else
10591 +
10592 +/*******************************************************************************
10593 + * Inferred Typedefs
10594 + *******************************************************************************/
10595 +
10596 +/* Infer the compile environment based on preprocessor symbols and pramas.
10597 + * Override type definitions as needed, and include configuration dependent
10598 + * header files to define types.
10599 + */
10600 +
10601 +#ifdef __cplusplus
10602 +
10603 +#define TYPEDEF_BOOL
10604 +#ifndef FALSE
10605 +#define FALSE false
10606 +#endif
10607 +#ifndef TRUE
10608 +#define TRUE true
10609 +#endif
10610 +
10611 +#else /* ! __cplusplus */
10612 +
10613 +#if defined(_WIN32)
10614 +
10615 +#define TYPEDEF_BOOL
10616 +typedef unsigned char bool; /* consistent w/BOOL */
10617 +
10618 +#endif /* _WIN32 */
10619 +
10620 +#endif /* ! __cplusplus */
10621 +
10622 +/* use the Windows ULONG_PTR type when compiling for 64 bit */
10623 +#if defined(_WIN64)
10624 +#include <basetsd.h>
10625 +#define TYPEDEF_UINTPTR
10626 +typedef ULONG_PTR uintptr;
10627 +#endif
10628 +
10629 +#ifdef _HNDRTE_
10630 +typedef long unsigned int size_t;
10631 +#endif
10632 +
10633 +#ifdef _MSC_VER /* Microsoft C */
10634 +#define TYPEDEF_INT64
10635 +#define TYPEDEF_UINT64
10636 +typedef signed __int64 int64;
10637 +typedef unsigned __int64 uint64;
10638 +#endif
10639 +
10640 +#if defined(MACOSX) && defined(KERNEL)
10641 +#define TYPEDEF_BOOL
10642 +#endif
10643 +
10644 +
10645 +#if defined(linux)
10646 +#define TYPEDEF_UINT
10647 +#define TYPEDEF_USHORT
10648 +#define TYPEDEF_ULONG
10649 +#endif
10650 +
10651 +#if !defined(linux) && !defined(_WIN32) && !defined(PMON) && !defined(_CFE_) && !defined(_HNDRTE_) && !defined(_MINOSL_)
10652 +#define TYPEDEF_UINT
10653 +#define TYPEDEF_USHORT
10654 +#endif
10655 +
10656 +
10657 +/* Do not support the (u)int64 types with strict ansi for GNU C */
10658 +#if defined(__GNUC__) && defined(__STRICT_ANSI__)
10659 +#define TYPEDEF_INT64
10660 +#define TYPEDEF_UINT64
10661 +#endif
10662 +
10663 +/* ICL accepts unsigned 64 bit type only, and complains in ANSI mode
10664 + * for singned or unsigned */
10665 +#if defined(__ICL)
10666 +
10667 +#define TYPEDEF_INT64
10668 +
10669 +#if defined(__STDC__)
10670 +#define TYPEDEF_UINT64
10671 +#endif
10672 +
10673 +#endif /* __ICL */
10674 +
10675 +
10676 +#if !defined(_WIN32) && !defined(PMON) && !defined(_CFE_) && !defined(_HNDRTE_) && !defined(_MINOSL_)
10677 +
10678 +/* pick up ushort & uint from standard types.h */
10679 +#if defined(linux) && defined(__KERNEL__)
10680 +
10681 +#include <linux/types.h> /* sys/types.h and linux/types.h are oil and water */
10682 +
10683 +#else
10684 +
10685 +#include <sys/types.h>
10686 +
10687 +#endif
10688 +
10689 +#endif /* !_WIN32 && !PMON && !_CFE_ && !_HNDRTE_ && !_MINOSL_ */
10690 +
10691 +#if defined(MACOSX) && defined(KERNEL)
10692 +#include <IOKit/IOTypes.h>
10693 +#endif
10694 +
10695 +
10696 +/* use the default typedefs in the next section of this file */
10697 +#define USE_TYPEDEF_DEFAULTS
10698 +
10699 +#endif /* SITE_TYPEDEFS */
10700 +
10701 +
10702 +/*******************************************************************************
10703 + * Default Typedefs
10704 + *******************************************************************************/
10705 +
10706 +#ifdef USE_TYPEDEF_DEFAULTS
10707 +#undef USE_TYPEDEF_DEFAULTS
10708 +
10709 +#ifndef TYPEDEF_BOOL
10710 +typedef /*@abstract@*/ unsigned char bool;
10711 +#endif
10712 +
10713 +/*----------------------- define uchar, ushort, uint, ulong ------------------*/
10714 +
10715 +#ifndef TYPEDEF_UCHAR
10716 +typedef unsigned char uchar;
10717 +#endif
10718 +
10719 +#ifndef TYPEDEF_USHORT
10720 +typedef unsigned short ushort;
10721 +#endif
10722 +
10723 +#ifndef TYPEDEF_UINT
10724 +typedef unsigned int uint;
10725 +#endif
10726 +
10727 +#ifndef TYPEDEF_ULONG
10728 +typedef unsigned long ulong;
10729 +#endif
10730 +
10731 +/*----------------------- define [u]int8/16/32/64, uintptr --------------------*/
10732 +
10733 +#ifndef TYPEDEF_UINT8
10734 +typedef unsigned char uint8;
10735 +#endif
10736 +
10737 +#ifndef TYPEDEF_UINT16
10738 +typedef unsigned short uint16;
10739 +#endif
10740 +
10741 +#ifndef TYPEDEF_UINT32
10742 +typedef unsigned int uint32;
10743 +#endif
10744 +
10745 +#ifndef TYPEDEF_UINT64
10746 +typedef unsigned long long uint64;
10747 +#endif
10748 +
10749 +#ifndef TYPEDEF_UINTPTR
10750 +typedef unsigned int uintptr;
10751 +#endif
10752 +
10753 +#ifndef TYPEDEF_INT8
10754 +typedef signed char int8;
10755 +#endif
10756 +
10757 +#ifndef TYPEDEF_INT16
10758 +typedef signed short int16;
10759 +#endif
10760 +
10761 +#ifndef TYPEDEF_INT32
10762 +typedef signed int int32;
10763 +#endif
10764 +
10765 +#ifndef TYPEDEF_INT64
10766 +typedef signed long long int64;
10767 +#endif
10768 +
10769 +/*----------------------- define float32/64, float_t -----------------------*/
10770 +
10771 +#ifndef TYPEDEF_FLOAT32
10772 +typedef float float32;
10773 +#endif
10774 +
10775 +#ifndef TYPEDEF_FLOAT64
10776 +typedef double float64;
10777 +#endif
10778 +
10779 +/*
10780 + * abstracted floating point type allows for compile time selection of
10781 + * single or double precision arithmetic. Compiling with -DFLOAT32
10782 + * selects single precision; the default is double precision.
10783 + */
10784 +
10785 +#ifndef TYPEDEF_FLOAT_T
10786 +
10787 +#if defined(FLOAT32)
10788 +typedef float32 float_t;
10789 +#else /* default to double precision floating point */
10790 +typedef float64 float_t;
10791 +#endif
10792 +
10793 +#endif /* TYPEDEF_FLOAT_T */
10794 +
10795 +/*----------------------- define macro values -----------------------------*/
10796 +
10797 +#ifndef FALSE
10798 +#define FALSE 0
10799 +#endif
10800 +
10801 +#ifndef TRUE
10802 +#define TRUE 1
10803 +#endif
10804 +
10805 +#ifndef NULL
10806 +#define NULL 0
10807 +#endif
10808 +
10809 +#ifndef OFF
10810 +#define OFF 0
10811 +#endif
10812 +
10813 +#ifndef ON
10814 +#define ON 1
10815 +#endif
10816 +
10817 +#define AUTO (-1)
10818 +
10819 +/* Reclaiming text and data :
10820 + The following macros specify special linker sections that can be reclaimed
10821 + after a system is considered 'up'.
10822 + */
10823 +#if defined(__GNUC__) && defined(BCMRECLAIM)
10824 +extern bool bcmreclaimed;
10825 +#define BCMINITDATA(_data) __attribute__ ((__section__ (".dataini." #_data))) _data##_ini
10826 +#define BCMINITFN(_fn) __attribute__ ((__section__ (".textini." #_fn))) _fn##_ini
10827 +#define BCMINIT(_id) _id##_ini
10828 +#else
10829 +#define BCMINITDATA(_data) _data
10830 +#define BCMINITFN(_fn) _fn
10831 +#define BCMINIT(_id) _id
10832 +#define bcmreclaimed 0
10833 +#endif
10834 +
10835 +/*----------------------- define PTRSZ, INLINE ----------------------------*/
10836 +
10837 +#ifndef PTRSZ
10838 +#define PTRSZ sizeof (char*)
10839 +#endif
10840 +
10841 +#ifndef INLINE
10842 +
10843 +#ifdef _MSC_VER
10844 +
10845 +#define INLINE __inline
10846 +
10847 +#elif __GNUC__
10848 +
10849 +#define INLINE __inline__
10850 +
10851 +#else
10852 +
10853 +#define INLINE
10854 +
10855 +#endif /* _MSC_VER */
10856 +
10857 +#endif /* INLINE */
10858 +
10859 +#undef TYPEDEF_BOOL
10860 +#undef TYPEDEF_UCHAR
10861 +#undef TYPEDEF_USHORT
10862 +#undef TYPEDEF_UINT
10863 +#undef TYPEDEF_ULONG
10864 +#undef TYPEDEF_UINT8
10865 +#undef TYPEDEF_UINT16
10866 +#undef TYPEDEF_UINT32
10867 +#undef TYPEDEF_UINT64
10868 +#undef TYPEDEF_UINTPTR
10869 +#undef TYPEDEF_INT8
10870 +#undef TYPEDEF_INT16
10871 +#undef TYPEDEF_INT32
10872 +#undef TYPEDEF_INT64
10873 +#undef TYPEDEF_FLOAT32
10874 +#undef TYPEDEF_FLOAT64
10875 +#undef TYPEDEF_FLOAT_T
10876 +
10877 +#endif /* USE_TYPEDEF_DEFAULTS */
10878 +
10879 +#endif /* _TYPEDEFS_H_ */
10880 diff -urN linux.old/arch/mips/bcm947xx/int-handler.S linux.dev/arch/mips/bcm947xx/int-handler.S
10881 --- linux.old/arch/mips/bcm947xx/int-handler.S 1970-01-01 01:00:00.000000000 +0100
10882 +++ linux.dev/arch/mips/bcm947xx/int-handler.S 2005-12-15 12:57:27.877187750 +0100
10883 @@ -0,0 +1,48 @@
10884 +/*
10885 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
10886 + *
10887 + * This program is free software; you can redistribute it and/or modify it
10888 + * under the terms of the GNU General Public License as published by the
10889 + * Free Software Foundation; either version 2 of the License, or (at your
10890 + * option) any later version.
10891 + *
10892 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
10893 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
10894 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
10895 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
10896 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
10897 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
10898 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
10899 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
10900 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
10901 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10902 + *
10903 + * You should have received a copy of the GNU General Public License along
10904 + * with this program; if not, write to the Free Software Foundation, Inc.,
10905 + * 675 Mass Ave, Cambridge, MA 02139, USA.
10906 + */
10907 +
10908 +#include <asm/asm.h>
10909 +#include <asm/mipsregs.h>
10910 +#include <asm/regdef.h>
10911 +#include <asm/stackframe.h>
10912 +
10913 + .text
10914 + .set noreorder
10915 + .set noat
10916 + .align 5
10917 +
10918 + NESTED(bcm47xx_irq_handler, PT_SIZE, sp)
10919 + SAVE_ALL
10920 + CLI
10921 +
10922 + .set at
10923 + .set noreorder
10924 +
10925 + jal bcm47xx_irq_dispatch
10926 + move a0, sp
10927 +
10928 + j ret_from_irq
10929 + nop
10930 +
10931 + END(bcm47xx_irq_handler)
10932 diff -urN linux.old/arch/mips/bcm947xx/irq.c linux.dev/arch/mips/bcm947xx/irq.c
10933 --- linux.old/arch/mips/bcm947xx/irq.c 1970-01-01 01:00:00.000000000 +0100
10934 +++ linux.dev/arch/mips/bcm947xx/irq.c 2005-12-15 12:57:27.877187750 +0100
10935 @@ -0,0 +1,67 @@
10936 +/*
10937 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
10938 + *
10939 + * This program is free software; you can redistribute it and/or modify it
10940 + * under the terms of the GNU General Public License as published by the
10941 + * Free Software Foundation; either version 2 of the License, or (at your
10942 + * option) any later version.
10943 + *
10944 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
10945 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
10946 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
10947 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
10948 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
10949 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
10950 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
10951 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
10952 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
10953 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10954 + *
10955 + * You should have received a copy of the GNU General Public License along
10956 + * with this program; if not, write to the Free Software Foundation, Inc.,
10957 + * 675 Mass Ave, Cambridge, MA 02139, USA.
10958 + */
10959 +
10960 +#include <linux/config.h>
10961 +#include <linux/errno.h>
10962 +#include <linux/init.h>
10963 +#include <linux/interrupt.h>
10964 +#include <linux/irq.h>
10965 +#include <linux/module.h>
10966 +#include <linux/smp.h>
10967 +#include <linux/types.h>
10968 +
10969 +#include <asm/cpu.h>
10970 +#include <asm/io.h>
10971 +#include <asm/irq.h>
10972 +#include <asm/irq_cpu.h>
10973 +
10974 +extern asmlinkage void bcm47xx_irq_handler(void);
10975 +
10976 +void bcm47xx_irq_dispatch(struct pt_regs *regs)
10977 +{
10978 + u32 cause;
10979 +
10980 + cause = read_c0_cause() & read_c0_status() & CAUSEF_IP;
10981 +
10982 + clear_c0_status(cause);
10983 +
10984 + if (cause & CAUSEF_IP7)
10985 + do_IRQ(7, regs);
10986 + if (cause & CAUSEF_IP2)
10987 + do_IRQ(2, regs);
10988 + if (cause & CAUSEF_IP3)
10989 + do_IRQ(3, regs);
10990 + if (cause & CAUSEF_IP4)
10991 + do_IRQ(4, regs);
10992 + if (cause & CAUSEF_IP5)
10993 + do_IRQ(5, regs);
10994 + if (cause & CAUSEF_IP6)
10995 + do_IRQ(6, regs);
10996 +}
10997 +
10998 +void __init arch_init_irq(void)
10999 +{
11000 + set_except_vector(0, bcm47xx_irq_handler);
11001 + mips_cpu_irq_init(0);
11002 +}
11003 diff -urN linux.old/arch/mips/bcm947xx/pci.c linux.dev/arch/mips/bcm947xx/pci.c
11004 --- linux.old/arch/mips/bcm947xx/pci.c 1970-01-01 01:00:00.000000000 +0100
11005 +++ linux.dev/arch/mips/bcm947xx/pci.c 2005-12-15 23:25:48.489984500 +0100
11006 @@ -0,0 +1,92 @@
11007 +#include <linux/kernel.h>
11008 +#include <linux/init.h>
11009 +#include <linux/pci.h>
11010 +#include <linux/types.h>
11011 +
11012 +#include <asm/cpu.h>
11013 +#include <asm/io.h>
11014 +
11015 +#include <typedefs.h>
11016 +#include <osl.h>
11017 +#include <sbutils.h>
11018 +#include <sbmips.h>
11019 +#include <sbconfig.h>
11020 +#include <sbpci.h>
11021 +
11022 +extern sb_t *sbh;
11023 +
11024 +
11025 +static int
11026 +sb_pci_read_config(struct pci_bus *bus, unsigned int devfn,
11027 + int reg, int size, u32 *val)
11028 +{
11029 + int ret;
11030 + ret = sbpci_read_config(sbh, bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), reg, val, size);
11031 + return ret ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
11032 +}
11033 +
11034 +static int
11035 +sb_pci_write_config(struct pci_bus *bus, unsigned int devfn,
11036 + int reg, int size, u32 val)
11037 +{
11038 + int ret;
11039 + ret = sbpci_write_config(sbh, bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), reg, &val, size);
11040 + return ret ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
11041 +}
11042 +
11043 +
11044 +static struct pci_ops sb_pci_ops = {
11045 + .read = sb_pci_read_config,
11046 + .write = sb_pci_write_config,
11047 +};
11048 +
11049 +
11050 +static struct resource sb_pci_mem_resource = {
11051 + .name = "SB PCI Memory resources",
11052 + .start = SB_ENUM_BASE,
11053 + .end = SB_ENUM_LIM - 1,
11054 + .flags = IORESOURCE_MEM,
11055 +};
11056 +
11057 +static struct resource sb_pci_io_resource = {
11058 + .name = "SB PCI I/O resources",
11059 + .start = 0x100,
11060 + .end = 0x1FF,
11061 + .flags = IORESOURCE_IO,
11062 +};
11063 +
11064 +static struct pci_controller bcm47xx_sb_pci_controller = {
11065 + .pci_ops = &sb_pci_ops,
11066 + .mem_resource = &sb_pci_mem_resource,
11067 + .io_resource = &sb_pci_io_resource,
11068 +};
11069 +
11070 +static struct resource ext_pci_mem_resource = {
11071 + .name = "Ext PCI Memory resources",
11072 + .start = 0x40000000,
11073 + .end = 0x7fffffff,
11074 + .flags = IORESOURCE_MEM,
11075 +};
11076 +
11077 +static struct resource ext_pci_io_resource = {
11078 + .name = "Ext PCI I/O resources",
11079 + .start = 0x200,
11080 + .end = 0x2FF,
11081 + .flags = IORESOURCE_IO,
11082 +};
11083 +
11084 +static struct pci_controller bcm47xx_ext_pci_controller = {
11085 + .pci_ops = &sb_pci_ops,
11086 + .mem_resource = &ext_pci_mem_resource,
11087 + .io_resource = &ext_pci_io_resource,
11088 +};
11089 +
11090 +void bcm47xx_pci_init(void)
11091 +{
11092 + sbpci_init(sbh);
11093 +
11094 + set_io_port_base((unsigned long) ioremap_nocache(SB_PCI_MEM, 0x04000000));
11095 +
11096 + register_pci_controller(&bcm47xx_sb_pci_controller);
11097 + register_pci_controller(&bcm47xx_ext_pci_controller);
11098 +}
11099 diff -urN linux.old/arch/mips/bcm947xx/prom.c linux.dev/arch/mips/bcm947xx/prom.c
11100 --- linux.old/arch/mips/bcm947xx/prom.c 1970-01-01 01:00:00.000000000 +0100
11101 +++ linux.dev/arch/mips/bcm947xx/prom.c 2005-12-15 12:57:27.877187750 +0100
11102 @@ -0,0 +1,59 @@
11103 +/*
11104 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
11105 + *
11106 + * This program is free software; you can redistribute it and/or modify it
11107 + * under the terms of the GNU General Public License as published by the
11108 + * Free Software Foundation; either version 2 of the License, or (at your
11109 + * option) any later version.
11110 + *
11111 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
11112 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
11113 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
11114 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
11115 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
11116 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
11117 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
11118 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
11119 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
11120 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11121 + *
11122 + * You should have received a copy of the GNU General Public License along
11123 + * with this program; if not, write to the Free Software Foundation, Inc.,
11124 + * 675 Mass Ave, Cambridge, MA 02139, USA.
11125 + */
11126 +
11127 +#include <linux/init.h>
11128 +#include <linux/mm.h>
11129 +#include <linux/sched.h>
11130 +#include <linux/bootmem.h>
11131 +
11132 +#include <asm/addrspace.h>
11133 +#include <asm/bootinfo.h>
11134 +#include <asm/pmon.h>
11135 +
11136 +const char *get_system_type(void)
11137 +{
11138 + return "Broadcom BCM47xx";
11139 +}
11140 +
11141 +void __init prom_init(void)
11142 +{
11143 + unsigned long mem;
11144 +
11145 + mips_machgroup = MACH_GROUP_BRCM;
11146 + mips_machtype = MACH_BCM47XX;
11147 +
11148 + /* Figure out memory size by finding aliases */
11149 + for (mem = (1 << 20); mem < (128 << 20); mem += (1 << 20)) {
11150 + if (*(unsigned long *)((unsigned long)(prom_init) + mem) ==
11151 + *(unsigned long *)(prom_init))
11152 + break;
11153 + }
11154 +
11155 + add_memory_region(0, mem, BOOT_MEM_RAM);
11156 +}
11157 +
11158 +unsigned long __init prom_free_prom_memory(void)
11159 +{
11160 + return 0;
11161 +}
11162 diff -urN linux.old/arch/mips/bcm947xx/setup.c linux.dev/arch/mips/bcm947xx/setup.c
11163 --- linux.old/arch/mips/bcm947xx/setup.c 1970-01-01 01:00:00.000000000 +0100
11164 +++ linux.dev/arch/mips/bcm947xx/setup.c 2005-12-15 19:17:21.508844000 +0100
11165 @@ -0,0 +1,107 @@
11166 +/*
11167 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
11168 + * Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
11169 + *
11170 + * This program is free software; you can redistribute it and/or modify it
11171 + * under the terms of the GNU General Public License as published by the
11172 + * Free Software Foundation; either version 2 of the License, or (at your
11173 + * option) any later version.
11174 + *
11175 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
11176 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
11177 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
11178 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
11179 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
11180 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
11181 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
11182 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
11183 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
11184 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11185 + *
11186 + * You should have received a copy of the GNU General Public License along
11187 + * with this program; if not, write to the Free Software Foundation, Inc.,
11188 + * 675 Mass Ave, Cambridge, MA 02139, USA.
11189 + */
11190 +
11191 +#include <linux/init.h>
11192 +#include <linux/types.h>
11193 +#include <linux/tty.h>
11194 +#include <linux/serial.h>
11195 +#include <linux/serial_core.h>
11196 +#include <linux/serial_reg.h>
11197 +#include <asm/bootinfo.h>
11198 +#include <asm/time.h>
11199 +#include <asm/reboot.h>
11200 +
11201 +#include <typedefs.h>
11202 +#include <osl.h>
11203 +#include <sbutils.h>
11204 +#include <sbmips.h>
11205 +#include <sbpci.h>
11206 +#include <sbconfig.h>
11207 +#include <bcmdevs.h>
11208 +
11209 +extern void bcm47xx_pci_init(void);
11210 +extern void bcm47xx_time_init(void);
11211 +extern void bcm47xx_timer_setup(struct irqaction *irq);
11212 +void *sbh;
11213 +
11214 +static int ser_line = 0;
11215 +
11216 +static void
11217 +serial_add(void *regs, uint irq, uint baud_base, uint reg_shift)
11218 +{
11219 + struct uart_port s;
11220 +
11221 + memset(&s, 0, sizeof(s));
11222 +
11223 + s.line = ser_line++;
11224 + s.membase = regs;
11225 + s.irq = irq + 2;
11226 + s.uartclk = baud_base;
11227 + s.flags = ASYNC_BOOT_AUTOCONF;
11228 + s.iotype = SERIAL_IO_MEM;
11229 + s.regshift = reg_shift;
11230 +
11231 + if (early_serial_setup(&s) != 0) {
11232 + printk(KERN_ERR "Serial setup failed!\n");
11233 + }
11234 +}
11235 +
11236 +static void bcm47xx_machine_restart(char *command)
11237 +{
11238 + printk("Please stand by while rebooting the system...\n");
11239 +
11240 + /* Set the watchdog timer to reset immediately */
11241 + local_irq_disable();
11242 + sb_watchdog(sbh, 1);
11243 + while (1);
11244 +}
11245 +
11246 +static void bcm47xx_machine_halt(void)
11247 +{
11248 + /* Disable interrupts and watchdog and spin forever */
11249 + local_irq_disable();
11250 + sb_watchdog(sbh, 0);
11251 + while (1);
11252 +}
11253 +
11254 +void __init plat_setup(void)
11255 +{
11256 +
11257 + sbh = sb_kattach();
11258 + sb_mips_init(sbh);
11259 +
11260 + bcm47xx_pci_init();
11261 +
11262 + set_io_port_base((unsigned long) ioremap_nocache(SB_PCI_MEM, 0x04000000));
11263 +
11264 + sb_serial_init(sbh, serial_add);
11265 +
11266 + _machine_restart = bcm47xx_machine_restart;
11267 + _machine_halt = bcm47xx_machine_halt;
11268 + _machine_power_off = bcm47xx_machine_halt;
11269 +
11270 + board_time_init = bcm47xx_time_init;
11271 + board_timer_setup = bcm47xx_timer_setup;
11272 +}
11273 diff -urN linux.old/arch/mips/bcm947xx/time.c linux.dev/arch/mips/bcm947xx/time.c
11274 --- linux.old/arch/mips/bcm947xx/time.c 1970-01-01 01:00:00.000000000 +0100
11275 +++ linux.dev/arch/mips/bcm947xx/time.c 2005-12-15 12:57:27.877187750 +0100
11276 @@ -0,0 +1,59 @@
11277 +/*
11278 + * Copyright (C) 2004 Florian Schirmer (jolt@tuxbox.org)
11279 + *
11280 + * This program is free software; you can redistribute it and/or modify it
11281 + * under the terms of the GNU General Public License as published by the
11282 + * Free Software Foundation; either version 2 of the License, or (at your
11283 + * option) any later version.
11284 + *
11285 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
11286 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
11287 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
11288 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
11289 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
11290 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
11291 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
11292 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
11293 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
11294 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11295 + *
11296 + * You should have received a copy of the GNU General Public License along
11297 + * with this program; if not, write to the Free Software Foundation, Inc.,
11298 + * 675 Mass Ave, Cambridge, MA 02139, USA.
11299 + */
11300 +
11301 +#include <linux/config.h>
11302 +#include <linux/init.h>
11303 +#include <linux/kernel.h>
11304 +#include <linux/sched.h>
11305 +#include <linux/serial_reg.h>
11306 +#include <linux/interrupt.h>
11307 +#include <asm/addrspace.h>
11308 +#include <asm/io.h>
11309 +#include <asm/time.h>
11310 +
11311 +void __init
11312 +bcm47xx_time_init(void)
11313 +{
11314 + unsigned int hz;
11315 +
11316 + /*
11317 + * Use deterministic values for initial counter interrupt
11318 + * so that calibrate delay avoids encountering a counter wrap.
11319 + */
11320 + write_c0_count(0);
11321 + write_c0_compare(0xffff);
11322 +
11323 + hz = 200 * 1000 * 1000;
11324 +
11325 + /* Set MIPS counter frequency for fixed_rate_gettimeoffset() */
11326 + mips_hpt_frequency = hz / 2;
11327 +
11328 +}
11329 +
11330 +void __init
11331 +bcm47xx_timer_setup(struct irqaction *irq)
11332 +{
11333 + /* Enable the timer interrupt */
11334 + setup_irq(7, irq);
11335 +}
11336 diff -urN linux.old/arch/mips/kernel/cpu-probe.c linux.dev/arch/mips/kernel/cpu-probe.c
11337 --- linux.old/arch/mips/kernel/cpu-probe.c 2005-12-15 13:26:49.766024000 +0100
11338 +++ linux.dev/arch/mips/kernel/cpu-probe.c 2005-12-15 12:57:27.901177250 +0100
11339 @@ -656,6 +656,28 @@
11340 }
11341
11342
11343 +static inline void cpu_probe_broadcom(struct cpuinfo_mips *c)
11344 +{
11345 + decode_config1(c);
11346 + switch (c->processor_id & 0xff00) {
11347 + case PRID_IMP_BCM3302:
11348 + c->cputype = CPU_BCM3302;
11349 + c->isa_level = MIPS_CPU_ISA_M32;
11350 + c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
11351 + MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER;
11352 + break;
11353 + case PRID_IMP_BCM4710:
11354 + c->cputype = CPU_BCM4710;
11355 + c->isa_level = MIPS_CPU_ISA_M32;
11356 + c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
11357 + MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER;
11358 + break;
11359 + default:
11360 + c->cputype = CPU_UNKNOWN;
11361 + break;
11362 + }
11363 +}
11364 +
11365 __init void cpu_probe(void)
11366 {
11367 struct cpuinfo_mips *c = &current_cpu_data;
11368 @@ -678,6 +700,9 @@
11369 case PRID_COMP_SIBYTE:
11370 cpu_probe_sibyte(c);
11371 break;
11372 + case PRID_COMP_BROADCOM:
11373 + cpu_probe_broadcom(c);
11374 + break;
11375 case PRID_COMP_SANDCRAFT:
11376 cpu_probe_sandcraft(c);
11377 break;
11378 diff -urN linux.old/arch/mips/kernel/head.S linux.dev/arch/mips/kernel/head.S
11379 --- linux.old/arch/mips/kernel/head.S 2005-12-15 13:26:49.766024000 +0100
11380 +++ linux.dev/arch/mips/kernel/head.S 2005-12-15 12:57:27.901177250 +0100
11381 @@ -107,6 +107,14 @@
11382 #endif
11383 .endm
11384
11385 +#ifdef CONFIG_BCM4710
11386 +#undef eret
11387 +#define eret nop; nop; eret
11388 +#endif
11389 +
11390 + j kernel_entry
11391 + nop
11392 +
11393 /*
11394 * Reserved space for exception handlers.
11395 * Necessary for machines which link their kernels at KSEG0.
11396 diff -urN linux.old/arch/mips/kernel/proc.c linux.dev/arch/mips/kernel/proc.c
11397 --- linux.old/arch/mips/kernel/proc.c 2005-12-15 13:26:49.766024000 +0100
11398 +++ linux.dev/arch/mips/kernel/proc.c 2005-12-15 12:57:27.921168500 +0100
11399 @@ -82,6 +82,8 @@
11400 [CPU_VR4181] = "NEC VR4181",
11401 [CPU_VR4181A] = "NEC VR4181A",
11402 [CPU_SR71000] = "Sandcraft SR71000",
11403 + [CPU_BCM3302] = "Broadcom BCM3302",
11404 + [CPU_BCM4710] = "Broadcom BCM4710",
11405 [CPU_PR4450] = "Philips PR4450",
11406 };
11407
11408 diff -urN linux.old/arch/mips/mm/tlbex.c linux.dev/arch/mips/mm/tlbex.c
11409 --- linux.old/arch/mips/mm/tlbex.c 2005-12-15 13:26:49.794011750 +0100
11410 +++ linux.dev/arch/mips/mm/tlbex.c 2005-12-15 12:57:27.945158000 +0100
11411 @@ -858,6 +858,8 @@
11412 case CPU_4KSC:
11413 case CPU_20KC:
11414 case CPU_25KF:
11415 + case CPU_BCM3302:
11416 + case CPU_BCM4710:
11417 tlbw(p);
11418 break;
11419
11420 diff -urN linux.old/arch/mips/pci/Makefile linux.dev/arch/mips/pci/Makefile
11421 --- linux.old/arch/mips/pci/Makefile 2005-12-15 13:26:49.814003000 +0100
11422 +++ linux.dev/arch/mips/pci/Makefile 2005-12-15 14:27:26.439319250 +0100
11423 @@ -18,6 +18,7 @@
11424 obj-$(CONFIG_MIPS_TX3927) += ops-tx3927.o
11425 obj-$(CONFIG_PCI_VR41XX) += ops-vr41xx.o pci-vr41xx.o
11426 obj-$(CONFIG_NEC_CMBVR4133) += fixup-vr4133.o
11427 +obj-$(CONFIG_BCM947XX) += fixup-bcm47xx.o
11428
11429 #
11430 # These are still pretty much in the old state, watch, go blind.
11431 diff -urN linux.old/arch/mips/pci/fixup-bcm47xx.c linux.dev/arch/mips/pci/fixup-bcm47xx.c
11432 --- linux.old/arch/mips/pci/fixup-bcm47xx.c 1970-01-01 01:00:00.000000000 +0100
11433 +++ linux.dev/arch/mips/pci/fixup-bcm47xx.c 2005-12-15 12:57:27.945158000 +0100
11434 @@ -0,0 +1,23 @@
11435 +#include <linux/init.h>
11436 +#include <linux/pci.h>
11437 +
11438 +/* Do platform specific device initialization at pci_enable_device() time */
11439 +int pcibios_plat_dev_init(struct pci_dev *dev)
11440 +{
11441 + return 0;
11442 +}
11443 +
11444 +int __init pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
11445 +{
11446 + u8 irq;
11447 +
11448 + if (dev->bus->number == 1)
11449 + return 2;
11450 +
11451 + pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
11452 + return irq + 2;
11453 +}
11454 +
11455 +struct pci_fixup pcibios_fixups[] = {
11456 + { 0 }
11457 +};
11458 diff -urN linux.old/include/asm-mips/bootinfo.h linux.dev/include/asm-mips/bootinfo.h
11459 --- linux.old/include/asm-mips/bootinfo.h 2005-12-15 13:26:49.818001250 +0100
11460 +++ linux.dev/include/asm-mips/bootinfo.h 2005-12-15 12:57:27.969147500 +0100
11461 @@ -218,6 +218,12 @@
11462 #define MACH_GROUP_TITAN 22 /* PMC-Sierra Titan */
11463 #define MACH_TITAN_YOSEMITE 1 /* PMC-Sierra Yosemite */
11464
11465 +/*
11466 + * Valid machtype for group Broadcom
11467 + */
11468 +#define MACH_GROUP_BRCM 23 /* Broadcom */
11469 +#define MACH_BCM47XX 1 /* Broadcom BCM47xx */
11470 +
11471 #define CL_SIZE COMMAND_LINE_SIZE
11472
11473 const char *get_system_type(void);
11474 diff -urN linux.old/include/asm-mips/cpu.h linux.dev/include/asm-mips/cpu.h
11475 --- linux.old/include/asm-mips/cpu.h 2005-12-15 13:26:49.818001250 +0100
11476 +++ linux.dev/include/asm-mips/cpu.h 2005-12-15 12:57:27.969147500 +0100
11477 @@ -102,6 +102,13 @@
11478 #define PRID_IMP_SR71000 0x0400
11479
11480 /*
11481 + * These are the PRID's for when 23:16 == PRID_COMP_BROADCOM
11482 + */
11483 +
11484 +#define PRID_IMP_BCM4710 0x4000
11485 +#define PRID_IMP_BCM3302 0x9000
11486 +
11487 +/*
11488 * Definitions for 7:0 on legacy processors
11489 */
11490
11491 @@ -196,7 +203,9 @@
11492 #define CPU_34K 60
11493 #define CPU_PR4450 61
11494 #define CPU_SB1A 62
11495 -#define CPU_LAST 62
11496 +#define CPU_BCM3302 63
11497 +#define CPU_BCM4710 64
11498 +#define CPU_LAST 64
11499
11500 /*
11501 * ISA Level encodings
11502 diff -urN linux.old/include/linux/init.h linux.dev/include/linux/init.h
11503 --- linux.old/include/linux/init.h 2005-12-15 13:26:49.818001250 +0100
11504 +++ linux.dev/include/linux/init.h 2005-12-15 12:57:27.973145750 +0100
11505 @@ -86,6 +86,8 @@
11506 static initcall_t __initcall_##fn __attribute_used__ \
11507 __attribute__((__section__(".initcall" level ".init"))) = fn
11508
11509 +#define early_initcall(fn) __define_initcall(".early1",fn)
11510 +
11511 #define core_initcall(fn) __define_initcall("1",fn)
11512 #define postcore_initcall(fn) __define_initcall("2",fn)
11513 #define arch_initcall(fn) __define_initcall("3",fn)
11514 diff -urN linux.old/include/linux/pci_ids.h linux.dev/include/linux/pci_ids.h
11515 --- linux.old/include/linux/pci_ids.h 2005-12-15 13:26:49.818001250 +0100
11516 +++ linux.dev/include/linux/pci_ids.h 2005-12-15 12:57:27.977144000 +0100
11517 @@ -1835,6 +1835,7 @@
11518 #define PCI_DEVICE_ID_TIGON3_5901_2 0x170e
11519 #define PCI_DEVICE_ID_BCM4401 0x4401
11520 #define PCI_DEVICE_ID_BCM4401B0 0x4402
11521 +#define PCI_DEVICE_ID_BCM4713 0x4713
11522
11523 #define PCI_VENDOR_ID_TOPIC 0x151f
11524 #define PCI_DEVICE_ID_TOPIC_TP560 0x0000
This page took 0.574982 seconds and 5 git commands to generate.