[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211222034646.222189-11-liambeguin@gmail.com>
Date: Tue, 21 Dec 2021 22:46:41 -0500
From: Liam Beguin <liambeguin@...il.com>
To: liambeguin@...il.com, peda@...ntia.se, jic23@...nel.org,
andy.shevchenko@...il.com, lars@...afoo.de
Cc: linux-kernel@...r.kernel.org, linux-iio@...r.kernel.org,
devicetree@...r.kernel.org, robh+dt@...nel.org
Subject: [PATCH v11 10/15] iio: afe: rescale: make use of units.h
From: Liam Beguin <lvb@...hos.com>
Make use of well-defined SI metric prefixes to improve code readability.
Signed-off-by: Liam Beguin <lvb@...hos.com>
---
drivers/iio/afe/iio-rescale.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c
index 0000a58bab9d..27f99ce67b94 100644
--- a/drivers/iio/afe/iio-rescale.c
+++ b/drivers/iio/afe/iio-rescale.c
@@ -49,11 +49,11 @@ int rescale_process_scale(struct rescale *rescale, int scale_type,
}
fallthrough;
case IIO_VAL_FRACTIONAL_LOG2:
- tmp = (s64)*val * 1000000000LL;
+ tmp = (s64)*val * NANO;
tmp = div_s64(tmp, rescale->denominator);
tmp *= rescale->numerator;
- tmp = div_s64_rem(tmp, 1000000000LL, &rem);
+ tmp = div_s64_rem(tmp, NANO, &rem);
*val = tmp;
if (!rem)
@@ -69,7 +69,7 @@ int rescale_process_scale(struct rescale *rescale, int scale_type,
*val2 = rem / (int)tmp;
if (rem2)
- *val2 += div_s64((s64)rem2 * 1000000000LL, tmp);
+ *val2 += div_s64((s64)rem2 * NANO, tmp);
return IIO_VAL_INT_PLUS_NANO;
case IIO_VAL_INT_PLUS_NANO:
@@ -330,8 +330,8 @@ static int rescale_current_sense_amplifier_props(struct device *dev,
* gain_div / (gain_mult * sense), while trying to keep the
* numerator/denominator from overflowing.
*/
- factor = gcd(sense, 1000000);
- rescale->numerator = 1000000 / factor;
+ factor = gcd(sense, MICRO);
+ rescale->numerator = MICRO / factor;
rescale->denominator = sense / factor;
factor = gcd(rescale->numerator, gain_mult);
@@ -359,8 +359,8 @@ static int rescale_current_sense_shunt_props(struct device *dev,
return ret;
}
- factor = gcd(shunt, 1000000);
- rescale->numerator = 1000000 / factor;
+ factor = gcd(shunt, MICRO);
+ rescale->numerator = MICRO / factor;
rescale->denominator = shunt / factor;
return 0;
--
2.34.0
Powered by blists - more mailing lists