From: Mike Frysinger <vapier@gentoo.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] Using I/O accessor instead of volatile pointers in SMC911x driver
Date: Wed, 22 Jul 2009 04:32:00 -0400 [thread overview]
Message-ID: <200907220432.01176.vapier@gentoo.org> (raw)
In-Reply-To: <1248250473-12694-1-git-send-email-matthias.weisser@graf-syteco.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
next prev parent reply other threads:[~2009-07-22 8:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-22 8:14 [U-Boot] [PATCH] Using I/O accessor instead of volatile pointers in SMC911x driver Matthias Weisser
2009-07-22 8:32 ` Mike Frysinger [this message]
2009-07-23 19:54 ` Wolfgang Denk
2009-07-23 21:25 ` Ben Warren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200907220432.01176.vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.