iio: light: opt4001: Fix power down clearing bits of the wrong register

opt4001_power_down() intends to clear the operating mode bits in the
CTRL register but reads OPT4001_DEVICE_ID instead of OPT4001_CTRL, so
the value written back to CTRL contains device ID bits rather than the
current configuration.

Fix and simplify this by using regmap_clear_bits() on the CTRL register
directly in the devm action, and drop opt4001_power_down() which has no
other users.

Suggested-by: Jonathan Cameron <jic23@kernel.org>
Fixes: 9a96084182 ("iio: light: Add support for TI OPT4001 light sensor")
Signed-off-by: Nikhil Gautam <nikhilgtr@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
This commit is contained in:
Nikhil Gautam 2026-07-14 17:01:31 +05:30 committed by Jonathan Cameron
parent ad36763821
commit 3b2cd82c52

View File

@ -222,33 +222,14 @@ static int opt4001_set_conf(struct opt4001_chip *chip)
return ret;
}
static int opt4001_power_down(struct opt4001_chip *chip)
{
struct device *dev = &chip->client->dev;
int ret;
unsigned int reg;
ret = regmap_read(chip->regmap, OPT4001_DEVICE_ID, &reg);
if (ret) {
dev_err(dev, "Failed to read configuration\n");
return ret;
}
/* MODE_OFF is 0x0 so just set bits to 0 */
reg &= ~OPT4001_CTRL_OPER_MODE_MASK;
ret = regmap_write(chip->regmap, OPT4001_CTRL, reg);
if (ret)
dev_err(dev, "Failed to set configuration to power down\n");
return ret;
}
static void opt4001_chip_off_action(void *data)
{
struct opt4001_chip *chip = data;
int ret;
opt4001_power_down(chip);
ret = regmap_clear_bits(chip->regmap, OPT4001_CTRL, OPT4001_CTRL_OPER_MODE_MASK);
if (ret)
dev_err(&chip->client->dev, "Failed to power down\n");
}
static const struct iio_chan_spec opt4001_channels[] = {