2 * Most of this taken from Redboot hal_platform_setup.h with cleanup
4 * NOTE: I haven't clean this up considerably, just enough to get it
5 * running. See hal_platform_setup.h for the source. See
6 * board/cradle/memsetup.S for another PXA250 setup that is
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #include <asm/arch/pxa-regs.h>
32 DRAM_SIZE: .long CFG_DRAM_SIZE
34 /* wait for coprocessor write complete */
36 mrc p15,0,\reg,c2,c0,0
47 /* Set up GPIO pins first */
50 ldr r1, =CFG_GPSR0_VAL
54 ldr r1, =CFG_GPSR1_VAL
58 ldr r1, =CFG_GPSR2_VAL
62 ldr r1, =CFG_GPCR0_VAL
66 ldr r1, =CFG_GPCR1_VAL
70 ldr r1, =CFG_GPCR2_VAL
74 ldr r1, =CFG_GPDR0_VAL
78 ldr r1, =CFG_GPDR1_VAL
82 ldr r1, =CFG_GPDR2_VAL
86 ldr r1, =CFG_GAFR0_L_VAL
90 ldr r1, =CFG_GAFR0_U_VAL
94 ldr r1, =CFG_GAFR1_L_VAL
98 ldr r1, =CFG_GAFR1_U_VAL
102 ldr r1, =CFG_GAFR2_L_VAL
106 ldr r1, =CFG_GAFR2_U_VAL
109 /* enable GPIO pins */
111 ldr r1, =CFG_PSSR_VAL
114 ldr r3, =MSC1 /* low - bank 2 Lubbock Registers / SRAM */
115 ldr r2, =CFG_MSC1_VAL /* high - bank 3 Ethernet Controller */
116 str r2, [r3] /* need to set MSC1 before trying to write to the HEX LEDs */
117 ldr r2, [r3] /* need to read it back to make sure the value latches (see MSC section of manual) */
121 str r0, [r1] /* turn on hex leds */
126 str r0, [r1] /* hex display */
128 /*********************************************************************
129 Initlialize Memory Controller
130 The sequence below is based on the recommended init steps detailed
131 in the EAS, chapter 5 (Chapter 10, Operating Systems Developers Guide)
134 pause for 200 uSecs- allow internal clocks to settle
135 *Note: only need this if hard reset... doing it anyway for now
139 ldr r3, =OSCR @ reset the OS Timer Count to zero
142 ldr r4, =0x300 @ really 0x2E1 is about 200usec, so 0x300 should be plenty
149 @ get memory controller base address
152 @****************************************************************************
156 @ write msc0, read back to ensure data latches
158 ldr r2, =CFG_MSC0_VAL
159 str r2, [r1, #MSC0_OFFSET]
160 ldr r2, [r1, #MSC0_OFFSET]
163 ldr r2, =CFG_MSC1_VAL
164 str r2, [r1, #MSC1_OFFSET]
165 ldr r2, [r1, #MSC1_OFFSET]
168 ldr r2, =CFG_MSC2_VAL
169 str r2, [r1, #MSC2_OFFSET]
170 ldr r2, [r1, #MSC2_OFFSET]
173 ldr r2, =CFG_MECR_VAL
174 str r2, [r1, #MECR_OFFSET]
177 ldr r2, =CFG_MCMEM0_VAL
178 str r2, [r1, #MCMEM0_OFFSET]
181 ldr r2, =CFG_MCMEM1_VAL
182 str r2, [r1, #MCMEM1_OFFSET]
185 ldr r2, =CFG_MCATT0_VAL
186 str r2, [r1, #MCATT0_OFFSET]
189 ldr r2, =CFG_MCATT1_VAL
190 str r2, [r1, #MCATT1_OFFSET]
193 ldr r2, =CFG_MCIO0_VAL
194 str r2, [r1, #MCIO0_OFFSET]
197 ldr r2, =CFG_MCIO1_VAL
198 str r2, [r1, #MCIO1_OFFSET]
200 @-------------------------------------------------------
204 @ get the mdrefr settings
205 ldr r3, =CFG_MDREFR_VAL_100
207 @ extract DRI field (we need a valid DRI field)
211 @ valid DRI field in r3
215 @ get the reset state of MDREFR
217 ldr r4, [r1, #MDREFR_OFFSET]
219 @ clear the DRI field
223 @ insert the valid DRI field loaded above
229 str r4, [r1, #MDREFR_OFFSET]
231 @ *Note: preserve the mdrefr value in r4 *
233 @****************************************************************************
236 /* This should be for SRAM, why is it commented out??? */
242 @str r2, [r1, #SXCNFG_OFFSET]
244 /* @if sxcnfg=0, don't program for synch-static memory */
249 @ldr r2, =SXMRS_SETTINGS
250 @str r2, [r1, #SXMRS_OFFSET]
253 @****************************************************************************
257 @ Assumes previous mdrefr value in r4, if not then read current mdrefr
259 @ clear the free-running clock bits
260 @ (clear K0Free, K1Free, K2Free
262 bic r4, r4, #(0x00800000 | 0x01000000 | 0x02000000)
264 @ set K1RUN if bank 0 installed
266 orr r4, r4, #0x00010000
271 @<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<
272 @<!<!<!<!<!<!<!<!<!<!<! Begin INSERT 1 <!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<
273 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
274 @ Lubbock: Allow the user to select the {T/R/M} with predetermined
275 @ SDCLK. Based on Table 3-1 in PXA250 and PXA210 Dev Man.
277 @ * = Must set MDREFR.K1DB2 to halve the MemClk for desired SDCLK[1]
279 @ S25, S26 used to provide all 400 MHz BIN values for Cotulla (0,0 - 1,3)
280 @ S25, S26 used to provide all 200 MHz BIN values for Sabinal
282 @ S23: Force the halving of MemClk when deriving SDCLK[1]
283 @ DOT: no override !DOT: halve (if not already forced half)
284 /* @ *For certain MemClks, SDCLK's derivation is forced to be halved */
287 @ DOT: Run mode !DOT: Turbo mode
288 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
291 @ Allow the user to control K1DB2 where applicable
293 @ Get the value of S23: @ 1 = DOT (unity), 0 = !DOT (halve it)
295 @ DOT: set K1DB2 (SDCLD = MemClk)
296 @ !DOT: clear K1DB2 (SDCLK = MemClk/2)
298 @ldr r2, =FPGA_REGS_BASE_PHYSICAL
300 bl GET_S23 @ r3, r2 @ get the value of S23 in R0, i put the base adx of fpga in r3
302 cmp r3, #0x0 @ is !DOT?
303 orreq r4, r4, #0x00020000 @ SDClk[1] = MemClk/2
304 bicne r4, r4, #0x00020000 @ SDClk[1] = MemClk
307 @ Next, we need to look for S25,S26 selections that necessitate the
308 @ halving of MemClk to derive SDCLK[1]: (S25,S26)={03-0C, 10-13}
309 @ Override above S23-based selection accordingly.
311 ldr r2, =FPGA_REGS_BASE_PHYSICAL
313 @ get the value of S25 in R0, i put the base adx of fpga in r2
317 ldr r2, =FPGA_REGS_BASE_PHYSICAL
319 @ get the value of S26 in R1, i put the base adx of fpga in r2
321 orr r0, r0, r3 @ concatenate S25 & S26 vals
324 @ Set K1DB2 for the frequencies that require it
340 orreq r4, r4, #0x00020000 @ SDCLK[1] = (MemClk)/2 for 03 - 0C @ 10 - 13
343 @ *Must make MSC0&1 adjustments now for MEMClks > 100MHz.
345 @ Adjust MSC0 for MemClks > 100 MHz
347 ldreq r0, [r1, #MSC0_OFFSET]
348 ldreq r3, =0x7F007F00
349 biceq r0, r0, r3 @ clear MSC0[14:12, 11:8] (RRR, RDN)
350 ldreq r3, =0x46004600
351 orreq r0, r0, r3 @ set MSC0[14, 10:9] (doubling RRR, RDN)
352 streq r0, [r1, #MSC0_OFFSET]
353 ldreq r0, [r1, #MSC0_OFFSET] @ read it back to ensure that the data latches
356 @ Adjust MSC1.LH for MemClks > 100 MHz
358 ldreq r0, [r1, #MSC1_OFFSET]
360 biceq r0, r0, r3 @ clear MSC1[14:12, 11:8, 7:4] (RRR, RDN, RDF)
362 orreq r0, r0, r3 @ set MSC1[14, 11, 7] (doubling RRR, RDN, RDF)
363 streq r0, [r1, #MSC1_OFFSET]
364 ldreq r0, [r1, #MSC1_OFFSET] @ read it back to ensure that the data latches
367 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
370 @<!<!<!<!<!<!<!<!<!<!<! End INSERT 1 <!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<
371 @<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<!<
376 str r4, [r1, #MDREFR_OFFSET]
377 ldr r4, [r1, #MDREFR_OFFSET]
381 bic r4, r4, #0x00400000
385 str r4, [r1, #MDREFR_OFFSET]
389 orr r4, r4, #0x00008000
393 str r4, [r1, #MDREFR_OFFSET]
394 ldr r4, [r1, #MDREFR_OFFSET]
399 @****************************************************************************
403 @ fetch platform value of mdcnfg
405 ldr r2, =CFG_MDCNFG_VAL
407 @ disable all sdram banks
409 bic r2, r2, #(MDCNFG_DE0 | MDCNFG_DE1)
410 bic r2, r2, #(MDCNFG_DE2 | MDCNFG_DE3)
412 @ program banks 0/1 for bus width
414 bic r2, r2, #MDCNFG_DWID0 @0=32-bit
417 @ write initial value of mdcnfg, w/o enabling sdram banks
419 str r2, [r1, #MDCNFG_OFFSET]
421 @ ****************************************************************************
425 @ pause for 200 uSecs
427 ldr r3, =OSCR @reset the OS Timer Count to zero
430 ldr r4, =0x300 @really 0x2E1 is about 200usec, so 0x300 should be plenty
437 @****************************************************************************
441 mov r0, #0x78 @turn everything off
442 mcr p15, 0, r0, c1, c0, 0 @(caches off, MMU off, etc.)
445 @ ****************************************************************************
448 @ Access memory *not yet enabled* for CBR refresh cycles (8)
449 @ - CBR is generated for all banks
451 ldr r2, =CFG_DRAM_BASE
462 @ ****************************************************************************
463 @ Step 8: NOP (enable dcache if you wanna... we dont)
467 @ ****************************************************************************
472 @get memory controller base address
476 @fetch current mdcnfg value
478 ldr r3, [r1, #MDCNFG_OFFSET]
480 @enable sdram bank 0 if installed (must do for any populated bank)
482 orr r3, r3, #MDCNFG_DE0
484 @write back mdcnfg, enabling the sdram bank(s)
486 str r3, [r1, #MDCNFG_OFFSET]
489 @****************************************************************************
495 ldr r2, =CFG_MDMRS_VAL
496 str r2, [r1, #MDMRS_OFFSET]
499 @****************************************************************************
500 @ Step 11: Final Step
504 @********************************************************************
505 @ Disable (mask) all interrupts at the interrupt controller
508 @ clear the interrupt level register (use IRQ, not FIQ)
514 @ mask all interrupts at the controller
521 @ ********************************************************************
522 @ Disable the peripheral clocks, and set the core clock
523 @ frequency (hard-coding at 398.12MHz for now).
526 @ Turn Off ALL on-chip peripheral clocks for re-configuration
527 @ *Note: See label 'ENABLECLKS' for the re-enabling
534 @ default value in case no valid rotary switch setting is found
535 ldr r2, =(CCCR_L27 | CCCR_M2 | CCCR_N10) @ DEFAULT: {200/200/100}
538 @... and write the core clock config register
543 /* @ enable the 32Khz oscillator for RTC and PowerManager
550 @ NOTE: spin here until OSCC.OOK get set,
551 @ meaning the PLL has settled.
563 @****************************************************************************
564 @ !!! Take care of A0 Errata Sighting #4 --
565 @ after a frequency change, the memory controller must be restarted
568 @ get memory controller base address
571 @ get the current state of MDREFR
573 ldr r2, [r1, #MDREFR_OFFSET]
577 bic r3, r2, #(MDREFR_E0PIN | MDREFR_E1PIN)
579 @ write MDREFR with E0PIN, E1PIN cleared (disable sdclk[0,1])
581 str r3, [r1, #MDREFR_OFFSET]
583 @ then write MDREFR with E0PIN, E1PIN set (enable sdclk[0,1])
585 str r2, [r1, #MDREFR_OFFSET]
587 @ get the current state of MDCNFG
589 ldr r3, [r1, #MDCNFG_OFFSET]
591 @ disable all SDRAM banks
593 bic r3, r3, #(MDCNFG_DE0 | MDCNFG_DE1)
594 bic r3, r3, #(MDCNFG_DE2 | MDCNFG_DE3)
598 ldr r3, [r1, #MDCNFG_OFFSET]
600 @ Access memory not yet enabled for CBR refresh cycles (8)
601 @ - CBR is generated for *all* banks
602 ldr r2, =CFG_DRAM_BASE
612 @ fetch current mdcnfg value
614 ldr r3, [r1, #MDCNFG_OFFSET]
616 @ enable sdram bank 0 if installed
618 orr r3, r3, #MDCNFG_DE0
620 @ write back mdcnfg, enabling the sdram bank(s)
622 str r3, [r1, #MDCNFG_OFFSET]
626 ldr r2, =CFG_MDMRS_VAL
627 str r2, [r1, #MDMRS_OFFSET]
631 /* @ errata: don't enable auto power-down */
632 @ get current value of mdrefr
633 @ldr r3, [r1, #MDREFR_OFFSET]
634 @ enable auto-power down
635 @orr r3, r3, #MDREFR_APD
637 @str r3, [r1, #MDREFR_OFFSET]
644 str r0, [r1] /* hex display */
646 @ ^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%
647 @ ^%^%^%^%^%^%^%^%^% above could be replaced by prememLLI ^%^%^%^%^%^%^%^%^%
648 @ ^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%^%
651 /* Save SDRAM size */
657 str r0, [r1] /* hex display */
660 /* Mask all interrupts */
661 ldr r0, =ICMR /* enable no sources */
667 /*Disable software and data breakpoints */
669 mcr p15,0,r0,c14,c8,0 /* ibcr0 */
670 mcr p15,0,r0,c14,c9,0 /* ibcr1 */
671 mcr p15,0,r0,c14,c4,0 /* dbcon */
673 /*Enable all debug functionality */
675 mcr p14,0,r0,c10,c0,0 /* dcsr */
681 str r0, [r1] /* hex display */
687 @ %%%%%%%%%%% Useful subroutines
689 @ This macro will read S23 and return its value in r3
690 @ r2 contains the base address of the Lubbock user registers
691 ldr r2, =FPGA_REGS_BASE_PHYSICAL
693 /*@ read S23's value */
694 ldr r3, [r2, #USER_SWITCHES_OFFSET]
696 @ mask out irrelevant bits
699 @ get bit into position 0
707 @ This macro will read S24 and return its value in r0
708 @ r2 contains the base address of the Lubbock user registers
709 ldr r2, =FPGA_REGS_BASE_PHYSICAL
711 /*@ read S24's value */
712 ldr r0, [r2, #USER_SWITCHES_OFFSET]
714 @ mask out irrelevant bits
717 @ get bit into position 0
725 @ This macro will read rotary S25 and return its value in r0
726 @ r2 contains the base address of the Lubbock user registers
727 @ read the user switches register
728 ldr r0, [r2, #USER_SWITCHES_OFFSET]
730 @ mask out irrelevant bits
738 @ This macro will read rotary S26 and return its value in r3
739 @ r2 contains the base address of the Lubbock user registers
740 @ read the user switches register
741 ldr r3, [r2, #USER_SWITCHES_OFFSET]
743 @ mask out irrelevant bits
747 @ End subroutine GET_S26