public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Albert ARIBAUD <albert.u.boot@aribaud.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/3] drivers/smc911x: Add support for shifted register read/write
Date: Thu, 13 Feb 2014 10:27:53 +0100	[thread overview]
Message-ID: <20140213102753.1ae7ba0b@lilith> (raw)
In-Reply-To: <1387542756-2857-2-git-send-email-rspliet@eclipso.eu>

Hi Roy,

Re: the subject: please next time put the version in the subjetc line
too. You may benefit from using patman, which helps managing patch
series and handles such things as adding version in suject lines and
Cc:ing people according to tags, etc. see tools/patman/README.

Also:

On Fri, 20 Dec 2013 13:32:34 +0100, Roy Spliet <rspliet@eclipso.eu>
wrote:

> Required for (but potentially not limited to) the snowball board. Implementation
> is inspired by the linux smsc911x implementation, but by using a (pre-compiler)
> constant, things should be optimised by the compiler for a shift of 0.
> 
> Signed-off-by: Roy Spliet <rspliet@eclipso.eu>
> ---
>  drivers/net/smc911x.h | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/smc911x.h b/drivers/net/smc911x.h
> index acae0cf..7144722 100644
> --- a/drivers/net/smc911x.h
> +++ b/drivers/net/smc911x.h
> @@ -19,6 +19,12 @@
>  	CONFIG_SMC911X_16_BIT shall be set"
>  #endif
>  
> +#ifndef CONFIG_SMC911X_SHIFT
> +#define CONFIG_SMC911X_SHIFT 0
> +#endif
> +
> +#define smc911x_shift(i) ((i) << CONFIG_SMC911X_SHIFT)

I find that defining a macro just to shift a field by a constant value
is over-engineering. It is not really worse to do the (i << NNN)@the
point(s) of use, and the reader will immediately understand what's
being done.

>  #if defined (CONFIG_SMC911X_32_BIT)
>  static inline u32 __smc911x_reg_read(struct eth_device *dev, u32 offset)
>  {
> @@ -37,14 +43,14 @@ void smc911x_reg_write(struct eth_device *dev, u32 offset, u32 val)
>  #elif defined (CONFIG_SMC911X_16_BIT)
>  static inline u32 smc911x_reg_read(struct eth_device *dev, u32 offset)
>  {
> -	volatile u16 *addr_16 = (u16 *)(dev->iobase + offset);
> -	return ((*addr_16 & 0x0000ffff) | (*(addr_16 + 1) << 16));
> +	volatile u16 *addr_16 = (u16 *)(dev->iobase + smc911x_shift(offset));
> +	return (*addr_16 & 0x0000FFFF) | (*(addr_16 + smc911x_shift(1)) << 16);
>  }
>  static inline void smc911x_reg_write(struct eth_device *dev,
>  					u32 offset, u32 val)
>  {
> -	*(volatile u16 *)(dev->iobase + offset) = (u16)val;
> -	*(volatile u16 *)(dev->iobase + offset + 2) = (u16)(val >> 16);
> +	*(volatile u16 *)(dev->iobase + smc911x_shift(offset)) = (u16)val;
> +	*(volatile u16 *)(dev->iobase + smc911x_shift(offset + 2)) = (u16)val;
>  }
>  #else
>  #error "SMC911X: undefined bus width"

Amicalement,
-- 
Albert.

  reply	other threads:[~2014-02-13  9:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-20 12:32 [U-Boot] Improve upstream support for Snowball board (v2) Roy Spliet
2013-12-20 12:32 ` [U-Boot] [PATCH 1/3] drivers/smc911x: Add support for shifted register read/write Roy Spliet
2014-02-13  9:27   ` Albert ARIBAUD [this message]
2013-12-20 12:32 ` [U-Boot] [PATCH 2/3] board/snowball: Add support for network boot Roy Spliet
2014-02-13  9:29   ` Albert ARIBAUD
2013-12-20 12:32 ` [U-Boot] [PATCH 3/3] board/snowball: Enable FDT Roy Spliet

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=20140213102753.1ae7ba0b@lilith \
    --to=albert.u.boot@aribaud.net \
    --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