All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabrice Gasnier <fabrice.gasnier@st.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>, <mcoquelin.stm32@gmail.com>,
	<alexandre.torgue@st.com>, <linux-iio@vger.kernel.org>,
	<lars@metafoo.de>, <knaack.h@gmx.de>, <pmeerw@pmeerw.net>,
	<linux-stm32@st-md-mailman.stormreply.com>,
	<arnaud.pouliquen@st.com>, <olivier.moysan@st.com>
Subject: Re: [PATCH 1/8] iio: adc: stm32-dfsdm: make spi_master_freq more accurate
Date: Thu, 21 Mar 2019 14:41:13 +0100	[thread overview]
Message-ID: <62742e3f-3860-3020-33a0-dafc9ae66dd1@st.com> (raw)
In-Reply-To: <20190310100932.71fd1af1@archlinux>

On 3/10/19 11:09 AM, Jonathan Cameron wrote:
> On Wed, 6 Mar 2019 09:55:17 +0100
> Fabrice Gasnier <fabrice.gasnier@st.com> wrote:
> 
>> When SPI clock isn't accurate, 'spi_master_freq' is filled in with
>> expected frequency. Use computed value instead:
>> - e.g. source clock / (CKOUTDIV + 1)
>> Also, current divider may be set to value that makes CKOUT to exceed
>> spi-max-frequency. Rather use lower value (e.g. round up divider when
>> ckout isn't accurate).
>>
>> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
>> ---
>>  drivers/iio/adc/stm32-dfsdm-core.c | 9 +++++++--
>>  1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/iio/adc/stm32-dfsdm-core.c b/drivers/iio/adc/stm32-dfsdm-core.c
>> index bf089f5..65b7556 100644
>> --- a/drivers/iio/adc/stm32-dfsdm-core.c
>> +++ b/drivers/iio/adc/stm32-dfsdm-core.c
>> @@ -243,13 +243,18 @@ static int stm32_dfsdm_parse_of(struct platform_device *pdev,
>>  		return 0;
>>  	}
>>  
>> -	priv->spi_clk_out_div = div_u64_rem(clk_freq, spi_freq, &rem) - 1;
>> +	priv->spi_clk_out_div = div_u64_rem(clk_freq, spi_freq, &rem);
>> +
>> +	/* round up divider when clkout isn't accurate (e.g. !rem) */
>> +	if (priv->spi_clk_out_div && !rem)
>> +		priv->spi_clk_out_div--;
>> +
> This comment perhaps needs adjusting because at the moment it looks
> like it decrements when it is accurate.   With the old code in place
> in the patch it's obvious that's because you actually want one less.
> 
> Might even be worth the dance of
> 
> /* round up if not precise */
> if (priv->spi_clk_out_div && rem)
> 	priv->spi_clk_out_div++;
> 
> /* subtract one because....  */
> priv->spi_clk_out_div--;

Hi Jonathan,

I'll rework this patch in v2, make it easier to understand & read.

In a few words: the clock output is divider = ckoutdiv + 1.
ckoutdiv range can be from 1-255 to provide divider of 2-256.
So I'll introduce this divider as a variable, and use it to setup
spi_clk_out_div.
This should address all your remarks here.

Thanks for reviewing,
Best Regards,
Fabrice
> 
>>  	if (!priv->spi_clk_out_div) {
>>  		/* spi_clk_out_div == 0 means ckout is OFF */
>>  		dev_err(&pdev->dev, "spi-max-frequency not achievable\n");
>>  		return -EINVAL;
>>  	}
>> -	priv->dfsdm.spi_master_freq = spi_freq;
>> +	priv->dfsdm.spi_master_freq = clk_freq / (priv->spi_clk_out_div + 1);
> And we increment it again here? That needs an explanation as well.
>>  
>>  	if (rem) {
>>  		dev_warn(&pdev->dev, "SPI clock not accurate\n");
> 

WARNING: multiple messages have this Message-ID (diff)
From: Fabrice Gasnier <fabrice.gasnier@st.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: lars@metafoo.de, olivier.moysan@st.com, alexandre.torgue@st.com,
	linux-iio@vger.kernel.org, pmeerw@pmeerw.net,
	arnaud.pouliquen@st.com, linux-kernel@vger.kernel.org,
	mcoquelin.stm32@gmail.com, knaack.h@gmx.de,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 1/8] iio: adc: stm32-dfsdm: make spi_master_freq more accurate
Date: Thu, 21 Mar 2019 14:41:13 +0100	[thread overview]
Message-ID: <62742e3f-3860-3020-33a0-dafc9ae66dd1@st.com> (raw)
In-Reply-To: <20190310100932.71fd1af1@archlinux>

On 3/10/19 11:09 AM, Jonathan Cameron wrote:
> On Wed, 6 Mar 2019 09:55:17 +0100
> Fabrice Gasnier <fabrice.gasnier@st.com> wrote:
> 
>> When SPI clock isn't accurate, 'spi_master_freq' is filled in with
>> expected frequency. Use computed value instead:
>> - e.g. source clock / (CKOUTDIV + 1)
>> Also, current divider may be set to value that makes CKOUT to exceed
>> spi-max-frequency. Rather use lower value (e.g. round up divider when
>> ckout isn't accurate).
>>
>> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
>> ---
>>  drivers/iio/adc/stm32-dfsdm-core.c | 9 +++++++--
>>  1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/iio/adc/stm32-dfsdm-core.c b/drivers/iio/adc/stm32-dfsdm-core.c
>> index bf089f5..65b7556 100644
>> --- a/drivers/iio/adc/stm32-dfsdm-core.c
>> +++ b/drivers/iio/adc/stm32-dfsdm-core.c
>> @@ -243,13 +243,18 @@ static int stm32_dfsdm_parse_of(struct platform_device *pdev,
>>  		return 0;
>>  	}
>>  
>> -	priv->spi_clk_out_div = div_u64_rem(clk_freq, spi_freq, &rem) - 1;
>> +	priv->spi_clk_out_div = div_u64_rem(clk_freq, spi_freq, &rem);
>> +
>> +	/* round up divider when clkout isn't accurate (e.g. !rem) */
>> +	if (priv->spi_clk_out_div && !rem)
>> +		priv->spi_clk_out_div--;
>> +
> This comment perhaps needs adjusting because at the moment it looks
> like it decrements when it is accurate.   With the old code in place
> in the patch it's obvious that's because you actually want one less.
> 
> Might even be worth the dance of
> 
> /* round up if not precise */
> if (priv->spi_clk_out_div && rem)
> 	priv->spi_clk_out_div++;
> 
> /* subtract one because....  */
> priv->spi_clk_out_div--;

Hi Jonathan,

I'll rework this patch in v2, make it easier to understand & read.

In a few words: the clock output is divider = ckoutdiv + 1.
ckoutdiv range can be from 1-255 to provide divider of 2-256.
So I'll introduce this divider as a variable, and use it to setup
spi_clk_out_div.
This should address all your remarks here.

Thanks for reviewing,
Best Regards,
Fabrice
> 
>>  	if (!priv->spi_clk_out_div) {
>>  		/* spi_clk_out_div == 0 means ckout is OFF */
>>  		dev_err(&pdev->dev, "spi-max-frequency not achievable\n");
>>  		return -EINVAL;
>>  	}
>> -	priv->dfsdm.spi_master_freq = spi_freq;
>> +	priv->dfsdm.spi_master_freq = clk_freq / (priv->spi_clk_out_div + 1);
> And we increment it again here? That needs an explanation as well.
>>  
>>  	if (rem) {
>>  		dev_warn(&pdev->dev, "SPI clock not accurate\n");
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-03-21 13:41 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-06  8:55 [PATCH 0/8] iio: adc: stm32-dfsdm: add buffer modes Fabrice Gasnier
2019-03-06  8:55 ` Fabrice Gasnier
2019-03-06  8:55 ` [PATCH 1/8] iio: adc: stm32-dfsdm: make spi_master_freq more accurate Fabrice Gasnier
2019-03-06  8:55   ` Fabrice Gasnier
2019-03-10 10:09   ` Jonathan Cameron
2019-03-10 10:09     ` Jonathan Cameron
2019-03-21 13:41     ` Fabrice Gasnier [this message]
2019-03-21 13:41       ` Fabrice Gasnier
2019-03-06  8:55 ` [PATCH 2/8] iio: adc: stm32-dfsdm: continuous mode depends on current mode Fabrice Gasnier
2019-03-06  8:55   ` Fabrice Gasnier
2019-03-06  8:55 ` [PATCH 3/8] iio: adc: stm32-dfsdm: move dma enable from start_conv() to start_dma() Fabrice Gasnier
2019-03-06  8:55   ` Fabrice Gasnier
2019-03-06  8:55 ` [PATCH 4/8] iio: adc: stm32-dfsdm: move dma slave config to start routine Fabrice Gasnier
2019-03-06  8:55   ` Fabrice Gasnier
2019-03-06  8:55 ` [PATCH 5/8] iio: adc: stm32-dfsdm: enable hw consumer Fabrice Gasnier
2019-03-06  8:55   ` Fabrice Gasnier
2019-03-06  8:55 ` [PATCH 6/8] iio: adc: stm32-dfsdm: add support for scan mode Fabrice Gasnier
2019-03-06  8:55   ` Fabrice Gasnier
2019-03-06  8:55 ` [PATCH 7/8] iio: adc: stm32-dfsdm: add support for buffer modes Fabrice Gasnier
2019-03-06  8:55   ` Fabrice Gasnier
2019-03-10 10:21   ` Jonathan Cameron
2019-03-10 10:21     ` Jonathan Cameron
2019-03-15 18:01     ` Fabrice Gasnier
2019-03-15 18:01       ` Fabrice Gasnier
2019-03-16 14:10       ` Jonathan Cameron
2019-03-16 14:10         ` Jonathan Cameron
2019-03-21 13:41         ` Fabrice Gasnier
2019-03-21 13:41           ` Fabrice Gasnier
2019-03-06  8:55 ` [PATCH 8/8] iio: adc: stm32-dfsdm: claim direct mode for raw read and settings Fabrice Gasnier
2019-03-06  8:55   ` Fabrice Gasnier

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=62742e3f-3860-3020-33a0-dafc9ae66dd1@st.com \
    --to=fabrice.gasnier@st.com \
    --cc=alexandre.torgue@st.com \
    --cc=arnaud.pouliquen@st.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=olivier.moysan@st.com \
    --cc=pmeerw@pmeerw.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.