blob: 24bfb6534c21bcbd51abd421dcbe5c88e9205169 [file] [log] [blame]
Colin Cross1cea7322010-02-21 17:46:23 -08001/*
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>
Russell King0f7b3322011-04-03 13:01:30 +010023#include <asm/hardware/gic.h>
Colin Cross1cea7322010-02-21 17:46:23 -080024#include <asm/mach-types.h>
Colin Cross1cea7322010-02-21 17:46:23 -080025#include <asm/smp_scu.h>
26
Peter De Schrijver86e51a22012-02-10 01:47:50 +020027#include <mach/clk.h>
Colin Cross1cea7322010-02-21 17:46:23 -080028#include <mach/iomap.h>
Peter De Schrijver86e51a22012-02-10 01:47:50 +020029#include <mach/powergate.h>
Colin Cross1cea7322010-02-21 17:46:23 -080030
Peter De Schrijverb36ab972012-02-10 01:47:45 +020031#include "fuse.h"
32#include "flowctrl.h"
33#include "reset.h"
34
Marc Zyngiera1725732011-09-08 13:15:22 +010035#include "common.h"
36
Colin Cross1cea7322010-02-21 17:46:23 -080037extern void tegra_secondary_startup(void);
38
Colin Cross1cea7322010-02-21 17:46:23 -080039static void __iomem *scu_base = IO_ADDRESS(TEGRA_ARM_PERIF_BASE);
40
41#define EVP_CPU_RESET_VECTOR \
42 (IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + 0x100)
43#define CLK_RST_CONTROLLER_CLK_CPU_CMPLX \
44 (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x4c)
Peter De Schrijverb36ab972012-02-10 01:47:45 +020045#define CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET \
46 (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x340)
Colin Cross1cea7322010-02-21 17:46:23 -080047#define CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR \
48 (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x344)
Peter De Schrijver86e51a22012-02-10 01:47:50 +020049#define CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR \
50 (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x34c)
Colin Cross1cea7322010-02-21 17:46:23 -080051
Peter De Schrijverb36ab972012-02-10 01:47:45 +020052#define CPU_CLOCK(cpu) (0x1<<(8+cpu))
53#define CPU_RESET(cpu) (0x1111ul<<(cpu))
54
Marc Zyngiera1725732011-09-08 13:15:22 +010055static void __cpuinit tegra_secondary_init(unsigned int cpu)
Colin Cross1cea7322010-02-21 17:46:23 -080056{
Colin Cross1cea7322010-02-21 17:46:23 -080057 /*
58 * if any interrupts are already enabled for the primary
59 * core (e.g. timer irq), then they will not have been enabled
60 * for us: do so
61 */
Russell King38489532010-12-04 16:01:03 +000062 gic_secondary_init(0);
Colin Cross1cea7322010-02-21 17:46:23 -080063
Peter De Schrijverb36ab972012-02-10 01:47:45 +020064}
65
66static int tegra20_power_up_cpu(unsigned int cpu)
67{
68 u32 reg;
69
70 /* Enable the CPU clock. */
71 reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
72 writel(reg & ~CPU_CLOCK(cpu), CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
73 barrier();
74 reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
75
76 /* Clear flow controller CSR. */
77 flowctrl_write_cpu_csr(cpu, 0);
78
79 return 0;
Colin Cross1cea7322010-02-21 17:46:23 -080080}
81
Peter De Schrijver86e51a22012-02-10 01:47:50 +020082static int tegra30_power_up_cpu(unsigned int cpu)
83{
84 u32 reg;
85 int ret, pwrgateid;
86 unsigned long timeout;
87
88 pwrgateid = tegra_cpu_powergate_id(cpu);
89 if (pwrgateid < 0)
90 return pwrgateid;
91
92 /* If this is the first boot, toggle powergates directly. */
93 if (!tegra_powergate_is_powered(pwrgateid)) {
94 ret = tegra_powergate_power_on(pwrgateid);
95 if (ret)
96 return ret;
97
98 /* Wait for the power to come up. */
99 timeout = jiffies + 10*HZ;
100 while (tegra_powergate_is_powered(pwrgateid)) {
101 if (time_after(jiffies, timeout))
102 return -ETIMEDOUT;
103 udelay(10);
104 }
105 }
106
107 /* CPU partition is powered. Enable the CPU clock. */
108 writel(CPU_CLOCK(cpu), CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR);
109 reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR);
110 udelay(10);
111
112 /* Remove I/O clamps. */
113 ret = tegra_powergate_remove_clamping(pwrgateid);
114 udelay(10);
115
116 /* Clear flow controller CSR. */
117 flowctrl_write_cpu_csr(cpu, 0);
118
119 return 0;
120}
121
Marc Zyngiera1725732011-09-08 13:15:22 +0100122static int __cpuinit tegra_boot_secondary(unsigned int cpu, struct task_struct *idle)
Colin Cross1cea7322010-02-21 17:46:23 -0800123{
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200124 int status;
125
Peter De Schrijver86e51a22012-02-10 01:47:50 +0200126 /*
127 * Force the CPU into reset. The CPU must remain in reset when the
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200128 * flow controller state is cleared (which will cause the flow
129 * controller to stop driving reset if the CPU has been power-gated
130 * via the flow controller). This will have no effect on first boot
131 * of the CPU since it should already be in reset.
132 */
133 writel(CPU_RESET(cpu), CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET);
134 dmb();
Colin Cross1cea7322010-02-21 17:46:23 -0800135
136 /*
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200137 * Unhalt the CPU. If the flow controller was used to power-gate the
138 * CPU this will cause the flow controller to stop driving reset.
139 * The CPU will remain in reset because the clock and reset block
140 * is now driving reset.
Colin Cross1cea7322010-02-21 17:46:23 -0800141 */
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200142 flowctrl_write_cpu_halt(cpu, 0);
Colin Cross1cea7322010-02-21 17:46:23 -0800143
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200144 switch (tegra_chip_id) {
145 case TEGRA20:
146 status = tegra20_power_up_cpu(cpu);
147 break;
Peter De Schrijver86e51a22012-02-10 01:47:50 +0200148 case TEGRA30:
149 status = tegra30_power_up_cpu(cpu);
150 break;
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200151 default:
152 status = -EINVAL;
153 break;
Colin Cross1cea7322010-02-21 17:46:23 -0800154 }
155
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200156 if (status)
157 goto done;
Colin Cross1cea7322010-02-21 17:46:23 -0800158
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200159 /* Take the CPU out of reset. */
160 writel(CPU_RESET(cpu), CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR);
161 wmb();
162done:
163 return status;
Colin Cross1cea7322010-02-21 17:46:23 -0800164}
165
166/*
167 * Initialise the CPU possible map early - this describes the CPUs
168 * which may be present or become present in the system.
169 */
Marc Zyngiera1725732011-09-08 13:15:22 +0100170static void __init tegra_smp_init_cpus(void)
Colin Cross1cea7322010-02-21 17:46:23 -0800171{
172 unsigned int i, ncores = scu_get_core_count(scu_base);
173
Russell Kinga06f9162011-10-20 22:04:18 +0100174 if (ncores > nr_cpu_ids) {
175 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
176 ncores, nr_cpu_ids);
177 ncores = nr_cpu_ids;
Russell King8975b6c2010-12-03 19:29:53 +0000178 }
179
Colin Cross1cea7322010-02-21 17:46:23 -0800180 for (i = 0; i < ncores; i++)
KOSAKI Motohiro24fe4322011-06-23 17:28:28 +0900181 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100182
183 set_smp_cross_call(gic_raise_softirq);
Colin Cross1cea7322010-02-21 17:46:23 -0800184}
185
Marc Zyngiera1725732011-09-08 13:15:22 +0100186static void __init tegra_smp_prepare_cpus(unsigned int max_cpus)
Colin Cross1cea7322010-02-21 17:46:23 -0800187{
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200188 tegra_cpu_reset_handler_init();
Russell King05c74a62010-12-03 11:09:48 +0000189 scu_enable(scu_base);
Colin Cross1cea7322010-02-21 17:46:23 -0800190}
Marc Zyngiera1725732011-09-08 13:15:22 +0100191
192struct smp_operations tegra_smp_ops __initdata = {
193 .smp_init_cpus = tegra_smp_init_cpus,
194 .smp_prepare_cpus = tegra_smp_prepare_cpus,
195 .smp_secondary_init = tegra_secondary_init,
196 .smp_boot_secondary = tegra_boot_secondary,
197#ifdef CONFIG_HOTPLUG_CPU
198 .cpu_die = tegra_cpu_die,
199#endif
200};