wdenk | 3d3befa | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Board specific setup info |
| 3 | * |
| 4 | * (C) Copyright 2004, ARM Ltd. |
| 5 | * Philippe Robin, <philippe.robin@arm.com> |
| 6 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 3d3befa | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <config.h> |
| 11 | #include <version.h> |
| 12 | |
Wolfgang Denk | 74f4304 | 2005-09-25 01:48:28 +0200 | [diff] [blame] | 13 | /* Reset using CM control register */ |
| 14 | .global reset_cpu |
| 15 | reset_cpu: |
| 16 | mov r0, #CM_BASE |
| 17 | ldr r1,[r0,#OS_CTRL] |
| 18 | orr r1,r1,#CMMASK_RESET |
Wolfgang Denk | 9b880bd | 2005-10-04 23:10:28 +0200 | [diff] [blame] | 19 | str r1,[r0,#OS_CTRL] |
Wolfgang Denk | 74f4304 | 2005-09-25 01:48:28 +0200 | [diff] [blame] | 20 | |
| 21 | reset_failed: |
| 22 | b reset_failed |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 23 | |
Wolfgang Denk | 87cb686 | 2005-10-06 17:08:18 +0200 | [diff] [blame] | 24 | /* Set up the platform, once the cpu has been initialized */ |
| 25 | .globl lowlevel_init |
| 26 | lowlevel_init: |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 27 | /* If U-Boot has been run after the ARM boot monitor |
| 28 | * then all the necessary actions have been done |
| 29 | * otherwise we are running from user flash mapped to 0x00000000 |
| 30 | * --- DO NOT REMAP BEFORE THE CODE HAS BEEN RELOCATED -- |
| 31 | * Changes to the (possibly soft) reset defaults of the processor |
| 32 | * itself should be performed in cpu/arm<>/start.S |
| 33 | * This function affects only the core module or board settings |
| 34 | */ |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 35 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 36 | #ifdef CONFIG_CM_INIT |
| 37 | /* CM has an initialization register |
| 38 | * - bits in it are wired into test-chip pins to force |
| 39 | * reset defaults |
| 40 | * - may need to change its contents for U-Boot |
| 41 | */ |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 42 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 43 | /* set the desired CM specific value */ |
| 44 | mov r2,#CMMASK_LOWVEC /* Vectors at 0x00000000 for all */ |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 45 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 46 | #if defined (CONFIG_CM10200E) || defined (CONFIG_CM10220E) |
| 47 | orr r2,r2,#CMMASK_INIT_102 |
| 48 | #else |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 49 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 50 | #if !defined (CONFIG_CM920T) && !defined (CONFIG_CM920T_ETM) && \ |
| 51 | !defined (CONFIG_CM940T) |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 52 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 53 | #ifdef CONFIG_CM_MULTIPLE_SSRAM |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 54 | /* set simple mapping */ |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 55 | and r2,r2,#CMMASK_MAP_SIMPLE |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 56 | #endif /* #ifdef CONFIG_CM_MULTIPLE_SSRAM */ |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 57 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 58 | #ifdef CONFIG_CM_TCRAM |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 59 | /* disable TCRAM */ |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 60 | and r2,r2,#CMMASK_TCRAM_DISABLE |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 61 | #endif /* #ifdef CONFIG_CM_TCRAM */ |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 62 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 63 | #if defined (CONFIG_CM926EJ_S) || defined (CONFIG_CM1026EJ_S) || \ |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 64 | defined (CONFIG_CM1136JF_S) |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 65 | |
| 66 | and r2,r2,#CMMASK_LE |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 67 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 68 | #endif /* cpu with little endian initialization */ |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 69 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 70 | orr r2,r2,#CMMASK_CMxx6_COMMON |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 71 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 72 | #endif /* CMxx6 code */ |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 73 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 74 | #endif /* ARM102xxE value */ |
| 75 | |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 76 | /* read CM_INIT */ |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 77 | mov r0, #CM_BASE |
| 78 | ldr r1, [r0, #OS_INIT] |
| 79 | /* check against desired bit setting */ |
| 80 | and r3,r1,r2 |
| 81 | cmp r3,r2 |
| 82 | beq init_reg_OK |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 83 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 84 | /* lock for change */ |
Wolfgang Denk | 9b880bd | 2005-10-04 23:10:28 +0200 | [diff] [blame] | 85 | mov r3, #CMVAL_LOCK1 |
| 86 | add r3,r3,#CMVAL_LOCK2 |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 87 | str r3, [r0, #OS_LOCK] |
| 88 | /* set desired value */ |
| 89 | orr r1,r1,r2 |
| 90 | /* write & relock CM_INIT */ |
| 91 | str r1, [r0, #OS_INIT] |
| 92 | mov r1, #CMVAL_UNLOCK |
| 93 | str r1, [r0, #OS_LOCK] |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 94 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 95 | /* soft reset so new values used */ |
| 96 | b reset_cpu |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 97 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 98 | init_reg_OK: |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 99 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 100 | #endif /* CONFIG_CM_INIT */ |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 101 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 102 | mov pc, lr |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 103 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 104 | #ifdef CONFIG_CM_SPD_DETECT |
| 105 | /* Fast memory is available for the DRAM data |
| 106 | * - ensure it has been transferred, then summarize the data |
| 107 | * into a CM register |
| 108 | */ |
| 109 | .globl dram_query |
| 110 | dram_query: |
| 111 | stmfd r13!,{r4-r6,lr} |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 112 | /* set up SDRAM info */ |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 113 | /* - based on example code from the CM User Guide */ |
| 114 | mov r0, #CM_BASE |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 115 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 116 | readspdbit: |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 117 | ldr r1, [r0, #OS_SDRAM] /* read the SDRAM register */ |
| 118 | and r1, r1, #0x20 /* mask SPD bit (5) */ |
| 119 | cmp r1, #0x20 /* test if set */ |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 120 | bne readspdbit |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 121 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 122 | setupsdram: |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 123 | add r0, r0, #OS_SPD /* address the copy of the SDP data */ |
| 124 | ldrb r1, [r0, #3] /* number of row address lines */ |
| 125 | ldrb r2, [r0, #4] /* number of column address lines */ |
| 126 | ldrb r3, [r0, #5] /* number of banks */ |
| 127 | ldrb r4, [r0, #31] /* module bank density */ |
| 128 | mul r5, r4, r3 /* size of SDRAM (MB divided by 4) */ |
| 129 | mov r5, r5, ASL#2 /* size in MB */ |
| 130 | mov r0, #CM_BASE /* reload for later code */ |
| 131 | cmp r5, #0x10 /* is it 16MB? */ |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 132 | bne not16 |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 133 | mov r6, #0x2 /* store size and CAS latency of 2 */ |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 134 | b writesize |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 135 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 136 | not16: |
| 137 | cmp r5, #0x20 /* is it 32MB? */ |
| 138 | bne not32 |
| 139 | mov r6, #0x6 |
| 140 | b writesize |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 141 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 142 | not32: |
| 143 | cmp r5, #0x40 /* is it 64MB? */ |
| 144 | bne not64 |
| 145 | mov r6, #0xa |
| 146 | b writesize |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 147 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 148 | not64: |
| 149 | cmp r5, #0x80 /* is it 128MB? */ |
| 150 | bne not128 |
| 151 | mov r6, #0xe |
| 152 | b writesize |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 153 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 154 | not128: |
| 155 | /* if it is none of these sizes then it is either 256MB, or |
| 156 | * there is no SDRAM fitted so default to 256MB |
| 157 | */ |
| 158 | mov r6, #0x12 |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 159 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 160 | writesize: |
| 161 | mov r1, r1, ASL#8 /* row addr lines from SDRAM reg */ |
| 162 | orr r2, r1, r2, ASL#12 /* OR in column address lines */ |
| 163 | orr r3, r2, r3, ASL#16 /* OR in number of banks */ |
| 164 | orr r6, r6, r3 /* OR in size and CAS latency */ |
| 165 | str r6, [r0, #OS_SDRAM] /* store SDRAM parameters */ |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 166 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 167 | #endif /* #ifdef CONFIG_CM_SPD_DETECT */ |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 168 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 169 | ldmfd r13!,{r4-r6,pc} /* back to caller */ |
| 170 | |
| 171 | #ifdef CONFIG_CM_REMAP |
| 172 | /* CM remap bit is operational |
| 173 | * - use it to map writeable memory at 0x00000000, in place of flash |
| 174 | */ |
| 175 | .globl cm_remap |
| 176 | cm_remap: |
| 177 | stmfd r13!,{r4-r10,lr} |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 178 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 179 | mov r0, #CM_BASE |
| 180 | ldr r1, [r0, #OS_CTRL] |
| 181 | orr r1, r1, #CMMASK_REMAP /* set remap and led bits */ |
| 182 | str r1, [r0, #OS_CTRL] |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 183 | |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 184 | /* Now 0x00000000 is writeable, replace the vectors */ |
| 185 | ldr r0, =_start /* r0 <- start of vectors */ |
Albert ARIBAUD | b60eff3 | 2014-02-22 17:53:43 +0100 | [diff] [blame^] | 186 | add r2, r0, #64 /* r2 <- past vectors */ |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 187 | sub r1,r1,r1 /* destination 0x00000000 */ |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 188 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 189 | copy_vec: |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 190 | ldmia r0!, {r3-r10} /* copy from source address [r0] */ |
| 191 | stmia r1!, {r3-r10} /* copy to target address [r1] */ |
| 192 | cmp r0, r2 /* until source end address [r2] */ |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 193 | ble copy_vec |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 194 | |
Wolfgang Denk | 96782c6 | 2005-10-09 00:22:48 +0200 | [diff] [blame] | 195 | ldmfd r13!,{r4-r10,pc} /* back to caller */ |
Wolfgang Denk | 716c1dc | 2005-09-25 18:49:35 +0200 | [diff] [blame] | 196 | |
Wolfgang Denk | 0148e8c | 2005-09-25 16:22:14 +0200 | [diff] [blame] | 197 | #endif /* #ifdef CONFIG_CM_REMAP */ |