linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Linux PM list <linux-pm@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Linux-sh list <linux-sh@vger.kernel.org>,
	Magnus Damm <magnus.damm@gmail.com>,
	Paul Mundt <lethal@linux-sh.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 13/15] sh: CMT: Basic runtime PM support
Date: Sun, 05 Aug 2012 23:48:57 +0000	[thread overview]
Message-ID: <201208060148.57556.rjw@sisk.pl> (raw)
In-Reply-To: <201208060138.03950.rjw@sisk.pl>


Modify the SH CMT clock source/clock event device driver to support
runtime PM at a basic level (i.e. device clocks can be disabled and
enabled, but domain power must be on, because the devices have to
be marked as "irq safe").

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/clocksource/sh_cmt.c |   44 +++++++++++++++++++++++++++++++++++--------
 1 file changed, 36 insertions(+), 8 deletions(-)

Index: linux/drivers/clocksource/sh_cmt.c
=================================--- linux.orig/drivers/clocksource/sh_cmt.c
+++ linux/drivers/clocksource/sh_cmt.c
@@ -33,6 +33,7 @@
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/pm_domain.h>
+#include <linux/pm_runtime.h>
 
 struct sh_cmt_priv {
 	void __iomem *mapbase;
@@ -52,6 +53,7 @@ struct sh_cmt_priv {
 	struct clock_event_device ced;
 	struct clocksource cs;
 	unsigned long total_cycles;
+	bool cs_enabled;
 };
 
 static DEFINE_RAW_SPINLOCK(sh_cmt_lock);
@@ -155,6 +157,9 @@ static int sh_cmt_enable(struct sh_cmt_p
 {
 	int k, ret;
 
+	pm_runtime_get_sync(&p->pdev->dev);
+	dev_pm_syscore_device(&p->pdev->dev, true);
+
 	/* enable clock */
 	ret = clk_enable(p->clk);
 	if (ret) {
@@ -221,6 +226,9 @@ static void sh_cmt_disable(struct sh_cmt
 
 	/* stop clock */
 	clk_disable(p->clk);
+
+	dev_pm_syscore_device(&p->pdev->dev, false);
+	pm_runtime_put(&p->pdev->dev);
 }
 
 /* private flags */
@@ -451,17 +459,26 @@ static int sh_cmt_clocksource_enable(str
 	int ret;
 	struct sh_cmt_priv *p = cs_to_sh_cmt(cs);
 
+	WARN_ON(p->cs_enabled);
+
 	p->total_cycles = 0;
 
 	ret = sh_cmt_start(p, FLAG_CLOCKSOURCE);
-	if (!ret)
+	if (!ret) {
 		__clocksource_updatefreq_hz(cs, p->rate);
+		p->cs_enabled = true;
+	}
 	return ret;
 }
 
 static void sh_cmt_clocksource_disable(struct clocksource *cs)
 {
-	sh_cmt_stop(cs_to_sh_cmt(cs), FLAG_CLOCKSOURCE);
+	struct sh_cmt_priv *p = cs_to_sh_cmt(cs);
+
+	WARN_ON(!p->cs_enabled);
+
+	sh_cmt_stop(p, FLAG_CLOCKSOURCE);
+	p->cs_enabled = false;
 }
 
 static void sh_cmt_clocksource_suspend(struct clocksource *cs)
@@ -693,6 +710,7 @@ static int sh_cmt_setup(struct sh_cmt_pr
 		dev_err(&p->pdev->dev, "registration failed\n");
 		goto err1;
 	}
+	p->cs_enabled = false;
 
 	ret = setup_irq(irq, &p->irqaction);
 	if (ret) {
@@ -711,18 +729,17 @@ err0:
 static int __devinit sh_cmt_probe(struct platform_device *pdev)
 {
 	struct sh_cmt_priv *p = platform_get_drvdata(pdev);
+	struct sh_timer_config *cfg = pdev->dev.platform_data;
 	int ret;
 
 	if (!is_early_platform_device(pdev)) {
-		struct sh_timer_config *cfg = pdev->dev.platform_data;
-
-		if (cfg->clocksource_rating || cfg->clockevent_rating)
-			dev_pm_syscore_device(&pdev->dev, true);
+		pm_runtime_set_active(&pdev->dev);
+		pm_runtime_enable(&pdev->dev);
 	}
 
 	if (p) {
 		dev_info(&pdev->dev, "kept as earlytimer\n");
-		return 0;
+		goto out;
 	}
 
 	p = kmalloc(sizeof(*p), GFP_KERNEL);
@@ -735,8 +752,19 @@ static int __devinit sh_cmt_probe(struct
 	if (ret) {
 		kfree(p);
 		platform_set_drvdata(pdev, NULL);
+		pm_runtime_idle(&pdev->dev);
+		return ret;
 	}
-	return ret;
+	if (is_early_platform_device(pdev))
+		return 0;
+
+ out:
+	if (cfg->clockevent_rating || cfg->clocksource_rating)
+		pm_runtime_irq_safe(&pdev->dev);
+	else
+		pm_runtime_idle(&pdev->dev);
+
+	return 0;
 }
 
 static int __devexit sh_cmt_remove(struct platform_device *pdev)


  parent reply	other threads:[~2012-08-05 23:48 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-29 14:12 [RFC][PATCH 0/6] PM: Suspend/resume for clock sources/clock event devices in PM domains Rafael J. Wysocki
2012-07-29 14:13 ` [RFC][PATCH 1/6] PM / Domains: Introduce simplified power on routine for system resume Rafael J. Wysocki
2012-07-29 14:14 ` [RFC][PATCH 2/6] PM / Domains: Add power off/on function for system core suspend stage Rafael J. Wysocki
2012-07-29 14:15 ` [RFC][PATCH 3/6] timekeeping: Add suspend and resume of clock event devices Rafael J. Wysocki
2012-07-29 14:16 ` [RFC][PATCH 4/6] sh: TMU: Introduce clocksource/clock events suspend/resume routines Rafael J. Wysocki
2012-07-29 14:16 ` [RFC][PATCH 5/6] sh: CMT: " Rafael J. Wysocki
2012-07-29 14:17 ` [RFC][PATCH 6/6] sh: MTU2: Introduce clock " Rafael J. Wysocki
2012-08-05 23:38 ` [PATCH 0/15] PM: Suspend/resume and runtime PM for clock sources/clock event devices in PM domains Rafael J. Wysocki
2012-08-05 23:39   ` [PATCH 1/15] PM / Domains: Introduce simplified power on routine for system resume Rafael J. Wysocki
2012-08-05 23:39   ` [PATCH 2/15] PM / Domains: Add power off/on function for system core suspend stage Rafael J. Wysocki
2012-08-05 23:40   ` [PATCH 3/15] timekeeping: Add suspend and resume of clock event devices Rafael J. Wysocki
2012-08-05 23:41   ` [PATCH 4/15] sh: TMU: Introduce clocksource/clock events suspend/resume routines Rafael J. Wysocki
2012-08-05 23:43   ` [PATCH 5/15] sh: CMT: " Rafael J. Wysocki
2012-08-05 23:43   ` [PATCH 6/15] sh: MTU2: Introduce clock " Rafael J. Wysocki
2012-08-05 23:44   ` [PATCH 7/15] PM: Reorganize device PM initialization Rafael J. Wysocki
2012-08-05 23:45   ` [PATCH 8/15] PM / Runtime: Allow helpers to be called by early platform drivers Rafael J. Wysocki
2012-08-05 23:45   ` [PATCH 9/15] PM / Domains: Rename the always_on device flag to syscore Rafael J. Wysocki
2012-08-05 23:46   ` [PATCH 10/15] PM / Domains: Move syscore flag from subsys data to struct device Rafael J. Wysocki
2012-08-05 23:47   ` [PATCH 11/15] PM / Domains: Do not measure start time for "irq safe" devices Rafael J. Wysocki
2012-08-05 23:48   ` [PATCH 12/15] sh: TMU: Basic runtime PM support Rafael J. Wysocki
2012-08-05 23:48   ` Rafael J. Wysocki [this message]
2012-08-05 23:49   ` [PATCH 14/15] sh: MTU2: " Rafael J. Wysocki
2012-08-11  9:39     ` Geert Uytterhoeven
2012-08-11 22:29       ` Rafael J. Wysocki
2012-08-05 23:53   ` [PATCH 15/15] PM: Do not use the syscore flag for runtime PM Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201208060148.57556.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).