From: Phil Sutter <n0-1@freewrt.org>
To: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Cc: Ralf Baechle <ralf@linux-mips.org>, linux-mips@linux-mips.org
Subject: Re: [PATCH] provide functions for gpio configuration
Date: Mon, 3 Nov 2008 15:29:42 +0100 [thread overview]
Message-ID: <20081103142942.GA13461@nuty> (raw)
In-Reply-To: <490E2200.1070201@ru.mvista.com>
Hi,
On Mon, Nov 03, 2008 at 12:56:16AM +0300, Sergei Shtylyov wrote:
> >+ val &= ~( ~bitval << offset ); /* unset bit if bitval == 0 */
> >
>
> If bitval == 0, ~bitval evaluates to all ones, and the final AND mask
> ~(0xffffffff << offset) clears 32-offset MSBs. What you want is simply
> ~(1 << offset).
Right, I messed up boolean and bitwise inverting. The correct line is:
| val &= ~(!bitval << offset); /* unset bit if bitval == 0 */
That's the same as ~(1 << offset) when bitval is zero, but turns into a
no op when it's one. That's what I want here, successfully removing the
need for the if-else case.
> >@@ -176,117 +184,60 @@ static int rb532_gpio_direction_input(struct
> >gpio_chip *chip, unsigned offset)
> > static int rb532_gpio_direction_output(struct gpio_chip *chip,
> > unsigned offset, int value)
> > {
> >- unsigned long flags;
> >- u32 mask = 1 << offset;
> >- u32 tmp;
> > struct rb532_gpio_chip *gpch;
> >- void __iomem *gpdr;
> >
> > gpch = container_of(chip, struct rb532_gpio_chip, chip);
> >- writel(mask, gpch->regbase + GPIOD);
> >
>
> Hm, the old code seems really borked here...
It's not as bad as this may look like. In fact I could just simplify
lots of the functions by having them call rb532_set_bit().
A patch fixing the above mentioned issue follows, thanks for your help!
Greetings, Phil
next prev parent reply other threads:[~2008-11-03 14:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-29 20:00 [PATCH] provide functions for gpio configuration Phil Sutter
2008-10-29 20:07 ` Florian Fainelli
2008-10-29 21:10 ` Phil Sutter
2008-10-30 17:13 ` Florian Fainelli
2008-10-30 17:47 ` Phil Sutter
2008-10-30 18:16 ` Florian Fainelli
2008-10-30 20:20 ` Phil Sutter
2008-10-30 20:26 ` Florian Fainelli
2008-10-31 0:25 ` [PATCH] add prototypes for the exported symbols Phil Sutter
2008-10-31 14:58 ` [PATCH] provide functions for gpio configuration Phil Sutter
2008-11-02 21:56 ` Sergei Shtylyov
2008-11-03 14:29 ` Phil Sutter [this message]
2008-11-03 14:30 ` [PATCH] MIPS: rb532: fix bit swapping in rb532_set_bit() Phil Sutter
2008-11-03 14:48 ` Atsushi Nemoto
2008-11-03 15:05 ` Phil Sutter
2008-11-11 23:09 ` Phil Sutter
2009-01-29 16:27 ` Ralf Baechle
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=20081103142942.GA13461@nuty \
--to=n0-1@freewrt.org \
--cc=linux-mips@linux-mips.org \
--cc=ralf@linux-mips.org \
--cc=sshtylyov@ru.mvista.com \
/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