wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Board specific setup info |
| 3 | * |
| 4 | * (C) Copyright 2004 |
| 5 | * Texas Instruments, <www.ti.com> |
| 6 | * Richard Woodruff <r-woodruff2@ti.com> |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <config.h> |
| 28 | #include <version.h> |
| 29 | #include <asm/arch/omap2420.h> |
| 30 | #include <asm/arch/mem.h> |
| 31 | #include <asm/arch/clocks.h> |
| 32 | |
| 33 | _TEXT_BASE: |
| 34 | .word TEXT_BASE /* sdram load addr from config.mk */ |
| 35 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 36 | /************************************************************************** |
| 37 | * cpy_clk_code: relocates clock code into SRAM where its safer to execute |
| 38 | * R1 = SRAM destination address. |
| 39 | *************************************************************************/ |
| 40 | .global cpy_clk_code |
| 41 | cpy_clk_code: |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 42 | /* Copy DPLL code into SRAM */ |
| 43 | adr r0, go_to_speed /* get addr of clock setting code */ |
| 44 | mov r2, #384 /* r2 size to copy (div by 32 bytes) */ |
| 45 | mov r1, r1 /* r1 <- dest address (passed in) */ |
| 46 | add r2, r2, r0 /* r2 <- source end address */ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 47 | next2: |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 48 | ldmia r0!, {r3-r10} /* copy from source address [r0] */ |
| 49 | stmia r1!, {r3-r10} /* copy to target address [r1] */ |
| 50 | cmp r0, r2 /* until source end address [r2] */ |
| 51 | bne next2 |
| 52 | mov pc, lr /* back to caller */ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 53 | |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 54 | /* **************************************************************************** |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 55 | * go_to_speed: -Moves to bypass, -Commits clock dividers, -puts dpll at speed |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 56 | * -executed from SRAM. |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 57 | * R0 = PRCM_CLKCFG_CTRL - addr of valid reg |
| 58 | * R1 = CM_CLKEN_PLL - addr dpll ctlr reg |
| 59 | * R2 = dpll value |
| 60 | * R3 = CM_IDLEST_CKGEN - addr dpll lock wait |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 61 | ******************************************************************************/ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 62 | .global go_to_speed |
| 63 | go_to_speed: |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 64 | sub sp, sp, #0x4 /* get some stack space */ |
| 65 | str r4, [sp] /* save r4's value */ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 66 | |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 67 | /* move into fast relock bypass */ |
| 68 | ldr r8, pll_ctl_add |
| 69 | mov r4, #0x2 |
| 70 | str r4, [r8] |
| 71 | ldr r4, pll_stat |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 72 | block: |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 73 | ldr r8, [r4] /* wait for bypass to take effect */ |
| 74 | and r8, r8, #0x3 |
| 75 | cmp r8, #0x1 |
| 76 | bne block |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 77 | |
| 78 | /* set new dpll dividers _after_ in bypass */ |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 79 | ldr r4, pll_div_add |
| 80 | ldr r8, pll_div_val |
| 81 | str r8, [r4] |
| 82 | |
| 83 | /* now prepare GPMC (flash) for new dpll speed */ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 84 | /* flash needs to be stable when we jump back to it */ |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 85 | ldr r4, cfg3_0_addr |
| 86 | ldr r8, cfg3_0_val |
| 87 | str r8, [r4] |
| 88 | ldr r4, cfg4_0_addr |
| 89 | ldr r8, cfg4_0_val |
| 90 | str r8, [r4] |
| 91 | ldr r4, cfg1_0_addr |
| 92 | ldr r8, [r4] |
| 93 | orr r8, r8, #0x3 /* up gpmc divider */ |
| 94 | str r8, [r4] |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 95 | |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 96 | /* setup to 2x loop though code. The first loop pre-loads the |
| 97 | * icache, the 2nd commits the prcm config, and locks the dpll |
| 98 | */ |
| 99 | mov r4, #0x1000 /* spin spin spin */ |
| 100 | mov r8, #0x4 /* first pass condition & set registers */ |
| 101 | cmp r8, #0x4 |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 102 | 2: |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 103 | ldrne r8, [r3] /* DPLL lock check */ |
| 104 | and r8, r8, #0x7 |
| 105 | cmp r8, #0x2 |
| 106 | beq 4f |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 107 | 3: |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 108 | subeq r8, r8, #0x1 |
| 109 | streq r8, [r0] /* commit dividers (2nd time) */ |
| 110 | nop |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 111 | lloop1: |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 112 | sub r4, r4, #0x1 /* Loop currently necessary else bad jumps */ |
| 113 | nop |
| 114 | cmp r4, #0x0 |
| 115 | bne lloop1 |
| 116 | mov r4, #0x40000 |
| 117 | cmp r8, #0x1 |
| 118 | nop |
| 119 | streq r2, [r1] /* lock dpll (2nd time) */ |
| 120 | nop |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 121 | lloop2: |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 122 | sub r4, r4, #0x1 /* loop currently necessary else bad jumps */ |
| 123 | nop |
| 124 | cmp r4, #0x0 |
| 125 | bne lloop2 |
| 126 | mov r4, #0x40000 |
| 127 | cmp r8, #0x1 |
| 128 | nop |
| 129 | ldreq r8, [r3] /* get lock condition for dpll */ |
| 130 | cmp r8, #0x4 /* first time though? */ |
| 131 | bne 2b |
| 132 | moveq r8, #0x2 /* set to dpll check condition. */ |
| 133 | beq 3b /* if condition not true branch */ |
| 134 | 4: |
| 135 | ldr r4, [sp] |
| 136 | add sp, sp, #0x4 /* return stack space */ |
| 137 | mov pc, lr /* back to caller, locked */ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 138 | |
| 139 | _go_to_speed: .word go_to_speed |
| 140 | |
| 141 | /* these constants need to be close for PIC code */ |
| 142 | cfg3_0_addr: |
| 143 | .word GPMC_CONFIG3_0 |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 144 | cfg3_0_val: |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 145 | .word H4_24XX_GPMC_CONFIG3_0 |
| 146 | cfg4_0_addr: |
| 147 | .word GPMC_CONFIG4_0 |
| 148 | cfg4_0_val: |
| 149 | .word H4_24XX_GPMC_CONFIG4_0 |
| 150 | cfg1_0_addr: |
| 151 | .word GPMC_CONFIG1_0 |
| 152 | pll_ctl_add: |
| 153 | .word CM_CLKEN_PLL |
| 154 | pll_stat: |
| 155 | .word CM_IDLEST_CKGEN |
| 156 | pll_div_add: |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 157 | .word CM_CLKSEL1_PLL |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 158 | pll_div_val: |
| 159 | .word DPLL_VAL /* DPLL setting (300MHz default) */ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 160 | |
Wolfgang Denk | 7f88a5e | 2005-10-06 17:08:18 +0200 | [diff] [blame] | 161 | .globl lowlevel_init |
| 162 | lowlevel_init: |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 163 | ldr sp, SRAM_STACK |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 164 | str ip, [sp] /* stash old link register */ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 165 | mov ip, lr /* save link reg across call */ |
wdenk | 2e405bf | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 166 | bl s_init /* go setup pll,mux,memory */ |
| 167 | ldr ip, [sp] /* restore save ip */ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 168 | mov lr, ip /* restore link reg */ |
wdenk | cb99da5 | 2005-01-12 00:15:14 +0000 | [diff] [blame] | 169 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 170 | /* map interrupt controller */ |
| 171 | ldr r0, VAL_INTH_SETUP |
| 172 | mcr p15, 0, r0, c15, c2, 4 |
| 173 | |
| 174 | /* back to arch calling code */ |
| 175 | mov pc, lr |
| 176 | |
| 177 | /* the literal pools origin */ |
| 178 | .ltorg |
| 179 | |
| 180 | REG_CONTROL_STATUS: |
| 181 | .word CONTROL_STATUS |
| 182 | VAL_INTH_SETUP: |
| 183 | .word PERIFERAL_PORT_BASE |
| 184 | SRAM_STACK: |
| 185 | .word LOW_LEVEL_SRAM_STACK |