blob: ff7af32da02cde39103e0fa65cea9bb93b8ee4ba [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/*
2 * Idle processing for ARMv7-based Qualcomm SoCs.
3 *
4 * Copyright (C) 2007 Google, Inc.
Pratik Patel17f3b822011-11-21 12:41:47 -08005 * Copyright (c) 2007-2009, 2011-2012 Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#include <linux/linkage.h>
19#include <linux/threads.h>
20#include <asm/assembler.h>
21
Steve Mucklefcece052012-02-18 20:09:58 -080022#include "idle.h"
Murali Nalajala73c13332012-05-15 11:30:59 +053023#include "idle-macros.S"
Steve Mucklefcece052012-02-18 20:09:58 -080024
Maheshkumar Sivasubramanianfa1d0dd2011-07-26 16:02:55 -060025#ifdef CONFIG_ARCH_MSM_KRAIT
26#define SCM_SVC_BOOT 0x1
27#define SCM_CMD_TERMINATE_PC 0x2
28#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070029
30ENTRY(msm_arch_idle)
Stepan Moskovchenkoae920e72012-07-03 19:10:44 -070031#ifdef CONFIG_ARCH_MSM_KRAIT
32 mrc p15, 0, r0, c0, c0, 0
33 bic r1, r0, #0xff
34 movw r2, #0x0400
35 movt r2, #0x511F
36 movw r3, #0x0600
37 movt r3, #0x510F
38 cmp r2, r1
39 cmpne r3, r1
40 bne go_wfi
41
42 mrs r0, cpsr
43 cpsid if
44
45 mrc p15, 7, r1, c15, c0, 5
46 bic r2, r1, #0x20000
47 mcr p15, 7, r2, c15, c0, 5
48 isb
49
50go_wfi:
51 wfi
52 bne wfi_done
53 mcr p15, 7, r1, c15, c0, 5
54 isb
55 msr cpsr_c, r0
56
57wfi_done:
58 bx lr
59#else
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060 wfi
Pratik Patelcbcc1f02011-11-08 12:58:00 -080061#ifdef CONFIG_ARCH_MSM8X60
62 mrc p14, 1, r1, c1, c5, 4 /* read ETM PDSR to clear sticky bit */
63 mrc p14, 0, r1, c1, c5, 4 /* read DBG PRSR to clear sticky bit */
64 isb
65#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066 bx lr
Stepan Moskovchenkoae920e72012-07-03 19:10:44 -070067#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070068
69ENTRY(msm_pm_collapse)
70#if defined(CONFIG_MSM_FIQ_SUPPORT)
71 cpsid f
72#endif
73
Steve Mucklefcece052012-02-18 20:09:58 -080074 ldr r0, =msm_saved_state /* address of msm_saved_state ptr */
75 ldr r0, [r0] /* load ptr */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070076#if (NR_CPUS >= 2)
77 mrc p15, 0, r1, c0, c0, 5 /* MPIDR */
78 ands r1, r1, #15 /* What CPU am I */
Mahesh Sivasubramanian0ff37e72011-12-15 14:12:31 -070079 mov r2, #CPU_SAVED_STATE_SIZE
80 mul r1, r1, r2
81 add r0, r0, r1
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070082#endif
83
84 stmia r0!, {r4-r14}
85 mrc p15, 0, r1, c1, c0, 0 /* MMU control */
86 mrc p15, 0, r2, c2, c0, 0 /* TTBR0 */
87 mrc p15, 0, r3, c3, c0, 0 /* dacr */
88#ifdef CONFIG_ARCH_MSM_SCORPION
89 /* This instruction is not valid for non scorpion processors */
90 mrc p15, 3, r4, c15, c0, 3 /* L2CR1 is the L2 cache control reg 1 */
91#endif
92 mrc p15, 0, r5, c10, c2, 0 /* PRRR */
93 mrc p15, 0, r6, c10, c2, 1 /* NMRR */
94 mrc p15, 0, r7, c1, c0, 1 /* ACTLR */
95 mrc p15, 0, r8, c2, c0, 1 /* TTBR1 */
96 mrc p15, 0, r9, c13, c0, 3 /* TPIDRURO */
97 mrc p15, 0, ip, c13, c0, 1 /* context ID */
98 stmia r0!, {r1-r9, ip}
99#ifdef CONFIG_MSM_CPU_AVS
100 mrc p15, 7, r1, c15, c1, 7 /* AVSCSR is the Adaptive Voltage Scaling
101 * Control and Status Register */
102 mrc p15, 7, r2, c15, c0, 6 /* AVSDSCR is the Adaptive Voltage
103 * Scaling Delay Synthesizer Control
104 * Register */
105#ifndef CONFIG_ARCH_MSM_KRAIT
106 mrc p15, 7, r3, c15, c1, 0 /* TSCSR is the Temperature Status and
107 * Control Register
108 */
109#endif
110
111 stmia r0!, {r1-r3}
112#endif
113
Pratik Patel17f3b822011-11-21 12:41:47 -0800114#ifdef CONFIG_MSM_JTAG
115 bl msm_jtag_save_state
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116#endif
Maheshkumar Sivasubramaniana012e092011-08-18 10:13:03 -0600117
118 ldr r0, =msm_pm_flush_l2_flag
119 ldr r0, [r0]
120 mov r1, #0
121 mcr p15, 2, r1, c0, c0, 0 /*CCSELR*/
Maheshkumar Sivasubramanian1d2b69c2011-11-17 10:26:09 -0700122 isb
Maheshkumar Sivasubramaniana012e092011-08-18 10:13:03 -0600123 mrc p15, 1, r1, c0, c0, 0 /*CCSIDR*/
124 mov r2, #1
125 and r1, r2, r1, ASR #30 /* Check if the cache is write back */
126 orr r1, r0, r1
127 cmp r1, #1
128 bne skip
129 bl v7_flush_dcache_all
Steve Mucklefcece052012-02-18 20:09:58 -0800130skip:
Maheshkumar Sivasubramanianfa1d0dd2011-07-26 16:02:55 -0600131#ifdef CONFIG_ARCH_MSM_KRAIT
132 ldr r0, =SCM_SVC_BOOT
133 ldr r1, =SCM_CMD_TERMINATE_PC
Maheshkumar Sivasubramanian16588412011-10-13 12:16:23 -0600134 ldr r2, =msm_pm_flush_l2_flag
135 ldr r2, [r2]
Maheshkumar Sivasubramanianfa1d0dd2011-07-26 16:02:55 -0600136 bl scm_call_atomic1
137#else
Stepan Moskovchenko34dc00f2012-01-28 19:31:41 -0800138 mrc p15, 0, r4, c1, c0, 0 /* read current CR */
139 bic r0, r4, #(1 << 2) /* clear dcache bit */
140 bic r0, r0, #(1 << 12) /* clear icache bit */
141 mcr p15, 0, r0, c1, c0, 0 /* disable d/i cache */
Murali Nalajala73c13332012-05-15 11:30:59 +0530142 isb
Stepan Moskovchenko34dc00f2012-01-28 19:31:41 -0800143
Murali Nalajala73c13332012-05-15 11:30:59 +0530144 SUSPEND_8x25_L2
Murali Nalajala93f29992012-03-21 15:59:27 +0530145 SET_SMP_COHERENCY OFF
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700146 wfi
Murali Nalajala3a6de242012-05-11 15:05:35 +0530147 DELAY_8x25 300
Stepan Moskovchenko34dc00f2012-01-28 19:31:41 -0800148
Maheshkumar Sivasubramanianfa1d0dd2011-07-26 16:02:55 -0600149 mcr p15, 0, r4, c1, c0, 0 /* restore d/i cache */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700150 isb
Murali Nalajala73c13332012-05-15 11:30:59 +0530151 ENABLE_8x25_L2 /* enable only l2, no need to restore the reg back */
Murali Nalajala93f29992012-03-21 15:59:27 +0530152 SET_SMP_COHERENCY ON
Murali Nalajala73c13332012-05-15 11:30:59 +0530153#endif
154
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700155#if defined(CONFIG_MSM_FIQ_SUPPORT)
156 cpsie f
157#endif
Pratik Patel17f3b822011-11-21 12:41:47 -0800158#ifdef CONFIG_MSM_JTAG
159 bl msm_jtag_restore_state
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700160#endif
Steve Mucklefcece052012-02-18 20:09:58 -0800161 ldr r0, =msm_saved_state /* address of msm_saved_state ptr */
162 ldr r0, [r0] /* load ptr */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700163#if (NR_CPUS >= 2)
164 mrc p15, 0, r1, c0, c0, 5 /* MPIDR */
165 ands r1, r1, #15 /* What CPU am I */
Praveen Chidambaram4b1e6f02012-02-11 16:17:30 -0700166 mov r2, #CPU_SAVED_STATE_SIZE
167 mul r2, r2, r1
168 add r0, r0, r2
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700169#endif
Steve Mucklefcece052012-02-18 20:09:58 -0800170 ldmfd r0, {r4-r14} /* restore registers */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700171 mov r0, #0 /* return power collapse failed */
172 bx lr
173
174ENTRY(msm_pm_collapse_exit)
175#if 0 /* serial debug */
176 mov r0, #0x80000016
177 mcr p15, 0, r0, c15, c2, 4
178 mov r0, #0xA9000000
179 add r0, r0, #0x00A00000 /* UART1 */
180 /*add r0, r0, #0x00C00000*/ /* UART3 */
181 mov r1, #'A'
182 str r1, [r0, #0x00C]
183#endif
Steve Mucklefcece052012-02-18 20:09:58 -0800184 ldr r1, =msm_saved_state_phys
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185 ldr r2, =msm_pm_collapse_exit
186 adr r3, msm_pm_collapse_exit
187 add r1, r1, r3
188 sub r1, r1, r2
Steve Mucklefcece052012-02-18 20:09:58 -0800189 ldr r1, [r1]
Mahesh Sivasubramanian0ff37e72011-12-15 14:12:31 -0700190 add r1, r1, #CPU_SAVED_STATE_SIZE
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700191#if (NR_CPUS >= 2)
192 mrc p15, 0, r2, c0, c0, 5 /* MPIDR */
193 ands r2, r2, #15 /* What CPU am I */
Mahesh Sivasubramanian0ff37e72011-12-15 14:12:31 -0700194 mov r3, #CPU_SAVED_STATE_SIZE
195 mul r2, r2, r3
196 add r1, r1, r2
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700197#endif
198
199#ifdef CONFIG_MSM_CPU_AVS
200 ldmdb r1!, {r2-r4}
201#ifndef CONFIG_ARCH_MSM_KRAIT
202 mcr p15, 7, r4, c15, c1, 0 /* TSCSR */
203#endif
204 mcr p15, 7, r3, c15, c0, 6 /* AVSDSCR */
205 mcr p15, 7, r2, c15, c1, 7 /* AVSCSR */
206#endif
207 ldmdb r1!, {r2-r11}
208 mcr p15, 0, r4, c3, c0, 0 /* dacr */
209 mcr p15, 0, r3, c2, c0, 0 /* TTBR0 */
210#ifdef CONFIG_ARCH_MSM_SCORPION
211 /* This instruction is not valid for non scorpion processors */
212 mcr p15, 3, r5, c15, c0, 3 /* L2CR1 */
213#endif
214 mcr p15, 0, r6, c10, c2, 0 /* PRRR */
215 mcr p15, 0, r7, c10, c2, 1 /* NMRR */
216 mcr p15, 0, r8, c1, c0, 1 /* ACTLR */
217 mcr p15, 0, r9, c2, c0, 1 /* TTBR1 */
218 mcr p15, 0, r10, c13, c0, 3 /* TPIDRURO */
219 mcr p15, 0, r11, c13, c0, 1 /* context ID */
220 isb
221 ldmdb r1!, {r4-r14}
222 ldr r0, =msm_pm_pc_pgd
223 ldr r1, =msm_pm_collapse_exit
224 adr r3, msm_pm_collapse_exit
225 add r0, r0, r3
226 sub r0, r0, r1
227 ldr r0, [r0]
228 mrc p15, 0, r1, c2, c0, 0 /* save current TTBR0 */
229 and r3, r1, #0x7f /* mask to get TTB flags */
230 orr r0, r0, r3 /* add TTB flags to switch TTBR value */
231 mcr p15, 0, r0, c2, c0, 0 /* temporary switch TTBR0 */
232 isb
233 mcr p15, 0, r2, c1, c0, 0 /* MMU control */
234 isb
235msm_pm_mapped_pa:
236 /* Switch to virtual */
237 ldr r0, =msm_pm_pa_to_va
238 mov pc, r0
239msm_pm_pa_to_va:
240 mcr p15, 0, r1, c2, c0, 0 /* restore TTBR0 */
241 isb
242 mcr p15, 0, r3, c8, c7, 0 /* UTLBIALL */
243 mcr p15, 0, r3, c7, c5, 6 /* BPIALL */
244 dsb
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700245 isb
Murali Nalajala93f29992012-03-21 15:59:27 +0530246
Stepan Moskovchenko6fd9c922011-12-08 18:15:05 -0800247#ifdef CONFIG_ARCH_MSM_KRAIT
248 mrc p15, 0, r1, c0, c0, 0
249 ldr r3, =0xff00fc00
250 and r3, r1, r3
251 ldr r1, =0x51000400
252 cmp r3, r1
253 mrceq p15, 7, r3, c15, c0, 2
254 biceq r3, r3, #0x400
255 mcreq p15, 7, r3, c15, c0, 2
Murali Nalajala73c13332012-05-15 11:30:59 +0530256#else
257 RESUME_8x25_L2
258 SET_SMP_COHERENCY ON
Stepan Moskovchenko6fd9c922011-12-08 18:15:05 -0800259#endif
Murali Nalajala73c13332012-05-15 11:30:59 +0530260
Pratik Patel17f3b822011-11-21 12:41:47 -0800261#ifdef CONFIG_MSM_JTAG
Steve Mucklec1421e32012-03-26 11:05:06 -0700262 stmfd sp!, {lr}
Pratik Patel17f3b822011-11-21 12:41:47 -0800263 bl msm_jtag_restore_state
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700264 ldmfd sp!, {lr}
Steve Mucklec1421e32012-03-26 11:05:06 -0700265#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700266 mov r0, #1
267 bx lr
268 nop
269 nop
270 nop
271 nop
272 nop
2731: b 1b
274
275ENTRY(msm_pm_boot_entry)
276 mrc p15, 0, r0, c0, c0, 5 /* MPIDR */
277 and r0, r0, #15 /* what CPU am I */
278
279 ldr r1, =msm_pm_boot_vector
280 ldr r2, =msm_pm_boot_entry
281 adr r3, msm_pm_boot_entry
282 add r1, r1, r3 /* translate virt to phys addr */
283 sub r1, r1, r2
284
285 add r1, r1, r0, LSL #2 /* locate boot vector for our cpu */
286 ldr pc, [r1] /* jump */
287
Maheshkumar Sivasubramaniana012e092011-08-18 10:13:03 -0600288ENTRY(msm_pm_set_l2_flush_flag)
289 ldr r1, =msm_pm_flush_l2_flag
290 str r0, [r1]
291 bx lr
292
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700293 .data
294
295 .globl msm_pm_pc_pgd
296msm_pm_pc_pgd:
297 .long 0x0
298
Steve Mucklefcece052012-02-18 20:09:58 -0800299 .globl msm_saved_state
300msm_saved_state:
301 .long 0x0
302
303 .globl msm_saved_state_phys
304msm_saved_state_phys:
305 .long 0x0
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700306
Steve Mucklec25a9362012-03-22 16:40:01 -0700307 .globl msm_pm_boot_vector
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700308msm_pm_boot_vector:
309 .space 4 * NR_CPUS
Maheshkumar Sivasubramaniana012e092011-08-18 10:13:03 -0600310
Murali Nalajala93f29992012-03-21 15:59:27 +0530311 .globl target_type
312target_type:
313 .long 0x0
314
Murali Nalajala73c13332012-05-15 11:30:59 +0530315 .globl apps_power_collapse
316apps_power_collapse:
317 .long 0x0
318
319 .globl l2x0_base_addr
320l2x0_base_addr:
321 .long 0x0
322
Maheshkumar Sivasubramaniana012e092011-08-18 10:13:03 -0600323/*
324 * Default the l2 flush flag to 1 so that caches are flushed during power
325 * collapse unless the L2 driver decides to flush them only during L2
326 * Power collapse.
327 */
328msm_pm_flush_l2_flag:
329 .long 0x1
Murali Nalajala73c13332012-05-15 11:30:59 +0530330
331/*
332 * Save & restore l2x0 registers while system is entering and resuming
333 * from Power Collapse.
334 * 1. aux_ctrl_save (0x0)
335 * 2. data_latency_ctrl (0x4)
336 * 3. prefetch control (0x8)
337 */
338l2x0_saved_ctrl_reg_val:
339 .space 4 * 3