[U-Boot] [PATCH v4 08/13] regmap: Support reading from specific range
Mario Six
mario.six at gdsys.cc
Fri Aug 3 08:01:13 UTC 2018
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 at denx.de>
Reviewed-by: Simon Glass <sjg at chromium.org>
Signed-off-by: Mario Six <mario.six at gdsys.cc>
---
v3 -> v4:
No changes
v2 -> v3:
* Renamed the functions to regmap_{write,read}_range
* Added function comments
* Fixed style violations
* Improved error handling
v1 -> v2:
New in v2
---
drivers/core/regmap.c | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
include/regmap.h | 31 +++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+), 5 deletions(-)
diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 87c4c950a63..86b35edc050 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:
@@ -208,20 +222,39 @@ int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len)
debug("%s: regmap size %u 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:
@@ -241,6 +274,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);
diff --git a/include/regmap.h b/include/regmap.h
index 46ae4ed0a03..df672df9fe1 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -113,6 +113,37 @@ int regmap_raw_write(struct regmap *map, uint offset, const void *val,
int regmap_raw_read(struct regmap *map, uint offset, void *valp,
size_t val_len);
+/**
+ * regmap_raw_write_range() - Write a value of specified length to a range of a
+ * regmap
+ *
+ * @map: Regmap to write to
+ * @range_num: Number of the range in the regmap to write to
+ * @offset: Offset in the regmap to write to
+ * @val: Value to write to the regmap at the specified offset
+ * @val_len: Length of the data to be written to the regmap
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int regmap_raw_write_range(struct regmap *map, uint range_num, uint offset,
+ const void *val, size_t val_len);
+
+/**
+ * regmap_raw_read_range() - Read a value of specified length from a range of a
+ * regmap
+ *
+ * @map: Regmap to read from
+ * @range_num: Number of the range in the regmap to write to
+ * @offset: Offset in the regmap to read from
+ * @valp: Pointer to the buffer to receive the data read from the regmap
+ * at the specified offset
+ * @val_len: Length of the data to be read from the regmap
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset,
+ void *valp, size_t val_len);
+
#define regmap_write32(map, ptr, member, val) \
regmap_write(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), val)
--
2.11.0
More information about the U-Boot
mailing list