Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 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> |
Rob Herring | 520f7bd | 2012-12-27 13:10:24 -0600 | [diff] [blame] | 21 | #include <linux/irqchip/arm-gic.h> |
Prashant Gaikwad | 89572c7 | 2013-01-11 13:16:21 +0530 | [diff] [blame] | 22 | #include <linux/clk/tegra.h> |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 23 | |
| 24 | #include <asm/cacheflush.h> |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 25 | #include <asm/mach-types.h> |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 26 | #include <asm/smp_scu.h> |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 27 | #include <asm/smp_plat.h> |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 28 | |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 29 | #include <mach/powergate.h> |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 30 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 31 | #include "fuse.h" |
| 32 | #include "flowctrl.h" |
| 33 | #include "reset.h" |
| 34 | |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 35 | #include "common.h" |
Stephen Warren | 2be39c0 | 2012-10-04 14:24:09 -0600 | [diff] [blame] | 36 | #include "iomap.h" |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 37 | |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 38 | extern void tegra_secondary_startup(void); |
| 39 | |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 40 | static cpumask_t tegra_cpu_init_mask; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 41 | |
| 42 | #define EVP_CPU_RESET_VECTOR \ |
| 43 | (IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + 0x100) |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 44 | |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 45 | static void __cpuinit tegra_secondary_init(unsigned int cpu) |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 46 | { |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 47 | /* |
| 48 | * if any interrupts are already enabled for the primary |
| 49 | * core (e.g. timer irq), then they will not have been enabled |
| 50 | * for us: do so |
| 51 | */ |
Russell King | 3848953 | 2010-12-04 16:01:03 +0000 | [diff] [blame] | 52 | gic_secondary_init(0); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 53 | |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 54 | cpumask_set_cpu(cpu, &tegra_cpu_init_mask); |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static int tegra20_power_up_cpu(unsigned int cpu) |
| 58 | { |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 59 | /* Enable the CPU clock. */ |
Joseph Lo | bb60327 | 2012-08-16 17:31:49 +0800 | [diff] [blame] | 60 | tegra_enable_cpu_clock(cpu); |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 61 | |
| 62 | /* Clear flow controller CSR. */ |
| 63 | flowctrl_write_cpu_csr(cpu, 0); |
| 64 | |
| 65 | return 0; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 68 | static int tegra30_power_up_cpu(unsigned int cpu) |
| 69 | { |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 70 | int ret, pwrgateid; |
| 71 | unsigned long timeout; |
| 72 | |
| 73 | pwrgateid = tegra_cpu_powergate_id(cpu); |
| 74 | if (pwrgateid < 0) |
| 75 | return pwrgateid; |
| 76 | |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 77 | /* |
| 78 | * The power up sequence of cold boot CPU and warm boot CPU |
| 79 | * was different. |
| 80 | * |
| 81 | * For warm boot CPU that was resumed from CPU hotplug, the |
| 82 | * power will be resumed automatically after un-halting the |
| 83 | * flow controller of the warm boot CPU. We need to wait for |
| 84 | * the confirmaiton that the CPU is powered then removing |
| 85 | * the IO clamps. |
| 86 | * For cold boot CPU, do not wait. After the cold boot CPU be |
| 87 | * booted, it will run to tegra_secondary_init() and set |
| 88 | * tegra_cpu_init_mask which influences what tegra30_power_up_cpu() |
| 89 | * next time around. |
| 90 | */ |
| 91 | if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) { |
Joseph Lo | 1395868 | 2013-01-07 10:56:14 +0800 | [diff] [blame] | 92 | timeout = jiffies + msecs_to_jiffies(50); |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 93 | do { |
| 94 | if (!tegra_powergate_is_powered(pwrgateid)) |
| 95 | goto remove_clamps; |
| 96 | udelay(10); |
| 97 | } while (time_before(jiffies, timeout)); |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * The power status of the cold boot CPU is power gated as |
| 102 | * default. To power up the cold boot CPU, the power should |
| 103 | * be un-gated by un-toggling the power gate register |
| 104 | * manually. |
| 105 | */ |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 106 | if (!tegra_powergate_is_powered(pwrgateid)) { |
| 107 | ret = tegra_powergate_power_on(pwrgateid); |
| 108 | if (ret) |
| 109 | return ret; |
| 110 | |
| 111 | /* Wait for the power to come up. */ |
Joseph Lo | 1395868 | 2013-01-07 10:56:14 +0800 | [diff] [blame] | 112 | timeout = jiffies + msecs_to_jiffies(100); |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 113 | while (tegra_powergate_is_powered(pwrgateid)) { |
| 114 | if (time_after(jiffies, timeout)) |
| 115 | return -ETIMEDOUT; |
| 116 | udelay(10); |
| 117 | } |
| 118 | } |
| 119 | |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 120 | remove_clamps: |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 121 | /* CPU partition is powered. Enable the CPU clock. */ |
Joseph Lo | bb60327 | 2012-08-16 17:31:49 +0800 | [diff] [blame] | 122 | tegra_enable_cpu_clock(cpu); |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 123 | udelay(10); |
| 124 | |
| 125 | /* Remove I/O clamps. */ |
| 126 | ret = tegra_powergate_remove_clamping(pwrgateid); |
| 127 | udelay(10); |
| 128 | |
| 129 | /* Clear flow controller CSR. */ |
| 130 | flowctrl_write_cpu_csr(cpu, 0); |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 135 | static int __cpuinit tegra_boot_secondary(unsigned int cpu, struct task_struct *idle) |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 136 | { |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 137 | int status; |
| 138 | |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 139 | cpu = cpu_logical_map(cpu); |
| 140 | |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 141 | /* |
| 142 | * Force the CPU into reset. The CPU must remain in reset when the |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 143 | * flow controller state is cleared (which will cause the flow |
| 144 | * controller to stop driving reset if the CPU has been power-gated |
| 145 | * via the flow controller). This will have no effect on first boot |
| 146 | * of the CPU since it should already be in reset. |
| 147 | */ |
Joseph Lo | bb60327 | 2012-08-16 17:31:49 +0800 | [diff] [blame] | 148 | tegra_put_cpu_in_reset(cpu); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 149 | |
| 150 | /* |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 151 | * Unhalt the CPU. If the flow controller was used to power-gate the |
| 152 | * CPU this will cause the flow controller to stop driving reset. |
| 153 | * The CPU will remain in reset because the clock and reset block |
| 154 | * is now driving reset. |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 155 | */ |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 156 | flowctrl_write_cpu_halt(cpu, 0); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 157 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 158 | switch (tegra_chip_id) { |
| 159 | case TEGRA20: |
| 160 | status = tegra20_power_up_cpu(cpu); |
| 161 | break; |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 162 | case TEGRA30: |
| 163 | status = tegra30_power_up_cpu(cpu); |
| 164 | break; |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 165 | default: |
| 166 | status = -EINVAL; |
| 167 | break; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 170 | if (status) |
| 171 | goto done; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 172 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 173 | /* Take the CPU out of reset. */ |
Joseph Lo | bb60327 | 2012-08-16 17:31:49 +0800 | [diff] [blame] | 174 | tegra_cpu_out_of_reset(cpu); |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 175 | done: |
| 176 | return status; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 179 | static void __init tegra_smp_prepare_cpus(unsigned int max_cpus) |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 180 | { |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 181 | /* Always mark the boot CPU (CPU0) as initialized. */ |
| 182 | cpumask_set_cpu(0, &tegra_cpu_init_mask); |
| 183 | |
Hiroshi Doyu | 909444a | 2013-01-22 07:52:02 +0200 | [diff] [blame] | 184 | if (scu_a9_has_base()) |
| 185 | scu_enable(IO_ADDRESS(scu_a9_get_base())); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 186 | } |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 187 | |
| 188 | struct smp_operations tegra_smp_ops __initdata = { |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 189 | .smp_prepare_cpus = tegra_smp_prepare_cpus, |
| 190 | .smp_secondary_init = tegra_secondary_init, |
| 191 | .smp_boot_secondary = tegra_boot_secondary, |
| 192 | #ifdef CONFIG_HOTPLUG_CPU |
Joseph Lo | b811943 | 2013-01-03 14:43:00 +0800 | [diff] [blame] | 193 | .cpu_kill = tegra_cpu_kill, |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 194 | .cpu_die = tegra_cpu_die, |
Olof Johansson | 25468fe | 2012-09-22 00:06:21 -0700 | [diff] [blame] | 195 | .cpu_disable = tegra_cpu_disable, |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 196 | #endif |
| 197 | }; |