1 |
27 |
unneback |
##
|
2 |
|
|
#=============================================================================
|
3 |
|
|
## platform.S
|
4 |
|
|
##
|
5 |
|
|
## MIPS Malta platform code
|
6 |
|
|
##
|
7 |
|
|
##=============================================================================
|
8 |
|
|
#####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
## -------------------------------------------
|
10 |
|
|
## This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
##
|
13 |
|
|
## eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
## the terms of the GNU General Public License as published by the Free
|
15 |
|
|
## Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
##
|
17 |
|
|
## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
## WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
## for more details.
|
21 |
|
|
##
|
22 |
|
|
## You should have received a copy of the GNU General Public License along
|
23 |
|
|
## with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
##
|
26 |
|
|
## As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
## or inline functions from this file, or you compile this file and link it
|
28 |
|
|
## with other works to produce a work based on this file, this file does not
|
29 |
|
|
## by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
## License. However the source code for this file must still be made available
|
31 |
|
|
## in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
##
|
33 |
|
|
## This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
## this file might be covered by the GNU General Public License.
|
35 |
|
|
##
|
36 |
|
|
## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
## at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
## -------------------------------------------
|
39 |
|
|
#####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
##=============================================================================
|
41 |
|
|
#######DESCRIPTIONBEGIN####
|
42 |
|
|
##
|
43 |
|
|
## Author(s): dmoseley
|
44 |
|
|
## Contributors:dmoseley, jskov
|
45 |
|
|
## Date: 2001-03-20
|
46 |
|
|
## Purpose: MIPS Malta platform code
|
47 |
|
|
## Description: Platform specific code for Malta board.
|
48 |
|
|
##
|
49 |
|
|
##
|
50 |
|
|
##
|
51 |
|
|
##
|
52 |
|
|
######DESCRIPTIONEND####
|
53 |
|
|
##
|
54 |
|
|
##=============================================================================
|
55 |
|
|
|
56 |
|
|
#include
|
57 |
|
|
#include
|
58 |
|
|
|
59 |
|
|
#ifdef CYGPKG_KERNEL
|
60 |
|
|
# include
|
61 |
|
|
#endif
|
62 |
|
|
|
63 |
|
|
#include
|
64 |
|
|
#include
|
65 |
|
|
#include
|
66 |
|
|
#include
|
67 |
|
|
#include CYGBLD_HAL_PLATFORM_H
|
68 |
|
|
|
69 |
|
|
##-----------------------------------------------------------------------------
|
70 |
|
|
|
71 |
|
|
##-----------------------------------------------------------------------------
|
72 |
|
|
# Platform Initialization.
|
73 |
|
|
# This code performs platform specific initialization.
|
74 |
|
|
|
75 |
|
|
##-----------------------------------------------------------------------------
|
76 |
|
|
## I2C accessors - these need to delay after accessing the controller.
|
77 |
|
|
// Need to delay between clocking the serial bits since the CPU is way too
|
78 |
|
|
// fast for the I2C interface. CPU runs at CYGHWR_HAL_MIPS_MALTA_CPU_CLOCK
|
79 |
|
|
// and the I2C no fasten than 1.7MHz. We want to delay the CPU for half
|
80 |
|
|
// an I2C cycle and two instructions are executed per loop, hence:
|
81 |
|
|
|
82 |
|
|
#define PAUSE \
|
83 |
|
|
li t0, (20*(CYGHWR_HAL_MIPS_MALTA_CPU_CLOCK/1700000/2/2)); \
|
84 |
|
|
99: bne t0, zero, 99b; \
|
85 |
|
|
addiu t0, -1
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
#define I2C_OE(v) \
|
89 |
|
|
li t0,v; \
|
90 |
|
|
sw t0,HAL_I2CFPGA_OE(a1); \
|
91 |
|
|
PAUSE
|
92 |
|
|
|
93 |
|
|
#define I2C_OUT(v) \
|
94 |
|
|
li t0,v; \
|
95 |
|
|
sw t0,HAL_I2CFPGA_OUT(a1); \
|
96 |
|
|
PAUSE
|
97 |
|
|
|
98 |
|
|
#define I2C_IN(v) \
|
99 |
|
|
lw v,HAL_I2CFPGA_INP(a1); \
|
100 |
|
|
andi v,v,HAL_I2CFPGA_IN_SDA_MASK; \
|
101 |
|
|
PAUSE
|
102 |
|
|
|
103 |
|
|
#define I2C_ENABLE \
|
104 |
|
|
I2C_OE(HAL_I2C_CIN_DIN); \
|
105 |
|
|
I2C_OUT(HAL_I2C_CHIGH_DHIGH); \
|
106 |
|
|
li t0,HAL_I2CFPGA_SEL_FPGA; \
|
107 |
|
|
sw t0,HAL_I2CFPGA_SEL(a1); \
|
108 |
|
|
PAUSE
|
109 |
|
|
|
110 |
|
|
##-----------------------------------------------------------------------------
|
111 |
|
|
## MEMC initialization.
|
112 |
|
|
##
|
113 |
|
|
|
114 |
|
|
#if defined(CYG_HAL_STARTUP_ROM)
|
115 |
|
|
|
116 |
|
|
.text
|
117 |
|
|
.set noreorder
|
118 |
|
|
|
119 |
|
|
.macro MASK_WRITE_PCI_REG regnum, devnum, mask
|
120 |
|
|
.set noreorder
|
121 |
|
|
# First, read the appropriate register
|
122 |
|
|
li t0, HAL_GALILEO_PCI0_CONFIG_ADDR_ConfigEn | \regnum | \devnum
|
123 |
|
|
sw t0, HAL_GALILEO_PCI0_CONFIG_ADDR_OFFSET(s7)
|
124 |
|
|
lw t1, HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET(s7)
|
125 |
|
|
|
126 |
|
|
# Now, mask in the appropriate bits
|
127 |
|
|
li t2, \mask
|
128 |
|
|
or t1, t2
|
129 |
|
|
|
130 |
|
|
# Write the updated value
|
131 |
|
|
li t0, HAL_GALILEO_PCI0_CONFIG_ADDR_ConfigEn | \regnum | \devnum
|
132 |
|
|
sw t0, HAL_GALILEO_PCI0_CONFIG_ADDR_OFFSET(s7)
|
133 |
|
|
sw t1, HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET(s7)
|
134 |
|
|
.endm
|
135 |
|
|
|
136 |
|
|
.macro WRITE_PCI_REG regnum, devnum, base
|
137 |
|
|
.set noreorder
|
138 |
|
|
li t0, HAL_GALILEO_PCI0_CONFIG_ADDR_ConfigEn | \regnum | \devnum
|
139 |
|
|
li t1, \base
|
140 |
|
|
sw t0, HAL_GALILEO_PCI0_CONFIG_ADDR_OFFSET(s7)
|
141 |
|
|
sw t1, HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET(s7)
|
142 |
|
|
.endm
|
143 |
|
|
|
144 |
|
|
#define NO_MASK 0
|
145 |
|
|
#define NO_ERROR_CHECK 0
|
146 |
|
|
#define ERROR_CHECK 1
|
147 |
|
|
.macro READ_SPD_VALUE func, mask, ret_reg, err_check
|
148 |
|
|
.set noreorder
|
149 |
|
|
jal read_spd_value
|
150 |
|
|
li a0, \func # delay slot
|
151 |
|
|
.if \err_check
|
152 |
|
|
beq v0, zero, error
|
153 |
|
|
nop
|
154 |
|
|
.endif
|
155 |
|
|
move \ret_reg, v0
|
156 |
|
|
.if \mask
|
157 |
|
|
and \ret_reg, \mask
|
158 |
|
|
.endif
|
159 |
|
|
.endm
|
160 |
|
|
|
161 |
|
|
##-----------------------------------------------------------------------------
|
162 |
|
|
##
|
163 |
|
|
## Initialize the RAM.
|
164 |
|
|
##
|
165 |
|
|
## To do that, we need to first initialize the Galileo PCI stuff to gain access
|
166 |
|
|
## to the SAA9730.
|
167 |
|
|
## From there, use the I2C bus of the SAA9730 to read the SPD SDRAM
|
168 |
|
|
## config data. We then setup the Galileo SDRAM configuration
|
169 |
|
|
##
|
170 |
|
|
## Returns
|
171 |
|
|
## v0 = Error Code
|
172 |
|
|
## v1 = SDRAM size
|
173 |
|
|
##
|
174 |
|
|
FUNC_START(hal_malta_init_sdram)
|
175 |
|
|
|
176 |
|
|
.set noreorder
|
177 |
|
|
|
178 |
|
|
# Save the return address
|
179 |
|
|
move s8, ra
|
180 |
|
|
|
181 |
|
|
# Setup the base address registers
|
182 |
|
|
li s7, CYGARC_UNCACHED_ADDRESS(HAL_GALILEO_REGISTER_BASE)
|
183 |
|
|
#
|
184 |
|
|
# Change the Galileo Base address to HAL_MALTA_CONTROLLER_BASE
|
185 |
|
|
#
|
186 |
|
|
li t0, HAL_MALTA_CONTROLLER_BASE_ISD_CONFIG
|
187 |
|
|
sw t0, HAL_GALILEO_INT_SPACE_DECODE_OFFSET(s7)
|
188 |
|
|
li s7, CYGARC_UNCACHED_ADDRESS(HAL_MALTA_CONTROLLER_BASE)
|
189 |
|
|
|
190 |
|
|
# Setup the Galileo controller Endian configuration
|
191 |
|
|
li t0, (HAL_GALILEO_BYTE_SWAP)
|
192 |
|
|
sw t0, HAL_GALILEO_PCI_INTERNAL_COMMAND_OFFSET(s7)
|
193 |
|
|
|
194 |
|
|
# Setup the PCI_0 Timeout and retry configuration
|
195 |
|
|
li t0, HAL_GALILEO_PCI0_TIMEOUT_RETRY_VALUE
|
196 |
|
|
sw t0, HAL_GALILEO_PCI0_TIMEOUT_RETRY_OFFSET(s7)
|
197 |
|
|
|
198 |
|
|
# Setup Galileo as PCI Master
|
199 |
|
|
MASK_WRITE_PCI_REG HAL_GALILEO_PCI0_STATUS_COMMAND_REGNUM, HAL_MALTA_NULL_DEVNUM, \
|
200 |
|
|
(HAL_GALILEO_PCI0_CONFIG_MEMEn | HAL_GALILEO_PCI0_CONFIG_MasEn | HAL_GALILEO_PCI0_CONFIG_SErrEn)
|
201 |
|
|
|
202 |
|
|
# Setup Galileo PCI latency timer
|
203 |
|
|
MASK_WRITE_PCI_REG HAL_GALILEO_PCI0_BIST_REGNUM, HAL_MALTA_NULL_DEVNUM, \
|
204 |
|
|
HAL_GALILEO_PCI0_LAT_TIMER_VAL
|
205 |
|
|
|
206 |
|
|
# Enable FPGA I2C
|
207 |
|
|
li a1, CYGARC_UNCACHED_ADDRESS(HAL_I2CFPGA_BASE)
|
208 |
|
|
I2C_ENABLE
|
209 |
|
|
|
210 |
|
|
##=====================================================================================
|
211 |
|
|
##
|
212 |
|
|
## Read the SPD device parameters and determine memory size
|
213 |
|
|
##
|
214 |
|
|
|
215 |
|
|
READ_SPD_VALUE HAL_SPD_GET_NUM_ROW_BITS, 0xf, s0, ERROR_CHECK
|
216 |
|
|
READ_SPD_VALUE HAL_SPD_GET_NUM_COL_BITS, 0xf, s1, ERROR_CHECK
|
217 |
|
|
|
218 |
|
|
READ_SPD_VALUE HAL_SPD_GET_NUM_DEVICE_BANKS, NO_MASK, s2, ERROR_CHECK
|
219 |
|
|
|
220 |
|
|
READ_SPD_VALUE HAL_SPD_GET_SDRAM_WIDTH, 0x7f, s3, ERROR_CHECK
|
221 |
|
|
READ_SPD_VALUE HAL_SPD_GET_NUM_MODULE_BANKS, NO_MASK, s4, ERROR_CHECK
|
222 |
|
|
READ_SPD_VALUE HAL_SPD_GET_ROW_DENSITY, NO_MASK, s5, ERROR_CHECK
|
223 |
|
|
|
224 |
|
|
READ_SPD_VALUE HAL_SPD_GET_BURST_LENGTH, NO_MASK, s6, ERROR_CHECK
|
225 |
|
|
|
226 |
|
|
#
|
227 |
|
|
# Determine Size in Mbit
|
228 |
|
|
# SIZE = SDRAM_WIDTH * NUM_DEVICE_BANKS * 2 ^ (NUM_ROW_BITS + NUM_COL_BITS)
|
229 |
|
|
#
|
230 |
|
|
addu t0, s0, s1 # t0 = (NUM_ROW_BITS + NUM_COL_BITS)
|
231 |
|
|
li t1, 1 # t1 = 2 ^ 0
|
232 |
|
|
sll t1, t0 # t1 = 2 ^ (NUM_ROW_BITS + NUM_COL_BITS)
|
233 |
|
|
multu s2, t1
|
234 |
|
|
mflo s6 # s6 = NUM_DEVICE_BANKS * 2 ^ (NUM_ROW_BITS + NUM_COL_BITS)
|
235 |
|
|
nop
|
236 |
|
|
nop
|
237 |
|
|
nop
|
238 |
|
|
multu s6, s3
|
239 |
|
|
mflo s6 # s6 = SDRAM_WIDTH * NUM_DEVICE_BANKS * 2 ^ (NUM_ROW_BITS + NUM_COL_BITS)
|
240 |
|
|
nop
|
241 |
|
|
nop
|
242 |
|
|
nop
|
243 |
|
|
|
244 |
|
|
#
|
245 |
|
|
# Determine size of Bank 0
|
246 |
|
|
# SPD Density of Each Row on Module value is used. Bit 7 represents
|
247 |
|
|
# 512MB, bit 6 256MB, etc. Highest set bit is size of bank 0.
|
248 |
|
|
# If there are two banks and these have different sizes, an extra
|
249 |
|
|
# bit will be set. If the sizes are the same, only the one bit is set.
|
250 |
|
|
# Note, at the exit of this loop, the size-bit of bank 0 will have been
|
251 |
|
|
# shifted out, allowing an easy check for multiple sizes below
|
252 |
|
|
#
|
253 |
|
|
li s0, SZ_512M
|
254 |
|
|
0:
|
255 |
|
|
and t1, s5, BIT7
|
256 |
|
|
bnez t1, 8f
|
257 |
|
|
sll s5, 1
|
258 |
|
|
b 0b
|
259 |
|
|
srl s0, 1
|
260 |
|
|
8:
|
261 |
|
|
|
262 |
|
|
#
|
263 |
|
|
# Determine if Bank 1 exists
|
264 |
|
|
#
|
265 |
|
|
li t0, 1
|
266 |
|
|
beq s4, t0, 8f
|
267 |
|
|
move s1, zero
|
268 |
|
|
#
|
269 |
|
|
# Determine if Bank 1 is different than Bank 0. If no additional bits
|
270 |
|
|
# set, size is the same.
|
271 |
|
|
#
|
272 |
|
|
and t1, s5, 0xFF
|
273 |
|
|
beq t1, zero, 8f
|
274 |
|
|
move s1, s0
|
275 |
|
|
#
|
276 |
|
|
# Determine size of Bank 1. It will be at least one factor smaller
|
277 |
|
|
# than that of bank 0.
|
278 |
|
|
#
|
279 |
|
|
sll s1,1
|
280 |
|
|
0:
|
281 |
|
|
and t1, s5, BIT7
|
282 |
|
|
bnez t1, 8f
|
283 |
|
|
sll s5, 1
|
284 |
|
|
b 0b
|
285 |
|
|
srl s1, 1
|
286 |
|
|
8:
|
287 |
|
|
|
288 |
|
|
#
|
289 |
|
|
# FIXME: We should probably do some validation on the various
|
290 |
|
|
# memory parameters here at some point.
|
291 |
|
|
#
|
292 |
|
|
|
293 |
|
|
#
|
294 |
|
|
# Set the base SDRAM bank configuration value.
|
295 |
|
|
# All other fields are zero, and the proper value is masked
|
296 |
|
|
# in when they are known
|
297 |
|
|
#
|
298 |
|
|
li s5, HAL_GALILEO_SDRAM_SRAS_TO_SCAS_DELAY_3C | \
|
299 |
|
|
HAL_GALILEO_SDRAM_WIDTH_64BIT | \
|
300 |
|
|
HAL_GALILEO_SDRAM_SRAS_PRECHARGE_3C
|
301 |
|
|
|
302 |
|
|
#
|
303 |
|
|
# Setup the CASLAT value.
|
304 |
|
|
# Support only CASLAT = 2
|
305 |
|
|
#
|
306 |
|
|
READ_SPD_VALUE HAL_SPD_GET_CAS_LAT, NO_MASK, v0, NO_ERROR_CHECK
|
307 |
|
|
and t0, v0, 2
|
308 |
|
|
beqz t0, error
|
309 |
|
|
nop
|
310 |
|
|
ori s5, HAL_GALILEO_SDRAM_BANK0_CASLAT_2
|
311 |
|
|
|
312 |
|
|
#
|
313 |
|
|
# Setup SDRAM device size
|
314 |
|
|
#
|
315 |
|
|
li t0, SZ_16M
|
316 |
|
|
beq s6, t0, 8f
|
317 |
|
|
nop
|
318 |
|
|
ori s5, HAL_GALILEO_SDRAM_BANK0_SZ_64M
|
319 |
|
|
8:
|
320 |
|
|
|
321 |
|
|
#
|
322 |
|
|
# Setup burst length: Support only 8
|
323 |
|
|
#
|
324 |
|
|
READ_SPD_VALUE HAL_SPD_GET_BURST_LENGTH, NO_MASK, v0, NO_ERROR_CHECK
|
325 |
|
|
and t0, v0, 8
|
326 |
|
|
beqz t0, error
|
327 |
|
|
nop
|
328 |
|
|
|
329 |
|
|
#
|
330 |
|
|
# Setup Parity.
|
331 |
|
|
# Only support Parity/Noparity. Don't support ECC.
|
332 |
|
|
#
|
333 |
|
|
READ_SPD_VALUE HAL_SPD_GET_CONFIG_TYPE, NO_MASK, v0, NO_ERROR_CHECK
|
334 |
|
|
li t0, HAL_SPD_CONFIG_TYPE_PARITY
|
335 |
|
|
beq t0, v0, 0f
|
336 |
|
|
nop
|
337 |
|
|
li t0, HAL_SPD_CONFIG_TYPE_ECC
|
338 |
|
|
beq t0, v0, error
|
339 |
|
|
nop
|
340 |
|
|
b 8f
|
341 |
|
|
li v1, 0
|
342 |
|
|
0:
|
343 |
|
|
ori s5, HAL_GALILEO_SDRAM_BANK0_PARITY
|
344 |
|
|
li v1, 1
|
345 |
|
|
8:
|
346 |
|
|
|
347 |
|
|
#
|
348 |
|
|
# Setup number of device banks
|
349 |
|
|
# Only support 2 or 4 banks
|
350 |
|
|
#
|
351 |
|
|
li t0, 2
|
352 |
|
|
beq s2, t0, 8f
|
353 |
|
|
nop
|
354 |
|
|
li t0, 4
|
355 |
|
|
beq s2, t0, 0f
|
356 |
|
|
nop
|
357 |
|
|
b error
|
358 |
|
|
nop
|
359 |
|
|
0:
|
360 |
|
|
ori s5, HAL_GALILEO_SDRAM_NUM_BANKS_4
|
361 |
|
|
8:
|
362 |
|
|
|
363 |
|
|
#
|
364 |
|
|
# Now actually store the bank config register
|
365 |
|
|
#
|
366 |
|
|
sw s5, HAL_GALILEO_SDRAM_BANK0_OFFSET(s7)
|
367 |
|
|
sw s5, HAL_GALILEO_SDRAM_BANK2_OFFSET(s7)
|
368 |
|
|
|
369 |
|
|
#
|
370 |
|
|
# Setup the SDRAM configuration register
|
371 |
|
|
# All other fields are zero, and the proper value is masked
|
372 |
|
|
# in when they are known
|
373 |
|
|
#
|
374 |
|
|
li s5, HAL_GALILEO_SDRAM_DUPLICATE_BANK_ADDR | HAL_GALILEO_SDRAM_BANK_INTERLEAVE_DIS
|
375 |
|
|
|
376 |
|
|
#
|
377 |
|
|
# Setup the Refresh Rate
|
378 |
|
|
#
|
379 |
|
|
READ_SPD_VALUE HAL_SPD_GET_REFRESH_RATE, 0x7f, v0, NO_ERROR_CHECK
|
380 |
|
|
|
381 |
|
|
li t0, HAL_SPD_REFRESH_RATE_125
|
382 |
|
|
beq t0, v0, 8f
|
383 |
|
|
li t0, HAL_SPD_REFRESH_COUNTER_125
|
384 |
|
|
|
385 |
|
|
li t0, HAL_SPD_REFRESH_RATE_62_5
|
386 |
|
|
beq t0, v0, 8f
|
387 |
|
|
li t0, HAL_SPD_REFRESH_COUNTER_62_5
|
388 |
|
|
|
389 |
|
|
li t0, HAL_SPD_REFRESH_RATE_31_3
|
390 |
|
|
beq t0, v0, 8f
|
391 |
|
|
li t0, HAL_SPD_REFRESH_COUNTER_31_3
|
392 |
|
|
|
393 |
|
|
li t0, HAL_SPD_REFRESH_RATE_15_625
|
394 |
|
|
beq t0, v0, 8f
|
395 |
|
|
li t0, HAL_SPD_REFRESH_COUNTER_15_625
|
396 |
|
|
|
397 |
|
|
li t0, HAL_SPD_REFRESH_RATE_7_8
|
398 |
|
|
beq t0, v0, 8f
|
399 |
|
|
li t0, HAL_SPD_REFRESH_COUNTER_7_8
|
400 |
|
|
|
401 |
|
|
# Unknown: assume 3.9 microseconds
|
402 |
|
|
li t0, HAL_SPD_REFRESH_COUNTER_3_9
|
403 |
|
|
8:
|
404 |
|
|
|
405 |
|
|
or s5, t0
|
406 |
|
|
|
407 |
|
|
#if 0 // FIXME: Dunno what this is supposed to do, but it changes the RMW flag,
|
408 |
|
|
// not anything related to RAM width.
|
409 |
|
|
#
|
410 |
|
|
# Setup RAM_WIDTH
|
411 |
|
|
#
|
412 |
|
|
beqz v1, 8f
|
413 |
|
|
nop
|
414 |
|
|
READ_SPD_VALUE HAL_SPD_GET_ERROR_CHECK_WIDTH, 0x7f, v0, NO_ERROR_CHECK
|
415 |
|
|
beq v0, zero, 8f
|
416 |
|
|
nop
|
417 |
|
|
ori s5, HAL_GALILEO_SDRAM_CFG_RAM_WIDTH
|
418 |
|
|
8:
|
419 |
|
|
#endif
|
420 |
|
|
|
421 |
|
|
#
|
422 |
|
|
# Store the SDRAM configuration register
|
423 |
|
|
#
|
424 |
|
|
sw s5, HAL_GALILEO_SDRAM_CONFIG_OFFSET(s7)
|
425 |
|
|
|
426 |
|
|
#
|
427 |
|
|
# Setup SDRAM Bank 0 Address Decoding
|
428 |
|
|
#
|
429 |
|
|
li a0, CYGARC_PHYSICAL_ADDRESS(HAL_MALTA_RAM_BASE) # Physical bottom of Bank 0
|
430 |
|
|
add a1, s0, a0
|
431 |
|
|
subu a1, 1 # Physical top of Bank 0
|
432 |
|
|
|
433 |
|
|
srl t0, a0, HAL_GALILEO_CPU_DECODE_SHIFT # Setup SCS[1:0]
|
434 |
|
|
srl t1, a1, HAL_GALILEO_CPU_DECODE_SHIFT # First level decoding
|
435 |
|
|
sw t0, HAL_GALILEO_SCS10_LD_OFFSET(s7) # (ie Processor Decode Region)
|
436 |
|
|
sw t1, HAL_GALILEO_SCS10_HD_OFFSET(s7) #
|
437 |
|
|
|
438 |
|
|
srl t0, a0, HAL_GALILEO_DEV_DECODE_SHIFT # Setup SCS0
|
439 |
|
|
srl t1, a1, HAL_GALILEO_DEV_DECODE_SHIFT # Second level decoding
|
440 |
|
|
sw t0, HAL_GALILEO_SCS0_LD_OFFSET(s7) # (ie Device Sub-decode Region)
|
441 |
|
|
sw t1, HAL_GALILEO_SCS0_HD_OFFSET(s7) #
|
442 |
|
|
|
443 |
|
|
#
|
444 |
|
|
# Setup SDRAM Bank 1 Address Decoding
|
445 |
|
|
#
|
446 |
|
|
add a0, s0, CYGARC_PHYSICAL_ADDRESS(HAL_MALTA_RAM_BASE) # Physical bottom of Bank 1
|
447 |
|
|
add a1, a0, s1
|
448 |
|
|
subu a1, 1 # Physical top of Bank 1
|
449 |
|
|
|
450 |
|
|
srl t0, a0, HAL_GALILEO_CPU_DECODE_SHIFT # Setup SCS[3:2]
|
451 |
|
|
srl t1, a1, HAL_GALILEO_CPU_DECODE_SHIFT # First level decoding
|
452 |
|
|
sw t0, HAL_GALILEO_SCS32_LD_OFFSET(s7) # (ie Processor Decode Region)
|
453 |
|
|
sw t1, HAL_GALILEO_SCS32_HD_OFFSET(s7) #
|
454 |
|
|
|
455 |
|
|
srl t0, a0, HAL_GALILEO_DEV_DECODE_SHIFT # Setup SCS2
|
456 |
|
|
srl t1, a1, HAL_GALILEO_DEV_DECODE_SHIFT # Second level decoding
|
457 |
|
|
sw t0, HAL_GALILEO_SCS2_LD_OFFSET(s7) # (ie Device Sub-decode Region)
|
458 |
|
|
sw t1, HAL_GALILEO_SCS2_HD_OFFSET(s7) #
|
459 |
|
|
|
460 |
|
|
#
|
461 |
|
|
# Setup PCI windows
|
462 |
|
|
#
|
463 |
|
|
li a0, CYGARC_PHYSICAL_ADDRESS(HAL_MALTA_PCI_MEM0_BASE)
|
464 |
|
|
add a1, a0, HAL_MALTA_PCI_MEM0_SIZE
|
465 |
|
|
subu a1, 1 # Physical top of Mem Bank 0
|
466 |
|
|
srl t0, a0, HAL_GALILEO_CPU_DECODE_SHIFT
|
467 |
|
|
srl t1, a1, HAL_GALILEO_CPU_DECODE_SHIFT
|
468 |
|
|
sw t0, HAL_GALILEO_PCIMEM0_LD_OFFSET(s7)
|
469 |
|
|
sw t1, HAL_GALILEO_PCIMEM0_HD_OFFSET(s7)
|
470 |
|
|
|
471 |
|
|
|
472 |
|
|
li a0, CYGARC_PHYSICAL_ADDRESS(HAL_MALTA_PCI_MEM1_BASE)
|
473 |
|
|
add a1, a0, HAL_MALTA_PCI_MEM1_SIZE
|
474 |
|
|
subu a1, 1 # Physical top of Mem Bank 1
|
475 |
|
|
srl t0, a0, HAL_GALILEO_CPU_DECODE_SHIFT
|
476 |
|
|
srl t1, a1, HAL_GALILEO_CPU_DECODE_SHIFT
|
477 |
|
|
sw t0, HAL_GALILEO_PCIMEM1_LD_OFFSET(s7)
|
478 |
|
|
sw t1, HAL_GALILEO_PCIMEM1_HD_OFFSET(s7)
|
479 |
|
|
|
480 |
|
|
li a0, CYGARC_PHYSICAL_ADDRESS(HAL_MALTA_PCI_IO_BASE)
|
481 |
|
|
add a1, a0, HAL_MALTA_PCI_IO_SIZE
|
482 |
|
|
subu a1, 1 # Physical top of IO Bank
|
483 |
|
|
srl t0, a0, HAL_GALILEO_CPU_DECODE_SHIFT
|
484 |
|
|
srl t1, a1, HAL_GALILEO_CPU_DECODE_SHIFT
|
485 |
|
|
sw t0, HAL_GALILEO_PCIIO_LD_OFFSET(s7)
|
486 |
|
|
sw t1, HAL_GALILEO_PCIIO_HD_OFFSET(s7)
|
487 |
|
|
|
488 |
|
|
# Here's a nice gotcha. The Intel southbridge *must* see IO
|
489 |
|
|
# starting from 0.
|
490 |
|
|
sw zero,HAL_GALILEO_PCI_IO_REMAP(s7)
|
491 |
|
|
|
492 |
|
|
#
|
493 |
|
|
# Setup FLASH Address Decoding
|
494 |
|
|
#
|
495 |
|
|
li a0, CYGARC_PHYSICAL_ADDRESS(HAL_MALTA_FLASH_BASE) # Physical bottom of Flash Bank
|
496 |
|
|
add a1, a0, HAL_MALTA_FLASH_SIZE
|
497 |
|
|
subu a1, 1 # Physical top of Flash Bank
|
498 |
|
|
|
499 |
|
|
srl t0, a0, HAL_GALILEO_CPU_DECODE_SHIFT # Setup CS[2:0]
|
500 |
|
|
srl t1, a1, HAL_GALILEO_CPU_DECODE_SHIFT # First level decoding
|
501 |
|
|
sw t0, HAL_GALILEO_CS20_LD_OFFSET(s7) # (ie Processor Decode Region)
|
502 |
|
|
sw t1, HAL_GALILEO_CS20_HD_OFFSET(s7) #
|
503 |
|
|
|
504 |
|
|
srl t0, a0, HAL_GALILEO_DEV_DECODE_SHIFT # Setup CS0
|
505 |
|
|
srl t1, a1, HAL_GALILEO_DEV_DECODE_SHIFT # Second level decoding
|
506 |
|
|
sw t0, HAL_GALILEO_CS0_LD_OFFSET(s7) # (ie Device Sub-decode Region)
|
507 |
|
|
sw t1, HAL_GALILEO_CS0_HD_OFFSET(s7) #
|
508 |
|
|
|
509 |
|
|
#
|
510 |
|
|
# Now disable all unused decodes
|
511 |
|
|
# (SCS1, SCS3, PCI1xx, CS1, CS2)
|
512 |
|
|
#
|
513 |
|
|
li t0, 0xffff
|
514 |
|
|
move t1, zero
|
515 |
|
|
sw t0, HAL_GALILEO_SCS1_LD_OFFSET(s7)
|
516 |
|
|
sw t1, HAL_GALILEO_SCS1_HD_OFFSET(s7)
|
517 |
|
|
sw t0, HAL_GALILEO_SCS3_LD_OFFSET(s7)
|
518 |
|
|
sw t1, HAL_GALILEO_SCS3_HD_OFFSET(s7)
|
519 |
|
|
sw t0, HAL_GALILEO_PCI1IO_LD_OFFSET(s7)
|
520 |
|
|
sw t1, HAL_GALILEO_PCI1IO_HD_OFFSET(s7)
|
521 |
|
|
sw t0, HAL_GALILEO_PCI1MEM0_LD_OFFSET(s7)
|
522 |
|
|
sw t1, HAL_GALILEO_PCI1MEM0_HD_OFFSET(s7)
|
523 |
|
|
sw t0, HAL_GALILEO_PCI1MEM1_LD_OFFSET(s7)
|
524 |
|
|
sw t1, HAL_GALILEO_PCI1MEM1_HD_OFFSET(s7)
|
525 |
|
|
sw t0, HAL_GALILEO_CS1_LD_OFFSET(s7)
|
526 |
|
|
sw t1, HAL_GALILEO_CS1_HD_OFFSET(s7)
|
527 |
|
|
sw t0, HAL_GALILEO_CS2_LD_OFFSET(s7)
|
528 |
|
|
sw t1, HAL_GALILEO_CS2_HD_OFFSET(s7)
|
529 |
|
|
|
530 |
|
|
noerror:
|
531 |
|
|
move v0, zero
|
532 |
|
|
add v1, s0, s1
|
533 |
|
|
move ra, s8
|
534 |
|
|
jr ra
|
535 |
|
|
nop
|
536 |
|
|
|
537 |
|
|
error:
|
538 |
|
|
li v0, HAL_MALTA_MEMERROR
|
539 |
|
|
move ra, s8
|
540 |
|
|
jr ra
|
541 |
|
|
nop
|
542 |
|
|
|
543 |
|
|
FUNC_END(hal_malta_init_sdram)
|
544 |
|
|
|
545 |
|
|
.macro i2c_start
|
546 |
|
|
# Start: SDA low -> high with SLC high
|
547 |
|
|
I2C_OE(HAL_I2C_COUT_DOUT)
|
548 |
|
|
I2C_OUT(HAL_I2C_CHIGH_DHIGH)
|
549 |
|
|
I2C_OUT(HAL_I2C_CHIGH_DLOW)
|
550 |
|
|
I2C_OUT(HAL_I2C_CLOW_DLOW)
|
551 |
|
|
.endm
|
552 |
|
|
|
553 |
|
|
.macro i2c_stop
|
554 |
|
|
# Stop: SDA high -> low with SLC high
|
555 |
|
|
I2C_OE(HAL_I2C_COUT_DOUT)
|
556 |
|
|
I2C_OUT(HAL_I2C_CLOW_DLOW)
|
557 |
|
|
I2C_OUT(HAL_I2C_CHIGH_DLOW)
|
558 |
|
|
I2C_OUT(HAL_I2C_CHIGH_DHIGH)
|
559 |
|
|
I2C_OUT(HAL_I2C_CLOW_DHIGH)
|
560 |
|
|
.endm
|
561 |
|
|
|
562 |
|
|
.macro i2c_write
|
563 |
|
|
# Value to write in t1.
|
564 |
|
|
# Writes happen by clocking SCL low->high->low while SDA defines
|
565 |
|
|
# the bit to be sent (MSB first).
|
566 |
|
|
I2C_OE(HAL_I2C_COUT_DOUT)
|
567 |
|
|
li t2, 7
|
568 |
|
|
1: srlv t3, t1, t2
|
569 |
|
|
andi t3, 1
|
570 |
|
|
beq t3, zero, 2f
|
571 |
|
|
nop
|
572 |
|
|
# Send 1
|
573 |
|
|
I2C_OUT(HAL_I2C_CLOW_DHIGH)
|
574 |
|
|
I2C_OUT(HAL_I2C_CHIGH_DHIGH)
|
575 |
|
|
I2C_OUT(HAL_I2C_CLOW_DHIGH)
|
576 |
|
|
b 3f
|
577 |
|
|
nop
|
578 |
|
|
|
579 |
|
|
2: # Send 0
|
580 |
|
|
I2C_OUT(HAL_I2C_CLOW_DLOW)
|
581 |
|
|
I2C_OUT(HAL_I2C_CHIGH_DLOW)
|
582 |
|
|
I2C_OUT(HAL_I2C_CLOW_DLOW)
|
583 |
|
|
|
584 |
|
|
3: bne t2, zero, 1b
|
585 |
|
|
addiu t2, -1
|
586 |
|
|
|
587 |
|
|
# Now tristate the SDA and pulse the clock. Receiver will
|
588 |
|
|
# ack the transfer by pulling SDA low.
|
589 |
|
|
# Read by pulsing clock. Leave result in t1
|
590 |
|
|
I2C_OE(HAL_I2C_COUT_DIN)
|
591 |
|
|
I2C_OUT(HAL_I2C_CHIGH_DHIGH)
|
592 |
|
|
I2C_IN(t1)
|
593 |
|
|
I2C_OUT(HAL_I2C_CLOW_DHIGH)
|
594 |
|
|
.endm
|
595 |
|
|
|
596 |
|
|
.macro i2c_read
|
597 |
|
|
# Value read is returned in t1
|
598 |
|
|
# Reads happen by clocking SCL high->low while reading SDA
|
599 |
|
|
I2C_OE(HAL_I2C_COUT_DIN)
|
600 |
|
|
move t1,zero
|
601 |
|
|
li t2, 7
|
602 |
|
|
1: I2C_OUT(HAL_I2C_CHIGH_DHIGH)
|
603 |
|
|
I2C_IN(t3)
|
604 |
|
|
sll t1,1
|
605 |
|
|
or t1,t1,t3
|
606 |
|
|
I2C_OUT(HAL_I2C_CLOW_DHIGH)
|
607 |
|
|
|
608 |
|
|
bne t2, zero, 1b
|
609 |
|
|
addiu t2, -1
|
610 |
|
|
|
611 |
|
|
// Send ack by clocking with SDA low.
|
612 |
|
|
I2C_OUT(HAL_I2C_CLOW_DHIGH)
|
613 |
|
|
I2C_OE(HAL_I2C_COUT_DOUT)
|
614 |
|
|
I2C_OUT(HAL_I2C_CHIGH_DHIGH)
|
615 |
|
|
I2C_OUT(HAL_I2C_CLOW_DHIGH)
|
616 |
|
|
.endm
|
617 |
|
|
|
618 |
|
|
##
|
619 |
|
|
## Read a value from the SDRAM SPD device.
|
620 |
|
|
##
|
621 |
|
|
## Parameters: a0 = subaddress
|
622 |
|
|
## Returns: v0 = SPD value read
|
623 |
|
|
##
|
624 |
|
|
FUNC_START(read_spd_value)
|
625 |
|
|
.set noreorder
|
626 |
|
|
# Setup a base address register
|
627 |
|
|
li a1, CYGARC_UNCACHED_ADDRESS(HAL_I2CFPGA_BASE)
|
628 |
|
|
|
629 |
|
|
i2c_start
|
630 |
|
|
|
631 |
|
|
# Write address of SDRAM sense controller
|
632 |
|
|
li t1,( HAL_I2C_SPD_ADDRESS | HAL_I2C_WRITE )
|
633 |
|
|
i2c_write
|
634 |
|
|
li t0,HAL_I2CFPGA_OUT_SDA_NACK
|
635 |
|
|
beq t0,t1,i2c_error
|
636 |
|
|
move v0,zero
|
637 |
|
|
|
638 |
|
|
# Write address of data wanted
|
639 |
|
|
move t1,a0
|
640 |
|
|
i2c_write
|
641 |
|
|
li t0,HAL_I2CFPGA_OUT_SDA_NACK
|
642 |
|
|
beq t0,t1,i2c_error
|
643 |
|
|
move v0,zero
|
644 |
|
|
|
645 |
|
|
i2c_start
|
646 |
|
|
|
647 |
|
|
# Write address of SDRAM sense controller
|
648 |
|
|
li t1,( HAL_I2C_SPD_ADDRESS | HAL_I2C_READ )
|
649 |
|
|
i2c_write
|
650 |
|
|
li t0,HAL_I2CFPGA_OUT_SDA_NACK
|
651 |
|
|
beq t0,t1,i2c_error
|
652 |
|
|
move v0,zero
|
653 |
|
|
|
654 |
|
|
# Read data
|
655 |
|
|
i2c_read
|
656 |
|
|
move v0,t1
|
657 |
|
|
|
658 |
|
|
i2c_stop
|
659 |
|
|
|
660 |
|
|
i2c_error:
|
661 |
|
|
jr ra
|
662 |
|
|
nop
|
663 |
|
|
|
664 |
|
|
FUNC_END(read_spd_value)
|
665 |
|
|
#endif // defined(CYG_HAL_STARTUP_ROM)
|
666 |
|
|
|
667 |
|
|
##-----------------------------------------------------------------------------
|
668 |
|
|
## ISR springboard.
|
669 |
|
|
## This routine decodes the interrupt from the southbridge and vectors to it.
|
670 |
|
|
|
671 |
|
|
# On entry:
|
672 |
|
|
# a0 = MIPS status register interrupt number (1,2 or 3)
|
673 |
|
|
# a1 = ISR data value (= interrupt controller reg address)
|
674 |
|
|
# a2 = saved reg dump ptr
|
675 |
|
|
# s0 = saved reg dump ptr
|
676 |
|
|
# s1 = vector table offset
|
677 |
|
|
# s2 = interrupt number
|
678 |
|
|
# a3,v0,v1 etc available for use
|
679 |
|
|
|
680 |
|
|
.text
|
681 |
|
|
|
682 |
|
|
FUNC_START(hal_isr_springboard_southbridge)
|
683 |
|
|
.set noreorder
|
684 |
|
|
# Get req bits of controller 1
|
685 |
|
|
lb v0,0(a1)
|
686 |
|
|
lb v1,1(a1) # apply mask
|
687 |
|
|
xori v1,v1,0xffff
|
688 |
|
|
and v0,v0,v1
|
689 |
|
|
andi v1,v0,0xffff&~(1<<(CYGNUM_HAL_INTERRUPT_CASCADE-CYGNUM_HAL_INTERRUPT_CTRL1_BASE))
|
690 |
|
|
bne v1,zero,1f
|
691 |
|
|
ori a2,zero,CYGNUM_HAL_INTERRUPT_CTRL1_BASE
|
692 |
|
|
# If cascade is set, check controller 2
|
693 |
|
|
andi v0,v0,(1<<(CYGNUM_HAL_INTERRUPT_CASCADE-CYGNUM_HAL_INTERRUPT_CTRL1_BASE))
|
694 |
|
|
beq v0,zero,2f
|
695 |
|
|
lb v0,HAL_PIIX4_MASTER_SLAVE_OFFSET(a1)
|
696 |
|
|
lb v1,HAL_PIIX4_MASTER_SLAVE_OFFSET+1(a1) # apply mask
|
697 |
|
|
xori v1,v1,0xffff
|
698 |
|
|
and v0,v0,v1
|
699 |
|
|
bne v0,zero,1f
|
700 |
|
|
ori a2,zero,CYGNUM_HAL_INTERRUPT_CTRL2_BASE
|
701 |
|
|
# Spurious interrupt, return to VSR
|
702 |
|
|
2: jr ra
|
703 |
|
|
move v0,zero
|
704 |
|
|
1:
|
705 |
|
|
|
706 |
|
|
# FIXME: May want to rewrite this to do ls bit on byte
|
707 |
|
|
# to save a few cycles.
|
708 |
|
|
# The following code implements an ls bit index algorithm similar
|
709 |
|
|
# to that in hal_lsbit_index() in hal_misc.c.
|
710 |
|
|
negu v1,v0 # v1 = -v0
|
711 |
|
|
and v1,v1,v0 # v1 &= v0 [isolate ls bit]
|
712 |
|
|
sll v0,v1,16 # v0 = v1<<16
|
713 |
|
|
subu v1,v0,v1 # v1 = v0 - v1
|
714 |
|
|
sll a0,v1,6 # a0 = v1<<6
|
715 |
|
|
addu v1,v1,a0 # v1 += a0
|
716 |
|
|
sll a1,v1,4 # a1 = v1<<4
|
717 |
|
|
addu v1,v1,a1 # v1 += a1
|
718 |
|
|
la v0,hal_isr_springboard_table # v0 = table address
|
719 |
|
|
srl v1,v1,26 # v1 = v1>>26
|
720 |
|
|
addu v1,v1,v0 # v1 = table entry address
|
721 |
|
|
lb a0,0(v1) # a0 = intc isr number
|
722 |
|
|
|
723 |
|
|
add s2,a0,a2 # s2 = eCos isr number
|
724 |
|
|
#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN
|
725 |
|
|
hal_isr_springboard_chaining:
|
726 |
|
|
# This serves as the __default_interrupt_isr entry-point in
|
727 |
|
|
# chaning mode, thus ensuring that all interrupts from
|
728 |
|
|
# vectors 0-5 eventually end up on the special CHAINING vector.
|
729 |
|
|
# (See the hal_interrupt_handlers table)
|
730 |
|
|
ori s1,zero,CYGNUM_HAL_INTERRUPT_CHAINING*4 # s1 = chaining isr ix
|
731 |
|
|
#else
|
732 |
|
|
sll s1,s2,2 # s1 = isr table index
|
733 |
|
|
#endif
|
734 |
|
|
|
735 |
|
|
la v1,hal_interrupt_handlers
|
736 |
|
|
add v1,v1,s1 # v1 = isr handler address
|
737 |
|
|
lw v1,0(v1) # v1 = isr handler
|
738 |
|
|
|
739 |
|
|
la a1,hal_interrupt_data
|
740 |
|
|
add a1,a1,s1 # a1 = address of data ptr
|
741 |
|
|
lw a1,0(a1) # a1 = data pointer
|
742 |
|
|
|
743 |
|
|
move a0,s2 # pass interrupt number
|
744 |
|
|
|
745 |
|
|
jr v1 # jump to handler, return is to
|
746 |
|
|
nop # default vsr already in ra
|
747 |
|
|
|
748 |
|
|
FUNC_END(hal_isr_springboard_southbridge)
|
749 |
|
|
|
750 |
|
|
|
751 |
|
|
hal_isr_springboard_table:
|
752 |
|
|
.byte -1, 0, 1, 12, 2, 6, 0, 13
|
753 |
|
|
.byte 3, 0, 7, 0, 0, 0, 0, 14
|
754 |
|
|
.byte 10, 4, 0, 0, 8, 0, 0, 25
|
755 |
|
|
.byte 0, 0, 0, 0, 0, 21, 27, 15
|
756 |
|
|
.byte 31, 11, 5, 0, 0, 0, 0, 0
|
757 |
|
|
.byte 9, 0, 0, 24, 0, 0, 20, 26
|
758 |
|
|
.byte 30, 0, 0, 0, 0, 23, 0, 19
|
759 |
|
|
.byte 29, 0, 22, 18, 28, 17, 16, 0
|
760 |
|
|
|
761 |
|
|
##-----------------------------------------------------------------------------
|
762 |
|
|
# Interrupt vector tables.
|
763 |
|
|
# These tables contain the isr, data and object pointers used to deliver
|
764 |
|
|
# interrupts to user code.
|
765 |
|
|
|
766 |
|
|
.extern hal_default_isr
|
767 |
|
|
|
768 |
|
|
.data
|
769 |
|
|
|
770 |
|
|
.globl hal_interrupt_handlers
|
771 |
|
|
hal_interrupt_handlers:
|
772 |
|
|
.long hal_isr_springboard_southbridge
|
773 |
|
|
.rept CYGNUM_HAL_ISR_COUNT-1
|
774 |
|
|
.long hal_default_isr
|
775 |
|
|
.endr
|
776 |
|
|
|
777 |
|
|
.globl hal_interrupt_data
|
778 |
|
|
hal_interrupt_data:
|
779 |
|
|
.long HAL_PIIX4_MASTER_OCW3
|
780 |
|
|
.rept CYGNUM_HAL_ISR_COUNT-1
|
781 |
|
|
.long 0
|
782 |
|
|
.endr
|
783 |
|
|
|
784 |
|
|
.globl hal_interrupt_objects
|
785 |
|
|
hal_interrupt_objects:
|
786 |
|
|
.rept CYGNUM_HAL_ISR_COUNT
|
787 |
|
|
.long 0
|
788 |
|
|
.endr
|
789 |
|
|
|
790 |
|
|
|
791 |
|
|
##-----------------------------------------------------------------------------
|
792 |
|
|
## end of platform.S
|