Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-omap3/sram.S |
| 3 | * |
| 4 | * Omap3 specific functions that need to be run in internal SRAM |
| 5 | * |
| 6 | * (C) Copyright 2007 |
| 7 | * Texas Instruments Inc. |
| 8 | * Rajendra Nayak <rnayak@ti.com> |
| 9 | * |
| 10 | * (C) Copyright 2004 |
| 11 | * Texas Instruments, <www.ti.com> |
| 12 | * Richard Woodruff <r-woodruff2@ti.com> |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License as |
| 16 | * published by the Free Software Foundation; either version 2 of |
| 17 | * the License, or (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 27 | * MA 02111-1307 USA |
| 28 | */ |
| 29 | #include <linux/linkage.h> |
| 30 | #include <asm/assembler.h> |
| 31 | #include <mach/hardware.h> |
| 32 | |
| 33 | #include <mach/io.h> |
| 34 | |
| 35 | #include "sdrc.h" |
| 36 | #include "cm.h" |
| 37 | |
| 38 | .text |
| 39 | |
| 40 | /* |
| 41 | * Change frequency of core dpll |
| 42 | * r0 = sdrc_rfr_ctrl r1 = sdrc_actim_ctrla r2 = sdrc_actim_ctrlb r3 = M2 |
Paul Walmsley | 4519c2b | 2009-05-12 17:26:32 -0600 | [diff] [blame] | 43 | * r4 = Unlock SDRC DLL? (1 = yes, 0 = no) -- only unlock DLL for |
| 44 | * SDRC rates < 83MHz |
Paul Walmsley | c9812d0 | 2009-06-19 19:08:26 -0600 | [diff] [blame^] | 45 | * r5 = number of MPU cycles to wait for SDRC to stabilize after |
| 46 | * reprogramming the SDRC when switching to a slower MPU speed |
| 47 | * |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 48 | */ |
| 49 | ENTRY(omap3_sram_configure_core_dpll) |
| 50 | stmfd sp!, {r1-r12, lr} @ store regs to stack |
Paul Walmsley | 4519c2b | 2009-05-12 17:26:32 -0600 | [diff] [blame] | 51 | ldr r4, [sp, #52] @ pull extra args off the stack |
Paul Walmsley | c9812d0 | 2009-06-19 19:08:26 -0600 | [diff] [blame^] | 52 | ldr r5, [sp, #56] @ load extra args from the stack |
Paul Walmsley | 69d4255 | 2009-05-12 17:27:09 -0600 | [diff] [blame] | 53 | dsb @ flush buffered writes to interconnect |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 54 | cmp r3, #0x2 |
| 55 | blne configure_sdrc |
Paul Walmsley | 4519c2b | 2009-05-12 17:26:32 -0600 | [diff] [blame] | 56 | cmp r4, #0x1 |
| 57 | bleq unlock_dll |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 58 | blne lock_dll |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 59 | bl sdram_in_selfrefresh @ put the SDRAM in self refresh |
| 60 | bl configure_core_dpll |
| 61 | bl enable_sdrc |
Paul Walmsley | 4519c2b | 2009-05-12 17:26:32 -0600 | [diff] [blame] | 62 | cmp r4, #0x1 |
| 63 | bleq wait_dll_unlock |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 64 | blne wait_dll_lock |
| 65 | cmp r3, #0x1 |
Paul Walmsley | c9812d0 | 2009-06-19 19:08:26 -0600 | [diff] [blame^] | 66 | beq return_to_sdram |
| 67 | bl configure_sdrc |
| 68 | mov r12, r5 @ if slowing, wait for SDRC to stabilize |
| 69 | bl wait_clk_stable |
| 70 | return_to_sdram: |
Paul Walmsley | 69d4255 | 2009-05-12 17:27:09 -0600 | [diff] [blame] | 71 | isb @ prevent speculative exec past here |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 72 | mov r0, #0 @ return value |
| 73 | ldmfd sp!, {r1-r12, pc} @ restore regs and return |
| 74 | unlock_dll: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 75 | ldr r11, omap3_sdrc_dlla_ctrl |
| 76 | ldr r12, [r11] |
| 77 | orr r12, r12, #0x4 |
| 78 | str r12, [r11] @ (no OCP barrier needed) |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 79 | bx lr |
| 80 | lock_dll: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 81 | ldr r11, omap3_sdrc_dlla_ctrl |
| 82 | ldr r12, [r11] |
| 83 | bic r12, r12, #0x4 |
| 84 | str r12, [r11] @ (no OCP barrier needed) |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 85 | bx lr |
| 86 | sdram_in_selfrefresh: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 87 | ldr r11, omap3_sdrc_power @ read the SDRC_POWER register |
| 88 | ldr r12, [r11] @ read the contents of SDRC_POWER |
| 89 | mov r9, r12 @ keep a copy of SDRC_POWER bits |
| 90 | orr r12, r12, #0x40 @ enable self refresh on idle req |
| 91 | bic r12, r12, #0x4 @ clear PWDENA |
| 92 | str r12, [r11] @ write back to SDRC_POWER register |
| 93 | ldr r12, [r11] @ posted-write barrier for SDRC |
| 94 | ldr r11, omap3_cm_iclken1_core @ read the CM_ICLKEN1_CORE reg |
| 95 | ldr r12, [r11] |
| 96 | bic r12, r12, #0x2 @ disable iclk bit for SDRC |
| 97 | str r12, [r11] |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 98 | wait_sdrc_idle: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 99 | ldr r11, omap3_cm_idlest1_core |
| 100 | ldr r12, [r11] |
| 101 | and r12, r12, #0x2 @ check for SDRC idle |
| 102 | cmp r12, #2 |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 103 | bne wait_sdrc_idle |
| 104 | bx lr |
| 105 | configure_core_dpll: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 106 | ldr r11, omap3_cm_clksel1_pll |
| 107 | ldr r12, [r11] |
| 108 | ldr r10, core_m2_mask_val @ modify m2 for core dpll |
| 109 | and r12, r12, r10 |
| 110 | orr r12, r12, r3, lsl #0x1B @ r3 contains the M2 val |
| 111 | str r12, [r11] |
| 112 | ldr r12, [r11] @ posted-write barrier for CM |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 113 | bx lr |
| 114 | wait_clk_stable: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 115 | subs r12, r12, #1 |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 116 | bne wait_clk_stable |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 117 | bx lr |
| 118 | enable_sdrc: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 119 | ldr r11, omap3_cm_iclken1_core |
| 120 | ldr r12, [r11] |
| 121 | orr r12, r12, #0x2 @ enable iclk bit for SDRC |
| 122 | str r12, [r11] |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 123 | wait_sdrc_idle1: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 124 | ldr r11, omap3_cm_idlest1_core |
| 125 | ldr r12, [r11] |
| 126 | and r12, r12, #0x2 |
| 127 | cmp r12, #0 |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 128 | bne wait_sdrc_idle1 |
Paul Walmsley | fa0406a | 2009-05-12 17:27:09 -0600 | [diff] [blame] | 129 | restore_sdrc_power_val: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 130 | ldr r11, omap3_sdrc_power |
| 131 | str r9, [r11] @ restore SDRC_POWER, no barrier needed |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 132 | bx lr |
| 133 | wait_dll_lock: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 134 | ldr r11, omap3_sdrc_dlla_status |
| 135 | ldr r12, [r11] |
| 136 | and r12, r12, #0x4 |
| 137 | cmp r12, #0x4 |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 138 | bne wait_dll_lock |
| 139 | bx lr |
| 140 | wait_dll_unlock: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 141 | ldr r11, omap3_sdrc_dlla_status |
| 142 | ldr r12, [r11] |
| 143 | and r12, r12, #0x4 |
| 144 | cmp r12, #0x0 |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 145 | bne wait_dll_unlock |
| 146 | bx lr |
| 147 | configure_sdrc: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 148 | ldr r11, omap3_sdrc_rfr_ctrl |
| 149 | str r0, [r11] |
| 150 | ldr r11, omap3_sdrc_actim_ctrla |
| 151 | str r1, [r11] |
| 152 | ldr r11, omap3_sdrc_actim_ctrlb |
| 153 | str r2, [r11] |
| 154 | ldr r2, [r11] @ posted-write barrier for SDRC |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 155 | bx lr |
| 156 | |
| 157 | omap3_sdrc_power: |
| 158 | .word OMAP34XX_SDRC_REGADDR(SDRC_POWER) |
| 159 | omap3_cm_clksel1_pll: |
| 160 | .word OMAP34XX_CM_REGADDR(PLL_MOD, CM_CLKSEL1) |
| 161 | omap3_cm_idlest1_core: |
| 162 | .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST) |
| 163 | omap3_cm_iclken1_core: |
| 164 | .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_ICLKEN1) |
| 165 | omap3_sdrc_rfr_ctrl: |
| 166 | .word OMAP34XX_SDRC_REGADDR(SDRC_RFR_CTRL_0) |
| 167 | omap3_sdrc_actim_ctrla: |
| 168 | .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_A_0) |
| 169 | omap3_sdrc_actim_ctrlb: |
| 170 | .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_B_0) |
| 171 | omap3_sdrc_dlla_status: |
| 172 | .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS) |
| 173 | omap3_sdrc_dlla_ctrl: |
| 174 | .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL) |
| 175 | core_m2_mask_val: |
| 176 | .word 0x07FFFFFF |
| 177 | |
| 178 | ENTRY(omap3_sram_configure_core_dpll_sz) |
| 179 | .word . - omap3_sram_configure_core_dpll |