dm: regmap: Various fixes for regmap
cover dm: regmap: Various fixes for regmap
Recently a feature was added to allow sandbox to do memory-mapped IO using readl(), writel(), etc. This adds a few fixes and improvements to this.
It also includes an updated version of Jean-Jacques patch to add more tests for regmap.
Jean-Jacques Hiblot (1):
test: regmap: check the values read from the regmap
Simon Glass (4):
sandbox: test: Show hex values on failure
sandbox: Drop 'const' from sandbox_write()
sandbox: test: Add a prototype for sandbox_set_enable_memio()
dm: regmap: Fix mask in regmap_update_bits()
arch/sandbox/cpu/cpu.c | 3 +-- arch/sandbox/include/asm/io.h | 11 +++++------ arch/sandbox/include/asm/test.h | 11 +++++++++++ drivers/core/regmap.c | 2 +- include/regmap.h | 3 ++- include/test/ut.h | 3 ++- test/dm/regmap.c | 19 ++++++++++++++++--- 7 files changed, 38 insertions(+), 14 deletions(-)
Signature · 1 line
2.23.0.700.g56cf767bdb-goog
PATCH 1/5 sandbox: test: Show hex values on failure
Quite a few tests use addresses or hex values for comparisons. Add hex output for test failures, e.g.:
0x55ca22fa == reg: Expected 0x55ca22fa (1439310586),
got 0x55ea22fb (1441407739)
---
include/test/ut.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/test/ut.h +2 -1
@@ -61,7 +61,8 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,if (val1 != val2) { \ut_failf (uts, __FILE__, __LINE__, __func__, \ #expr1 " == " #expr2, \ -"Expected %d, got %d" , val1, val2); \ +"Expected %#x (%d), got %#x (%d)" , val1, val1, \ + val2, val2); \return CMD_RET_FAILURE ; \ } \ }
Signature · 1 line
2.23.0.700.g56cf767bdb-goog
PATCH 1/5 sandbox: test: Show hex values on failure
Quoted 4 lines · Simon Glass
Quite a few tests use addresses or hex values for comparisons. Add hex output for test failures, e.g.:
Quoted 9 lines
0x55ca22fa == reg: Expected 0x55ca22fa (1439310586), got 0x55ea22fb (1441407739)Signed-off-by Simon Glass <[email protected]>---
include/test/ut.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
PATCH 1/5 sandbox: test: Show hex values on failure
Quoted 4 lines · Simon Glass
Quite a few tests use addresses or hex values for comparisons. Add hex output for test failures, e.g.:
Quoted 9 lines
0x55ca22fa == reg: Expected 0x55ca22fa (1439310586), got 0x55ea22fb (1441407739)Signed-off-by Simon Glass <[email protected]>---
include/test/ut.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Applied to u-boot-dm, thanks!
PATCH 2/5 sandbox: Drop 'const' from sandbox_write()
In reply to Simon GlassThis function writes to its address so the address should not be declared as const. Fix it.
---
arch/sandbox/cpu/cpu.c | 3 +-- arch/sandbox/include/asm/io.h | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-)
arch/sandbox/cpu/cpu.c +1 -2
@@ -246,8 +246,7 @@ unsigned int sandbox_read(const void *addr, enum sandboxio_size_t size)return 0 ; } -void sandbox_write (const void *addr,unsigned int val, -enum sandboxio_size_t size) +void sandbox_write (void *addr,unsigned int val,enum sandboxio_size_t size) {struct sandbox_state *state =state_get_current ();
arch/sandbox/include/asm/io.h +5 -6
@@ -46,8 +46,7 @@ static inline void unmap_sysmem(const void *vaddr)phys_addr_t map_to_sysmem (const void *ptr);unsigned int sandbox_read (const void *addr,enum sandboxio_size_t size); -void sandbox_write (const void *addr,unsigned int val, -enum sandboxio_size_t size); +void sandbox_write (void *addr,unsigned int val,enum sandboxio_size_t size);#define readb (addr) sandbox_read((const void *)addr, SB_SIZE_8)#define readw (addr) sandbox_read((const void *)addr, SB_SIZE_16)
@@ -55,11 +54,11 @@ void sandbox_write(const void *addr, unsigned int val,#ifdef CONFIG_SANDBOX64 #define readq (addr) sandbox_read((const void *)addr, SB_SIZE_64)#endif -#define writeb (v, addr) sandbox_write((const void *)addr, v, SB_SIZE_8) -#define writew (v, addr) sandbox_write((const void *)addr, v, SB_SIZE_16) -#define writel (v, addr) sandbox_write((const void *)addr, v, SB_SIZE_32) +#define writeb (v, addr) sandbox_write((void *)addr, v, SB_SIZE_8) +#define writew (v, addr) sandbox_write((void *)addr, v, SB_SIZE_16) +#define writel (v, addr) sandbox_write((void *)addr, v, SB_SIZE_32)#ifdef CONFIG_SANDBOX64 -#define writeq (v, addr) sandbox_write((const void *)addr, v, SB_SIZE_64) +#define writeq (v, addr) sandbox_write((void *)addr, v, SB_SIZE_64)#endif /*
Signature · 1 line
2.23.0.700.g56cf767bdb-goog
PATCH 2/5 sandbox: Drop 'const' from sandbox_write()
Hi Simon,
Quoted 11 lines · Simon Glass
This function writes to its address so the address should not be declared as const. Fix it.
Signed-off-by Simon Glass <[email protected]>---
arch/sandbox/cpu/cpu.c | 3 +-- arch/sandbox/include/asm/io.h | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-)
It looks I did something wrong when testing the previous patch :) I remember adding const was to fix build warning somewhere else.
Anyway the changes look good to me. But I suspect we need give it a full build to see whether it generates warning somewhere.
PATCH 2/5 sandbox: Drop 'const' from sandbox_write()
Hi Simon,
Quoted 11 lines · Simon Glass
This function writes to its address so the address should not be declared as const. Fix it.
Signed-off-by Simon Glass <[email protected]>---
arch/sandbox/cpu/cpu.c | 3 +-- arch/sandbox/include/asm/io.h | 11 +++++------ 2 files changed, 6 insertions(+), 8 deletions(-)
It looks I did something wrong when testing the previous patch :) I remember adding const was to fix build warning somewhere else.
Anyway the changes look good to me. But I suspect we need give it a full build to see whether it generates warning somewhere.
Applied to u-boot-dm, thanks!
PATCH 3/5 sandbox: test: Add a prototype for sandbox_set_enable_memio()
In reply to Simon GlassThis function needs a prototype so that tests can use it. Add one.
---
arch/sandbox/include/asm/test.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/sandbox/include/asm/test.h +11 -0
@@ -213,4 +213,15 @@ int sandbox_get_pci_ep_irq_count(struct udevice *dev);*/ uint sandbox_pci_read_bar (u32 barval,int type,uint size); +/** +* sandbox_set_enable_memio() - Enable readl/writel() for sandbox +* +* Normally these I/O functions do nothing with sandbox. Certain tests need them +* to work as for other architectures, so this function can be used to enable +* them. +* +* @enable: true to enable, false to disable +*/ +void sandbox_set_enable_memio (bool enable); +#endif
Signature · 1 line
2.23.0.700.g56cf767bdb-goog
PATCH 3/5 sandbox: test: Add a prototype for sandbox_set_enable_memio()
Quoted 9 lines · Simon Glass
This function needs a prototype so that tests can use it. Add one.
Signed-off-by Simon Glass <[email protected]>---
arch/sandbox/include/asm/test.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
PATCH 3/5 sandbox: test: Add a prototype for sandbox_set_enable_memio()
Quoted 9 lines · Simon Glass
This function needs a prototype so that tests can use it. Add one.
Signed-off-by Simon Glass <[email protected]>---
arch/sandbox/include/asm/test.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
Applied to u-boot-dm, thanks!
PATCH 4/5 dm: regmap: Fix mask in regmap_update_bits()
In reply to Simon GlassThis function assumes that the 'val' parameter has no masked bits set. This is not defined by the function prototype though. Fix the function to mask the value and update the documentation.
---
drivers/core/regmap.c | 2 +- include/regmap.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
drivers/core/regmap.c +1 -1
@@ -462,5 +462,5 @@ int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val) reg &= ~mask; -return regmap_write (map, offset, reg | val); +return regmap_write (map, offset, reg | (val & mask)); }
include/regmap.h +2 -1
@@ -295,7 +295,8 @@ int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset,* @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 +* @val: Value to OR with the read value after masking. Note that any +* bits set in @val which are not set in @mask are ignored * Return: 0 if OK, -ve on error */ int regmap_update_bits (struct regmap *map,uint offset,uint mask,uint val);
Signature · 1 line
2.23.0.700.g56cf767bdb-goog
PATCH 4/5 dm: regmap: Fix mask in regmap_update_bits()
Quoted 5 lines · Simon Glass
This function assumes that the 'val' parameter has no masked bits set. This is not defined by the function prototype though. Fix the function to mask the value and update the documentation.
Quoted 7 lines
Signed-off-by Simon Glass <[email protected]>---
drivers/core/regmap.c | 2 +- include/regmap.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
PATCH 4/5 dm: regmap: Fix mask in regmap_update_bits()
In reply to Simon GlassQuoted 27 lines · Simon Glass
This function assumes that the 'val' parameter has no masked bits set. This is not defined by the function prototype though. Fix the function to mask the value and update the documentation.
Signed-off-by Simon Glass <[email protected]>---
drivers/core/regmap.c | 2 +- include/regmap.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)drivers/core/regmap.c +1
-1@@ -462,5 +462,5 @@ int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val) reg &= ~mask; -return regmap_write (map, offset, reg | val); +return regmap_write (map, offset, reg | (val & mask)); }include/regmap.h +0
-0
include/regmap.h int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset, · line 302
Quoted 9 lines
include/regmap.h +2
-1@@ -295,7 +295,8 @@ int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset,* @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 +* @val: Value to OR with the read value after masking. Note that any +* bits set in @val which are not set in @mask are ignored * Return: 0 if OK, -ve on error */ int regmap_update_bits (struct regmap *map,uint offset,uint mask,uint val);
PATCH 4/5 dm: regmap: Fix mask in regmap_update_bits()
Quoted 11 lines · Simon Glass
This function assumes that the 'val' parameter has no masked bits set. This is not defined by the function prototype though. Fix the function to mask the value and update the documentation.
Signed-off-by Simon Glass <[email protected]>---
drivers/core/regmap.c | 2 +- include/regmap.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
Applied to u-boot-dm, thanks!
PATCH 5/5 test: regmap: check the values read from the regmap
In reply to Simon GlassFrom: Jean-Jacques Hiblot <[email protected]>
The test did reads after writes but didn't check the value. It probably was because the sandbox didn't implement the writeX/readX functions.
Updated to use sandbox_set_enable_memio():
---
test/dm/regmap.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
test/dm/regmap.c +16 -3
@@ -99,18 +99,27 @@ static int dm_test_regmap_rw(struct unit_test_state *uts)struct regmap *map;uint reg; +sandbox_set_enable_memio (true);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_write (map,5 ,0x55aa2211 ));ut_assertok (regmap_read (map,0 , ®)); -ut_assertok (regmap_read (map,3 , ®)); +ut_asserteq (0xcacafafa , reg); +ut_assertok (regmap_read (map,5 , ®)); +ut_asserteq (0x55aa2211 , reg); +ut_assertok (regmap_read (map,0 , ®)); +ut_asserteq (0xcacafafa , reg);ut_assertok (regmap_update_bits (map,0 ,0xff00ff00 ,0x55aa2211 )); -ut_assertok (regmap_update_bits (map,3 ,0x00ff00ff ,0xcacafada )); +ut_assertok (regmap_read (map,0 , ®)); +ut_asserteq (0x55ca22fa , reg); +ut_assertok (regmap_update_bits (map,5 ,0x00ff00ff ,0xcacafada )); +ut_assertok (regmap_read (map,5 , ®)); +ut_asserteq (0x55ca22da , reg);return 0 ; }
@@ -130,6 +139,7 @@ static int dm_test_regmap_getset(struct unit_test_state *uts)u32 val3; }; +sandbox_set_enable_memio (true);ut_assertok (uclass_get_device (UCLASS_SYSCON ,0 , &dev)); map =syscon_get_regmap (dev);ut_assertok_ptr (map);
@@ -138,7 +148,9 @@ static int dm_test_regmap_getset(struct unit_test_state *uts) regmap_set(map, struct layout, val3, 0x55aa2211); ut_assertok(regmap_get(map, struct layout, val0, ®)); +ut_asserteq (0xcacafafa , reg); ut_assertok(regmap_get(map, struct layout, val3, ®)); +ut_asserteq (0x55aa2211 , reg);return 0 ; }
@@ -159,6 +171,7 @@ static int dm_test_regmap_poll(struct unit_test_state *uts) start =get_timer (0 ); +ut_assertok (regmap_write (map,0 ,0x0 )); ut_asserteq(-ETIMEDOUT, regmap_read_poll_timeout_test(map, 0, reg, (reg == 0xcacafafa),
Signature · 1 line
2.23.0.700.g56cf767bdb-goog
PATCH 5/5 test: regmap: check the values read from the regmap
Quoted 7 lines · Simon Glass
From: Jean-Jacques Hiblot <[email protected]>
The test did reads after writes but didn't check the value. It probably was because the sandbox didn't implement the writeX/readX functions.
Quoted 8 lines
Signed-off-by Jean-Jacques Hiblot <[email protected]>Updated to use
sandbox_set_enable_memio():Signed-off-by Simon Glass <[email protected]>---
test/dm/regmap.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
PATCH 5/5 test: regmap: check the values read from the regmap
Quoted 7 lines · Simon Glass
From: Jean-Jacques Hiblot <[email protected]>
The test did reads after writes but didn't check the value. It probably was because the sandbox didn't implement the writeX/readX functions.
Quoted 8 lines
Signed-off-by Jean-Jacques Hiblot <[email protected]>Updated to use
sandbox_set_enable_memio():Signed-off-by Simon Glass <[email protected]>---
test/dm/regmap.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
Applied to u-boot-dm, thanks!