aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Six2018-10-15 02:24:11 -0500
committerSimon Glass2018-11-14 11:16:27 -0600
commitd5c7bd985d759b7aade2700c11890821e6187e4b (patch)
tree1ae2265b0c770b50524fb4e0655d74a866c24422 /drivers
parent84ff8f622d2e2aeb67c1cec1c2c814895648fca8 (diff)
downloadu-boot-d5c7bd985d759b7aade2700c11890821e6187e4b.tar.gz
u-boot-d5c7bd985d759b7aade2700c11890821e6187e4b.tar.xz
u-boot-d5c7bd985d759b7aade2700c11890821e6187e4b.zip
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.c49
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)
188 return 0; 188 return 0;
189} 189}
190 190
191int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len) 191int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset,
192 void *valp, size_t val_len)
192{ 193{
194 struct regmap_range *range;
193 void *ptr; 195 void *ptr;
194 196
195 ptr = map_physmem(map->ranges[0].start + offset, val_len, MAP_NOCACHE); 197 if (range_num >= map->range_count) {
198 debug("%s: range index %d larger than range count\n",
199 __func__, range_num);
200 return -ERANGE;
201 }
202 range = &map->ranges[range_num];
203
204 ptr = map_physmem(range->start + offset, val_len, MAP_NOCACHE);
205
206 if (offset + val_len > range->size) {
207 debug("%s: offset/size combination invalid\n", __func__);
208 return -ERANGE;
209 }
196 210
197 switch (val_len) { 211 switch (val_len) {
198 case REGMAP_SIZE_8: 212 case REGMAP_SIZE_8:
@@ -213,20 +227,39 @@ int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len)
213 debug("%s: regmap size %zu unknown\n", __func__, val_len); 227 debug("%s: regmap size %zu unknown\n", __func__, val_len);
214 return -EINVAL; 228 return -EINVAL;
215 } 229 }
230
216 return 0; 231 return 0;
217} 232}
218 233
234int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len)
235{
236 return regmap_raw_read_range(map, 0, offset, valp, val_len);
237}
238
219int regmap_read(struct regmap *map, uint offset, uint *valp) 239int regmap_read(struct regmap *map, uint offset, uint *valp)
220{ 240{
221 return regmap_raw_read(map, offset, valp, REGMAP_SIZE_32); 241 return regmap_raw_read(map, offset, valp, REGMAP_SIZE_32);
222} 242}
223 243
224int regmap_raw_write(struct regmap *map, uint offset, const void *val, 244int regmap_raw_write_range(struct regmap *map, uint range_num, uint offset,
225 size_t val_len) 245 const void *val, size_t val_len)
226{ 246{
247 struct regmap_range *range;
227 void *ptr; 248 void *ptr;
228 249
229 ptr = map_physmem(map->ranges[0].start + offset, val_len, MAP_NOCACHE); 250 if (range_num >= map->range_count) {
251 debug("%s: range index %d larger than range count\n",
252 __func__, range_num);
253 return -ERANGE;
254 }
255 range = &map->ranges[range_num];
256
257 ptr = map_physmem(range->start + offset, val_len, MAP_NOCACHE);
258
259 if (offset + val_len > range->size) {
260 debug("%s: offset/size combination invalid\n", __func__);
261 return -ERANGE;
262 }
230 263
231 switch (val_len) { 264 switch (val_len) {
232 case REGMAP_SIZE_8: 265 case REGMAP_SIZE_8:
@@ -251,6 +284,12 @@ int regmap_raw_write(struct regmap *map, uint offset, const void *val,
251 return 0; 284 return 0;
252} 285}
253 286
287int regmap_raw_write(struct regmap *map, uint offset, const void *val,
288 size_t val_len)
289{
290 return regmap_raw_write_range(map, 0, offset, val, val_len);
291}
292
254int regmap_write(struct regmap *map, uint offset, uint val) 293int regmap_write(struct regmap *map, uint offset, uint val)
255{ 294{
256 return regmap_raw_write(map, offset, &val, REGMAP_SIZE_32); 295 return regmap_raw_write(map, offset, &val, REGMAP_SIZE_32);