Skip to contentSkip to conversation

regmap: add regmap_update_bits and sandbox R/W test

PATCH New Neil Armstrong 3 participants 7 messages Apr 27, 2018 – May 8, 2018

lore
Share & tools
lore
#0 lore raw

v2 cover regmap: add regmap_update_bits and sandbox R/W test

This patchset adds the regmap_update_bits() to easy read/modify/write like the Linux ragmap API.

The second patch adds a read/update_bits/write test to call these functions but we cannot check the behaviour since io read/write is not implemented on the sandbox arch.

Changes since v1:
- moved from include to regmap.c
- added a sandbox test

Neil Armstrong (2):
regmap: add regmap_update_bits() helper
test: regmap: add read/modify/write test

 drivers/core/regmap.c | 14 ++++++++++++++
 include/regmap.h      | 10 ++++++++++
 test/dm/regmap.c      | 24 ++++++++++++++++++++++++
 3 files changed, 48 insertions(+)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/2 regmap: add regmap_update_bits() helper

Add the regmap_update_bits() to simply the read/modify/write of registers in a single command. The function is taken from Linux regmap implementation.

---
 drivers/core/regmap.c | 14 ++++++++++++++
 include/regmap.h      | 10 ++++++++++
 2 files changed, 24 insertions(+)
drivers/core/regmap.c +14 -0
index 8a0e00f..9fae252 100644
@@ -147,3 +147,17 @@ int regmap_write(struct regmap *map, uint offset, uint val)
 
 	return 0;
 }
+
+int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val)
+{
+	uint reg;
+	int ret;
+
+	ret = regmap_read(map, offset, &reg);
+	if (ret)
+		return ret;
+
+	reg &= ~mask;
+
+	return regmap_write(map, offset, reg | val);
+}
include/regmap.h +10 -0
index 493a5d8..1349d40 100644
@@ -47,6 +47,16 @@ int regmap_read(struct regmap *map, uint offset, uint *valp);
 	regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp)
 
 /**
+ * regmap_update_bits() - Perform a read/modify/write using a mask
+ *
+ * @map:	The map returned by regmap_init_mem*()
+ * @offset:	Offset of the memory
+ * @mask:	Mask to apply to the read value
+ * @val:	Value to apply to the value to write
+ */
+int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val);
+
+/**
  * regmap_init_mem() - Set up a new register map that uses memory access
  *
  * Use regmap_uninit() to free it.
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 1/2 regmap: add regmap_update_bits() helper

Hi Neil,

Quoted 10 lines · Neil Armstrong

Add the regmap_update_bits() to simply the read/modify/write of registers in a single command. The function is taken from Linux regmap implementation.

---
 drivers/core/regmap.c | 14 ++++++++++++++
 include/regmap.h      | 10 ++++++++++
 2 files changed, 24 insertions(+)

nit below:

Quoted 28 lines
drivers/core/regmap.c +14 -0
index 8a0e00f..9fae252 100644
@@ -147,3 +147,17 @@ int regmap_write(struct regmap *map, uint offset, uint val)
 
        return 0;
 }
+
+int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val)
+{
+       uint reg;
+       int ret;
+
+       ret = regmap_read(map, offset, &reg);
+       if (ret)
+               return ret;
+
+       reg &= ~mask;
+
+       return regmap_write(map, offset, reg | val);
+}
include/regmap.h +0 -0
index 493a5d8..1349d40 100644

include/regmap.h int regmap_read(struct regmap *map, uint offset, uint *valp); · line 55

Quoted 9 lines
include/regmap.h +6 -0
@@ -47,6 +47,16 @@ int regmap_read(struct regmap *map, uint offset, uint *valp);
        regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp)
 
 /**
+ * regmap_update_bits() - Perform a read/modify/write using a mask
+ *
+ * @map:       The map returned by regmap_init_mem*()
+ * @offset:    Offset of the memory
+ * @mask:      Mask to apply to the read value
+ * @val:       Value to apply to the value to write

How about 'Value to OR to the value to write"

Quoted 10 lines
include/regmap.h +4 -1
+ */
+int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val);
+
+/**
  * regmap_init_mem() - Set up a new register map that uses memory access
  *
  * Use regmap_uninit() to free it.
--

2.7.4

Regards,
Simon

#3 lore raw

PATCH v2 1/2 regmap: add regmap_update_bits() helper

In reply to Neil Armstrong
Quoted 6 lines · Neil Armstrong

Add the regmap_update_bits() to simply the read/modify/write of registers in a single command. The function is taken from Linux regmap implementation.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180508/d9a2eeb2/attachment.sig>
#4 lore raw

PATCH v2 2/2 test: regmap: add read/modify/write test

In reply to Neil Armstrong

Add calls to regmap_read/modify_bits/write even if the proper memory read/write calls are not executed in sandbox.

---
 test/dm/regmap.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
test/dm/regmap.c +25 -0
index 7f66058..42f17c6 100644
@@ -80,3 +80,28 @@ static int dm_test_regmap_syscon(struct unit_test_state *uts)
 }
 
 DM_TEST(dm_test_regmap_syscon, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Read/Write/Modify test */
+static int dm_test_regmap_rw(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	struct regmap *map;
+	uint reg;
+
+	ut_assertok(uclass_get_device(UCLASS_SYSCON, 0, &dev));
+	map = syscon_get_regmap(dev);
+	ut_assertok_ptr(map);
+
+	ut_assertok(regmap_write(map, 0, 0xcacafafa));
+	ut_assertok(regmap_write(map, 3, 0x55aa2211));
+
+	ut_assertok(regmap_read(map, 0, &reg));
+	ut_assertok(regmap_read(map, 3, &reg));
+
+	ut_assertok(regmap_update_bits(map, 0, 0xff00ff00, 0x55aa2211));
+	ut_assertok(regmap_update_bits(map, 3, 0x00ff00ff, 0xcacafada));
+
+	return 0;
+}
+
+DM_TEST(dm_test_regmap_rw, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
Signature · 1 line
2.7.4
#6 lore raw

PATCH v2 2/2 test: regmap: add read/modify/write test

In reply to Neil Armstrong
Quoted 5 lines · Neil Armstrong

Add calls to regmap_read/modify_bits/write even if the proper memory read/write calls are not executed in sandbox.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180508/3fa0aab2/attachment.sig>