leds: gpio: Support the "panic-indicator" firmware property
[linux-2.6-block.git] / arch / sh / kernel / cpu / sh4a / smp-shx3.c
CommitLineData
1a442fe0
PM
1/*
2 * SH-X3 SMP
3 *
3366e358 4 * Copyright (C) 2007 - 2010 Paul Mundt
1a442fe0
PM
5 * Copyright (C) 2007 Magnus Damm
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11#include <linux/init.h>
e7dc951e 12#include <linux/kernel.h>
1a442fe0
PM
13#include <linux/cpumask.h>
14#include <linux/smp.h>
15#include <linux/interrupt.h>
16#include <linux/io.h>
e7dc951e
PM
17#include <linux/sched.h>
18#include <linux/delay.h>
19#include <linux/cpu.h>
20#include <asm/sections.h>
1a442fe0 21
94eab0bb
PM
22#define STBCR_REG(phys_id) (0xfe400004 | (phys_id << 12))
23#define RESET_REG(phys_id) (0xfe400008 | (phys_id << 12))
24
25#define STBCR_MSTP 0x00000001
26#define STBCR_RESET 0x00000002
e7dc951e 27#define STBCR_SLEEP 0x00000004
94eab0bb
PM
28#define STBCR_LTSLP 0x80000000
29
c7936b9a
PM
30static irqreturn_t ipi_interrupt_handler(int irq, void *arg)
31{
32 unsigned int message = (unsigned int)(long)arg;
33 unsigned int cpu = hard_smp_processor_id();
34 unsigned int offs = 4 * cpu;
35 unsigned int x;
36
94eab0bb 37 x = __raw_readl(0xfe410070 + offs); /* C0INITICI..CnINTICI */
c7936b9a 38 x &= (1 << (message << 2));
94eab0bb 39 __raw_writel(x, 0xfe410080 + offs); /* C0INTICICLR..CnINTICICLR */
c7936b9a
PM
40
41 smp_message_recv(message);
42
43 return IRQ_HANDLED;
44}
45
3366e358 46static void shx3_smp_setup(void)
1a442fe0
PM
47{
48 unsigned int cpu = 0;
49 int i, num;
50
e09377ba 51 init_cpu_possible(cpumask_of(cpu));
1a442fe0 52
94eab0bb
PM
53 /* Enable light sleep for the boot CPU */
54 __raw_writel(__raw_readl(STBCR_REG(cpu)) | STBCR_LTSLP, STBCR_REG(cpu));
55
1a442fe0
PM
56 __cpu_number_map[0] = 0;
57 __cpu_logical_map[0] = 0;
58
59 /*
60 * Do this stupidly for now.. we don't have an easy way to probe
61 * for the total number of cores.
62 */
63 for (i = 1, num = 0; i < NR_CPUS; i++) {
e09377ba 64 set_cpu_possible(i, true);
1a442fe0
PM
65 __cpu_number_map[i] = ++num;
66 __cpu_logical_map[num] = i;
67 }
68
69 printk(KERN_INFO "Detected %i available secondary CPU(s)\n", num);
70}
71
3366e358 72static void shx3_prepare_cpus(unsigned int max_cpus)
1a442fe0 73{
c7936b9a
PM
74 int i;
75
fc6191dd
PM
76 local_timer_setup(0);
77
c7936b9a
PM
78 BUILD_BUG_ON(SMP_MSG_NR >= 8);
79
80 for (i = 0; i < SMP_MSG_NR; i++)
fecf066c 81 request_irq(104 + i, ipi_interrupt_handler,
d11584a0 82 IRQF_PERCPU, "IPI", (void *)(long)i);
7acb59eb
PM
83
84 for (i = 0; i < max_cpus; i++)
85 set_cpu_present(i, true);
1a442fe0
PM
86}
87
3366e358 88static void shx3_start_cpu(unsigned int cpu, unsigned long entry_point)
1a442fe0 89{
f0cb7737
PM
90 if (__in_29bit_mode())
91 __raw_writel(entry_point, RESET_REG(cpu));
92 else
93 __raw_writel(virt_to_phys(entry_point), RESET_REG(cpu));
1a442fe0 94
94eab0bb
PM
95 if (!(__raw_readl(STBCR_REG(cpu)) & STBCR_MSTP))
96 __raw_writel(STBCR_MSTP, STBCR_REG(cpu));
1a442fe0 97
94eab0bb 98 while (!(__raw_readl(STBCR_REG(cpu)) & STBCR_MSTP))
71f0bdca 99 cpu_relax();
1a442fe0
PM
100
101 /* Start up secondary processor by sending a reset */
94eab0bb 102 __raw_writel(STBCR_RESET | STBCR_LTSLP, STBCR_REG(cpu));
1a442fe0
PM
103}
104
3366e358 105static unsigned int shx3_smp_processor_id(void)
1a442fe0 106{
94eab0bb 107 return __raw_readl(0xff000048); /* CPIDR */
1a442fe0
PM
108}
109
3366e358 110static void shx3_send_ipi(unsigned int cpu, unsigned int message)
1a442fe0
PM
111{
112 unsigned long addr = 0xfe410070 + (cpu * 4);
113
114 BUG_ON(cpu >= 4);
1a442fe0 115
94eab0bb 116 __raw_writel(1 << (message << 2), addr); /* C0INTICI..CnINTICI */
1a442fe0 117}
3366e358 118
e7dc951e
PM
119static void shx3_update_boot_vector(unsigned int cpu)
120{
121 __raw_writel(STBCR_MSTP, STBCR_REG(cpu));
122 while (!(__raw_readl(STBCR_REG(cpu)) & STBCR_MSTP))
123 cpu_relax();
124 __raw_writel(STBCR_RESET, STBCR_REG(cpu));
125}
126
4603f53a 127static int
e7dc951e
PM
128shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
129{
130 unsigned int cpu = (unsigned int)hcpu;
131
132 switch (action) {
133 case CPU_UP_PREPARE:
134 shx3_update_boot_vector(cpu);
135 break;
136 case CPU_ONLINE:
137 pr_info("CPU %u is now online\n", cpu);
138 break;
139 case CPU_DEAD:
140 break;
141 }
142
143 return NOTIFY_OK;
144}
145
4603f53a 146static struct notifier_block shx3_cpu_notifier = {
e7dc951e
PM
147 .notifier_call = shx3_cpu_callback,
148};
149
4603f53a 150static int register_shx3_cpu_notifier(void)
e7dc951e
PM
151{
152 register_hotcpu_notifier(&shx3_cpu_notifier);
153 return 0;
154}
155late_initcall(register_shx3_cpu_notifier);
156
3366e358
PM
157struct plat_smp_ops shx3_smp_ops = {
158 .smp_setup = shx3_smp_setup,
159 .prepare_cpus = shx3_prepare_cpus,
160 .start_cpu = shx3_start_cpu,
161 .smp_processor_id = shx3_smp_processor_id,
162 .send_ipi = shx3_send_ipi,
e7dc951e
PM
163 .cpu_die = native_cpu_die,
164 .cpu_disable = native_cpu_disable,
165 .play_dead = native_play_dead,
3366e358 166};