RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / cfe / cfe / arch / mips / board / pt1125 / src / pt1125_init.S
blobfda59b5ac5736e19485c88f8036714eb4d691148
1 /*  *********************************************************************
2     *  SB1250 Board Support Package
3     *  
4     *  Board-specific initialization            File: PT1125_INIT.S
5     *
6     *  This module contains the assembly-language part of the init
7     *  code for this board support package.  The routine
8     *  "board_earlyinit" lives here.
9     *  
10     *  Author:  Mitch Lichtenberg (mpl@broadcom.com)
11     *
12     * modification history
13     * --------------------
14     * 01a,01aug02,gtb  Ported from  pt1120_init.S.
15     *  
16     *********************************************************************  
17     *
18     *  Copyright 2000,2001
19     *  Broadcom Corporation. All rights reserved.
20     *  
21     *  This software is furnished under license and may be used and 
22     *  copied only in accordance with the following terms and 
23     *  conditions.  Subject to these conditions, you may download, 
24     *  copy, install, use, modify and distribute modified or unmodified 
25     *  copies of this software in source and/or binary form.  No title 
26     *  or ownership is transferred hereby.
27     *  
28     *  1) Any source code used, modified or distributed must reproduce 
29     *     and retain this copyright notice and list of conditions as 
30     *     they appear in the source file.
31     *  
32     *  2) No right is granted to use any trade name, trademark, or 
33     *     logo of Broadcom Corporation. Neither the "Broadcom 
34     *     Corporation" name nor any trademark or logo of Broadcom 
35     *     Corporation may be used to endorse or promote products 
36     *     derived from this software without the prior written 
37     *     permission of Broadcom Corporation.
38     *  
39     *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
40     *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED 
41     *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
42     *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT 
43     *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN 
44     *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT, 
45     *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
46     *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
47     *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
48     *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
49     *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
50     *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF 
51     *     THE POSSIBILITY OF SUCH DAMAGE.
52     ********************************************************************* */
55 #include "sbmips.h"
56 #include "sb1250_genbus.h"
57 #include "sb1250_regs.h"
58 #include "sb1250_scd.h"
59 #include "bsp_config.h"
60 #include "pt1125.h"
61 #include "sb1250_draminit.h"
62 #include "../dev/ns16550.h"
64 #if defined(_PT1125_DIAG_CFG_)
65 #undef SERIAL_PORT_LEDS
66 #define SERIAL_PORT_LEDS
67 #endif
68                 .text
70 /*  *********************************************************************
71     *  Macros
72     ********************************************************************* */
75 #if CFG_RUNFROMKSEG0
76 #define CALLKSEG1(x)  la k0,x ; or k0,K1BASE ; jal k0
77 #else
78 #define CALLKSEG1(x)  jal x
79 #endif
82 /*  *********************************************************************
83     *  BOARD_EARLYINIT()
84     *  
85     *  Initialize board registers.  This is the earliest 
86     *  time the BSP gets control.  This routine cannot assume that
87     *  memory is operational, and therefore all code in this routine
88     *  must run from registers only.  The $ra register must not
89     *  be modified, as it contains the return address.
90     *
91     *  This routine will be called from uncached space, before
92     *  the caches are initialized.  If you want to make
93     *  subroutine calls from here, you must use the CALLKSEG1 macro.
94     *
95     *  Among other things, this is where the GPIO registers get 
96     *  programmed to make on-board LEDs function, or other startup
97     *  that has to be done before anything will work.
98     *  
99     *  Input parameters: 
100     *      nothing
101     *      
102     *  Return value:
103     *      nothing
104     ********************************************************************* */
106 LEAF(board_earlyinit)
108        #
109        # Configure the GPIOs
110        #
111        # 0 is output
112        # 1, 2, and 5 are interrupts
113        # remainder are input (unused)
114        #
116                 li      t0,PHYS_TO_K1(A_GPIO_DIRECTION)
117                 li      t1,GPIO_OUTPUT_MASK
118                 sd      t1,0(t0)
120                 li      t0,PHYS_TO_K1(A_GPIO_INT_TYPE)
121                 li      t1,GPIO_INTERRUPT_MASK
122                 sd      t1,0(t0)
124        #
125        # Turn on the diagnostic LED 
126        #
127                 li      t0,PHYS_TO_K1(A_GPIO_PIN_SET)
128                 li      t1,M_GPIO_DEBUG_LED
129                 sd      t1,0(t0)
131        #
132        # Configure the LEDs
133        #     
135                 li      t0,PHYS_TO_K1(A_IO_EXT_CS_BASE(LEDS_CS))
136                 li      t1,LEDS_PHYS >> S_IO_ADDRBASE
137                 sd      t1,R_IO_EXT_START_ADDR(t0)
139                 li      t1,LEDS_SIZE-1  /* Needs to be 1 smaller, se UM for details */
140                 sd      t1,R_IO_EXT_MULT_SIZE(t0)
142                 li      t1,LEDS_TIMING0
143                 sd      t1,R_IO_EXT_TIME_CFG0(t0)
145                 li      t1,LEDS_TIMING1
146                 sd      t1,R_IO_EXT_TIME_CFG1(t0)
148                 li      t1,LEDS_CONFIG
149                 sd      t1,R_IO_EXT_CFG(t0)
151        #
152        # Configure the alternate boot ROM
153        #     
155                 li      t0,PHYS_TO_K1(A_IO_EXT_CS_BASE(ALT_BOOTROM_CS))
157                 li      t1,ALT_BOOTROM_PHYS >> S_IO_ADDRBASE
158                 sd      t1,R_IO_EXT_START_ADDR(t0)
160                 li      t1,ALT_BOOTROM_SIZE-1
161                 sd      t1,R_IO_EXT_MULT_SIZE(t0)
163                 li      t1,ALT_BOOTROM_TIMING0
164                 sd      t1,R_IO_EXT_TIME_CFG0(t0)
166                 li      t1,ALT_BOOTROM_TIMING1
167                 sd      t1,R_IO_EXT_TIME_CFG1(t0)
169                 li      t1,ALT_BOOTROM_CONFIG
170                 sd      t1,R_IO_EXT_CFG(t0)
172        #
173        # Configure I/O bus for an external UART
174        #     
176                 li      t0,PHYS_TO_K1(A_IO_EXT_CS_BASE(UART_CS))
178                 li      t1, UART_PHYS >> S_IO_ADDRBASE
179                 sd      t1,R_IO_EXT_START_ADDR(t0)
181                 li      t1, (UART_SIZE-1)
182                 sd      t1,R_IO_EXT_MULT_SIZE(t0)
184                 li      t1, (UART_TIMING0)
185                 sd      t1,R_IO_EXT_TIME_CFG0(t0)
187                 li      t1, (UART_TIMING1)
188                 sd      t1,R_IO_EXT_TIME_CFG1(t0)
190                 li      t1, (UART_CONFIG)
191                 sd      t1,R_IO_EXT_CFG(t0)
193 #ifdef SERIAL_PORT_LEDS
195         /*
196          * Initialize the UART well enough to output characters.
197          */
198                 li      t0, PHYS_TO_K1(UART_PHYS)
200                 li      t1, CFCR_DLAB
201                 sb      t1, R_UART_CFCR(t0)
203                 li      t1, BRTC(CFG_SERIAL_BAUD_RATE)
204                 sb      t1, R_UART_DATA(t0)
205                 dsra    t1, t1, 8
206                 sb      t1, R_UART_IER(t0)
208                 li      t1, CFCR_8BITS
209                 sb      t1, R_UART_CFCR(t0)
211                 li      t1, (MCR_DTR | MCR_RTS | MCR_IENABLE)
212                 sb      t1, R_UART_MCR(t0)
214                 li      t1, 0
215                 sb      t1, R_UART_IER(t0)
217                 li      t1, FIFO_ENABLE
218                 sb      t1, R_UART_FIFO(t0)
220                 /* A short delay.  */
221                 li      t1, 200
222 1:              addiu   t1, t1, -1
223                 bne     t1, zero, 1b
225                 li      t1, (FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST \
226                              | FIFO_TRIGGER_1)
227                 sb      t1, R_UART_FIFO(t0)
229                 /* A short delay.  */
230                 li      t1, 200
231 1:              addiu   t1, t1, -1
232                 bne     t1, zero, 1b
234                 /* if (value & MASK) != MASK, write 0 to fifo reg.  */
235                 lb      t1, R_UART_IIR(t0)
236                 andi    t1, t1, IIR_FIFO_MASK
237                 xori    t1, t1, IIR_FIFO_MASK
238                 beq     t1, zero, 1f
240                 li      t1, 0
241                 sb      t1, R_UART_FIFO(t0)
243 #endif
246          * If the CPU is a 1250 or hybrid, certain initialization has
247          * to be done so that the chip can be used like an 112x.
248          */
250         /* First, figure out what type of SOC we're on. */
251         ld      t1, PHYS_TO_K1(A_SCD_SYSTEM_REVISION)
252         SYS_SOC_TYPE(t3, t1)
253         bne     t3, K_SYS_SOC_TYPE_BCM1250, is_bcm112x
255         /*
256          * We have a 1250 or hybrid.  Initialize registers as appropriate.
257          */
259         /*
260          * If we're not already running as a uniprocessor, get us there.
261          */
262         dsrl    t1, t1, S_SYS_PART      # part number now in t1
263         and     t3, t1, 0xf00
264         dsrl    t3, t3, 8               # t3 = numcpus
266         ld      t4, PHYS_TO_K1(A_SCD_SYSTEM_CFG)
267         or      t4, t4, M_SYS_SB_SOFTRES
268         xor     t4, t4, M_SYS_SB_SOFTRES
269         sd      t4, PHYS_TO_K1(A_SCD_SYSTEM_CFG)        /* clear soft reset */
271         beq     t3, 1, 2f
273         or      t4, t4, M_SYS_SB_SOFTRES | M_SYS_UNICPU0
274         sd      t4, PHYS_TO_K1(A_SCD_SYSTEM_CFG)        /* go unicpu */
275         sync
277         b       1b
279         
280         /*
281          * Clean up MC 0.
282          */
284         li      t0, PHYS_TO_K1(A_MC_BASE_0)
285         dli     t1, V_MC_CONFIG_DEFAULT | M_MC_ECC_DISABLE | \
286                     V_MC_CS_MODE_MSB_CS
287         sd      t1, R_MC_CONFIG(t0)
288         sd      zero, R_MC_CS_START(t0)
289         sd      zero, R_MC_CS_END(t0)
290         sd      zero, R_MC_CS_INTERLEAVE(t0)
291         sd      zero, R_MC_CS_ATTR(t0)
292         sd      zero, R_MC_TEST_DATA(t0)
293         sd      zero, R_MC_TEST_ECC(t0)
295         /*
296          * Zero out MAC 2's address register.  (This has
297          * undefined value after reset, but OSes may check
298          * it on some parts to see if they should init
299          * the interface.  This is a convenient place
300          * to zero it.)
301          */
303         li      t0, PHYS_TO_K1(A_MAC_BASE_2)
304         sd      zero, R_MAC_ETHERNET_ADDR(t0)
306 is_bcm112x:
309                 j       ra
311 END(board_earlyinit)
314 /*  *********************************************************************
315     *  BOARD_DRAMINFO
316     *  
317     *  Return the address of the DRAM information table
318     *  
319     *  Input parameters: 
320     *      nothing
321     *      
322     *  Return value:
323     *      v0 - DRAM info table, return 0 to use default table
324     ********************************************************************* */
326 #define  _HARDWIRED_MEMORY_TABLE 1
328 #define CFG_DRAM_tROUNDTRIP DRT10(2,0)
329 /* CFG_DRAM_MIN_tMEMCLK must be set to 7.  Some DIMMS cause diag failures
330     when the memclk is at 125 MHz but pass at 100 MHz or 133 MHz.  Setting to 7 causes
331     memclk to be 133 MHz*/
332 #define CFG_DRAM_MIN_tMEMCLK  DRT10(7,0)
333 #define DEVADDR (CFG_DRAM_SMBUS_BASE)
334 #define DEFCHAN (CFG_DRAM_SMBUS_CHANNEL)
336 #if CFG_EMBEDDED_PIC
337 #define LOADREL(reg,label)                      \
338         .set noreorder ;                        \
339         bal  1f        ;                        \
340         nop            ;                        \
341 1:      nop            ;                        \
342         .set reorder   ;                        \
343         la   reg,label-1b ;                     \
344         add  reg,ra
345 #else
346 #define LOADREL(reg,label)                      \
347         la   reg,label
348 #endif
350 LEAF(board_draminfo)
352                 move    t0,ra
354 #ifdef _HARDWIRED_MEMORY_TABLE
355                 LOADREL(v0,myinfo)
356 #else
357                 move    v0,zero         # auto configure
358 #endif
360                 move    ra,t0
361                 j       ra
364 myinfo:
365     DRAM_GLOBALS(0)                     /* no  port interleaving */
367     /*
368      * Memory channel 0: Configure via SMBUS, Automatic Timing
369      * Assumes SMBus device numbers are arranged such
370      * that the first two addresses are CS0,1 and CS2,3 on MC0
371      * and the second two addresses are CS0,1 and CS2,3 on MC1
372      */
373        DRAM_CHAN_CFG2(MC_CHAN1, CFG_DRAM_MIN_tMEMCLK, CFG_DRAM_tROUNDTRIP,  DRAM_TYPE_SPD, CASCHECK, CFG_DRAM_BLOCK_SIZE, CFG_DRAM_CSINTERLEAVE, CFG_DRAM_ECC, 0)
375       
377        DRAM_CS_SPD(MC_CS0, 0, DEFCHAN, DEVADDR+2)       
378        DRAM_CS_SPD(MC_CS2, 0, DEFCHAN, DEVADDR+3)
380    
381        DRAM_EOT
383 END(board_draminfo)
387 #ifdef SERIAL_PORT_LEDS
388 /*  *********************************************************************
389     *  BOARD_UART_TXCHAR(x)
390     *  
391     *  Transmit one character out the UART on the GENERIC bus.
392     *  
393     *  Input parameters: 
394     *      a0 - 8 bit character value.
395     *      
396     *  Return value:
397     *      nothing
398     *  
399     *  Registers used:
400     *      t0,t1
401     ********************************************************************* */
403 LEAF(board_uart_txchar)
405         # Wait until there is space in the transmit buffer.
407                 li      t0, PHYS_TO_K1(UART_PHYS)
409 1:              lb      t1, R_UART_LSR(t0)
410                 andi    t1, t1, LSR_TXRDY
411                 beq     t1, zero, 1b
413         # OK, now send a character.
415                 sb      a0, R_UART_DATA(t0)
417         # And return.
419                 j       ra
421 END(board_uart_txchar)
422 #endif
425 /*  *********************************************************************
426     *  BOARD_SETLEDS(x)
427     *  
428     *  Set LEDs for boot-time progress indication.  Not used if
429     *  the board does not have progress LEDs.  This routine
430     *  must not call any other routines, since it may be invoked
431     *  either from KSEG0 or KSEG1 and it may be invoked 
432     *  whether or not the icache is operational.
433     *  
434     *  Input parameters: 
435     *      a0 - LED value (8 bits per character, 4 characters)
436     *      
437     *  Return value:
438     *      nothing
439     *  
440     *  Registers used:
441     *      t0,t1,t2,t3
442     ********************************************************************* */
445 #define LED_CHAR0       (32+8*3)
446 #define LED_CHAR1       (32+8*2)
447 #define LED_CHAR2       (32+8*1)
448 #define LED_CHAR3       (32+8*0)
450 #ifdef SERIAL_PORT_LEDS
451 #define OUTPUT_CHAR(offset)                                     \
452         li      t0, PHYS_TO_K1(LEDS_PHYS) ;                     \
453         sb      a0, offset(t0) ;                                \
454         bal     board_uart_txchar
455 #else
456 #define OUTPUT_CHAR(offset)                                     \
457         li      t0, PHYS_TO_K1(LEDS_PHYS) ;                     \
458         sb      a0, offset(t0)
459 #endif
461 LEAF(board_setleds)
463                 move    t3, ra
464                 move    t2, a0
466 #ifdef SERIAL_PORT_LEDS
467                 li      a0, '['
468                 bal     board_uart_txchar
469 #endif
471                 move    a0, t2
472                 rol     a0, 8
473                 OUTPUT_CHAR(LED_CHAR0)
475                 rol     a0, 8
476                 OUTPUT_CHAR(LED_CHAR1)
478                 rol     a0, 8
479                 OUTPUT_CHAR(LED_CHAR2)
481                 rol     a0, 8
482                 OUTPUT_CHAR(LED_CHAR3)
484 #ifdef SERIAL_PORT_LEDS
485                 li      a0, ']'
486                 bal     board_uart_txchar
487                 li      a0, '\r'
488                 bal     board_uart_txchar
489                 li      a0, '\n'
490                 bal     board_uart_txchar
491 #endif
493                 move    ra, t3
494                 j       ra
496 END(board_setleds)
498 /*  *********************************************************************
499     *  cs0_remap()
500     *  
501     *  Change the size of the bootrom area.
502     *  This routine is called only after CFE has been relocated to DRAM
503     *  and is executing from DRAM.  After that point, the boot rom
504     *  is serving as a flash file storage area.  Note:  this could be
505     *  done in board_earlyinit since we're not changing the base address.
506     *  
507     *  Input parameters: 
508     *      none
509     *      
510     *  Return value:
511     *      nothing
512     *  
513     *  Registers used:
514     *      t0,t1
515     ********************************************************************* */
517 LEAF(cs0_remap)
518                 li      t0,PHYS_TO_K1(A_IO_EXT_CS_BASE(BOOTROM_CS))
520                 li      t1,BOOTROM_SIZE-1    
521                 sd      t1,R_IO_EXT_MULT_SIZE(t0)
523                 j       ra
524 END(cs0_remap)
526 /*  *********************************************************************
527     *  cs1_remap()
528     *  
529     *  Change the size of the flash area.
530     *  Usually CS1 is the promice, but if it's not, the flash is here.
531     *  
532     *  Input parameters: 
533     *      none
534     *      
535     *  Return value:
536     *      nothing
537     *  
538     *  Registers used:
539     *      t0,t1
540     ********************************************************************* */
542 LEAF(cs1_remap)
543                 li      t0,PHYS_TO_K1(A_IO_EXT_CS_BASE(ALT_BOOTROM_CS))
545                 li      t1,BOOTROM_SIZE-1    
546                 sd      t1,R_IO_EXT_MULT_SIZE(t0)
548                 j       ra
549 END(cs1_remap)