Skip to content

Commit d049151

Browse files
M-Vaittinenjic23
authored andcommitted
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: Matti Vaittinen <[email protected]> Fixes: e52afbd ("iio: light: ROHM BU27034 Ambient Light Sensor") Link: https://lore.kernel.org/r/ZFjWhbfuN5XcKty+@fedora Signed-off-by: Jonathan Cameron <[email protected]>
1 parent a146ecc commit d049151

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

drivers/iio/light/rohm-bu27034.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ struct bu27034_result {
231231

232232
static const struct regmap_range bu27034_volatile_ranges[] = {
233233
{
234+
.range_min = BU27034_REG_SYSTEM_CONTROL,
235+
.range_max = BU27034_REG_SYSTEM_CONTROL,
236+
}, {
234237
.range_min = BU27034_REG_MODE_CONTROL4,
235238
.range_max = BU27034_REG_MODE_CONTROL4,
236239
}, {
@@ -1272,12 +1275,19 @@ static int bu27034_chip_init(struct bu27034_data *data)
12721275
int ret, sel;
12731276

12741277
/* Reset */
1275-
ret = regmap_update_bits(data->regmap, BU27034_REG_SYSTEM_CONTROL,
1278+
ret = regmap_write_bits(data->regmap, BU27034_REG_SYSTEM_CONTROL,
12761279
BU27034_MASK_SW_RESET, BU27034_MASK_SW_RESET);
12771280
if (ret)
12781281
return dev_err_probe(data->dev, ret, "Sensor reset failed\n");
12791282

12801283
msleep(1);
1284+
1285+
ret = regmap_reinit_cache(data->regmap, &bu27034_regmap);
1286+
if (ret) {
1287+
dev_err(data->dev, "Failed to reinit reg cache\n");
1288+
return ret;
1289+
}
1290+
12811291
/*
12821292
* Read integration time here to ensure it is in regmap cache. We do
12831293
* this to speed-up the int-time acquisition in the start of the buffer

0 commit comments

Comments
 (0)