Skip to content

Commit 954757d

Browse files
Dimitris Papastamosbroonie
authored andcommitted
regmap: Implement generic syncing functionality
In the absence of a sync callback, do it manually. This of course can't take advantange of the specific optimizations of each cache type but it will do well enough in most cases. Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent dfdc444 commit 954757d

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

‎drivers/base/regmap/regcache.c‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,20 +223,39 @@ EXPORT_SYMBOL_GPL(regcache_write);
223223
*/
224224
int regcache_sync(struct regmap *map)
225225
{
226-
int ret;
226+
int ret = 0;
227+
unsigned int val;
228+
unsigned int i;
227229
const char *name;
228230

229231
BUG_ON(!map->cache_ops);
230232

233+
dev_dbg(map->dev, "Syncing %s cache\n",
234+
map->cache_ops->name);
235+
name = map->cache_ops->name;
236+
trace_regcache_sync(map->dev, name, "start");
231237
if (map->cache_ops->sync) {
232-
dev_dbg(map->dev, "Syncing %s cache\n",
233-
map->cache_ops->name);
234-
name = map->cache_ops->name;
235-
trace_regcache_sync(map->dev, name, "start");
236238
ret = map->cache_ops->sync(map);
237-
trace_regcache_sync(map->dev, name, "stop");
239+
} else {
240+
for (i = 0; i < map->num_reg_defaults; i++) {
241+
ret = regcache_read(map, i, &val);
242+
if (ret < 0)
243+
goto out;
244+
regcache_cache_bypass(map, true);
245+
ret = regcache_write(map, i, val);
246+
regcache_cache_bypass(map, false);
247+
if (ret < 0)
248+
goto out;
249+
dev_dbg(map->dev, "Synced register %#x, value %#x\n",
250+
map->reg_defaults[i].reg,
251+
map->reg_defaults[i].def);
252+
}
253+
238254
}
239-
return 0;
255+
out:
256+
trace_regcache_sync(map->dev, name, "stop");
257+
258+
return ret;
240259
}
241260
EXPORT_SYMBOL_GPL(regcache_sync);
242261

0 commit comments

Comments
 (0)