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 | */ |
Thierry Reding | a0524ac | 2014-07-11 09:44:49 +0200 | [diff] [blame] | 14 | |
| 15 | #include <linux/clk/tegra.h> |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 16 | #include <linux/delay.h> |
| 17 | #include <linux/device.h> |
Thierry Reding | a0524ac | 2014-07-11 09:44:49 +0200 | [diff] [blame] | 18 | #include <linux/errno.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/io.h> |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 21 | #include <linux/jiffies.h> |
| 22 | #include <linux/smp.h> |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 23 | |
Thierry Reding | 304664e | 2014-07-11 09:52:41 +0200 | [diff] [blame] | 24 | #include <soc/tegra/fuse.h> |
Thierry Reding | 7232398 | 2014-07-11 13:19:06 +0200 | [diff] [blame] | 25 | #include <soc/tegra/pmc.h> |
Thierry Reding | 304664e | 2014-07-11 09:52:41 +0200 | [diff] [blame] | 26 | |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 27 | #include <asm/cacheflush.h> |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 28 | #include <asm/mach-types.h> |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 29 | #include <asm/smp_plat.h> |
Thierry Reding | a0524ac | 2014-07-11 09:44:49 +0200 | [diff] [blame] | 30 | #include <asm/smp_scu.h> |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 31 | |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 32 | #include "common.h" |
Thierry Reding | a0524ac | 2014-07-11 09:44:49 +0200 | [diff] [blame] | 33 | #include "flowctrl.h" |
Stephen Warren | 2be39c0 | 2012-10-04 14:24:09 -0600 | [diff] [blame] | 34 | #include "iomap.h" |
Thierry Reding | a0524ac | 2014-07-11 09:44:49 +0200 | [diff] [blame] | 35 | #include "reset.h" |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 36 | |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 37 | static cpumask_t tegra_cpu_init_mask; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 38 | |
Paul Gortmaker | 8bd26e3 | 2013-06-17 15:43:14 -0400 | [diff] [blame] | 39 | static void tegra_secondary_init(unsigned int cpu) |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 40 | { |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 41 | cpumask_set_cpu(cpu, &tegra_cpu_init_mask); |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 42 | } |
| 43 | |
Hiroshi Doyu | 0d1f79b | 2013-02-22 14:24:27 +0800 | [diff] [blame] | 44 | |
| 45 | static int tegra20_boot_secondary(unsigned int cpu, struct task_struct *idle) |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 46 | { |
Hiroshi Doyu | 0d1f79b | 2013-02-22 14:24:27 +0800 | [diff] [blame] | 47 | cpu = cpu_logical_map(cpu); |
| 48 | |
| 49 | /* |
| 50 | * Force the CPU into reset. The CPU must remain in reset when |
| 51 | * the flow controller state is cleared (which will cause the |
| 52 | * flow controller to stop driving reset if the CPU has been |
| 53 | * power-gated via the flow controller). This will have no |
| 54 | * effect on first boot of the CPU since it should already be |
| 55 | * in reset. |
| 56 | */ |
| 57 | tegra_put_cpu_in_reset(cpu); |
| 58 | |
| 59 | /* |
| 60 | * Unhalt the CPU. If the flow controller was used to |
| 61 | * power-gate the CPU this will cause the flow controller to |
| 62 | * stop driving reset. The CPU will remain in reset because the |
| 63 | * clock and reset block is now driving reset. |
| 64 | */ |
| 65 | flowctrl_write_cpu_halt(cpu, 0); |
| 66 | |
Joseph Lo | bb60327 | 2012-08-16 17:31:49 +0800 | [diff] [blame] | 67 | tegra_enable_cpu_clock(cpu); |
Hiroshi Doyu | 0d1f79b | 2013-02-22 14:24:27 +0800 | [diff] [blame] | 68 | flowctrl_write_cpu_csr(cpu, 0); /* Clear flow controller CSR. */ |
| 69 | tegra_cpu_out_of_reset(cpu); |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 70 | return 0; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Hiroshi Doyu | 0d1f79b | 2013-02-22 14:24:27 +0800 | [diff] [blame] | 73 | static int tegra30_boot_secondary(unsigned int cpu, struct task_struct *idle) |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 74 | { |
Joseph Lo | 7e56474 | 2013-02-26 16:28:06 +0000 | [diff] [blame] | 75 | int ret; |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 76 | unsigned long timeout; |
| 77 | |
Hiroshi Doyu | 0d1f79b | 2013-02-22 14:24:27 +0800 | [diff] [blame] | 78 | cpu = cpu_logical_map(cpu); |
Hiroshi Doyu | 0d1f79b | 2013-02-22 14:24:27 +0800 | [diff] [blame] | 79 | tegra_put_cpu_in_reset(cpu); |
| 80 | flowctrl_write_cpu_halt(cpu, 0); |
| 81 | |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 82 | /* |
| 83 | * The power up sequence of cold boot CPU and warm boot CPU |
| 84 | * was different. |
| 85 | * |
| 86 | * For warm boot CPU that was resumed from CPU hotplug, the |
| 87 | * power will be resumed automatically after un-halting the |
| 88 | * flow controller of the warm boot CPU. We need to wait for |
| 89 | * the confirmaiton that the CPU is powered then removing |
| 90 | * the IO clamps. |
| 91 | * For cold boot CPU, do not wait. After the cold boot CPU be |
| 92 | * booted, it will run to tegra_secondary_init() and set |
Hiroshi Doyu | 0d1f79b | 2013-02-22 14:24:27 +0800 | [diff] [blame] | 93 | * tegra_cpu_init_mask which influences what tegra30_boot_secondary() |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 94 | * next time around. |
| 95 | */ |
| 96 | if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) { |
Joseph Lo | 1395868 | 2013-01-07 10:56:14 +0800 | [diff] [blame] | 97 | timeout = jiffies + msecs_to_jiffies(50); |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 98 | do { |
Joseph Lo | 7e56474 | 2013-02-26 16:28:06 +0000 | [diff] [blame] | 99 | if (tegra_pmc_cpu_is_powered(cpu)) |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 100 | goto remove_clamps; |
| 101 | udelay(10); |
| 102 | } while (time_before(jiffies, timeout)); |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * The power status of the cold boot CPU is power gated as |
| 107 | * default. To power up the cold boot CPU, the power should |
| 108 | * be un-gated by un-toggling the power gate register |
| 109 | * manually. |
| 110 | */ |
Joseph Lo | 7e56474 | 2013-02-26 16:28:06 +0000 | [diff] [blame] | 111 | if (!tegra_pmc_cpu_is_powered(cpu)) { |
| 112 | ret = tegra_pmc_cpu_power_on(cpu); |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 113 | if (ret) |
| 114 | return ret; |
| 115 | |
| 116 | /* Wait for the power to come up. */ |
Joseph Lo | 1395868 | 2013-01-07 10:56:14 +0800 | [diff] [blame] | 117 | timeout = jiffies + msecs_to_jiffies(100); |
Stefan Agner | 5f80993 | 2014-02-11 01:44:13 +0100 | [diff] [blame] | 118 | while (!tegra_pmc_cpu_is_powered(cpu)) { |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 119 | if (time_after(jiffies, timeout)) |
| 120 | return -ETIMEDOUT; |
| 121 | udelay(10); |
| 122 | } |
| 123 | } |
| 124 | |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 125 | remove_clamps: |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 126 | /* CPU partition is powered. Enable the CPU clock. */ |
Joseph Lo | bb60327 | 2012-08-16 17:31:49 +0800 | [diff] [blame] | 127 | tegra_enable_cpu_clock(cpu); |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 128 | udelay(10); |
| 129 | |
| 130 | /* Remove I/O clamps. */ |
Joseph Lo | 7e56474 | 2013-02-26 16:28:06 +0000 | [diff] [blame] | 131 | ret = tegra_pmc_cpu_remove_clamping(cpu); |
Hiroshi Doyu | b4c25cc | 2013-02-22 14:24:25 +0800 | [diff] [blame] | 132 | if (ret) |
| 133 | return ret; |
| 134 | |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 135 | udelay(10); |
| 136 | |
Hiroshi Doyu | 0d1f79b | 2013-02-22 14:24:27 +0800 | [diff] [blame] | 137 | flowctrl_write_cpu_csr(cpu, 0); /* Clear flow controller CSR. */ |
| 138 | tegra_cpu_out_of_reset(cpu); |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | |
Joseph Lo | e562b86 | 2013-02-26 16:28:07 +0000 | [diff] [blame] | 142 | static int tegra114_boot_secondary(unsigned int cpu, struct task_struct *idle) |
| 143 | { |
Joseph Lo | 18901e9 | 2013-05-20 18:39:27 +0800 | [diff] [blame] | 144 | int ret = 0; |
| 145 | |
Joseph Lo | e562b86 | 2013-02-26 16:28:07 +0000 | [diff] [blame] | 146 | cpu = cpu_logical_map(cpu); |
Joseph Lo | 18901e9 | 2013-05-20 18:39:27 +0800 | [diff] [blame] | 147 | |
| 148 | if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) { |
| 149 | /* |
| 150 | * Warm boot flow |
| 151 | * The flow controller in charge of the power state and |
| 152 | * control for each CPU. |
| 153 | */ |
| 154 | /* set SCLK as event trigger for flow controller */ |
| 155 | flowctrl_write_cpu_csr(cpu, 1); |
| 156 | flowctrl_write_cpu_halt(cpu, |
| 157 | FLOW_CTRL_WAITEVENT | FLOW_CTRL_SCLK_RESUME); |
| 158 | } else { |
| 159 | /* |
| 160 | * Cold boot flow |
| 161 | * The CPU is powered up by toggling PMC directly. It will |
| 162 | * also initial power state in flow controller. After that, |
| 163 | * the CPU's power state is maintained by flow controller. |
| 164 | */ |
| 165 | ret = tegra_pmc_cpu_power_on(cpu); |
| 166 | } |
| 167 | |
| 168 | return ret; |
Joseph Lo | e562b86 | 2013-02-26 16:28:07 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Paul Gortmaker | 8bd26e3 | 2013-06-17 15:43:14 -0400 | [diff] [blame] | 171 | static int tegra_boot_secondary(unsigned int cpu, |
Hiroshi Doyu | 0d1f79b | 2013-02-22 14:24:27 +0800 | [diff] [blame] | 172 | struct task_struct *idle) |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 173 | { |
Thierry Reding | 304664e | 2014-07-11 09:52:41 +0200 | [diff] [blame] | 174 | if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC) && tegra_get_chip_id() == TEGRA20) |
Hiroshi Doyu | 0d1f79b | 2013-02-22 14:24:27 +0800 | [diff] [blame] | 175 | return tegra20_boot_secondary(cpu, idle); |
Thierry Reding | 304664e | 2014-07-11 09:52:41 +0200 | [diff] [blame] | 176 | if (IS_ENABLED(CONFIG_ARCH_TEGRA_3x_SOC) && tegra_get_chip_id() == TEGRA30) |
Hiroshi Doyu | 0d1f79b | 2013-02-22 14:24:27 +0800 | [diff] [blame] | 177 | return tegra30_boot_secondary(cpu, idle); |
Thierry Reding | 304664e | 2014-07-11 09:52:41 +0200 | [diff] [blame] | 178 | if (IS_ENABLED(CONFIG_ARCH_TEGRA_114_SOC) && tegra_get_chip_id() == TEGRA114) |
Joseph Lo | e562b86 | 2013-02-26 16:28:07 +0000 | [diff] [blame] | 179 | return tegra114_boot_secondary(cpu, idle); |
Thierry Reding | 304664e | 2014-07-11 09:52:41 +0200 | [diff] [blame] | 180 | if (IS_ENABLED(CONFIG_ARCH_TEGRA_124_SOC) && tegra_get_chip_id() == TEGRA124) |
Joseph Lo | 7394447 | 2013-10-08 12:50:03 +0800 | [diff] [blame] | 181 | return tegra114_boot_secondary(cpu, idle); |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 182 | |
Hiroshi Doyu | 0d1f79b | 2013-02-22 14:24:27 +0800 | [diff] [blame] | 183 | return -EINVAL; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 184 | } |
| 185 | |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 186 | static void __init tegra_smp_prepare_cpus(unsigned int max_cpus) |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 187 | { |
Joseph Lo | 130bfed | 2013-01-03 15:31:31 +0800 | [diff] [blame] | 188 | /* Always mark the boot CPU (CPU0) as initialized. */ |
| 189 | cpumask_set_cpu(0, &tegra_cpu_init_mask); |
| 190 | |
Hiroshi Doyu | 909444a | 2013-01-22 07:52:02 +0200 | [diff] [blame] | 191 | if (scu_a9_has_base()) |
| 192 | scu_enable(IO_ADDRESS(scu_a9_get_base())); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 193 | } |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 194 | |
| 195 | struct smp_operations tegra_smp_ops __initdata = { |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 196 | .smp_prepare_cpus = tegra_smp_prepare_cpus, |
| 197 | .smp_secondary_init = tegra_secondary_init, |
| 198 | .smp_boot_secondary = tegra_boot_secondary, |
| 199 | #ifdef CONFIG_HOTPLUG_CPU |
Joseph Lo | b811943 | 2013-01-03 14:43:00 +0800 | [diff] [blame] | 200 | .cpu_kill = tegra_cpu_kill, |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 201 | .cpu_die = tegra_cpu_die, |
| 202 | #endif |
| 203 | }; |