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 |
Paul Walmsley | d0ba392 | 2009-06-19 19:08:27 -0600 | [diff] [blame^] | 47 | * r6 = SDRC_MR_0 register value |
Paul Walmsley | c9812d0 | 2009-06-19 19:08:26 -0600 | [diff] [blame] | 48 | * |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 49 | */ |
| 50 | ENTRY(omap3_sram_configure_core_dpll) |
| 51 | stmfd sp!, {r1-r12, lr} @ store regs to stack |
Paul Walmsley | 4519c2b | 2009-05-12 17:26:32 -0600 | [diff] [blame] | 52 | ldr r4, [sp, #52] @ pull extra args off the stack |
Paul Walmsley | c9812d0 | 2009-06-19 19:08:26 -0600 | [diff] [blame] | 53 | ldr r5, [sp, #56] @ load extra args from the stack |
Paul Walmsley | d0ba392 | 2009-06-19 19:08:27 -0600 | [diff] [blame^] | 54 | ldr r6, [sp, #60] @ load extra args from the stack |
Paul Walmsley | 69d4255 | 2009-05-12 17:27:09 -0600 | [diff] [blame] | 55 | dsb @ flush buffered writes to interconnect |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 56 | cmp r3, #0x2 |
| 57 | blne configure_sdrc |
Paul Walmsley | 4519c2b | 2009-05-12 17:26:32 -0600 | [diff] [blame] | 58 | cmp r4, #0x1 |
| 59 | bleq unlock_dll |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 60 | blne lock_dll |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 61 | bl sdram_in_selfrefresh @ put the SDRAM in self refresh |
| 62 | bl configure_core_dpll |
| 63 | bl enable_sdrc |
Paul Walmsley | 4519c2b | 2009-05-12 17:26:32 -0600 | [diff] [blame] | 64 | cmp r4, #0x1 |
| 65 | bleq wait_dll_unlock |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 66 | blne wait_dll_lock |
| 67 | cmp r3, #0x1 |
Paul Walmsley | c9812d0 | 2009-06-19 19:08:26 -0600 | [diff] [blame] | 68 | beq return_to_sdram |
| 69 | bl configure_sdrc |
| 70 | mov r12, r5 @ if slowing, wait for SDRC to stabilize |
| 71 | bl wait_clk_stable |
| 72 | return_to_sdram: |
Paul Walmsley | 69d4255 | 2009-05-12 17:27:09 -0600 | [diff] [blame] | 73 | isb @ prevent speculative exec past here |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 74 | mov r0, #0 @ return value |
| 75 | ldmfd sp!, {r1-r12, pc} @ restore regs and return |
| 76 | unlock_dll: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 77 | ldr r11, omap3_sdrc_dlla_ctrl |
| 78 | ldr r12, [r11] |
| 79 | orr r12, r12, #0x4 |
| 80 | str r12, [r11] @ (no OCP barrier needed) |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 81 | bx lr |
| 82 | lock_dll: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 83 | ldr r11, omap3_sdrc_dlla_ctrl |
| 84 | ldr r12, [r11] |
| 85 | bic r12, r12, #0x4 |
| 86 | str r12, [r11] @ (no OCP barrier needed) |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 87 | bx lr |
| 88 | sdram_in_selfrefresh: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 89 | ldr r11, omap3_sdrc_power @ read the SDRC_POWER register |
| 90 | ldr r12, [r11] @ read the contents of SDRC_POWER |
| 91 | mov r9, r12 @ keep a copy of SDRC_POWER bits |
| 92 | orr r12, r12, #0x40 @ enable self refresh on idle req |
| 93 | bic r12, r12, #0x4 @ clear PWDENA |
| 94 | str r12, [r11] @ write back to SDRC_POWER register |
| 95 | ldr r12, [r11] @ posted-write barrier for SDRC |
| 96 | ldr r11, omap3_cm_iclken1_core @ read the CM_ICLKEN1_CORE reg |
| 97 | ldr r12, [r11] |
| 98 | bic r12, r12, #0x2 @ disable iclk bit for SDRC |
| 99 | str r12, [r11] |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 100 | wait_sdrc_idle: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 101 | ldr r11, omap3_cm_idlest1_core |
| 102 | ldr r12, [r11] |
| 103 | and r12, r12, #0x2 @ check for SDRC idle |
| 104 | cmp r12, #2 |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 105 | bne wait_sdrc_idle |
| 106 | bx lr |
| 107 | configure_core_dpll: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 108 | ldr r11, omap3_cm_clksel1_pll |
| 109 | ldr r12, [r11] |
| 110 | ldr r10, core_m2_mask_val @ modify m2 for core dpll |
| 111 | and r12, r12, r10 |
| 112 | orr r12, r12, r3, lsl #0x1B @ r3 contains the M2 val |
| 113 | str r12, [r11] |
| 114 | ldr r12, [r11] @ posted-write barrier for CM |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 115 | bx lr |
| 116 | wait_clk_stable: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 117 | subs r12, r12, #1 |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 118 | bne wait_clk_stable |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 119 | bx lr |
| 120 | enable_sdrc: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 121 | ldr r11, omap3_cm_iclken1_core |
| 122 | ldr r12, [r11] |
| 123 | orr r12, r12, #0x2 @ enable iclk bit for SDRC |
| 124 | str r12, [r11] |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 125 | wait_sdrc_idle1: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 126 | ldr r11, omap3_cm_idlest1_core |
| 127 | ldr r12, [r11] |
| 128 | and r12, r12, #0x2 |
| 129 | cmp r12, #0 |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 130 | bne wait_sdrc_idle1 |
Paul Walmsley | fa0406a | 2009-05-12 17:27:09 -0600 | [diff] [blame] | 131 | restore_sdrc_power_val: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 132 | ldr r11, omap3_sdrc_power |
| 133 | str r9, [r11] @ restore SDRC_POWER, no barrier needed |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 134 | bx lr |
| 135 | wait_dll_lock: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 136 | ldr r11, omap3_sdrc_dlla_status |
| 137 | ldr r12, [r11] |
| 138 | and r12, r12, #0x4 |
| 139 | cmp r12, #0x4 |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 140 | bne wait_dll_lock |
| 141 | bx lr |
| 142 | wait_dll_unlock: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 143 | ldr r11, omap3_sdrc_dlla_status |
| 144 | ldr r12, [r11] |
| 145 | and r12, r12, #0x4 |
| 146 | cmp r12, #0x0 |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 147 | bne wait_dll_unlock |
| 148 | bx lr |
| 149 | configure_sdrc: |
Paul Walmsley | b2abb27 | 2009-05-12 17:27:10 -0600 | [diff] [blame] | 150 | ldr r11, omap3_sdrc_rfr_ctrl |
| 151 | str r0, [r11] |
| 152 | ldr r11, omap3_sdrc_actim_ctrla |
| 153 | str r1, [r11] |
| 154 | ldr r11, omap3_sdrc_actim_ctrlb |
| 155 | str r2, [r11] |
Paul Walmsley | d0ba392 | 2009-06-19 19:08:27 -0600 | [diff] [blame^] | 156 | ldr r11, omap3_sdrc_mr_0 |
| 157 | str r6, [r11] |
| 158 | ldr r6, [r11] @ posted-write barrier for SDRC |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 159 | bx lr |
| 160 | |
| 161 | omap3_sdrc_power: |
| 162 | .word OMAP34XX_SDRC_REGADDR(SDRC_POWER) |
| 163 | omap3_cm_clksel1_pll: |
| 164 | .word OMAP34XX_CM_REGADDR(PLL_MOD, CM_CLKSEL1) |
| 165 | omap3_cm_idlest1_core: |
| 166 | .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST) |
| 167 | omap3_cm_iclken1_core: |
| 168 | .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_ICLKEN1) |
| 169 | omap3_sdrc_rfr_ctrl: |
| 170 | .word OMAP34XX_SDRC_REGADDR(SDRC_RFR_CTRL_0) |
| 171 | omap3_sdrc_actim_ctrla: |
| 172 | .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_A_0) |
| 173 | omap3_sdrc_actim_ctrlb: |
| 174 | .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_B_0) |
Paul Walmsley | d0ba392 | 2009-06-19 19:08:27 -0600 | [diff] [blame^] | 175 | omap3_sdrc_mr_0: |
| 176 | .word OMAP34XX_SDRC_REGADDR(SDRC_MR_0) |
Syed Mohammed, Khasim | cc26b3b | 2008-10-09 17:51:41 +0300 | [diff] [blame] | 177 | omap3_sdrc_dlla_status: |
| 178 | .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS) |
| 179 | omap3_sdrc_dlla_ctrl: |
| 180 | .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL) |
| 181 | core_m2_mask_val: |
| 182 | .word 0x07FFFFFF |
| 183 | |
| 184 | ENTRY(omap3_sram_configure_core_dpll_sz) |
| 185 | .word . - omap3_sram_configure_core_dpll |