|
@@ -22,14 +22,13 @@
|
|
|
#include <linux/spinlock.h>
|
|
|
#include <linux/interrupt.h>
|
|
|
#include <linux/irq.h>
|
|
|
+#include <linux/irqdomain.h>
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
#include <asm/mach/irq.h>
|
|
|
|
|
|
#include <plat/pincfg.h>
|
|
|
#include <plat/gpio-nomadik.h>
|
|
|
-#include <mach/hardware.h>
|
|
|
-#include <asm/gpio.h>
|
|
|
|
|
|
/*
|
|
|
* The GPIO module in the Nomadik family of Systems-on-Chip is an
|
|
@@ -43,6 +42,7 @@
|
|
|
|
|
|
struct nmk_gpio_chip {
|
|
|
struct gpio_chip chip;
|
|
|
+ struct irq_domain *domain;
|
|
|
void __iomem *addr;
|
|
|
struct clk *clk;
|
|
|
unsigned int bank;
|
|
@@ -58,8 +58,10 @@ struct nmk_gpio_chip {
|
|
|
u32 real_wake;
|
|
|
u32 rwimsc;
|
|
|
u32 fwimsc;
|
|
|
- u32 slpm;
|
|
|
+ u32 rimsc;
|
|
|
+ u32 fimsc;
|
|
|
u32 pull_up;
|
|
|
+ u32 lowemi;
|
|
|
};
|
|
|
|
|
|
static struct nmk_gpio_chip *
|
|
@@ -124,6 +126,24 @@ static void __nmk_gpio_set_pull(struct nmk_gpio_chip *nmk_chip,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static void __nmk_gpio_set_lowemi(struct nmk_gpio_chip *nmk_chip,
|
|
|
+ unsigned offset, bool lowemi)
|
|
|
+{
|
|
|
+ u32 bit = BIT(offset);
|
|
|
+ bool enabled = nmk_chip->lowemi & bit;
|
|
|
+
|
|
|
+ if (lowemi == enabled)
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (lowemi)
|
|
|
+ nmk_chip->lowemi |= bit;
|
|
|
+ else
|
|
|
+ nmk_chip->lowemi &= ~bit;
|
|
|
+
|
|
|
+ writel_relaxed(nmk_chip->lowemi,
|
|
|
+ nmk_chip->addr + NMK_GPIO_LOWEMI);
|
|
|
+}
|
|
|
+
|
|
|
static void __nmk_gpio_make_input(struct nmk_gpio_chip *nmk_chip,
|
|
|
unsigned offset)
|
|
|
{
|
|
@@ -150,8 +170,8 @@ static void __nmk_gpio_set_mode_safe(struct nmk_gpio_chip *nmk_chip,
|
|
|
unsigned offset, int gpio_mode,
|
|
|
bool glitch)
|
|
|
{
|
|
|
- u32 rwimsc = readl(nmk_chip->addr + NMK_GPIO_RWIMSC);
|
|
|
- u32 fwimsc = readl(nmk_chip->addr + NMK_GPIO_FWIMSC);
|
|
|
+ u32 rwimsc = nmk_chip->rwimsc;
|
|
|
+ u32 fwimsc = nmk_chip->fwimsc;
|
|
|
|
|
|
if (glitch && nmk_chip->set_ioforce) {
|
|
|
u32 bit = BIT(offset);
|
|
@@ -173,6 +193,36 @@ static void __nmk_gpio_set_mode_safe(struct nmk_gpio_chip *nmk_chip,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static void
|
|
|
+nmk_gpio_disable_lazy_irq(struct nmk_gpio_chip *nmk_chip, unsigned offset)
|
|
|
+{
|
|
|
+ u32 falling = nmk_chip->fimsc & BIT(offset);
|
|
|
+ u32 rising = nmk_chip->rimsc & BIT(offset);
|
|
|
+ int gpio = nmk_chip->chip.base + offset;
|
|
|
+ int irq = NOMADIK_GPIO_TO_IRQ(gpio);
|
|
|
+ struct irq_data *d = irq_get_irq_data(irq);
|
|
|
+
|
|
|
+ if (!rising && !falling)
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (!d || !irqd_irq_disabled(d))
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (rising) {
|
|
|
+ nmk_chip->rimsc &= ~BIT(offset);
|
|
|
+ writel_relaxed(nmk_chip->rimsc,
|
|
|
+ nmk_chip->addr + NMK_GPIO_RIMSC);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (falling) {
|
|
|
+ nmk_chip->fimsc &= ~BIT(offset);
|
|
|
+ writel_relaxed(nmk_chip->fimsc,
|
|
|
+ nmk_chip->addr + NMK_GPIO_FIMSC);
|
|
|
+ }
|
|
|
+
|
|
|
+ dev_dbg(nmk_chip->chip.dev, "%d: clearing interrupt mask\n", gpio);
|
|
|
+}
|
|
|
+
|
|
|
static void __nmk_config_pin(struct nmk_gpio_chip *nmk_chip, unsigned offset,
|
|
|
pin_cfg_t cfg, bool sleep, unsigned int *slpmregs)
|
|
|
{
|
|
@@ -238,6 +288,17 @@ static void __nmk_config_pin(struct nmk_gpio_chip *nmk_chip, unsigned offset,
|
|
|
__nmk_gpio_set_pull(nmk_chip, offset, pull);
|
|
|
}
|
|
|
|
|
|
+ __nmk_gpio_set_lowemi(nmk_chip, offset, PIN_LOWEMI(cfg));
|
|
|
+
|
|
|
+ /*
|
|
|
+ * If the pin is switching to altfunc, and there was an interrupt
|
|
|
+ * installed on it which has been lazy disabled, actually mask the
|
|
|
+ * interrupt to prevent spurious interrupts that would occur while the
|
|
|
+ * pin is under control of the peripheral. Only SKE does this.
|
|
|
+ */
|
|
|
+ if (af != NMK_GPIO_ALT_GPIO)
|
|
|
+ nmk_gpio_disable_lazy_irq(nmk_chip, offset);
|
|
|
+
|
|
|
/*
|
|
|
* If we've backed up the SLPM registers (glitch workaround), modify
|
|
|
* the backups since they will be restored.
|
|
@@ -334,7 +395,7 @@ static int __nmk_config_pins(pin_cfg_t *cfgs, int num, bool sleep)
|
|
|
struct nmk_gpio_chip *nmk_chip;
|
|
|
int pin = PIN_NUM(cfgs[i]);
|
|
|
|
|
|
- nmk_chip = irq_get_chip_data(NOMADIK_GPIO_TO_IRQ(pin));
|
|
|
+ nmk_chip = nmk_gpio_chips[pin / NMK_GPIO_PER_CHIP];
|
|
|
if (!nmk_chip) {
|
|
|
ret = -EINVAL;
|
|
|
break;
|
|
@@ -342,7 +403,7 @@ static int __nmk_config_pins(pin_cfg_t *cfgs, int num, bool sleep)
|
|
|
|
|
|
clk_enable(nmk_chip->clk);
|
|
|
spin_lock(&nmk_chip->lock);
|
|
|
- __nmk_config_pin(nmk_chip, pin - nmk_chip->chip.base,
|
|
|
+ __nmk_config_pin(nmk_chip, pin % NMK_GPIO_PER_CHIP,
|
|
|
cfgs[i], sleep, glitch ? slpm : NULL);
|
|
|
spin_unlock(&nmk_chip->lock);
|
|
|
clk_disable(nmk_chip->clk);
|
|
@@ -426,7 +487,7 @@ int nmk_gpio_set_slpm(int gpio, enum nmk_gpio_slpm mode)
|
|
|
struct nmk_gpio_chip *nmk_chip;
|
|
|
unsigned long flags;
|
|
|
|
|
|
- nmk_chip = irq_get_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
|
|
|
+ nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP];
|
|
|
if (!nmk_chip)
|
|
|
return -EINVAL;
|
|
|
|
|
@@ -434,7 +495,7 @@ int nmk_gpio_set_slpm(int gpio, enum nmk_gpio_slpm mode)
|
|
|
spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
|
|
|
spin_lock(&nmk_chip->lock);
|
|
|
|
|
|
- __nmk_gpio_set_slpm(nmk_chip, gpio - nmk_chip->chip.base, mode);
|
|
|
+ __nmk_gpio_set_slpm(nmk_chip, gpio % NMK_GPIO_PER_CHIP, mode);
|
|
|
|
|
|
spin_unlock(&nmk_chip->lock);
|
|
|
spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
|
|
@@ -461,13 +522,13 @@ int nmk_gpio_set_pull(int gpio, enum nmk_gpio_pull pull)
|
|
|
struct nmk_gpio_chip *nmk_chip;
|
|
|
unsigned long flags;
|
|
|
|
|
|
- nmk_chip = irq_get_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
|
|
|
+ nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP];
|
|
|
if (!nmk_chip)
|
|
|
return -EINVAL;
|
|
|
|
|
|
clk_enable(nmk_chip->clk);
|
|
|
spin_lock_irqsave(&nmk_chip->lock, flags);
|
|
|
- __nmk_gpio_set_pull(nmk_chip, gpio - nmk_chip->chip.base, pull);
|
|
|
+ __nmk_gpio_set_pull(nmk_chip, gpio % NMK_GPIO_PER_CHIP, pull);
|
|
|
spin_unlock_irqrestore(&nmk_chip->lock, flags);
|
|
|
clk_disable(nmk_chip->clk);
|
|
|
|
|
@@ -489,13 +550,13 @@ int nmk_gpio_set_mode(int gpio, int gpio_mode)
|
|
|
struct nmk_gpio_chip *nmk_chip;
|
|
|
unsigned long flags;
|
|
|
|
|
|
- nmk_chip = irq_get_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
|
|
|
+ nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP];
|
|
|
if (!nmk_chip)
|
|
|
return -EINVAL;
|
|
|
|
|
|
clk_enable(nmk_chip->clk);
|
|
|
spin_lock_irqsave(&nmk_chip->lock, flags);
|
|
|
- __nmk_gpio_set_mode(nmk_chip, gpio - nmk_chip->chip.base, gpio_mode);
|
|
|
+ __nmk_gpio_set_mode(nmk_chip, gpio % NMK_GPIO_PER_CHIP, gpio_mode);
|
|
|
spin_unlock_irqrestore(&nmk_chip->lock, flags);
|
|
|
clk_disable(nmk_chip->clk);
|
|
|
|
|
@@ -508,11 +569,11 @@ int nmk_gpio_get_mode(int gpio)
|
|
|
struct nmk_gpio_chip *nmk_chip;
|
|
|
u32 afunc, bfunc, bit;
|
|
|
|
|
|
- nmk_chip = irq_get_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
|
|
|
+ nmk_chip = nmk_gpio_chips[gpio / NMK_GPIO_PER_CHIP];
|
|
|
if (!nmk_chip)
|
|
|
return -EINVAL;
|
|
|
|
|
|
- bit = 1 << (gpio - nmk_chip->chip.base);
|
|
|
+ bit = 1 << (gpio % NMK_GPIO_PER_CHIP);
|
|
|
|
|
|
clk_enable(nmk_chip->clk);
|
|
|
|
|
@@ -529,21 +590,19 @@ EXPORT_SYMBOL(nmk_gpio_get_mode);
|
|
|
/* IRQ functions */
|
|
|
static inline int nmk_gpio_get_bitmask(int gpio)
|
|
|
{
|
|
|
- return 1 << (gpio % 32);
|
|
|
+ return 1 << (gpio % NMK_GPIO_PER_CHIP);
|
|
|
}
|
|
|
|
|
|
static void nmk_gpio_irq_ack(struct irq_data *d)
|
|
|
{
|
|
|
- int gpio;
|
|
|
struct nmk_gpio_chip *nmk_chip;
|
|
|
|
|
|
- gpio = NOMADIK_IRQ_TO_GPIO(d->irq);
|
|
|
nmk_chip = irq_data_get_irq_chip_data(d);
|
|
|
if (!nmk_chip)
|
|
|
return;
|
|
|
|
|
|
clk_enable(nmk_chip->clk);
|
|
|
- writel(nmk_gpio_get_bitmask(gpio), nmk_chip->addr + NMK_GPIO_IC);
|
|
|
+ writel(nmk_gpio_get_bitmask(d->hwirq), nmk_chip->addr + NMK_GPIO_IC);
|
|
|
clk_disable(nmk_chip->clk);
|
|
|
}
|
|
|
|
|
@@ -556,37 +615,52 @@ static void __nmk_gpio_irq_modify(struct nmk_gpio_chip *nmk_chip,
|
|
|
int gpio, enum nmk_gpio_irq_type which,
|
|
|
bool enable)
|
|
|
{
|
|
|
- u32 rimsc = which == WAKE ? NMK_GPIO_RWIMSC : NMK_GPIO_RIMSC;
|
|
|
- u32 fimsc = which == WAKE ? NMK_GPIO_FWIMSC : NMK_GPIO_FIMSC;
|
|
|
u32 bitmask = nmk_gpio_get_bitmask(gpio);
|
|
|
- u32 reg;
|
|
|
+ u32 *rimscval;
|
|
|
+ u32 *fimscval;
|
|
|
+ u32 rimscreg;
|
|
|
+ u32 fimscreg;
|
|
|
+
|
|
|
+ if (which == NORMAL) {
|
|
|
+ rimscreg = NMK_GPIO_RIMSC;
|
|
|
+ fimscreg = NMK_GPIO_FIMSC;
|
|
|
+ rimscval = &nmk_chip->rimsc;
|
|
|
+ fimscval = &nmk_chip->fimsc;
|
|
|
+ } else {
|
|
|
+ rimscreg = NMK_GPIO_RWIMSC;
|
|
|
+ fimscreg = NMK_GPIO_FWIMSC;
|
|
|
+ rimscval = &nmk_chip->rwimsc;
|
|
|
+ fimscval = &nmk_chip->fwimsc;
|
|
|
+ }
|
|
|
|
|
|
/* we must individually set/clear the two edges */
|
|
|
if (nmk_chip->edge_rising & bitmask) {
|
|
|
- reg = readl(nmk_chip->addr + rimsc);
|
|
|
if (enable)
|
|
|
- reg |= bitmask;
|
|
|
+ *rimscval |= bitmask;
|
|
|
else
|
|
|
- reg &= ~bitmask;
|
|
|
- writel(reg, nmk_chip->addr + rimsc);
|
|
|
+ *rimscval &= ~bitmask;
|
|
|
+ writel(*rimscval, nmk_chip->addr + rimscreg);
|
|
|
}
|
|
|
if (nmk_chip->edge_falling & bitmask) {
|
|
|
- reg = readl(nmk_chip->addr + fimsc);
|
|
|
if (enable)
|
|
|
- reg |= bitmask;
|
|
|
+ *fimscval |= bitmask;
|
|
|
else
|
|
|
- reg &= ~bitmask;
|
|
|
- writel(reg, nmk_chip->addr + fimsc);
|
|
|
+ *fimscval &= ~bitmask;
|
|
|
+ writel(*fimscval, nmk_chip->addr + fimscreg);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void __nmk_gpio_set_wake(struct nmk_gpio_chip *nmk_chip,
|
|
|
int gpio, bool on)
|
|
|
{
|
|
|
- if (nmk_chip->sleepmode) {
|
|
|
- __nmk_gpio_set_slpm(nmk_chip, gpio - nmk_chip->chip.base,
|
|
|
- on ? NMK_GPIO_SLPM_WAKEUP_ENABLE
|
|
|
- : NMK_GPIO_SLPM_WAKEUP_DISABLE);
|
|
|
+ /*
|
|
|
+ * Ensure WAKEUP_ENABLE is on. No need to disable it if wakeup is
|
|
|
+ * disabled, since setting SLPM to 1 increases power consumption, and
|
|
|
+ * wakeup is anyhow controlled by the RIMSC and FIMSC registers.
|
|
|
+ */
|
|
|
+ if (nmk_chip->sleepmode && on) {
|
|
|
+ __nmk_gpio_set_slpm(nmk_chip, gpio % nmk_chip->chip.base,
|
|
|
+ NMK_GPIO_SLPM_WAKEUP_ENABLE);
|
|
|
}
|
|
|
|
|
|
__nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, on);
|
|
@@ -594,14 +668,12 @@ static void __nmk_gpio_set_wake(struct nmk_gpio_chip *nmk_chip,
|
|
|
|
|
|
static int nmk_gpio_irq_maskunmask(struct irq_data *d, bool enable)
|
|
|
{
|
|
|
- int gpio;
|
|
|
struct nmk_gpio_chip *nmk_chip;
|
|
|
unsigned long flags;
|
|
|
u32 bitmask;
|
|
|
|
|
|
- gpio = NOMADIK_IRQ_TO_GPIO(d->irq);
|
|
|
nmk_chip = irq_data_get_irq_chip_data(d);
|
|
|
- bitmask = nmk_gpio_get_bitmask(gpio);
|
|
|
+ bitmask = nmk_gpio_get_bitmask(d->hwirq);
|
|
|
if (!nmk_chip)
|
|
|
return -EINVAL;
|
|
|
|
|
@@ -609,10 +681,10 @@ static int nmk_gpio_irq_maskunmask(struct irq_data *d, bool enable)
|
|
|
spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
|
|
|
spin_lock(&nmk_chip->lock);
|
|
|
|
|
|
- __nmk_gpio_irq_modify(nmk_chip, gpio, NORMAL, enable);
|
|
|
+ __nmk_gpio_irq_modify(nmk_chip, d->hwirq, NORMAL, enable);
|
|
|
|
|
|
if (!(nmk_chip->real_wake & bitmask))
|
|
|
- __nmk_gpio_set_wake(nmk_chip, gpio, enable);
|
|
|
+ __nmk_gpio_set_wake(nmk_chip, d->hwirq, enable);
|
|
|
|
|
|
spin_unlock(&nmk_chip->lock);
|
|
|
spin_unlock_irqrestore(&nmk_gpio_slpm_lock, flags);
|
|
@@ -636,20 +708,18 @@ static int nmk_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
|
|
|
struct nmk_gpio_chip *nmk_chip;
|
|
|
unsigned long flags;
|
|
|
u32 bitmask;
|
|
|
- int gpio;
|
|
|
|
|
|
- gpio = NOMADIK_IRQ_TO_GPIO(d->irq);
|
|
|
nmk_chip = irq_data_get_irq_chip_data(d);
|
|
|
if (!nmk_chip)
|
|
|
return -EINVAL;
|
|
|
- bitmask = nmk_gpio_get_bitmask(gpio);
|
|
|
+ bitmask = nmk_gpio_get_bitmask(d->hwirq);
|
|
|
|
|
|
clk_enable(nmk_chip->clk);
|
|
|
spin_lock_irqsave(&nmk_gpio_slpm_lock, flags);
|
|
|
spin_lock(&nmk_chip->lock);
|
|
|
|
|
|
if (irqd_irq_disabled(d))
|
|
|
- __nmk_gpio_set_wake(nmk_chip, gpio, on);
|
|
|
+ __nmk_gpio_set_wake(nmk_chip, d->hwirq, on);
|
|
|
|
|
|
if (on)
|
|
|
nmk_chip->real_wake |= bitmask;
|
|
@@ -667,17 +737,14 @@ static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type)
|
|
|
{
|
|
|
bool enabled = !irqd_irq_disabled(d);
|
|
|
bool wake = irqd_is_wakeup_set(d);
|
|
|
- int gpio;
|
|
|
struct nmk_gpio_chip *nmk_chip;
|
|
|
unsigned long flags;
|
|
|
u32 bitmask;
|
|
|
|
|
|
- gpio = NOMADIK_IRQ_TO_GPIO(d->irq);
|
|
|
nmk_chip = irq_data_get_irq_chip_data(d);
|
|
|
- bitmask = nmk_gpio_get_bitmask(gpio);
|
|
|
+ bitmask = nmk_gpio_get_bitmask(d->hwirq);
|
|
|
if (!nmk_chip)
|
|
|
return -EINVAL;
|
|
|
-
|
|
|
if (type & IRQ_TYPE_LEVEL_HIGH)
|
|
|
return -EINVAL;
|
|
|
if (type & IRQ_TYPE_LEVEL_LOW)
|
|
@@ -687,10 +754,10 @@ static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type)
|
|
|
spin_lock_irqsave(&nmk_chip->lock, flags);
|
|
|
|
|
|
if (enabled)
|
|
|
- __nmk_gpio_irq_modify(nmk_chip, gpio, NORMAL, false);
|
|
|
+ __nmk_gpio_irq_modify(nmk_chip, d->hwirq, NORMAL, false);
|
|
|
|
|
|
if (enabled || wake)
|
|
|
- __nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, false);
|
|
|
+ __nmk_gpio_irq_modify(nmk_chip, d->hwirq, WAKE, false);
|
|
|
|
|
|
nmk_chip->edge_rising &= ~bitmask;
|
|
|
if (type & IRQ_TYPE_EDGE_RISING)
|
|
@@ -701,10 +768,10 @@ static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type)
|
|
|
nmk_chip->edge_falling |= bitmask;
|
|
|
|
|
|
if (enabled)
|
|
|
- __nmk_gpio_irq_modify(nmk_chip, gpio, NORMAL, true);
|
|
|
+ __nmk_gpio_irq_modify(nmk_chip, d->hwirq, NORMAL, true);
|
|
|
|
|
|
if (enabled || wake)
|
|
|
- __nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, true);
|
|
|
+ __nmk_gpio_irq_modify(nmk_chip, d->hwirq, WAKE, true);
|
|
|
|
|
|
spin_unlock_irqrestore(&nmk_chip->lock, flags);
|
|
|
clk_disable(nmk_chip->clk);
|
|
@@ -750,7 +817,7 @@ static void __nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc,
|
|
|
chained_irq_enter(host_chip, desc);
|
|
|
|
|
|
nmk_chip = irq_get_handler_data(irq);
|
|
|
- first_irq = NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base);
|
|
|
+ first_irq = nmk_chip->domain->revmap_data.legacy.first_irq;
|
|
|
while (status) {
|
|
|
int bit = __ffs(status);
|
|
|
|
|
@@ -784,18 +851,6 @@ static void nmk_gpio_secondary_irq_handler(unsigned int irq,
|
|
|
|
|
|
static int nmk_gpio_init_irq(struct nmk_gpio_chip *nmk_chip)
|
|
|
{
|
|
|
- unsigned int first_irq;
|
|
|
- int i;
|
|
|
-
|
|
|
- first_irq = NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base);
|
|
|
- for (i = first_irq; i < first_irq + nmk_chip->chip.ngpio; i++) {
|
|
|
- irq_set_chip_and_handler(i, &nmk_gpio_irq_chip,
|
|
|
- handle_edge_irq);
|
|
|
- set_irq_flags(i, IRQF_VALID);
|
|
|
- irq_set_chip_data(i, nmk_chip);
|
|
|
- irq_set_irq_type(i, IRQ_TYPE_EDGE_FALLING);
|
|
|
- }
|
|
|
-
|
|
|
irq_set_chained_handler(nmk_chip->parent_irq, nmk_gpio_irq_handler);
|
|
|
irq_set_handler_data(nmk_chip->parent_irq, nmk_chip);
|
|
|
|
|
@@ -872,7 +927,7 @@ static int nmk_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
|
|
|
struct nmk_gpio_chip *nmk_chip =
|
|
|
container_of(chip, struct nmk_gpio_chip, chip);
|
|
|
|
|
|
- return NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base) + offset;
|
|
|
+ return irq_find_mapping(nmk_chip->domain, offset);
|
|
|
}
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
@@ -1008,21 +1063,11 @@ void nmk_gpio_wakeups_suspend(void)
|
|
|
|
|
|
clk_enable(chip->clk);
|
|
|
|
|
|
- chip->rwimsc = readl(chip->addr + NMK_GPIO_RWIMSC);
|
|
|
- chip->fwimsc = readl(chip->addr + NMK_GPIO_FWIMSC);
|
|
|
-
|
|
|
writel(chip->rwimsc & chip->real_wake,
|
|
|
chip->addr + NMK_GPIO_RWIMSC);
|
|
|
writel(chip->fwimsc & chip->real_wake,
|
|
|
chip->addr + NMK_GPIO_FWIMSC);
|
|
|
|
|
|
- if (chip->sleepmode) {
|
|
|
- chip->slpm = readl(chip->addr + NMK_GPIO_SLPC);
|
|
|
-
|
|
|
- /* 0 -> wakeup enable */
|
|
|
- writel(~chip->real_wake, chip->addr + NMK_GPIO_SLPC);
|
|
|
- }
|
|
|
-
|
|
|
clk_disable(chip->clk);
|
|
|
}
|
|
|
}
|
|
@@ -1042,9 +1087,6 @@ void nmk_gpio_wakeups_resume(void)
|
|
|
writel(chip->rwimsc, chip->addr + NMK_GPIO_RWIMSC);
|
|
|
writel(chip->fwimsc, chip->addr + NMK_GPIO_FWIMSC);
|
|
|
|
|
|
- if (chip->sleepmode)
|
|
|
- writel(chip->slpm, chip->addr + NMK_GPIO_SLPC);
|
|
|
-
|
|
|
clk_disable(chip->clk);
|
|
|
}
|
|
|
}
|
|
@@ -1068,19 +1110,62 @@ void nmk_gpio_read_pull(int gpio_bank, u32 *pull_up)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+int nmk_gpio_irq_map(struct irq_domain *d, unsigned int irq,
|
|
|
+ irq_hw_number_t hwirq)
|
|
|
+{
|
|
|
+ struct nmk_gpio_chip *nmk_chip = d->host_data;
|
|
|
+
|
|
|
+ if (!nmk_chip)
|
|
|
+ return -EINVAL;
|
|
|
+
|
|
|
+ irq_set_chip_and_handler(irq, &nmk_gpio_irq_chip, handle_edge_irq);
|
|
|
+ set_irq_flags(irq, IRQF_VALID);
|
|
|
+ irq_set_chip_data(irq, nmk_chip);
|
|
|
+ irq_set_irq_type(irq, IRQ_TYPE_EDGE_FALLING);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+const struct irq_domain_ops nmk_gpio_irq_simple_ops = {
|
|
|
+ .map = nmk_gpio_irq_map,
|
|
|
+ .xlate = irq_domain_xlate_twocell,
|
|
|
+};
|
|
|
+
|
|
|
static int __devinit nmk_gpio_probe(struct platform_device *dev)
|
|
|
{
|
|
|
struct nmk_gpio_platform_data *pdata = dev->dev.platform_data;
|
|
|
+ struct device_node *np = dev->dev.of_node;
|
|
|
struct nmk_gpio_chip *nmk_chip;
|
|
|
struct gpio_chip *chip;
|
|
|
struct resource *res;
|
|
|
struct clk *clk;
|
|
|
int secondary_irq;
|
|
|
+ void __iomem *base;
|
|
|
int irq;
|
|
|
int ret;
|
|
|
|
|
|
- if (!pdata)
|
|
|
+ if (!pdata && !np) {
|
|
|
+ dev_err(&dev->dev, "No platform data or device tree found\n");
|
|
|
return -ENODEV;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (np) {
|
|
|
+ pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
|
|
|
+ if (!pdata)
|
|
|
+ return -ENOMEM;
|
|
|
+
|
|
|
+ if (of_get_property(np, "supports-sleepmode", NULL))
|
|
|
+ pdata->supports_sleepmode = true;
|
|
|
+
|
|
|
+ if (of_property_read_u32(np, "gpio-bank", &dev->id)) {
|
|
|
+ dev_err(&dev->dev, "gpio-bank property not found\n");
|
|
|
+ ret = -EINVAL;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ pdata->first_gpio = dev->id * NMK_GPIO_PER_CHIP;
|
|
|
+ pdata->num_gpio = NMK_GPIO_PER_CHIP;
|
|
|
+ }
|
|
|
|
|
|
res = platform_get_resource(dev, IORESOURCE_MEM, 0);
|
|
|
if (!res) {
|
|
@@ -1106,10 +1191,16 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev)
|
|
|
goto out;
|
|
|
}
|
|
|
|
|
|
+ base = ioremap(res->start, resource_size(res));
|
|
|
+ if (!base) {
|
|
|
+ ret = -ENOMEM;
|
|
|
+ goto out_release;
|
|
|
+ }
|
|
|
+
|
|
|
clk = clk_get(&dev->dev, NULL);
|
|
|
if (IS_ERR(clk)) {
|
|
|
ret = PTR_ERR(clk);
|
|
|
- goto out_release;
|
|
|
+ goto out_unmap;
|
|
|
}
|
|
|
|
|
|
nmk_chip = kzalloc(sizeof(*nmk_chip), GFP_KERNEL);
|
|
@@ -1117,13 +1208,14 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev)
|
|
|
ret = -ENOMEM;
|
|
|
goto out_clk;
|
|
|
}
|
|
|
+
|
|
|
/*
|
|
|
* The virt address in nmk_chip->addr is in the nomadik register space,
|
|
|
* so we can simply convert the resource address, without remapping
|
|
|
*/
|
|
|
nmk_chip->bank = dev->id;
|
|
|
nmk_chip->clk = clk;
|
|
|
- nmk_chip->addr = io_p2v(res->start);
|
|
|
+ nmk_chip->addr = base;
|
|
|
nmk_chip->chip = nmk_gpio_template;
|
|
|
nmk_chip->parent_irq = irq;
|
|
|
nmk_chip->secondary_parent_irq = secondary_irq;
|
|
@@ -1139,6 +1231,12 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev)
|
|
|
chip->dev = &dev->dev;
|
|
|
chip->owner = THIS_MODULE;
|
|
|
|
|
|
+ clk_enable(nmk_chip->clk);
|
|
|
+ nmk_chip->lowemi = readl_relaxed(nmk_chip->addr + NMK_GPIO_LOWEMI);
|
|
|
+ clk_disable(nmk_chip->clk);
|
|
|
+
|
|
|
+ chip->of_node = np;
|
|
|
+
|
|
|
ret = gpiochip_add(&nmk_chip->chip);
|
|
|
if (ret)
|
|
|
goto out_free;
|
|
@@ -1146,12 +1244,22 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev)
|
|
|
BUG_ON(nmk_chip->bank >= ARRAY_SIZE(nmk_gpio_chips));
|
|
|
|
|
|
nmk_gpio_chips[nmk_chip->bank] = nmk_chip;
|
|
|
+
|
|
|
platform_set_drvdata(dev, nmk_chip);
|
|
|
|
|
|
+ nmk_chip->domain = irq_domain_add_legacy(np, NMK_GPIO_PER_CHIP,
|
|
|
+ NOMADIK_GPIO_TO_IRQ(pdata->first_gpio),
|
|
|
+ 0, &nmk_gpio_irq_simple_ops, nmk_chip);
|
|
|
+ if (!nmk_chip->domain) {
|
|
|
+ pr_err("%s: Failed to create irqdomain\n", np->full_name);
|
|
|
+ ret = -ENOSYS;
|
|
|
+ goto out_free;
|
|
|
+ }
|
|
|
+
|
|
|
nmk_gpio_init_irq(nmk_chip);
|
|
|
|
|
|
- dev_info(&dev->dev, "at address %p\n",
|
|
|
- nmk_chip->addr);
|
|
|
+ dev_info(&dev->dev, "at address %p\n", nmk_chip->addr);
|
|
|
+
|
|
|
return 0;
|
|
|
|
|
|
out_free:
|
|
@@ -1159,18 +1267,29 @@ out_free:
|
|
|
out_clk:
|
|
|
clk_disable(clk);
|
|
|
clk_put(clk);
|
|
|
+out_unmap:
|
|
|
+ iounmap(base);
|
|
|
out_release:
|
|
|
release_mem_region(res->start, resource_size(res));
|
|
|
out:
|
|
|
dev_err(&dev->dev, "Failure %i for GPIO %i-%i\n", ret,
|
|
|
pdata->first_gpio, pdata->first_gpio+31);
|
|
|
+ if (np)
|
|
|
+ kfree(pdata);
|
|
|
+
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
+static const struct of_device_id nmk_gpio_match[] = {
|
|
|
+ { .compatible = "st,nomadik-gpio", },
|
|
|
+ {}
|
|
|
+};
|
|
|
+
|
|
|
static struct platform_driver nmk_gpio_driver = {
|
|
|
.driver = {
|
|
|
.owner = THIS_MODULE,
|
|
|
.name = "gpio",
|
|
|
+ .of_match_table = nmk_gpio_match,
|
|
|
},
|
|
|
.probe = nmk_gpio_probe,
|
|
|
};
|