blob: 8d4a88c307180cffff3a4cec230fe4152297d064 [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
47 *
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030048 */
49ENTRY(omap3_sram_configure_core_dpll)
50 stmfd sp!, {r1-r12, lr} @ store regs to stack
Paul Walmsley4519c2b2009-05-12 17:26:32 -060051 ldr r4, [sp, #52] @ pull extra args off the stack
Paul Walmsleyc9812d02009-06-19 19:08:26 -060052 ldr r5, [sp, #56] @ load extra args from the stack
Paul Walmsley69d42552009-05-12 17:27:09 -060053 dsb @ flush buffered writes to interconnect
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030054 cmp r3, #0x2
55 blne configure_sdrc
Paul Walmsley4519c2b2009-05-12 17:26:32 -060056 cmp r4, #0x1
57 bleq unlock_dll
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030058 blne lock_dll
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030059 bl sdram_in_selfrefresh @ put the SDRAM in self refresh
60 bl configure_core_dpll
61 bl enable_sdrc
Paul Walmsley4519c2b2009-05-12 17:26:32 -060062 cmp r4, #0x1
63 bleq wait_dll_unlock
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030064 blne wait_dll_lock
65 cmp r3, #0x1
Paul Walmsleyc9812d02009-06-19 19:08:26 -060066 beq return_to_sdram
67 bl configure_sdrc
68 mov r12, r5 @ if slowing, wait for SDRC to stabilize
69 bl wait_clk_stable
70return_to_sdram:
Paul Walmsley69d42552009-05-12 17:27:09 -060071 isb @ prevent speculative exec past here
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +030072 mov r0, #0 @ return value
73 ldmfd sp!, {r1-r12, pc} @ restore regs and return
74unlock_dll:
Paul Walmsleyb2abb272009-05-12 17:27:10 -060075 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, Khasimcc26b3b2008-10-09 17:51:41 +030079 bx lr
80lock_dll:
Paul Walmsleyb2abb272009-05-12 17:27:10 -060081 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, Khasimcc26b3b2008-10-09 17:51:41 +030085 bx lr
86sdram_in_selfrefresh:
Paul Walmsleyb2abb272009-05-12 17:27:10 -060087 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, Khasimcc26b3b2008-10-09 17:51:41 +030098wait_sdrc_idle:
Paul Walmsleyb2abb272009-05-12 17:27:10 -060099 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, Khasimcc26b3b2008-10-09 17:51:41 +0300103 bne wait_sdrc_idle
104 bx lr
105configure_core_dpll:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600106 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, Khasimcc26b3b2008-10-09 17:51:41 +0300113 bx lr
114wait_clk_stable:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600115 subs r12, r12, #1
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300116 bne wait_clk_stable
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300117 bx lr
118enable_sdrc:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600119 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, Khasimcc26b3b2008-10-09 17:51:41 +0300123wait_sdrc_idle1:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600124 ldr r11, omap3_cm_idlest1_core
125 ldr r12, [r11]
126 and r12, r12, #0x2
127 cmp r12, #0
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300128 bne wait_sdrc_idle1
Paul Walmsleyfa0406a2009-05-12 17:27:09 -0600129restore_sdrc_power_val:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600130 ldr r11, omap3_sdrc_power
131 str r9, [r11] @ restore SDRC_POWER, no barrier needed
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300132 bx lr
133wait_dll_lock:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600134 ldr r11, omap3_sdrc_dlla_status
135 ldr r12, [r11]
136 and r12, r12, #0x4
137 cmp r12, #0x4
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300138 bne wait_dll_lock
139 bx lr
140wait_dll_unlock:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600141 ldr r11, omap3_sdrc_dlla_status
142 ldr r12, [r11]
143 and r12, r12, #0x4
144 cmp r12, #0x0
Syed Mohammed, Khasimcc26b3b2008-10-09 17:51:41 +0300145 bne wait_dll_unlock
146 bx lr
147configure_sdrc:
Paul Walmsleyb2abb272009-05-12 17:27:10 -0600148 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, Khasimcc26b3b2008-10-09 17:51:41 +0300155 bx lr
156
157omap3_sdrc_power:
158 .word OMAP34XX_SDRC_REGADDR(SDRC_POWER)
159omap3_cm_clksel1_pll:
160 .word OMAP34XX_CM_REGADDR(PLL_MOD, CM_CLKSEL1)
161omap3_cm_idlest1_core:
162 .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST)
163omap3_cm_iclken1_core:
164 .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_ICLKEN1)
165omap3_sdrc_rfr_ctrl:
166 .word OMAP34XX_SDRC_REGADDR(SDRC_RFR_CTRL_0)
167omap3_sdrc_actim_ctrla:
168 .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_A_0)
169omap3_sdrc_actim_ctrlb:
170 .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_B_0)
171omap3_sdrc_dlla_status:
172 .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS)
173omap3_sdrc_dlla_ctrl:
174 .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL)
175core_m2_mask_val:
176 .word 0x07FFFFFF
177
178ENTRY(omap3_sram_configure_core_dpll_sz)
179 .word . - omap3_sram_configure_core_dpll