Merge remote-tracking branches 'regulator/fix/as3722', 'regulator/fix/ltc3589' and...
[cascardo/linux.git] / arch / arm / mach-exynos / hotplug.c
1 /* linux arch/arm/mach-exynos4/hotplug.c
2  *
3  *  Cloned from linux/arch/arm/mach-realview/hotplug.c
4  *
5  *  Copyright (C) 2002 ARM Ltd.
6  *  All Rights Reserved
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11 */
12
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/smp.h>
16 #include <linux/io.h>
17
18 #include <asm/cacheflush.h>
19 #include <asm/cp15.h>
20 #include <asm/smp_plat.h>
21
22 #include "common.h"
23 #include "regs-pmu.h"
24
25 static inline void cpu_leave_lowpower(void)
26 {
27         unsigned int v;
28
29         asm volatile(
30         "mrc    p15, 0, %0, c1, c0, 0\n"
31         "       orr     %0, %0, %1\n"
32         "       mcr     p15, 0, %0, c1, c0, 0\n"
33         "       mrc     p15, 0, %0, c1, c0, 1\n"
34         "       orr     %0, %0, %2\n"
35         "       mcr     p15, 0, %0, c1, c0, 1\n"
36           : "=&r" (v)
37           : "Ir" (CR_C), "Ir" (0x40)
38           : "cc");
39 }
40
41 static inline void platform_do_lowpower(unsigned int cpu, int *spurious)
42 {
43         for (;;) {
44
45                 /* make cpu1 to be turned off at next WFI command */
46                 if (cpu == 1)
47                         exynos_cpu_power_down(cpu);
48
49                 /*
50                  * here's the WFI
51                  */
52                 asm(".word      0xe320f003\n"
53                     :
54                     :
55                     : "memory", "cc");
56
57                 if (pen_release == cpu_logical_map(cpu)) {
58                         /*
59                          * OK, proper wakeup, we're done
60                          */
61                         break;
62                 }
63
64                 /*
65                  * Getting here, means that we have come out of WFI without
66                  * having been woken up - this shouldn't happen
67                  *
68                  * Just note it happening - when we're woken, we can report
69                  * its occurrence.
70                  */
71                 (*spurious)++;
72         }
73 }
74
75 /*
76  * platform-specific code to shutdown a CPU
77  *
78  * Called with IRQs disabled
79  */
80 void __ref exynos_cpu_die(unsigned int cpu)
81 {
82         int spurious = 0;
83
84         v7_exit_coherency_flush(louis);
85
86         platform_do_lowpower(cpu, &spurious);
87
88         /*
89          * bring this CPU back into the world of cache
90          * coherency, and then restore interrupts
91          */
92         cpu_leave_lowpower();
93
94         if (spurious)
95                 pr_warn("CPU%u: %u spurious wakeup calls\n", cpu, spurious);
96 }