All of lore.kernel.org
 help / color / mirror / Atom feed
From: arnd@arndb.de (Arnd Bergmann)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC 4/5] pinctrl: SPEAr: Add gpio ranges support
Date: Mon, 7 May 2012 15:28:48 +0000	[thread overview]
Message-ID: <201205071528.48460.arnd@arndb.de> (raw)
In-Reply-To: <CACRpkdbhbESbQWX=5RC86X9Z+R767oijDB4myw=bSRay9ud-qQ@mail.gmail.com>

On Monday 07 May 2012, Linus Walleij wrote:
> Hm first I wonder what i2c0 and ssp0 have to do with GPIO...
> Well whatever, maybe split out a special patch just adding the
> groups?
> 
> Please cut down this code by using a clever macro:
> 
> #define SPEAR_PCTL_GRP(a,b) \
> { \
>     .pins =  a##_pins, \
>     .npins = ARRAY_SIZE(a##_pins), \
>     .muxreg = { \
>         .reg = PAD_FUNCTION_EN_2, \
>         .mask PMX_##b##_MASK, \
>         .val = 0, \
>     }, \
> }
> 
> Then:
> 
> static struct spear_gpio_pingroup spear1310_gpio_pingroup[] = {
>     SPEAR_PCTL_GRP(i2c0, I2C0),
>     SPEAR_PCTL_GRP(ssp0, SSP0),
>     SPEAR_PCTL_GRP(ssp0_cs0, SSP0_CS0),
>     (...)
> };
> 
> (You get the picture.)

If you allow me to give my 2 cents, I would recommend the exact opposite
in general: resist the urge to use complex macros for everything!

When that gets too hard, please at least use macros that do not concatenate
C identifies because that makes it really hard to grep for where a constant
gets used. 

A more acceptable macro would be 

#define SPEAR_PCTL_GRP(_pins, _mask) \
{ \
	.pins =  _pins, \
	.npins = ARRAY_SIZE(_pins), \
	.muxreg = { \
	        .reg = PAD_FUNCTION_EN_2, \
	        .mask _val, \
	        .val = 0, \
	}, \
}

but open-coding is generally ok too. Note that you can sometimes save a lot
of lines if you don't first define all those constants as macros but
treat a table like this as the place where you put the raw numbers
from the data sheet, if that the only code location in which they are
used.

	Arnd

  reply	other threads:[~2012-05-07 15:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-27 11:43 [RFC 0/5] pinctrl: SPEAr Updates Viresh Kumar
     [not found] ` <4f7690c68b1fa5ef14b29b88fed50237e068fe4d.1335526926.git.viresh.kumar@st.com>
2012-05-07 12:38   ` [RFC 4/5] pinctrl: SPEAr: Add gpio ranges support Linus Walleij
2012-05-07 15:28     ` Arnd Bergmann [this message]
2012-05-07 15:58       ` viresh kumar
2012-05-09 12:07         ` Linus Walleij
2012-05-07 15:56     ` viresh kumar
2012-05-07 12:39 ` [RFC 0/5] pinctrl: SPEAr Updates Linus Walleij

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=201205071528.48460.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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.