public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Ben Warren <biggerbadderben@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] [PATCH] net: add 16 bit support for smc911x
Date: Tue, 29 Apr 2008 07:43:10 -0700	[thread overview]
Message-ID: <481733FE.2070502@gmail.com> (raw)
In-Reply-To: <20080429100913.23049.90329.stgit@tq-sewsrv-4.tq-net.de>

Hi Jens,

Jens Gehrlein wrote:
> Hi Ben, Magnus,
>
> here is my patch to enable 2x16 bit accesses to the LAN9x1x.
> I still not have a HW, so may I ask you to test it and, if applicable,
> fix the code?
>
> Best Regards,
> Jens
>
> ---
>
>  drivers/net/smc911x.c |   17 ++++++++++++++++-
>  1 files changed, 16 insertions(+), 1 deletions(-)
>
>
> diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
> index d22c889..841a64d 100644
> --- a/drivers/net/smc911x.c
> +++ b/drivers/net/smc911x.c
> @@ -30,6 +30,8 @@
>  #include <net.h>
>  #include <miiphy.h>
>  
> +#define CONFIG_DRIVER_SMC911X_16_BIT 1
> +
>  #ifdef CONFIG_DRIVER_SMC911X_32_BIT
>  static inline u32 reg_read(u32 addr)
>  {
> @@ -39,8 +41,21 @@ static inline void reg_write(u32 addr, u32 val)
>  {
>  	*(volatile u32*)addr = val;
>  }
> +#elif CONFIG_DRIVER_SMC911X_16_BIT
> +static inline u32 reg_read(u32 addr)
> +{
> +	u32 val_lo = (u32)(*(volatile u16*)addr);
> +	u32 val_hi = (u32)(*(volatile u16*)(addr | 2));
> +
>   
This won't work.  Presumably addr will already be a multiple of 2, so 
the bit-wise OR will make val_lo and val_hi identical.  Here's how I'd 
do it:

    volatile u16 *addr_16 = (u16 *)addr;
    return ((*addr_16 & 0x0000ffff) | (*(addr_16 + 1) << 16));

Of course, this could be done as a 1-liner with  castings, but it 
becomes even more unreadable that way.  The mask here might be 
unnecessary too.
> +	return (val_hi << 16) | val_lo;
> +}
> +static inline void reg_write(u32 addr, u32 val)
> +{
> +	*(volatile u16*)addr = (u16)val;
> +	*(volatile u16*)(addr | 2) = (u16)(val >> 16);
>   
Same problem here with the bitwise OR.  Second line should be:
    *(volatile u16*)(addr + 2) = (u16)(val >> 16);
> +}
>  #else
> -#error "SMC911X: Only 32-bit bus is supported"
> +#error "SMC911X: undefined buswidth"
>  #endif
>  
>  #define mdelay(n)       udelay((n)*1000)
>
>   
Thanks for doing this!  Hopefully Magnus will get a chance to try on 
real hardware and we can put this issue to rest.

regards,
Ben

  reply	other threads:[~2008-04-29 14:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-29 10:15 [U-Boot-Users] [PATCH] net: add 16 bit support for smc911x Jens Gehrlein
2008-04-29 14:43 ` Ben Warren [this message]
2008-04-29 14:59   ` Magnus Lilja
2008-04-29 17:23     ` Ben Warren
2008-04-29 20:10 ` Guennadi Liakhovetski
2008-04-30  5:20   ` Jens Gehrlein
2008-04-30  6:11     ` Ben Warren
2008-04-30  8:12       ` Magnus Lilja

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=481733FE.2070502@gmail.com \
    --to=biggerbadderben@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox