blob: d13f1cc4bd58ba1e2d874ae8a2d69c564db7cac6 [file] [log] [blame]
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +03001/*
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 Walmsley4519c2b2009-05-12 17:26:32 -060043 * r4 = Unlock SDRC DLL? (1 = yes, 0 = no) -- only unlock DLL for
44 * SDRC rates < 83MHz
Paul Walmsleyc9812d02009-06-19 19:08:26 -060045 * r5 = number of MPU cycles to wait for SDRC to stabilize after
46 * reprogramming the SDRC when switching to a slower MPU speed
Paul Walmsleyd0ba3922009-06-19 19:08:27 -060047 * r6 = SDRC_MR_0 register value
Paul Walmsleyc9812d02009-06-19 19:08:26 -060048 *
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030049 */
50ENTRY(omap3_sram_configure_core_dpll)
51 stmfd sp!, {r1-r12, lr} @ store regs to stack
Paul Walmsley4519c2b2009-05-12 17:26:32 -060052 ldr r4, [sp, #52] @ pull extra args off the stack
Paul Walmsleyc9812d02009-06-19 19:08:26 -060053 ldr r5, [sp, #56] @ load extra args from the stack
Paul Walmsleyd0ba3922009-06-19 19:08:27 -060054 ldr r6, [sp, #60] @ load extra args from the stack
Paul Walmsley69d42552009-05-12 17:27:09 -060055 dsb @ flush buffered writes to interconnect
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030056 cmp r3, #0x2
57 blne configure_sdrc
Paul Walmsley4519c2b2009-05-12 17:26:32 -060058 cmp r4, #0x1
59 bleq unlock_dll
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030060 blne lock_dll
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030061 bl sdram_in_selfrefresh @ put the SDRAM in self refresh
62 bl configure_core_dpll
63 bl enable_sdrc
Paul Walmsley4519c2b2009-05-12 17:26:32 -060064 cmp r4, #0x1
65 bleq wait_dll_unlock
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030066 blne wait_dll_lock
67 cmp r3, #0x1
Paul Walmsleyc9812d02009-06-19 19:08:26 -060068 beq return_to_sdram
69 bl configure_sdrc
70 mov r12, r5 @ if slowing, wait for SDRC to stabilize
71 bl wait_clk_stable
72return_to_sdram:
Paul Walmsley69d42552009-05-12 17:27:09 -060073 isb @ prevent speculative exec past here
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030074 mov r0, #0 @ return value
75 ldmfd sp!, {r1-r12, pc} @ restore regs and return
76unlock_dll:
Paul Walmsleyb2abb272009-05-12 17:27:10 -060077 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, Khasimcc26b3b2008-10-09 17:51:41 +030081 bx lr
82lock_dll:
Paul Walmsleyb2abb272009-05-12 17:27:10 -060083 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, Khasimcc26b3b2008-10-09 17:51:41 +030087 bx lr
88sdram_in_selfrefresh:
Paul Walmsleyb2abb272009-05-12 17:27:10 -060089 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, Khasimcc26b3b2008-10-09 17:51:41 +0300100wait_sdrc_idle:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600101 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, Khasimcc26b3b2008-10-09 17:51:41 +0300105 bne wait_sdrc_idle
106 bx lr
107configure_core_dpll:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600108 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, Khasimcc26b3b2008-10-09 17:51:41 +0300115 bx lr
116wait_clk_stable:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600117 subs r12, r12, #1
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300118 bne wait_clk_stable
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300119 bx lr
120enable_sdrc:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600121 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, Khasimcc26b3b2008-10-09 17:51:41 +0300125wait_sdrc_idle1:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600126 ldr r11, omap3_cm_idlest1_core
127 ldr r12, [r11]
128 and r12, r12, #0x2
129 cmp r12, #0
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300130 bne wait_sdrc_idle1
Paul Walmsleyfa0406a2009-05-12 17:27:09 -0600131restore_sdrc_power_val:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600132 ldr r11, omap3_sdrc_power
133 str r9, [r11] @ restore SDRC_POWER, no barrier needed
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300134 bx lr
135wait_dll_lock:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600136 ldr r11, omap3_sdrc_dlla_status
137 ldr r12, [r11]
138 and r12, r12, #0x4
139 cmp r12, #0x4
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300140 bne wait_dll_lock
141 bx lr
142wait_dll_unlock:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600143 ldr r11, omap3_sdrc_dlla_status
144 ldr r12, [r11]
145 and r12, r12, #0x4
146 cmp r12, #0x0
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300147 bne wait_dll_unlock
148 bx lr
149configure_sdrc:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600150 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 Walmsleyd0ba3922009-06-19 19:08:27 -0600156 ldr r11, omap3_sdrc_mr_0
157 str r6, [r11]
158 ldr r6, [r11] @ posted-write barrier for SDRC
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300159 bx lr
160
161omap3_sdrc_power:
162 .word OMAP34XX_SDRC_REGADDR(SDRC_POWER)
163omap3_cm_clksel1_pll:
164 .word OMAP34XX_CM_REGADDR(PLL_MOD, CM_CLKSEL1)
165omap3_cm_idlest1_core:
166 .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST)
167omap3_cm_iclken1_core:
168 .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_ICLKEN1)
169omap3_sdrc_rfr_ctrl:
170 .word OMAP34XX_SDRC_REGADDR(SDRC_RFR_CTRL_0)
171omap3_sdrc_actim_ctrla:
172 .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_A_0)
173omap3_sdrc_actim_ctrlb:
174 .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_B_0)
Paul Walmsleyd0ba3922009-06-19 19:08:27 -0600175omap3_sdrc_mr_0:
176 .word OMAP34XX_SDRC_REGADDR(SDRC_MR_0)
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300177omap3_sdrc_dlla_status:
178 .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS)
179omap3_sdrc_dlla_ctrl:
180 .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL)
181core_m2_mask_val:
182 .word 0x07FFFFFF
183
184ENTRY(omap3_sram_configure_core_dpll_sz)
185 .word . - omap3_sram_configure_core_dpll