wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004 Sascha Hauer, Synertronixx GmbH |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <config.h> |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 8 | #include <asm/arch/imx-regs.h> |
| 9 | |
wdenk | 400558b | 2005-04-02 23:52:25 +0000 | [diff] [blame] | 10 | .globl lowlevel_init |
| 11 | lowlevel_init: |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 12 | |
| 13 | mov r10, lr |
| 14 | |
| 15 | /* Change PERCLK1DIV to 14 ie 14+1 */ |
| 16 | ldr r0, =PCDR |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 17 | ldr r1, =CONFIG_SYS_PCDR_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 18 | str r1, [r0] |
| 19 | |
| 20 | /* set MCU PLL Control Register 0 */ |
| 21 | |
| 22 | ldr r0, =MPCTL0 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | ldr r1, =CONFIG_SYS_MPCTL0_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 24 | str r1, [r0] |
| 25 | |
| 26 | /* set mpll restart bit */ |
| 27 | ldr r0, =CSCR |
| 28 | ldr r1, [r0] |
| 29 | orr r1,r1,#(1<<21) |
| 30 | str r1, [r0] |
| 31 | |
| 32 | mov r2,#0x10 |
| 33 | 1: |
| 34 | mov r3,#0x2000 |
| 35 | 2: |
| 36 | subs r3,r3,#1 |
| 37 | bne 2b |
| 38 | |
| 39 | subs r2,r2,#1 |
| 40 | bne 1b |
| 41 | |
| 42 | /* set System PLL Control Register 0 */ |
| 43 | |
| 44 | ldr r0, =SPCTL0 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 45 | ldr r1, =CONFIG_SYS_SPCTL0_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 46 | str r1, [r0] |
| 47 | |
| 48 | /* set spll restart bit */ |
| 49 | ldr r0, =CSCR |
| 50 | ldr r1, [r0] |
| 51 | orr r1,r1,#(1<<22) |
| 52 | str r1, [r0] |
| 53 | |
| 54 | mov r2,#0x10 |
| 55 | 1: |
| 56 | mov r3,#0x2000 |
| 57 | 2: |
| 58 | subs r3,r3,#1 |
| 59 | bne 2b |
| 60 | |
| 61 | subs r2,r2,#1 |
| 62 | bne 1b |
| 63 | |
| 64 | ldr r0, =CSCR |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 65 | ldr r1, =CONFIG_SYS_CSCR_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 66 | str r1, [r0] |
| 67 | |
| 68 | /* I have now read the ARM920 DataSheet back-to-Back, and have stumbled upon |
| 69 | *this..... |
| 70 | * |
| 71 | * It would appear that from a Cold-Boot the ARM920T enters "FastBus" mode CP15 |
| 72 | * register 1, this stops it using the output of the PLL and thus runs at the |
| 73 | * slow rate. Unless you place the Core into "Asynch" mode, the CPU will never |
| 74 | * use the value set in the CM_OSC registers...regardless of what you set it |
| 75 | * too! Thus, although i thought i was running at 140MHz, i'm actually running |
| 76 | * at 40!.. |
| 77 | |
| 78 | * Slapping this into my bootloader does the trick... |
| 79 | |
| 80 | * MRC p15,0,r0,c1,c0,0 ; read core configuration register |
| 81 | * ORR r0,r0,#0xC0000000 ; set asynchronous clocks and not fastbus mode |
| 82 | * MCR p15,0,r0,c1,c0,0 ; write modified value to core configuration |
| 83 | * register |
| 84 | */ |
| 85 | MRC p15,0,r0,c1,c0,0 |
| 86 | ORR r0,r0,#0xC0000000 |
| 87 | MCR p15,0,r0,c1,c0,0 |
| 88 | |
| 89 | ldr r0, =GPR(0) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 90 | ldr r1, =CONFIG_SYS_GPR_A_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 91 | str r1, [r0] |
| 92 | |
| 93 | ldr r0, =GIUS(0) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 94 | ldr r1, =CONFIG_SYS_GIUS_A_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 95 | str r1, [r0] |
| 96 | |
| 97 | /* CS3 becomes CS3 by clearing reset default bit 1 in FMCR */ |
| 98 | |
| 99 | ldr r0, =FMCR |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 100 | ldr r1, =CONFIG_SYS_FMCR_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 101 | str r1, [r0] |
| 102 | |
| 103 | ldr r0, =CS0U |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 104 | ldr r1, =CONFIG_SYS_CS0U_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 105 | str r1, [r0] |
| 106 | |
| 107 | ldr r0, =CS0L |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 108 | ldr r1, =CONFIG_SYS_CS0L_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 109 | str r1, [r0] |
| 110 | |
| 111 | ldr r0, =CS1U |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 112 | ldr r1, =CONFIG_SYS_CS1U_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 113 | str r1, [r0] |
| 114 | |
| 115 | ldr r0, =CS1L |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 116 | ldr r1, =CONFIG_SYS_CS1L_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 117 | str r1, [r0] |
| 118 | |
| 119 | ldr r0, =CS2U |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 120 | ldr r1, =CONFIG_SYS_CS2U_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 121 | str r1, [r0] |
| 122 | |
| 123 | ldr r0, =CS2L |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 124 | ldr r1, =CONFIG_SYS_CS2L_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 125 | str r1, [r0] |
| 126 | |
| 127 | ldr r0, =CS3U |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 128 | ldr r1, =CONFIG_SYS_CS3U_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 129 | str r1, [r0] |
| 130 | |
| 131 | ldr r0, =CS3L |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 132 | ldr r1, =CONFIG_SYS_CS3L_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 133 | str r1, [r0] |
| 134 | |
| 135 | ldr r0, =CS4U |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 136 | ldr r1, =CONFIG_SYS_CS4U_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 137 | str r1, [r0] |
| 138 | |
| 139 | ldr r0, =CS4L |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 140 | ldr r1, =CONFIG_SYS_CS4L_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 141 | str r1, [r0] |
| 142 | |
| 143 | ldr r0, =CS5U |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 144 | ldr r1, =CONFIG_SYS_CS5U_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 145 | str r1, [r0] |
| 146 | |
| 147 | ldr r0, =CS5L |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 148 | ldr r1, =CONFIG_SYS_CS5L_VAL |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 149 | str r1, [r0] |
| 150 | |
| 151 | /* SDRAM Setup */ |
| 152 | |
| 153 | ldr r0, =SDCTL0 |
| 154 | ldr r1, =PRECHARGE_CMD |
| 155 | str r1, [r0] |
| 156 | |
| 157 | ldr r0, =0x08200000 |
| 158 | ldr r1, =0x0 /* Issue Precharge all Command */ |
| 159 | str r1, [r0] |
| 160 | |
| 161 | ldr r0, =SDCTL0 |
| 162 | ldr r1, =AUTOREFRESH_CMD |
| 163 | str r1, [r0] |
| 164 | |
| 165 | ldr r0, =0x08000000 |
| 166 | ldr r1, =0x0 /* Issue AutoRefresh Command */ |
| 167 | str r1, [r0] |
| 168 | str r1, [r0] |
| 169 | str r1, [r0] |
| 170 | str r1, [r0] |
| 171 | str r1, [r0] |
| 172 | str r1, [r0] |
| 173 | str r1, [r0] |
| 174 | str r1, [r0] |
| 175 | |
| 176 | ldr r0, =SDCTL0 |
| 177 | ldr r1, =0xb10a8300 |
| 178 | str r1, [r0] |
| 179 | |
| 180 | ldr r0, =0x08223000 /* CAS Latency 2 */ |
| 181 | ldr r1, =0x0 /* Issue Mode Register Command, Burst Length = 8 */ |
| 182 | str r1, [r0] |
| 183 | |
| 184 | ldr r0, =SDCTL0 |
| 185 | ldr r1, =0x810a8200 /* Set to Normal Mode CAS 2 */ |
| 186 | str r1, [r0] |
| 187 | |
| 188 | mov pc,r10 |