Skip to contentSkip to conversation

ARM: tegra114: bring up secondary CPU for SMP

PATCH Superseded Joseph Lo 2 participants 9 messages Feb 27, 2013 – Mar 6, 2013

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Joseph Lo

author
#0 lore raw

v2 cover ARM: tegra114: bring up secondary CPU for SMP

This series bring up secondary CPU for Tegra114. Because we are going to support generic power domain later, the conventional powergate driver will be removed. So we add the CPU power on/off function in PMC driver first.

This series was dependent on the patches below.
"ARM: tegra: don't unlock MMIO access to DBGLAR for working"
"ARM: tegra: Fix unchecked return value"
"ARM: tegra30: fix the logical detection of power on sequence of warm boot CPUs" "ARM: tegra: refactor tegra{20,30}_boot_secondary"

And the V2 series below.
"ARM: tegra: pmc: add specific compatible DT string for Tegra30 and Tegra114" "ARM: dts: tegra: fix the PMC compatible string"

V2:
* take care the comments from V1

Joseph Lo (4):
ARM: tegra: pmc: convert PMC driver to support DT only
ARM: tegra: pmc: add power on function for secondary CPUs
ARM: tegra30: platsmp: replace the CPU power on function in PMC driver
ARM: tegra114: bring up secondary CPU for SMP

 arch/arm/mach-tegra/platsmp.c |  27 +++----
 arch/arm/mach-tegra/pmc.c     | 159 ++++++++++++++++++++++++++++++++++--------
 arch/arm/mach-tegra/pmc.h     |   4 ++
 3 files changed, 148 insertions(+), 42 deletions(-)
Signature · 1 line
1.8.1.1
author
#1 lore raw

PATCH v2 1/4 ARM: tegra: pmc: convert PMC driver to support DT only

The Tegra kernel only support boot from DT now. Clean up the PMC driver to support DT only, that includes:

* remove the ifdef of CONFIG_OF
* replace the static mapping of PMC addr to map from DT

---
V2:
* removing the change from readl_relaxed back to readl, same with the write function
* adding a BUG() when there is no PMC node in DT
* removeing the redundancy of_have_populated_dt() check

---
 arch/arm/mach-tegra/pmc.c | 54 ++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 29 deletions(-)
arch/arm/mach-tegra/pmc.c +25 -29
index 5d79d34..f7d63ab 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
+ * Copyright (C) 2012,2013 NVIDIA CORPORATION. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -18,59 +18,55 @@
 #include <linux/kernel.h>
 #include <linux/io.h>
 #include <linux/of.h>
-
-#include "iomap.h"
+#include <linux/of_address.h>
 
 #define PMC_CTRL		0x0
 #define PMC_CTRL_INTR_LOW	(1 << 17)
 
+static void __iomem *tegra_pmc_base;
+static bool tegra_pmc_invert_interrupt;
+
 static inline u32 tegra_pmc_readl(u32 reg)
 {
-	return readl(IO_ADDRESS(TEGRA_PMC_BASE + reg));
+	return readl(tegra_pmc_base + reg);
 }
 
 static inline void tegra_pmc_writel(u32 val, u32 reg)
 {
-	writel(val, IO_ADDRESS(TEGRA_PMC_BASE + reg));
+	writel(val, (tegra_pmc_base + reg));
 }
 
-#ifdef CONFIG_OF
 static const struct of_device_id matches[] __initconst = {
 	{ .compatible = "nvidia,tegra114-pmc" },
 	{ .compatible = "nvidia,tegra30-pmc" },
 	{ .compatible = "nvidia,tegra20-pmc" },
 	{ }
 };
-#endif
 
-void __init tegra_pmc_init(void)
+static void tegra_pmc_parse_dt(void)
 {
-	/*
-	 * For now, Harmony is the only board that uses the PMC, and it wants
-	 * the signal inverted. Seaboard would too if it used the PMC.
-	 * Hopefully by the time other boards want to use the PMC, everything
-	 * will be device-tree, or they also want it inverted.
-	 */
-	bool invert_interrupt = true;
-	u32 val;
-
-#ifdef CONFIG_OF
-	if (of_have_populated_dt()) {
-		struct device_node *np;
+	struct device_node *np;
 
-		invert_interrupt = false;
+	np = of_find_matching_node(NULL, matches);
+	if (np) {
+		tegra_pmc_base = of_iomap(np, 0);
 
-		np = of_find_matching_node(NULL, matches);
-		if (np) {
-			if (of_find_property(np, "nvidia,invert-interrupt",
-						NULL))
-				invert_interrupt = true;
-		}
+		tegra_pmc_invert_interrupt = of_property_read_bool(np,
+					     "nvidia,invert-interrupt");
+	} else {
+		/* Should not be here, the PMC DT node should always exist. */
+		BUG();
 	}
-#endif
+}
+
+void __init tegra_pmc_init(void)
+{
+	u32 val;
+
+	tegra_pmc_parse_dt();
 
 	val = tegra_pmc_readl(PMC_CTRL);
-	if (invert_interrupt)
+	if (tegra_pmc_invert_interrupt)
 		val |= PMC_CTRL_INTR_LOW;
 	else
 		val &= ~PMC_CTRL_INTR_LOW;
Signature · 1 line
1.8.1.1
#2 lore raw

PATCH v2 1/4 ARM: tegra: pmc: convert PMC driver to support DT only

arch/arm/mach-tegra/pmc.c line 36

Quoted 12 lines · Joseph Lo

The Tegra kernel only support boot from DT now. Clean up the PMC driver to support DT only, that includes:

* remove the ifdef of CONFIG_OF
* replace the static mapping of PMC addr to map from DT

arch/arm/mach-tegra/pmc.c +1 -1
 
 static inline void tegra_pmc_writel(u32 val, u32 reg)
 {
-	writel(val, IO_ADDRESS(TEGRA_PMC_BASE + reg));
+	writel(val, (tegra_pmc_base + reg));

There are redundant () there.

arch/arm/mach-tegra/pmc.c line 51

Quoted 6 lines
arch/arm/mach-tegra/pmc.c +4 -0
+static void tegra_pmc_parse_dt(void)
 {
+	struct device_node *np;
 
+	np = of_find_matching_node(NULL, matches);
+	if (np) {

Why not:

BUG_ON(!np);

That way, you can get rid of if if/else blocks, and remove one level of indentation throughout this function. I already mentioned this internally...

author
#3 lore raw

PATCH v2 2/4 ARM: tegra: pmc: add power on function for secondary CPUs

In reply to Joseph Lo

Adding the power on function for secondary CPUs in PMC driver, this can help us to remove legacy powergate driver and add generic power domain support later.

---
V2:
* Don't use ISS_ERR_VALUE for checking error return code
* the CPU power on function only available for secondary CPU which means we don't care (cpuid <= 0 || cpuid >= num_possible_cpus())
* adding a WARN_ON when the current power state is same with we want to set

---
 arch/arm/mach-tegra/pmc.c | 107 +++++++++++++++++++++++++++++++++++++++++++++-
 arch/arm/mach-tegra/pmc.h |   4 ++
 2 files changed, 109 insertions(+), 2 deletions(-)
arch/arm/mach-tegra/pmc.c +105 -2
index f7d63ab..d4e4421 100644
@@ -20,8 +20,26 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 
-#define PMC_CTRL		0x0
-#define PMC_CTRL_INTR_LOW	(1 << 17)
+#define PMC_CTRL			0x0
+#define PMC_CTRL_INTR_LOW		(1 << 17)
+#define PMC_PWRGATE_TOGGLE		0x30
+#define PMC_PWRGATE_TOGGLE_START	(1 << 8)
+#define PMC_REMOVE_CLAMPING		0x34
+#define PMC_PWRGATE_STATUS		0x38
+
+#define TEGRA_POWERGATE_PCIE	3
+#define TEGRA_POWERGATE_VDEC	4
+#define TEGRA_POWERGATE_CPU1	9
+#define TEGRA_POWERGATE_CPU2	10
+#define TEGRA_POWERGATE_CPU3	11
+
+static u8 tegra_cpu_domains[] = {
+	0xFF,			/* not available for CPU0 */
+	TEGRA_POWERGATE_CPU1,
+	TEGRA_POWERGATE_CPU2,
+	TEGRA_POWERGATE_CPU3,
+};
+static DEFINE_SPINLOCK(tegra_powergate_lock);
 
 static void __iomem *tegra_pmc_base;
 static bool tegra_pmc_invert_interrupt;
@@ -36,6 +54,91 @@ static inline void tegra_pmc_writel(u32 val, u32 reg)
 	writel(val, (tegra_pmc_base + reg));
 }
 
+static int tegra_pmc_get_cpu_powerdomain_id(int cpuid)
+{
+	if (cpuid <= 0 || cpuid >= num_possible_cpus())
+		return -EINVAL;
+	return tegra_cpu_domains[cpuid];
+}
+
+static int tegra_pmc_powergate_set(int id, bool new_state)
+{
+	u32 reg;
+	bool old_state;
+	unsigned long flags;
+
+	spin_lock_irqsave(&tegra_powergate_lock, flags);
+
+	reg = tegra_pmc_readl(PMC_PWRGATE_STATUS);
+
+	old_state = (reg >> id) & 1;
+	WARN_ON(old_state == new_state);
+
+	tegra_pmc_writel(PMC_PWRGATE_TOGGLE_START | id, PMC_PWRGATE_TOGGLE);
+
+	spin_unlock_irqrestore(&tegra_powergate_lock, flags);
+
+	return 0;
+}
+
+static bool tegra_pmc_powergate_is_powered(int id)
+{
+	u32 status;
+
+	status = tegra_pmc_readl(PMC_PWRGATE_STATUS) & (1 << id);
+	return !!status;
+}
+
+static int tegra_pmc_powergate_remove_clamping(int id)
+{
+	u32 mask;
+
+	/*
+	 * Tegra has a bug where PCIE and VDE clamping masks are
+	 * swapped relatively to the partition ids.
+	 */
+	if (id ==  TEGRA_POWERGATE_VDEC)
+		mask = (1 << TEGRA_POWERGATE_PCIE);
+	else if	(id == TEGRA_POWERGATE_PCIE)
+		mask = (1 << TEGRA_POWERGATE_VDEC);
+	else
+		mask = (1 << id);
+
+	tegra_pmc_writel(mask, PMC_REMOVE_CLAMPING);
+
+	return 0;
+}
+
+bool tegra_pmc_cpu_is_powered(int cpuid)
+{
+	int id;
+
+	id = tegra_pmc_get_cpu_powerdomain_id(cpuid);
+	if (id < 0)
+		return false;
+	return tegra_pmc_powergate_is_powered(id);
+}
+
+int tegra_pmc_cpu_power_on(int cpuid)
+{
+	int id;
+
+	id = tegra_pmc_get_cpu_powerdomain_id(cpuid);
+	if (id < 0)
+		return id;
+	return tegra_pmc_powergate_set(id, true);
+}
+
+int tegra_pmc_cpu_remove_clamping(int cpuid)
+{
+	int id;
+
+	id = tegra_pmc_get_cpu_powerdomain_id(cpuid);
+	if (id < 0)
+		return id;
+	return tegra_pmc_powergate_remove_clamping(id);
+}
+
 static const struct of_device_id matches[] __initconst = {
 	{ .compatible = "nvidia,tegra114-pmc" },
 	{ .compatible = "nvidia,tegra30-pmc" },
arch/arm/mach-tegra/pmc.h +4 -0
index 8995ee4..7d44710 100644
@@ -18,6 +18,10 @@
 #ifndef __MACH_TEGRA_PMC_H
 #define __MACH_TEGRA_PMC_H
 
+bool tegra_pmc_cpu_is_powered(int cpuid);
+int tegra_pmc_cpu_power_on(int cpuid);
+int tegra_pmc_cpu_remove_clamping(int cpuid);
+
 void tegra_pmc_init(void);
 
 #endif
Signature · 1 line
1.8.1.1
#4 lore raw

PATCH v2 2/4 ARM: tegra: pmc: add power on function for secondary CPUs

Quoted 10 lines · Joseph Lo

Adding the power on function for secondary CPUs in PMC driver, this can help us to remove legacy powergate driver and add generic power domain support later.

---
V2:
* Don't use ISS_ERR_VALUE for checking error return code
* the CPU power on function only available for secondary CPU which means we don't care (cpuid <= 0 || cpuid >= num_possible_cpus())

s/don't care/don't support/, I think.

arch/arm/mach-tegra/pmc.c static inline void tegra_pmc_writel(u32 val, u32 reg) · line 74

Quoted 7 lines
arch/arm/mach-tegra/pmc.c +4 -0
 
+static int tegra_pmc_powergate_set(int id, bool new_state)
 
+	reg = tegra_pmc_readl(PMC_PWRGATE_STATUS);
+
+	old_state = (reg >> id) & 1;

You could actually replace those last to lines with:

old_state = tegra_pmc_powergate_is_powered_id();

arch/arm/mach-tegra/pmc.c static inline void tegra_pmc_writel(u32 val, u32 reg) · line 89

Quoted 6 lines
arch/arm/mach-tegra/pmc.c +6 -0
+static bool tegra_pmc_powergate_is_powered(int id)
+{
+	u32 status;
+
+	status = tegra_pmc_readl(PMC_PWRGATE_STATUS) & (1 << id);
+	return !!status;

That might be simpler as:

return (tegra_pmc_readl(PMC_PWRGATE_STATUS) >> id) & 1;

(i.e. the code that's currently part of tegra_pmc_powergate_set to calculate old_status)

author
#5 lore raw

PATCH v2 3/4 ARM: tegra30: platsmp: replace the CPU power on function in PMC driver

In reply to Joseph Lo

Using the CPU power on function in PMC driver to bring up secondary CPUs, because we are going to re-factor powergate driver to support generic power domain. It will be removed later and added the generic power domain support in PMC driver.

---
V2:
* no change

---
 arch/arm/mach-tegra/platsmp.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
arch/arm/mach-tegra/platsmp.c +7 -12
index 41971ac..601bd0c 100644
@@ -26,11 +26,10 @@
 #include <asm/smp_scu.h>
 #include <asm/smp_plat.h>
 
-#include <mach/powergate.h>
-
 #include "fuse.h"
 #include "flowctrl.h"
 #include "reset.h"
+#include "pmc.h"
 
 #include "common.h"
 #include "iomap.h"
@@ -80,14 +79,10 @@ static int tegra20_boot_secondary(unsigned int cpu, struct task_struct *idle)
 
 static int tegra30_boot_secondary(unsigned int cpu, struct task_struct *idle)
 {
-	int ret, pwrgateid;
+	int ret;
 	unsigned long timeout;
 
 	cpu = cpu_logical_map(cpu);
-	pwrgateid = tegra_cpu_powergate_id(cpu);
-	if (pwrgateid < 0)
-		return pwrgateid;
-
 	tegra_put_cpu_in_reset(cpu);
 	flowctrl_write_cpu_halt(cpu, 0);
 
@@ -108,7 +103,7 @@ static int tegra30_boot_secondary(unsigned int cpu, struct task_struct *idle)
 	if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
 		timeout = jiffies + msecs_to_jiffies(50);
 		do {
-			if (tegra_powergate_is_powered(pwrgateid))
+			if (tegra_pmc_cpu_is_powered(cpu))
 				goto remove_clamps;
 			udelay(10);
 		} while (time_before(jiffies, timeout));
@@ -120,14 +115,14 @@ static int tegra30_boot_secondary(unsigned int cpu, struct task_struct *idle)
 	 * be un-gated by un-toggling the power gate register
 	 * manually.
 	 */
-	if (!tegra_powergate_is_powered(pwrgateid)) {
-		ret = tegra_powergate_power_on(pwrgateid);
+	if (!tegra_pmc_cpu_is_powered(cpu)) {
+		ret = tegra_pmc_cpu_power_on(cpu);
 		if (ret)
 			return ret;
 
 		/* Wait for the power to come up. */
 		timeout = jiffies + msecs_to_jiffies(100);
-		while (tegra_powergate_is_powered(pwrgateid)) {
+		while (tegra_pmc_cpu_is_powered(cpu)) {
 			if (time_after(jiffies, timeout))
 				return -ETIMEDOUT;
 			udelay(10);
@@ -140,7 +135,7 @@ remove_clamps:
 	udelay(10);
 
 	/* Remove I/O clamps. */
-	ret = tegra_powergate_remove_clamping(pwrgateid);
+	ret = tegra_pmc_cpu_remove_clamping(cpu);
 	if (ret)
 		return ret;
 
Signature · 1 line
1.8.1.1
author
#6 lore raw

PATCH v2 4/4 ARM: tegra114: bring up secondary CPU for SMP

In reply to Joseph Lo

The secondary CPU can be brought up by toggling the power in PMC. Then the flow controller will release CPU to go by clearing the reset and clamp signal automatically.

Based on the work by:
Bo Yan <[email protected]>

---
V2:
* no change

---
 arch/arm/mach-tegra/platsmp.c | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm/mach-tegra/platsmp.c +8 -0
index 601bd0c..516aab2 100644
@@ -146,6 +146,12 @@ remove_clamps:
 	return 0;
 }
 
+static int tegra114_boot_secondary(unsigned int cpu, struct task_struct *idle)
+{
+	cpu = cpu_logical_map(cpu);
+	return tegra_pmc_cpu_power_on(cpu);
+}
+
 static int __cpuinit tegra_boot_secondary(unsigned int cpu,
 					  struct task_struct *idle)
 {
@@ -153,6 +159,8 @@ static int __cpuinit tegra_boot_secondary(unsigned int cpu,
 		return tegra20_boot_secondary(cpu, idle);
 	if (IS_ENABLED(CONFIG_ARCH_TEGRA_3x_SOC) && tegra_chip_id == TEGRA30)
 		return tegra30_boot_secondary(cpu, idle);
+	if (IS_ENABLED(CONFIG_ARCH_TEGRA_114_SOC) && tegra_chip_id == TEGRA114)
+		return tegra114_boot_secondary(cpu, idle);
 
 	return -EINVAL;
 }
Signature · 1 line
1.8.1.1
#7 lore raw

PATCH v2 4/4 ARM: tegra114: bring up secondary CPU for SMP

Quoted 3 lines · Joseph Lo

The secondary CPU can be brought up by toggling the power in PMC. Then the flow controller will release CPU to go by clearing the reset and clamp signal automatically.

Patches 3 and 4 look fine as-is.

#8 lore raw

v2 cover ARM: tegra114: bring up secondary CPU for SMP

In reply to Joseph Lo
Quoted 3 lines · Joseph Lo

This series bring up secondary CPU for Tegra114. Because we are going to support generic power domain later, the conventional powergate driver will be removed. So we add the CPU power on/off function in PMC driver first.

I have applied all 4 patches in this series:

1/4: Applied V3, to Tegra's for-3.10/cleanup branch 2/4: Applied V3, to Tegra's for-3.10/cleanup branch 3/4: Applied V2, to Tegra's for-3.10/cleanup branch 4/4: Applied V2, to Tegra's for-3.10/soc branch