Skip to content

Commit 99e8dd3

Browse files
charleskeepaxbroonie
authored andcommitted
regmap: Add missing cache_only checks
The current behaviour around cache_only is slightly inconsistent, most paths will only check cache_only if cache_bypass is false, and will return -EBUSY if a read attempts to go to the hardware whilst cache_only is true. However, a couple of paths will not check cache_only at all. The most notable of these being regmap_raw_read which will check cache_only in the case it processes the transaction one register at a time, but not in the case it handles them as a block. In the typical case a device has been put into cache_only whilst powered down this can cause physical reads to happen whilst the device is unavailable. Add a check in regmap_raw_read and move the check in regmap_noinc_read, adding a check for cache_bypass, such that all paths are covered and consistent. Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com> Link: https://lore.kernel.org/r/20230601101036.1499612-2-ckeepax@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 02534c8 commit 99e8dd3

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

drivers/base/regmap/regmap.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,6 +2981,11 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
29812981
size_t chunk_count, chunk_bytes;
29822982
size_t chunk_regs = val_count;
29832983

2984+
if (!map->cache_bypass && map->cache_only) {
2985+
ret = -EBUSY;
2986+
goto out;
2987+
}
2988+
29842989
if (!map->read) {
29852990
ret = -ENOTSUPP;
29862991
goto out;
@@ -3076,18 +3081,19 @@ int regmap_noinc_read(struct regmap *map, unsigned int reg,
30763081
goto out_unlock;
30773082
}
30783083

3084+
/*
3085+
* We have not defined the FIFO semantics for cache, as the
3086+
* cache is just one value deep. Should we return the last
3087+
* written value? Just avoid this by always reading the FIFO
3088+
* even when using cache. Cache only will not work.
3089+
*/
3090+
if (!map->cache_bypass && map->cache_only) {
3091+
ret = -EBUSY;
3092+
goto out_unlock;
3093+
}
3094+
30793095
/* Use the accelerated operation if we can */
30803096
if (map->bus->reg_noinc_read) {
3081-
/*
3082-
* We have not defined the FIFO semantics for cache, as the
3083-
* cache is just one value deep. Should we return the last
3084-
* written value? Just avoid this by always reading the FIFO
3085-
* even when using cache. Cache only will not work.
3086-
*/
3087-
if (map->cache_only) {
3088-
ret = -EBUSY;
3089-
goto out_unlock;
3090-
}
30913097
ret = regmap_noinc_readwrite(map, reg, val, val_len, false);
30923098
goto out_unlock;
30933099
}

0 commit comments

Comments
 (0)