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