From 06971deda10930f250749c0abb8892b5b2fe8ae8 Mon Sep 17 00:00:00 2001
From: Greg Meiste <w30289@motorola.com>
Date: Wed, 25 Aug 2010 10:55:21 -0500
Subject: [PATCH] Revert "Revert "[ARM] tegra: stingray: Support soft reset""

This reverts commit 22d12890334af316424b43cbc36458546b6eca1c.

Change-Id: I7f864e29fefeb8bf5c0c7541fc91221e3f7986ae
---
 arch/arm/mach-tegra/board-stingray-power.c |  7 +++++++
 arch/arm/mach-tegra/board-stingray.c       | 21 +++++++++++++++++----
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-tegra/board-stingray-power.c b/arch/arm/mach-tegra/board-stingray-power.c
index a13a6b67520c..ffda3a90bdb6 100644
--- a/arch/arm/mach-tegra/board-stingray-power.c
+++ b/arch/arm/mach-tegra/board-stingray-power.c
@@ -172,6 +172,13 @@ static int cpcap_validity_probe(struct platform_device *pdev)
 	} else
 		dev_info(&pdev->dev, "Not starting macro 14 (no hw support)\n");
 
+	/* Enable workaround to allow soft resets to work */
+	/* TODO: Only enable this on non-production hardware. */
+	cpcap_regacc_write(cpcap_di, CPCAP_REG_PGC,
+			   CPCAP_BIT_SYS_RST_MODE, CPCAP_BIT_SYS_RST_MODE);
+	err = cpcap_uc_start(cpcap_di, CPCAP_MACRO_15);
+	dev_info(&pdev->dev, "Started macro 15: %d\n", err);
+
 	return 0;
 }
 
diff --git a/arch/arm/mach-tegra/board-stingray.c b/arch/arm/mach-tegra/board-stingray.c
index 3da0912b8e31..4bcb64b45150 100644
--- a/arch/arm/mach-tegra/board-stingray.c
+++ b/arch/arm/mach-tegra/board-stingray.c
@@ -48,6 +48,7 @@
 #include <mach/audio.h>
 #include <mach/cpcap_audio.h>
 #include <mach/suspend.h>
+#include <mach/system.h>
 
 #include <linux/usb/android_composite.h>
 
@@ -785,6 +786,17 @@ static void __init tegra_stingray_fixup(struct machine_desc *desc, struct tag *t
 	mi->bank[1].size = SZ_512M - SZ_256K;
 }
 
+static void stingray_reset(char mode, const char *cmd)
+{
+	/* Signal to CPCAP to stop the uC. */
+	gpio_set_value(TEGRA_GPIO_PG3, 0);
+	mdelay(100);
+	gpio_set_value(TEGRA_GPIO_PG3, 1);
+	mdelay(100);
+
+	tegra_assert_system_reset();
+}
+
 static void stingray_power_off(void)
 {
 	printk(KERN_INFO "stingray_pm_power_off...\n");
@@ -802,6 +814,11 @@ static void stingray_power_off(void)
 
 static void __init stingray_power_off_init(void)
 {
+	tegra_gpio_enable(TEGRA_GPIO_PG3);
+	gpio_request(TEGRA_GPIO_PG3, "sys_restart_b");
+	gpio_direction_output(TEGRA_GPIO_PG3, 1);
+	tegra_reset = stingray_reset;
+
 	tegra_gpio_enable(TEGRA_GPIO_PV7);
 	if (!gpio_request(TEGRA_GPIO_PV7, "wdi"))
 		pm_power_off = stingray_power_off;
@@ -886,10 +903,6 @@ static void __init tegra_stingray_init(void)
 	gpio_request(TEGRA_GPIO_PV4, "usb_data_en");
 	gpio_direction_output(TEGRA_GPIO_PV4, 1);
 
-	tegra_gpio_enable(TEGRA_GPIO_PG3);
-	gpio_request(TEGRA_GPIO_PG3, "sys_restart_b");
-	gpio_direction_output(TEGRA_GPIO_PG3, 1);
-
 	/* ULPI_PHY_RESET_B (TEGRA_GPIO_PG2) can be initialized as
 	   output low when the kernel boots.
 	   FIXME: This will need to be evaluated for datacard scenarios
-- 
2.34.1