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 | |
| 27 | #include <mach/iomap.h> |
| 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" |
| 32 | |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 33 | extern void tegra_secondary_startup(void); |
| 34 | |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 35 | static void __iomem *scu_base = IO_ADDRESS(TEGRA_ARM_PERIF_BASE); |
| 36 | |
| 37 | #define EVP_CPU_RESET_VECTOR \ |
| 38 | (IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + 0x100) |
| 39 | #define CLK_RST_CONTROLLER_CLK_CPU_CMPLX \ |
| 40 | (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x4c) |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame^] | 41 | #define CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET \ |
| 42 | (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x340) |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 43 | #define CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR \ |
| 44 | (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x344) |
| 45 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame^] | 46 | #define CPU_CLOCK(cpu) (0x1<<(8+cpu)) |
| 47 | #define CPU_RESET(cpu) (0x1111ul<<(cpu)) |
| 48 | |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 49 | void __cpuinit platform_secondary_init(unsigned int cpu) |
| 50 | { |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 51 | /* |
| 52 | * if any interrupts are already enabled for the primary |
| 53 | * core (e.g. timer irq), then they will not have been enabled |
| 54 | * for us: do so |
| 55 | */ |
Russell King | 3848953 | 2010-12-04 16:01:03 +0000 | [diff] [blame] | 56 | gic_secondary_init(0); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 57 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame^] | 58 | } |
| 59 | |
| 60 | static int tegra20_power_up_cpu(unsigned int cpu) |
| 61 | { |
| 62 | u32 reg; |
| 63 | |
| 64 | /* Enable the CPU clock. */ |
| 65 | reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX); |
| 66 | writel(reg & ~CPU_CLOCK(cpu), CLK_RST_CONTROLLER_CLK_CPU_CMPLX); |
| 67 | barrier(); |
| 68 | reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX); |
| 69 | |
| 70 | /* Clear flow controller CSR. */ |
| 71 | flowctrl_write_cpu_csr(cpu, 0); |
| 72 | |
| 73 | return 0; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle) |
| 77 | { |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame^] | 78 | int status; |
| 79 | |
| 80 | /* Force the CPU into reset. The CPU must remain in reset when the |
| 81 | * flow controller state is cleared (which will cause the flow |
| 82 | * controller to stop driving reset if the CPU has been power-gated |
| 83 | * via the flow controller). This will have no effect on first boot |
| 84 | * of the CPU since it should already be in reset. |
| 85 | */ |
| 86 | writel(CPU_RESET(cpu), CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET); |
| 87 | dmb(); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 88 | |
| 89 | /* |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame^] | 90 | * Unhalt the CPU. If the flow controller was used to power-gate the |
| 91 | * CPU this will cause the flow controller to stop driving reset. |
| 92 | * The CPU will remain in reset because the clock and reset block |
| 93 | * is now driving reset. |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 94 | */ |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame^] | 95 | flowctrl_write_cpu_halt(cpu, 0); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 96 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame^] | 97 | switch (tegra_chip_id) { |
| 98 | case TEGRA20: |
| 99 | status = tegra20_power_up_cpu(cpu); |
| 100 | break; |
| 101 | default: |
| 102 | status = -EINVAL; |
| 103 | break; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame^] | 106 | if (status) |
| 107 | goto done; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 108 | |
Peter De Schrijver | b36ab97 | 2012-02-10 01:47:45 +0200 | [diff] [blame^] | 109 | /* Take the CPU out of reset. */ |
| 110 | writel(CPU_RESET(cpu), CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR); |
| 111 | wmb(); |
| 112 | done: |
| 113 | return status; |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* |
| 117 | * Initialise the CPU possible map early - this describes the CPUs |
| 118 | * which may be present or become present in the system. |
| 119 | */ |
| 120 | void __init smp_init_cpus(void) |
| 121 | { |
| 122 | unsigned int i, ncores = scu_get_core_count(scu_base); |
| 123 | |
Russell King | a06f916 | 2011-10-20 22:04:18 +0100 | [diff] [blame] | 124 | if (ncores > nr_cpu_ids) { |
| 125 | pr_warn("SMP: %u cores greater than maximum (%u), clipping\n", |
| 126 | ncores, nr_cpu_ids); |
| 127 | ncores = nr_cpu_ids; |
Russell King | 8975b6c | 2010-12-03 19:29:53 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 130 | for (i = 0; i < ncores; i++) |
KOSAKI Motohiro | 24fe432 | 2011-06-23 17:28:28 +0900 | [diff] [blame] | 131 | set_cpu_possible(i, true); |
Russell King | 0f7b332 | 2011-04-03 13:01:30 +0100 | [diff] [blame] | 132 | |
| 133 | set_smp_cross_call(gic_raise_softirq); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Russell King | 05c74a6 | 2010-12-03 11:09:48 +0000 | [diff] [blame] | 136 | void __init platform_smp_prepare_cpus(unsigned int max_cpus) |
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 | tegra_cpu_reset_handler_init(); |
Russell King | 05c74a6 | 2010-12-03 11:09:48 +0000 | [diff] [blame] | 139 | scu_enable(scu_base); |
Colin Cross | 1cea732 | 2010-02-21 17:46:23 -0800 | [diff] [blame] | 140 | } |