From: Jisheng Zhang <jszhang@marvell.com>
To: <thierry.reding@gmail.com>, <sebastian.hesselbarth@gmail.com>,
<antoine.tenart@free-electrons.com>
Cc: <linux-pwm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
Jisheng Zhang <jszhang@marvell.com>
Subject: [PATCH] pwm: berlin: Add PM support
Date: Tue, 24 Nov 2015 13:43:05 +0800 [thread overview]
Message-ID: <1448343785-1540-1-git-send-email-jszhang@marvell.com> (raw)
This patch adds S2R support for berlin pwm driver.
Signed-off-by: Jisheng Zhang <jszhang@marvell.com>
---
drivers/pwm/pwm-berlin.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 1 deletion(-)
diff --git a/drivers/pwm/pwm-berlin.c b/drivers/pwm/pwm-berlin.c
index 6510812..2afdb40 100644
--- a/drivers/pwm/pwm-berlin.c
+++ b/drivers/pwm/pwm-berlin.c
@@ -27,10 +27,20 @@
#define BERLIN_PWM_TCNT 0xc
#define BERLIN_PWM_MAX_TCNT 65535
+#define NUM_PWM_CHANNEL 4 /* berlin PWM channels */
+
+struct berlin_pwm_context {
+ u32 enable;
+ u32 ctrl;
+ u32 duty;
+ u32 tcnt;
+};
+
struct berlin_pwm_chip {
struct pwm_chip chip;
struct clk *clk;
void __iomem *base;
+ struct berlin_pwm_context ctx[NUM_PWM_CHANNEL];
};
static inline struct berlin_pwm_chip *to_berlin_pwm_chip(struct pwm_chip *chip)
@@ -176,7 +186,7 @@ static int berlin_pwm_probe(struct platform_device *pdev)
pwm->chip.dev = &pdev->dev;
pwm->chip.ops = &berlin_pwm_ops;
pwm->chip.base = -1;
- pwm->chip.npwm = 4;
+ pwm->chip.npwm = NUM_PWM_CHANNEL;
pwm->chip.can_sleep = true;
pwm->chip.of_xlate = of_pwm_xlate_with_flags;
pwm->chip.of_pwm_n_cells = 3;
@@ -204,12 +214,57 @@ static int berlin_pwm_remove(struct platform_device *pdev)
return ret;
}
+#ifdef CONFIG_PM_SLEEP
+static int berlin_pwm_suspend(struct device *dev)
+{
+ int i;
+ struct berlin_pwm_chip *pwm = dev_get_drvdata(dev);
+
+ for (i = 0; i < pwm->chip.npwm; i++) {
+ struct berlin_pwm_context *ctx = &pwm->ctx[i];
+
+ ctx->enable = berlin_pwm_readl(pwm, i, BERLIN_PWM_ENABLE);
+ ctx->ctrl = berlin_pwm_readl(pwm, i, BERLIN_PWM_CONTROL);
+ ctx->duty = berlin_pwm_readl(pwm, i, BERLIN_PWM_DUTY);
+ ctx->tcnt = berlin_pwm_readl(pwm, i, BERLIN_PWM_TCNT);
+ }
+ clk_disable_unprepare(pwm->clk);
+
+ return 0;
+}
+
+static int berlin_pwm_resume(struct device *dev)
+{
+ int i;
+ struct berlin_pwm_chip *pwm = dev_get_drvdata(dev);
+
+ clk_prepare_enable(pwm->clk);
+ for (i = 0; i < pwm->chip.npwm; i++) {
+ struct berlin_pwm_context *ctx = &pwm->ctx[i];
+
+ berlin_pwm_writel(pwm, i, ctx->ctrl, BERLIN_PWM_CONTROL);
+ berlin_pwm_writel(pwm, i, ctx->duty, BERLIN_PWM_DUTY);
+ berlin_pwm_writel(pwm, i, ctx->tcnt, BERLIN_PWM_TCNT);
+ berlin_pwm_writel(pwm, i, ctx->enable, BERLIN_PWM_ENABLE);
+ }
+
+ return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(berlin_pwm_pm_ops, berlin_pwm_suspend,
+ berlin_pwm_resume);
+#define BERLIN_PWM_PM_OPS (&berlin_pwm_pm_ops)
+#else
+#define BERLIN_PWM_PM_OPS NULL
+#endif
+
static struct platform_driver berlin_pwm_driver = {
.probe = berlin_pwm_probe,
.remove = berlin_pwm_remove,
.driver = {
.name = "berlin-pwm",
.of_match_table = berlin_pwm_match,
+ .pm = BERLIN_PWM_PM_OPS,
},
};
module_platform_driver(berlin_pwm_driver);
--
2.6.2
next reply other threads:[~2015-11-24 5:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-24 5:43 Jisheng Zhang [this message]
2015-11-24 16:23 ` Thierry Reding
2015-11-25 8:30 ` Jisheng Zhang
2015-11-25 15:16 ` Thierry Reding
2015-11-26 7:41 ` Jisheng Zhang
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=1448343785-1540-1-git-send-email-jszhang@marvell.com \
--to=jszhang@marvell.com \
--cc=antoine.tenart@free-electrons.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=sebastian.hesselbarth@gmail.com \
--cc=thierry.reding@gmail.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
all inboxes | Powered by JetHome®