[U-Boot] [PATCH] Using I/O accessor instead of volatile pointers in SMC911x driver

Mike Frysinger vapier at gentoo.org
Wed Jul 22 10:32:00 CEST 2009


On Wednesday 22 July 2009 04:14:33 Matthias Weisser wrote:
>  static inline u32 smc911x_reg_read(u32 addr)
>  {
> -	volatile u16 *addr_16 = (u16 *)addr;
> -	return ((*addr_16 & 0x0000ffff) | (*(addr_16 + 1) << 16));
> +	u32 res;
> +
> +	res = readw(addr) & 0xFFFF;
> +	res |= ((u32)(readw(addr + 2) & 0xFFFF) << 16);
> +
> +	return res;
>  }
>  static inline void smc911x_reg_write(u32 addr, u32 val)
>  {
> -	*(volatile u16*)addr = (u16)val;
> -	*(volatile u16*)(addr + 2) = (u16)(val >> 16);
> +	writew(val & 0xFFFF, addr);
> +	writew(val >> 16, addr + 2);
>  }

i think your masking and casting are unnecessary.  you're dealing with 
unsigned values which means there wont be sign extension.  the code would look 
a lot simpler without it:
static inline u32 smc911x_reg_read(u32 addr)
{
	return readw(addr) | (readw(addr + 2) << 16);
}
static inline void smc911x_reg_write(u32 addr, u32 val)
{
	writew(val, addr);
	writew(val >> 16, addr + 2);
}
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20090722/0f6545c9/attachment.pgp 


More information about the U-Boot mailing list