Commit f40531d1 authored by Brian Masney's avatar Brian Masney Committed by Jonathan Cameron

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: default avatarBrian Masney <masneyb@onstation.org>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 91ca1a8c
...@@ -124,6 +124,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, ...@@ -124,6 +124,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip,
{ {
int ret = 0; int ret = 0;
if (chip->als_ir_mode == mode)
return 0;
switch (mode) { switch (mode) {
case ISL29028_MODE_ALS: case ISL29028_MODE_ALS:
ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
...@@ -160,6 +163,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, ...@@ -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 */ /* Need to wait for conversion time if ALS/IR mode enabled */
mdelay(ISL29028_CONV_TIME_MS); mdelay(ISL29028_CONV_TIME_MS);
chip->als_ir_mode = mode;
return 0; return 0;
} }
...@@ -223,15 +229,11 @@ static int isl29028_als_get(struct isl29028_chip *chip, int *als_data) ...@@ -223,15 +229,11 @@ static int isl29028_als_get(struct isl29028_chip *chip, int *als_data)
int ret; int ret;
int als_ir_data; int als_ir_data;
if (chip->als_ir_mode != ISL29028_MODE_ALS) {
ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS); ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS);
if (ret < 0) { if (ret < 0) {
dev_err(dev, dev_err(dev, "Error in enabling ALS mode err %d\n", ret);
"Error in enabling ALS mode err %d\n", ret);
return ret; return ret;
} }
chip->als_ir_mode = ISL29028_MODE_ALS;
}
ret = isl29028_read_als_ir(chip, &als_ir_data); ret = isl29028_read_als_ir(chip, &als_ir_data);
if (ret < 0) if (ret < 0)
...@@ -256,15 +258,11 @@ static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data) ...@@ -256,15 +258,11 @@ static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data)
struct device *dev = regmap_get_device(chip->regmap); struct device *dev = regmap_get_device(chip->regmap);
int ret; int ret;
if (chip->als_ir_mode != ISL29028_MODE_IR) {
ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR); ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR);
if (ret < 0) { if (ret < 0) {
dev_err(dev, dev_err(dev, "Error in enabling IR mode err %d\n", ret);
"Error in enabling IR mode err %d\n", ret);
return ret; return ret;
} }
chip->als_ir_mode = ISL29028_MODE_IR;
}
return isl29028_read_als_ir(chip, ir_data); return isl29028_read_als_ir(chip, ir_data);
} }
......
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