Commit 438a2c9a authored by Linus Walleij's avatar Linus Walleij

gpio: pl061: refactor type setting

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: default avatarBaruch Siach <baruch@tkos.co.il>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent f6f29311
...@@ -150,6 +150,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger) ...@@ -150,6 +150,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)
int offset = irqd_to_hwirq(d); int offset = irqd_to_hwirq(d);
unsigned long flags; unsigned long flags;
u8 gpiois, gpioibe, gpioiev; u8 gpiois, gpioibe, gpioiev;
u8 bit = BIT(offset);
if (offset < 0 || offset >= PL061_GPIO_NR) if (offset < 0 || offset >= PL061_GPIO_NR)
return -EINVAL; return -EINVAL;
...@@ -157,30 +158,31 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger) ...@@ -157,30 +158,31 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)
spin_lock_irqsave(&chip->lock, flags); spin_lock_irqsave(&chip->lock, flags);
gpioiev = readb(chip->base + GPIOIEV); gpioiev = readb(chip->base + GPIOIEV);
gpiois = readb(chip->base + GPIOIS); gpiois = readb(chip->base + GPIOIS);
gpioibe = readb(chip->base + GPIOIBE);
if (trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { if (trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
gpiois |= 1 << offset; gpiois |= bit;
if (trigger & IRQ_TYPE_LEVEL_HIGH) if (trigger & IRQ_TYPE_LEVEL_HIGH)
gpioiev |= 1 << offset; gpioiev |= bit;
else else
gpioiev &= ~(1 << offset); gpioiev &= ~bit;
} else } else
gpiois &= ~(1 << offset); gpiois &= ~bit;
writeb(gpiois, chip->base + GPIOIS);
gpioibe = readb(chip->base + GPIOIBE);
if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) if ((trigger & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
gpioibe |= 1 << offset; /* Setting this makes GPIOEV be ignored */
gpioibe |= bit;
else { else {
gpioibe &= ~(1 << offset); gpioibe &= ~bit;
if (trigger & IRQ_TYPE_EDGE_RISING) if (trigger & IRQ_TYPE_EDGE_RISING)
gpioiev |= 1 << offset; gpioiev |= bit;
else if (trigger & IRQ_TYPE_EDGE_FALLING) 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); writeb(gpioiev, chip->base + GPIOIEV);
spin_unlock_irqrestore(&chip->lock, flags); spin_unlock_irqrestore(&chip->lock, flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment