From: Mike Frysinger Date: Wed, 22 Jul 2009 04:32:00 -0400 Subject: [U-Boot] [PATCH] Using I/O accessor instead of volatile pointers in SMC911x driver In-Reply-To: <1248250473-12694-1-git-send-email-matthias.weisser@graf-syteco.de> References: <1248250473-12694-1-git-send-email-matthias.weisser@graf-syteco.de> Message-ID: <200907220432.01176.vapier@gentoo.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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