From 317aa33993ed2a7a9de10501bddc76a9a5fafa50 Mon Sep 17 00:00:00 2001
From: Heiko Stuebner <heiko@sntech.de>
Date: Thu, 22 Dec 2011 15:23:05 +0100
Subject: [PATCH] S3C2443: add power domain for usb phy

This makes it possible to remove the raw write to the PWRCFG-register
from the s3c-hsudc driver.

The phy-power-handling is common to S3C2443/2416/2450, so introduce a
s3c2443-pm-common.c to handle this for all of them.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
 arch/arm/mach-s3c2416/Kconfig             |    1 +
 arch/arm/mach-s3c2443/Kconfig             |    1 +
 arch/arm/plat-s3c24xx/Kconfig             |    7 ++++
 arch/arm/plat-s3c24xx/Makefile            |    1 +
 arch/arm/plat-s3c24xx/s3c2443-pm-common.c |   49 +++++++++++++++++++++++++++++
 5 files changed, 59 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/plat-s3c24xx/s3c2443-pm-common.c

diff --git a/arch/arm/mach-s3c2416/Kconfig b/arch/arm/mach-s3c2416/Kconfig
index 380a710..00bd088 100644
--- a/arch/arm/mach-s3c2416/Kconfig
+++ b/arch/arm/mach-s3c2416/Kconfig
@@ -15,6 +15,7 @@ config CPU_S3C2416
 	select CPU_LLSERIAL_S3C2440
 	select SAMSUNG_CLKSRC
 	select S3C2443_CLOCK
+	select S3C2443_PM_COMMON
 	help
 	  Support for the S3C2416 SoC from the S3C24XX line
 
diff --git a/arch/arm/mach-s3c2443/Kconfig b/arch/arm/mach-s3c2443/Kconfig
index 8814031..3bff23f 100644
--- a/arch/arm/mach-s3c2443/Kconfig
+++ b/arch/arm/mach-s3c2443/Kconfig
@@ -10,6 +10,7 @@ config CPU_S3C2443
 	select CPU_LLSERIAL_S3C2440
 	select SAMSUNG_CLKSRC
 	select S3C2443_CLOCK
+	select S3C2443_PM_COMMON
 	help
 	  Support for the S3C2443 SoC from the S3C24XX line
 
diff --git a/arch/arm/plat-s3c24xx/Kconfig b/arch/arm/plat-s3c24xx/Kconfig
index d8973ac..0a9f37c 100644
--- a/arch/arm/plat-s3c24xx/Kconfig
+++ b/arch/arm/plat-s3c24xx/Kconfig
@@ -50,6 +50,13 @@ config S3C2443_CLOCK
 	  Clock code for the S3C2443 and similar processors, which includes
 	  the S3C2416 and S3C2450.
 
+config S3C2443_PM_COMMON
+	bool
+	select PM_GENERIC_DOMAINS
+	help
+	  Common power management code for the S3C2443 and similar processors,
+	  which include the S3C2416 and S3C2450.
+
 config S3C24XX_DCLK
 	bool
 	help
diff --git a/arch/arm/plat-s3c24xx/Makefile b/arch/arm/plat-s3c24xx/Makefile
index b2b0112..300f77c 100644
--- a/arch/arm/plat-s3c24xx/Makefile
+++ b/arch/arm/plat-s3c24xx/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_PM)		+= irq-pm.o
 obj-$(CONFIG_PM)		+= sleep.o
 obj-$(CONFIG_S3C2410_CLOCK)	+= s3c2410-clock.o
 obj-$(CONFIG_S3C2443_CLOCK)	+= s3c2443-clock.o
+obj-$(CONFIG_S3C2443_PM_COMMON)	+= s3c2443-pm-common.o
 obj-$(CONFIG_S3C2410_DMA)	+= dma.o
 obj-$(CONFIG_S3C2410_IOTIMING)	+= s3c2410-iotiming.o
 obj-$(CONFIG_S3C2412_IOTIMING)	+= s3c2412-iotiming.o
diff --git a/arch/arm/plat-s3c24xx/s3c2443-pm-common.c b/arch/arm/plat-s3c24xx/s3c2443-pm-common.c
new file mode 100644
index 0000000..9121276
--- /dev/null
+++ b/arch/arm/plat-s3c24xx/s3c2443-pm-common.c
@@ -0,0 +1,49 @@
+#include <linux/io.h>
+#include <linux/pm_domain.h>
+
+#include <mach/regs-s3c2443-clock.h>
+#include <plat/devs.h>
+
+
+static int s3c2443_usbphy_off(struct generic_pm_domain *domain)
+{
+	u32 val;
+
+	val = __raw_readl(S3C2443_PWRCFG);
+	val &= ~(S3C2443_PWRCFG_USBPHY);
+	__raw_writel(val, S3C2443_PWRCFG);
+
+	return 0;
+}
+
+static int s3c2443_usbphy_on(struct generic_pm_domain *domain)
+{
+	u32 val;
+
+	val = __raw_readl(S3C2443_PWRCFG);
+	val |= S3C2443_PWRCFG_USBPHY;
+	__raw_writel(val, S3C2443_PWRCFG);
+
+	return 0;
+}
+
+static struct generic_pm_domain s3c2443_usbphy_pd = {
+	.power_off = s3c2443_usbphy_off,
+	.power_on = s3c2443_usbphy_on,
+};
+
+static int __init s3c2443_pm_common_init(void)
+{
+	pm_genpd_init(&s3c2443_usbphy_pd, NULL, false);
+	pm_genpd_add_device(&s3c2443_usbphy_pd, &s3c_device_usb_hsudc.dev);
+
+	return 0;
+}
+arch_initcall(s3c2443_pm_common_init);
+
+static __init int s3c2443_pm_common_late_initcall(void)
+{
+	pm_genpd_poweroff_unused();
+	return 0;
+}
+late_initcall(s3c2443_pm_common_late_initcall);
-- 
1.7.5.4

