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