diff options
author | Mario Six <mario.six@gdsys.cc> | 2018-10-15 09:24:11 +0200 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2018-11-14 09:16:27 -0800 |
commit | d5c7bd985d759b7aade2700c11890821e6187e4b (patch) | |
tree | 1ae2265b0c770b50524fb4e0655d74a866c24422 /drivers | |
parent | 84ff8f622d2e2aeb67c1cec1c2c814895648fca8 (diff) | |
download | u-boot-d5c7bd985d759b7aade2700c11890821e6187e4b.tar.gz |
regmap: Support reading from specific range
It is useful to be able to treat the different ranges of a regmap
separately to be able to use distinct offset for them, but this is
currently not implemented in the regmap API.
To preserve backwards compatibility, add regmap_read_range and
regmap_write_range functions that take an additional parameter
'range_num' that identifies the range to operate on.
Reviewed-by: Anatolij Gustschin <agust@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mario Six <mario.six@gdsys.cc>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/core/regmap.c | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c index 916d9272ea..9b2e02af2e 100644 --- a/drivers/core/regmap.c +++ b/drivers/core/regmap.c @@ -188,11 +188,25 @@ int regmap_uninit(struct regmap *map) return 0; } -int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len) +int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset, + void *valp, size_t val_len) { + struct regmap_range *range; void *ptr; - ptr = map_physmem(map->ranges[0].start + offset, val_len, MAP_NOCACHE); + if (range_num >= map->range_count) { + debug("%s: range index %d larger than range count\n", + __func__, range_num); + return -ERANGE; + } + range = &map->ranges[range_num]; + + ptr = map_physmem(range->start + offset, val_len, MAP_NOCACHE); + + if (offset + val_len > range->size) { + debug("%s: offset/size combination invalid\n", __func__); + return -ERANGE; + } switch (val_len) { case REGMAP_SIZE_8: @@ -213,20 +227,39 @@ int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len) debug("%s: regmap size %zu unknown\n", __func__, val_len); return -EINVAL; } + return 0; } +int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len) +{ + return regmap_raw_read_range(map, 0, offset, valp, val_len); +} + int regmap_read(struct regmap *map, uint offset, uint *valp) { return regmap_raw_read(map, offset, valp, REGMAP_SIZE_32); } -int regmap_raw_write(struct regmap *map, uint offset, const void *val, - size_t val_len) +int regmap_raw_write_range(struct regmap *map, uint range_num, uint offset, + const void *val, size_t val_len) { + struct regmap_range *range; void *ptr; - ptr = map_physmem(map->ranges[0].start + offset, val_len, MAP_NOCACHE); + if (range_num >= map->range_count) { + debug("%s: range index %d larger than range count\n", + __func__, range_num); + return -ERANGE; + } + range = &map->ranges[range_num]; + + ptr = map_physmem(range->start + offset, val_len, MAP_NOCACHE); + + if (offset + val_len > range->size) { + debug("%s: offset/size combination invalid\n", __func__); + return -ERANGE; + } switch (val_len) { case REGMAP_SIZE_8: @@ -251,6 +284,12 @@ int regmap_raw_write(struct regmap *map, uint offset, const void *val, return 0; } +int regmap_raw_write(struct regmap *map, uint offset, const void *val, + size_t val_len) +{ + return regmap_raw_write_range(map, 0, offset, val, val_len); +} + int regmap_write(struct regmap *map, uint offset, uint val) { return regmap_raw_write(map, offset, &val, REGMAP_SIZE_32); |