blob: 79a241a6320fa21e1fd2b762c823f00bb383fbf0 [file] [log] [blame]
Colin Cross1cea7322010-02-21 17:46:23 -08001/*
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 King0f7b3322011-04-03 13:01:30 +010023#include <asm/hardware/gic.h>
Colin Cross1cea7322010-02-21 17:46:23 -080024#include <asm/mach-types.h>
Colin Cross1cea7322010-02-21 17:46:23 -080025#include <asm/smp_scu.h>
26
27#include <mach/iomap.h>
28
Peter De Schrijverb36ab972012-02-10 01:47:45 +020029#include "fuse.h"
30#include "flowctrl.h"
31#include "reset.h"
32
Colin Cross1cea7322010-02-21 17:46:23 -080033extern void tegra_secondary_startup(void);
34
Colin Cross1cea7322010-02-21 17:46:23 -080035static 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 Schrijverb36ab972012-02-10 01:47:45 +020041#define CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET \
42 (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x340)
Colin Cross1cea7322010-02-21 17:46:23 -080043#define CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR \
44 (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x344)
45
Peter De Schrijverb36ab972012-02-10 01:47:45 +020046#define CPU_CLOCK(cpu) (0x1<<(8+cpu))
47#define CPU_RESET(cpu) (0x1111ul<<(cpu))
48
Colin Cross1cea7322010-02-21 17:46:23 -080049void __cpuinit platform_secondary_init(unsigned int cpu)
50{
Colin Cross1cea7322010-02-21 17:46:23 -080051 /*
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 King38489532010-12-04 16:01:03 +000056 gic_secondary_init(0);
Colin Cross1cea7322010-02-21 17:46:23 -080057
Peter De Schrijverb36ab972012-02-10 01:47:45 +020058}
59
60static 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 Cross1cea7322010-02-21 17:46:23 -080074}
75
76int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
77{
Peter De Schrijverb36ab972012-02-10 01:47:45 +020078 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 Cross1cea7322010-02-21 17:46:23 -080088
89 /*
Peter De Schrijverb36ab972012-02-10 01:47:45 +020090 * 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 Cross1cea7322010-02-21 17:46:23 -080094 */
Peter De Schrijverb36ab972012-02-10 01:47:45 +020095 flowctrl_write_cpu_halt(cpu, 0);
Colin Cross1cea7322010-02-21 17:46:23 -080096
Peter De Schrijverb36ab972012-02-10 01:47:45 +020097 switch (tegra_chip_id) {
98 case TEGRA20:
99 status = tegra20_power_up_cpu(cpu);
100 break;
101 default:
102 status = -EINVAL;
103 break;
Colin Cross1cea7322010-02-21 17:46:23 -0800104 }
105
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200106 if (status)
107 goto done;
Colin Cross1cea7322010-02-21 17:46:23 -0800108
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200109 /* Take the CPU out of reset. */
110 writel(CPU_RESET(cpu), CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR);
111 wmb();
112done:
113 return status;
Colin Cross1cea7322010-02-21 17:46:23 -0800114}
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 */
120void __init smp_init_cpus(void)
121{
122 unsigned int i, ncores = scu_get_core_count(scu_base);
123
Russell Kinga06f9162011-10-20 22:04:18 +0100124 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 King8975b6c2010-12-03 19:29:53 +0000128 }
129
Colin Cross1cea7322010-02-21 17:46:23 -0800130 for (i = 0; i < ncores; i++)
KOSAKI Motohiro24fe4322011-06-23 17:28:28 +0900131 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100132
133 set_smp_cross_call(gic_raise_softirq);
Colin Cross1cea7322010-02-21 17:46:23 -0800134}
135
Russell King05c74a62010-12-03 11:09:48 +0000136void __init platform_smp_prepare_cpus(unsigned int max_cpus)
Colin Cross1cea7322010-02-21 17:46:23 -0800137{
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200138 tegra_cpu_reset_handler_init();
Russell King05c74a62010-12-03 11:09:48 +0000139 scu_enable(scu_base);
Colin Cross1cea7322010-02-21 17:46:23 -0800140}