linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: benoit.thebaudeau@advansee.com (Benoît Thébaudeau)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 7/8] pwm i.MX: fix clock lookup
Date: Wed, 5 Sep 2012 23:48:51 +0200 (CEST)	[thread overview]
Message-ID: <1698432111.3713458.1346881731396.JavaMail.root@advansee.com> (raw)
In-Reply-To: <1346852127-25226-8-git-send-email-s.hauer@pengutronix.de>

On Wednesday, September 5, 2012 3:35:26 PM, Sascha Hauer wrote:
> 
> From: Philipp Zabel <p.zabel@pengutronix.de>
> 
> The i.MX pwm core has two clocks: The ipg clock and the ipg highfreq
> (peripheral) clock. The ipg clock has to be enabled for this hardware
> to work. The actual pwm output can either be driven by the ipg clock
> or the ipg highfreq. The ipg highfreq has the advantage that it runs
> even when the SoC is in low power modes.
> This patch requests both clocks and enables the ipg clock for
> accessing
> registers and the peripheral clock to actually turn on the pwm.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/pwm/pwm-imx.c |   33 +++++++++++++++++++++++++--------
>  1 file changed, 25 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c
> index b234288..5b03ace 100644
> --- a/drivers/pwm/pwm-imx.c
> +++ b/drivers/pwm/pwm-imx.c
> @@ -40,7 +40,8 @@
>  #define MX3_PWMCR_EN              (1 << 0)
>  
>  struct imx_chip {
> -	struct clk	*clk;
> +	struct clk	*clk_per;
> +	struct clk	*clk_ipg;
>  
>  	int		enabled;
>  	void __iomem	*mmio_base;
> @@ -105,7 +106,7 @@ static int imx_pwm_config_v2(struct pwm_chip
> *chip,
>  	unsigned long period_cycles, duty_cycles, prescale;
>  	u32 cr;
>  
> -	c = clk_get_rate(imx->clk);
> +	c = clk_get_rate(imx->clk_per);
>  	c = c * period_ns;
>  	do_div(c, 1000000000);
>  	period_cycles = c;
> @@ -160,8 +161,15 @@ static int imx_pwm_config(struct pwm_chip *chip,
>  		struct pwm_device *pwm, int duty_ns, int period_ns)
>  {
>  	struct imx_chip *imx = to_imx_chip(chip);
> +	int ret;
>  
> -	return imx->config(chip, pwm, duty_ns, period_ns);
> +	clk_prepare_enable(imx->clk_ipg);

Why don't you test the return value like in imx_pwm_enable()?

> +
> +	ret = imx->config(chip, pwm, duty_ns, period_ns);
> +
> +	clk_disable_unprepare(imx->clk_ipg);
> +
> +	return ret;
>  }
>  
>  static int imx_pwm_enable(struct pwm_chip *chip, struct pwm_device
>  *pwm)
> @@ -169,7 +177,7 @@ static int imx_pwm_enable(struct pwm_chip *chip,
> struct pwm_device *pwm)
>  	struct imx_chip *imx = to_imx_chip(chip);
>  	int rc;
>  
> -	rc = clk_prepare_enable(imx->clk);
> +	rc = clk_prepare_enable(imx->clk_per);
>  	if (rc)
>  		return rc;
>  
> @@ -186,7 +194,7 @@ static void imx_pwm_disable(struct pwm_chip
> *chip, struct pwm_device *pwm)
>  
>  	imx->set_enable(chip, false);
>  
> -	clk_disable_unprepare(imx->clk);
> +	clk_disable_unprepare(imx->clk_per);
>  	imx->enabled = 0;
>  }
>  
> @@ -238,10 +246,19 @@ static int __devinit imx_pwm_probe(struct
> platform_device *pdev)
>  		return -ENOMEM;
>  	}
>  
> -	imx->clk = devm_clk_get(&pdev->dev, "pwm");
> +	imx->clk_per = devm_clk_get(&pdev->dev, "per");
> +	if (IS_ERR(imx->clk_per)) {
> +		dev_err(&pdev->dev, "getting per clock failed with %ld\n",
> +				PTR_ERR(imx->clk_per));
> +		return PTR_ERR(imx->clk_per);
> +	}
>  
> -	if (IS_ERR(imx->clk))
> -		return PTR_ERR(imx->clk);
> +	imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
> +	if (IS_ERR(imx->clk_ipg)) {
> +		dev_err(&pdev->dev, "getting ipg clock failed with %ld\n",
> +				PTR_ERR(imx->clk_ipg));
> +		return PTR_ERR(imx->clk_ipg);
> +	}
>  
>  	imx->chip.ops = &imx_pwm_ops;
>  	imx->chip.dev = &pdev->dev;

I have reviewed the whole series. Apart from the comments I made, it looks good
to me.

Best regards,
Beno?t

  reply	other threads:[~2012-09-05 21:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-05 13:35 [PATCH v2] pwm i.MX: add devicetree support Sascha Hauer
2012-09-05 13:35 ` [PATCH 1/8] pwm i.MX: factor out SoC specific functions Sascha Hauer
2012-09-05 13:35 ` [PATCH 2/8] pwm i.MX: remove unnecessary if in pwm_[en|dis]able Sascha Hauer
2012-09-05 13:35 ` [PATCH 3/8] pwm i.MX: add functions to enable/disable pwm Sascha Hauer
2012-09-05 13:35 ` [PATCH 4/8] pwm i.MX: Use module_platform_driver Sascha Hauer
2012-09-05 13:35 ` [PATCH 5/8] pwm i.MX: add devicetree support Sascha Hauer
2012-09-05 21:42   ` Benoît Thébaudeau
2012-09-06  6:58     ` Sascha Hauer
2012-09-05 13:35 ` [PATCH 6/8] pwm i.MX: use per clock unconditionally Sascha Hauer
2012-09-05 13:35 ` [PATCH 7/8] pwm i.MX: fix clock lookup Sascha Hauer
2012-09-05 21:48   ` Benoît Thébaudeau [this message]
2012-09-06  7:15     ` Sascha Hauer
2012-09-05 13:35 ` [PATCH 8/8] ARM i.MX53: Add pwm support Sascha Hauer
2012-09-06  8:19 ` [PATCH v2] pwm i.MX: add devicetree support Shawn Guo

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=1698432111.3713458.1346881731396.JavaMail.root@advansee.com \
    --to=benoit.thebaudeau@advansee.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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).