Commit 76170adb authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Jonathan Cameron

iio: light: si1133: Use get_unaligned_be24()

This makes the driver code slightly easier to read.

Cc: Maxime Roussin-Bélanger <maxime.roussinbelanger@gmail.com>
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent d324ac2e
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <linux/util_macros.h> #include <linux/util_macros.h>
#include <asm/unaligned.h>
#define SI1133_REG_PART_ID 0x00 #define SI1133_REG_PART_ID 0x00
#define SI1133_REG_REV_ID 0x01 #define SI1133_REG_REV_ID 0x01
#define SI1133_REG_MFR_ID 0x02 #define SI1133_REG_MFR_ID 0x02
...@@ -104,8 +106,6 @@ ...@@ -104,8 +106,6 @@
#define SI1133_LUX_BUFFER_SIZE 9 #define SI1133_LUX_BUFFER_SIZE 9
#define SI1133_MEASURE_BUFFER_SIZE 3 #define SI1133_MEASURE_BUFFER_SIZE 3
#define SI1133_SIGN_BIT_INDEX 23
static const int si1133_scale_available[] = { static const int si1133_scale_available[] = {
1, 2, 4, 8, 16, 32, 64, 128}; 1, 2, 4, 8, 16, 32, 64, 128};
...@@ -633,8 +633,7 @@ static int si1133_measure(struct si1133_data *data, ...@@ -633,8 +633,7 @@ static int si1133_measure(struct si1133_data *data,
if (err) if (err)
return err; return err;
*val = sign_extend32((buffer[0] << 16) | (buffer[1] << 8) | buffer[2], *val = sign_extend32(get_unaligned_be24(&buffer[0]), 23);
SI1133_SIGN_BIT_INDEX);
return err; return err;
} }
...@@ -723,16 +722,11 @@ static int si1133_get_lux(struct si1133_data *data, int *val) ...@@ -723,16 +722,11 @@ static int si1133_get_lux(struct si1133_data *data, int *val)
if (err) if (err)
return err; return err;
high_vis = high_vis = sign_extend32(get_unaligned_be24(&buffer[0]), 23);
sign_extend32((buffer[0] << 16) | (buffer[1] << 8) | buffer[2],
SI1133_SIGN_BIT_INDEX);
low_vis = low_vis = sign_extend32(get_unaligned_be24(&buffer[3]), 23);
sign_extend32((buffer[3] << 16) | (buffer[4] << 8) | buffer[5],
SI1133_SIGN_BIT_INDEX);
ir = sign_extend32((buffer[6] << 16) | (buffer[7] << 8) | buffer[8], ir = sign_extend32(get_unaligned_be24(&buffer[6]), 23);
SI1133_SIGN_BIT_INDEX);
if (high_vis > SI1133_ADC_THRESHOLD || ir > SI1133_ADC_THRESHOLD) if (high_vis > SI1133_ADC_THRESHOLD || ir > SI1133_ADC_THRESHOLD)
lux = si1133_calc_polynomial(high_vis, ir, lux = si1133_calc_polynomial(high_vis, ir,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment