1/*  *********************************************************************
2    *  SB1250 Board Support Package
3    *
4    *  Board-specific initialization		File: TINY_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
11    *
12    *********************************************************************
13    *
14    *  Copyright 2000,2001,2002,2003
15    *  Broadcom Corporation. All rights reserved.
16    *
17    *  This software is furnished under license and may be used and
18    *  copied only in accordance with the following terms and
19    *  conditions.  Subject to these conditions, you may download,
20    *  copy, install, use, modify and distribute modified or unmodified
21    *  copies of this software in source and/or binary form.  No title
22    *  or ownership is transferred hereby.
23    *
24    *  1) Any source code used, modified or distributed must reproduce
25    *     and retain this copyright notice and list of conditions
26    *     as they appear in the source file.
27    *
28    *  2) No right is granted to use any trade name, trademark, or
29    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
30    *     name may not be used to endorse or promote products derived
31    *     from this software without the prior written permission of
32    *     Broadcom Corporation.
33    *
34    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
35    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
36    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
37    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
38    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
39    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
40    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
42    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
44    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
45    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
46    *     THE POSSIBILITY OF SUCH DAMAGE.
47    ********************************************************************* */
48
49
50#include "sbmips.h"
51#include "sb1250_genbus.h"
52#include "sb1250_regs.h"
53#include "sb1250_scd.h"
54#include "bsp_config.h"
55#include "tiny.h"
56
57		.text
58
59/*  *********************************************************************
60    *  Macros
61    ********************************************************************* */
62
63
64
65/*  *********************************************************************
66    *  BOARD_EARLYINIT()
67    *
68    *  Initialize board registers.  This is the earliest
69    *  time the BSP gets control.  This routine cannot assume that
70    *  memory is operational, and therefore all code in this routine
71    *  must run from registers only.  The $ra register must not
72    *  be modified, as it contains the return address.
73    *
74    *  This routine will be called from uncached space, before
75    *  the caches are initialized.  If you want to make
76    *  subroutine calls from here, you must use the CALLKSEG1 macro.
77    *
78    *  Among other things, this is where the GPIO registers get
79    *  programmed to make on-board LEDs function, or other startup
80    *  that has to be done before anything will work.
81    *
82    *  Input parameters:
83    *  	   nothing
84    *
85    *  Return value:
86    *  	   nothing
87    ********************************************************************* */
88
89LEAF(board_earlyinit)
90
91	#
92	# Reprogram the SCD to make sure UART0 is enabled.
93	# Some CSWARM boards have the SER0 enable bit when
94	# they're not supposed to, which switches the UART
95	# into synchronous mode.  Kill off the SCD bit.
96	# XXX this should be investigated in hardware, as
97	# XXX it is a strap option on the CPU.
98	#
99
100		li      t0,PHYS_TO_K1(A_SCD_SYSTEM_CFG)
101		ld	t1,0(t0)
102		dli	t2,~M_SYS_SER0_ENABLE
103		and	t1,t1,t2
104		sd	t1,0(t0)
105
106       #
107       # Configure the GPIOs
108       #
109
110		li	t0,PHYS_TO_K1(A_GPIO_DIRECTION)
111		li	t1,GPIO_OUTPUT_MASK
112		sd	t1,0(t0)
113
114		li	t0,PHYS_TO_K1(A_GPIO_INT_TYPE)
115		li	t1,GPIO_INTERRUPT_MASK
116		sd	t1,0(t0)
117
118       #
119       # Turn on the diagnostic LED and turn off the sturgeon NMI
120       #
121		li	t0,PHYS_TO_K1(A_GPIO_PIN_SET)
122		li	t1,M_GPIO_DEBUG_LED
123		sd	t1,0(t0)
124
125		li	t0,PHYS_TO_K1(A_GPIO_PIN_CLR)
126		li	t1,M_GPIO_STURGEON_NMI
127		sd	t1,0(t0)
128
129
130       #
131       # Configure the LEDs
132       #
133
134		li	t0,PHYS_TO_K1(A_IO_EXT_CS_BASE(LEDS_CS))
135		li	t1,LEDS_PHYS >> S_IO_ADDRBASE
136		sd	t1,R_IO_EXT_START_ADDR(t0)
137
138		li	t1,LEDS_SIZE-1	/* Needs to be 1 smaller, se UM for details */
139		sd	t1,R_IO_EXT_MULT_SIZE(t0)
140
141		li	t1,LEDS_TIMING0
142		sd	t1,R_IO_EXT_TIME_CFG0(t0)
143
144		li	t1,LEDS_TIMING1
145		sd	t1,R_IO_EXT_TIME_CFG1(t0)
146
147		li	t1,LEDS_CONFIG
148		sd	t1,R_IO_EXT_CFG(t0)
149
150
151		j	ra
152
153END(board_earlyinit)
154
155
156/*  *********************************************************************
157    *  BOARD_DRAMINFO
158    *
159    *  Return the address of the DRAM information table.  Note that
160    *  the address must be obtained in a position-independent way,
161    *  so avoid the use of the "la" instruction.
162    *
163    *  Input parameters:
164    *  	   nothing
165    *
166    *  Return value:
167    *  	   v0 - DRAM info table, return 0 to use default table
168    ********************************************************************* */
169
170LEAF(board_draminfo)
171
172		move	v0,zero
173		j	ra
174
175END(board_draminfo)
176
177
178
179/*  *********************************************************************
180    *  BOARD_SETLEDS(x)
181    *
182    *  Set LEDs for boot-time progress indication.  Not used if
183    *  the board does not have progress LEDs.  This routine
184    *  must not call any other routines, since it may be invoked
185    *  either from KSEG0 or KSEG1 and it may be invoked
186    *  whether or not the icache is operational.
187    *
188    *  Input parameters:
189    *  	   a0 - LED value (8 bits per character, 4 characters)
190    *
191    *  Return value:
192    *  	   nothing
193    *
194    *  Registers used:
195    *  	   t0,t1,t2,t3
196    ********************************************************************* */
197
198
199#define LED_CHAR0	(32+8*3)
200#define LED_CHAR1	(32+8*2)
201#define LED_CHAR2	(32+8*1)
202#define LED_CHAR3	(32+8*0)
203
204LEAF(board_setleds)
205
206		li	t0,PHYS_TO_K1(LEDS_PHYS)
207
208		rol	a0,a0,8
209		and	t1,a0,0xFF
210		sb	t1,LED_CHAR0(t0)
211
212		rol	a0,a0,8
213		and	t1,a0,0xFF
214		sb	t1,LED_CHAR1(t0)
215
216		rol	a0,a0,8
217		and	t1,a0,0xFF
218		sb	t1,LED_CHAR2(t0)
219
220		rol	a0,a0,8
221		and	t1,a0,0xFF
222		sb	t1,LED_CHAR3(t0)
223
224		j	ra
225
226END(board_setleds)
227