Merge branch 'gpio/next' of git://git.secretlab.ca/git/linux-2.6
[pandora-kernel.git] / drivers / gpio / gpio-omap.c
index e5667ba..0599854 100644 (file)
@@ -90,40 +90,6 @@ int gpio_bank_count;
 #define GPIO_INDEX(bank, gpio) (gpio % bank->width)
 #define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio))
 
-static inline int gpio_valid(int gpio)
-{
-       if (gpio < 0)
-               return -1;
-       if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio)) {
-               if (gpio >= OMAP_MAX_GPIO_LINES + 16)
-                       return -1;
-               return 0;
-       }
-       if (cpu_is_omap15xx() && gpio < 16)
-               return 0;
-       if ((cpu_is_omap16xx()) && gpio < 64)
-               return 0;
-       if (cpu_is_omap7xx() && gpio < 192)
-               return 0;
-       if (cpu_is_omap2420() && gpio < 128)
-               return 0;
-       if (cpu_is_omap2430() && gpio < 160)
-               return 0;
-       if ((cpu_is_omap34xx() || cpu_is_omap44xx()) && gpio < 192)
-               return 0;
-       return -1;
-}
-
-static int check_gpio(int gpio)
-{
-       if (unlikely(gpio_valid(gpio) < 0)) {
-               printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio);
-               dump_stack();
-               return -1;
-       }
-       return 0;
-}
-
 static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
 {
        void __iomem *reg = bank->base;
@@ -172,9 +138,6 @@ static int _get_gpio_datain(struct gpio_bank *bank, int gpio)
 {
        void __iomem *reg = bank->base + bank->regs->datain;
 
-       if (check_gpio(gpio) < 0)
-               return -EINVAL;
-
        return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0;
 }
 
@@ -182,9 +145,6 @@ static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
 {
        void __iomem *reg = bank->base + bank->regs->dataout;
 
-       if (check_gpio(gpio) < 0)
-               return -EINVAL;
-
        return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0;
 }
 
@@ -208,7 +168,7 @@ do {        \
 static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
                unsigned debounce)
 {
-       void __iomem            *reg = bank->base;
+       void __iomem            *reg;
        u32                     val;
        u32                     l;
 
@@ -224,19 +184,10 @@ static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
 
        l = GPIO_BIT(bank, gpio);
 
-       if (bank->method == METHOD_GPIO_44XX)
-               reg += OMAP4_GPIO_DEBOUNCINGTIME;
-       else
-               reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
-
+       reg = bank->base + bank->regs->debounce;
        __raw_writel(debounce, reg);
 
-       reg = bank->base;
-       if (bank->method == METHOD_GPIO_44XX)
-               reg += OMAP4_GPIO_DEBOUNCENABLE;
-       else
-               reg += OMAP24XX_GPIO_DEBOUNCE_EN;
-
+       reg = bank->base + bank->regs->debounce_en;
        val = __raw_readl(reg);
 
        if (debounce) {
@@ -294,8 +245,9 @@ static inline void set_24xx_gpio_triggering(struct gpio_bank *bank, int gpio,
                                        + OMAP24XX_GPIO_CLEARWKUENA);
                }
        }
-       /* This part needs to be executed always for OMAP34xx */
-       if (cpu_is_omap34xx() || (bank->non_wakeup_gpios & gpio_bit)) {
+       /* This part needs to be executed always for OMAP{34xx, 44xx} */
+       if (cpu_is_omap34xx() || cpu_is_omap44xx() ||
+                       (bank->non_wakeup_gpios & gpio_bit)) {
                /*
                 * Log the edge gpio and manually trigger the IRQ
                 * after resume if the input level changes
@@ -453,9 +405,6 @@ static int gpio_irq_type(struct irq_data *d, unsigned type)
        else
                gpio = d->irq - IH_GPIO_BASE;
 
-       if (check_gpio(gpio) < 0)
-               return -EINVAL;
-
        if (type & ~IRQ_TYPE_SENSE_MASK)
                return -EINVAL;
 
@@ -568,42 +517,24 @@ static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int ena
  */
 static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
 {
-       unsigned long uninitialized_var(flags);
+       u32 gpio_bit = GPIO_BIT(bank, gpio);
+       unsigned long flags;
 
-       switch (bank->method) {
-#ifdef CONFIG_ARCH_OMAP16XX
-       case METHOD_MPUIO:
-       case METHOD_GPIO_1610:
-               spin_lock_irqsave(&bank->lock, flags);
-               if (enable)
-                       bank->suspend_wakeup |= (1 << gpio);
-               else
-                       bank->suspend_wakeup &= ~(1 << gpio);
-               spin_unlock_irqrestore(&bank->lock, flags);
-               return 0;
-#endif
-#ifdef CONFIG_ARCH_OMAP2PLUS
-       case METHOD_GPIO_24XX:
-       case METHOD_GPIO_44XX:
-               if (bank->non_wakeup_gpios & (1 << gpio)) {
-                       printk(KERN_ERR "Unable to modify wakeup on "
-                                       "non-wakeup GPIO%d\n",
-                              (bank - gpio_bank) * bank->width + gpio);
-                       return -EINVAL;
-               }
-               spin_lock_irqsave(&bank->lock, flags);
-               if (enable)
-                       bank->suspend_wakeup |= (1 << gpio);
-               else
-                       bank->suspend_wakeup &= ~(1 << gpio);
-               spin_unlock_irqrestore(&bank->lock, flags);
-               return 0;
-#endif
-       default:
-               printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
-                      bank->method);
+       if (bank->non_wakeup_gpios & gpio_bit) {
+               dev_err(bank->dev, 
+                       "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio);
                return -EINVAL;
        }
+
+       spin_lock_irqsave(&bank->lock, flags);
+       if (enable)
+               bank->suspend_wakeup |= gpio_bit;
+       else
+               bank->suspend_wakeup &= ~gpio_bit;
+
+       spin_unlock_irqrestore(&bank->lock, flags);
+
+       return 0;
 }
 
 static void _reset_gpio(struct gpio_bank *bank, int gpio)
@@ -621,10 +552,8 @@ static int gpio_wake_enable(struct irq_data *d, unsigned int enable)
        struct gpio_bank *bank;
        int retval;
 
-       if (check_gpio(gpio) < 0)
-               return -ENODEV;
        bank = irq_data_get_irq_chip_data(d);
-       retval = _set_gpio_wakeup(bank, GPIO_INDEX(bank, gpio), enable);
+       retval = _set_gpio_wakeup(bank, gpio, enable);
 
        return retval;
 }
@@ -1056,19 +985,17 @@ static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
 
 static void __init omap_gpio_show_rev(struct gpio_bank *bank)
 {
+       static bool called;
        u32 rev;
 
-       if (cpu_is_omap16xx() && !(bank->method != METHOD_MPUIO))
-               rev = __raw_readw(bank->base + OMAP1610_GPIO_REVISION);
-       else if (cpu_is_omap24xx() || cpu_is_omap34xx())
-               rev = __raw_readl(bank->base + OMAP24XX_GPIO_REVISION);
-       else if (cpu_is_omap44xx())
-               rev = __raw_readl(bank->base + OMAP4_GPIO_REVISION);
-       else
+       if (called || bank->regs->revision == USHRT_MAX)
                return;
 
-       printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n",
+       rev = __raw_readw(bank->base + bank->regs->revision);
+       pr_info("OMAP GPIO hardware version %d.%d\n",
                (rev >> 4) & 0x0f, rev & 0x0f);
+
+       called = true;
 }
 
 /* This lock class tells lockdep that GPIO irqs are in a different