blob: 9a454151c4228b4d86464889ebb9b2a90ba9de1c [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
43 */
44ENTRY(omap3_sram_configure_core_dpll)
45 stmfd sp!, {r1-r12, lr} @ store regs to stack
Paul Walmsley69d42552009-05-12 17:27:09 -060046 dsb @ flush buffered writes to interconnect
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030047 cmp r3, #0x2
48 blne configure_sdrc
49 cmp r3, #0x2
50 blne lock_dll
51 cmp r3, #0x1
52 blne unlock_dll
53 bl sdram_in_selfrefresh @ put the SDRAM in self refresh
54 bl configure_core_dpll
55 bl enable_sdrc
56 cmp r3, #0x1
57 blne wait_dll_unlock
58 cmp r3, #0x2
59 blne wait_dll_lock
60 cmp r3, #0x1
61 blne configure_sdrc
Paul Walmsley69d42552009-05-12 17:27:09 -060062 isb @ prevent speculative exec past here
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030063 mov r0, #0 @ return value
64 ldmfd sp!, {r1-r12, pc} @ restore regs and return
65unlock_dll:
66 ldr r4, omap3_sdrc_dlla_ctrl
67 ldr r5, [r4]
68 orr r5, r5, #0x4
Paul Walmsleyd75d9e72009-05-12 17:27:09 -060069 str r5, [r4] @ (no OCP barrier needed)
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030070 bx lr
71lock_dll:
72 ldr r4, omap3_sdrc_dlla_ctrl
73 ldr r5, [r4]
74 bic r5, r5, #0x4
Paul Walmsleyd75d9e72009-05-12 17:27:09 -060075 str r5, [r4] @ (no OCP barrier needed)
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030076 bx lr
77sdram_in_selfrefresh:
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030078 ldr r4, omap3_sdrc_power @ read the SDRC_POWER register
79 ldr r5, [r4] @ read the contents of SDRC_POWER
Paul Walmsleyfa0406a2009-05-12 17:27:09 -060080 mov r9, r5 @ keep a copy of SDRC_POWER bits
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030081 orr r5, r5, #0x40 @ enable self refresh on idle req
Paul Walmsleyfa0406a2009-05-12 17:27:09 -060082 bic r5, r5, #0x4 @ clear PWDENA
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030083 str r5, [r4] @ write back to SDRC_POWER register
Paul Walmsleyd75d9e72009-05-12 17:27:09 -060084 ldr r5, [r4] @ posted-write barrier for SDRC
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030085 ldr r4, omap3_cm_iclken1_core @ read the CM_ICLKEN1_CORE reg
86 ldr r5, [r4]
Paul Walmsleyd75d9e72009-05-12 17:27:09 -060087 bic r5, r5, #0x2 @ disable iclk bit for SDRC
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030088 str r5, [r4]
89wait_sdrc_idle:
90 ldr r4, omap3_cm_idlest1_core
91 ldr r5, [r4]
92 and r5, r5, #0x2 @ check for SDRC idle
93 cmp r5, #2
94 bne wait_sdrc_idle
95 bx lr
96configure_core_dpll:
97 ldr r4, omap3_cm_clksel1_pll
98 ldr r5, [r4]
99 ldr r6, core_m2_mask_val @ modify m2 for core dpll
100 and r5, r5, r6
101 orr r5, r5, r3, lsl #0x1B @ r3 contains the M2 val
102 str r5, [r4]
Paul Walmsleyd75d9e72009-05-12 17:27:09 -0600103 ldr r5, [r4] @ posted-write barrier for CM
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300104 mov r5, #0x800 @ wait for the clock to stabilise
105 cmp r3, #2
106 bne wait_clk_stable
107 bx lr
108wait_clk_stable:
109 subs r5, r5, #1
110 bne wait_clk_stable
111 nop
112 nop
113 nop
114 nop
115 nop
116 nop
117 nop
118 nop
119 nop
120 nop
121 bx lr
122enable_sdrc:
123 ldr r4, omap3_cm_iclken1_core
124 ldr r5, [r4]
125 orr r5, r5, #0x2 @ enable iclk bit for SDRC
126 str r5, [r4]
127wait_sdrc_idle1:
128 ldr r4, omap3_cm_idlest1_core
129 ldr r5, [r4]
130 and r5, r5, #0x2
131 cmp r5, #0
132 bne wait_sdrc_idle1
Paul Walmsleyfa0406a2009-05-12 17:27:09 -0600133restore_sdrc_power_val:
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300134 ldr r4, omap3_sdrc_power
Paul Walmsleyfa0406a2009-05-12 17:27:09 -0600135 str r9, [r4] @ restore SDRC_POWER, no barrier needed
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300136 bx lr
137wait_dll_lock:
138 ldr r4, omap3_sdrc_dlla_status
139 ldr r5, [r4]
140 and r5, r5, #0x4
141 cmp r5, #0x4
142 bne wait_dll_lock
143 bx lr
144wait_dll_unlock:
145 ldr r4, omap3_sdrc_dlla_status
146 ldr r5, [r4]
147 and r5, r5, #0x4
148 cmp r5, #0x0
149 bne wait_dll_unlock
150 bx lr
151configure_sdrc:
152 ldr r4, omap3_sdrc_rfr_ctrl
153 str r0, [r4]
154 ldr r4, omap3_sdrc_actim_ctrla
155 str r1, [r4]
156 ldr r4, omap3_sdrc_actim_ctrlb
157 str r2, [r4]
Paul Walmsleyd75d9e72009-05-12 17:27:09 -0600158 ldr r2, [r4] @ 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)
175omap3_sdrc_dlla_status:
176 .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS)
177omap3_sdrc_dlla_ctrl:
178 .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL)
179core_m2_mask_val:
180 .word 0x07FFFFFF
181
182ENTRY(omap3_sram_configure_core_dpll_sz)
183 .word . - omap3_sram_configure_core_dpll