Patchwork [U-Boot,V5.1,1/6] io: add and* and or* operation api to set and clear bit

login
register
mail settings
Submitter Lei Wen
Date March 29, 2011, 2:53 a.m.
Message ID <1301367218-13339-1-git-send-email-leiwen@marvell.com>
Download mbox | patch
Permalink /patch/88719/
State Superseded
Delegated to: Marek Vasut
Headers show

Comments

Lei Wen - March 29, 2011, 2:53 a.m.
Those api take use of read*/write* to align the current dmb usage.
Also this could short the code length in one line.

Signed-off-by: Lei Wen <leiwen@marvell.com>
---
Changelog:
V2:
V3:
V4:
Move original driver specific bit set to the general place

V5:
fix code style issue

V5.1:
Add parentheses for the around incoming parameters to prevent
parsing the complex expression wrong.

 arch/arm/include/asm/io.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
Prafulla Wadaskar - March 29, 2011, 5:40 a.m.
> -----Original Message-----
> From: Lei Wen [mailto:leiwen@marvell.com]
> Sent: Tuesday, March 29, 2011 8:24 AM
> To: Scott Wood; Heiko Schocher; Prafulla Wadaskar; Wolfgang Denk; u-
> boot@lists.denx.de; Marek Vasut; Ashish Karkare; Prabhanjan Sarnaik; Yu
> Tang; adrian.wenl@gmail.com
> Subject: [PATCH V5.1 1/6] io: add and* and or* operation api to set and
> clear bit
> 
> Those api take use of read*/write* to align the current dmb usage.
> Also this could short the code length in one line.
> 
> Signed-off-by: Lei Wen <leiwen@marvell.com>
> ---
> Changelog:
> V2:
> V3:
> V4:
> Move original driver specific bit set to the general place
> 
> V5:
> fix code style issue
> 
> V5.1:
> Add parentheses for the around incoming parameters to prevent
> parsing the complex expression wrong.
> 
>  arch/arm/include/asm/io.h |    8 ++++++++
>  1 files changed, 8 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
> index 1fbc531..71e85e8 100644
> --- a/arch/arm/include/asm/io.h
> +++ b/arch/arm/include/asm/io.h
> @@ -141,6 +141,14 @@ extern inline void __raw_readsl(unsigned int addr,
> void *data, int longlen)
>  #define readw(c)	({ u16 __v = __arch_getw(c); __iormb(); __v; })
>  #define readl(c)	({ u32 __v = __arch_getl(c); __iormb(); __v; })
> 
> +#define orb(v, c)       writeb(readb(c) | (v), c)

If I am not wrong, this should be like
#define orb(v, c)       writeb((readb(c) | v), c)

Regards..
Prafulla . .
Mike Frysinger - March 29, 2011, 5:44 a.m.
On Tue, Mar 29, 2011 at 1:40 AM, Prafulla Wadaskar wrote:
> From: Lei Wen [mailto:leiwen@marvell.com]
>> +#define orb(v, c)       writeb(readb(c) | (v), c)
>
> If I am not wrong, this should be like
> #define orb(v, c)       writeb((readb(c) | v), c)

no, Lei's version is correct.  yours mishandles v, and adds useless
paren to the first arg to writeb.  writeb itself should be wrapping
its first arg in paren if need be.
-mike

Patch

diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index 1fbc531..71e85e8 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -141,6 +141,14 @@  extern inline void __raw_readsl(unsigned int addr, void *data, int longlen)
 #define readw(c)	({ u16 __v = __arch_getw(c); __iormb(); __v; })
 #define readl(c)	({ u32 __v = __arch_getl(c); __iormb(); __v; })
 
+#define orb(v, c)       writeb(readb(c) | (v), c)
+#define orw(v, c)       writew(readw(c) | (v), c)
+#define orl(v, c)       writel(readl(c) | (v), c)
+
+#define andb(v, c)      writeb(readb(c) & (v), c)
+#define andw(v, c)      writew(readw(c) & (v), c)
+#define andl(v, c)      writel(readl(c) & (v), c)
+
 /*
  * The compiler seems to be incapable of optimising constants
  * properly.  Spell it out to the compiler in some cases.