Skip to content

Commit

Permalink
MIPS: RB532: Fix bit swapping in rb532_set_bit()
Browse files Browse the repository at this point in the history
The algorithm works unconditionally. If bitval is one, the first line is
a no op and the second line sets the bit at offset position. Vice versa,
if bitval is zero, the first line clears the bit at offset position and
the second line is a no op.

Signed-off-by: Phil Sutter <n0-1@freewrt.org>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
  • Loading branch information
Phil Sutter authored and Ralf Baechle committed Jan 30, 2009
1 parent f839490 commit 5379a5f
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions arch/mips/rb532/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,11 @@ static inline void rb532_set_bit(unsigned bitval,
unsigned long flags;
u32 val;

bitval = !!bitval; /* map parameter to {0,1} */

local_irq_save(flags);

val = readl(ioaddr);
val &= ~( ~bitval << offset ); /* unset bit if bitval == 0 */
val |= ( bitval << offset ); /* set bit if bitval == 1 */
val &= ~(!bitval << offset); /* unset bit if bitval == 0 */
val |= (!!bitval << offset); /* set bit if bitval == 1 */
writel(val, ioaddr);

local_irq_restore(flags);
Expand Down

0 comments on commit 5379a5f

Please sign in to comment.