Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1276622
| Path | csiph.com!news.mixmin.net!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Thierry Reding <thierry.reding@gmail.com> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] pwm: berlin: Add PM support |
| Date | Tue, 24 Nov 2015 17:30:05 +0100 |
| Message-ID | <qyoDH-262-87@gated-at.bofh.it> (permalink) |
| References | <qyeEi-3VK-1@gated-at.bofh.it> |
| X-Original-To | Jisheng Zhang <jszhang@marvell.com> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=5D0CuhiGb8Ic0oO7xY6qwAgSz3hl2tvGxwy5XqQ2Lqw=; b=oXkp9Fd6kDn3KTZvOEgoR4kcKn6OoLoe6a9BTC+wwxJL4Ysv9FvJLxCuo4bIakNVbZ 0jRg/o1Sb3eQG5rNk05bX5s52C+ui1yRzsXEOO5iUqCeT1zOPRmUFp3zNV/YkDuawGgQ zhP32p0aafosyN7Rmt/knZMvmA18vhMbMuvj7ztLGw9Jl729Cw8i9K3xDCm6XcsAL70K eczSrxE/k5V5DPaofDNIaricZENPQNfeY6Tb8RIr/5Sjv0dQ0TBDzcEFXP9Ec6z0LVB3 5N6dcebuDLtd7ZVUL6hPqUHUYDe8exXAeoXQsMhao8posdcDl5GObbqPyWnqvLaJ3WYi LyPw== |
| X-Received | by 10.66.248.106 with SMTP id yl10mr43461511pac.140.1448382190602; Tue, 24 Nov 2015 08:23:10 -0800 (PST) |
| MIME-Version | 1.0 |
| Content-Type | multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="7gGkHNMELEOhSGF6" |
| Content-Disposition | inline |
| User-Agent | Mutt/1.5.23+102 (2ca89bed6448) (2014-03-12) |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 147 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | sebastian.hesselbarth@gmail.com, antoine.tenart@free-electrons.com, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org |
| X-Original-Date | Tue, 24 Nov 2015 17:23:06 +0100 |
| X-Original-Message-ID | <20151124162306.GC32623@ulmo.nvidia.com> |
| X-Original-References | <1448343785-1540-1-git-send-email-jszhang@marvell.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1276622 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On Tue, Nov 24, 2015 at 01:43:05PM +0800, Jisheng Zhang wrote:
> 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];
Please don't do this. You can easily attach per-PWM data using the
pwm_set_chip_data() function and retrieve it using pwm_get_chip_data().
> };
>
> 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;
unsigned int, please.
> + 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;
unsigned int, please.
> + struct berlin_pwm_chip *pwm = dev_get_drvdata(dev);
> +
> + clk_prepare_enable(pwm->clk);
Always check the return value of this function.
> + 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
This is a weird way of writing this. I think a more typical way would be
to have the #ifdef contain only the implementation and then define the
dev_pm_ops variable unconditonally, so you don't need a separate macro
for it.
Thierry
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] pwm: berlin: Add PM support Jisheng Zhang <jszhang@marvell.com> - 2015-11-24 06:50 +0100
Re: [PATCH] pwm: berlin: Add PM support Thierry Reding <thierry.reding@gmail.com> - 2015-11-24 17:30 +0100
Re: [PATCH] pwm: berlin: Add PM support Jisheng Zhang <jszhang@marvell.com> - 2015-11-25 09:40 +0100
Re: [PATCH] pwm: berlin: Add PM support Thierry Reding <thierry.reding@gmail.com> - 2015-11-25 16:20 +0100
Re: [PATCH] pwm: berlin: Add PM support Jisheng Zhang <jszhang@marvell.com> - 2015-11-26 08:50 +0100
csiph-web