* [PATCH] mxc/gpio: make _set_value work with values != 0/1
@ 2010-10-11 11:59 Peter Korsgaard
2010-10-11 12:12 ` Marc Kleine-Budde
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Peter Korsgaard @ 2010-10-11 11:59 UTC (permalink / raw)
To: linux-arm-kernel
Documentation/gpio.txt specifies that the value argument to
gpio_set_value() should be handled as a boolean (E.G. != 0 is high),
so use the same logic as in _set_direction().
Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
---
arch/arm/plat-mxc/gpio.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/arch/arm/plat-mxc/gpio.c b/arch/arm/plat-mxc/gpio.c
index 57ec4a8..e226801 100644
--- a/arch/arm/plat-mxc/gpio.c
+++ b/arch/arm/plat-mxc/gpio.c
@@ -234,8 +234,13 @@ static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
u32 l;
unsigned long flags;
+
spin_lock_irqsave(&port->lock, flags);
- l = (__raw_readl(reg) & (~(1 << offset))) | (value << offset);
+ l = __raw_readl(reg);
+ if (value)
+ l |= 1 << offset;
+ else
+ l &= ~(1 << offset);
__raw_writel(l, reg);
spin_unlock_irqrestore(&port->lock, flags);
}
--
1.7.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH] mxc/gpio: make _set_value work with values != 0/1
2010-10-11 11:59 [PATCH] mxc/gpio: make _set_value work with values != 0/1 Peter Korsgaard
@ 2010-10-11 12:12 ` Marc Kleine-Budde
2010-10-11 12:18 ` Peter Korsgaard
2010-10-11 12:15 ` Uwe Kleine-König
2010-10-11 12:17 ` Baruch Siach
2 siblings, 1 reply; 11+ messages in thread
From: Marc Kleine-Budde @ 2010-10-11 12:12 UTC (permalink / raw)
To: linux-arm-kernel
On 10/11/2010 01:59 PM, Peter Korsgaard wrote:
> Documentation/gpio.txt specifies that the value argument to
> gpio_set_value() should be handled as a boolean (E.G. != 0 is high),
> so use the same logic as in _set_direction().
>
> Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
> ---
> arch/arm/plat-mxc/gpio.c | 7 ++++++-
> 1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/arch/arm/plat-mxc/gpio.c b/arch/arm/plat-mxc/gpio.c
> index 57ec4a8..e226801 100644
> --- a/arch/arm/plat-mxc/gpio.c
> +++ b/arch/arm/plat-mxc/gpio.c
> @@ -234,8 +234,13 @@ static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
> u32 l;
> unsigned long flags;
>
> +
> spin_lock_irqsave(&port->lock, flags);
> - l = (__raw_readl(reg) & (~(1 << offset))) | (value << offset);
what about using "!!value" instead of just "value".
> + l = __raw_readl(reg);
> + if (value)
> + l |= 1 << offset;
> + else
> + l &= ~(1 << offset);
> __raw_writel(l, reg);
> spin_unlock_irqrestore(&port->lock, flags);
> }
cheers, Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20101011/2c692258/attachment.sig>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] mxc/gpio: make _set_value work with values != 0/1
2010-10-11 12:12 ` Marc Kleine-Budde
@ 2010-10-11 12:18 ` Peter Korsgaard
0 siblings, 0 replies; 11+ messages in thread
From: Peter Korsgaard @ 2010-10-11 12:18 UTC (permalink / raw)
To: linux-arm-kernel
>>>>> "Marc" == Marc Kleine-Budde <mkl@pengutronix.de> writes:
Hi,
Marc> On 10/11/2010 01:59 PM, Peter Korsgaard wrote:
>> Documentation/gpio.txt specifies that the value argument to
>> gpio_set_value() should be handled as a boolean (E.G. != 0 is high),
>> so use the same logic as in _set_direction().
>>
>> Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
>> ---
>> arch/arm/plat-mxc/gpio.c | 7 ++++++-
>> 1 files changed, 6 insertions(+), 1 deletions(-)
>>
>> diff --git a/arch/arm/plat-mxc/gpio.c b/arch/arm/plat-mxc/gpio.c
>> index 57ec4a8..e226801 100644
>> --- a/arch/arm/plat-mxc/gpio.c
>> +++ b/arch/arm/plat-mxc/gpio.c
>> @@ -234,8 +234,13 @@ static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
>> u32 l;
>> unsigned long flags;
>>
>> +
>> spin_lock_irqsave(&port->lock, flags);
>> - l = (__raw_readl(reg) & (~(1 << offset))) | (value << offset);
Marc> what about using "!!value" instead of just "value".
Sure, that's equivalent, but I found that harder to read. My form has
the extra advantage that it matches the structure of
_set_gpio_direction() just above.
--
Bye, Peter Korsgaard
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] mxc/gpio: make _set_value work with values != 0/1
2010-10-11 11:59 [PATCH] mxc/gpio: make _set_value work with values != 0/1 Peter Korsgaard
2010-10-11 12:12 ` Marc Kleine-Budde
@ 2010-10-11 12:15 ` Uwe Kleine-König
2010-10-11 12:21 ` Peter Korsgaard
2010-10-11 12:17 ` Baruch Siach
2 siblings, 1 reply; 11+ messages in thread
From: Uwe Kleine-König @ 2010-10-11 12:15 UTC (permalink / raw)
To: linux-arm-kernel
Hallali,
On Mon, Oct 11, 2010 at 01:59:05PM +0200, Peter Korsgaard wrote:
> Documentation/gpio.txt specifies that the value argument to
> gpio_set_value() should be handled as a boolean (E.G. != 0 is high),
> so use the same logic as in _set_direction().
>
> Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
> ---
> arch/arm/plat-mxc/gpio.c | 7 ++++++-
> 1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/arch/arm/plat-mxc/gpio.c b/arch/arm/plat-mxc/gpio.c
> index 57ec4a8..e226801 100644
> --- a/arch/arm/plat-mxc/gpio.c
> +++ b/arch/arm/plat-mxc/gpio.c
> @@ -234,8 +234,13 @@ static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
> u32 l;
> unsigned long flags;
>
> +
> spin_lock_irqsave(&port->lock, flags);
> - l = (__raw_readl(reg) & (~(1 << offset))) | (value << offset);
> + l = __raw_readl(reg);
> + if (value)
> + l |= 1 << offset;
> + else
> + l &= ~(1 << offset);
Why not just
l = (__raw_readl(reg) & (~(1 << offset))) | (!!value << offset);
?
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] mxc/gpio: make _set_value work with values != 0/1
2010-10-11 12:15 ` Uwe Kleine-König
@ 2010-10-11 12:21 ` Peter Korsgaard
2010-10-11 13:19 ` Michał Nazarewicz
0 siblings, 1 reply; 11+ messages in thread
From: Peter Korsgaard @ 2010-10-11 12:21 UTC (permalink / raw)
To: linux-arm-kernel
>>>>> "Uwe" == Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de> writes:
Hi,
Uwe> On Mon, Oct 11, 2010 at 01:59:05PM +0200, Peter Korsgaard wrote:
>> @@ -234,8 +234,13 @@ static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
>> u32 l;
>> unsigned long flags;
>>
>> +
Ups, that extra line shouldn't have been there.
>> spin_lock_irqsave(&port->lock, flags);
>> - l = (__raw_readl(reg) & (~(1 << offset))) | (value << offset);
>> + l = __raw_readl(reg);
>> + if (value)
>> + l |= 1 << offset;
>> + else
>> + l &= ~(1 << offset);
Uwe> Why not just
Uwe> l = (__raw_readl(reg) & (~(1 << offset))) | (!!value << offset);
Se my other reply. I don't feel strongly about it, but I for one don't
remember the precedence rules for !! and << offhand.
--
Bye, Peter Korsgaard
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] mxc/gpio: make _set_value work with values != 0/1
2010-10-11 12:21 ` Peter Korsgaard
@ 2010-10-11 13:19 ` Michał Nazarewicz
0 siblings, 0 replies; 11+ messages in thread
From: Michał Nazarewicz @ 2010-10-11 13:19 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, 11 Oct 2010 14:21:30 +0200, Peter Korsgaard <jacmet@sunsite.dk> wrote:
> Se my other reply. I don't feel strongly about it, but I for one don't
> remember the precedence rules for !! and << offhand.
A bit off-topic, but hopefuly it'll help someone:
1. (In C,) one argument operators have binding tighter than two (or three) argument
operators. (The only exception to this rule is the :: operator in C++ which has
the tighest binding of all operators.)
2. The next rule, is that one argument postfix operators has tigter binding
then prefix operators, thus *a++ is *(a++).
I find those two rules let me understand most operatrs use cases. Hope this
helps. :)
Also, I haven't followed the patch from the beginnig (just stumbled accross
some mails), but anoter possible solution to the problem would be to change
the type of "value" to "bool".
--
Best regards, _ _
| Humble Liege of Serenely Enlightened Majesty of o' \,=./ `o
| Computer Science, Micha? "mina86" Nazarewicz (o o)
+----[mina86*mina86.com]---[mina86*jabber.org]----ooO--(_)--Ooo--
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] mxc/gpio: make _set_value work with values != 0/1
2010-10-11 11:59 [PATCH] mxc/gpio: make _set_value work with values != 0/1 Peter Korsgaard
2010-10-11 12:12 ` Marc Kleine-Budde
2010-10-11 12:15 ` Uwe Kleine-König
@ 2010-10-11 12:17 ` Baruch Siach
2010-10-11 12:23 ` Peter Korsgaard
2 siblings, 1 reply; 11+ messages in thread
From: Baruch Siach @ 2010-10-11 12:17 UTC (permalink / raw)
To: linux-arm-kernel
Hi Peter,
On Mon, Oct 11, 2010 at 01:59:05PM +0200, Peter Korsgaard wrote:
> Documentation/gpio.txt specifies that the value argument to
> gpio_set_value() should be handled as a boolean (E.G. != 0 is high),
> so use the same logic as in _set_direction().
>
> Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
> ---
> arch/arm/plat-mxc/gpio.c | 7 ++++++-
> 1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/arch/arm/plat-mxc/gpio.c b/arch/arm/plat-mxc/gpio.c
> index 57ec4a8..e226801 100644
> --- a/arch/arm/plat-mxc/gpio.c
> +++ b/arch/arm/plat-mxc/gpio.c
> @@ -234,8 +234,13 @@ static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
> u32 l;
> unsigned long flags;
>
> +
Unneeded empty line.
> spin_lock_irqsave(&port->lock, flags);
> - l = (__raw_readl(reg) & (~(1 << offset))) | (value << offset);
> + l = __raw_readl(reg);
> + if (value)
> + l |= 1 << offset;
> + else
> + l &= ~(1 << offset);
Alternative shorter version:
l = (__raw_readl(reg) & (~(1 << offset))) | (!!value << offset);
baruch
> __raw_writel(l, reg);
> spin_unlock_irqrestore(&port->lock, flags);
> }
> --
> 1.7.1
--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH] mxc/gpio: make _set_value work with values != 0/1
2010-10-11 12:17 ` Baruch Siach
@ 2010-10-11 12:23 ` Peter Korsgaard
2010-10-11 12:39 ` Sascha Hauer
0 siblings, 1 reply; 11+ messages in thread
From: Peter Korsgaard @ 2010-10-11 12:23 UTC (permalink / raw)
To: linux-arm-kernel
>>>>> "Baruch" == Baruch Siach <baruch@tkos.co.il> writes:
Hi,
>> +
Baruch> Unneeded empty line.
Yeah, just noticed as well.
>> spin_lock_irqsave(&port->lock, flags);
>> - l = (__raw_readl(reg) & (~(1 << offset))) | (value << offset);
>> + l = __raw_readl(reg);
>> + if (value)
>> + l |= 1 << offset;
>> + else
>> + l &= ~(1 << offset);
Baruch> Alternative shorter version:
Baruch> l = (__raw_readl(reg) & (~(1 << offset))) | (!!value << offset);
Well, what do you know - I seem to be outnumbered ;)
Sasha, do you want the !! version instead? Then I'll resend.
--
Bye, Peter Korsgaard
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] mxc/gpio: make _set_value work with values != 0/1
2010-10-11 12:23 ` Peter Korsgaard
@ 2010-10-11 12:39 ` Sascha Hauer
2010-10-11 12:47 ` Peter Korsgaard
0 siblings, 1 reply; 11+ messages in thread
From: Sascha Hauer @ 2010-10-11 12:39 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Oct 11, 2010 at 02:23:00PM +0200, Peter Korsgaard wrote:
> >>>>> "Baruch" == Baruch Siach <baruch@tkos.co.il> writes:
>
> Hi,
>
> >> +
>
> Baruch> Unneeded empty line.
>
> Yeah, just noticed as well.
>
> >> spin_lock_irqsave(&port->lock, flags);
> >> - l = (__raw_readl(reg) & (~(1 << offset))) | (value << offset);
> >> + l = __raw_readl(reg);
> >> + if (value)
> >> + l |= 1 << offset;
> >> + else
> >> + l &= ~(1 << offset);
>
> Baruch> Alternative shorter version:
>
> Baruch> l = (__raw_readl(reg) & (~(1 << offset))) | (!!value << offset);
This is shorter but I find this significantly harder to read and I bet
the compiler generates the same code from both versions.
>
> Well, what do you know - I seem to be outnumbered ;)
>
> Sasha, do you want the !! version instead? Then I'll resend.
I like the !! version. The only problem with this is that people tend
to try to remove the !! as it looks like a noop at first sight.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] mxc/gpio: make _set_value work with values != 0/1
2010-10-11 12:39 ` Sascha Hauer
@ 2010-10-11 12:47 ` Peter Korsgaard
2010-10-11 12:54 ` Sascha Hauer
0 siblings, 1 reply; 11+ messages in thread
From: Peter Korsgaard @ 2010-10-11 12:47 UTC (permalink / raw)
To: linux-arm-kernel
>>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
Hi,
Baruch> Alternative shorter version:
Baruch> l = (__raw_readl(reg) & (~(1 << offset))) | (!!value << offset);
Sascha> This is shorter but I find this significantly harder to read and I bet
Sascha> the compiler generates the same code from both versions.
Agreed.
>> Well, what do you know - I seem to be outnumbered ;)
>>
>> Sasha, do you want the !! version instead? Then I'll resend.
Sascha> I like the !! version. The only problem with this is that people tend
Sascha> to try to remove the !! as it looks like a noop at first sight.
So what then? Do you want me to change to !!, resend with the extra
empty line removed or just let you remove the line when you apply it?
--
Bye, Peter Korsgaard
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] mxc/gpio: make _set_value work with values != 0/1
2010-10-11 12:47 ` Peter Korsgaard
@ 2010-10-11 12:54 ` Sascha Hauer
0 siblings, 0 replies; 11+ messages in thread
From: Sascha Hauer @ 2010-10-11 12:54 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, Oct 11, 2010 at 02:47:41PM +0200, Peter Korsgaard wrote:
> >>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
>
> Hi,
>
> Baruch> Alternative shorter version:
> Baruch> l = (__raw_readl(reg) & (~(1 << offset))) | (!!value << offset);
>
> Sascha> This is shorter but I find this significantly harder to read and I bet
> Sascha> the compiler generates the same code from both versions.
>
> Agreed.
>
> >> Well, what do you know - I seem to be outnumbered ;)
> >>
> >> Sasha, do you want the !! version instead? Then I'll resend.
>
> Sascha> I like the !! version. The only problem with this is that people tend
> Sascha> to try to remove the !! as it looks like a noop at first sight.
>
> So what then? Do you want me to change to !!, resend with the extra
> empty line removed or just let you remove the line when you apply it?
If noone replies with '!! totally sucks' within 2 minutes just send a
patch which changes it to !! and removes the extra empty line.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2010-10-11 13:19 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-11 11:59 [PATCH] mxc/gpio: make _set_value work with values != 0/1 Peter Korsgaard
2010-10-11 12:12 ` Marc Kleine-Budde
2010-10-11 12:18 ` Peter Korsgaard
2010-10-11 12:15 ` Uwe Kleine-König
2010-10-11 12:21 ` Peter Korsgaard
2010-10-11 13:19 ` Michał Nazarewicz
2010-10-11 12:17 ` Baruch Siach
2010-10-11 12:23 ` Peter Korsgaard
2010-10-11 12:39 ` Sascha Hauer
2010-10-11 12:47 ` Peter Korsgaard
2010-10-11 12:54 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox