Re: [PATCH 2/4] iio: add processed write API
From: Romain Gantois
Date: Wed Sep 17 2025 - 12:24:12 EST
Hello David,
On Tuesday, 16 September 2025 21:23:04 CEST David Lechner wrote:
> On 9/16/25 5:24 AM, Romain Gantois wrote:
> > Add a function to allow IIO consumers to write a processed value to a
...
> > + case IIO_VAL_FRACTIONAL:
> > + tmp_num = (s64)processed * (s64)scale_val2;
> > + tmp_den = scale_val;
> > + break;
> > + case IIO_VAL_FRACTIONAL_LOG2:
> > + tmp_num = (s64)processed << scale_val2;
> > + tmp_den = scale_val;
> > + break;
> > + default:
> > + return -EINVAL;
> > + }
> > +
> > + tmp_den *= scale;
> > +
> > + *raw = div64_s64(tmp_num, tmp_den);
> > + }
>
> It can be quite tricky to get all of these combinations right. I would
> prefer if added some unit tests like we did in [1].
>
> [1]:
> https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/?h=tes
> ting&id=c732e60ee10ed0611a59513cbf9c8d35fbe7cf65
Agreed, that would be nice, I'll look into it.
Thanks,
--
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Attachment:
signature.asc
Description: This is a digitally signed message part.