Commit d049151a authored by Matti Vaittinen's avatar Matti Vaittinen Committed by Jonathan Cameron

iio: bu27034: Ensure reset is written

The reset bit must be always written to the hardware no matter what value
is in a cache or register. Ensure this by using regmap_write_bits()
instead of the regmap_update_bits(). Furthermore, the SWRESET bit may be
self-clearing, so mark the SYSTEM_CONTROL register volatile to guarantee
we do also read the right state - should we ever need to read it.

Finally, writing the SWRESET bit will restore the default register
values. This can cause register cache to be outdated if there are any
register values cached.

Rebuild register cache after SWRESET and use regmap_update_bits() when
performing the reset.
Signed-off-by: default avatarMatti Vaittinen <mazziesaccount@gmail.com>
Fixes: e52afbd6 ("iio: light: ROHM BU27034 Ambient Light Sensor")
Link: https://lore.kernel.org/r/ZFjWhbfuN5XcKty+@fedoraSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent a146eccb
...@@ -231,6 +231,9 @@ struct bu27034_result { ...@@ -231,6 +231,9 @@ struct bu27034_result {
static const struct regmap_range bu27034_volatile_ranges[] = { static const struct regmap_range bu27034_volatile_ranges[] = {
{ {
.range_min = BU27034_REG_SYSTEM_CONTROL,
.range_max = BU27034_REG_SYSTEM_CONTROL,
}, {
.range_min = BU27034_REG_MODE_CONTROL4, .range_min = BU27034_REG_MODE_CONTROL4,
.range_max = BU27034_REG_MODE_CONTROL4, .range_max = BU27034_REG_MODE_CONTROL4,
}, { }, {
...@@ -1272,12 +1275,19 @@ static int bu27034_chip_init(struct bu27034_data *data) ...@@ -1272,12 +1275,19 @@ static int bu27034_chip_init(struct bu27034_data *data)
int ret, sel; int ret, sel;
/* Reset */ /* Reset */
ret = regmap_update_bits(data->regmap, BU27034_REG_SYSTEM_CONTROL, ret = regmap_write_bits(data->regmap, BU27034_REG_SYSTEM_CONTROL,
BU27034_MASK_SW_RESET, BU27034_MASK_SW_RESET); BU27034_MASK_SW_RESET, BU27034_MASK_SW_RESET);
if (ret) if (ret)
return dev_err_probe(data->dev, ret, "Sensor reset failed\n"); return dev_err_probe(data->dev, ret, "Sensor reset failed\n");
msleep(1); msleep(1);
ret = regmap_reinit_cache(data->regmap, &bu27034_regmap);
if (ret) {
dev_err(data->dev, "Failed to reinit reg cache\n");
return ret;
}
/* /*
* Read integration time here to ensure it is in regmap cache. We do * Read integration time here to ensure it is in regmap cache. We do
* this to speed-up the int-time acquisition in the start of the buffer * this to speed-up the int-time acquisition in the start of the buffer
......
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