From: linus.walleij@linaro.org (Linus Walleij)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] gpio: add a custom configuration mechanism to gpiolib
Date: Thu, 28 Apr 2011 18:07:22 +0200 [thread overview]
Message-ID: <BANLkTimy4zREJyAmtOVEMUSObxWBaJk8Xg@mail.gmail.com> (raw)
In-Reply-To: <BANLkTi=o-2ML0MxNXa0SsFm8JQ1D+_4Zxw@mail.gmail.com>
On Mon, Apr 25, 2011 at 7:21 PM, Stijn Devriendt <highguy@gmail.com> wrote:
> Why contain all values in the config rather than
> // Actual config
> #define GPIO_CONFIG_BIAS 0x1
>
> #define GPIO_BIAS_UNKNOWN 0x0
> #define GPIO_BIAS_FLOAT 0x1
> #define GPIO_BIAS_PULL_UP ? ? ? 0x2
> #define GPIO_BIAS_PULL_DOWN ? ? 0x3
> #define GPIO_BIAS_HIGH ? ? ? ? ?0x4
> #define GPIO_BIAS_GROUND ? ? ? ? ? ? ? ?0x5
> #define GPIO_BIAS_ARCH_SPECIFIC 0x100
>
> #define GPIO_CONFIG_DRIVE 0x2
> /// omitted rest
>
> #define GPIO_CONFIG_COMPLEX_SAMPLE 0x3
> struct gpio_complex_sample_config
> {
> ?// whatever here
> };
>
> // code:
> gpio_config(10, GPIO_CONFIG_BIAS, GPIO_BIAS_FLOAT);
> struct gpio_complex_sample_config config = { ... };
> gpio_config(10, GPIO_CONFIG_COMPLEX_SAMPLE, &config);
It doesn't work like that, since the gpio_config() function has this
signature:
gpio_config(unsigned gpio, u16 param, unsigned long *data);
If you want to pass two parameters you need to store the second
parameter in a variable and pass a pointer to that:
unsigned long data = GPIO_BIAS_FLOAT;
gpio_config(10, GPIO_CONFIG_BIAS, &data);
Well you COULD do this:
gpio_config(10, GPIO_CONFIG_BIAS, (unsigned long *) GPIO_BIAS_FLOAT);
Which leads to inventing pointer-cast macros like we have
for PTR_ERR() and similar to stash enumerators into the
pointer... and since a corresponding get_* operation will
not pass data in the pointer but an actual pointer it gets
awfully asymmetric.
So compared to enumerating and passing simply one argument
and NULL:
gpio_config(10, GPIO_CONFIG_BIAS_FLOAT, NULL);
I think this is less ugly than either of the two above.
Since this is a little bit of matter of taste, I will drive it in the current
version unless there is an massive choir of "no" from all directions.
Yours,
Linus Walleij
prev parent reply other threads:[~2011-04-28 16:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-20 16:00 [PATCH 1/2] gpio: add a custom configuration mechanism to gpiolib Linus Walleij
2011-04-25 17:21 ` Stijn Devriendt
2011-04-28 16:07 ` Linus Walleij [this message]
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=BANLkTimy4zREJyAmtOVEMUSObxWBaJk8Xg@mail.gmail.com \
--to=linus.walleij@linaro.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).