Skip to content

Commit

Permalink
gpio: pl061: refactor type setting
Browse files Browse the repository at this point in the history
Refactor this function so that I can understand it, do one
big read/modify/write operation and have the bitmask in a
variable instead of recalculating it every time it's needed.

Cc: Haojian Zhuang <haojian.zhuang@linaro.org>
Cc: Deepak Sikri <deepak.sikri@st.com>
Acked-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Linus Walleij committed Feb 3, 2014
1 parent f6f2931 commit 438a2c9
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions drivers/gpio/gpio-pl061.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,37 +150,39 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)
int offset = irqd_to_hwirq(d);
unsigned long flags;
u8 gpiois, gpioibe, gpioiev;
u8 bit = BIT(offset);

if (offset < 0 || offset >= PL061_GPIO_NR)
return -EINVAL;

spin_lock_irqsave(&chip->lock, flags);

gpioiev = readb(chip->base + GPIOIEV);

gpiois = readb(chip->base + GPIOIS);
gpioibe = readb(chip->base + GPIOIBE);

if (trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
gpiois |= 1 << offset;
gpiois |= bit;
if (trigger & IRQ_TYPE_LEVEL_HIGH)
gpioiev |= 1 << offset;
gpioiev |= bit;
else
gpioiev &= ~(1 << offset);
gpioiev &= ~bit;
} else
gpiois &= ~(1 << offset);
writeb(gpiois, chip->base + GPIOIS);
gpiois &= ~bit;

gpioibe = readb(chip->base + GPIOIBE);
if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
gpioibe |= 1 << offset;
/* Setting this makes GPIOEV be ignored */
gpioibe |= bit;
else {
gpioibe &= ~(1 << offset);
gpioibe &= ~bit;
if (trigger & IRQ_TYPE_EDGE_RISING)
gpioiev |= 1 << offset;
gpioiev |= bit;
else if (trigger & IRQ_TYPE_EDGE_FALLING)
gpioiev &= ~(1 << offset);
gpioiev &= ~bit;
}
writeb(gpioibe, chip->base + GPIOIBE);

writeb(gpiois, chip->base + GPIOIS);
writeb(gpioibe, chip->base + GPIOIBE);
writeb(gpioiev, chip->base + GPIOIEV);

spin_unlock_irqrestore(&chip->lock, flags);
Expand Down

0 comments on commit 438a2c9

Please sign in to comment.