Skip to content

Commit

Permalink
gpio: twl6040: Use bitops
Browse files Browse the repository at this point in the history
It's nice to use BIT() macros rather than open coding the same.
It's good practice as sometimes people use BIT(31) and forget
that the constant must be cast unsigned long.

Acked-by: Tony Lindgren <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
  • Loading branch information
linusw committed Sep 10, 2018
1 parent b4f53ed commit 4bef8bf
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/gpio/gpio-twl6040.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/irq.h>
#include <linux/gpio/driver.h>
#include <linux/platform_device.h>
#include <linux/bitops.h>
#include <linux/of.h>

#include <linux/mfd/twl6040.h>
Expand All @@ -28,7 +29,7 @@ static int twl6040gpo_get(struct gpio_chip *chip, unsigned offset)
if (ret < 0)
return ret;

return (ret >> offset) & 1;
return !!(ret & BIT(offset));
}

static int twl6040gpo_direction_out(struct gpio_chip *chip, unsigned offset,
Expand All @@ -49,9 +50,9 @@ static void twl6040gpo_set(struct gpio_chip *chip, unsigned offset, int value)
return;

if (value)
gpoctl = ret | (1 << offset);
gpoctl = ret | BIT(offset);
else
gpoctl = ret & ~(1 << offset);
gpoctl = ret & ~BIT(offset);

twl6040_reg_write(twl6040, TWL6040_REG_GPOCTL, gpoctl);
}
Expand Down

0 comments on commit 4bef8bf

Please sign in to comment.