Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009, Emcraft Systems, Ilya Yanok <yanok@emcraft.com> |
| 3 | * |
| 4 | * Based on board/freescale/mx31ads/lowlevel_init.S |
| 5 | * by Guennadi Liakhovetski. |
| 6 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
Stefano Babic | 78129d9 | 2011-03-14 15:43:56 +0100 | [diff] [blame] | 10 | #include <asm/arch/imx-regs.h> |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 11 | |
| 12 | .macro REG reg, val |
| 13 | ldr r2, =\reg |
| 14 | ldr r3, =\val |
| 15 | str r3, [r2] |
| 16 | .endm |
| 17 | |
| 18 | .macro REG8 reg, val |
| 19 | ldr r2, =\reg |
| 20 | ldr r3, =\val |
| 21 | strb r3, [r2] |
| 22 | .endm |
| 23 | |
| 24 | .macro DELAY loops |
| 25 | ldr r2, =\loops |
| 26 | 1: |
| 27 | subs r2, r2, #1 |
| 28 | nop |
| 29 | bcs 1b |
| 30 | .endm |
| 31 | |
Stefano Babic | bd9280e | 2010-03-31 10:27:47 +0200 | [diff] [blame] | 32 | .macro SETUP_RAM cfg, ctl |
| 33 | /* B8xxxxxx - NAND, 8xxxxxxx - CSD0 RAM */ |
| 34 | REG 0xB8001010, 0x00000004 |
| 35 | ldr r3, =\cfg |
| 36 | ldr r2, =WEIM_ESDCFG0 |
| 37 | str r3, [r2] |
| 38 | REG 0xB8001000, 0x92100000 |
| 39 | REG 0x80000f00, 0x12344321 |
| 40 | REG 0xB8001000, 0xa2100000 |
| 41 | REG 0x80000000, 0x12344321 |
| 42 | REG 0x80000000, 0x12344321 |
| 43 | REG 0xB8001000, 0xb2100000 |
| 44 | REG8 0x80000033, 0xda |
| 45 | REG8 0x81000000, 0xff |
| 46 | ldr r3, =\ctl |
| 47 | ldr r2, =WEIM_ESDCTL0 |
| 48 | str r3, [r2] |
| 49 | REG 0x80000000, 0xDEADBEEF |
| 50 | REG 0xB8001010, 0x0000000c |
| 51 | |
| 52 | .endm |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 53 | /* RedBoot: To support 133MHz DDR */ |
| 54 | .macro init_drive_strength |
| 55 | /* |
| 56 | * Disable maximum drive strength SDRAM/DDR lines by clearing DSE1 bits |
| 57 | * in SW_PAD_CTL registers |
| 58 | */ |
| 59 | |
| 60 | /* SDCLK */ |
| 61 | ldr r1, =IOMUXC_SW_PAD_CTL(0x2b) |
| 62 | ldr r0, [r1, #0x6C] |
| 63 | bic r0, r0, #(1 << 12) |
| 64 | str r0, [r1, #0x6C] |
| 65 | |
| 66 | /* CAS */ |
| 67 | ldr r0, [r1, #0x70] |
| 68 | bic r0, r0, #(1 << 22) |
| 69 | str r0, [r1, #0x70] |
| 70 | |
| 71 | /* RAS */ |
| 72 | ldr r0, [r1, #0x74] |
| 73 | bic r0, r0, #(1 << 2) |
| 74 | str r0, [r1, #0x74] |
| 75 | |
| 76 | /* CS2 (CSD0) */ |
| 77 | ldr r0, [r1, #0x7C] |
| 78 | bic r0, r0, #(1 << 22) |
| 79 | str r0, [r1, #0x7C] |
| 80 | |
| 81 | /* DQM3 */ |
| 82 | ldr r0, [r1, #0x84] |
| 83 | bic r0, r0, #(1 << 22) |
| 84 | str r0, [r1, #0x84] |
| 85 | |
| 86 | /* DQM2, DQM1, DQM0, SD31-SD0, A25-A0, MA10 (0x288..0x2DC) */ |
| 87 | ldr r2, =22 /* (0x2E0 - 0x288) / 4 = 22 */ |
| 88 | pad_loop: |
| 89 | ldr r0, [r1, #0x88] |
| 90 | bic r0, r0, #(1 << 22) |
| 91 | bic r0, r0, #(1 << 12) |
| 92 | bic r0, r0, #(1 << 2) |
| 93 | str r0, [r1, #0x88] |
| 94 | add r1, r1, #4 |
| 95 | subs r2, r2, #0x1 |
| 96 | bne pad_loop |
| 97 | .endm /* init_drive_strength */ |
| 98 | |
| 99 | .globl lowlevel_init |
| 100 | lowlevel_init: |
| 101 | |
| 102 | init_drive_strength |
| 103 | |
| 104 | /* Image Processing Unit: */ |
| 105 | /* Too early to switch display on? */ |
| 106 | /* Switch on Display Interface */ |
| 107 | REG IPU_CONF, IPU_CONF_DI_EN |
| 108 | /* Clock Control Module: */ |
| 109 | REG CCM_CCMR, 0x074B0BF5 /* Use CKIH, MCU PLL off */ |
| 110 | |
| 111 | DELAY 0x40000 |
| 112 | |
| 113 | REG CCM_CCMR, 0x074B0BF5 | CCMR_MPE /* MCU PLL on */ |
| 114 | /* Switch to MCU PLL */ |
| 115 | REG CCM_CCMR, (0x074B0BF5 | CCMR_MPE) & ~CCMR_MDS |
| 116 | |
| 117 | /* 399-133-66.5 */ |
| 118 | ldr r0, =CCM_BASE |
| 119 | ldr r1, =0xFF871650 |
| 120 | /* PDR0 */ |
| 121 | str r1, [r0, #0x4] |
| 122 | ldr r1, MPCTL_PARAM_399 |
| 123 | /* MPCTL */ |
| 124 | str r1, [r0, #0x10] |
| 125 | |
| 126 | /* Set UPLL=240MHz, USB=60MHz */ |
| 127 | ldr r1, =0x49FCFE7F |
| 128 | /* PDR1 */ |
| 129 | str r1, [r0, #0x8] |
| 130 | ldr r1, UPCTL_PARAM_240 |
| 131 | /* UPCTL */ |
| 132 | str r1, [r0, #0x14] |
| 133 | /* default CLKO to 1/8 of the ARM core */ |
| 134 | mov r1, #0x00000208 |
| 135 | /* COSR */ |
| 136 | str r1, [r0, #0x1c] |
| 137 | |
| 138 | /* Default: 1, 4, 12, 1 */ |
| 139 | REG CCM_SPCTL, PLL_PD(1) | PLL_MFD(4) | PLL_MFI(12) | PLL_MFN(1) |
| 140 | |
Stefano Babic | bd9280e | 2010-03-31 10:27:47 +0200 | [diff] [blame] | 141 | check_ddr_module: |
| 142 | /* Set stackpointer in internal RAM to call get_ram_size */ |
| 143 | ldr sp, =(IRAM_BASE_ADDR + IRAM_SIZE - 16) |
| 144 | stmfd sp!, {r0-r11, ip, lr} |
| 145 | mov ip, lr /* save link reg across call */ |
| 146 | |
| 147 | ldr r0,=0x08000000 |
| 148 | SETUP_RAM ESDCFG0_256MB, ESDCTL0_256MB |
| 149 | ldr r0,=0x80000000 |
| 150 | ldr r1,=0x10000000 |
| 151 | bl get_ram_size |
| 152 | ldr r1,=0x10000000 |
| 153 | cmp r0,r1 |
| 154 | beq restore_regs |
| 155 | SETUP_RAM ESDCFG0_128MB, ESDCTL0_128MB |
| 156 | ldr r0,=0x80000000 |
| 157 | ldr r1,=0x08000000 |
| 158 | bl get_ram_size |
| 159 | ldr r1,=0x08000000 |
| 160 | cmp r0,r1 |
| 161 | beq restore_regs |
| 162 | |
| 163 | restore_regs: |
| 164 | ldmfd sp!, {r0-r11, ip, lr} |
| 165 | mov lr, ip /* restore link reg */ |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 166 | |
| 167 | mov pc, lr |
| 168 | |
Stefano Babic | bd9280e | 2010-03-31 10:27:47 +0200 | [diff] [blame] | 169 | |
Ilya Yanok | 509a1ea | 2009-02-10 00:22:31 +0100 | [diff] [blame] | 170 | MPCTL_PARAM_399: |
| 171 | .word (((1 - 1) << 26) + ((52 - 1) << 16) + (7 << 10) + (35 << 0)) |
| 172 | UPCTL_PARAM_240: |
| 173 | .word (((2 - 1) << 26) + ((13 - 1) << 16) + (9 << 10) + (3 << 0)) |
Stefano Babic | bd9280e | 2010-03-31 10:27:47 +0200 | [diff] [blame] | 174 | |
| 175 | .equ ESDCFG0_128MB, \ |
| 176 | (0 << 21) + /* tXP */ \ |
| 177 | (1 << 20) + /* tWTR */ \ |
| 178 | (2 << 18) + /* tRP */ \ |
| 179 | (1 << 16) + /* tMRD */ \ |
| 180 | (0 << 15) + /* tWR */ \ |
| 181 | (5 << 12) + /* tRAS */ \ |
| 182 | (1 << 10) + /* tRRD */ \ |
| 183 | (3 << 8) + /* tCAS */ \ |
| 184 | (2 << 4) + /* tRCD */ \ |
| 185 | (0x0F << 0) /* tRC */ |
| 186 | |
| 187 | .equ ESDCTL0_128MB, \ |
| 188 | (1 << 31) + /* enable */ \ |
| 189 | (0 << 28) + /* mode */ \ |
| 190 | (0 << 27) + /* supervisor protect */ \ |
| 191 | (2 << 24) + /* 13 rows */ \ |
| 192 | (2 << 20) + /* 10 cols */ \ |
| 193 | (2 << 16) + /* 32 bit */ \ |
| 194 | (3 << 13) + /* 7.81us (64ms/8192) */ \ |
| 195 | (0 << 10) + /* power down timer */ \ |
| 196 | (0 << 8) + /* full page */ \ |
| 197 | (1 << 7) + /* burst length */ \ |
| 198 | (0 << 0) /* precharge timer */ |
| 199 | |
| 200 | .equ ESDCFG0_256MB, \ |
| 201 | (3 << 21) + /* tXP */ \ |
| 202 | (0 << 20) + /* tWTR */ \ |
| 203 | (2 << 18) + /* tRP */ \ |
| 204 | (1 << 16) + /* tMRD */ \ |
| 205 | (0 << 15) + /* tWR */ \ |
| 206 | (5 << 12) + /* tRAS */ \ |
| 207 | (1 << 10) + /* tRRD */ \ |
| 208 | (3 << 8) + /* tCAS */ \ |
| 209 | (2 << 4) + /* tRCD */ \ |
| 210 | (7 << 0) /* tRC */ |
| 211 | |
| 212 | .equ ESDCTL0_256MB, \ |
| 213 | (1 << 31) + \ |
| 214 | (0 << 28) + \ |
| 215 | (0 << 27) + \ |
| 216 | (3 << 24) + /* 14 rows */ \ |
| 217 | (2 << 20) + /* 10 cols */ \ |
| 218 | (2 << 16) + \ |
| 219 | (4 << 13) + /* 3.91us (64ms/16384) */ \ |
| 220 | (0 << 10) + \ |
| 221 | (0 << 8) + \ |
| 222 | (1 << 7) + \ |
| 223 | (0 << 0) |