public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH v3] staging: iio: ad5933: Correct settling cycles encoding per datasheet
@ 2025-04-20  0:30 Gabriel Shahrouzi
  2025-04-20  0:54 ` Marcelo Schmitt
  2025-04-22 10:02 ` Dan Carpenter
  0 siblings, 2 replies; 4+ messages in thread
From: Gabriel Shahrouzi @ 2025-04-20  0:30 UTC (permalink / raw)
  To: gregkh, jic23, lars, linux-iio, linux-kernel, linux-staging,
	Michael.Hennerich
  Cc: gshahrouzi, skhan, linux-kernel-mentees, stable

Implement the settling cycles encoding as specified in the AD5933
datasheet, Table 13 ("Number of Settling Times Cycles Register"). The
previous logic did not correctly translate the user-requested effective
cycle count into the required 9-bit base + 2-bit multiplier format
(D10..D0) for values exceeding 511.

Clamp the user input for out_altvoltage0_settling_cycles to the
maximum effective value of 2044 cycles (511 * 4x multiplier).

Fixes: f94aa354d676 ("iio: impedance-analyzer: New driver for AD5933/4 Impedance Converter, Network Analyzer")
Cc: stable@vger.kernel.org
Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
---
Changes in v3:
	- Only include fix (remove refactoring which will be its own
	  separate patch).
Changes in v2:
        - Fix spacing in comment around '+'.
        - Define mask and values for settling cycle multipliers.
---
 drivers/staging/iio/impedance-analyzer/ad5933.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index d5544fc2fe989..f8fcc10ea8150 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -411,7 +411,7 @@ static ssize_t ad5933_store(struct device *dev,
 		ret = ad5933_cmd(st, 0);
 		break;
 	case AD5933_OUT_SETTLING_CYCLES:
-		val = clamp(val, (u16)0, (u16)0x7FF);
+		val = clamp(val, (u16)0, (u16)0x7FC);
 		st->settling_cycles = val;
 
 		/* 2x, 4x handling, see datasheet */
-- 
2.43.0


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

* Re: [PATCH v3] staging: iio: ad5933: Correct settling cycles encoding per datasheet
  2025-04-20  0:30 [PATCH v3] staging: iio: ad5933: Correct settling cycles encoding per datasheet Gabriel Shahrouzi
@ 2025-04-20  0:54 ` Marcelo Schmitt
  2025-04-20  1:22   ` Gabriel Shahrouzi
  2025-04-22 10:02 ` Dan Carpenter
  1 sibling, 1 reply; 4+ messages in thread
From: Marcelo Schmitt @ 2025-04-20  0:54 UTC (permalink / raw)
  To: Gabriel Shahrouzi
  Cc: gregkh, jic23, lars, linux-iio, linux-kernel, linux-staging,
	Michael.Hennerich, skhan, linux-kernel-mentees, stable

On 04/19, Gabriel Shahrouzi wrote:
> Implement the settling cycles encoding as specified in the AD5933
> datasheet, Table 13 ("Number of Settling Times Cycles Register"). The
> previous logic did not correctly translate the user-requested effective
> cycle count into the required 9-bit base + 2-bit multiplier format
> (D10..D0) for values exceeding 511.
Hmm, the above description should probably go on the refactoring patch I think.
Otherwise looks good.

Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>

> 
> Clamp the user input for out_altvoltage0_settling_cycles to the
> maximum effective value of 2044 cycles (511 * 4x multiplier).
> 
> Fixes: f94aa354d676 ("iio: impedance-analyzer: New driver for AD5933/4 Impedance Converter, Network Analyzer")
> Cc: stable@vger.kernel.org
> Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
> ---
> Changes in v3:
> 	- Only include fix (remove refactoring which will be its own
> 	  separate patch).
> Changes in v2:
>         - Fix spacing in comment around '+'.
>         - Define mask and values for settling cycle multipliers.
> ---

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

* Re: [PATCH v3] staging: iio: ad5933: Correct settling cycles encoding per datasheet
  2025-04-20  0:54 ` Marcelo Schmitt
@ 2025-04-20  1:22   ` Gabriel Shahrouzi
  0 siblings, 0 replies; 4+ messages in thread
From: Gabriel Shahrouzi @ 2025-04-20  1:22 UTC (permalink / raw)
  To: Marcelo Schmitt
  Cc: gregkh, jic23, lars, linux-iio, linux-kernel, linux-staging,
	Michael.Hennerich, skhan, linux-kernel-mentees, stable

On Sat, Apr 19, 2025 at 8:52 PM Marcelo Schmitt
<marcelo.schmitt1@gmail.com> wrote:
>
> On 04/19, Gabriel Shahrouzi wrote:
> > Implement the settling cycles encoding as specified in the AD5933
> > datasheet, Table 13 ("Number of Settling Times Cycles Register"). The
> > previous logic did not correctly translate the user-requested effective
> > cycle count into the required 9-bit base + 2-bit multiplier format
> > (D10..D0) for values exceeding 511.
> Hmm, the above description should probably go on the refactoring patch I think.
> Otherwise looks good.
You're right - will update that for v4. I don't think my description
was accurate either since the old logic did correctly map the cycle
counts to the correct bits. It just didn't use the correct mask.
>
> Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
>
> >
> > Clamp the user input for out_altvoltage0_settling_cycles to the
> > maximum effective value of 2044 cycles (511 * 4x multiplier).
> >
> > Fixes: f94aa354d676 ("iio: impedance-analyzer: New driver for AD5933/4 Impedance Converter, Network Analyzer")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
> > ---
> > Changes in v3:
> >       - Only include fix (remove refactoring which will be its own
> >         separate patch).
> > Changes in v2:
> >         - Fix spacing in comment around '+'.
> >         - Define mask and values for settling cycle multipliers.
> > ---

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

* Re: [PATCH v3] staging: iio: ad5933: Correct settling cycles encoding per datasheet
  2025-04-20  0:30 [PATCH v3] staging: iio: ad5933: Correct settling cycles encoding per datasheet Gabriel Shahrouzi
  2025-04-20  0:54 ` Marcelo Schmitt
@ 2025-04-22 10:02 ` Dan Carpenter
  1 sibling, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2025-04-22 10:02 UTC (permalink / raw)
  To: Gabriel Shahrouzi
  Cc: gregkh, jic23, lars, linux-iio, linux-kernel, linux-staging,
	Michael.Hennerich, skhan, linux-kernel-mentees, stable

On Sat, Apr 19, 2025 at 08:30:00PM -0400, Gabriel Shahrouzi wrote:
> Implement the settling cycles encoding as specified in the AD5933
> datasheet, Table 13 ("Number of Settling Times Cycles Register"). The
> previous logic did not correctly translate the user-requested effective
> cycle count into the required 9-bit base + 2-bit multiplier format
> (D10..D0) for values exceeding 511.
> 
> Clamp the user input for out_altvoltage0_settling_cycles to the
> maximum effective value of 2044 cycles (511 * 4x multiplier).
> 
> Fixes: f94aa354d676 ("iio: impedance-analyzer: New driver for AD5933/4 Impedance Converter, Network Analyzer")
> Cc: stable@vger.kernel.org
> Signed-off-by: Gabriel Shahrouzi <gshahrouzi@gmail.com>
> ---
> Changes in v3:
> 	- Only include fix (remove refactoring which will be its own
> 	  separate patch).
> Changes in v2:
>         - Fix spacing in comment around '+'.
>         - Define mask and values for settling cycle multipliers.
> ---
>  drivers/staging/iio/impedance-analyzer/ad5933.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
> index d5544fc2fe989..f8fcc10ea8150 100644
> --- a/drivers/staging/iio/impedance-analyzer/ad5933.c
> +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
> @@ -411,7 +411,7 @@ static ssize_t ad5933_store(struct device *dev,
>  		ret = ad5933_cmd(st, 0);
>  		break;
>  	case AD5933_OUT_SETTLING_CYCLES:
> -		val = clamp(val, (u16)0, (u16)0x7FF);
> +		val = clamp(val, (u16)0, (u16)0x7FC);

We have a fancy clamp() define now so the ugly casts are no longer
required.

regards,
dan carpenter


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

end of thread, other threads:[~2025-04-22 10:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-20  0:30 [PATCH v3] staging: iio: ad5933: Correct settling cycles encoding per datasheet Gabriel Shahrouzi
2025-04-20  0:54 ` Marcelo Schmitt
2025-04-20  1:22   ` Gabriel Shahrouzi
2025-04-22 10:02 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox