Skip to content

Commit 518e26f

Browse files
Haibo Chenbrgl
authored andcommitted
gpio: pca953x: Add mutex_lock for regcache sync in PM
The regcache sync will set the cache_bypass = true, at that time, when there is regmap write operation, it will bypass the regmap cache, then the regcache sync will write back the value from cache to register, which is not as our expectation. Though regmap already use its internal lock to avoid such issue, but this driver force disable the regmap internal lock in its regmap config: disable_locking = true To avoid this issue, use the driver's own lock to do the protect in system PM. Fixes: b765743 ("gpio: pca953x: Restore registers after suspend/resume cycle") Signed-off-by: Haibo Chen <haibo.chen@nxp.com> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
1 parent 303e6da commit 518e26f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/gpio/gpio-pca953x.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,9 @@ static int pca953x_suspend(struct device *dev)
11751175
{
11761176
struct pca953x_chip *chip = dev_get_drvdata(dev);
11771177

1178+
mutex_lock(&chip->i2c_lock);
11781179
regcache_cache_only(chip->regmap, true);
1180+
mutex_unlock(&chip->i2c_lock);
11791181

11801182
if (atomic_read(&chip->wakeup_path))
11811183
device_set_wakeup_path(dev);
@@ -1198,13 +1200,17 @@ static int pca953x_resume(struct device *dev)
11981200
}
11991201
}
12001202

1203+
mutex_lock(&chip->i2c_lock);
12011204
regcache_cache_only(chip->regmap, false);
12021205
regcache_mark_dirty(chip->regmap);
12031206
ret = pca953x_regcache_sync(dev);
1204-
if (ret)
1207+
if (ret) {
1208+
mutex_unlock(&chip->i2c_lock);
12051209
return ret;
1210+
}
12061211

12071212
ret = regcache_sync(chip->regmap);
1213+
mutex_unlock(&chip->i2c_lock);
12081214
if (ret) {
12091215
dev_err(dev, "Failed to restore register map: %d\n", ret);
12101216
return ret;

0 commit comments

Comments
 (0)