]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/arm/mach-shmobile/platsmp-scu.c
Merge remote-tracking branch 'nfs/linux-next'
[karo-tx-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/cpu.h>
11 #include <linux/delay.h>
12 #include <linux/init.h>
13 #include <linux/io.h>
14 #include <linux/smp.h>
15 #include <asm/cacheflush.h>
16 #include <asm/smp_plat.h>
17 #include <asm/smp_scu.h>
18 #include "common.h"
19
20
21 static phys_addr_t shmobile_scu_base_phys;
22 static void __iomem *shmobile_scu_base;
23
24 static int shmobile_smp_scu_notifier_call(struct notifier_block *nfb,
25                                           unsigned long action, void *hcpu)
26 {
27         unsigned int cpu = (long)hcpu;
28
29         switch (action) {
30         case CPU_UP_PREPARE:
31                 /* For this particular CPU register SCU SMP boot vector */
32                 shmobile_smp_hook(cpu, virt_to_phys(shmobile_boot_scu),
33                                   shmobile_scu_base_phys);
34                 break;
35         };
36
37         return NOTIFY_OK;
38 }
39
40 static struct notifier_block shmobile_smp_scu_notifier = {
41         .notifier_call = shmobile_smp_scu_notifier_call,
42 };
43
44 void __init shmobile_smp_scu_prepare_cpus(phys_addr_t scu_base_phys,
45                                           unsigned int max_cpus)
46 {
47         /* install boot code shared by all CPUs */
48         shmobile_boot_fn = virt_to_phys(shmobile_smp_boot);
49         shmobile_boot_arg = MPIDR_HWID_BITMASK;
50
51         /* enable SCU and cache coherency on booting CPU */
52         shmobile_scu_base_phys = scu_base_phys;
53         shmobile_scu_base = ioremap(scu_base_phys, PAGE_SIZE);
54         scu_enable(shmobile_scu_base);
55         scu_power_mode(shmobile_scu_base, SCU_PM_NORMAL);
56
57         /* Use CPU notifier for reset vector control */
58         register_cpu_notifier(&shmobile_smp_scu_notifier);
59 }
60
61 #ifdef CONFIG_HOTPLUG_CPU
62 void shmobile_smp_scu_cpu_die(unsigned int cpu)
63 {
64         /* For this particular CPU deregister boot vector */
65         shmobile_smp_hook(cpu, 0, 0);
66
67         dsb();
68         flush_cache_all();
69
70         /* disable cache coherency */
71         scu_power_mode(shmobile_scu_base, SCU_PM_POWEROFF);
72
73         /* jump to shared mach-shmobile sleep / reset code */
74         shmobile_smp_sleep();
75 }
76
77 static int shmobile_smp_scu_psr_core_disabled(int cpu)
78 {
79         unsigned long mask = SCU_PM_POWEROFF << (cpu * 8);
80
81         if ((__raw_readl(shmobile_scu_base + 8) & mask) == mask)
82                 return 1;
83
84         return 0;
85 }
86
87 int shmobile_smp_scu_cpu_kill(unsigned int cpu)
88 {
89         int k;
90
91         /* this function is running on another CPU than the offline target,
92          * here we need wait for shutdown code in platform_cpu_die() to
93          * finish before asking SoC-specific code to power off the CPU core.
94          */
95         for (k = 0; k < 1000; k++) {
96                 if (shmobile_smp_scu_psr_core_disabled(cpu))
97                         return 1;
98
99                 mdelay(1);
100         }
101
102         return 0;
103 }
104 #endif