7a0c066df686a83eec8e9c5309e60a35b0145ee8
[cascardo/linux.git] / arch / arm / mach-shmobile / platsmp-scu.c
1 /*
2  * SMP support for SoCs with SCU covered by mach-shmobile
3  *
4  * Copyright (C) 2013  Magnus Damm
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10 #include <linux/delay.h>
11 #include <linux/init.h>
12 #include <linux/io.h>
13 #include <linux/smp.h>
14 #include <asm/cacheflush.h>
15 #include <asm/smp_plat.h>
16 #include <asm/smp_scu.h>
17 #include <mach/common.h>
18
19 void __init shmobile_smp_scu_prepare_cpus(unsigned int max_cpus)
20 {
21         shmobile_boot_fn = virt_to_phys(shmobile_boot_scu);
22         shmobile_boot_arg = (unsigned long)shmobile_scu_base;
23
24         /* enable SCU and cache coherency on booting CPU */
25         scu_enable(shmobile_scu_base);
26         scu_power_mode(shmobile_scu_base, SCU_PM_NORMAL);
27 }
28
29 int shmobile_smp_scu_boot_secondary(unsigned int cpu, struct task_struct *idle)
30 {
31         /* do nothing for now */
32         return 0;
33 }
34
35 #ifdef CONFIG_HOTPLUG_CPU
36 void shmobile_smp_scu_cpu_die(unsigned int cpu)
37 {
38         dsb();
39         flush_cache_all();
40
41         /* disable cache coherency */
42         scu_power_mode(shmobile_scu_base, SCU_PM_POWEROFF);
43
44         /* Endless loop until reset */
45         while (1)
46                 cpu_do_idle();
47 }
48
49 static int shmobile_smp_scu_psr_core_disabled(int cpu)
50 {
51         unsigned long mask = SCU_PM_POWEROFF << (cpu * 8);
52
53         if ((__raw_readl(shmobile_scu_base + 8) & mask) == mask)
54                 return 1;
55
56         return 0;
57 }
58
59 int shmobile_smp_scu_cpu_kill(unsigned int cpu)
60 {
61         int k;
62
63         /* this function is running on another CPU than the offline target,
64          * here we need wait for shutdown code in platform_cpu_die() to
65          * finish before asking SoC-specific code to power off the CPU core.
66          */
67         for (k = 0; k < 1000; k++) {
68                 if (shmobile_smp_scu_psr_core_disabled(cpu))
69                         return 1;
70
71                 mdelay(1);
72         }
73
74         return 0;
75 }
76 #endif