iio: light: tsl2563: Drop unused defintion(s)
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 7 Dec 2022 19:03:42 +0000 (21:03 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 28 Dec 2022 17:19:45 +0000 (17:19 +0000)
The CALIB_FRAC() is defined and might had been used in
tsl2563_calib_from_sysfs(). But let's just move a comment
from it to the latter function.

CLAIB_FRAC_HALF is used in a single place, i.e. in
tsl2563_calib_to_sysfs(). So, let's just inline it there.

While at it, switch to use DIV_ROUND_CLOSEST().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Ferry Toth <ftoth@exalondelft.nl>
Link: https://lore.kernel.org/r/20221207190348.9347-5-andriy.shevchenko@linux.intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/light/tsl2563.c

index 3b60d800035192aed00534a06fabb64cca994ed5..bdd40a5df53de763fb9ad84fd8392acdc5a00d65 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/sched.h>
+#include <linux/math.h>
 #include <linux/mutex.h>
 #include <linux/delay.h>
 #include <linux/pm.h>
 
 /* Bits used for fraction in calibration coefficients.*/
 #define CALIB_FRAC_BITS                10
-/* 0.5 in CALIB_FRAC_BITS precision */
-#define CALIB_FRAC_HALF                BIT(CALIB_FRAC_BITS - 1)
-/* Make a fraction from a number n that was multiplied with b. */
-#define CALIB_FRAC(n, b)       (((n) << CALIB_FRAC_BITS) / (b))
 /* Decimal 10^(digits in sysfs presentation) */
 #define CALIB_BASE_SYSFS       1000
 
@@ -360,12 +357,12 @@ out:
 
 static inline int tsl2563_calib_to_sysfs(u32 calib)
 {
-       return (int) (((calib * CALIB_BASE_SYSFS) +
-                      CALIB_FRAC_HALF) >> CALIB_FRAC_BITS);
+       return (int)DIV_ROUND_CLOSEST(calib * CALIB_BASE_SYSFS, BIT(CALIB_FRAC_BITS));
 }
 
 static inline u32 tsl2563_calib_from_sysfs(int value)
 {
+       /* Make a fraction from a number n that was multiplied with b. */
        return (((u32) value) << CALIB_FRAC_BITS) / CALIB_BASE_SYSFS;
 }