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