From: Christophe LEROY <christophe.leroy@c-s.fr>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>, Scott Wood <oss@buserror.net>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] powerpc: sysdev: cpm1: Optimise gpio bit calculation
Date: Fri, 10 Mar 2017 15:41:23 +0100 [thread overview]
Message-ID: <777e903f-b816-5efa-2ece-e4e16fab27c6@c-s.fr> (raw)
In-Reply-To: <20170310143241.GJ31469@gate.crashing.org>
Le 10/03/2017 à 15:32, Segher Boessenkool a écrit :
> On Fri, Mar 10, 2017 at 03:04:48PM +0100, Christophe LEROY wrote:
>> Le 10/03/2017 à 14:06, Segher Boessenkool a écrit :
>>> On Fri, Mar 10, 2017 at 11:54:19AM +0100, Christophe LEROY wrote:
>>>> gpio_get() and gpio_set() are used extensively by some GPIO based
>>>> drivers like SPI, NAND, so it may be worth it as it doesn't impair
>>>> readability (if anyone prefers, we could write (1 << 31) >> i instead
>>>> of 0x80000000 >> i )
>>>
>>> 1 << 31 is undefined behaviour, of course.
>>>
>>
>> Shall it be 1U << 31 ?
>
> Sure, that works. "1 << (31 - i)" is most readable (but it doesn't yet
> generate the code you want).
>
>
Euh .... I'm a bit lost. Do you mean the form we have today is the
driver is wrong ?
@@ -684,9 +682,7 @@ static int cpm1_gpio32_get(struct gpio_chip *gc,
unsigned int gpio)
{
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
struct cpm_ioport32b __iomem *iop = mm_gc->regs;
- u32 pin_mask;
-
- pin_mask = 1 << (31 - gpio);
+ u32 pin_mask = 0x80000000 >> gpio;
return !!(in_be32(&iop->dat) & pin_mask);
}
Which I thought could also become
@@ -684,9 +682,7 @@ static int cpm1_gpio32_get(struct gpio_chip *gc,
unsigned int gpio)
{
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
struct cpm_ioport32b __iomem *iop = mm_gc->regs;
- u32 pin_mask;
-
- pin_mask = 1 << (31 - gpio);
+ u32 pin_mask = (1 << 31) >> gpio;
return !!(in_be32(&iop->dat) & pin_mask);
}
Christophe
next prev parent reply other threads:[~2017-03-10 14:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-09 9:42 Christophe Leroy
2017-03-10 8:41 ` Michael Ellerman
2017-03-10 10:54 ` Christophe LEROY
2017-03-10 13:06 ` Segher Boessenkool
2017-03-10 14:04 ` Christophe LEROY
2017-03-10 14:32 ` Segher Boessenkool
2017-03-10 14:41 ` Christophe LEROY [this message]
2017-03-10 15:41 ` Segher Boessenkool
2017-03-21 15:04 ` Christophe LEROY
2017-03-10 13:02 ` Segher Boessenkool
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=777e903f-b816-5efa-2ece-e4e16fab27c6@c-s.fr \
--to=christophe.leroy@c-s.fr \
--cc=benh@kernel.crashing.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=oss@buserror.net \
--cc=paulus@samba.org \
--cc=segher@kernel.crashing.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
all inboxes | Powered by JetHome®