linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: lpc18xx_adc: Reorder clk_get_rate function call
@ 2021-10-24 19:43 André Gustavo Nakagomi Lopez
  2021-10-24 20:12 ` Vladimir Zapolskiy
  0 siblings, 1 reply; 3+ messages in thread
From: André Gustavo Nakagomi Lopez @ 2021-10-24 19:43 UTC (permalink / raw)
  To: jic23, lars, vz; +Cc: linux-iio, linux-arm-kernel, linux-kernel, andregnl

clk_get_rate is not garanteed to work if called before clk_prepare_enable.

Reorder clk_get_rate, so it's called after clk_prepare_enable and
after devm_add_action_or_reset of lpc18xx_clk_disable.

Signed-off-by: André Gustavo Nakagomi Lopez <andregnl@usp.br>
---
 drivers/iio/adc/lpc18xx_adc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/adc/lpc18xx_adc.c b/drivers/iio/adc/lpc18xx_adc.c
index ceefa4d793cf..ae9c9384f23e 100644
--- a/drivers/iio/adc/lpc18xx_adc.c
+++ b/drivers/iio/adc/lpc18xx_adc.c
@@ -157,9 +157,6 @@ static int lpc18xx_adc_probe(struct platform_device *pdev)
 		return dev_err_probe(&pdev->dev, PTR_ERR(adc->clk),
 				     "error getting clock\n");
 
-	rate = clk_get_rate(adc->clk);
-	clkdiv = DIV_ROUND_UP(rate, LPC18XX_ADC_CLK_TARGET);
-
 	adc->vref = devm_regulator_get(&pdev->dev, "vref");
 	if (IS_ERR(adc->vref))
 		return dev_err_probe(&pdev->dev, PTR_ERR(adc->vref),
@@ -192,6 +189,9 @@ static int lpc18xx_adc_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	rate = clk_get_rate(adc->clk);
+	clkdiv = DIV_ROUND_UP(rate, LPC18XX_ADC_CLK_TARGET);
+
 	adc->cr_reg = (clkdiv << LPC18XX_ADC_CR_CLKDIV_SHIFT) |
 			LPC18XX_ADC_CR_PDN;
 	writel(adc->cr_reg, adc->base + LPC18XX_ADC_CR);
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: lpc18xx_adc: Reorder clk_get_rate function call
  2021-10-24 19:43 [PATCH] iio: adc: lpc18xx_adc: Reorder clk_get_rate function call André Gustavo Nakagomi Lopez
@ 2021-10-24 20:12 ` Vladimir Zapolskiy
  2021-10-25 12:18   ` André Gustavo Nakagomi Lopez
  0 siblings, 1 reply; 3+ messages in thread
From: Vladimir Zapolskiy @ 2021-10-24 20:12 UTC (permalink / raw)
  To: André Gustavo Nakagomi Lopez, jic23, lars
  Cc: linux-iio, linux-arm-kernel, linux-kernel

Hi André,

On 10/24/21 10:43 PM, André Gustavo Nakagomi Lopez wrote:
> clk_get_rate is not garanteed to work if called before clk_prepare_enable.

typo, s/garanteed/guaranteed/

> 
> Reorder clk_get_rate, so it's called after clk_prepare_enable and
> after devm_add_action_or_reset of lpc18xx_clk_disable.
> 
> Signed-off-by: André Gustavo Nakagomi Lopez <andregnl@usp.br>
> ---
>   drivers/iio/adc/lpc18xx_adc.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/adc/lpc18xx_adc.c b/drivers/iio/adc/lpc18xx_adc.c
> index ceefa4d793cf..ae9c9384f23e 100644
> --- a/drivers/iio/adc/lpc18xx_adc.c
> +++ b/drivers/iio/adc/lpc18xx_adc.c
> @@ -157,9 +157,6 @@ static int lpc18xx_adc_probe(struct platform_device *pdev)
>   		return dev_err_probe(&pdev->dev, PTR_ERR(adc->clk),
>   				     "error getting clock\n");
>   
> -	rate = clk_get_rate(adc->clk);
> -	clkdiv = DIV_ROUND_UP(rate, LPC18XX_ADC_CLK_TARGET);
> -
>   	adc->vref = devm_regulator_get(&pdev->dev, "vref");
>   	if (IS_ERR(adc->vref))
>   		return dev_err_probe(&pdev->dev, PTR_ERR(adc->vref),
> @@ -192,6 +189,9 @@ static int lpc18xx_adc_probe(struct platform_device *pdev)
>   	if (ret)
>   		return ret;
>   
> +	rate = clk_get_rate(adc->clk);
> +	clkdiv = DIV_ROUND_UP(rate, LPC18XX_ADC_CLK_TARGET);
> +
>   	adc->cr_reg = (clkdiv << LPC18XX_ADC_CR_CLKDIV_SHIFT) |
>   			LPC18XX_ADC_CR_PDN;
>   	writel(adc->cr_reg, adc->base + LPC18XX_ADC_CR);
> 

Thank you for the change, per se this particular change is not needed on
LPC18xx/43xx platform, however I don't object to it.

Suggested-by: Jonathan Cameron <jic23@kernel.org>
Acked-by: Vladimir Zapolskiy <vz@mleia.com>

--
Best wishes,
Vladimir

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: adc: lpc18xx_adc: Reorder clk_get_rate function call
  2021-10-24 20:12 ` Vladimir Zapolskiy
@ 2021-10-25 12:18   ` André Gustavo Nakagomi Lopez
  0 siblings, 0 replies; 3+ messages in thread
From: André Gustavo Nakagomi Lopez @ 2021-10-25 12:18 UTC (permalink / raw)
  To: Vladimir Zapolskiy; +Cc: jic23, lars, linux-iio, linux-arm-kernel, linux-kernel

On Sun, Oct 24, 2021 at 11:12:39PM +0300, Vladimir Zapolskiy wrote:
> Hi André,
> 
> On 10/24/21 10:43 PM, André Gustavo Nakagomi Lopez wrote:
> > clk_get_rate is not garanteed to work if called before clk_prepare_enable.
> 
> typo, s/garanteed/guaranteed/
> 
> > 
> > Reorder clk_get_rate, so it's called after clk_prepare_enable and
> > after devm_add_action_or_reset of lpc18xx_clk_disable.
> > 
> > Signed-off-by: André Gustavo Nakagomi Lopez <andregnl@usp.br>
> > ---
> >   drivers/iio/adc/lpc18xx_adc.c | 6 +++---
> >   1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/lpc18xx_adc.c b/drivers/iio/adc/lpc18xx_adc.c
> > index ceefa4d793cf..ae9c9384f23e 100644
> > --- a/drivers/iio/adc/lpc18xx_adc.c
> > +++ b/drivers/iio/adc/lpc18xx_adc.c
> > @@ -157,9 +157,6 @@ static int lpc18xx_adc_probe(struct platform_device *pdev)
> >   		return dev_err_probe(&pdev->dev, PTR_ERR(adc->clk),
> >   				     "error getting clock\n");
> > -	rate = clk_get_rate(adc->clk);
> > -	clkdiv = DIV_ROUND_UP(rate, LPC18XX_ADC_CLK_TARGET);
> > -
> >   	adc->vref = devm_regulator_get(&pdev->dev, "vref");
> >   	if (IS_ERR(adc->vref))
> >   		return dev_err_probe(&pdev->dev, PTR_ERR(adc->vref),
> > @@ -192,6 +189,9 @@ static int lpc18xx_adc_probe(struct platform_device *pdev)
> >   	if (ret)
> >   		return ret;
> > +	rate = clk_get_rate(adc->clk);
> > +	clkdiv = DIV_ROUND_UP(rate, LPC18XX_ADC_CLK_TARGET);
> > +
> >   	adc->cr_reg = (clkdiv << LPC18XX_ADC_CR_CLKDIV_SHIFT) |
> >   			LPC18XX_ADC_CR_PDN;
> >   	writel(adc->cr_reg, adc->base + LPC18XX_ADC_CR);
> > 
> 
> Thank you for the change, per se this particular change is not needed on
> LPC18xx/43xx platform, however I don't object to it.
> 
> Suggested-by: Jonathan Cameron <jic23@kernel.org>
> Acked-by: Vladimir Zapolskiy <vz@mleia.com>
> 
> --
> Best wishes,
> Vladimir

Ok, thank you for the review. I will fix the typo and add the appropriate tags.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-25 12:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-24 19:43 [PATCH] iio: adc: lpc18xx_adc: Reorder clk_get_rate function call André Gustavo Nakagomi Lopez
2021-10-24 20:12 ` Vladimir Zapolskiy
2021-10-25 12:18   ` André Gustavo Nakagomi Lopez

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).