[U-Boot] [PATCH v11 10/16] regmap: Define regmap_{get,set}
Mario Six
mario.six at gdsys.cc
Mon Oct 15 07:24:12 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.
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>
---
v10 -> v11:
No changes
v9 -> v10:
No changes
v8 -> v9:
No changes
v7 -> v8:
No changes
v6 -> v7:
No changes
v5 -> v6:
No changes
v4 -> v5:
No changes
v3 -> v4:
No changes
v2 -> v3:
* Fixed style violations
* Added documentation
v1 -> v2:
New in v2
---
include/regmap.h | 54 ++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 50 insertions(+), 4 deletions(-)
diff --git a/include/regmap.h b/include/regmap.h
index eba300da29..3b7eea5f49 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -146,11 +146,57 @@ int regmap_raw_write_range(struct regmap *map, uint range_num, uint offset,
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)
+/**
+ * regmap_range_set() - Set a value in a regmap range described by a struct
+ * @map: Regmap in which a value should be set
+ * @range: Range of the regmap in which a value should be set
+ * @type: Structure type that describes the memory layout of the regmap range
+ * @member: Member of the describing structure that should be set in the regmap
+ * range
+ * @val: Value which should be written to the regmap range
+ */
+#define regmap_range_set(map, range, type, member, val) \
+ do { \
+ typeof(((type *)0)->member) __tmp = val; \
+ regmap_raw_write_range(map, range, offsetof(type, member), \
+ &__tmp, sizeof(((type *)0)->member)); \
+ } while (0)
+
+/**
+ * regmap_set() - Set a value in a regmap described by a struct
+ * @map: Regmap in which a value should be set
+ * @type: Structure type that describes the memory layout of the regmap
+ * @member: Member of the describing structure that should be set in the regmap
+ * @val: Value which should be written to the regmap
+ */
+#define regmap_set(map, type, member, val) \
+ regmap_range_set(map, 0, type, member, val)
-#define regmap_read32(map, ptr, member, valp) \
- regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp)
+/**
+ * regmap_range_get() - Get a value from a regmap range described by a struct
+ * @map: Regmap from which a value should be read
+ * @range: Range of the regmap from which a value should be read
+ * @type: Structure type that describes the memory layout of the regmap
+ * range
+ * @member: Member of the describing structure that should be read in the
+ * regmap range
+ * @valp: Variable that receives the value read from the regmap range
+ */
+#define regmap_range_get(map, range, type, member, valp) \
+ regmap_raw_read_range(map, range, offsetof(type, member), \
+ (void *)valp, sizeof(((type *)0)->member))
+
+/**
+ * regmap_get() - Get a value from a regmap described by a struct
+ * @map: Regmap from which a value should be read
+ * @type: Structure type that describes the memory layout of the regmap
+ * range
+ * @member: Member of the describing structure that should be read in the
+ * regmap
+ * @valp: Variable that receives the value read from the regmap
+ */
+#define regmap_get(map, type, member, valp) \
+ regmap_range_get(map, 0, type, member, valp)
/**
* regmap_update_bits() - Perform a read/modify/write using a mask
--
2.18.1
More information about the U-Boot
mailing list