]> git.baikalelectronics.ru Git - kernel.git/commitdiff
iio: light: si1133: Use get_unaligned_be24()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 21 Apr 2020 00:31:28 +0000 (03:31 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 3 May 2020 08:47:19 +0000 (09:47 +0100)
This makes the driver code slightly easier to read.

Cc: Maxime Roussin-BĂ©langer <maxime.roussinbelanger@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/light/si1133.c

index 9174ab9288808af9e2bfc231e4d7cd1e0329606a..c1adab2a50fd5a0631d561c48080830f4bf34ba5 100644 (file)
@@ -17,6 +17,8 @@
 
 #include <linux/util_macros.h>
 
+#include <asm/unaligned.h>
+
 #define SI1133_REG_PART_ID             0x00
 #define SI1133_REG_REV_ID              0x01
 #define SI1133_REG_MFR_ID              0x02
 #define SI1133_LUX_BUFFER_SIZE         9
 #define SI1133_MEASURE_BUFFER_SIZE     3
 
-#define SI1133_SIGN_BIT_INDEX 23
-
 static const int si1133_scale_available[] = {
        1, 2, 4, 8, 16, 32, 64, 128};
 
@@ -633,8 +633,7 @@ static int si1133_measure(struct si1133_data *data,
        if (err)
                return err;
 
-       *val = sign_extend32((buffer[0] << 16) | (buffer[1] << 8) | buffer[2],
-                            SI1133_SIGN_BIT_INDEX);
+       *val = sign_extend32(get_unaligned_be24(&buffer[0]), 23);
 
        return err;
 }
@@ -723,16 +722,11 @@ static int si1133_get_lux(struct si1133_data *data, int *val)
        if (err)
                return err;
 
-       high_vis =
-               sign_extend32((buffer[0] << 16) | (buffer[1] << 8) | buffer[2],
-                             SI1133_SIGN_BIT_INDEX);
+       high_vis = sign_extend32(get_unaligned_be24(&buffer[0]), 23);
 
-       low_vis =
-               sign_extend32((buffer[3] << 16) | (buffer[4] << 8) | buffer[5],
-                             SI1133_SIGN_BIT_INDEX);
+       low_vis = sign_extend32(get_unaligned_be24(&buffer[3]), 23);
 
-       ir = sign_extend32((buffer[6] << 16) | (buffer[7] << 8) | buffer[8],
-                          SI1133_SIGN_BIT_INDEX);
+       ir = sign_extend32(get_unaligned_be24(&buffer[6]), 23);
 
        if (high_vis > SI1133_ADC_THRESHOLD || ir > SI1133_ADC_THRESHOLD)
                lux = si1133_calc_polynomial(high_vis, ir,