1 /*
2  * SMP support for R-Mobile / SH-Mobile - sh73a0 portion
3  *
4  * Copyright (C) 2010  Magnus Damm
5  * Copyright (C) 2010  Takashi Yoshii
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 as published by
9  * the Free Software Foundation; version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/smp.h>
23 #include <linux/io.h>
24 #include <linux/delay.h>
25 #include <mach/common.h>
26 #include <mach/sh73a0.h>
27 #include <asm/smp_plat.h>
28 #include <asm/smp_twd.h>
29 
30 #define WUPCR		IOMEM(0xe6151010)
31 #define SRESCR		IOMEM(0xe6151018)
32 #define PSTR		IOMEM(0xe6151040)
33 #define SBAR		IOMEM(0xe6180020)
34 #define APARMBAREA	IOMEM(0xe6f10020)
35 
36 #define SH73A0_SCU_BASE 0xf0000000
37 
38 #ifdef CONFIG_HAVE_ARM_TWD
39 static DEFINE_TWD_LOCAL_TIMER(twd_local_timer, SH73A0_SCU_BASE + 0x600, 29);
40 void __init sh73a0_register_twd(void)
41 {
42 	twd_local_timer_register(&twd_local_timer);
43 }
44 #endif
45 
46 static int sh73a0_boot_secondary(unsigned int cpu, struct task_struct *idle)
47 {
48 	unsigned int lcpu = cpu_logical_map(cpu);
49 	int ret;
50 
51 	ret = shmobile_smp_scu_boot_secondary(cpu, idle);
52 	if (ret)
53 		return ret;
54 
55 	if (((__raw_readl(PSTR) >> (4 * lcpu)) & 3) == 3)
56 		__raw_writel(1 << lcpu, WUPCR);	/* wake up */
57 	else
58 		__raw_writel(1 << lcpu, SRESCR);	/* reset */
59 
60 	return 0;
61 }
62 
63 static void __init sh73a0_smp_prepare_cpus(unsigned int max_cpus)
64 {
65 	/* Map the reset vector (in headsmp.S) */
66 	__raw_writel(0, APARMBAREA);      /* 4k */
67 	__raw_writel(__pa(shmobile_boot_vector), SBAR);
68 
69 	/* setup sh73a0 specific SCU bits */
70 	shmobile_scu_base = IOMEM(SH73A0_SCU_BASE);
71 	shmobile_smp_scu_prepare_cpus(max_cpus);
72 }
73 
74 #ifdef CONFIG_HOTPLUG_CPU
75 static int sh73a0_cpu_disable(unsigned int cpu)
76 {
77 	return 0; /* CPU0 and CPU1 supported */
78 }
79 #endif /* CONFIG_HOTPLUG_CPU */
80 
81 struct smp_operations sh73a0_smp_ops __initdata = {
82 	.smp_prepare_cpus	= sh73a0_smp_prepare_cpus,
83 	.smp_boot_secondary	= sh73a0_boot_secondary,
84 #ifdef CONFIG_HOTPLUG_CPU
85 	.cpu_disable		= sh73a0_cpu_disable,
86 	.cpu_die		= shmobile_smp_scu_cpu_die,
87 	.cpu_kill		= shmobile_smp_scu_cpu_kill,
88 #endif
89 };
90