linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cao Van Dong <cv-dong@jinso.co.jp>
To: linux-renesas-soc@vger.kernel.org, thierry.reding@gmail.com,
	horms+renesas@verge.net.au, geert+renesas@glider.be,
	broonie@kernel.org, linux-pwm@vger.kernel.org
Cc: yoshihiro.shimoda.uh@renesas.com,
	kuninori.morimoto.gx@renesas.com, h-inayoshi@jinso.co.jp,
	na-hoan@jinso.co.jp, cv-dong@jinso.co.jp
Subject: [PATCH] pwm: renesas-tpu: Add suspend/resume function
Date: Wed, 22 May 2019 17:06:19 +0900	[thread overview]
Message-ID: <1558512379-8858-1-git-send-email-cv-dong@jinso.co.jp> (raw)

This patch adds suspend/resume function support for Renesas the 16-Bit Timer
Pulse Unit (TPU) driver. This has been tested on the Salvator-XS board 
with R-Car M3-N and H3 at renesas-drivers-2019-05-21-v5.2-rc1 tag.
I expect this to work on other SoCs.

Test procedure:
  - Enable TPU and pin control in DTS.
  - Make sure switches { SW29-[1-2] are switched off or 
    SW31-[1-4] are switched off(only for Salvator-xs) }.
  - Exercise userspace PWM control for pwm[2,3] 
    of /sys/class/pwm/pwmchip1/ .
  - Inspect PWM signals on the input side of { CN29-[58,60] 
    or SW31-[1,2] (only for Salvator-xs) }
    before and after suspend/resume using an oscilloscope. 

Signed-off-by: Cao Van Dong <cv-dong@jinso.co.jp>
Tested-by: Cao Van Dong <cv-dong@jinso.co.jp>
---
 drivers/pwm/pwm-renesas-tpu.c | 49 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/drivers/pwm/pwm-renesas-tpu.c b/drivers/pwm/pwm-renesas-tpu.c
index 4a855a2..97b026e 100644
--- a/drivers/pwm/pwm-renesas-tpu.c
+++ b/drivers/pwm/pwm-renesas-tpu.c
@@ -366,6 +366,54 @@ static void tpu_pwm_disable(struct pwm_chip *chip, struct pwm_device *_pwm)
 	tpu_pwm_timer_stop(pwm);
 }
 
+#ifdef CONFIG_PM_SLEEP
+static struct pwm_device *tpu_pwm_dev_to_pwm_dev(struct device *dev)
+{
+	struct tpu_device *tpu = dev_get_drvdata(dev);
+	struct pwm_chip *chip = &tpu->chip;
+
+	if((pwm_get_chip_data(&chip->pwms[0])) != NULL)
+		return &chip->pwms[0];
+	if((pwm_get_chip_data(&chip->pwms[1])) != NULL)
+		return &chip->pwms[1];
+	if((pwm_get_chip_data(&chip->pwms[2])) != NULL)
+		return &chip->pwms[2];
+	if((pwm_get_chip_data(&chip->pwms[3])) != NULL)
+		return &chip->pwms[3];
+
+	return NULL;
+}
+
+static int tpu_pwm_suspend(struct device *dev)
+{
+	struct pwm_device *pwm = tpu_pwm_dev_to_pwm_dev(dev);
+
+	if (!test_bit(PWMF_REQUESTED, &pwm->flags))
+		return 0;
+
+	pm_runtime_put(dev);
+
+	return 0;
+}
+
+static int tpu_pwm_resume(struct device *dev)
+{
+	struct pwm_device *pwm = tpu_pwm_dev_to_pwm_dev(dev);
+
+	if ((!test_bit(PWMF_REQUESTED, &pwm->flags)) || pwm == NULL)
+		return 0;
+
+	pm_runtime_get_sync(dev);
+
+	/* Restart timer */
+	tpu_pwm_disable(pwm->chip,pwm);
+	tpu_pwm_enable(pwm->chip,pwm);
+
+	return 0;
+}
+#endif /* CONFIG_PM_SLEEP */
+static SIMPLE_DEV_PM_OPS(tpu_pwm_pm_ops, tpu_pwm_suspend, tpu_pwm_resume);
+
 static const struct pwm_ops tpu_pwm_ops = {
 	.request = tpu_pwm_request,
 	.free = tpu_pwm_free,
@@ -459,6 +507,7 @@ static struct platform_driver tpu_driver = {
 	.remove		= tpu_remove,
 	.driver		= {
 		.name	= "renesas-tpu-pwm",
+		.pm		= &tpu_pwm_pm_ops,
 		.of_match_table = of_match_ptr(tpu_of_table),
 	}
 };
-- 
2.7.4


             reply	other threads:[~2019-05-22  8:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-22  8:06 Cao Van Dong [this message]
2019-05-23  0:29 ` [PATCH] pwm: renesas-tpu: Add suspend/resume function Cao Van Dong

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=1558512379-8858-1-git-send-email-cv-dong@jinso.co.jp \
    --to=cv-dong@jinso.co.jp \
    --cc=broonie@kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=h-inayoshi@jinso.co.jp \
    --cc=horms+renesas@verge.net.au \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=na-hoan@jinso.co.jp \
    --cc=thierry.reding@gmail.com \
    --cc=yoshihiro.shimoda.uh@renesas.com \
    /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).