All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@jic23.retrosnub.co.uk>
To: <alexandru.ardelean@analog.com>
Cc: <linux-iio@vger.kernel.org>, <michael.hennerich@analog.com>
Subject: Re: [PATCH v3] staging: iio: adc: ad7192: fix external frequency setting
Date: Sun, 28 Jan 2018 08:17:14 +0000	[thread overview]
Message-ID: <20180128081714.4813b50c@archlinux> (raw)
In-Reply-To: <20180122095312.1150-1-alexandru.ardelean@analog.com>

On Mon, 22 Jan 2018 11:53:12 +0200
<alexandru.ardelean@analog.com> wrote:

> From: Alexandru Ardelean <alexandru.ardelean@analog.com>
> 
> The external clock frequency was set only when selecting
> the internal clock, which is fixed at 4.9152 Mhz.
> 
> This is incorrect, since it should be set when any of
> the external clock or crystal settings is selected.
> 
> Added range validation for the external (crystal/clock)
> frequency setting.
> Valid values are between 2.4576 and 5.12 Mhz.
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Applied to fixes-togreg-post-rc1 and marked for stable.

Thanks,

Jonathan

> ---
> 
> Changes v2 -> v3:
>  * changed fallthrough for AD7192_CLK_EXT_MCLK1_2 & AD7192_CLK_EXT_MCLK2
>    to `ret = -EINVAL` + `goto out`
>  * re-phrased commit comment; to make it more simple/direct
> 
>  drivers/staging/iio/adc/ad7192.c | 27 +++++++++++++++++++--------
>  1 file changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
> index 9287b50b7870..03aba22093a8 100644
> --- a/drivers/staging/iio/adc/ad7192.c
> +++ b/drivers/staging/iio/adc/ad7192.c
> @@ -141,6 +141,8 @@
>  #define AD7192_GPOCON_P1DAT	BIT(1) /* P1 state */
>  #define AD7192_GPOCON_P0DAT	BIT(0) /* P0 state */
>  
> +#define AD7192_EXT_FREQ_MHZ_MIN	2457600
> +#define AD7192_EXT_FREQ_MHZ_MAX	5120000
>  #define AD7192_INT_FREQ_MHZ	4915200
>  
>  /* NOTE:
> @@ -217,6 +219,12 @@ static int ad7192_calibrate_all(struct ad7192_state *st)
>  				ARRAY_SIZE(ad7192_calib_arr));
>  }
>  
> +static inline bool ad7192_valid_external_frequency(u32 freq)
> +{
> +	return (freq >= AD7192_EXT_FREQ_MHZ_MIN &&
> +		freq <= AD7192_EXT_FREQ_MHZ_MAX);
> +}
> +
>  static int ad7192_setup(struct ad7192_state *st,
>  			const struct ad7192_platform_data *pdata)
>  {
> @@ -244,17 +252,20 @@ static int ad7192_setup(struct ad7192_state *st,
>  			 id);
>  
>  	switch (pdata->clock_source_sel) {
> -	case AD7192_CLK_EXT_MCLK1_2:
> -	case AD7192_CLK_EXT_MCLK2:
> -		st->mclk = AD7192_INT_FREQ_MHZ;
> -		break;
>  	case AD7192_CLK_INT:
>  	case AD7192_CLK_INT_CO:
> -		if (pdata->ext_clk_hz)
> -			st->mclk = pdata->ext_clk_hz;
> -		else
> -			st->mclk = AD7192_INT_FREQ_MHZ;
> +		st->mclk = AD7192_INT_FREQ_MHZ;
>  		break;
> +	case AD7192_CLK_EXT_MCLK1_2:
> +	case AD7192_CLK_EXT_MCLK2:
> +		if (ad7192_valid_external_frequency(pdata->ext_clk_hz)) {
> +			st->mclk = pdata->ext_clk_hz;
> +			break;
> +		}
> +		dev_err(&st->sd.spi->dev, "Invalid frequency setting %u\n",
> +			pdata->ext_clk_hz);
> +		ret = -EINVAL;
> +		goto out;
>  	default:
>  		ret = -EINVAL;
>  		goto out;


      reply	other threads:[~2018-01-28  8:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-18 14:44 [PATCH v2] staging: iio: adc: ad7192: fix external frequency setting alexandru.ardelean
2018-01-20 16:41 ` Jonathan Cameron
2018-01-22  7:54   ` Ardelean, Alexandru
2018-01-22  9:53 ` [PATCH v3] " alexandru.ardelean
2018-01-28  8:17   ` Jonathan Cameron [this message]

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=20180128081714.4813b50c@archlinux \
    --to=jic23@jic23.retrosnub.co.uk \
    --cc=alexandru.ardelean@analog.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    /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.