summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Masney <masneyb@onstation.org>2016-12-03 21:19:25 -0500
committerJonathan Cameron <jic23@kernel.org>2016-12-04 11:01:10 +0000
commitf40531d1e7848cf49f323f91a653d16caac27431 (patch)
treeb2b97a897a678753fd4da85578a3e178d57b7cb2
parent91ca1a8c584f55857b1f6ab20a1d3a1ce7a559bb (diff)
downloadblackbird-op-linux-f40531d1e7848cf49f323f91a653d16caac27431.tar.gz
blackbird-op-linux-f40531d1e7848cf49f323f91a653d16caac27431.zip
staging: iio: isl29028: remove nested if statements
There are two callers to the function isl29028_set_als_ir_mode() and both instances use a nested if statement to only change the chip state if it is not in the proper mode. This patch moves this check into the isl29028_set_als_ir_mode() function to remove the nested if statements. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/staging/iio/light/isl29028.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c
index aa413e5878b9..4e35d00a3e56 100644
--- a/drivers/staging/iio/light/isl29028.c
+++ b/drivers/staging/iio/light/isl29028.c
@@ -124,6 +124,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip,
{
int ret = 0;
+ if (chip->als_ir_mode == mode)
+ return 0;
+
switch (mode) {
case ISL29028_MODE_ALS:
ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
@@ -160,6 +163,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip,
/* Need to wait for conversion time if ALS/IR mode enabled */
mdelay(ISL29028_CONV_TIME_MS);
+
+ chip->als_ir_mode = mode;
+
return 0;
}
@@ -223,14 +229,10 @@ static int isl29028_als_get(struct isl29028_chip *chip, int *als_data)
int ret;
int als_ir_data;
- if (chip->als_ir_mode != ISL29028_MODE_ALS) {
- ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS);
- if (ret < 0) {
- dev_err(dev,
- "Error in enabling ALS mode err %d\n", ret);
- return ret;
- }
- chip->als_ir_mode = ISL29028_MODE_ALS;
+ ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS);
+ if (ret < 0) {
+ dev_err(dev, "Error in enabling ALS mode err %d\n", ret);
+ return ret;
}
ret = isl29028_read_als_ir(chip, &als_ir_data);
@@ -256,14 +258,10 @@ static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data)
struct device *dev = regmap_get_device(chip->regmap);
int ret;
- if (chip->als_ir_mode != ISL29028_MODE_IR) {
- ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR);
- if (ret < 0) {
- dev_err(dev,
- "Error in enabling IR mode err %d\n", ret);
- return ret;
- }
- chip->als_ir_mode = ISL29028_MODE_IR;
+ ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR);
+ if (ret < 0) {
+ dev_err(dev, "Error in enabling IR mode err %d\n", ret);
+ return ret;
}
return isl29028_read_als_ir(chip, ir_data);
}
OpenPOWER on IntegriCloud