regmap: add regmap_update_bits and sandbox R/W test
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
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
@@ -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, ®); +if (ret) +return ret; + + reg &= ~mask; + +return regmap_write (map, offset, reg | val); +}
include/regmap.h +10 -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 + */ +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
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.Signed-off-by Neil Armstrong <[email protected]>--- 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@@ -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, ®); +if (ret) +return ret; + + reg &= ~mask; + +return regmap_write (map, offset, reg | val); +}include/regmap.h +0
-0
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
PATCH v2 1/2 regmap: add regmap_update_bits() helper
In reply to Neil ArmstrongQuoted 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.Signed-off-by Neil Armstrong <[email protected]>Reviewed-by Simon Glass <[email protected]>
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>
PATCH v2 2/2 test: regmap: add read/modify/write test
In reply to Neil ArmstrongAdd 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
@@ -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 , ®)); +ut_assertok (regmap_read (map,3 , ®)); + +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
PATCH v2 2/2 test: regmap: add read/modify/write test
Quoted 7 lines · Neil Armstrong
Add calls to regmap_read/modify_bits/write even if the proper memory read/write calls are not executed in sandbox.
Signed-off-by Neil Armstrong <[email protected]>--- test/dm/regmap.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
PATCH v2 2/2 test: regmap: add read/modify/write test
In reply to Neil ArmstrongQuoted 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.
Signed-off-by Neil Armstrong <[email protected]>Reviewed-by Simon Glass <[email protected]>
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>