Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Freescale Semiconductor, Inc. |
| 3 | * Copyright 2011 Linaro Ltd. |
| 4 | * |
| 5 | * The code contained herein is licensed under the GNU General Public |
| 6 | * License. You may obtain a copy of the GNU General Public License |
| 7 | * Version 2 or later at the following locations: |
| 8 | * |
| 9 | * http://www.opensource.org/licenses/gpl-license.html |
| 10 | * http://www.gnu.org/copyleft/gpl.html |
| 11 | */ |
| 12 | |
| 13 | #include <linux/errno.h> |
Shawn Guo | 009e63f | 2013-05-08 21:05:53 +0800 | [diff] [blame] | 14 | #include <linux/jiffies.h> |
Shawn Guo | 602bf40 | 2012-05-22 22:13:46 +0800 | [diff] [blame] | 15 | #include <asm/cp15.h> |
Shawn Guo | 009e63f | 2013-05-08 21:05:53 +0800 | [diff] [blame] | 16 | #include <asm/proc-fns.h> |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 17 | |
| 18 | #include "common.h" |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 19 | |
Shawn Guo | 602bf40 | 2012-05-22 22:13:46 +0800 | [diff] [blame] | 20 | static inline void cpu_enter_lowpower(void) |
| 21 | { |
| 22 | unsigned int v; |
| 23 | |
Shawn Guo | 602bf40 | 2012-05-22 22:13:46 +0800 | [diff] [blame] | 24 | asm volatile( |
| 25 | "mcr p15, 0, %1, c7, c5, 0\n" |
| 26 | " mcr p15, 0, %1, c7, c10, 4\n" |
| 27 | /* |
| 28 | * Turn off coherency |
| 29 | */ |
| 30 | " mrc p15, 0, %0, c1, c0, 1\n" |
| 31 | " bic %0, %0, %3\n" |
| 32 | " mcr p15, 0, %0, c1, c0, 1\n" |
| 33 | " mrc p15, 0, %0, c1, c0, 0\n" |
| 34 | " bic %0, %0, %2\n" |
| 35 | " mcr p15, 0, %0, c1, c0, 0\n" |
| 36 | : "=&r" (v) |
| 37 | : "r" (0), "Ir" (CR_C), "Ir" (0x40) |
| 38 | : "cc"); |
| 39 | } |
| 40 | |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 41 | /* |
| 42 | * platform-specific code to shutdown a CPU |
| 43 | * |
| 44 | * Called with IRQs disabled |
| 45 | */ |
Marc Zyngier | e4f2d97 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 46 | void imx_cpu_die(unsigned int cpu) |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 47 | { |
Shawn Guo | 602bf40 | 2012-05-22 22:13:46 +0800 | [diff] [blame] | 48 | cpu_enter_lowpower(); |
Shawn Guo | 2f3edfd | 2013-03-26 16:46:07 +0800 | [diff] [blame] | 49 | /* |
| 50 | * We use the cpu jumping argument register to sync with |
| 51 | * imx_cpu_kill() which is running on cpu0 and waiting for |
| 52 | * the register being cleared to kill the cpu. |
| 53 | */ |
| 54 | imx_set_cpu_arg(cpu, ~0); |
Shawn Guo | fcd75f9 | 2013-10-09 15:29:14 +0800 | [diff] [blame] | 55 | |
| 56 | while (1) |
| 57 | cpu_do_idle(); |
Shawn Guo | 8375766 | 2013-01-14 14:08:50 +0800 | [diff] [blame] | 58 | } |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 59 | |
Shawn Guo | 8375766 | 2013-01-14 14:08:50 +0800 | [diff] [blame] | 60 | int imx_cpu_kill(unsigned int cpu) |
| 61 | { |
Shawn Guo | 2f3edfd | 2013-03-26 16:46:07 +0800 | [diff] [blame] | 62 | unsigned long timeout = jiffies + msecs_to_jiffies(50); |
| 63 | |
| 64 | while (imx_get_cpu_arg(cpu) == 0) |
| 65 | if (time_after(jiffies, timeout)) |
| 66 | return 0; |
Shawn Guo | 8375766 | 2013-01-14 14:08:50 +0800 | [diff] [blame] | 67 | imx_enable_cpu(cpu, false); |
Shawn Guo | 2f3edfd | 2013-03-26 16:46:07 +0800 | [diff] [blame] | 68 | imx_set_cpu_arg(cpu, 0); |
Shawn Guo | 8375766 | 2013-01-14 14:08:50 +0800 | [diff] [blame] | 69 | return 1; |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 70 | } |