GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / arch / mips / board / ptswarm / src / ptswarm_init.S
blob11948fc3979d3b3f649458daca8c229969541fd3
1 /*  *********************************************************************
2     *  SB1250 Board Support Package
3     *  
4     *  Board-specific initialization            File: PTSWARM_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     * 01f,09apr03,gtb    Added hardwired memory init table to set memclk to 133 MHz
15     * 01e,02feb02,jmb  Incorporate Mitch's 1.0.27 DRAM patches from CSWARM
16     * 01d,07jan02,jmb  Resizing of CS1 space
17     * 01c,20dec01,jmb  Just resize ROM space after CFE starts
18     * 01b,19dec01,jmb  Add function to remap ROM space after CFE starts
19     * 01a,14dec01,jmb  Ported from  cswarm_init.S.
20     *                  Added configuration of I/O bus for the
21     *                  external UART.  Deleted unused chip selects.
22     *  
23     *********************************************************************  
24     *
25     *  Copyright 2000,2001,2002,2003
26     *  Broadcom Corporation. All rights reserved.
27     *  
28     *  This software is furnished under license and may be used and 
29     *  copied only in accordance with the following terms and 
30     *  conditions.  Subject to these conditions, you may download, 
31     *  copy, install, use, modify and distribute modified or unmodified 
32     *  copies of this software in source and/or binary form.  No title 
33     *  or ownership is transferred hereby.
34     *  
35     *  1) Any source code used, modified or distributed must reproduce 
36     *     and retain this copyright notice and list of conditions 
37     *     as they appear in the source file.
38     *  
39     *  2) No right is granted to use any trade name, trademark, or 
40     *     logo of Broadcom Corporation.  The "Broadcom Corporation" 
41     *     name may not be used to endorse or promote products derived 
42     *     from this software without the prior written permission of 
43     *     Broadcom Corporation.
44     *  
45     *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
46     *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
47     *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
48     *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT 
49     *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN 
50     *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
51     *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
52     *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
53     *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
54     *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
55     *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
56     *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF 
57     *     THE POSSIBILITY OF SUCH DAMAGE.
58     ********************************************************************* */
61 #include "sbmips.h"
62 #include "sb1250_genbus.h"
63 #include "sb1250_regs.h"
64 #include "sb1250_scd.h"
65 #include "bsp_config.h"
66 #include "ptswarm.h"
67 #include "sb1250_draminit.h"
68 #include "../dev/ns16550.h"
70 #if defined(_PTSWARM_DIAG_CFG_)
71 #undef SERIAL_PORT_LEDS
72 #define SERIAL_PORT_LEDS
73 #endif
74                 .text
76 /*  *********************************************************************
77     *  Macros
78     ********************************************************************* */
81 #if CFG_RUNFROMKSEG0
82 #define CALLKSEG1(x)  la k0,x ; or k0,K1BASE ; jal k0
83 #else
84 #define CALLKSEG1(x)  jal x
85 #endif
88 /*  *********************************************************************
89     *  BOARD_EARLYINIT()
90     *  
91     *  Initialize board registers.  This is the earliest 
92     *  time the BSP gets control.  This routine cannot assume that
93     *  memory is operational, and therefore all code in this routine
94     *  must run from registers only.  The $ra register must not
95     *  be modified, as it contains the return address.
96     *
97     *  This routine will be called from uncached space, before
98     *  the caches are initialized.  If you want to make
99     *  subroutine calls from here, you must use the CALLKSEG1 macro.
100     *
101     *  Among other things, this is where the GPIO registers get 
102     *  programmed to make on-board LEDs function, or other startup
103     *  that has to be done before anything will work.
104     *  
105     *  Input parameters: 
106     *      nothing
107     *      
108     *  Return value:
109     *      nothing
110     ********************************************************************* */
112 LEAF(board_earlyinit)
114        #
115        # Configure the GPIOs
116        #
117        # 0 is output
118        # 1, 2, and 5 are interrupts
119        # remainder are input (unused)
120        #
122                 li      t0,PHYS_TO_K1(A_GPIO_DIRECTION)
123                 li      t1,GPIO_OUTPUT_MASK
124                 sd      t1,0(t0)
126                 li      t0,PHYS_TO_K1(A_GPIO_INT_TYPE)
127                 li      t1,GPIO_INTERRUPT_MASK
128                 sd      t1,0(t0)
130        #
131        # Turn on the diagnostic LED 
132        #
133                 li      t0,PHYS_TO_K1(A_GPIO_PIN_SET)
134                 li      t1,M_GPIO_DEBUG_LED
135                 sd      t1,0(t0)
137        #
138        # Configure the LEDs
139        #     
141                 li      t0,PHYS_TO_K1(A_IO_EXT_CS_BASE(LEDS_CS))
142                 li      t1,LEDS_PHYS >> S_IO_ADDRBASE
143                 sd      t1,R_IO_EXT_START_ADDR(t0)
145                 li      t1,LEDS_SIZE-1  /* Needs to be 1 smaller, se UM for details */
146                 sd      t1,R_IO_EXT_MULT_SIZE(t0)
148                 li      t1,LEDS_TIMING0
149                 sd      t1,R_IO_EXT_TIME_CFG0(t0)
151                 li      t1,LEDS_TIMING1
152                 sd      t1,R_IO_EXT_TIME_CFG1(t0)
154                 li      t1,LEDS_CONFIG
155                 sd      t1,R_IO_EXT_CFG(t0)
156     
157                 
159        #
160        # Configure the alternate boot ROM
161        #     
163                 li      t0,PHYS_TO_K1(A_IO_EXT_CS_BASE(ALT_BOOTROM_CS))
165                 li      t1,ALT_BOOTROM_PHYS >> S_IO_ADDRBASE
166                 sd      t1,R_IO_EXT_START_ADDR(t0)
168                 li      t1,ALT_BOOTROM_SIZE-1
169                 sd      t1,R_IO_EXT_MULT_SIZE(t0)
171                 li      t1,ALT_BOOTROM_TIMING0
172                 sd      t1,R_IO_EXT_TIME_CFG0(t0)
174                 li      t1,ALT_BOOTROM_TIMING1
175                 sd      t1,R_IO_EXT_TIME_CFG1(t0)
177                 li      t1,ALT_BOOTROM_CONFIG
178                 sd      t1,R_IO_EXT_CFG(t0)
180        #
181        # Configure I/O bus for an external UART
182        #     
184                 li      t0,PHYS_TO_K1(A_IO_EXT_CS_BASE(UART_CS))
186                 li      t1, UART_PHYS >> S_IO_ADDRBASE
187                 sd      t1,R_IO_EXT_START_ADDR(t0)
189                 li      t1, (UART_SIZE-1)
190                 sd      t1,R_IO_EXT_MULT_SIZE(t0)
192                 li      t1, (UART_TIMING0)
193                 sd      t1,R_IO_EXT_TIME_CFG0(t0)
195                 li      t1, (UART_TIMING1)
196                 sd      t1,R_IO_EXT_TIME_CFG1(t0)
198                 li      t1, (UART_CONFIG)
199                 sd      t1,R_IO_EXT_CFG(t0)
201 #ifdef SERIAL_PORT_LEDS
203         /*
204          * Initialize the UART well enough to output characters.
205          */
206                 li      t0, PHYS_TO_K1(UART_PHYS)
208                 li      t1, CFCR_DLAB
209                 sb      t1, R_UART_CFCR(t0)
211                 li      t1, BRTC(CFG_SERIAL_BAUD_RATE)
212                 sb      t1, R_UART_DATA(t0)
213                 dsra    t1, t1, 8
214                 sb      t1, R_UART_IER(t0)
216                 li      t1, CFCR_8BITS
217                 sb      t1, R_UART_CFCR(t0)
219                 li      t1, (MCR_DTR | MCR_RTS | MCR_IENABLE)
220                 sb      t1, R_UART_MCR(t0)
222                 li      t1, 0
223                 sb      t1, R_UART_IER(t0)
225                 li      t1, FIFO_ENABLE
226                 sb      t1, R_UART_FIFO(t0)
228                 /* A short delay.  */
229                 li      t1, 200
230 1:              addiu   t1, t1, -1
231                 bne     t1, zero, 1b
233                 li      t1, (FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST \
234                              | FIFO_TRIGGER_1)
235                 sb      t1, R_UART_FIFO(t0)
237                 /* A short delay.  */
238                 li      t1, 200
239 1:              addiu   t1, t1, -1
240                 bne     t1, zero, 1b
242                 /* if (value & MASK) != MASK, write 0 to fifo reg.  */
243                 lb      t1, R_UART_IIR(t0)
244                 andi    t1, t1, IIR_FIFO_MASK
245                 xori    t1, t1, IIR_FIFO_MASK
246                 beq     t1, zero, 1f
248                 li      t1, 0
249                 sb      t1, R_UART_FIFO(t0)
251 #endif
253                 j       ra
255 END(board_earlyinit)
258 /*  *********************************************************************
259     *  BOARD_DRAMINFO
260     *  
261     *  Return the address of the DRAM information table
262     *  
263     *  Input parameters: 
264     *      nothing
265     *      
266     *  Return value:
267     *      v0 - DRAM info table, return 0 to use default table
268     ********************************************************************* */
269 /* Use hard wired table */
270 #define  _HARDWIRED_MEMORY_TABLE 1  
271 #define CFG_DRAM_tROUNDTRIP DRT10(2,0)
272 /* CFG_DRAM_MIN_tMEMCLK must be set to 7.  Some DIMMS cause diag failures
273     when the memclk is at 125 MHz but pass at 100 MHz or 133 MHz.  Setting to 7 causes
274     memclk to be 133 MHz*/
275 #define CFG_DRAM_MIN_tMEMCLK  DRT10(7,0)
276 #define DEVADDR (CFG_DRAM_SMBUS_BASE)
277 #define DEFCHAN (CFG_DRAM_SMBUS_CHANNEL)
280 #if CFG_EMBEDDED_PIC
281 #define LOADREL(reg,label)                      \
282         .set noreorder ;                        \
283         bal  1f        ;                        \
284         nop            ;                        \
285 1:      nop            ;                        \
286         .set reorder   ;                        \
287         la   reg,label-1b ;                     \
288         add  reg,ra
289 #else
290 #define LOADREL(reg,label)                      \
291         la   reg,label
292 #endif
294 LEAF(board_draminfo)
296                 move    t0,ra
298 #ifdef _HARDWIRED_MEMORY_TABLE
299                 LOADREL(v0,myinfo)
300 #else
301                 move    v0,zero         # auto configure
302 #endif
304                 move    ra,t0
305                 j       ra
308  myinfo:
311 DRAM_GLOBALS(CFG_DRAM_INTERLEAVE)                       /* do port interleaving if possible */
313     /*
314      * Memory channel 0: Configure via SMBUS, Automatic Timing
315      * Assumes SMBus device numbers are arranged such
316      * that the first two addresses are CS0,1 and CS2,3 on MC0
317      * and the second two addresses are CS0,1 and CS2,3 on MC1
318      */
319  DRAM_CHAN_CFG2(MC_CHAN0, CFG_DRAM_MIN_tMEMCLK, CFG_DRAM_tROUNDTRIP,  DRAM_TYPE_SPD, CASCHECK, CFG_DRAM_BLOCK_SIZE, CFG_DRAM_CSINTERLEAVE, CFG_DRAM_ECC, 0)
320  DRAM_CHAN_CLKCFG(0x08, 0x08, 0x08, 0x0f, 0x0f, 0x0f)
322     DRAM_CS_SPD(MC_CS0, 0, DEFCHAN, DEVADDR+0)  
323     DRAM_CS_SPD(MC_CS2, 0, DEFCHAN, DEVADDR+1)
325     /*
326      * Memory channel 1: Configure via SMBUS
327      */
330     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)
331  DRAM_CHAN_CLKCFG(0x08, 0x08, 0x08, 0x0f, 0x0f, 0x0f)
333     DRAM_CS_SPD(MC_CS0, 0, DEFCHAN, DEVADDR+2)  
334     DRAM_CS_SPD(MC_CS2, 0, DEFCHAN, DEVADDR+3)
336     DRAM_EOT
339 END(board_draminfo)
342 #ifdef SERIAL_PORT_LEDS
343 /*  *********************************************************************
344     *  BOARD_UART_TXCHAR(x)
345     *  
346     *  Transmit one character out the UART on the GENERIC bus.
347     *  
348     *  Input parameters: 
349     *      a0 - 8 bit character value.
350     *      
351     *  Return value:
352     *      nothing
353     *  
354     *  Registers used:
355     *      t0,t1
356     ********************************************************************* */
358 LEAF(board_uart_txchar)
360         # Wait until there is space in the transmit buffer.
362                 li      t0, PHYS_TO_K1(UART_PHYS)
364 1:              lb      t1, R_UART_LSR(t0)
365                 andi    t1, t1, LSR_TXRDY
366                 beq     t1, zero, 1b
368         # OK, now send a character.
370                 sb      a0, R_UART_DATA(t0)
372         # And return.
374                 j       ra
376 END(board_uart_txchar)
377 #endif
380 /*  *********************************************************************
381     *  BOARD_SETLEDS(x)
382     *  
383     *  Set LEDs for boot-time progress indication.  Not used if
384     *  the board does not have progress LEDs.  This routine
385     *  must not call any other routines, since it may be invoked
386     *  either from KSEG0 or KSEG1 and it may be invoked 
387     *  whether or not the icache is operational.
388     *  
389     *  Input parameters: 
390     *      a0 - LED value (8 bits per character, 4 characters)
391     *      
392     *  Return value:
393     *      nothing
394     *  
395     *  Registers used:
396     *      t0,t1,t2,t3
397     ********************************************************************* */
400 #define LED_CHAR0       (32+8*3)
401 #define LED_CHAR1       (32+8*2)
402 #define LED_CHAR2       (32+8*1)
403 #define LED_CHAR3       (32+8*0)
405 #ifdef SERIAL_PORT_LEDS
406 #define OUTPUT_CHAR(offset)                                     \
407         li      t0, PHYS_TO_K1(LEDS_PHYS) ;                     \
408         sb      a0, offset(t0) ;                                \
409         bal     board_uart_txchar
410 #else
411 #define OUTPUT_CHAR(offset)                                     \
412         li      t0, PHYS_TO_K1(LEDS_PHYS) ;                     \
413         sb      a0, offset(t0)
414 #endif
416 LEAF(board_setleds)
418                 move    t3, ra
419                 move    t2, a0
421 #ifdef SERIAL_PORT_LEDS
422                 li      a0, '['
423                 bal     board_uart_txchar
424 #endif
426                 move    a0, t2
427                 rol     a0, 8
428                 OUTPUT_CHAR(LED_CHAR0)
430                 rol     a0, 8
431                 OUTPUT_CHAR(LED_CHAR1)
433                 rol     a0, 8
434                 OUTPUT_CHAR(LED_CHAR2)
436                 rol     a0, 8
437                 OUTPUT_CHAR(LED_CHAR3)
439 #ifdef SERIAL_PORT_LEDS
440                 li      a0, ']'
441                 bal     board_uart_txchar
442                 li      a0, '\r'
443                 bal     board_uart_txchar
444                 li      a0, '\n'
445                 bal     board_uart_txchar
446 #endif
448                 move    ra, t3
449                 j       ra
451 END(board_setleds)
453 /*  *********************************************************************
454     *  cs0_remap()
455     *  
456     *  Change the size of the bootrom area.
457     *  This routine is called only after CFE has been relocated to DRAM
458     *  and is executing from DRAM.  After that point, the boot rom
459     *  is serving as a flash file storage area.  Note:  this could be
460     *  done in board_earlyinit since we're not changing the base address.
461     *  
462     *  Input parameters: 
463     *      none
464     *      
465     *  Return value:
466     *      nothing
467     *  
468     *  Registers used:
469     *      t0,t1
470     ********************************************************************* */
472 LEAF(cs0_remap)
473                 li      t0,PHYS_TO_K1(A_IO_EXT_CS_BASE(BOOTROM_CS))
475                 li      t1,BOOTROM_SIZE-1    
476                 sd      t1,R_IO_EXT_MULT_SIZE(t0)
478                 j       ra
479 END(cs0_remap)
481 /*  *********************************************************************
482     *  cs1_remap()
483     *  
484     *  Change the size of the flash area.
485     *  Usually CS1 is the promice, but if it's not, the flash is here.
486     *  
487     *  Input parameters: 
488     *      none
489     *      
490     *  Return value:
491     *      nothing
492     *  
493     *  Registers used:
494     *      t0,t1
495     ********************************************************************* */
497 LEAF(cs1_remap)
498                 li      t0,PHYS_TO_K1(A_IO_EXT_CS_BASE(ALT_BOOTROM_CS))
500                 li      t1,BOOTROM_SIZE-1    
501                 sd      t1,R_IO_EXT_MULT_SIZE(t0)
503                 j       ra
504 END(cs1_remap)