msm: wdog_debug: switch to using scm call to disable wdog debug

To enable TZ to lock down (for security reasons) the wdog debug
and boot partition select registers, switch to using scm call to
disable wdog debug and/or clear boot partition select register.

CRs-Fixed: 459479
Change-Id: If09b25d73a25e59b4d6afbfbe7ee2bd07afb83c8
Signed-off-by: Pratik Patel <pratikp@codeaurora.org>
diff --git a/Documentation/devicetree/bindings/arm/msm/qcom-wdog-debug.txt b/Documentation/devicetree/bindings/arm/msm/qcom-wdog-debug.txt
deleted file mode 100644
index e5fd1b2..0000000
--- a/Documentation/devicetree/bindings/arm/msm/qcom-wdog-debug.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-* Qualcomm's Watchdog Debug Image Controller
-
-The Qualcomm's Watchdog debug image controller is used for enabling/disabling of
-watchdog debug image feature.
-
-Required properties:
-- compatible : should be "qcom,msm-wdog-debug"
-- reg : base page aligned physical base address of the controller and length of
-	memory mapped region.
-
-Example:
-
-	qcom,msm-wdog-debug@fc401000 {
-		compatible = "qcom,msm-wdogi-debug";
-		reg = <0xfc401000 0x1000>;
-	};
diff --git a/arch/arm/boot/dts/msm8974.dtsi b/arch/arm/boot/dts/msm8974.dtsi
index 2a5347e..d0b3c6d 100644
--- a/arch/arm/boot/dts/msm8974.dtsi
+++ b/arch/arm/boot/dts/msm8974.dtsi
@@ -1266,10 +1266,6 @@
 		interrupts = <0 29 1>;
 	};
 
-        qcom,msm-wdog-debug@fc401000 {
-               compatible = "qcom,msm-wdog-debug";
-               reg = <0xfc401000 0x1000>;
-        };
         qcom,msm-mem-hole {
                 compatible = "qcom,msm-mem-hole";
                 qcom,memblock-remove = <0x7f00000 0x8000000>; /* Address and Size of Hole */
diff --git a/arch/arm/mach-msm/Kconfig b/arch/arm/mach-msm/Kconfig
index 68fee3b..c7cb771 100644
--- a/arch/arm/mach-msm/Kconfig
+++ b/arch/arm/mach-msm/Kconfig
@@ -2843,12 +2843,12 @@
 	 does not have a direct access to the PMIC.
 
 config MSM_ENABLE_WDOG_DEBUG_CONTROL
-	bool "MSM Watchdog driver to disable debug Image"
+	bool "Enable control of watchdog debug and boot partition select"
 	help
-	 This driver supports the configuration of the GCC_WDOG_DEBUG register
-	 used to control debug image.
-	 This support is currently required for MSM8974 to disable debug image
-	 on PS HOLD reset
+	  Enables support for controlling watchdog debug and boot partition
+	  select. This is currently used to bypass debug image for PS_HOLD reset
+	  by disabling watchdog debug and boot partition select. This allows
+	  for a clean MSM reset for reboot scenarios.
 
 config MSM_FIQ
 	bool "Enable FIQ for debugging"
diff --git a/arch/arm/mach-msm/restart.c b/arch/arm/mach-msm/restart.c
index a67af45..d95f979 100644
--- a/arch/arm/mach-msm/restart.c
+++ b/arch/arm/mach-msm/restart.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -253,7 +253,7 @@
 		__raw_writel(0x31F3, msm_tmr0_base + WDT0_BITE_TIME);
 		__raw_writel(1, msm_tmr0_base + WDT0_EN);
 	} else {
-		/* Needed for 8974: Reset GCC_WDOG_DEBUG register */
+		/* Needed to bypass debug image on some chips */
 		msm_disable_wdog_debug();
 		__raw_writel(0, MSM_MPM2_PSHOLD_BASE);
 	}
diff --git a/arch/arm/mach-msm/wdog_debug.c b/arch/arm/mach-msm/wdog_debug.c
index 8b39d26..cccca26 100644
--- a/arch/arm/mach-msm/wdog_debug.c
+++ b/arch/arm/mach-msm/wdog_debug.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 and
@@ -10,144 +10,31 @@
  * GNU General Public License for more details.
  */
 
-#include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/io.h>
-#include <linux/delay.h>
-#include <linux/mutex.h>
-#include <linux/sched.h>
-#include <linux/of.h>
-#include <linux/platform_device.h>
+#include <linux/module.h>
 #include <mach/scm.h>
-#include <linux/slab.h>
 
-#define MODULE_NAME "wdog_debug"
-#define WDOG_DEBUG_EN 17
-#define GCC_WDOG_DEBUG_OFFSET 0x780
-
-struct msm_wdog_debug_data {
-	unsigned int __iomem phys_base;
-	size_t size;
-	void __iomem *base;
-	struct device *dev;
-};
-
-static struct msm_wdog_debug_data *wdog_data;
-
-void msm_disable_wdog_debug(void)
-{
-	unsigned long int value;
-
-	if (wdog_data == NULL)
-		return;
-	value = readl_relaxed(wdog_data->base + GCC_WDOG_DEBUG_OFFSET);
-	value &= ~BIT(WDOG_DEBUG_EN);
-	writel_relaxed(value, wdog_data->base + GCC_WDOG_DEBUG_OFFSET);
-
-	/* Ensure the WDOG_DEBUG_EN status has changed */
-	while (readl_relaxed(wdog_data->base + GCC_WDOG_DEBUG_OFFSET) &
-		BIT(WDOG_DEBUG_EN))
-			;
-}
-EXPORT_SYMBOL(msm_disable_wdog_debug);
+#define SCM_WDOG_DEBUG_BOOT_PART	0x9
+#define BOOT_PART_EN_VAL		0x5D1
 
 void msm_enable_wdog_debug(void)
 {
-	unsigned long int value;
+	int ret;
 
-	if (wdog_data == NULL)
-		return;
-	value = readl_relaxed(wdog_data->base + GCC_WDOG_DEBUG_OFFSET);
-	value |= BIT(WDOG_DEBUG_EN);
-	writel_relaxed(value, wdog_data->base + GCC_WDOG_DEBUG_OFFSET);
+	ret = scm_call_atomic2(SCM_SVC_BOOT,
+			       SCM_WDOG_DEBUG_BOOT_PART, 0, BOOT_PART_EN_VAL);
+	if (ret)
+		pr_err("failed to enable wdog debug\n");
 }
 EXPORT_SYMBOL(msm_enable_wdog_debug);
 
-static int __devexit msm_wdog_debug_remove(struct platform_device *pdev)
-{
-	kfree(wdog_data);
-	wdog_data = NULL;
-	pr_info("MSM wdog_debug Exit - Deactivated\n");
-	return 0;
-}
-
-static int __devinit msm_wdog_debug_dt_to_pdata(struct platform_device *pdev,
-					struct msm_wdog_debug_data *pdata)
-{
-	struct resource *wdog_resource;
-
-	wdog_resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!wdog_resource) {
-		dev_err(&pdev->dev, \
-		"%s cannot allocate resource for wdog_debug\n", \
-		 __func__);
-		return -ENXIO;
-	}
-	pdata->size = resource_size(wdog_resource);
-	pdata->phys_base = wdog_resource->start;
-	if (unlikely(!(devm_request_region(&pdev->dev, pdata->phys_base,
-					pdata->size, "msm-wdog-debug")))) {
-		dev_err(&pdev->dev, "%s cannot reserve wdog_debug region\n",
-								__func__);
-		return -ENXIO;
-	}
-	pdata->base  = devm_ioremap(&pdev->dev, pdata->phys_base,
-							pdata->size);
-	if (!pdata->base) {
-		dev_err(&pdev->dev, "%s cannot map wdog register space\n",
-				__func__);
-		return -ENXIO;
-	}
-
-	return 0;
-}
-
-static int __devinit msm_wdog_debug_probe(struct platform_device *pdev)
+void msm_disable_wdog_debug(void)
 {
 	int ret;
-	if (!pdev->dev.of_node)
-		return -ENODEV;
-	wdog_data = kzalloc(sizeof(struct msm_wdog_debug_data), GFP_KERNEL);
-	if (!wdog_data)
-		return -ENOMEM;
-	ret = msm_wdog_debug_dt_to_pdata(pdev, wdog_data);
+
+	ret = scm_call_atomic2(SCM_SVC_BOOT,
+			       SCM_WDOG_DEBUG_BOOT_PART, 1, 0);
 	if (ret)
-		goto err;
-	wdog_data->dev = &pdev->dev;
-	platform_set_drvdata(pdev, wdog_data);
-	return 0;
-err:
-	kzfree(wdog_data);
-	wdog_data = NULL;
-	return ret;
+		pr_err("failed to disable wdog debug\n");
 }
-
-static struct of_device_id msm_wdog_debug_match_table[] = {
-	{ .compatible = "qcom,msm-wdog-debug" },
-	{}
-};
-
-static struct platform_driver msm_wdog_debug_driver = {
-	.probe = msm_wdog_debug_probe,
-	.remove = msm_wdog_debug_remove,
-	.driver = {
-		.name = MODULE_NAME,
-		.owner = THIS_MODULE,
-		.of_match_table = msm_wdog_debug_match_table,
-	},
-};
-
-static int __devinit wdog_debug_init(void)
-{
-	return platform_driver_register(&msm_wdog_debug_driver);
-}
-module_init(wdog_debug_init);
-
-static void __exit wdog_debug_exit(void)
-{
-	platform_driver_unregister(&msm_wdog_debug_driver);
-}
-module_exit(wdog_debug_exit);
-
-MODULE_DESCRIPTION("MSM Driver to disable debug Image");
-MODULE_LICENSE("GPL v2");
+EXPORT_SYMBOL(msm_disable_wdog_debug);