1 /******************************************************************************
3 * This source code has been made available to you by IBM on an AS-IS
4 * basis. Anyone receiving this source is licensed under IBM
5 * copyrights to use it in any way he or she deems fit, including
6 * copying it, modifying it, compiling it, and redistributing it either
7 * with or without modifications. No license under IBM patents or
8 * patent applications is to be implied by the copyright license.
10 * Any user of this software should understand that IBM cannot provide
11 * technical support for this software and will not be responsible for
12 * any consequences resulting from the use of this software.
14 * Any person who transfers this source code or any derivative work
15 * must include the IBM copyright notice, this paragraph, and the
16 * preceding two paragraphs in the transferred software.
18 * COPYRIGHT I B M CORPORATION 1995
19 * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
21 *****************************************************************************/
25 #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
27 #include <ppc_asm.tmpl>
30 #include <asm/cache.h>
33 /******************************************************************************
34 * Function: ext_bus_cntlr_init
36 * Description: Configures EBC Controller and a few basic chip selects.
38 * CS0 is setup to get the Boot Flash out of the addresss range
39 * so that we may setup a stack. CS7 is setup so that we can
40 * access and reset the hardware watchdog.
42 * IMPORTANT: For pass1 this code must run from
43 * cache since you can not reliably change a peripheral banks
44 * timing register (pbxap) while running code from that bank.
45 * For ex., since we are running from ROM on bank 0, we can NOT
46 * execute the code that modifies bank 0 timings from ROM, so
47 * we run it from cache.
49 * Notes: Does NOT use the stack.
50 *****************************************************************************/
53 .globl ext_bus_cntlr_init
54 .type ext_bus_cntlr_init, @function
57 /********************************************************************
58 * Prefetch entire ext_bus_cntrl_init function into the icache.
59 * This is necessary because we are going to change the same CS we
60 * are executing from. Otherwise a CPU lockup may occur.
61 *******************************************************************/
64 mflr r3 /* get address of ..getAddr */
66 /* Calculate number of cache lines for this function */
67 addi r4, 0, (((.Lfe0 - ..getAddr) / CFG_CACHELINE_SIZE) + 2)
70 icbt r0, r3 /* prefetch cache line for addr in r3*/
71 addi r3, r3, CFG_CACHELINE_SIZE /* move to next cache line */
72 bdnz ..ebcloop /* continue for $CTR cache lines */
74 /********************************************************************
75 * Delay to ensure all accesses to ROM are complete before changing
76 * bank 0 timings. 200usec should be enough.
77 * 200,000,000 (cycles/sec) X .000200 (sec) = 0x9C40 cycles.
78 *******************************************************************/
80 ori r3, r3, 0xA000 /* wait 200us from reset */
83 bdnz ..spinlp /* spin loop */
85 /********************************************************************
86 * Setup External Bus Controller (EBC).
87 *******************************************************************/
90 addis r4, 0, 0xb040 /* Device base timeout = 1024 cycles */
91 ori r4, r4, 0x0 /* Drive CS with external master */
94 /********************************************************************
95 * Change PCIINT signal to PerWE
96 *******************************************************************/
101 /********************************************************************
102 * Memory Bank 0 (Flash Bank 0) initialization
103 *******************************************************************/
106 addis r4, 0, CFG_W7O_EBC_PB0AP@h
107 ori r4, r4, CFG_W7O_EBC_PB0AP@l
112 addis r4, 0, CFG_W7O_EBC_PB0CR@h
113 ori r4, r4, CFG_W7O_EBC_PB0CR@l
116 /********************************************************************
117 * Memory Bank 7 LEDs - NEEDED BECAUSE OF HW WATCHDOG AND LEDs.
118 *******************************************************************/
121 addis r4, 0, CFG_W7O_EBC_PB7AP@h
122 ori r4, r4, CFG_W7O_EBC_PB7AP@l
127 addis r4, 0, CFG_W7O_EBC_PB7CR@h
128 ori r4, r4, CFG_W7O_EBC_PB7CR@l
131 /* We are all done */
132 mtlr r0 /* Restore link register */
133 blr /* Return to calling function */
134 .Lfe0: .size ext_bus_cntlr_init,.Lfe0-ext_bus_cntlr_init
135 /* end ext_bus_cntlr_init() */
137 /******************************************************************************
138 * Function: sdram_init
140 * Description: Configures SDRAM memory banks.
142 * Serial Presence Detect, "SPD," reads the SDRAM EEPROM
143 * via the IIC bus and then configures the SDRAM memory
144 * banks appropriately. If Auto Memory Configuration is
145 * is not used, it is assumed that a 4MB 11x8x2, non-ECC,
146 * SDRAM is soldered down.
148 * Notes: Expects that the stack is already setup.
149 *****************************************************************************/
153 .type sdram_init, @function
155 /* save the return info on stack */
156 mflr r0 /* Get link register */
157 stwu r1, -8(r1) /* Save back chain and move SP */
158 stw r0, +12(r1) /* Save link register */
161 * First call spd_sdram to try to init SDRAM according to the
162 * contents of the SPD EEPROM. If the SPD EEPROM is blank or
163 * erronious, spd_sdram returns 0 in R3.
167 addic. r3, r3, 0 /* Check for error, save dram size */
168 bne ..sdri_done /* If it worked, we're done... */
170 /********************************************************************
171 * If SPD detection fails, we'll default to 4MB, 11x8x2, as this
172 * is the SMALLEST SDRAM size the 405 supports. We can do this
173 * because W7O boards have soldered on RAM, and there will always
174 * be some amount present. If we were using DIMMs, we should hang
175 * the board instead, since it doesn't have any RAM to continue
177 *******************************************************************/
180 * Disable memory controller to allow
181 * values to be changed.
183 addi r3, 0, mem_mcopt1
190 * Set MB0CF for ext bank 0. (0-4MB) Address Mode 5 since 11x8x2
191 * All other banks are disabled.
193 addi r3, 0, mem_mb0cf
195 addis r4, 0, 0x0000 /* BA=0x0, SZ=4MB */
196 ori r4, r4, 0x8001 /* Mode is 5, 11x8x2or4, BE=Enabled */
199 /* Clear MB1CR,MB2CR,MB3CR to turn other banks off */
200 addi r4, 0, 0 /* Zero the data reg */
202 addi r3, r3, 4 /* Point to MB1CF reg */
203 mtdcr memcfga, r3 /* Set the address */
204 mtdcr memcfgd, r4 /* Zero the reg */
206 addi r3, r3, 4 /* Point to MB2CF reg */
207 mtdcr memcfga, r3 /* Set the address */
208 mtdcr memcfgd, r4 /* Zero the reg */
210 addi r3, r3, 4 /* Point to MB3CF reg */
211 mtdcr memcfga, r3 /* Set the address */
212 mtdcr memcfgd, r4 /* Zero the reg */
214 /********************************************************************
215 * Set the SDRAM Timing reg, SDTR1 and the refresh timer reg, RTR.
216 * To set the appropriate timings, we assume sdram is
217 * 100MHz (pc100 compliant).
218 *******************************************************************/
223 addi r3, 0, mem_sdtr1
225 addis r4, 0, 0x0086 /* SDTR1 value for 100Mhz */
234 addis r4, 0, 0x05F0 /* RTR refresh val = 15.625ms@100Mhz */
237 /********************************************************************
238 * Delay to ensure 200usec have elapsed since reset. Assume worst
239 * case that the core is running 200Mhz:
240 * 200,000,000 (cycles/sec) X .000200 (sec) = 0x9C40 cycles
241 *******************************************************************/
243 ori r3, r3, 0xA000 /* Wait 200us from reset */
246 bdnz ..spinlp2 /* spin loop */
248 /********************************************************************
249 * Set memory controller options reg, MCOPT1.
250 *******************************************************************/
251 addi r3, 0, mem_mcopt1
253 addis r4, 0, 0x80E0 /* DC_EN=1,SRE=0,PME=0,MEMCHK=0 */
254 ori r4, r4, 0x0000 /* REGEN=0,DRW=00,BRPF=01,ECCDD=1 */
255 mtdcr memcfgd, r4 /* EMDULR=1 */
258 /* restore and return */
259 lwz r0, +12(r1) /* Get saved link register */
260 addi r1, r1, +8 /* Remove frame from stack */
261 mtlr r0 /* Restore link register */
262 blr /* Return to calling function */
263 .Lfe1: .size sdram_init,.Lfe1-sdram_init
264 /* end sdram_init() */