[U-Boot] [PATCH v2 3/5] regmap: Define regmap_{get,set}
Mario Six
mario.six at gdsys.cc
Fri Apr 27 12:52:01 UTC 2018
It would be convenient if one could use the regmap API in conjunction
with register maps defined as structs (i.e. structs that directly mirror
the memory layout of the registers in question). A similar approach was
planned with the regmap_write32/regmap_read32 macros, but was never
used.
Hence, implement regmap_set/regmap_range_set and
regmap_get/regmap_range_get macros, which, given a register map, a
struct describing the layout of the register map, and a member name
automatically produce regmap_read/regmap_write calls that access the
specified member in the register map.
Signed-off-by: Mario Six <mario.six at gdsys.cc>
---
v1 -> v2:
New in v2
---
include/regmap.h | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/regmap.h b/include/regmap.h
index bb7e947ce2..69cbe8a96a 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -49,11 +49,17 @@ int regmap_write(struct regmap *map, ulong offset, ulong val, enum regmap_size_t
int regmap_read_ext(struct regmap *map, uint range_num, ulong offset, ulong *valp, enum regmap_size_t size);
int regmap_read(struct regmap *map, ulong offset, ulong *valp, enum regmap_size_t size);
-#define regmap_write32(map, ptr, member, val) \
- regmap_write(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), val)
+#define regmap_range_set(map, range, type, member, val) \
+ regmap_write_ext(map, range, offsetof(type, member), val, sizeof(((type *)0)->member))
-#define regmap_read32(map, ptr, member, valp) \
- regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp)
+#define regmap_set(map, type, member, val) \
+ regmap_range_set(map, 0, type, member, val)
+
+#define regmap_range_get(map, range, type, member, valp) \
+ regmap_read_ext(map, range, offsetof(type, member), (void *)valp, sizeof(((type *)0)->member))
+
+#define regmap_get(map, type, member, valp) \
+ regmap_range_get(map, 0, type, member, valp) \
/**
* regmap_init_mem() - Set up a new register map that uses memory access
--
2.16.1
More information about the U-Boot
mailing list