]> Pileus Git - ~andy/linux/blob - arch/arm/mach-tegra/platsmp.c
ARM: tegra: rework Tegra secondary CPU core bringup
[~andy/linux] / arch / arm / mach-tegra / platsmp.c
1 /*
2  *  linux/arch/arm/mach-tegra/platsmp.c
3  *
4  *  Copyright (C) 2002 ARM Ltd.
5  *  All Rights Reserved
6  *
7  *  Copyright (C) 2009 Palm
8  *  All Rights Reserved
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  */
14 #include <linux/init.h>
15 #include <linux/errno.h>
16 #include <linux/delay.h>
17 #include <linux/device.h>
18 #include <linux/jiffies.h>
19 #include <linux/smp.h>
20 #include <linux/io.h>
21
22 #include <asm/cacheflush.h>
23 #include <asm/hardware/gic.h>
24 #include <asm/mach-types.h>
25 #include <asm/smp_scu.h>
26
27 #include <mach/iomap.h>
28
29 #include "fuse.h"
30 #include "flowctrl.h"
31 #include "reset.h"
32
33 extern void tegra_secondary_startup(void);
34
35 static void __iomem *scu_base = IO_ADDRESS(TEGRA_ARM_PERIF_BASE);
36
37 #define EVP_CPU_RESET_VECTOR \
38         (IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + 0x100)
39 #define CLK_RST_CONTROLLER_CLK_CPU_CMPLX \
40         (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x4c)
41 #define CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET \
42         (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x340)
43 #define CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR \
44         (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x344)
45
46 #define CPU_CLOCK(cpu)  (0x1<<(8+cpu))
47 #define CPU_RESET(cpu)  (0x1111ul<<(cpu))
48
49 void __cpuinit platform_secondary_init(unsigned int cpu)
50 {
51         /*
52          * if any interrupts are already enabled for the primary
53          * core (e.g. timer irq), then they will not have been enabled
54          * for us: do so
55          */
56         gic_secondary_init(0);
57
58 }
59
60 static int tegra20_power_up_cpu(unsigned int cpu)
61 {
62         u32 reg;
63
64         /* Enable the CPU clock. */
65         reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
66         writel(reg & ~CPU_CLOCK(cpu), CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
67         barrier();
68         reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
69
70         /* Clear flow controller CSR. */
71         flowctrl_write_cpu_csr(cpu, 0);
72
73         return 0;
74 }
75
76 int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
77 {
78         int status;
79
80         /* Force the CPU into reset. The CPU must remain in reset when the
81          * flow controller state is cleared (which will cause the flow
82          * controller to stop driving reset if the CPU has been power-gated
83          * via the flow controller). This will have no effect on first boot
84          * of the CPU since it should already be in reset.
85          */
86         writel(CPU_RESET(cpu), CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET);
87         dmb();
88
89         /*
90          * Unhalt the CPU. If the flow controller was used to power-gate the
91          * CPU this will cause the flow controller to stop driving reset.
92          * The CPU will remain in reset because the clock and reset block
93          * is now driving reset.
94          */
95         flowctrl_write_cpu_halt(cpu, 0);
96
97         switch (tegra_chip_id) {
98         case TEGRA20:
99                 status = tegra20_power_up_cpu(cpu);
100                 break;
101         default:
102                 status = -EINVAL;
103                 break;
104         }
105
106         if (status)
107                 goto done;
108
109         /* Take the CPU out of reset. */
110         writel(CPU_RESET(cpu), CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR);
111         wmb();
112 done:
113         return status;
114 }
115
116 /*
117  * Initialise the CPU possible map early - this describes the CPUs
118  * which may be present or become present in the system.
119  */
120 void __init smp_init_cpus(void)
121 {
122         unsigned int i, ncores = scu_get_core_count(scu_base);
123
124         if (ncores > nr_cpu_ids) {
125                 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
126                         ncores, nr_cpu_ids);
127                 ncores = nr_cpu_ids;
128         }
129
130         for (i = 0; i < ncores; i++)
131                 set_cpu_possible(i, true);
132
133         set_smp_cross_call(gic_raise_softirq);
134 }
135
136 void __init platform_smp_prepare_cpus(unsigned int max_cpus)
137 {
138         tegra_cpu_reset_handler_init();
139         scu_enable(scu_base);
140 }