linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: frequency: ad9523: Improve reported VCO frequency accuracy
@ 2019-03-26 13:26 Alexandru Ardelean
  2019-05-17 13:37 ` [PATCH][RESEND] iio: ad9523-1: " Alexandru Ardelean
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandru Ardelean @ 2019-03-26 13:26 UTC (permalink / raw)
  To: linux-iio; +Cc: Lars-Peter Clausen, Alexandru Ardelean

From: Lars-Peter Clausen <lars@metafoo.de>

To improve the accuracy of the reported VCO frequency perform all
multiplications before divisions. This reduces rounding errors and makes
sure the reported rates are accurate down to the last digit.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/frequency/ad9523.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
index 3f9be69499ec..d2aef511189a 100644
--- a/drivers/iio/frequency/ad9523.c
+++ b/drivers/iio/frequency/ad9523.c
@@ -862,9 +862,11 @@ static int ad9523_setup(struct iio_dev *indio_dev)
 	if (ret < 0)
 		return ret;
 
-	st->vco_freq = (pdata->vcxo_freq * (pdata->pll2_freq_doubler_en ? 2 : 1)
-			/ pdata->pll2_r2_div) * AD9523_PLL2_FB_NDIV(pdata->
-			pll2_ndiv_a_cnt, pdata->pll2_ndiv_b_cnt);
+	st->vco_freq = div_u64((unsigned long long)pdata->vcxo_freq *
+			       (pdata->pll2_freq_doubler_en ? 2 : 1) *
+			       AD9523_PLL2_FB_NDIV(pdata->pll2_ndiv_a_cnt,
+						   pdata->pll2_ndiv_b_cnt),
+			       pdata->pll2_r2_div);
 
 	ret = ad9523_write(indio_dev, AD9523_PLL2_VCO_CTRL,
 		AD9523_PLL2_VCO_CALIBRATE);
-- 
2.17.1


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

* [PATCH][RESEND] iio: ad9523-1: Improve reported VCO frequency accuracy
  2019-03-26 13:26 [PATCH] iio: frequency: ad9523: Improve reported VCO frequency accuracy Alexandru Ardelean
@ 2019-05-17 13:37 ` Alexandru Ardelean
  2019-05-18  8:41   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandru Ardelean @ 2019-05-17 13:37 UTC (permalink / raw)
  To: linux-iio; +Cc: Lars-Peter Clausen, Alexandru Ardelean

From: Lars-Peter Clausen <lars@metafoo.de>

To improve the accuracy of the reported VCO frequency perform all
multiplications before divisions. This reduces rounding errors and makes
sure the reported rates are accurate down to the last digit.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/frequency/ad9523.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
index 246e38d76eff..541cb5975dd9 100644
--- a/drivers/iio/frequency/ad9523.c
+++ b/drivers/iio/frequency/ad9523.c
@@ -1140,9 +1140,11 @@ static int ad9523_setup(struct iio_dev *indio_dev)
 	if (ret < 0)
 		return ret;
 
-	st->vco_freq = (pdata->vcxo_freq * (pdata->pll2_freq_doubler_en ? 2 : 1)
-			/ pdata->pll2_r2_div) * AD9523_PLL2_FB_NDIV(pdata->
-			pll2_ndiv_a_cnt, pdata->pll2_ndiv_b_cnt);
+	st->vco_freq = div_u64((unsigned long long)pdata->vcxo_freq *
+			       (pdata->pll2_freq_doubler_en ? 2 : 1) *
+			       AD9523_PLL2_FB_NDIV(pdata->pll2_ndiv_a_cnt,
+						   pdata->pll2_ndiv_b_cnt),
+			       pdata->pll2_r2_div);
 
 	ret = ad9523_write(indio_dev, AD9523_PLL2_VCO_CTRL,
 		AD9523_PLL2_VCO_CALIBRATE);
-- 
2.17.1


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

* Re: [PATCH][RESEND] iio: ad9523-1: Improve reported VCO frequency accuracy
  2019-05-17 13:37 ` [PATCH][RESEND] iio: ad9523-1: " Alexandru Ardelean
@ 2019-05-18  8:41   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2019-05-18  8:41 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: linux-iio, Lars-Peter Clausen

On Fri, 17 May 2019 16:37:11 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:

> From: Lars-Peter Clausen <lars@metafoo.de>
> 
> To improve the accuracy of the reported VCO frequency perform all
> multiplications before divisions. This reduces rounding errors and makes
> sure the reported rates are accurate down to the last digit.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Not sure how I missed this one the first time around!  Thanks for the
resend and applied to the togreg branch of iio.git.

Thanks,

Jonathan

> ---
>  drivers/iio/frequency/ad9523.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
> index 246e38d76eff..541cb5975dd9 100644
> --- a/drivers/iio/frequency/ad9523.c
> +++ b/drivers/iio/frequency/ad9523.c
> @@ -1140,9 +1140,11 @@ static int ad9523_setup(struct iio_dev *indio_dev)
>  	if (ret < 0)
>  		return ret;
>  
> -	st->vco_freq = (pdata->vcxo_freq * (pdata->pll2_freq_doubler_en ? 2 : 1)
> -			/ pdata->pll2_r2_div) * AD9523_PLL2_FB_NDIV(pdata->
> -			pll2_ndiv_a_cnt, pdata->pll2_ndiv_b_cnt);
> +	st->vco_freq = div_u64((unsigned long long)pdata->vcxo_freq *
> +			       (pdata->pll2_freq_doubler_en ? 2 : 1) *
> +			       AD9523_PLL2_FB_NDIV(pdata->pll2_ndiv_a_cnt,
> +						   pdata->pll2_ndiv_b_cnt),
> +			       pdata->pll2_r2_div);
>  
>  	ret = ad9523_write(indio_dev, AD9523_PLL2_VCO_CTRL,
>  		AD9523_PLL2_VCO_CALIBRATE);


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

end of thread, other threads:[~2019-05-18  8:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-26 13:26 [PATCH] iio: frequency: ad9523: Improve reported VCO frequency accuracy Alexandru Ardelean
2019-05-17 13:37 ` [PATCH][RESEND] iio: ad9523-1: " Alexandru Ardelean
2019-05-18  8:41   ` Jonathan Cameron

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