diff mbox

[v7,10/12] OMAP: dmtimer: pm_runtime support

Message ID 1292882719-30255-11-git-send-email-tarun.kanti@ti.com (mailing list archive)
State New, archived
Delegated to: Tony Lindgren
Headers show

Commit Message

Tarun Kanti DebBarma Dec. 20, 2010, 10:05 p.m. UTC
None
diff mbox

Patch

diff --git a/arch/arm/plat-omap/dmtimer.c b/arch/arm/plat-omap/dmtimer.c
index b66f122..0fcc242 100644
--- a/arch/arm/plat-omap/dmtimer.c
+++ b/arch/arm/plat-omap/dmtimer.c
@@ -39,6 +39,7 @@ 
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/slab.h>
+#include <linux/pm_runtime.h>
 #include <linux/err.h>
 #include <plat/dmtimer.h>
 
@@ -212,13 +213,16 @@  static void omap_dm_timer_prepare(struct omap_dm_timer *timer)
 {
 	struct dmtimer_platform_data *pdata = timer->pdev->dev.platform_data;
 
-	timer->fclk = clk_get(&timer->pdev->dev, "fck");
-	if (WARN_ON_ONCE(IS_ERR_OR_NULL(timer->fclk))) {
-		dev_err(&timer->pdev->dev, ": No fclk handle.\n");
-		return;
+	if (!pdata->is_omap16xx) {
+		timer->fclk = clk_get(&timer->pdev->dev, "fck");
+		if (WARN_ON_ONCE(IS_ERR_OR_NULL(timer->fclk))) {
+			dev_err(&timer->pdev->dev, ": No fclk handle.\n");
+			return;
+		}
 	}
 
-	omap_dm_timer_enable(timer);
+	if (!pdata->is_omap16xx)
+		omap_dm_timer_enable(timer);
 
 	if (pdata->dm_timer_reset)
 		pdata->dm_timer_reset(timer);
@@ -293,10 +297,22 @@  EXPORT_SYMBOL_GPL(omap_dm_timer_free);
 
 void omap_dm_timer_enable(struct omap_dm_timer *timer)
 {
+	struct dmtimer_platform_data *pdata = timer->pdev->dev.platform_data;
+
 	if (timer->enabled)
 		return;
 
-	clk_enable(timer->fclk);
+	if (unlikely(pdata->is_early_init)) {
+		clk_enable(timer->fclk);
+		timer->enabled = 1;
+		return;
+	}
+
+	if (pm_runtime_get_sync(&timer->pdev->dev) < 0) {
+		dev_err(&timer->pdev->dev, "%s: pm_runtime_get_sync() FAILED\n",
+			__func__);
+		return;
+	}
 
 	timer->enabled = 1;
 }
@@ -304,10 +320,22 @@  EXPORT_SYMBOL_GPL(omap_dm_timer_enable);
 
 void omap_dm_timer_disable(struct omap_dm_timer *timer)
 {
+	struct dmtimer_platform_data *pdata = timer->pdev->dev.platform_data;
+
 	if (!timer->enabled)
 		return;
 
-	clk_disable(timer->fclk);
+	if (unlikely(pdata->is_early_init)) {
+		clk_disable(timer->fclk);
+		timer->enabled = 0;
+		return;
+	}
+
+	if (pm_runtime_put_sync(&timer->pdev->dev) < 0) {
+		dev_err(&timer->pdev->dev, "%s: pm_runtime_put_sync() FAILED\n",
+			__func__);
+		return;
+	}
 
 	timer->enabled = 0;
 }
@@ -425,12 +453,14 @@  int omap_dm_timer_set_source(struct omap_dm_timer *timer, int source)
 	if (source < 0 || source >= 3)
 		return -EINVAL;
 
-	omap_dm_timer_disable(timer);
+	if (!pdata->is_omap16xx)
+		omap_dm_timer_disable(timer);
 
 	/* change the timer clock source */
 	ret = pdata->set_timer_src(timer->pdev, source);
 
-	omap_dm_timer_enable(timer);
+	if (!pdata->is_omap16xx)
+		omap_dm_timer_enable(timer);
 
 	/*
 	 * When the functional clock disappears, too quick writes seem
@@ -604,11 +634,21 @@  static int __devinit omap_dm_timer_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	/* OMAP2+
+	 * Early timers are already registered and in list.
+	 * What we need to do during second phase of probe
+	 * is to assign the newly allocated/configured pdev
+	 * to timer->pdev. We also call pm_runtime_enable()
+	 * for each device because it could not be called
+	 * during early boot because pm_runtime framework
+	 * was not yet up and running.
+	 */
 	spin_lock_irqsave(&dm_timer_lock, flags);
 	list_for_each_entry(timer, &omap_timer_list, node)
 		if (!pdata->is_early_init && timer->id == pdev->id) {
 			timer->pdev = pdev;
 			spin_unlock_irqrestore(&dm_timer_lock, flags);
+			pm_runtime_enable(&pdev->dev);
 			dev_dbg(&pdev->dev, "Regular Probed\n");
 			return 0;
 		}
@@ -659,6 +699,8 @@  static int __devinit omap_dm_timer_probe(struct platform_device *pdev)
 		pdata->dm_timer_read_reg = omap_dm_timer_read_reg;
 		pdata->dm_timer_write_reg = omap_dm_timer_write_reg;
 		pdata->is_early_init = 0;
+		pm_runtime_enable(&pdev->dev);
+		dev_dbg(&pdev->dev, " pm_runtime enabled\n");
 	}
 
 	timer->id = pdev->id;