mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 1/1] iio: light: opt4001: Re-use generic struct s32_fract
@ 2026-10-23  9:08 Andy Shevchenko
  2026-10-23  9:21 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-10-23  9:08 UTC (permalink / raw)
  To: Andy Shevchenko, Jonathan Cameron, Nikhil Gautam, linux-iio,
	linux-kernel
  Cc: Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Jesper X Nilsson

Instead of custom data type re-use generic struct s32_fract.
No functional changes intended.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/light/opt4001.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/light/opt4001.c b/drivers/iio/light/opt4001.c
index aa3d87995b7c..b2e7abc22434 100644
--- a/drivers/iio/light/opt4001.c
+++ b/drivers/iio/light/opt4001.c
@@ -75,8 +75,7 @@
  * lux values.
  */
 struct opt4001_chip_info {
-	int mul;
-	int div;
+	struct s32_fract ratio;
 	const char *name;
 };
 
@@ -88,14 +87,12 @@ struct opt4001_chip {
 };
 
 static const struct opt4001_chip_info opt4001_sot_5x3_info = {
-	.mul = 4375,
-	.div = 10000000,
+	,ratio = { .numerator = 4375, .denominator = 10000000 },
 	.name = "opt4001-sot-5x3"
 };
 
 static const struct opt4001_chip_info opt4001_picostar_info = {
-	.mul = 3125,
-	.div = 10000000,
+	,ratio = { .numerator = 3125, .denominator = 10000000 },
 	.name = "opt4001-picostar"
 };
 
@@ -199,8 +196,8 @@ static int opt4001_read_lux_value(struct iio_dev *indio_dev,
 		return -EIO;
 
 	lux_raw = lux_raw << exp;
-	lux_raw = lux_raw * chip->chip_info->mul;
-	*val = div_u64_rem(lux_raw, chip->chip_info->div, &rem);
+	lux_raw = lux_raw * chip->chip_info->ratio.numerator;
+	*val = div_u64_rem(lux_raw, chip->chip_info->ratio.denominator, &rem);
 	*val2 = rem * 100;
 
 	return IIO_VAL_INT_PLUS_NANO;
-- 
2.50.1


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

* Re: [PATCH v1 1/1] iio: light: opt4001: Re-use generic struct s32_fract
  2026-10-23  9:08 [PATCH v1 1/1] iio: light: opt4001: Re-use generic struct s32_fract Andy Shevchenko
@ 2026-10-23  9:21 ` Andy Shevchenko
  2026-10-23 10:02   ` Jesper X Nilsson
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-10-23  9:21 UTC (permalink / raw)
  To: Jonathan Cameron, Nikhil Gautam, linux-iio, linux-kernel
  Cc: Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Jesper X Nilsson

On Fri, Oct 23, 2026 at 11:08:02AM +0200, Andy Shevchenko wrote:
> Instead of custom data type re-use generic struct s32_fract.
> No functional changes intended.

...

>  static const struct opt4001_chip_info opt4001_sot_5x3_info = {
> -	.mul = 4375,
> -	.div = 10000000,
> +	,ratio = { .numerator = 4375, .denominator = 10000000 },

Oh, I should have compiled it, but I missed. Should start with a period, of
course.

>  	.name = "opt4001-sot-5x3"
>  };

>  static const struct opt4001_chip_info opt4001_picostar_info = {
> -	.mul = 3125,
> -	.div = 10000000,
> +	,ratio = { .numerator = 3125, .denominator = 10000000 },
>  	.name = "opt4001-picostar"
>  };

Ditto.

...

Jesper, please take this patch into your series, but also fix those typos.
Or if you are busy, I can do it after my lunch.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v1 1/1] iio: light: opt4001: Re-use generic struct s32_fract
  2026-10-23  9:21 ` Andy Shevchenko
@ 2026-10-23 10:02   ` Jesper X Nilsson
  0 siblings, 0 replies; 3+ messages in thread
From: Jesper X Nilsson @ 2026-10-23 10:02 UTC (permalink / raw)
  To: Andy Shevchenko, Jonathan Cameron, Nikhil Gautam, linux-iio,
	linux-kernel
  Cc: Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Jesper X Nilsson

On 10/23/26 11:21, Andy Shevchenko wrote:
> On Fri, Oct 23, 2026 at 11:08:02AM +0200, Andy Shevchenko wrote:
>> Instead of custom data type re-use generic struct s32_fract.
>> No functional changes intended.
> 
> ...
> 
>>   static const struct opt4001_chip_info opt4001_sot_5x3_info = {
>> -     .mul = 4375,
>> -     .div = 10000000,
>> +     ,ratio = { .numerator = 4375, .denominator = 10000000 },
> 
> Oh, I should have compiled it, but I missed. Should start with a period, of
> course.
> 
>>        .name = "opt4001-sot-5x3"
>>   };
> 
>>   static const struct opt4001_chip_info opt4001_picostar_info = {
>> -     .mul = 3125,
>> -     .div = 10000000,
>> +     ,ratio = { .numerator = 3125, .denominator = 10000000 },
>>        .name = "opt4001-picostar"
>>   };
> 
> Ditto.
> 
> ...
> 
> Jesper, please take this patch into your series, but also fix those typos.
> Or if you are busy, I can do it after my lunch.
> 
I will add it to my series and fix the typos.
Best regards,
Jesper

> --
> With Best Regards,
> Andy Shevchenko


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

end of thread, other threads:[~2026-10-23 10:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-23  9:08 [PATCH v1 1/1] iio: light: opt4001: Re-use generic struct s32_fract Andy Shevchenko
2026-10-23  9:21 ` Andy Shevchenko
2026-10-23 10:02   ` Jesper X Nilsson

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

all inboxes | Powered by JetHome®