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> |
| 21 | |
| 22 | #include <asm/cacheflush.h> |
Russell King | 0f7b332 | 2011-04-03 13:01:30 +0100 | [diff] [blame] | 23 | #include <asm/hardware/gic.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> |
| 26 | |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 27 | #include <mach/powergate.h> |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 28 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 29 | #include "fuse.h" |
| 30 | #include "flowctrl.h" |
| 31 | #include "reset.h" |
Joseph Lo | bb60327 | 2012-08-16 17:31:49 +0800 | [diff] [blame] | 32 | #include "tegra_cpu_car.h" |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 33 | |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 34 | #include "common.h" |
Stephen Warren | 2be39c0 | 2012-10-04 14:24:09 -0600 | [diff] [blame] | 35 | #include "iomap.h" |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 36 | |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 37 | extern void tegra_secondary_startup(void); |
| 38 | |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 39 | #define EVP_CPU_RESET_VECTOR \ |
| 40 | (IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + 0x100) |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 41 | |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 42 | static void __cpuinit tegra_secondary_init(unsigned int cpu) |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 43 | { |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 44 | /* |
| 45 | * if any interrupts are already enabled for the primary |
| 46 | * core (e.g. timer irq), then they will not have been enabled |
| 47 | * for us: do so |
| 48 | */ |
Russell King | 3848953 | 2010-12-04 16:01:03 +0000 | [diff] [blame] | 49 | gic_secondary_init(0); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 50 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static int tegra20_power_up_cpu(unsigned int cpu) |
| 54 | { |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 55 | /* Enable the CPU clock. */ |
Joseph Lo | bb60327 | 2012-08-16 17:31:49 +0800 | [diff] [blame] | 56 | tegra_enable_cpu_clock(cpu); |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 57 | |
| 58 | /* Clear flow controller CSR. */ |
| 59 | flowctrl_write_cpu_csr(cpu, 0); |
| 60 | |
| 61 | return 0; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 64 | static int tegra30_power_up_cpu(unsigned int cpu) |
| 65 | { |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 66 | int ret, pwrgateid; |
| 67 | unsigned long timeout; |
| 68 | |
| 69 | pwrgateid = tegra_cpu_powergate_id(cpu); |
| 70 | if (pwrgateid < 0) |
| 71 | return pwrgateid; |
| 72 | |
| 73 | /* If this is the first boot, toggle powergates directly. */ |
| 74 | if (!tegra_powergate_is_powered(pwrgateid)) { |
| 75 | ret = tegra_powergate_power_on(pwrgateid); |
| 76 | if (ret) |
| 77 | return ret; |
| 78 | |
| 79 | /* Wait for the power to come up. */ |
| 80 | timeout = jiffies + 10*HZ; |
| 81 | while (tegra_powergate_is_powered(pwrgateid)) { |
| 82 | if (time_after(jiffies, timeout)) |
| 83 | return -ETIMEDOUT; |
| 84 | udelay(10); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /* CPU partition is powered. Enable the CPU clock. */ |
Joseph Lo | bb60327 | 2012-08-16 17:31:49 +0800 | [diff] [blame] | 89 | tegra_enable_cpu_clock(cpu); |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 90 | udelay(10); |
| 91 | |
| 92 | /* Remove I/O clamps. */ |
| 93 | ret = tegra_powergate_remove_clamping(pwrgateid); |
| 94 | udelay(10); |
| 95 | |
| 96 | /* Clear flow controller CSR. */ |
| 97 | flowctrl_write_cpu_csr(cpu, 0); |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 102 | 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] | 103 | { |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 104 | int status; |
| 105 | |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 106 | /* |
| 107 | * 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] | 108 | * flow controller state is cleared (which will cause the flow |
| 109 | * controller to stop driving reset if the CPU has been power-gated |
| 110 | * via the flow controller). This will have no effect on first boot |
| 111 | * of the CPU since it should already be in reset. |
| 112 | */ |
Joseph Lo | bb60327 | 2012-08-16 17:31:49 +0800 | [diff] [blame] | 113 | tegra_put_cpu_in_reset(cpu); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 114 | |
| 115 | /* |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 116 | * Unhalt the CPU. If the flow controller was used to power-gate the |
| 117 | * CPU this will cause the flow controller to stop driving reset. |
| 118 | * The CPU will remain in reset because the clock and reset block |
| 119 | * is now driving reset. |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 120 | */ |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 121 | flowctrl_write_cpu_halt(cpu, 0); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 122 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 123 | switch (tegra_chip_id) { |
| 124 | case TEGRA20: |
| 125 | status = tegra20_power_up_cpu(cpu); |
| 126 | break; |
Peter De Schrijver | 86e51a2 | 2012-02-10 01:47:50 +0200 | [diff] [blame] | 127 | case TEGRA30: |
| 128 | status = tegra30_power_up_cpu(cpu); |
| 129 | break; |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 130 | default: |
| 131 | status = -EINVAL; |
| 132 | break; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 135 | if (status) |
| 136 | goto done; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 137 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 138 | /* Take the CPU out of reset. */ |
Joseph Lo | bb60327 | 2012-08-16 17:31:49 +0800 | [diff] [blame] | 139 | tegra_cpu_out_of_reset(cpu); |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 140 | done: |
| 141 | return status; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 144 | static void __init tegra_smp_init_cpus(void) |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 145 | { |
Russell King | 0f7b332 | 2011-04-03 13:01:30 +0100 | [diff] [blame] | 146 | set_smp_cross_call(gic_raise_softirq); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 149 | static void __init tegra_smp_prepare_cpus(unsigned int max_cpus) |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 150 | { |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame] | 151 | tegra_cpu_reset_handler_init(); |
Hiroshi Doyu | 909444a | 2013-01-22 07:52:02 +0200 | [diff] [blame^] | 152 | if (scu_a9_has_base()) |
| 153 | scu_enable(IO_ADDRESS(scu_a9_get_base())); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 154 | } |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 155 | |
| 156 | struct smp_operations tegra_smp_ops __initdata = { |
| 157 | .smp_init_cpus = tegra_smp_init_cpus, |
| 158 | .smp_prepare_cpus = tegra_smp_prepare_cpus, |
| 159 | .smp_secondary_init = tegra_secondary_init, |
| 160 | .smp_boot_secondary = tegra_boot_secondary, |
| 161 | #ifdef CONFIG_HOTPLUG_CPU |
| 162 | .cpu_die = tegra_cpu_die, |
Olof Johansson | 25468fe | 2012-09-22 00:06:21 -0700 | [diff] [blame] | 163 | .cpu_disable = tegra_cpu_disable, |
Marc Zyngier | a172573 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 164 | #endif |
| 165 | }; |