mxc/gpio: make _set_value work with values != 0/1
Subsystems (3)
PATCH 1/1 mxc/gpio: make _set_value work with values != 0/1
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().
--- arch/arm/plat-mxc/gpio.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
arch/arm/plat-mxc/gpio.c +6 -1
@@ -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); }
Signature · 1 line
1.7.1
PATCH 1/1 mxc/gpio: make _set_value work with values != 0/1
Quoted 14 lines · Peter Korsgaard
Documentation/gpio.txtspecifies that the value argument togpio_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 <[email protected]>--- arch/arm/plat-mxc/gpio.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)arch/arm/plat-mxc/gpio.c +0
-0
arch/arm/plat-mxc/gpio.c static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 238
Quoted 6 lines
arch/arm/plat-mxc/gpio.c +1
-1@@ -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".
arch/arm/plat-mxc/gpio.c static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 246
Quoted 8 lines
arch/arm/plat-mxc/gpio.c +5
-0+ 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
Signature · 12 lines
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>
PATCH 1/1 mxc/gpio: make _set_value work with values != 0/1
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Marc" == Marc Kleine-Budde <[email protected]> writes:
Hi,
Quoted 17 lines · Peter Korsgaard
Quoted 17 lines
Documentation/gpio.txtspecifies that the value argument togpio_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 <[email protected]>---
arch/arm/plat-mxc/gpio.c| 7 ++++++-1 files changed, 6 insertions(+), 1 deletions(-)arch/arm/plat-mxc/gpio.c +0
-0@@ -234,8 +234,13 @@ static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value)u32 l;unsigned long flags;
Quoted 3 lines
arch/arm/plat-mxc/gpio.c static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 238
Quoted 3 lines
arch/arm/plat-mxc/gpio.c +1
-1+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.
Signature · 1 line
Bye, Peter Korsgaard
PATCH 1/1 mxc/gpio: make _set_value work with values != 0/1
In reply to Peter KorsgaardHallali,
Quoted 15 lines · Peter Korsgaard
Documentation/gpio.txtspecifies that the value argument togpio_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 <[email protected]>--- arch/arm/plat-mxc/gpio.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)arch/arm/plat-mxc/gpio.c +0
-0@@ -234,8 +234,13 @@ static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value)u32 l;
arch/arm/plat-mxc/gpio.c static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 243
Quoted 10 lines
arch/arm/plat-mxc/gpio.c +6
-1unsigned 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
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH 1/1 mxc/gpio: make _set_value work with values != 0/1
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Uwe" == Uwe Kleine-K?nig <[email protected]> writes:
Hi,
Quoted 5 lines · Peter Korsgaard
arch/arm/plat-mxc/gpio.c static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 237
Quoted 5 lines
arch/arm/plat-mxc/gpio.c +1
-0@@ -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.
Quoted 7 lines
arch/arm/plat-mxc/gpio.c static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 243
Quoted 7 lines
arch/arm/plat-mxc/gpio.c +5
-1spin_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.
Signature · 1 line
Bye, Peter Korsgaard
PATCH 1/1 mxc/gpio: make _set_value work with values != 0/1
Quoted 2 lines · Peter Korsgaard
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".
Signature · 4 lines
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--
PATCH 1/1 mxc/gpio: make _set_value work with values != 0/1
In reply to Peter KorsgaardHi Peter,
Quoted 14 lines · Peter Korsgaard
Documentation/gpio.txtspecifies that the value argument togpio_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 <[email protected]>--- arch/arm/plat-mxc/gpio.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)arch/arm/plat-mxc/gpio.c +0
-0
arch/arm/plat-mxc/gpio.c static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 237
Quoted 4 lines
arch/arm/plat-mxc/gpio.c +1
-0@@ -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.
arch/arm/plat-mxc/gpio.c static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 243
Quoted 7 lines
arch/arm/plat-mxc/gpio.c +5
-1spin_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
Quoted 5 lines
arch/arm/plat-mxc/gpio.c +0
-0__raw_writel (l, reg);spin_unlock_irqrestore (&port->lock, flags); }Signature · 1 line
1.7.1
Signature · 3 lines
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -PATCH 1/1 mxc/gpio: make _set_value work with values != 0/1
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Baruch" == Baruch Siach <[email protected]> writes:
Hi,
Quoted 1 line
Quoted 1 line
+
Baruch> Unneeded empty line.
Yeah, just noticed as well.
Quoted 7 lines
arch/arm/plat-mxc/gpio.c static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 243
Quoted 7 lines
spin_lock_irqsave(&port->lock, flags);arch/arm/plat-mxc/gpio.c +5
-1- 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.
Signature · 1 line
Bye, Peter Korsgaard
Sascha Hauer
maintainerPATCH 1/1 mxc/gpio: make _set_value work with values != 0/1
Quoted 20 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Baruch" == Baruch Siach <[email protected]> writes:
Hi,
Quoted 1 line
Quoted 1 line
+
Baruch> Unneeded empty line.
Yeah, just noticed as well.
Quoted 7 lines
arch/arm/plat-mxc/gpio.c static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 243
Quoted 7 lines
spin_lock_irqsave(&port->lock, flags);arch/arm/plat-mxc/gpio.c +5
-1- 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:
Quoted 1 line
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.
Quoted 4 lines
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
Signature · 4 lines
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 |
PATCH 1/1 mxc/gpio: make _set_value work with values != 0/1
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Sascha" == Sascha Hauer <[email protected]> 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.
Quoted 3 lines
Quoted 3 lines
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?
Signature · 1 line
Bye, Peter Korsgaard
Sascha Hauer
maintainerPATCH 1/1 mxc/gpio: make _set_value work with values != 0/1
Quoted 14 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Sascha" == Sascha Hauer <[email protected]> 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.
Quoted 2 lines
Quoted 2 lines
Well, what do you know - I seem to be outnumbered ;)
Quoted 7 lines
Quoted 1 line
Quoted 1 line
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
Signature · 4 lines
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 |