BCM WL 6.30.102.9 (r366174)
[tomato.git] / release / src-rt / cfe / cfe / arch / mips / board / p5064 / src / sbdreset.S
blobe449f89a174c147923cf911f56ef9b9c902a4078
1 /*
2  * p5064/sbdreset.S: low level code for Algorithmics P5064 board
3  * Copyright (c) 1997 Algorithmics Ltd.
4  */
6 #include <sbmips.h>
7 #include "sbd.h"
8 #include "pio.h"
9 #include "z80pio.h"
10 #include "gpio.h"
11 #include "v96xpbc.h"
12 #include "i82371sb.h"
13 #include "i8254.h"
14 #include "rtc.h"
15 #include "pc97307.h"
16 #include "isapnpreg.h"
17 #include "bsp_config.h"
19 #include "mipsmacros.h"
21 #if !defined(__MIPSEB) && !defined(__MIPSEL)
22 #error "must define MIPSEB or MIPSEL"
23 #endif
25 #define CFG_BE          0x00008000      /* Big Endian */
26 #define MAXREVISION 3
27 #define NTLBENTRIES 64
28         
29 #if defined(__MIPSEL)
30 #define V96X_SWAP_MEM   V96X_SWAP_NONE
31 #define V96X_SWAP_IO    V96X_SWAP_NONE
32 #elif defined(__MIPSEB)
33 #define V96X_SWAP_MEM   V96X_SWAP_8BIT
34 #define V96X_SWAP_IO    V96X_SWAP_AUTO
35 #endif
36         
37 #if !__mips64 && __mips >= 3 && __mips != 32
38         /* force 64-bit register support */
39 #undef __mips64 
40 #define __mips64 1      
41         .set    gp64
42 #endif
43         
44 #define DISPLAY(d0,d1,d2,d3)                    \
45         li      t8,PHYS_TO_K1(LED_BASE);        \
46         li      t9,d0;                          \
47         sw      t9,LED(0)(t8);                  \
48         li      t9,d1;                          \
49         sw      t9,LED(1)(t8);                  \
50         li      t9,d2;                          \
51         sw      t9,LED(2)(t8);                  \
52         li      t9,d3;                          \
53         sw      t9,LED(3)(t8)
55 #define MEG     0x100000                
58  * Data 
59  */
61 #define R_R5K_INITCACHE         _TBLIDX(0)
63 boardinit_table:
64         _LONG_  rm5200_l1cache_init             # [ 0] R_R5K_INITCACHE
67  * Basic board initialisation, called straight from RESET.
68  * It is only called if this program is built for ROM.  
69  * It can use any registers except s8, k0 and k1.
70  *
71  * Note that s8 holds a "relocation factor" (see ../share/romlow.sx)
72  * which must be added to any address before it is used.  This
73  * is to support relocatable roms.
74  */
75         
76 #define tmpsize         s0
77 #define pio_base        s1
78 #define pio_val         s2
79 #define crptr           s3
80 #define crval           s4
81 #define msize           s5
82 #define rasave          s6
83 #define revision        t7
85 LEAF(mips_kseg0_switch)
87                 and     ra,(K0SIZE-1)
88                 or      ra,K0BASE
89                 jr      ra
91 END(mips_kseg0_switch)
93 LEAF(mips_kseg1_switch)
95                 and     ra,(K0SIZE-1)
96                 or      ra,K1BASE
97                 jr      ra
99 END(mips_kseg1_switch)
103 LEAF(board_earlyinit)
104         move    rasave,ra
106         /*
107          * Determine board revision
108          */
111         li      revision,PHYS_TO_K1(OPTION_BASE)
112         lw      revision,0(revision)
113         and     revision,OPTION_REV
114         srl     revision,OPTION_REV_SHIFT
115         bleu    revision,MAXREVISION,1f
116         li      revision,MAXREVISION
117 1:              
119         /* Initialise other low-level I/O devices */
120         LOADREL(a0,reginittab)
121         or      a0,K1BASE
122         sll     v0,revision,2
123         addu    a0,v0
124         lw      a0,0(a0)
125         or      a0,K1BASE
127         bal     reginit
130         move    ra,rasave
131         j       ra
133 END(board_earlyinit)
135 LEAF(board_dram_init)
137         move    rasave,ra
139         /* 
140          * Now determine DRAM configuration and size by
141          * reading the I2C EEROM on the DIMMS
142          */
144         bal     i2creset
145         li      msize,0
146         
147         DISPLAY ('D','I','M','0')
148         
149         /* start with DIMM #0 */
150         li      a0,0
151         li      crval,DCR_SLOW_CAS|DCR_DIMM0
152         
153 .nextdimm:
154         /* read DIMM memory type (must be SDRAM) */
155         li      a1,2
156         bal     i2cread
157         bne     v0,4,.nodimm
158         
159         /* read DIMM memory size per side */
160         li      a1,31
161         bal     i2cread
162         li      tmpsize,4*1024*1024     # memory size unit
163         mul     tmpsize,v0      
164         
165         /* read DIMM number of rows */
166         li      a1,3
167         bal     i2cread
168         bne     v0,11,1f
169         or      crval,DCR_ROWS_11       
170         b       2f
171 1:      bne     v0,12,1f
172         or      crval,DCR_ROWS_12       
173         b       2f
174 1:      bne     v0,13,.nodimm
175         or      crval,DCR_ROWS_13       
176         b       2f
177         
178 2:      /* read DIMM number of cols */
179         li      a1,4
180         bal     i2cread
181         bne     v0,8,1f
182         or      crval,DCR_COLS_8
183         b       2f
184 1:      bne     v0,9,1f
185         or      crval,DCR_COLS_9
186         b       2f
187 1:      bne     v0,10,1f
188         or      crval,DCR_COLS_10
189         b       2f
190 1:      bne     v0,11,.nodimm
191         or      crval,DCR_COLS_11
192         b       2f
193         
194 2:      /* read DIMM number of blocks-per-dram */
195         li      a1,17
196         bal     i2cread
197         bne     v0,2,1f
198         or      crval,DCR_BLOCKS_2
199         b       2f
200 1:      bne     v0,4,.nodimm
201         or      crval,DCR_BLOCKS_4
202         b       2f
203         
204 2:      /* read DIMM number of sides (banks) */
205         li      a1,5
206         bal     i2cread
207         bne     v0,1,1f
208         or      crval,DCR_SINGLE
209         b       2f
210 1:      bne     v0,2,.nodimm
211         b       2f
212         
213         /* msize *= sides (banks) */
214 2:      mul     tmpsize,v0      
215         addu    msize,tmpsize
216         
217 .nodimm:                
218         /* write control register value */
219 /*      la      ta0,PHYS_TO_K1(DCR_BASE)*/
220         li      ta0,PHYS_TO_K1(DCR_BASE)
221         move    ta1,crval
222         bal     crwrite
223         
224         DISPLAY ('D','I','M','1')
225         li      crval,DCR_SLOW_CAS|DCR_DIMM1
226         addu    a0,1
227         bltu    a0,2,.nextdimm
228         
229         /* Panic if we've not got any memory! */
230         bnez    msize,1f
231         DISPLAY ('!','M','E','M')
232 2:      b       2b
233         
234         /* Skip the memory clear if this was a soft reset */
235 1:      mfc0    t1,C0_STATUS
236         and     t1,M_SR_SR
237         bnez    t1,noclear
238         
239         /* We have to clear memory to initialise parity */
241         /* Clear bottom 64K running uncached */
242         DISPLAY ('Z','6','4','K')
243         li      a0,PHYS_TO_K1(0)
244         addu    a1,a0,65536
245         .set noreorder
246 1:      SR      zero,0(a0)
247         SR      zero,REGSIZE(a0)
248         SR      zero,(2*REGSIZE)(a0)
249         addu    a0,REGSIZE*4
250         bne     a0,a1,1b
251         SR      zero,-REGSIZE(a0)
252         .set reorder
253         
254         /* we can now initialise the caches for a fast clear_mem */
255         DISPLAY ('C','A','C','H')
256         CALLINIT_KSEG1(boardinit_table,R_R5K_INITCACHE)
258         /* Finally clear rest of memory running cached */
259         li      a0,PHYS_TO_K1(65536)
260         subu    a1,msize,65536
261         blez    a1,noclear
262         addu    a1,a0
263         
264         /* clear all of memory (to set correct parity) */
265         DISPLAY ('Z','M','E','M')
267         /* run memory clear loop cached */
268         bal     mips_kseg0_switch
269         
270         .set noreorder
271 1:      #cache  Create_Dirty_Exc_D,0(a0)
272         SR      zero,0(a0)
273         SR      zero,REGSIZE(a0)
274         SR      zero,(REGSIZE*2)(a0)
275         addu    a0,REGSIZE*4
276         bne     a0,a1,1b
277         SR      zero,-REGSIZE(a0)
278         .set reorder
280         /* revert to uncached */
281         bal     mips_kseg1_switch
282         
283 noclear:                
284         /* store memory size */
285         move     k0,msize               /* K0 returns the memory size */
286         srl     t0,msize,22     # in 4MB units
287         sb      t0,PHYS_TO_K1(SOFTC_BASE + SOFTC_MEMSZ)
289         li      t0,K1BASE
290         sw      k0,0(t0)                /* store in 1st word of memory */
292 .noinit:
294         move    v0,k0
295         srl     v0,20                   /* return in megabytes */
297         move    ra,rasave
298         j       ra
299 END(board_dram_init)
302 /* crwrite (base, val) 
303  *      Write 8-bit <val> to 8 consecutive 1-bit registers, 
304  *      starting at <base>.
305  * Uses:        t8
306  */
307 SLEAF(crwrite)
308         li      t8,8
309 1:      .set    noat
310         and     AT,ta1,1
311         sll     AT,31
312         sra     AT,31
313         sw      AT,0(ta0)
314         .set    at
315         srl     ta1,1
316         subu    t8,1
317         addu    ta0,4
318         bnez    t8,1b
319         j       ra
320 SEND(crwrite)
321                 
324  * This is the code to read the I2C EEROM on the DIMMS
325  */
326         
327 #define EEABITS         8       /* 256x8 = 8 address bits */
328 #define PGSHIFT         7
329 #define PGMASK          (((0x1 << (EEABITS-8)) - 1) << 1)
330 #define PGNUM(o)        (((o) >> PGSHIFT) & PGMASK)
331 #define OMASK           0xff
332 #define OFFS(o)         ((o) & OMASK)
333 #define READ            0x01
334 #define WRITE           0x00
337 #define SET \
338         bgeu    revision,2,97f; \
339         sw      pio_val,ZPIO_B_DAT(pio_base); \
340         b       98f; \
341 97:     sb      pio_val,GPIO2_DATA(pio_base); \
342 98:             
343         
344 #define BIS(x) \
345         or      pio_val,x; SET
347 #define BIC(x) \
348         and     pio_val,~(x); SET
349         
351  * Max chip frequency = 100 kHz, so we require at least 5 usec
352  * delay between signal changes.
353  */
354 #define WAIT \
355         li      t9,ROMUS(6); \
356         .set noreorder; \
357 10:     bnez    t9,10b; \
358         subu    t9,1; \
359         .set reorder
360         
361 /* set SCL high */
362 #define SCL_HI \
363         WAIT; BIS(PIO_I2C_SCL)
364         
365 /* set SCL low */
366 #define SCL_LO \
367         WAIT; BIC(PIO_I2C_SCL)
368         
369 /* set SDA high */
370 #define SDA_HI \
371         WAIT; BIS(PIO_I2C_SDA)
372         
373 /* set SDA low */
374 #define SDA_LO \
375         WAIT; BIC(PIO_I2C_SDA)
376         
377 /* disable SDA output driver (tristate) */
378 #define SDI \
379         WAIT; \
380         and     pio_val,~PIO_I2C_DIR; \
381         bgeu    revision,2,97f; \
382         li      t9,ZPIO_MODE_CTRL; \
383         sw      t9,ZPIO_B_CTL(pio_base); \
384         li      t9,~PIO_OMASK; \
385         sw      t9,ZPIO_B_CTL(pio_base); \
386         sw      pio_val,ZPIO_B_DAT(pio_base); \
387         b       98f; \
388 97:     li      t9,PIO_OMASK; \
389         sb      t9,GPIO2_DIR(pio_base); \
390         sb      pio_val,GPIO2_DATA(pio_base); \
391 98:                     
392         
393 /* enable SDA output driver (tristate) */
394 #define SDO \
395         WAIT; \
396         or      pio_val,PIO_I2C_DIR; \
397         bgeu    revision,2,97f; \
398         li      t9,ZPIO_MODE_CTRL; \
399         sw      t9,ZPIO_B_CTL(pio_base); \
400         li      t9,~(PIO_I2C_SDA | PIO_OMASK); \
401         sw      t9,ZPIO_B_CTL(pio_base); \
402         sw      pio_val,ZPIO_B_DAT(pio_base); \
403         b       98f; \
404 97:     li      t9,PIO_I2C_SDA | PIO_OMASK; \
405         sb      t9,GPIO2_DIR(pio_base); \
406         sb      pio_val,GPIO2_DATA(pio_base); \
409 /* read SDA */
410 #define SDRD \
411         WAIT; \
412         bgeu    revision,2,97f; \
413         lw      v0,ZPIO_B_DAT(pio_base); \
414         b       98f; \
415 97:     lb      v0,GPIO2_DATA(pio_base); \
416 98:     srl     v0, 7; \
417         and     v0, 1
418         
419 /* send a START: SDA high->low when SCL high */
420 #define START \
421         SDO;    \
422         SDA_HI; \
423         SCL_HI; \
424         SDA_LO; \
425         SCL_LO
427 /* send a STOP: SDA low->high when SCL high */
428 #define STOP \
429         SDO;    \
430         SDA_LO; \
431         SCL_HI; \
432         SDA_HI; \
433         SCL_LO; \
434         SDA_LO; \
435         SDI
437 /* receive an ACK: a single 0 bit */
438 #define GETACK \
439         SCL_HI; \
440         SDRD;   \
441         SCL_LO; \
442         xor v0,1
444 /* send an ACK: a single 0 bit */
445 #define SENDACK \
446         SDO;    \
447         SDA_LO; \
448         SCL_HI; \
449         SCL_LO; \
450         SDI
451         
452 /* send a NACK: a single 1 bit */
453 #define SENDNACK \
454         SDO;    \
455         SDA_HI; \
456         SCL_HI; \
457         SCL_LO; \
458         SDA_LO; \
459         SDI
461 /* send 8 bit word in ta0 (note: check for ACK externally) */
462 SLEAF(i2csend8)
463         li      t0,8
464         SDO
465 1:      and     t1,ta0,0x80
466         beqz    t1,2f
467         SDA_HI
468         b       3f
469 2:      SDA_LO
470 3:      SCL_HI
471         SCL_LO
472         sll     ta0,1
473         subu    t0,1
474         bnez    t0,1b
475         SDA_LO
476         SDI
477         j       ra
478 SEND(i2csend8)
481 /* receive 8 bit word into v0 (note: send ACK/NACK externally) */
482 SLEAF(i2cget8)
483         li      t1,0
484         li      t0,7
485 1:      SCL_HI
486         SDRD
487         SCL_LO
488         sll     v0,t0
489         or      t1,v0
490         subu    t0,1
491         bgez    t0,1b
492         move    v0,t1
493         j       ra
494 SEND(i2cget8)
495         
497 /* DADDR(rw, a0=dev, a1=addr)
498         send first command byte: device address & page number */
499         
500 #define DADDR(rw)                                               \
501         START;                                                  \
502         sll t0,a0,1;            /* t0 = dev << 1 */             \
503         srl ta0,a1,PGSHIFT;     /* ta0 = (addr >> PGSHIFT) */   \
504         and ta0,PGMASK;         /* ta0 &= PGMASK */             \
505         or ta0,t0;              /* ta0 |= (dev << 1) */         \
506         or ta0,(0xa0 | rw);     /* ta0 |= (0xa0 | rw) */        \
507         bal i2csend8;                                           \
508         GETACK
510 /* ADDR(rw, a0=dev, a1=addr)
511         send two command bytes */
512         
513 #define ADDR(rw)                                                \
514         /* timeout for previous write to complete */            \
515         li t3,1000;                                             \
516                                                                 \
517         /* send first byte: device address */                   \
518 1:      DADDR(rw);                                              \
519         bnez v0, 2f;                                            \
520         /* no acknowledge - count down */                       \
521         subu t3,1;                                              \
522         beqz t3,99f;                                            \
523         b 1b;                                                   \
524                                                                 \
525 2:      /* send second byte: word offset */                     \
526         and ta0,a1,OMASK;       /* offset in page */            \
527         bal i2csend8;                                           \
528         GETACK;                                                 \
531         
532 SLEAF(i2creset)
533         /* initialise global registers */
535         bgeu    revision,2,97f
536         
537         li      pio_base,PHYS_TO_K1(ZPIO_BASE)
538         b       98f
540 97:     li      pio_base,PHYS_TO_K1(ISAPORT_BASE(GPIO_PORT))
541         
542 98:     li      pio_val,0
543         
544         /* send 9 STOPS */
545         li      t0,9
546 1:      STOP
547         subu    t0,1
548         bnez    t0,1b
549         
550         j       ra
551 SEND(i2creset)
552         
554 /* i2cread (unsigned dev, unsigned offs) */
555 SLEAF(i2cread)  
556         move    t8,ra
557         
558         ADDR(WRITE)             # write address
559         beqz    v0,9f           # ack?
560         
561         DADDR(READ)             # start read
562         beqz    v0,9f           # ack?
563         
564         bal     i2cget8         # get data byte
565         
566         SENDNACK                # terminate read
567         STOP
568         
569         j       t8
570         
571 9:      li      v0,-1
572         j       t8
573 SEND(i2cread)   
574         
577         .lcomm  wbfltmp,4
579 LEAF(wbflush)
580         sync
581         la      t0,wbfltmp
582         or      t0,K1BASE
583         lw      zero,0(t0)
584         j       ra
585 END(wbflush)
588 LEAF(sbddelay)
589         mfc0    t0,C0_CONFIG
590         li      t1,CACHEMISS+ROMCYCLE
591         and     t0,M_CFG_K0COH
592         beq     t0,V_CFG_K0COH(K_CFG_K0COH_UNCACHED),1f
593         and     t0,ra,0x20000000
594         bnez    t0,1f
595         li      t1,CACHECYCLE
596 1:      mul     a0,1000
597         addu    a0,t1
598         sll     t1,1
599         divu    a0,t1
600         subu    a0,48           # approx number of loops so far
601         .set    noreorder       
602         .set    nomacro
603         nop
604 2:      bgtz    a0,2b
605         subu    a0,1
606         .set    macro
607         .set    reorder
608         j       ra
609 END(sbddelay)
612 LEAF(mips_cycle)
613         .set    noreorder       
614         .set    nomacro
615 1:      bgtz    a0,1b
616         subu    a0,1
617         .set    macro
618         .set    reorder
619         j       ra
620 END(mips_cycle)
624 #define MOD_B           0x00000000 /* byte "modifier" */
625 #define MOD_H           0x00000001 /* halfword "modifier" */
626 #define MOD_W           0x00000002 /* word "modifier" */
627 #define MOD_D           0x00000003 /* doubleword "modifier" */
628 #define MOD_MASK        0x00000003
630 #define OP_MASK         0x000000fc
631 #define OP_EXIT         0x00000000 /* exit(status) */
632 #define OP_DELAY        0x00000008 /* delay(cycles) */
633 #define OP_RD           0x00000010 /* read (addr)) */
634 #define OP_WR           0x00000014 /* write (addr, val) */
635 #define OP_RMW          0x00000018 /* read-modify-write (addr, and, or) */
636 #define OP_WAIT         0x00000020 /* poll (addr, mask, value) */
638 #define Init_Op 0
639 #define Init_A0 4
640 #define Init_A1 8
641 #define Init_A2 12
642 #define Init_Size 16
643         
646 SLEAF(reginit)
647         lw      t3, Init_Op(a0)
648         lw      t0, Init_A0(a0)
649         and     t4, t3,OP_MASK
650         
651         bne     t4, OP_EXIT, 8f
652         /* exit(status) */
653         move    v0,t0
654         b       9f
656 8:      bne     t4, OP_DELAY, 8f
657         /* delay(cycles) */
658         .set noreorder
659 1:      bnez    t0,1b
660         subu    t0,1
661         .set reorder
662         addu    a0,Init_Size
663         b       reginit
664         
665 8:      bne     t4,OP_RD,8f
666         /* read(addr) */
667         and     t4,t3,MOD_MASK
668         bnez    t4,1f
669         lbu     zero,0(t0)
670         b       2f
671 1:      subu    t4,1
672         bnez    t4,1f
673         lhu     zero,0(t0)
674         b       2f
675 1:      subu    t4,1
676         bnez    t4,1f
677         lw      zero,0(t0)
678 #if __mips64
679         b       2f
680 1:      ld      zero,0(t0)
681 #endif
682 2:      addu    a0,Init_Size
683         b       reginit
684         
685 8:      bne     t4,OP_WR,8f
686         /* write(addr,val) */
687         lw      t1,Init_A1(a0)
688         and     t4,t3,MOD_MASK
689         bnez    t4,1f
690         sb      t1,0(t0)
691         b       2f
692 1:      subu    t4,1
693         bnez    t4,1f
694         sh      t1,0(t0)
695         b       2f
696 1:      subu    t4,1
697         bnez    t4,1f
698         sw      t1,0(t0)
699 #if __mips64
700         b       2f
701 1:      sd      t1,0(t0)
702 #else
703 1:                      
704 #endif
705 2:      addu    a0,Init_Size
706         b       reginit
707         
708 8:      bne     t4,OP_RMW,8f
709         /* write(addr,val) */
710         lw      t1,Init_A1(a0)
711         lw      t2,Init_A2(a0)
712         and     t4,t3,MOD_MASK
713         bnez    t4,1f
714         lbu     t4,0(t0)
715         and     t4,t1
716         or      t4,t2
717         sb      t4,0(t0)
718         b       2f
719 1:      subu    t4,1
720         bnez    t4,1f
721         lhu     t4,0(t0)
722         and     t4,t1
723         or      t4,t2
724         sh      t4,0(t0)
725         b       2f
726 1:      subu    t4,1
727         bnez    t4,1f
728         lw      t4,0(t0)
729         and     t4,t1
730         or      t4,t2
731         sw      t4,0(t0)
732 #if __mips64
733         b       2f
734 1:      ld      t4,0(t0)
735         and     t4,t1
736         or      t4,t2
737         sd      t4,0(t0)
738 #else
739 1:                      
740 #endif
741 2:      addu    a0,Init_Size
742         b       reginit
743         
744 8:      li      v0,-1           
745 9:      j       ra      
746         
747 SEND(reginit)
749 #define WR_INIT(mod,addr,val) \
750         .word   OP_WR|MOD_##mod,PHYS_TO_K1(addr),(val),0
751 #define DELAY_INIT(cycles) \
752         .word   OP_DELAY,(cycles),0,0
753 #define EXIT_INIT(status) \
754         .word   OP_EXIT,(status),0,0
755         
756 #define V96XWR_INIT(mod,v96xreg,val) \
757         WR_INIT(mod,V96XPBC_BASE+(v96xreg),val)
759 #define ISABWR_INIT(mod,isabreg,val) \
760         WR_INIT(mod,PCI_CONF_SPACE+(isabreg),val)
761         
762 #define ISAWR_INIT(mod,isareg,val) \
763         WR_INIT(mod,PCI_IO_SPACE+(isareg),val)
764         
765 #define DISPLAY_INIT(a,b,c,d) \
766         WR_INIT(W, LED_BASE+LED(0), 0+a); \
767         WR_INIT(W, LED_BASE+LED(1), 0+b); \
768         WR_INIT(W, LED_BASE+LED(2), 0+c); \
769         WR_INIT(W, LED_BASE+LED(3), 0+d)
771 /*      .rdata*/                    /* this RO data can go in text section */
772         .text
773         .globl reginittab
774         
775 reginittab:
776         .word   reginittabRevA  
777         .word   reginittabRevB
778         .word   reginittabRevC
779         .word   reginittabRevD
781 /* 15us ISA bus refresh clock */
782 #define ISAREFRESH (PT_CRYSTAL/(1000000/15))
783         
784 reginittabRevA: 
785 reginittabRevB: 
786         /* Set i/o system endianness first with a 64-bit write */
787 #if __mips64    
788 #ifdef __MIPSEB
789         WR_INIT(D, BCR0_BASE + BCR0_ENDIAN, BCR0_ENDIAN_BE)
790 #else
791         WR_INIT(D, BCR0_BASE + BCR0_ENDIAN, BCR0_ENDIAN_LE)
792 #endif  
793 #else
794 #ifdef __MIPSEB
795         WR_INIT(W, BCR0_BASE + BCR0_ENDIAN + 4, BCR0_ENDIAN_BE)
796 #else
797         WR_INIT(W, BCR0_BASE + BCR0_ENDIAN + 0, BCR0_ENDIAN_LE)
798 #endif  
799 #endif          
800         /* switch on the LED */
801         WR_INIT(W, BCR0_BASE + BCR0_LED, BCR0_LED_ON)
802         
803         /* first ever led message */
804         DISPLAY_INIT('P','5','6','4')
805         
806         /* toggle the V3 reset */
807         WR_INIT(W, BCR1_BASE + BCR1_V96X, BCR1_ENABLE)
808         WR_INIT(W, BCR1_BASE + BCR1_V96X, BCR1_RESET)
809         WR_INIT(W, BCR1_BASE + BCR1_V96X, BCR1_ENABLE)
810         
811         /* initialise the z80pio chip, B channel */
812         WR_INIT(W, ZPIO_BASE + ZPIO_B_CTL, ZPIO_MODE_CTRL)      # bidir control mode
813         WR_INIT(W, ZPIO_BASE + ZPIO_B_CTL, ~PIO_OMASK)          # ip msk = ~op mask
814         WR_INIT(W, ZPIO_BASE + ZPIO_B_DAT, 0)                   # initial op value
815         
816         /* enable the ISA bridge */
817         WR_INIT(W, BCR1_BASE + BCR1_ISA, BCR1_ENABLE)
818         
819         /* enable the PCMCIA controller */
820         WR_INIT(W, BCR1_BASE + BCR1_PCMCIA, BCR1_ENABLE)
821                 
822         /* > 18.5ms delay while V3 attempts to read EEROM... */
823         DELAY_INIT(ROMMS(20))
824         
825         /*
826          * Setup a bare minimum to allow us to get at the i/o
827          * registers on the Intel PCI->ISA bridge, ISA bus
828          * and XBUS.
829          */
830         DISPLAY_INIT('V','9','6','X')
831         
832         /* initial magic cycle for PCI bridge */
833         V96XWR_INIT(W, V96X_LB_IO_BASE, V96XPBC_BASE+V96X_LB_IO_BASE)
834         
835         /* Local bus to PCI aptr 2 - LOCAL:PCI_IO_SPACE -> PCI:00000000 */
836         V96XWR_INIT(H, V96X_LB_BASE2, \
837                 (PCI_IO_SPACE >> 16)|(V96X_SWAP_IO >> 2)|V96X_LB_BASEx_ENABLE)
838         V96XWR_INIT(H, V96X_LB_MAP2, 0)
839         
840         /* Local to PCI aptr 0 - LOCAL:PCI_CONF_SPACE -> PCI:config (1MB) */
841         V96XWR_INIT(W, V96X_LB_BASE0, \
842                 PCI_CONF_SPACE | V96X_SWAP_IO | V96X_ADR_SIZE_1MB | V96X_LB_BASEx_ENABLE)
844         /* high 12 bits of conf space address go in map reg */
845         V96XWR_INIT(H, V96X_LB_MAP0, \
846                 ((1 << (8+PCI_IDSEL_I82371)) & V96X_LB_MAPx_MAP_ADR) | V96X_LB_TYPE_CONF)
848         /* Enable PCI bus master access */
849         V96XWR_INIT(H, V96X_PCI_CMD, V96X_PCI_CMD_MASTER_EN)
851         /* Unreset the PCI bus */
852         V96XWR_INIT(H, V96X_SYSTEM, V96X_SYSTEM_RST_OUT);
854         /* 2ms reset delay */
855         DELAY_INIT(ROMMS(2))
857         /* 
858          * Initialise the ISA bridge via its CONF space
859          */
860         
861         DISPLAY_INIT ('I','S','A','B')
862         
863         /* Enable PCI 2.1 timing support */
864         ISABWR_INIT(B, I82371_DLC, \
865                         I82371_DLC_DT | I82371_DLC_PR | I82371_DLC_USBPR | I82371_DLC_DTTE)
867         /* Enable USB function, and force SYSCLK=PCICLK/4 */
868         ISABWR_INIT(H, I82371_MSTAT, I82371_MSTAT_USBE|I82371_MSTAT_ISADIV_4);
869         
870         /* Programmable decode for Centronics input latch */
871         ISABWR_INIT(H, I82371_PCSC, CEN_LATCH_PORT|I82371_PCSC_SIZE_4)
873         /* Set top of memory to 16MB, so all ISA bus master & DMA
874            accesses are forwarded to PCI mem space, except for the
875            hole from 640K (A0000) to 1MB, which is confined to ISA */
876         ISAWR_INIT (B, I82371_TOM, I82371_TOM_TOM(16) | I82371_TOM_FWD_89)
877         
878         /* Initialise ISA bus low-level I/O devices */
879         DISPLAY_INIT('I','S','A','R')
881         /* program i8254 ISA refresh counter */
882         ISAWR_INIT(B,CTC_PORT+PT_CONTROL, \
883                 PTCW_SC(PT_REFRESH)|PTCW_16B|PTCW_MODE(MODE_RG))
884         ISAWR_INIT(B,CTC_PORT+PT_REFRESH, ISAREFRESH & 0xff)
885         ISAWR_INIT(B,CTC_PORT+PT_REFRESH, ISAREFRESH >> 8)
886         
887         /* setup 32kHz refresh for our DRAM */
888         ISAWR_INIT(B,RTC_ADDR_PORT, RTC_STATUSA)
889          ISAWR_INIT(B,RTC_DATA_PORT, RTC_OSC_32KHz)
890         ISAWR_INIT(B,RTC_ADDR_PORT, RTC_STATUSB)
891          ISAWR_INIT(B,RTC_DATA_PORT, RTCSB_SQWE)
892         ISAWR_INIT(B,RTC_ADDR_PORT, RTC_INTR)                   
893          ISAWR_INIT(B,RTC_DATA_PORT, RTCIR_32KE)
895         /* Completed */
896         DISPLAY_INIT('d','o','n','e')
897                 
898         EXIT_INIT(0)
899         
901 reginittabRevC: 
902 reginittabRevD: 
903         /* Set i/o system endianness first with a 64-bit write */
904 #ifdef __MIPSEB
905         WR_INIT(D, BCR0_BASE + BCR0_ENDIAN, BCR0_ENDIAN_BE)
906 #else
907         WR_INIT(D, BCR0_BASE + BCR0_ENDIAN, BCR0_ENDIAN_LE)
908 #endif  
909         
910         /* switch on the LED */
911         WR_INIT(W, BCR0_BASE + BCR0_LED, BCR0_LED_ON)
912         
913         /* first ever led message */
914         DISPLAY_INIT('P','5','6','4')
915         
916         /* toggle the V3 reset */
917         WR_INIT(W, BCR1_BASE + BCR1_V96X, BCR1_ENABLE)
918         WR_INIT(W, BCR1_BASE + BCR1_V96X, BCR1_RESET)
919         WR_INIT(W, BCR1_BASE + BCR1_V96X, BCR1_ENABLE)
920         
921         /* enable the ISA bridge */
922         WR_INIT(W, BCR1_BASE + BCR1_ISA, BCR1_ENABLE)
923         
924         /* enable the PCMCIA controller */
925         WR_INIT(W, BCR1_BASE + BCR1_PCMCIA, BCR1_ENABLE)
926                 
927         /* > 18.5ms delay while V3 attempts to read EEROM... */
928         DELAY_INIT(ROMMS(20))
929         
930         /*
931          * Setup a bare minimum to allow us to get at the i/o
932          * registers on the Intel PCI->ISA bridge, ISA bus
933          * and XBUS.
934          */
935         DISPLAY_INIT('V','9','6','X')
936         
937         /* initial magic cycle for PCI bridge */
938         V96XWR_INIT(W, V96X_LB_IO_BASE, V96XPBC_BASE+V96X_LB_IO_BASE)
939         
940         /* Local bus to PCI aptr 2 - LOCAL:PCI_IO_SPACE -> PCI:00000000 */
941         V96XWR_INIT(H, V96X_LB_BASE2, \
942                 (PCI_IO_SPACE >> 16)|(V96X_SWAP_IO >> 2)|V96X_LB_BASEx_ENABLE)
943         V96XWR_INIT(H, V96X_LB_MAP2, 0)
944         
945         /* Local to PCI aptr 0 - LOCAL:PCI_CONF_SPACE -> PCI:config (1MB) */
946         V96XWR_INIT(W, V96X_LB_BASE0, \
947                 PCI_CONF_SPACE | V96X_SWAP_IO | V96X_ADR_SIZE_1MB | V96X_LB_BASEx_ENABLE)
949         /* high 12 bits of conf space address go in map reg */
950         V96XWR_INIT(H, V96X_LB_MAP0, \
951                 ((1 << (8+PCI_IDSEL_I82371)) & V96X_LB_MAPx_MAP_ADR) | V96X_LB_TYPE_CONF)
953         /* Enable PCI bus master access */
954         V96XWR_INIT(H, V96X_PCI_CMD, V96X_PCI_CMD_MASTER_EN)
956         /* Unreset the PCI bus */
957         V96XWR_INIT(H, V96X_SYSTEM, V96X_SYSTEM_RST_OUT);
959         /* 2ms reset delay */
960         DELAY_INIT(ROMMS(2))
962         /* 
963          * Initialise the ISA bridge via its CONF space
964          */
965         
966         DISPLAY_INIT ('I','S','A','B')
967         
968         /* Enable PCI 2.1 timing support */
969         ISABWR_INIT(B, I82371_DLC, \
970                         I82371_DLC_DT | I82371_DLC_PR | I82371_DLC_USBPR | I82371_DLC_DTTE)
972         /* Enable USB function, and force SYSCLK=PCICLK/4 */
973         ISABWR_INIT(H, I82371_MSTAT, I82371_MSTAT_USBE|I82371_MSTAT_ISADIV_4);
974         
975         /* Programmable decode for Centronics input latch */
976         ISABWR_INIT(H, I82371_PCSC, CEN_LATCH_PORT|I82371_PCSC_SIZE_4)
978         /* Set top of memory to 16MB, so all ISA bus master & DMA
979            accesses are forwarded to PCI mem space, except for the
980            hole from 640K (A0000) to 1MB, which is confined to ISA */
981         ISAWR_INIT (B, I82371_TOM, I82371_TOM_TOM(16) | I82371_TOM_FWD_89 | I82371_TOM_FWD_AB)
983         /* Initialise ISA bus low-level I/O devices */
984         DISPLAY_INIT('I','S','A','R')
986         /* program i8254 ISA refresh counter */
987         ISAWR_INIT(B,CTC_PORT+PT_CONTROL, \
988                 PTCW_SC(PT_REFRESH)|PTCW_16B|PTCW_MODE(MODE_RG))
989         ISAWR_INIT(B,CTC_PORT+PT_REFRESH, ISAREFRESH & 0xff)
990         ISAWR_INIT(B,CTC_PORT+PT_REFRESH, ISAREFRESH >> 8)
991         
992         /* set up ISA devices */
994         /* select logical device 0 (keyboard) */        
995         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
996         ISAWR_INIT(B,ISAPNP_MBDATA,0)
997         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_ACTIVATE)
998         ISAWR_INIT(B,ISAPNP_MBDATA,1)
1000         /* select logical device 1 (mouse) */   
1001         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
1002         ISAWR_INIT(B,ISAPNP_MBDATA,1)
1003         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_ACTIVATE)
1004         ISAWR_INIT(B,ISAPNP_MBDATA,1)
1005         
1006         /* select logical device 4 (parallel) */        
1007         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
1008         ISAWR_INIT(B,ISAPNP_MBDATA,4)
1009         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_15_8)
1010         ISAWR_INIT(B,ISAPNP_MBDATA,(ECP_PORT>>8) & 0xff)
1011         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_7_0)
1012         ISAWR_INIT(B,ISAPNP_MBDATA,ECP_PORT & 0xff)
1013         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_IRQ_DESC0+ISAPNP_IRQ_CONTROL)
1014         ISAWR_INIT(B,ISAPNP_MBDATA,ISAPNP_IRQ_HIGH)
1015         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_ACTIVATE)
1016         ISAWR_INIT(B,ISAPNP_MBDATA,1)
1017         
1018         /* select logical device 5 (COM2) */    
1019         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
1020         ISAWR_INIT(B,ISAPNP_MBDATA,5)
1021         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_ACTIVATE)
1022         ISAWR_INIT(B,ISAPNP_MBDATA,1)
1023         
1024         /* select logical device 6 (COM1) */    
1025         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
1026         ISAWR_INIT(B,ISAPNP_MBDATA,6)
1027         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_ACTIVATE)
1028         ISAWR_INIT(B,ISAPNP_MBDATA,1)
1029         
1030         /* select logical device 7 (PIO) */     
1031         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
1032         ISAWR_INIT(B,ISAPNP_MBDATA,7)
1033         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_15_8)
1034         ISAWR_INIT(B,ISAPNP_MBDATA,(GPIO_PORT>>8) & 0xff)
1035         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_7_0)
1036         ISAWR_INIT(B,ISAPNP_MBDATA,GPIO_PORT & 0xff)
1037         ISAWR_INIT(B,ISAPNP_MBADDR,ISAPNP_ACTIVATE)
1038         ISAWR_INIT(B,ISAPNP_MBDATA,1)
1039         
1040         /* set default configuration for GPIO2 */
1041         ISAWR_INIT(B,GPIO_PORT+GPIO2_OTYPE, 0xff)
1042         ISAWR_INIT(B,GPIO_PORT+GPIO2_PULLUP, 0)
1043         ISAWR_INIT(B,GPIO_PORT+GPIO2_DIR, GPIO2_OMASK)
1044         ISAWR_INIT(B,GPIO_PORT+GPIO2_DATA, 0)
1045         
1046         /* Completed */
1047         DISPLAY_INIT('d','o','n','e')
1048                 
1049         EXIT_INIT(0)
1050         
1051