GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / arch / mips / board / p6064 / src / sbdreset.S
blob4e2427eae433100a0f083acbcfb4a146fe50ee6a
1 /*
2  * p6032/sbdreset.sx: low level reset code for P-6032/P-6064
3  *
4  * Copyright (c) 2000 Algorithmics Ltd - all rights reserved.
5  * 
6  * This program is free software; you can redistribute it and/or modify 
7  * it under the terms of the "Free MIPS" License Agreement, a copy of 
8  * which is available at:
9  *
10  *  http://www.algor.co.uk/ftp/pub/doc/freemips-license.txt
11  *
12  * You may not, however, modify or remove any part of this copyright 
13  * message if this program is redistributed or reused in whole or in
14  * part.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * "Free MIPS" License for more details.  
20  */
22 #define P60XX_I2C
23 #define P60XX_PARITY
25 #include "sbmips.h"             
26 #include "sbd.h"
28 #include "hd2532.h"
29 #include "i82371eb.h"
30 #include "i8254.h"
31 #include "pc97307.h"
32 #include "isapnpreg.h"
33 #include "pcireg.h"
34 #define PCI_MAP_IO 1
35 #include "prid.h"
36 #include "mipsmacros.h"
39  * R4000 Config Register 
40  */
41 //#ifndef CFG_ECMASK
42 #define CFG_CM          0x80000000      /* Master-Checker mode */
43 #define CFG_ECMASK      0x70000000      /* System Clock Ratio */
44 #define CFG_ECSHIFT     28
45 #define CFG_ECBY2       0x00000000      /* divide by 2 */
46 #define CFG_ECBY3       0x00000000      /* divide by 3 */
47 #define CFG_ECBY4       0x00000000      /* divide by 4 */
48 #define CFG_EPMASK      0x0f000000      /* Transmit data pattern */
49 #define CFG_EPD         0x00000000      /* D */
50 #define CFG_EPDDX       0x01000000      /* DDX */
51 #define CFG_EPDDXX      0x02000000      /* DDXX */
52 #define CFG_EPDXDX      0x03000000      /* DXDX */
53 #define CFG_EPDDXXX     0x04000000      /* DDXXX */
54 #define CFG_EPDDXXXX    0x05000000      /* DDXXXX */
55 #define CFG_EPDXXDXX    0x06000000      /* DXXDXX */
56 #define CFG_EPDDXXXXX   0x07000000      /* DDXXXXX */
57 #define CFG_EPDXXXDXXX  0x08000000      /* DXXXDXXX */
58 #define CFG_SBMASK      0x00c00000      /* Secondary cache block size */
59 #define CFG_SBSHIFT     22
60 #define CFG_SB4         0x00000000      /* 4 words */
61 #define CFG_SB8         0x00400000      /* 8 words */
62 #define CFG_SB16        0x00800000      /* 16 words */
63 #define CFG_SB32        0x00c00000      /* 32 words */
64 #define CFG_EMMASK      0x00c00000      /* Vr54xx: SysAD mode */
65 #define CFG_EMSHIFT     22
66 #define CFG_EM_R4K      0x00000000      /* Vr54xx: R4x000 compatible */
67 #define CFG_EM_SPLITRD  0x00400000      /* Vr54xx: Multiple split reads */
68 #define CFG_EM_PIPEWR   0x00800000      /* Vr54xx: Pipeline writes */
69 #define CFG_EM_WRREISSU 0x00c00000      /* Vr54xx: Write-reissue */
70 #define CFG_AD          0x00800000      /* Accelerated data (R4100) */
71 #define CFG_SS          0x00200000      /* Split secondary cache */
72 #define CFG_SW          0x00100000      /* Secondary cache port width */
73 #define CFG_EWMASK      0x000c0000      /* System port width */
74 #define CFG_EWSHIFT     18
75 #define CFG_EW64        0x00000000      /* 64 bit */
76 #define CFG_EW32        0x00040000      /* 32 bit */
77 #define CFG_SC          0x00020000      /* Secondary cache absent */
78 #define CFG_SM          0x00010000      /* Dirty Shared mode disabled */
79 #define CFG_BE          0x00008000      /* Big Endian */
80 #define CFG_EM          0x00004000      /* ECC mode enable */
81 #define CFG_EB          0x00002000      /* Block ordering */
82 #define CFG_ICMASK      0x00000e00      /* Instruction cache size */
83 #define CFG_ICSHIFT     9
84 #define CFG_DCMASK      0x000001c0      /* Data cache size */
85 #define CFG_DCSHIFT     6
86 #define CFG_IB          0x00000020      /* Instruction cache block size */
87 #define CFG_DB          0x00000010      /* Data cache block size */
88 #define CFG_CU          0x00000008      /* Update on Store Conditional */
89 #define CFG_K0MASK      0x00000007      /* KSEG0 coherency algorithm */
90 //#endif
93  * Primary cache mode
94  */
95 #define CFG_C_WTHRU_NOALLOC     0       /* r4600 only */
96 #define CFG_C_WTHRU_ALLOC       1       /* r4600 only */
97 #define CFG_C_UNCACHED          2
98 #define CFG_C_NONCOHERENT       3
99 #define CFG_C_WBACK             3
100 #define CFG_C_COHERENTXCL       4
101 #define CFG_C_COHERENTXCLW      5
102 #define CFG_C_COHERENTUPD       6       /* r4000/r4400 only */
103 #define CFG_C_UNCACHED_ACCEL    7       /* t5 only */
106                 
107 //#undef DBGSBD
108 #define DBGSBD 0
109         
110 /* CPU-specific bootmode bitstreams */  
111 #ifdef __MIPSEB
112 #define BOOTMODE_RM7000         0x02034100
113 #define BOOTMODE_RM52XX         0x00230100
114 #define BOOTMODE_R4650          0x00001100
115 #define BOOTMODE_RC6447X        0x00001100
116 #define BOOTMODE_RC6457X        0x06001100
117 #else
118 #define BOOTMODE_RM7000         0x02034000
119 #define BOOTMODE_RM52XX         0x00230000
120 #define BOOTMODE_R4650          0x00001000
121 #define BOOTMODE_RC6447X        0x00001000
122 #define BOOTMODE_RC6457X        0x06001000
123 #endif
124         
125 #define WBFLUSH 
127 #define MEG     0x100000                
128         
129 #define DISPLAY(d0,d1,d2,d3,d4,d5,d6,d7) \
130         li      t8,PHYS_TO_K1(LED_BASE+HD2532_CRAM);    \
131         li      t9,d0;                          \
132         sw      t9,HD2532_CHAR(0)(t8);          \
133         li      t9,d1;                          \
134         sw      t9,HD2532_CHAR(1)(t8);          \
135         li      t9,d2;                          \
136         sw      t9,HD2532_CHAR(2)(t8);          \
137         li      t9,d3;                          \
138         sw      t9,HD2532_CHAR(3)(t8);          \
139         li      t9,d4;                          \
140         sw      t9,HD2532_CHAR(4)(t8);          \
141         li      t9,d5;                          \
142         sw      t9,HD2532_CHAR(5)(t8);          \
143         li      t9,d6;                          \
144         sw      t9,HD2532_CHAR(6)(t8);          \
145         li      t9,d7;                          \
146         sw      t9,HD2532_CHAR(7)(t8)
148         
150 #if !defined(DBGSBD)
151 #define DBGDISPLAY(d0,d1,d2,d3,d4,d5,d6,d7)
152 #define DBGLA(reg, label)
153 #define DBGLW(reg, label)
154 #define DBGSTRING(label, string)
155 #define DBGTSTRING(string)
156 #define DBGLSTR(reg, string)
157 #define DBGPSTR(string)
158 #else   
159 #define DBGDISPLAY(d0,d1,d2,d3,d4,d5,d6,d7) \
160         DISPLAY(d0,d1,d2,d3,d4,d5,d6,d7); \
161         li      t8,ROMMS(500); \
162         .set    noreorder; \
163 99:     bnez    t8,99b; \
164         subu    t8,1; \
165         .set    reorder
167 #define DBGLA(reg, label)        \
168         LOADREL(reg,label);              \
169         or      reg,K1BASE
170                 
171 #define DBGLW(reg, label)       \
172         DBGLA(reg,label);       \
173         lw      reg,0(reg)
175 #define DBGSTRING(label, string)        \
176         .rdata;                 \
177 label:  .asciiz string;         \
178         .previous
179         
180 #define DBGTSTRING(string)              \
181         .rdata;                 \
182         .word   9f;             \
183         .section .rodata1;      \
184 9:      .asciiz string
186 #define DBGLSTR(reg, string)    \
187         DBGLA(reg,9f);          \
188         DBGSTRING(9,string)
190 /* print a string */
191 #define DBGPSTR(string) \
192         DBGLSTR(a0,string);             \
193         bal     rom_prs
194         
195 #include "ns16550.h"
196         
197 #define TXWAIT          10000
198         
199 #ifndef NS16550_INB
200 #define NS16550_INB(dst,offs,base) \
201         lbu     dst,offs(base)
202 #endif
203         
204 #ifndef NS16550_OUTB
205 #define NS16550_OUTB(src,offs,base) \
206         sb      src,offs(base)
207 #endif
209         .text
210 reset_table:
211         _LONG_  reginit 
212         
214  * rom_outch (int c)
215  * Print a character on console device
216  */
217 SLEAF(rom_outch)
218         /* blocking transmit, with timeout */
219         li      t0,TXWAIT                       # timeout
220         li      t1,PHYS_TO_K1(UART0_BASE)
221 1:      NS16550_INB(v0,LSR,t1)                  # get LSR
222         and     v0,LSR_TXRDY                    # tx ready?
223         bnez    v0,1f                           # yup - go and write
224         subu    t0,1                            # continue until timeout
225         bnez    t0,1b
226 1:      NS16550_OUTB(a0,DATA,t1)                # write data
227         j       ra
228 SEND(rom_outch)
229         
232  * rom_prnl ()
233  * Print <CR, LF> on console device
234  */
235 LEAF(rom_prnl)
236         move    t7,ra
237         li      a0,'\r'
238         bal     rom_outch
239         li      a0,'\n'
240         bal     rom_outch
241         j       t7
242 END(rom_prnl)
246  * rom_prs (char *s)
247  * Print a string on console device
248  */
249 LEAF(rom_prs)
250         move    t7,ra
251         move    t6,a0
253 1:      lbu     a0,0(t6)
254         beqz    a0,2f
255         bal     rom_outch
256         addu    t6,1
257         b       1b
259 2:      j       t7
260 END(rom_prs)
264  * rom_prx (unsigned int x, unsigned int log2size)
265  * Print a register on console device as hex digits
266  */
267 LEAF(rom_prx)
268         move    t7,ra
269         
270         li      t5,8                    # t5 = bitcnt = 8 << log2size
271         sll     t5,a1                   
272         
273 #if __mips64
274         li      t6,64                   # t6 = regsize - bitcnt
275         subu    t6,t5
276         dsll    t6,a0,t6                # get sig part of a0 to top of t6
277 1:      dsrl    a0,t6,60                # get top 4 bits
278         addu    a0,'0'
279         ble     a0,'9',2f
280         addu    a0,'A'-'0'-10
281 2:      bal     rom_outch
282         dsll    t6,4
283         subu    t5,4
284         bnez    t5,1b
285 #else
286         li      t6,32                   # t6 = regsize - bitcnt
287         subu    t6,t5
288         sll     t6,a0,t6                # get sig part of a0 to top of t6
289 1:      srl     a0,t6,28                # get top 4 bits
290         addu    a0,'0'
291         ble     a0,'9',2f
292         addu    a0,'A'-'0'-10
293 2:      bal     rom_outch
294         sll     t6,4
295         subu    t5,4
296         bnez    t5,1b
297 #endif  
298         
299         j       t7
300 END(rom_prx)
302 SLEAF(_rom_consinit)
303         li      v0,PHYS_TO_K1(UART0_BASE)
304         # enable 16550 fifo if it is there
305         li      t0,FIFO_ENABLE|FIFO_RCV_RST|FIFO_XMT_RST|FIFO_TRIGGER_4
306         NS16550_OUTB(t0,FIFO,v0)
307         
308         # 100us delay 
309         .set    noreorder
310         li      t0,CACHEUS(100)
311 1:      bnez    t0,1b
312         subu    t0,1
313         .set    reorder
314         
315         li      a1,9600
317         /* wait for all tx data to be sent */
318         li      t0,TXWAIT
319 1:      NS16550_INB(t1,LSR,v0)
320         and     t1,LSR_TSRE
321         bnez    t1,2f
322         subu    t0,1
323         bnez    t0,1b
324         
325         /* convert baud rate in a1 into register value */
326 2:      beqz    a1,.fail                        # don't want divide error
327         li      t2,NS16550_HZ/16                # brtc = CLK/16/speed
328         divu    t2,a1
329         blez    t2,.fail                        # brtc must be > 0
330         
331         li      t0,CFCR_DLAB                    # select brtc divisor
332         NS16550_OUTB(t0,CFCR,v0)                        
333         NS16550_OUTB(t2,DLL,v0)                 # store divisor lsb
334         srl     t2,8    
335         NS16550_OUTB(t2,DLM,v0)                 # store divisor msb
336         li      t0,CFCR_8BITS                   # set 8N1 mode
337         NS16550_OUTB(t0,CFCR,v0)
338         
339         li      t0,MCR_DTR|MCR_RTS|MCR_IENABLE  # enable DTR & RTS
340         NS16550_OUTB(t0,MCR,v0)
341         
342         li      t0,IER_ERXRDY                   # enable receive interrupt(!)
343         NS16550_OUTB(t0,IER,v0)
344         
345         move    v0,zero                         # indicate success
346         j       ra
347         
348 .fail:  li      v0,1
349         j       ra
350         
351 SEND(_rom_consinit)                     
352 #endif
353         
355  * Basic board initialisation, called straight from RESET.
356  * It is only called if this program is built for ROM.  
357  * It can use any registers except s8, k0 and k1.
359  * Note that s8 holds a "relocation factor" (see ../share/romlow.sx)
360  * which must be added to any address before it is used.  This
361  * is to support relocatable roms.
362  */
363         
364 #define tmpsize         s0
365 #define msize           s1
366 #define sdShape         s2
367 #define bonito          s3
368 #define dbg             s4
369 #define sdCfg           s5
370 #define rasave          s7
372 LEAF(board_earlyinit)
373         move    rasave,ra
374         
375 #ifdef DBGSBD
376         /* Initialise the LED so we can write to it */
377         li      a1, PHYS_TO_K1(LED_BASE+HD2532_CW)
378         li      a2,HD2532_CW_C
379         sw      a2,(a1)
381         .set    noreorder
382         li      t0,CACHEUS(110)
383 1:      bnez    t0,1b
384         subu    t0,1
385         .set    reorder
387         DBGDISPLAY('P','6','0','6','4',' ',' ',' ');
388 #endif
389         
390         mfc0    t2,C0_PRID              # get PrID
391         mtc0    zero,$18                # C0_IWATCH/C0_WATCHLO
392         mtc0    zero,$19                # C0_DWATCH/C0_WATCHHI
394         /* get global pointer to Bonito registers */
395         li      bonito,PHYS_TO_K1(BONITO_BASE)
396         
397         srl     t2,8
398         and     t2,0xff
400         /*
401          * some CPUs need a non-zero bootmode stream
402          * we achieve this by loading the bitstream into the intpol
403          * register and issuing a self-reset
404          * but first we must avoid getting into an infinite loop...
405          */
407         lw      t3,BONITO_BONGENCFG(bonito)
408         and     t3,BONITO_BONGENCFG_CPUSELFRESET
409         bnez    t3,.noreset
411         b       .noreset
412         
413         
414 //      .rdata
415         .align  2
416 #define QEDCDIV(mb20,mb7_5) \
417         .word   0+((mb20<<20)|(mb7_5<<5))
418                 
419 cdiv_qed:
420         QEDCDIV(0,0)    # x2
421         QEDCDIV(1,3)    # x2.5
422         QEDCDIV(0,1)    # x3
423         QEDCDIV(1,5)    # x3.5
424         QEDCDIV(0,2)    # x4
425         QEDCDIV(1,7)    # x4.5
426         QEDCDIV(0,3)    # x5
427         QEDCDIV(0,3)    # x5
428         
429         
430         .struct 0
431 #define CPU(prid,bootmode,cdiv,xtra) \
432         .word   prid,bootmode,cdiv,xtra
433 CPU_PRID:       .word   0
434 CPU_BOOTMODE:   .word   0
435 CPU_CDIV:       .word   0
436 CPU_XTRA:       .word   0
437 CPU_SIZE:       
438         .previous
439 cpu_data:
440         CPU(PRID_RM7000,BOOTMODE_RM7000,cdiv_qed,xtra_rm7000)
441         CPU(PRID_RM52XX,BOOTMODE_RM52XX,cdiv_qed,0)
442         CPU(PRID_RC6447X,0,0,BOOTMODE_RC6447X)
443         CPU(PRID_RC6457X,0,BOOTMODE_RC6457X,0)
444         CPU(PRID_R4650,0,BOOTMODE_R4650,0)
445         .word   0
446         .text
448         DISPLAY('R','e','s','e','t','C','h','k')
450         LOADREL(t1,cpu_data)    
451         or      t1,K1BASE
452         
453 1:      lw      t3,CPU_PRID(t1)
454         beqz    t3,.noreset             # off end of table
455         beq     t3,t2,.reset
456         addu    t1,CPU_SIZE
457         b       1b
458                 
459 .reset: 
460         DISPLAY('R','e','s','e','t','R','e','q')
461         # use the switch settings to modify the base settings 
463         # to access the switches we need to enable CS0 buffbit
464         li      t4,BONITO_IODEVCFG_BUFFBIT_CS0
465         sw      t4,BONITO_IODEVCFG(bonito)
466         lw      zero,BONITO_IODEVCFG(bonito)
468         li      t4,PHYS_TO_K1(CPLD_BASE)
469         lw      t4,CPLD_SWITCHES(t4)
471         lw      t3,CPU_BOOTMODE(t1)     # base setting
472         lw      t5,CPU_CDIV(t1)
473         beqz    t5,1f                   # skip CDIV settings if we don't know how
475         # get clock multiplier switches
476         or      t5,K1BASE
477         
478         and     t6,t4,CPLD_CLKMULT
479         srl     t7,t6,CPLD_CLKMULT_SHIFT
480         sll     t7,2
481         addu    t5,t7
482         lw      t6,0(t5)
483         
484         or      t3,t6                   # set multiplier bits
486 1:      /* others... */         
487         lw      t5,CPU_XTRA(t1)
488         beqz    t5,.doreset
489         or      t5,K1BASE
490         j       t5
492 xtra_rm7000:
493         # set scache 
494         b       .doreset
495         
496                 
497 .doreset:
498         DISPLAY('R','e','s','e','t','G','o',' ')
499         sw      t3,BONITO_INTPOL(bonito)
500         lw      t3,BONITO_BONGENCFG(bonito)
501         or      t3,BONITO_BONGENCFG_CPUSELFRESET
502         sw      t3,BONITO_BONGENCFG(bonito)
503         lw      t3,BONITO_BONGENCFG(bonito)
504 1:      b       1b              # loop forever
505         
506 .noreset:
507         DISPLAY('N','o',' ','R','e','s','e','t')
508         
509         /* if we get here, the cpu has been correctly initialised */
510         bne     t2,PRID_R4650,2f
511         
512         /* r4640/50 initialisation */
513         mtc0    zero,$0                 # C0_IBASE
514         mtc0    zero,$1                 # C0_IBOUND
515         mtc0    zero,$2                 # C0_DBASE
516         mtc0    zero,$3                 # C0_DBOUND
517 #ifndef BOOTPKG
518         /* Making this dependent on BOOTPKG is wrong, but it is done this
519          * way to stop PMON reenabling the caches if ITROM has detected an
520          * error
521          */
522         li      t3,0x22233333
523         mtc0    t3,$17                  # C0_CALG
524 #endif  
525         b       3f
526         
527 2:      /* r4xxx/r5xxx initialisation */
528         /* set config register for 32b/32b cachelines, kseg0 cacheable */
529         and     t1,~0x3f                # set bits 5..0 only
530         or      t1,CFG_IB | CFG_DB | CFG_C_WBACK
531         /* Vr4300/5432: software controls the endianness (r/o on other CPUs) */
532 #ifdef __MIPSEB
533 //      or      t1,CFG_BE       
534 #else
535 //      and     t1,~CFG_BE      
536 #endif
537         /* set DDDD rate for CPUs that aren't hardware configured */
538         and     t1,~CFG_EPMASK
539         or      t1,CFG_EPD
540         bne     t2,PRID_R5400,1f
541         /* Vr5400: set R4x00 compatible bus mode */
542         and     t1,~CFG_EMMASK
543         or      t1,CFG_EM_R4K
544         b       2f
545         /* Vr4100: switch off accelerated data (undefined on other CPUs)*/
546 1:      and     t1,~CFG_AD
547 2:      mtc0    t1,C0_CONFIG
548         
549 3:      mfc0    t1,C0_STATUS            # get Status
550         mtc0    zero,C0_CAUSE
551         and     t1,M_SR_SR              # leave the SoftReset bit
552         or      t1,M_SR_BEV             # force Boot Exception Vec
553         mtc0    t1,C0_STATUS
554         
555         /* Initialise other low-level I/O devices */
557         LOADREL(a0,reginittab)
558         or      a0,K1BASE
559         LOADREL(t1,reset_table)
560         or      t1,K1BASE
561         LW      t1,0(t1)
562         or      t1,K1BASE
564         DISPLAY('R','e','g','i','n','i','t',' ')
566         jal     t1
568 #if DBGSBD > 0
569         
570         li      a0,PHYS_TO_K1(PCI_IO_SPACE)
571         li      a1,0x55
572         li      a2,0xaa
573         sb      a1,0x4d0(a0)
574         sb      a2,0x4d1(a0)
575         sb      a1,0x4d2(a0)
576         sb      a2,0x4d3(a0)
577         lbu     zero,0x4d0(a0)
578         lbu     zero,0x4d1(a0)
579         lbu     zero,0x4d2(a0)
580         lbu     zero,0x4d3(a0)
582         sb      a2,0x4d0(a0)
583         sb      a1,0x4d1(a0)
584         sb      a2,0x4d2(a0)
585         sb      a1,0x4d3(a0)
586         lbu     zero,0x4d0(a0)
587         lbu     zero,0x4d1(a0)
588         lbu     zero,0x4d2(a0)
589         lbu     zero,0x4d3(a0)
591         bal     _rom_consinit
593         DBGPSTR("In _sbd_reset\r\n")
594 #endif
596         move    ra,rasave
598         j       ra
600 END(board_earlyinit)
602 LEAF(board_dram_init)
604         move    rasave,ra
606         li      bonito,PHYS_TO_K1(BONITO_BASE)
608 #ifdef P60XX_I2C
609         /* 
610          * Now determine DRAM configuration and size by
611          * reading the I2C EEROM on the DIMMS
612          */
614         bal     i2creset
615         li      msize,0
616         
617         DISPLAY ('D','I','M','M','0',' ',' ',' ')
618         
619         /* start with DIMM #0 */
620         li      a0,0
621         /* Do a RMW on SDCFG to preserve power up values */
622         lw      sdCfg,BONITO_SDCFG(bonito)
623         /* use parity if DIMMS support it */
624         or      sdCfg,BONITO_SDCFG_DRAMPARITY
625         
626 .nextdimm:
627         li      sdShape,0
628         
629         /* read DIMM memory type (must be SDRAM) */
630         li      a1,2
631         bal     i2cread
632         bne     v0,4,.nodimm
633         
634         /* read DIMM memory size per side */
635         li      a1,31
636         bal     i2cread
637         beqz    v0,.nodimm
638         sll     tmpsize,v0,22           # multiply by 4M
639         
640         /* read DIMM number of rows */
641         li      a1,3
642         bal     i2cread
643         subu    v0,11
644         bgtu    v0,14-11,.nodimm
645         sll     v0,BONITO_SDCFG_AROWBITS_SHIFT
646         and     v0,BONITO_SDCFG_AROWBITS
647         or      sdShape,v0
648         
649 2:      /* read DIMM number of cols */
650         li      a1,4
651         bal     i2cread
652         subu    v0,8
653         bgtu    v0,11-8,.nodimm
654         sll     v0,BONITO_SDCFG_ACOLBITS_SHIFT
655         and     v0,BONITO_SDCFG_ACOLBITS
656         or      sdShape,v0
657         
658 2:      /* read DIMM number of blocks-per-dram */
659         li      a1,17
660         bal     i2cread
661         beq     v0,2,2f
662         bne     v0,4,.nodimm
663         or      sdShape,BONITO_SDCFG_ABANKBIT
664         
665 2:      /* read DIMM number of sides (banks) */
666         li      a1,5
667         bal     i2cread
668         beq     v0,1,2f
669         bne     v0,2,.nodimm
670         or      sdShape,BONITO_SDCFG_ASIDES
671         sll     tmpsize,1       # msize *= 2    
672         
673 2:      /* read DIMM width */
674         li      a1,6
675         bal     i2cread
676         bleu    v0,36,2f
677         bgtu    v0,72,.nodimm
678         or      sdShape,BONITO_SDCFG_AWIDTH64
680 2:      /* check width for parity operation */
681         beq     v0,36,2f
682         beq     v0,72,2f
684         and     sdCfg,~BONITO_SDCFG_DRAMPARITY
685         
686 2:      
687         addu    msize,tmpsize
688         b       2f
689                 
690 .nodimm:
691         or      sdShape,BONITO_SDCFG_AABSENT
692         li      v0,0xff<<BONITO_SDCFG_AROWBITS_SHIFT
693 2:      beqz    a0,1f
694         sll     sdShape,BONITO_SDCFG_BROWBITS_SHIFT
695         li      v0,0xff<<BONITO_SDCFG_BROWBITS_SHIFT
696 1:      not     v0
697         and     sdCfg,v0
698         or      sdCfg,sdShape
699         
700         DISPLAY ('D','I','M','M','1',' ',' ',' ')
701         addu    a0,1
702         bltu    a0,2,.nextdimm
704         /* If we are running in SDRAM, chop 4MB off the memory size,
705            and don't modify sdCfg register (assume someone in 
706            PCI-world has already set it up). */
707         lw      t0,BONITO_BONPONCFG(bonito)
708         and     t0,BONITO_BONPONCFG_ROMBOOT
709         bne     t0,BONITO_BONPONCFG_ROMBOOT_SDRAM,1f
710         
711         beqz    msize,2f        # already zero!
712         subu    msize,4*1024*1024
713         b       2f
714         
715 1:      sw      sdCfg,BONITO_SDCFG(bonito)
716         
717 2:              
718 #else   
719         li      msize,4*0x100000
720 #endif
721         
722         
723         
724         li      t1,0            # accumulate pcimembasecfg settings
725                 
726         /* set bar0 mask and translation to point to all memory */
727         sub     t0,msize,1
728         not     t0
729         srl     t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE0_MASK_SHIFT
730         and     t0,BONITO_PCIMEMBASECFG_MEMBASE0_MASK
731         or      t1,t0
732         
733         li      t0,0x00000000
734         srl     t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE0_TRANS_SHIFT
735         and     t0,BONITO_PCIMEMBASECFG_MEMBASE0_TRANS
736         or      t1,t0
737         or      t1,BONITO_PCIMEMBASECFG_MEMBASE0_CACHED
739         /* set bar1 to minimum size to conserve PCI space */
740         li      t0, ~0
741         srl     t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE1_MASK_SHIFT
742         and     t0,BONITO_PCIMEMBASECFG_MEMBASE1_MASK
743         or      t1,t0
744         
745         li      t0,0x00000000
746         srl     t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE1_TRANS_SHIFT
747         and     t0,BONITO_PCIMEMBASECFG_MEMBASE1_TRANS
748         or      t1,t0
749         or      t1,BONITO_PCIMEMBASECFG_MEMBASE1_CACHED
751         sw      t1,BONITO_PCIMEMBASECFG(bonito)
753         /* enable configuration cycles now */
754         lw      t0,BONITO_BONPONCFG(bonito)
755         and     t0,~BONITO_BONPONCFG_CONFIG_DIS
756         sw      t0,BONITO_BONPONCFG(bonito)
757                         
758 #ifdef P60XX_PARITY     
759         /* We have to clear memory to initialise parity */
761         /* Skip memory clear if no memory */
762         beqz    msize,.noclear
763         
764         /* Skip memory clear if non-parity memory */
765         lw      t1,BONITO_SDCFG(bonito)
766         and     t1,BONITO_SDCFG_DRAMPARITY
767         beqz    t1,.noclear
768         
769         /* Skip memory clear if a soft reset */
770         mfc0    t1,C0_STATUS
771         and     t1,M_SR_SR
772         bnez    t1,.noclear
774         /* Clear bottom 256K running uncached */
775         DISPLAY ('Z','2','5','6','K',' ',' ',' ')
776         li      a0,PHYS_TO_K1(0)
777         addu    a1,a0,256*1024
778         .set noreorder
779 1:      sd      zero,0(a0)
780         sd      zero,8(a0)
781         sd      zero,16(a0)
782         addu    a0,32
783         bne     a0,a1,1b
784         sd      zero,-8(a0)
785         .set reorder
786         
787         /* We can now initialise the caches for a fast clear_mem */
788 //      DISPLAY ('C','A','C','H',' ',' ',' ',' ')
789 //      bal     mips_init_cache 
790                 
791         /* Finally clear rest of memory running cached */
792         li      a0,PHYS_TO_K1(256*1024)
793         subu    a1,msize,256*1024
794         blez    a1,.noclear
795         addu    a1,a0
796         
797         /* clear all of memory (to set correct parity) */
798         DISPLAY ('Z','M','E','M',' ',' ',' ',' ')
799         
800         
801         .set noreorder
803         sd      zero,0(a0)
804         sd      zero,8(a0)
805         sd      zero,16(a0)
806         sd      zero,24(a0)
807         sd      zero,32(a0)
808         sd      zero,40(a0)
809         sd      zero,48(a0)
810         addu    a0,64
811         bne     a0,a1,1b
812         sd      zero,-8(a0)
813         .set reorder
815 .noclear:
816                 
817 #endif /* P60XX_PARITY */
818                 
819         /* return to generic code, with available memory size */
820         DISPLAY ('R','U','N',' ',' ',' ',' ',' ')
821         move    ra,rasave
823         move    v0,msize
825         srl     v0,20                   /* return in megabytes */
827         j       ra
828 END(board_dram_init)
831 LEAF(_sbd_memfail)
832         DISPLAY ('!','M','E','M','O','R','Y',' ')
833 1:      b       1b
834         j       ra
835 END(_sbd_memfail)
837 #define SMBOFFS(reg) I82371_SMB_SMB##reg
838                         
840 SLEAF(i2creset)
841         j       ra
842 SEND(i2creset)
843         
845 /* i2cread (unsigned dev, unsigned offs) */
846 SLEAF(i2cread)  
847         li      t0,PHYS_TO_K1(ISAPORT_BASE(SMB_PORT))
849         lbu     t1,SMBOFFS(HSTSTS)(t0)
850         and     t1,~(I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR|I82371_SMB_INTER)
851         sb      t1,SMBOFFS(HSTSTS)(t0)
852         
853         sll     t1,a0,1
854         or      t1,0xa1         # DIMM base address and read bit
855         sb      t1,SMBOFFS(HSTADD)(t0)
856         sb      a1,SMBOFFS(HSTCMD)(t0)
857         
858         
859         li      t1,I82371_SMB_START|I82371_SMB_BDRW
860         sb      t1,SMBOFFS(HSTCNT)(t0)
862         li      t3,10000        
863 1:      lbu     t1,SMBOFFS(HSTSTS)(t0)
864         and     t2,t1,I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR|I82371_SMB_INTER
865         bnez    t2,1f
866         sub     t3,1
867         bnez    t3,1b
868         b       9f              
869 1:      
870         # clear pending errors/interrupts
871         sb      t1,SMBOFFS(HSTSTS)(t0)
872         
873         and     t2,t1,I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR
874         bnez    t2,9f
876         lbu     v0,SMBOFFS(HSTDAT0)(t0)
877         j       ra
878         
879 9:      li      v0,-1
880         j       ra
881 SEND(i2cread)   
882         
885 #include "reginit.s"            
887          .text
888 //      .rdata
889 //      .align 3
890 #define BONITO_INIT(r,v)        WR_INIT(W,BONITO_BASE+BONITO_##r,v)
891 #define BONITO_BIS(r,b)         RMW_INIT(W,BONITO_BASE+BONITO_##r,~0,b)
892 #define BONITO_BIC(r,b)         RMW_INIT(W,BONITO_BASE+BONITO_##r,~(b),0)
893 #define BONITO_RMW(r,c,s)       RMW_INIT(W,BONITO_BASE+BONITO_##r,~(c),s)
894         
895 #define CFGADDR(idsel,function,reg) ((1<<(11+(idsel)))+((function)<<8)+(reg))
896 /* generic ISA Bridge (PIIX) configuration accesses */  
897 #define _ISABWR_INIT(mod,function,isabreg,val) \
898         WR_INIT(W,BONITO_BASE+BONITO_PCIMAP_CFG,CFGADDR(PCI_DEV_I82371,function,isabreg)>>16) ; \
899         RD_INIT(W,BONITO_BASE+BONITO_PCIMAP_CFG) ; \
900         WR_INIT(mod,PCI_CFG_SPACE+(CFGADDR(PCI_DEV_I82371,function,isabreg)&0xffff),val)
901 #define _ISABRD_INIT(mod,function,isabreg) \
902         WR_INIT(W,BONITO_BASE+BONITO_PCIMAP_CFG,CFGADDR(PCI_DEV_I82371,function,isabreg)>>16) ; \
903         RD_INIT(W,BONITO_BASE+BONITO_PCIMAP_CFG) ; \
904         RD_INIT(mod,PCI_CFG_SPACE+(CFGADDR(PCI_DEV_I82371,function,isabreg)&0xffff))
906 /* generic ISA I/O accesses */  
907 #define _ISAWR_INIT(isareg,val) \
908         WR_INIT(B,PCI_IO_SPACE+(isareg),val)
909 #define _ISARD_INIT(isareg) \
910         RD_INIT(B,PCI_IO_SPACE+(isareg))
911         
912 /* ISA Bridge (PIIX) configuration accesses */
913 #ifdef __MIPSEB
915  * byte swapper disabled for config cycles
916  * twiddle addresses but not data
917  */     
918 #define ISABBWR_INIT(function,isabreg,val) \
919         _ISABWR_INIT(B,function,(isabreg)^3,val)
920 #define ISABHWR_INIT(function,isabreg,val) \
921         _ISABWR_INIT(H,function,(isabreg)^2,val)
922 #define ISABWWR_INIT(function,isabreg,val) \
923         _ISABWR_INIT(W,function,isabreg,val)
924 #else
925 #define ISABBWR_INIT(function,isabreg,val) \
926         _ISABWR_INIT(B,function,(isabreg),val)
927 #define ISABHWR_INIT(function,isabreg,val) \
928         _ISABWR_INIT(H,function,(isabreg),val)
929 #define ISABWWR_INIT(function,isabreg,val) \
930         _ISABWR_INIT(W,function,isabreg,val)
931 #endif
932         
933 /* ISA I/O accesses */  
934 #define ISAWR_INIT(isareg,val) \
935         _ISAWR_INIT(isareg,val)
936 #define ISARD_INIT(isareg) \
937         _ISARD_INIT(isareg)
938                                 
939 #define DISPLAY_INIT(d0,d1,d2,d3,d4,d5,d6,d7) \
940         WR_INIT(W, LED_BASE+HD2532_CRAM+HD2532_CHAR(0), 0+d0); \
941         WR_INIT(W, LED_BASE+HD2532_CRAM+HD2532_CHAR(1), 0+d1); \
942         WR_INIT(W, LED_BASE+HD2532_CRAM+HD2532_CHAR(2), 0+d2); \
943         WR_INIT(W, LED_BASE+HD2532_CRAM+HD2532_CHAR(3), 0+d3); \
944         WR_INIT(W, LED_BASE+HD2532_CRAM+HD2532_CHAR(4), 0+d4); \
945         WR_INIT(W, LED_BASE+HD2532_CRAM+HD2532_CHAR(5), 0+d5); \
946         WR_INIT(W, LED_BASE+HD2532_CRAM+HD2532_CHAR(6), 0+d6); \
947         WR_INIT(W, LED_BASE+HD2532_CRAM+HD2532_CHAR(7), 0+d7)
949 #define ISAREFRESH (PT_CRYSTAL/(1000000/15))
951 reginittab:
952         /* bonito endianess */
953 #ifdef __MIPSEB
954         BONITO_BIS(BONPONCFG,BONITO_BONPONCFG_CPUBIGEND)
955         BONITO_BIS(BONGENCFG,BONITO_BONGENCFG_BYTESWAP|BONITO_BONGENCFG_MSTRBYTESWAP)
956 #else
957         BONITO_BIC(BONPONCFG,BONITO_BONPONCFG_CPUBIGEND)
958         BONITO_BIC(BONGENCFG,BONITO_BONGENCFG_BYTESWAP|BONITO_BONGENCFG_MSTRBYTESWAP)
959 #endif
960         BONITO_BIS(BONPONCFG, BONITO_BONPONCFG_IS_ARBITER|BONITO_BONPONCFG_PCIRESET_OUT)
961         
962         /* Bonito PIO initialisation */
964         BONITO_INIT(GPIODATA,PIO_PIIXRESET)     # initial value
965         BONITO_INIT(GPIOIE,PIO_IE)
966         
967         /* Clear PCI reset and enable PIIX */
968         DELAY_INIT(ROMMS(1))
969         BONITO_BIC(BONPONCFG,BONITO_BONPONCFG_PCIRESET_OUT)
970         DELAY_INIT(ROMMS(2))
971         BONITO_BIC(GPIODATA,PIO_PIIXRESET)
972         DELAY_INIT(ROMMS(50))
973         
974         /* PCI bus and PIIX should now be usable */
975         
976         BONITO_BIS(PCICMD, BONITO_PCICMD_PERRRESPEN)
977         
978         BONITO_BIS(PCICMD, PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE|PCI_COMMAND_MASTER_ENABLE)
979         
980         /* enable i/o buffer cache and other go faster bits */
981         BONITO_BIS(BONGENCFG, \
982                         BONITO_BONGENCFG_BUSERREN| \
983                         BONITO_BONGENCFG_PREFETCHEN| \
984                         BONITO_BONGENCFG_WBEHINDEN| \
985                         BONITO_BONGENCFG_PCIQUEUE| \
986                         BONITO_BONGENCFG_SNOOPEN)
988         /* Set debug mode */
989         BONITO_BIS(BONGENCFG, BONITO_BONGENCFG_DEBUGMODE)
991         BONITO_BIS(IODEVCFG, BONITO_IODEVCFG_BUFFBIT_CS0|\
992                              BONITO_IODEVCFG_BUFFBIT_CS1|\
993                              BONITO_IODEVCFG_SPEEDBIT_CS2|BONITO_IODEVCFG_BUFFBIT_CS2|\
994                              BONITO_IODEVCFG_SPEEDBIT_CS3|BONITO_IODEVCFG_BUFFBIT_CS3|\
995                              BONITO_IODEVCFG_BUFFBIT_IDE)
996                 
997         /* switch on the LED */
998         WR_INIT(W, LED_BASE+HD2532_CW,HD2532_CW_C)
999         DELAY_INIT(ROMUS(110))
1000         
1001         /* 
1002          * Initialise the ISA bridge via its CONF space
1003          */
1004         
1005         DISPLAY_INIT ('I','s','a','B','r','i','d','g')
1006         
1007         /* Turn most special purpose pins into GPIO; set ISA mode */
1008         ISABWWR_INIT(0, I82371_GENCFG, I82371_GENCFG_CFG)
1009         
1010         /* disable RTC & KBD chip selects */
1011         ISABHWR_INIT(0, I82371_XBCS, 0)
1012         
1013         /* Enable PCI 2.1 timing support */
1014         ISABBWR_INIT(0, I82371_DLC, I82371_DLC_DT /* | I82371_DLC_PR */ | I82371_DLC_USBPR | I82371_DLC_DTTE)
1016         /* Set top of memory to 16MB, so all ISA bus master & DMA
1017            accesses are forwarded to PCI mem space
1018          */
1019         ISABBWR_INIT(0, I82371_TOM, I82371_TOM_TOM(16) | I82371_TOM_FWD_LBIOS | I82371_TOM_FWD_AB | I82371_TOM_FWD_89)
1020         
1021         /* disable the internal RTC */
1022         ISABBWR_INIT(0, I82371_RTCCFG, 0);      
1023         
1024         /* Set the SMB base address */
1025         ISABWWR_INIT(3, I82371_PCI3_SMBBA, SMB_PORT|PCI_MAP_IO)
1026         /* enable the host controller */
1027         ISABBWR_INIT(3, I82371_PCI3_SMBHSTCFG, I82371_PCI3_SMB_HST_EN)
1028         /* enable the SMB IO ports */
1029         ISABBWR_INIT(3, PCI_COMMAND_STATUS_REG, PCI_COMMAND_IO_ENABLE)
1031         /* Set the PIIX power management base address */
1032         ISABWWR_INIT(3, I82371_PCI3_PMBA, PM_PORT|PCI_MAP_IO)
1033         /* enable the power management ports */
1034         ISABBWR_INIT(3, I82371_PCI3_PMREGMISC, I82371_PCI3_PMIOSE)
1036         /* Initialise ISA bus low-level I/O devices */
1037         DISPLAY_INIT('I','s','a','D','e','v',' ',' ')
1039 /* 15us ISA bus refresh clock */
1040 #define ISAREFRESH (PT_CRYSTAL/(1000000/15))
1041         
1042         ISARD_INIT(CTC_PORT+PT_CONTROL)
1043         
1044         /* program i8254 ISA refresh counter */
1045         ISAWR_INIT(CTC_PORT+PT_CONTROL,PTCW_SC(PT_REFRESH)|PTCW_16B|PTCW_MODE(MODE_RG))
1046         ISAWR_INIT(CTC_PORT+PT_REFRESH, ISAREFRESH & 0xff)
1047         ISAWR_INIT(CTC_PORT+PT_REFRESH, ISAREFRESH >> 8)
1049         /* program ISA ICU */
1050         ISAWR_INIT(ICU1_PORT,  0x11) /* ICW1 */
1051         ISAWR_INIT(ICU1_PORT+1,0x00) /* ICW2: vector */
1052         ISAWR_INIT(ICU1_PORT+1,0x04) /* ICW3: cascade on IRQ2 */
1053         ISAWR_INIT(ICU1_PORT+1,0x01) /* ICW4: 8086 mode */
1054         ISAWR_INIT(ICU1_PORT+1,0xff) /* OCW1: mask all */
1056         ISAWR_INIT(ICU2_PORT,  0x11) /* ICW1 */
1057         ISAWR_INIT(ICU2_PORT+1,0x08) /* ICW2: vector */
1058         ISAWR_INIT(ICU2_PORT+1,0x02) /* ICW3:  */
1059         ISAWR_INIT(ICU2_PORT+1,0x01) /* ICW4: 8086 mode */
1060         ISAWR_INIT(ICU2_PORT+1,0xff) /* OCW1: mask all */
1061                 
1062         ISAWR_INIT(ICU1_PORT+1,~(1<<2)) /* enable IRQ2 */
1064         /* set up ISA devices */
1066         /* select logical device 1 (mouse) */   
1067         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
1068         ISAWR_INIT(ISAPNP_MBDATA,1)
1069         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
1070         ISAWR_INIT(ISAPNP_MBDATA,1)
1071         
1072         /* select logical device 4 (parallel) */        
1073         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
1074         ISAWR_INIT(ISAPNP_MBDATA,4)
1075         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_15_8)
1076         ISAWR_INIT(ISAPNP_MBDATA,(ECP_PORT>>8) & 0xff)
1077         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_7_0)
1078         ISAWR_INIT(ISAPNP_MBDATA,ECP_PORT & 0xff)
1079         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IRQ_DESC0+ISAPNP_IRQ_CONTROL)
1080         ISAWR_INIT(ISAPNP_MBDATA,ISAPNP_IRQ_HIGH)
1081         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
1082         ISAWR_INIT(ISAPNP_MBDATA,1)
1083         
1084         /* select logical device 5 (COM2) */    
1085         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
1086         ISAWR_INIT(ISAPNP_MBDATA,5)
1087         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
1088         ISAWR_INIT(ISAPNP_MBDATA,1)
1089         
1090         /* select logical device 6 (COM1) */    
1091         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
1092         ISAWR_INIT(ISAPNP_MBDATA,6)
1093         ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
1094         ISAWR_INIT(ISAPNP_MBDATA,1)
1095         
1096                 
1097         /* Completed */
1098         DISPLAY_INIT('I','n','i','t','d','o','n','e')
1099                 
1100         EXIT_INIT(0)
1101         
1103         
1104 #define M_SR_DE _MM_MAKEMASK1(16)
1105         
1106 LEAF(sbdberrenb)
1107         mfc0    v0,C0_SR
1108         li      t0,M_SR_DE      
1109         bnez    a0,1f
1110         or      t1,v0,t0        # disable cache/parity errors (SR_DE = 1)
1111         b       2f
1112 1:      not     t1,t0           # enable cache/parity errors (SR_DE = 0)
1113         and     t1,v0
1114 2:      mtc0    t1,C0_SR
1115         and     v0,t0           # get old SR_DE bit
1116         xor     v0,t0           # and invert to make it an enable bit
1117         j       ra
1118 END(sbdberrenb)
1121 LEAF(sbdberrcnt)
1122         move    v0,zero
1123         j       ra
1124 END(sbdberrcnt)
1125         
1127 //      .lcomm  wbfltmp,4
1129 LEAF(wbflush)
1130         la      t0,K1BASE
1131         sync
1132         lw      zero,0(t0)
1133         j       ra
1134 END(wbflush)
1136         
1137 LEAF(sbddelay)
1138         mfc0    t0,C0_CONFIG
1139         li      t1,CACHEMISS+ROMCYCLE
1140         and     t0,CFG_K0MASK
1141         beq     t0,CFG_C_UNCACHED,1f
1142         and     t0,ra,0x20000000
1143         bnez    t0,1f
1144         li      t1,CACHECYCLE
1145 1:      mul     a0,1000
1146         addu    a0,t1
1147         sll     t1,1
1148         divu    a0,t1
1149         subu    a0,48           # approx number of loops so far
1150         .set    noreorder       
1151         .set    nomacro
1152         nop
1153 2:      bgtz    a0,2b
1154         subu    a0,1
1155         .set    macro
1156         .set    reorder
1157         j       ra
1158 END(sbddelay)
1160 LEAF(mips_cycle)
1161         .set    noreorder       
1162         .set    nomacro
1163 1:      bgtz    a0,1b
1164         subu    a0,1
1165         .set    macro
1166         .set    reorder
1167         j       ra
1168 END(mips_cycle)
1169