]> Pileus Git - ~andy/linux/blob - arch/arm/mach-tegra/platsmp.c
irqchip: gic: Perform the gic_secondary_init() call via CPU notifier
[~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 #include <linux/clk/tegra.h>
22
23 #include <asm/cacheflush.h>
24 #include <asm/mach-types.h>
25 #include <asm/smp_scu.h>
26 #include <asm/smp_plat.h>
27
28 #include <mach/powergate.h>
29
30 #include "fuse.h"
31 #include "flowctrl.h"
32 #include "reset.h"
33
34 #include "common.h"
35 #include "iomap.h"
36
37 extern void tegra_secondary_startup(void);
38
39 static cpumask_t tegra_cpu_init_mask;
40
41 #define EVP_CPU_RESET_VECTOR \
42         (IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + 0x100)
43
44 static void __cpuinit tegra_secondary_init(unsigned int cpu)
45 {
46         cpumask_set_cpu(cpu, &tegra_cpu_init_mask);
47 }
48
49 static int tegra20_power_up_cpu(unsigned int cpu)
50 {
51         /* Enable the CPU clock. */
52         tegra_enable_cpu_clock(cpu);
53
54         /* Clear flow controller CSR. */
55         flowctrl_write_cpu_csr(cpu, 0);
56
57         return 0;
58 }
59
60 static int tegra30_power_up_cpu(unsigned int cpu)
61 {
62         int ret, pwrgateid;
63         unsigned long timeout;
64
65         pwrgateid = tegra_cpu_powergate_id(cpu);
66         if (pwrgateid < 0)
67                 return pwrgateid;
68
69         /*
70          * The power up sequence of cold boot CPU and warm boot CPU
71          * was different.
72          *
73          * For warm boot CPU that was resumed from CPU hotplug, the
74          * power will be resumed automatically after un-halting the
75          * flow controller of the warm boot CPU. We need to wait for
76          * the confirmaiton that the CPU is powered then removing
77          * the IO clamps.
78          * For cold boot CPU, do not wait. After the cold boot CPU be
79          * booted, it will run to tegra_secondary_init() and set
80          * tegra_cpu_init_mask which influences what tegra30_power_up_cpu()
81          * next time around.
82          */
83         if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
84                 timeout = jiffies + msecs_to_jiffies(50);
85                 do {
86                         if (!tegra_powergate_is_powered(pwrgateid))
87                                 goto remove_clamps;
88                         udelay(10);
89                 } while (time_before(jiffies, timeout));
90         }
91
92         /*
93          * The power status of the cold boot CPU is power gated as
94          * default. To power up the cold boot CPU, the power should
95          * be un-gated by un-toggling the power gate register
96          * manually.
97          */
98         if (!tegra_powergate_is_powered(pwrgateid)) {
99                 ret = tegra_powergate_power_on(pwrgateid);
100                 if (ret)
101                         return ret;
102
103                 /* Wait for the power to come up. */
104                 timeout = jiffies + msecs_to_jiffies(100);
105                 while (tegra_powergate_is_powered(pwrgateid)) {
106                         if (time_after(jiffies, timeout))
107                                 return -ETIMEDOUT;
108                         udelay(10);
109                 }
110         }
111
112 remove_clamps:
113         /* CPU partition is powered. Enable the CPU clock. */
114         tegra_enable_cpu_clock(cpu);
115         udelay(10);
116
117         /* Remove I/O clamps. */
118         ret = tegra_powergate_remove_clamping(pwrgateid);
119         udelay(10);
120
121         /* Clear flow controller CSR. */
122         flowctrl_write_cpu_csr(cpu, 0);
123
124         return 0;
125 }
126
127 static int __cpuinit tegra_boot_secondary(unsigned int cpu, struct task_struct *idle)
128 {
129         int status;
130
131         cpu = cpu_logical_map(cpu);
132
133         /*
134          * Force the CPU into reset. The CPU must remain in reset when the
135          * flow controller state is cleared (which will cause the flow
136          * controller to stop driving reset if the CPU has been power-gated
137          * via the flow controller). This will have no effect on first boot
138          * of the CPU since it should already be in reset.
139          */
140         tegra_put_cpu_in_reset(cpu);
141
142         /*
143          * Unhalt the CPU. If the flow controller was used to power-gate the
144          * CPU this will cause the flow controller to stop driving reset.
145          * The CPU will remain in reset because the clock and reset block
146          * is now driving reset.
147          */
148         flowctrl_write_cpu_halt(cpu, 0);
149
150         switch (tegra_chip_id) {
151         case TEGRA20:
152                 status = tegra20_power_up_cpu(cpu);
153                 break;
154         case TEGRA30:
155                 status = tegra30_power_up_cpu(cpu);
156                 break;
157         default:
158                 status = -EINVAL;
159                 break;
160         }
161
162         if (status)
163                 goto done;
164
165         /* Take the CPU out of reset. */
166         tegra_cpu_out_of_reset(cpu);
167 done:
168         return status;
169 }
170
171 static void __init tegra_smp_prepare_cpus(unsigned int max_cpus)
172 {
173         /* Always mark the boot CPU (CPU0) as initialized. */
174         cpumask_set_cpu(0, &tegra_cpu_init_mask);
175
176         if (scu_a9_has_base())
177                 scu_enable(IO_ADDRESS(scu_a9_get_base()));
178 }
179
180 struct smp_operations tegra_smp_ops __initdata = {
181         .smp_prepare_cpus       = tegra_smp_prepare_cpus,
182         .smp_secondary_init     = tegra_secondary_init,
183         .smp_boot_secondary     = tegra_boot_secondary,
184 #ifdef CONFIG_HOTPLUG_CPU
185         .cpu_kill               = tegra_cpu_kill,
186         .cpu_die                = tegra_cpu_die,
187         .cpu_disable            = tegra_cpu_disable,
188 #endif
189 };