1 /*----------------------------------------------------------------------------+
2 | This source code has been made available to you by IBM on an AS-IS
3 | basis. Anyone receiving this source is licensed under IBM
4 | copyrights to use it in any way he or she deems fit, including
5 | copying it, modifying it, compiling it, and redistributing it either
6 | with or without modifications. No license under IBM patents or
7 | patent applications is to be implied by the copyright license.
9 | Any user of this software should understand that IBM cannot provide
10 | technical support for this software and will not be responsible for
11 | any consequences resulting from the use of this software.
13 | Any person who transfers this source code or any derivative work
14 | must include the IBM copyright notice, this paragraph, and the
15 | preceding two paragraphs in the transferred software.
17 | COPYRIGHT I B M CORPORATION 1997
18 | LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
19 +----------------------------------------------------------------------------*/
20 /*----------------------------------------------------------------------------+
21 | Author: Tony J. Cerreto
24 | Purpose: Vesta Evaluation Board initialization subroutines. The following
25 | routines are available:
26 | 1. INITB_EBIU0: Initialize EBIU0.
27 | 2. INITB_CONFIG: Configure board.
28 | 3. INITB_HSMC0: Initialize HSMC0 (SDRAM).
29 | 4. INITB_HSMC1: Initialize HSMC1 (SDRAM).
30 | 5. INITB_CACHE: Initialize Data and Instruction Cache.
31 | 6. INITB_DCACHE: Initialize Data Cache.
32 | 7. INITB_ICACHE: Initialize Instruction Cache.
33 | 8. INITB_GET_CSPD: Get CPU Speed (Bus Speed and Processor Speed)
36 | Date: Author Comment:
37 | --------- ------ --------
38 | 01-Mar-00 tjc Created
39 | 04-Mar-00 jfh Modified CIC_SEL3_VAL to support 1284 (Mux3 & GPIO 21-28)
40 | 04-Mar-00 jfh Modified XILINIX Reg 0 to support 1284 (Mux3 & GPIO 21-28)
41 | 04-Mar-00 jfh Modified XILINIX Reg 1 to support 1284 (Mux3 & GPIO 21-28)
42 | 04-Mar-00 jfh Modified XILINIX Reg 4 to support 1284 (Mux3 & GPIO 21-28)
43 | 19-May-00 rlb Relcoated HSMC0 to 0x1F000000 to support 32MB of contiguous
44 | SDRAM space. Changed cache ctl regs to reflect this.
45 | 22-May-00 tjc Changed initb_get_cspd interface and eliminated
46 | initb_get_bspd routines.
47 | 26-May-00 tjc Added two nop instructions after all mtxxx/mfxxx
48 | instructions due to PPC405 bug.
49 +----------------------------------------------------------------------------*/
54 /*----------------------------------------------------------------------------+
55 | BOARD CONFIGURATION DEFINES
56 +----------------------------------------------------------------------------*/
57 #define CBS0_CR_VAL 0x00000002 /* CBS control reg value */
58 #define CIC0_CR_VAL 0xD0800448 /* CIC control reg value */
59 #define CIC0_SEL3_VAL 0x11500000 /* CIC select 3 reg value */
60 #define CIC0_VCR_VAL 0x00631700 /* CIC video cntl reg value */
62 /*----------------------------------------------------------------------------+
63 | EBIU0 BANK REGISTERS DEFINES
64 +----------------------------------------------------------------------------*/
65 #define EBIU0_BRCRH0_VAL 0x00000000 /* BR High 0 (Extension Reg)*/
66 #define EBIU0_BRCRH1_VAL 0x00000000 /* BR High 1 (Extension Reg)*/
67 #define EBIU0_BRCRH2_VAL 0x40000000 /* BR High 2 (Extension Reg)*/
68 #define EBIU0_BRCRH3_VAL 0x40000000 /* BR High 3 (Extension Reg)*/
69 #define EBIU0_BRCRH4_VAL 0x00000000 /* BR High 4 (Extension Reg)*/
70 #define EBIU0_BRCRH5_VAL 0x00000000 /* BR High 5 (Extension Reg)*/
71 #define EBIU0_BRCRH6_VAL 0x00000000 /* BR High 6 (Extension Reg)*/
72 #define EBIU0_BRCRH7_VAL 0x40000000 /* BR High 7 (Extension Reg)*/
74 #define EBIU0_BRCR0_VAL 0xFC58BFFE /* BR 0: 16 bit Flash 4 MB */
75 #define EBIU0_BRCR1_VAL 0xFF00BFFE /* BR 1: Ext Connector 1 MB */
77 #define EBIU0_BRCR2_VAL 0x207CFFBE /* BR 2: Xilinx 8 MB */
80 #define EBIU0_BRCR2_VAL 0x207CCFBE /* BR 2: Xilinx 8 MB */
83 #define EBIU0_BRCR3_VAL 0x407CBFBE /* BR 3: IDE Drive 8 MB */
84 #define EBIU0_BRCR4_VAL 0xFF00BFFF /* BR 4: Disabled. 0 MB */
85 #define EBIU0_BRCR5_VAL 0xFF00BFFF /* BR 5: Disabled. 0 MB */
86 #define EBIU0_BRCR6_VAL 0xFF00BFFF /* BR 6: Disabled. 0 MB */
87 #define EBIU0_BRCR7_VAL 0xCE3F0003 /* BR 7: Line Mode DMA 2 MB */
89 /*----------------------------------------------------------------------------+
91 +----------------------------------------------------------------------------*/
92 #define STB_GPIO0_OUTPUT (STB_GPIO0_BASE_ADDRESS+ 0x00)
93 #define STB_GPIO0_TC (STB_GPIO0_BASE_ADDRESS+ 0x04)
94 #define STB_GPIO0_OS_0_31 (STB_GPIO0_BASE_ADDRESS+ 0x08)
95 #define STB_GPIO0_OS_32_63 (STB_GPIO0_BASE_ADDRESS+ 0x0C)
96 #define STB_GPIO0_TS_0_31 (STB_GPIO0_BASE_ADDRESS+ 0x10)
97 #define STB_GPIO0_TS_32_63 (STB_GPIO0_BASE_ADDRESS+ 0x14)
98 #define STB_GPIO0_OD (STB_GPIO0_BASE_ADDRESS+ 0x18)
99 #define STB_GPIO0_INPUT (STB_GPIO0_BASE_ADDRESS+ 0x1C)
100 #define STB_GPIO0_R1 (STB_GPIO0_BASE_ADDRESS+ 0x20)
101 #define STB_GPIO0_R2 (STB_GPIO0_BASE_ADDRESS+ 0x24)
102 #define STB_GPIO0_R3 (STB_GPIO0_BASE_ADDRESS+ 0x28)
103 #define STB_GPIO0_IS_1_0_31 (STB_GPIO0_BASE_ADDRESS+ 0x30)
104 #define STB_GPIO0_IS_1_32_63 (STB_GPIO0_BASE_ADDRESS+ 0x34)
105 #define STB_GPIO0_IS_2_0_31 (STB_GPIO0_BASE_ADDRESS+ 0x38)
106 #define STB_GPIO0_IS_2_32_63 (STB_GPIO0_BASE_ADDRESS+ 0x3C)
107 #define STB_GPIO0_IS_3_0_31 (STB_GPIO0_BASE_ADDRESS+ 0x40)
108 #define STB_GPIO0_IS_3_32_63 (STB_GPIO0_BASE_ADDRESS+ 0x44)
109 #define STB_GPIO0_SS_1 (STB_GPIO0_BASE_ADDRESS+ 0x50)
110 #define STB_GPIO0_SS_2 (STB_GPIO0_BASE_ADDRESS+ 0x54)
111 #define STB_GPIO0_SS_3 (STB_GPIO0_BASE_ADDRESS+ 0x58)
113 #define GPIO0_TC_VAL 0x0C020004 /* three-state control val */
114 #define GPIO0_OS_0_31_VAL 0x51A00004 /* output select 0-31 val */
115 #define GPIO0_OS_32_63_VAL 0x0000002F /* output select 32-63 val */
116 #define GPIO0_TS_0_31_VAL 0x51A00000 /* three-state sel 0-31 val*/
117 #define GPIO0_TS_32_63_VAL 0x0000000F /* three-state sel 32-63 val*/
118 #define GPIO0_OD_VAL 0xC0000004 /* open drain val */
119 #define GPIO0_IS_1_0_31_VAL 0x50000151 /* input select 1 0-31 val */
120 #define GPIO0_IS_1_32_63_VAL 0x00000000 /* input select 1 32-63 val */
121 #define GPIO0_IS_2_0_31_VAL 0x00000000 /* input select 2 0-31 val */
122 #define GPIO0_IS_2_32_63_VAL 0x00000000 /* input select 2 32-63 val */
123 #define GPIO0_IS_3_0_31_VAL 0x00000440 /* input select 3 0-31 val */
124 #define GPIO0_IS_3_32_63_VAL 0x00000000 /* input select 3 32-63 val */
125 #define GPIO0_SS_1_VAL 0x00000000 /* sync select 1 val */
126 #define GPIO0_SS_2_VAL 0x00000000 /* sync select 2 val */
127 #define GPIO0_SS_3_VAL 0x00000000 /* sync select 3 val */
129 /*----------------------------------------------------------------------------+
131 +----------------------------------------------------------------------------*/
132 #define STB_XILINX_LED (STB_FPGA_BASE_ADDRESS+ 0x0100)
133 #define STB_XILINX1_REG0 (STB_FPGA_BASE_ADDRESS+ 0x40000)
134 #define STB_XILINX1_REG1 (STB_FPGA_BASE_ADDRESS+ 0x40002)
135 #define STB_XILINX1_REG2 (STB_FPGA_BASE_ADDRESS+ 0x40004)
136 #define STB_XILINX1_REG3 (STB_FPGA_BASE_ADDRESS+ 0x40006)
137 #define STB_XILINX1_REG4 (STB_FPGA_BASE_ADDRESS+ 0x40008)
138 #define STB_XILINX1_REG5 (STB_FPGA_BASE_ADDRESS+ 0x4000A)
139 #define STB_XILINX1_REG6 (STB_FPGA_BASE_ADDRESS+ 0x4000C)
140 #define STB_XILINX1_ID (STB_FPGA_BASE_ADDRESS+ 0x4000E)
141 #define STB_XILINX1_FLUSH (STB_FPGA_BASE_ADDRESS+ 0x4000E)
142 #define STB_XILINX2_REG0 (STB_FPGA_BASE_ADDRESS+ 0x80000)
143 #define STB_XILINX2_REG1 (STB_FPGA_BASE_ADDRESS+ 0x80002)
144 #define STB_XILINX2_REG2 (STB_FPGA_BASE_ADDRESS+ 0x80004)
146 #define XILINX1_R0_VAL 0x2440 /* Xilinx 1 Register 0 Val */
147 #define XILINX1_R1_VAL 0x0025 /* Xilinx 1 Register 1 Val */
148 #define XILINX1_R2_VAL 0x0441 /* Xilinx 1 Register 2 Val */
149 #define XILINX1_R3_VAL 0x0008 /* Xilinx 1 Register 3 Val */
150 #define XILINX1_R4_VAL 0x0100 /* Xilinx 1 Register 4 Val */
151 #define XILINX1_R5_VAL 0x6810 /* Xilinx 1 Register 5 Val */
152 #define XILINX1_R6_VAL 0x0000 /* Xilinx 1 Register 6 Val */
154 #define XILINX2_R0_VAL 0x0008 /* Xilinx 2 Register 0 Val */
155 #define XILINX2_R1_VAL 0x0000 /* Xilinx 2 Register 1 Val */
157 #define XILINX2_R0_VAL 0x0018 /* disable IBM IrDA RxD */
158 #define XILINX2_R1_VAL 0x0008 /* enable SICC MAX chip */
160 #define XILINX2_R2_VAL 0x0000 /* Xilinx 2 Register 2 Val */
162 /*----------------------------------------------------------------------------+
163 | HSMC BANK REGISTERS DEFINES
164 +----------------------------------------------------------------------------*/
166 #define HSMC0_BR0_VAL 0x000D2D55 /* 0x1F000000-007FFFFF R/W */
167 #define HSMC0_BR1_VAL 0x008D2D55 /* 0x1F800000-1FFFFFFF R/W */
169 #define HSMC0_BR0_VAL 0x1F0D2D55 /* 0x1F000000-007FFFFF R/W */
170 #define HSMC0_BR1_VAL 0x1F8D2D55 /* 0x1F800000-1FFFFFFF R/W */
172 #define HSMC1_BR0_VAL 0xA00D2D55 /* 0xA0000000-A07FFFFF R/W */
173 #define HSMC1_BR1_VAL 0xA08D2D55 /* 0xA0800000-A0FFFFFF R/W */
175 /*----------------------------------------------------------------------------+
177 +----------------------------------------------------------------------------*/
178 #define DCACHE_NLINES 128 /* no. D-cache lines */
179 #define DCACHE_NBYTES 32 /* no. bytes/ D-cache line */
180 #define ICACHE_NLINES 256 /* no. I-cache lines */
181 #define ICACHE_NBYTES 32 /* no. bytes/ I-cache line */
183 #define DCACHE_ENABLE 0x80000000 /* D-cache regions to enable*/
184 #define ICACHE_ENABLE 0x80000001 /* I-cache regions to enable*/
186 #define DCACHE_ENABLE 0x18000000 /* D-cache regions to enable*/
187 #define ICACHE_ENABLE 0x18000001 /* I-cache regions to enable*/
190 /*----------------------------------------------------------------------------+
191 | CPU CORE SPEED CALCULATION DEFINES
192 +----------------------------------------------------------------------------*/
193 #define GCS_LCNT 500000 /* CPU speed loop count */
194 #define GCS_TROW_BYTES 8 /* no. bytes in table row */
195 #define GCS_CTICK_TOL 100 /* allowable clock tick tol */
196 #define GCS_NMULT 4 /* no. of core speed mults */
198 /*--------------------------------------------------------------------+
204 +--------------------------------------------------------------------*/
206 .int 50000, 54000000 /* 54.0 Mhz */
207 .int 66667, 40500000 /* 40.5 Mhz */
208 .int 54545, 49500000 /* 49.5 Mhz */
209 .int 46154, 58500000 /* 58.5 Mhz */
210 .int 0, 0 /* end of table flag */
213 /*****************************************************************************+
214 | XXXXXXX XXX XXX XXXXXX XXXXXXX XXXXXX XX XX XX XXXX
215 | XX X XX XX X XX X XX X XX XX XXX XX XXXX XX
216 | XX X XXX XX XX X XX XX XXXX XX XX XX XX
217 | XXXX X XX XXXX XXXXX XX XXXX XX XX XX
218 | XX X XXX XX XX X XX XX XX XXX XXXXXX XX
219 | XX X XX XX XX XX X XX XX XX XX XX XX XX XX
220 | XXXXXXX XXX XXX XXXX XXXXXXX XXX XX XX XX XX XX XXXXXXX
221 +*****************************************************************************/
222 /******************************************************************************
224 | Routine: INITB_EBIU0.
226 | Purpose: Initialize all the EBIU0 Bank Registers
230 ******************************************************************************/
231 function_prolog(initb_ebiu0)
232 /*--------------------------------------------------------------------+
234 +--------------------------------------------------------------------*/
235 lis r10,EBIU0_BRCR0_VAL@h
236 ori r10,r10,EBIU0_BRCR0_VAL@l
237 mtdcr ebiu0_brcr0,r10
238 lis r10,EBIU0_BRCRH0_VAL@h
239 ori r10,r10,EBIU0_BRCRH0_VAL@l
240 mtdcr ebiu0_brcrh0,r10
242 /*--------------------------------------------------------------------+
244 +--------------------------------------------------------------------*/
245 lis r10,EBIU0_BRCR1_VAL@h
246 ori r10,r10,EBIU0_BRCR1_VAL@l
247 mtdcr ebiu0_brcr1,r10
248 lis r10,EBIU0_BRCRH1_VAL@h
249 ori r10,r10,EBIU0_BRCRH1_VAL@l
250 mtdcr ebiu0_brcrh1,r10
252 /*--------------------------------------------------------------------+
254 +--------------------------------------------------------------------*/
255 lis r10,EBIU0_BRCR2_VAL@h
256 ori r10,r10,EBIU0_BRCR2_VAL@l
257 mtdcr ebiu0_brcr2,r10
258 lis r10,EBIU0_BRCRH2_VAL@h
259 ori r10,r10,EBIU0_BRCRH2_VAL@l
260 mtdcr ebiu0_brcrh2,r10
262 /*--------------------------------------------------------------------+
264 +--------------------------------------------------------------------*/
265 lis r10,EBIU0_BRCR3_VAL@h
266 ori r10,r10,EBIU0_BRCR3_VAL@l
267 mtdcr ebiu0_brcr3,r10
268 lis r10,EBIU0_BRCRH3_VAL@h
269 ori r10,r10,EBIU0_BRCRH3_VAL@l
270 mtdcr ebiu0_brcrh3,r10
272 /*--------------------------------------------------------------------+
274 +--------------------------------------------------------------------*/
275 lis r10,EBIU0_BRCR4_VAL@h
276 ori r10,r10,EBIU0_BRCR4_VAL@l
277 mtdcr ebiu0_brcr4,r10
278 lis r10,EBIU0_BRCRH4_VAL@h
279 ori r10,r10,EBIU0_BRCRH4_VAL@l
280 mtdcr ebiu0_brcrh4,r10
282 /*--------------------------------------------------------------------+
284 +--------------------------------------------------------------------*/
285 lis r10,EBIU0_BRCR5_VAL@h
286 ori r10,r10,EBIU0_BRCR5_VAL@l
287 mtdcr ebiu0_brcr5,r10
288 lis r10,EBIU0_BRCRH5_VAL@h
289 ori r10,r10,EBIU0_BRCRH5_VAL@l
290 mtdcr ebiu0_brcrh5,r10
292 /*--------------------------------------------------------------------+
294 +--------------------------------------------------------------------*/
295 lis r10,EBIU0_BRCR6_VAL@h
296 ori r10,r10,EBIU0_BRCR6_VAL@l
297 mtdcr ebiu0_brcr6,r10
298 lis r10,EBIU0_BRCRH6_VAL@h
299 ori r10,r10,EBIU0_BRCRH6_VAL@l
300 mtdcr ebiu0_brcrh6,r10
302 /*--------------------------------------------------------------------+
304 +--------------------------------------------------------------------*/
305 lis r10,EBIU0_BRCR7_VAL@h
306 ori r10,r10,EBIU0_BRCR7_VAL@l
307 mtdcr ebiu0_brcr7,r10
308 lis r10,EBIU0_BRCRH7_VAL@h
309 ori r10,r10,EBIU0_BRCRH7_VAL@l
310 mtdcr ebiu0_brcrh7,r10
313 function_epilog(initb_ebiu0)
316 /******************************************************************************
318 | Routine: INITB_CONFIG
320 | Purpose: Configure the Vesta Evaluation Board. The following items
321 | will be configured:
322 | 1. Cross-Bar Switch.
323 | 2. Chip Interconnect.
324 | 3. Clear/reset key PPC registers.
325 | 4. Xilinx and GPIO Registers.
329 ******************************************************************************/
330 function_prolog(initb_config)
331 /*--------------------------------------------------------------------+
332 | Init CROSS-BAR SWITCH
333 +--------------------------------------------------------------------*/
334 lis r10,CBS0_CR_VAL@h /* r10 <- CBS Cntl Reg val */
335 ori r10,r10,CBS0_CR_VAL@l
338 /*--------------------------------------------------------------------+
339 | Init Chip-Interconnect (CIC) Registers
340 +--------------------------------------------------------------------*/
341 lis r10,CIC0_CR_VAL@h /* r10 <- CIC Cntl Reg val */
342 ori r10,r10,CIC0_CR_VAL@l
345 lis r10,CIC0_SEL3_VAL@h /* r10 <- CIC SEL3 Reg val */
346 ori r10,r10,CIC0_SEL3_VAL@l
349 lis r10,CIC0_VCR_VAL@h /* r10 <- CIC Vid C-Reg val */
350 ori r10,r10,CIC0_VCR_VAL@l
353 /*--------------------------------------------------------------------+
355 +--------------------------------------------------------------------*/
360 /*--------------------------------------------------------------------+
361 | Clear/set up some machine state registers.
362 +--------------------------------------------------------------------*/
363 li r10,0x0000 /* r10 <- 0 */
364 mtdcr ebiu0_besr,r10 /* clr Bus Err Syndrome Reg */
365 mtspr esr,r10 /* clr Exceptn Syndrome Reg */
366 mttcr r10 /* timer control register */
368 mtdcr uic0_er,r10 /* disable all interrupts */
370 /* UIC_IIC0 | UIC_IIC1 | UIC_U0 | UIC_IR_RCV | UIC_IR_XMIT */
371 lis r10, 0x00600e00@h
372 ori r10,r10,0x00600e00@l
375 li r10,0x00000020 /* UIC_EIR1 */
378 lis r10,0xFFFF /* r10 <- 0xFFFFFFFF */
379 ori r10,r10,0xFFFF /* */
380 mtdbsr r10 /* clear/reset the dbsr */
381 mtdcr uic0_sr,r10 /* clear pending interrupts */
383 li r10,0x1000 /* set Machine Exception bit*/
384 oris r10,r10,0x2 /* set Criticl Exception bit*/
385 mtmsr r10 /* change MSR */
387 /*--------------------------------------------------------------------+
389 +--------------------------------------------------------------------*/
393 /*--------------------------------------------------------------------+
394 | Init GPIO0 Registers
395 +--------------------------------------------------------------------*/
396 lis r10, STB_GPIO0_TC@h /* Three-state control */
397 ori r10,r10,STB_GPIO0_TC@l
398 lis r11, GPIO0_TC_VAL@h
399 ori r11,r11,GPIO0_TC_VAL@l
402 lis r10, STB_GPIO0_OS_0_31@h /* output select 0-31 */
403 ori r10,r10,STB_GPIO0_OS_0_31@l
404 lis r11, GPIO0_OS_0_31_VAL@h
405 ori r11,r11,GPIO0_OS_0_31_VAL@l
408 lis r10, STB_GPIO0_OS_32_63@h /* output select 32-63 */
409 ori r10,r10,STB_GPIO0_OS_32_63@l
410 lis r11, GPIO0_OS_32_63_VAL@h
411 ori r11,r11,GPIO0_OS_32_63_VAL@l
414 lis r10, STB_GPIO0_TS_0_31@h /* three-state select 0-31 */
415 ori r10,r10,STB_GPIO0_TS_0_31@l
416 lis r11, GPIO0_TS_0_31_VAL@h
417 ori r11,r11,GPIO0_TS_0_31_VAL@l
420 lis r10, STB_GPIO0_TS_32_63@h /* three-state select 32-63 */
421 ori r10,r10,STB_GPIO0_TS_32_63@l
422 lis r11, GPIO0_TS_32_63_VAL@h
423 ori r11,r11,GPIO0_TS_32_63_VAL@l
426 lis r10, STB_GPIO0_OD@h /* open drain */
427 ori r10,r10,STB_GPIO0_OD@l
428 lis r11, GPIO0_OD_VAL@h
429 ori r11,r11,GPIO0_OD_VAL@l
432 lis r10, STB_GPIO0_IS_1_0_31@h /* input select 1, 0-31 */
433 ori r10,r10,STB_GPIO0_IS_1_0_31@l
434 lis r11, GPIO0_IS_1_0_31_VAL@h
435 ori r11,r11,GPIO0_IS_1_0_31_VAL@l
438 lis r10, STB_GPIO0_IS_1_32_63@h /* input select 1, 32-63 */
439 ori r10,r10,STB_GPIO0_IS_1_32_63@l
440 lis r11, GPIO0_IS_1_32_63_VAL@h
441 ori r11,r11,GPIO0_IS_1_32_63_VAL@l
444 lis r10, STB_GPIO0_IS_2_0_31@h /* input select 2, 0-31 */
445 ori r10,r10,STB_GPIO0_IS_2_0_31@l
446 lis r11, GPIO0_IS_2_0_31_VAL@h
447 ori r11,r11,GPIO0_IS_2_0_31_VAL@l
450 lis r10, STB_GPIO0_IS_2_32_63@h /* input select 2, 32-63 */
451 ori r10,r10,STB_GPIO0_IS_2_32_63@l
452 lis r11, GPIO0_IS_2_32_63_VAL@h
453 ori r11,r11,GPIO0_IS_2_32_63_VAL@l
456 lis r10, STB_GPIO0_IS_3_0_31@h /* input select 3, 0-31 */
457 ori r10,r10,STB_GPIO0_IS_3_0_31@l
458 lis r11, GPIO0_IS_3_0_31_VAL@h
459 ori r11,r11,GPIO0_IS_3_0_31_VAL@l
462 lis r10, STB_GPIO0_IS_3_32_63@h /* input select 3, 32-63 */
463 ori r10,r10,STB_GPIO0_IS_3_32_63@l
464 lis r11, GPIO0_IS_3_32_63_VAL@h
465 ori r11,r11,GPIO0_IS_3_32_63_VAL@l
468 lis r10, STB_GPIO0_SS_1@h /* sync select 1 */
469 ori r10,r10,STB_GPIO0_SS_1@l
470 lis r11, GPIO0_SS_1_VAL@h
471 ori r11,r11,GPIO0_SS_1_VAL@l
474 lis r10, STB_GPIO0_SS_2@h /* sync select 2 */
475 ori r10,r10,STB_GPIO0_SS_2@l
476 lis r11, GPIO0_SS_2_VAL@h
477 ori r11,r11,GPIO0_SS_2_VAL@l
480 lis r10, STB_GPIO0_SS_3@h /* sync select 3 */
481 ori r10,r10,STB_GPIO0_SS_3@l
482 lis r11, GPIO0_SS_3_VAL@h
483 ori r11,r11,GPIO0_SS_3_VAL@l
486 /*--------------------------------------------------------------------+
487 | Init Xilinx #1 Registers
488 +--------------------------------------------------------------------*/
489 lis r10, STB_XILINX1_REG0@h /* init Xilinx1 Reg 0 */
490 ori r10,r10,STB_XILINX1_REG0@l
491 li r11,XILINX1_R0_VAL
494 lis r10, STB_XILINX1_REG1@h /* init Xilinx1 Reg 1 */
495 ori r10,r10,STB_XILINX1_REG1@l
496 li r11,XILINX1_R1_VAL
499 lis r10, STB_XILINX1_REG2@h /* init Xilinx1 Reg 2 */
500 ori r10,r10,STB_XILINX1_REG2@l
501 li r11,XILINX1_R2_VAL
504 lis r10, STB_XILINX1_REG3@h /* init Xilinx1 Reg 3 */
505 ori r10,r10,STB_XILINX1_REG3@l
506 li r11,XILINX1_R3_VAL
509 lis r10, STB_XILINX1_REG4@h /* init Xilinx1 Reg 4 */
510 ori r10,r10,STB_XILINX1_REG4@l
511 li r11,XILINX1_R4_VAL
514 lis r10, STB_XILINX1_REG5@h /* init Xilinx1 Reg 5 */
515 ori r10,r10,STB_XILINX1_REG5@l
516 li r11,XILINX1_R5_VAL
519 lis r10, STB_XILINX1_REG6@h /* init Xilinx1 Reg 6 */
520 ori r10,r10,STB_XILINX1_REG6@l
521 li r11,XILINX1_R6_VAL
524 lis r10, STB_XILINX1_FLUSH@h /* latch registers in Xilinx*/
525 ori r10,r10,STB_XILINX1_FLUSH@l
529 /*--------------------------------------------------------------------+
530 | Init Xilinx #2 Registers
531 +--------------------------------------------------------------------*/
532 lis r10, STB_XILINX2_REG0@h /* init Xilinx2 Reg 0 */
533 ori r10,r10,STB_XILINX2_REG0@l
534 li r11,XILINX2_R0_VAL
537 lis r10, STB_XILINX2_REG1@h /* init Xilinx2 Reg 1 */
538 ori r10,r10,STB_XILINX2_REG1@l
539 li r11,XILINX2_R1_VAL
542 lis r10, STB_XILINX2_REG2@h /* init Xilinx2 Reg 2 */
543 ori r10,r10,STB_XILINX2_REG2@l
544 li r11,XILINX2_R2_VAL
548 function_epilog(initb_config)
551 /******************************************************************************
553 | Routine: INITB_HSMC0.
555 | Purpose: Initialize the HSMC0 Registers for SDRAM
557 | Returns: R3 = 0: Successful
558 | = -1: Unsuccessful, SDRAM did not reset properly.
560 ******************************************************************************/
561 function_prolog(initb_hsmc0)
562 mflr r0 /* Save return addr */
564 /*--------------------------------------------------------------------+
565 | Set Global SDRAM Controller to recommended default
566 +--------------------------------------------------------------------*/
571 /*--------------------------------------------------------------------+
572 | Set HSMC0 Data Register to recommended default
573 +--------------------------------------------------------------------*/
578 /*--------------------------------------------------------------------+
579 | Init HSMC0 Bank Register 0
580 +--------------------------------------------------------------------*/
581 lis r10,HSMC0_BR0_VAL@h
582 ori r10,r10,HSMC0_BR0_VAL@l
585 /*--------------------------------------------------------------------+
586 | Init HSMC0 Bank Register 1
587 +--------------------------------------------------------------------*/
588 lis r10,HSMC0_BR1_VAL@h
589 ori r10,r10,HSMC0_BR1_VAL@l
592 /*--------------------------------------------------------------------+
593 | Set HSMC0 Control Reg 0
594 +--------------------------------------------------------------------*/
595 lis r10,0x8077 /* PRECHARGE ALL DEVICE BKS */
599 bl hsmc_cr_wait /* wait for op completion */
603 lis r10,0x8078 /* AUTO-REFRESH */
607 bl hsmc_cr_wait /* wait for op completion */
611 lis r10,0x8070 /* PROG MODE W/DATA REG VAL */
615 bl hsmc_cr_wait /* wait for op completion */
619 /*--------------------------------------------------------------------+
620 | Set HSMC0 Control Reg 1
621 +--------------------------------------------------------------------*/
622 lis r10,0x8077 /* PRECHARGE ALL DEVICE BKS */
626 bl hsmc_cr_wait /* wait for op completion */
630 lis r10,0x8078 /* AUTO-REFRESH */
634 bl hsmc_cr_wait /* wait for op completion */
638 lis r10,0x8070 /* PROG MODE W/DATA REG VAL */
642 bl hsmc_cr_wait /* wait for op completion */
646 /*--------------------------------------------------------------------+
647 | Set HSMC0 Refresh Register
648 +--------------------------------------------------------------------*/
657 function_epilog(initb_hsmc0)
660 /******************************************************************************
662 | Routine: INITB_HSMC1.
664 | Purpose: Initialize the HSMC1 Registers for SDRAM
666 | Returns: R3 = 0: Successful
667 | = -1: Unsuccessful, SDRAM did not reset properly.
669 ******************************************************************************/
670 function_prolog(initb_hsmc1)
671 mflr r0 /* Save return addr */
673 /*--------------------------------------------------------------------+
674 | Set Global SDRAM Controller to recommended default
675 +--------------------------------------------------------------------*/
680 /*--------------------------------------------------------------------+
681 | Set HSMC1 Data Register to recommended default
682 +--------------------------------------------------------------------*/
687 /*--------------------------------------------------------------------+
688 | Init HSMC1 Bank Register 0
689 +--------------------------------------------------------------------*/
690 lis r10,HSMC1_BR0_VAL@h
691 ori r10,r10,HSMC1_BR0_VAL@l
694 /*--------------------------------------------------------------------+
695 | Init HSMC1 Bank Register 1
696 +--------------------------------------------------------------------*/
697 lis r10,HSMC1_BR1_VAL@h
698 ori r10,r10,HSMC1_BR1_VAL@l
701 /*--------------------------------------------------------------------+
702 | Set HSMC1 Control Reg 0
703 +--------------------------------------------------------------------*/
704 lis r10,0x8077 /* PRECHARGE ALL DEVICE BANKS */
708 bl hsmc_cr_wait /* wait for operation completion */
712 lis r10,0x8078 /* AUTO-REFRESH */
716 bl hsmc_cr_wait /* wait for operation completion */
720 lis r10,0x8070 /* PROGRAM MODE W/DATA REG VALUE */
724 bl hsmc_cr_wait /* wait for operation completion */
728 /*--------------------------------------------------------------------+
729 | Set HSMC1 Control Reg 1
730 +--------------------------------------------------------------------*/
731 lis r10,0x8077 /* PRECHARGE ALL DEVICE BKS */
735 bl hsmc_cr_wait /* wait for op completion */
739 lis r10,0x8078 /* AUTO-REFRESH */
743 bl hsmc_cr_wait /* wait for op completion */
747 lis r10,0x8070 /* PROG MODE W/DATA REG VAL */
751 bl hsmc_cr_wait /* wait for op completion */
755 /*--------------------------------------------------------------------+
756 | Set HSMC1 Refresh Register
757 +--------------------------------------------------------------------*/
766 function_epilog(initb_hsmc1)
769 /******************************************************************************
771 | Routine: INITB_CACHE
773 | Purpose: This routine will enable Data and Instruction Cache.
774 | The Data Cache is an 8K two-way set associative and the
775 | Instruction Cache is an 16K two-way set associative cache.
781 ******************************************************************************/
782 function_prolog(initb_cache)
783 mflr r0 /* Save return addr */
785 bl initb_Dcache /* enable D-Cache */
786 bl initb_Icache /* enable I-Cache */
790 function_epilog(initb_cache)
793 /******************************************************************************
795 | Routine: INITB_DCACHE
797 | Purpose: This routine will invalidate all data in the Data Cache and
798 | then enable D-Cache. If cache is enabled already, the D-Cache
799 | will be flushed before the data is invalidated.
805 ******************************************************************************/
806 function_prolog(initb_Dcache)
807 /*--------------------------------------------------------------------+
808 | Flush Data Cache if enabled
809 +--------------------------------------------------------------------*/
810 mfdccr r10 /* r10 <- DCCR */
811 isync /* ensure prev insts done */
813 beq ic_dcinv /* D-cache off, invalidate */
815 /*--------------------------------------------------------------------+
816 | Data Cache enabled, force known memory addresses to be Cached
817 +--------------------------------------------------------------------*/
818 lis r10,HSMC0_BR0_VAL@h /* r10 <- first memory loc */
819 andis. r10,r10,0xFFF0
820 li r11,DCACHE_NLINES /* r11 <- # A-way addresses */
821 addi r11,r11,DCACHE_NLINES /* r11 <- # B-way addresses */
822 mtctr r11 /* set loop counter */
825 lwz r12,0(r10) /* force cache of address */
826 addi r10,r10,DCACHE_NBYTES /* r10 <- next memory loc */
828 sync /* ensure prev insts done */
831 /*--------------------------------------------------------------------+
832 | Flush the known memory addresses from Cache
833 +--------------------------------------------------------------------*/
834 lis r10,HSMC0_BR0_VAL@h /* r10 <- first memory loc */
835 andis. r10,r10,0xFFF0
836 mtctr r11 /* set loop counter */
839 dcbf 0,r10 /* flush D-cache line */
840 addi r10,r10,DCACHE_NBYTES /* r10 <- next memory loc */
842 sync /* ensure prev insts done */
845 /*--------------------------------------------------------------------+
846 | Disable then invalidate Data Cache
847 +--------------------------------------------------------------------*/
848 li r10,0 /* r10 <- 0 */
849 mtdccr r10 /* disable the D-Cache */
850 isync /* ensure prev insts done */
853 li r10,0 /* r10 <- line address */
854 li r11,DCACHE_NLINES /* r11 <- # lines in cache */
855 mtctr r11 /* set loop counter */
858 dccci 0,r10 /* invalidate A/B cache lns */
859 addi r10,r10,DCACHE_NBYTES /* bump to next line */
861 sync /* ensure prev insts done */
864 /*--------------------------------------------------------------------+
866 +--------------------------------------------------------------------*/
867 lis r10,DCACHE_ENABLE@h /* r10 <- D-cache enable msk*/
868 ori r10,r10,DCACHE_ENABLE@l
870 sync /* ensure prev insts done */
874 function_epilog(initb_Dcache)
877 /******************************************************************************
879 | Routine: INITB_ICACHE
881 | Purpose: This routine will invalidate all data in the Instruction
882 | Cache then enable I-Cache.
888 ******************************************************************************/
889 function_prolog(initb_Icache)
890 /*--------------------------------------------------------------------+
891 | Invalidate Instruction Cache
892 +--------------------------------------------------------------------*/
893 li r10,0 /* r10 <- lines address */
894 iccci 0,r10 /* invalidate all I-cache */
895 sync /* ensure prev insts done */
898 /*--------------------------------------------------------------------+
899 | Enable Instruction Cache
900 +--------------------------------------------------------------------*/
901 lis r10,ICACHE_ENABLE@h /* r10 <- I-cache enable msk*/
902 ori r10,r10,ICACHE_ENABLE@l
904 sync /* ensure prev insts done */
908 function_epilog(initb_Icache)
911 /******************************************************************************
913 | Routine: INITB_GET_CSPD
915 | Purpose: Determine the CPU Core Speed. The 13.5 Mhz Time Base
916 | Counter (TBC) is used to measure a conditional branch
919 | Parameters: R3 = Address of Bus Speed
920 | R4 = Address of Core Speed
922 | Returns: (R3) = >0: Bus Speed.
923 | 0: Bus Speed not found in Look-Up Table.
924 | (R4) = >0: Core Speed.
925 | 0: Core Speed not found in Look-Up Table.
927 | Note: 1. This routine assumes the bdnz branch instruction takes
928 | two instruction cycles to complete.
929 | 2. This routine must be called before interrupts are enabled.
931 ******************************************************************************/
932 function_prolog(initb_get_cspd)
933 mflr r0 /* Save return address */
934 /*--------------------------------------------------------------------+
936 +--------------------------------------------------------------------*/
937 lis r9,gcs_time_loop@h /* r9 <- addr loop instr */
938 ori r9,r9,gcs_time_loop@l
939 lis r10,GCS_LCNT@h /* r10 <- loop count */
940 ori r10,r10,GCS_LCNT@l
941 mtctr r10 /* ctr <- loop count */
942 lis r11,STB_TIMERS_TBC@h /* r11 <- TBC register addr */
943 ori r11,r11,STB_TIMERS_TBC@l
944 li r12,0 /* r12 <- 0 */
946 /*--------------------------------------------------------------------+
947 | Cache timed-loop instruction
948 +--------------------------------------------------------------------*/
953 /*--------------------------------------------------------------------+
954 | Get number of 13.5 Mhz cycles to execute time-loop
955 +--------------------------------------------------------------------*/
956 stw r12,0(r11) /* reset TBC */
958 bdnz+ gcs_time_loop /* force branch pred taken */
959 lwz r5,0(r11) /* r5 <- num 13.5 Mhz ticks */
960 li r6,5 /* LUT based on 1/5th the...*/
961 divw r5,r5,r6 /*..loop count used */
965 /*--------------------------------------------------------------------+
966 | Look-up core speed based on TBC value
967 +--------------------------------------------------------------------*/
968 lis r6,gcs_lookup_table@h /* r6 <- pts at core spd LUT*/
969 ori r6,r6,gcs_lookup_table@l
970 bl gcs_cspd_lookup /* find core speed in LUT */
972 mtlr r0 /* set return address */
974 function_epilog(initb_get_cspd)
977 /*****************************************************************************+
978 | XXXX XX XX XXXXXX XXXXXXX XXXXXX XX XX XX XXXX
979 | XX XXX XX X XX X XX X XX XX XXX XX XXXX XX
980 | XX XXXX XX XX XX X XX XX XXXX XX XX XX XX
981 | XX XX XXXX XX XXXX XXXXX XX XXXX XX XX XX
982 | XX XX XXX XX XX X XX XX XX XXX XXXXXX XX
983 | XX XX XX XX XX X XX XX XX XX XX XX XX XX
984 | XXXX XX XX XXXX XXXXXXX XXX XX XX XX XX XX XXXXXXX
985 +*****************************************************************************/
986 /******************************************************************************
988 | Routine: HSMC_CR_WAIT
990 | Purpose: Wait for the HSMC Control Register (bits 12-16) to be reset
991 | after an auto-refresh, pre-charge or program mode register
994 | Parameters: R3 = HSMC Control Register ID.
1000 | Returns: R3 = 0: Successful
1003 ******************************************************************************/
1006 li r11,10 /* r11 <- retry counter */
1007 mtctr r11 /* set retry counter */
1008 mr r11,r3 /* r11 <- HSMC CR reg id */
1011 bdz hsmc_cr_err /* branch if max retries hit*/
1013 /*--------------------------------------------------------------------+
1014 | GET HSMCx_CRx value based on HSMC Control Register ID
1015 +--------------------------------------------------------------------*/
1016 try_hsmc0_cr0: /* CHECK IF ID=HSMC0 CR0 REG*/
1017 cmpwi cr0,r11,0x0000
1018 bne cr0,try_hsmc0_cr1
1019 mfdcr r10,hsmc0_cr0 /* r11 <- HSMC0 CR0 value */
1022 try_hsmc0_cr1: /* CHECK IF ID=HSMC0 CR1 REG*/
1023 cmpwi cr0,r11,0x0001
1024 bne cr0,try_hsmc1_cr0
1025 mfdcr r10,hsmc0_cr1 /* r10 <- HSMC0 CR1 value */
1028 try_hsmc1_cr0: /* CHECK IF ID=HSMC1 CR0 REG*/
1029 cmpwi cr0,r11,0x0002
1030 bne cr0,try_hsmc1_cr1
1031 mfdcr r10,hsmc1_cr0 /* r10 <- HSMC1 CR0 value */
1034 try_hsmc1_cr1: /* CHECK IF ID=HSMC1 CR1 REG*/
1035 cmpwi cr0,r11,0x0003
1037 mfdcr r10,hsmc1_cr1 /* r10 <- HSMC1 CR1 value */
1039 /*--------------------------------------------------------------------+
1040 | Check if HSMC CR register was reset after command execution
1041 +--------------------------------------------------------------------*/
1043 lis r12,0x000F /* create "AND" mask */
1045 and. r10,r10,r12 /* r10 <- HSMC CR bits 12-16*/
1046 bne cr0,hsmc_cr_rep /* wait for bits to reset */
1047 li r3,0 /* set return code = success*/
1050 hsmc_cr_err: /* ERROR: SDRAM didn't reset*/
1051 li r3,-1 /* set RC=unsuccessful */
1057 /******************************************************************************
1059 | Routine: GCS_CSPD_LOOKUP
1061 | Purpose: Uses the number of 13.5 Mhz clock ticks found after executing
1062 | the branch instruction time loop to look-up the CPU Core Speed
1063 | in the Core Speed Look-up Table.
1065 | Parameters: R3 = Address of Bus Speed
1066 | R4 = Address of Core Speed
1067 | R5 = Number of 13.5 Mhz clock ticks found in time loop.
1068 | R6 = Pointer to Core-Speed Look-Up Table
1070 | Returns: (R3) = >0: Bus Speed.
1071 | 0: Bus Speed not found in Look-Up Table.
1072 | (R4) = >0: Core Speed.
1073 | 0: Core Speed not found in Look-Up Table.
1075 | Note: Core Speed = Bus Speed * Mult Factor (1-4x).
1077 ******************************************************************************/
1080 li r9,1 /* r9 <- core speed mult */
1081 /*--------------------------------------------------------------------+
1082 | Get theoritical number 13.5 Mhz ticks for a given Bus Speed from
1083 | Look-up Table. Check all mult factors to determine if calculated
1084 | value matches theoretical value (within a tolerance).
1085 +--------------------------------------------------------------------*/
1087 lwz r10,0(r6) /* r10 <- no. ticks from LUT*/
1088 divw r10,r10,r9 /* r10 <- div mult (1-4x) */
1089 subi r11,r10,GCS_CTICK_TOL /* r11 <- no. tks low range */
1090 addi r12,r10,GCS_CTICK_TOL /* r12 <- no. tks high range*/
1092 cmpw cr0,r5,r11 /* calc value within range? */
1093 blt gcs_cspd_retry /* less than low range */
1095 bgt gcs_cspd_retry /* greater than high range */
1096 b gcs_cspd_fnd /* calc value within range */
1098 /*--------------------------------------------------------------------+
1099 | SO FAR CORE SPEED NOT FOUND: Check next mult factor
1100 +--------------------------------------------------------------------*/
1102 addi r9,r9,1 /* bump mult factor (1-4x) */
1103 cmpwi cr0,r9,GCS_NMULT
1106 /*--------------------------------------------------------------------+
1107 | SO FAR CORE SPEED NOT FOUND: Point at next Bus Speed in LUT
1108 +--------------------------------------------------------------------*/
1109 li r9,1 /* reset mult factor */
1110 addi r6,r6,GCS_TROW_BYTES /* point at next table entry*/
1112 cmpwi cr0,r10,0 /* check for EOT flag */
1115 /*--------------------------------------------------------------------+
1116 | COMPUTE CORE SPEED AND GET BUS SPEED FROM LOOK-UP TABLE
1117 +--------------------------------------------------------------------*/
1119 lwz r5,4(r6) /* r5 <- Bus Speed in LUT */
1120 mullw r6,r5,r9 /* r6 <- Core speed */
1121 stw r5,0(r3) /* (r3) <- Bus Speed */
1122 stw r6,0(r4) /* (r4) <- Core Speed */