ar71xx: build ALFA AP96 images with default profile as well
[openwrt/openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / gpio.c
index 137a0181564d8aa915888a5c85d79ee65b0a7eb5..91c838345d2ae05a7965d05b121795d3fa364a52 100644 (file)
@@ -30,15 +30,15 @@ void __ar71xx_gpio_set_value(unsigned gpio, int value)
        void __iomem *base = ar71xx_gpio_base;
 
        if (value)
-               __raw_writel(1 << gpio, base + GPIO_REG_SET);
+               __raw_writel(1 << gpio, base + AR71XX_GPIO_REG_SET);
        else
-               __raw_writel(1 << gpio, base + GPIO_REG_CLEAR);
+               __raw_writel(1 << gpio, base + AR71XX_GPIO_REG_CLEAR);
 }
 EXPORT_SYMBOL(__ar71xx_gpio_set_value);
 
 int __ar71xx_gpio_get_value(unsigned gpio)
 {
-       return (__raw_readl(ar71xx_gpio_base + GPIO_REG_IN) >> gpio) & 1;
+       return (__raw_readl(ar71xx_gpio_base + AR71XX_GPIO_REG_IN) >> gpio) & 1;
 }
 EXPORT_SYMBOL(__ar71xx_gpio_get_value);
 
@@ -61,8 +61,8 @@ static int ar71xx_gpio_direction_input(struct gpio_chip *chip,
 
        spin_lock_irqsave(&ar71xx_gpio_lock, flags);
 
-       __raw_writel(__raw_readl(base + GPIO_REG_OE) & ~(1 << offset),
-                    base + GPIO_REG_OE);
+       __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) & ~(1 << offset),
+                    base + AR71XX_GPIO_REG_OE);
 
        spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
 
@@ -78,12 +78,12 @@ static int ar71xx_gpio_direction_output(struct gpio_chip *chip,
        spin_lock_irqsave(&ar71xx_gpio_lock, flags);
 
        if (value)
-               __raw_writel(1 << offset, base + GPIO_REG_SET);
+               __raw_writel(1 << offset, base + AR71XX_GPIO_REG_SET);
        else
-               __raw_writel(1 << offset, base + GPIO_REG_CLEAR);
+               __raw_writel(1 << offset, base + AR71XX_GPIO_REG_CLEAR);
 
-       __raw_writel(__raw_readl(base + GPIO_REG_OE) | (1 << offset),
-                    base + GPIO_REG_OE);
+       __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) | (1 << offset),
+                    base + AR71XX_GPIO_REG_OE);
 
        spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
 
@@ -98,8 +98,8 @@ static int ar934x_gpio_direction_input(struct gpio_chip *chip,
 
        spin_lock_irqsave(&ar71xx_gpio_lock, flags);
 
-       __raw_writel(__raw_readl(base + GPIO_REG_OE) | (1 << offset),
-                    base + GPIO_REG_OE);
+       __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) | (1 << offset),
+                    base + AR71XX_GPIO_REG_OE);
 
        spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
 
@@ -115,12 +115,12 @@ static int ar934x_gpio_direction_output(struct gpio_chip *chip,
        spin_lock_irqsave(&ar71xx_gpio_lock, flags);
 
        if (value)
-               __raw_writel(1 << offset, base + GPIO_REG_SET);
+               __raw_writel(1 << offset, base + AR71XX_GPIO_REG_SET);
        else
-               __raw_writel(1 << offset, base + GPIO_REG_CLEAR);
+               __raw_writel(1 << offset, base + AR71XX_GPIO_REG_CLEAR);
 
-       __raw_writel(__raw_readl(base + GPIO_REG_OE) & ~(1 << offset),
-                    base + GPIO_REG_OE);
+       __raw_writel(__raw_readl(base + AR71XX_GPIO_REG_OE) & ~(1 << offset),
+                    base + AR71XX_GPIO_REG_OE);
 
        spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
 
@@ -141,13 +141,21 @@ void ar71xx_gpio_function_enable(u32 mask)
 {
        void __iomem *base = ar71xx_gpio_base;
        unsigned long flags;
+       unsigned int reg;
+
+       if (ar71xx_soc == AR71XX_SOC_AR9341 ||
+           ar71xx_soc == AR71XX_SOC_AR9342 ||
+           ar71xx_soc == AR71XX_SOC_AR9344) {
+               reg = AR934X_GPIO_REG_FUNC;
+       } else {
+               reg = AR71XX_GPIO_REG_FUNC;
+       }
 
        spin_lock_irqsave(&ar71xx_gpio_lock, flags);
 
-       __raw_writel(__raw_readl(base + GPIO_REG_FUNC) | mask,
-                    base + GPIO_REG_FUNC);
+       __raw_writel(__raw_readl(base + reg) | mask, base + reg);
        /* flush write */
-       (void) __raw_readl(base + GPIO_REG_FUNC);
+       (void) __raw_readl(base + reg);
 
        spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
 }
@@ -156,13 +164,21 @@ void ar71xx_gpio_function_disable(u32 mask)
 {
        void __iomem *base = ar71xx_gpio_base;
        unsigned long flags;
+       unsigned int reg;
+
+       if (ar71xx_soc == AR71XX_SOC_AR9341 ||
+           ar71xx_soc == AR71XX_SOC_AR9342 ||
+           ar71xx_soc == AR71XX_SOC_AR9344) {
+               reg = AR934X_GPIO_REG_FUNC;
+       } else {
+               reg = AR71XX_GPIO_REG_FUNC;
+       }
 
        spin_lock_irqsave(&ar71xx_gpio_lock, flags);
 
-       __raw_writel(__raw_readl(base + GPIO_REG_FUNC) & ~mask,
-                    base + GPIO_REG_FUNC);
+       __raw_writel(__raw_readl(base + reg) & ~mask, base + reg);
        /* flush write */
-       (void) __raw_readl(base + GPIO_REG_FUNC);
+       (void) __raw_readl(base + reg);
 
        spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
 }
@@ -171,18 +187,57 @@ void ar71xx_gpio_function_setup(u32 set, u32 clear)
 {
        void __iomem *base = ar71xx_gpio_base;
        unsigned long flags;
+       unsigned int reg;
+
+       if (ar71xx_soc == AR71XX_SOC_AR9341 ||
+           ar71xx_soc == AR71XX_SOC_AR9342 ||
+           ar71xx_soc == AR71XX_SOC_AR9344) {
+               reg = AR934X_GPIO_REG_FUNC;
+       } else {
+               reg = AR71XX_GPIO_REG_FUNC;
+       }
 
        spin_lock_irqsave(&ar71xx_gpio_lock, flags);
 
-       __raw_writel((__raw_readl(base + GPIO_REG_FUNC) & ~clear) | set,
-                    base + GPIO_REG_FUNC);
+       __raw_writel((__raw_readl(base + reg) & ~clear) | set, base + reg);
        /* flush write */
-       (void) __raw_readl(base + GPIO_REG_FUNC);
+       (void) __raw_readl(base + reg);
 
        spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
 }
 EXPORT_SYMBOL(ar71xx_gpio_function_setup);
 
+void __init ar71xx_gpio_output_select(unsigned gpio, u8 val)
+{
+       void __iomem *base = ar71xx_gpio_base;
+       unsigned long flags;
+       unsigned int reg;
+       u32 t, s;
+
+       if (ar71xx_soc != AR71XX_SOC_AR9341 &&
+           ar71xx_soc != AR71XX_SOC_AR9342 &&
+           ar71xx_soc != AR71XX_SOC_AR9344)
+               return;
+
+       if (gpio >= AR934X_GPIO_COUNT)
+               return;
+
+       reg = AR934X_GPIO_REG_OUT_FUNC0 + 4 * (gpio / 4);
+       s = 8 * (gpio % 4);
+
+       spin_lock_irqsave(&ar71xx_gpio_lock, flags);
+
+       t = __raw_readl(base + reg);
+       t &= ~(0xff << s);
+       t |= val << s;
+       __raw_writel(t, base + reg);
+
+       /* flush write */
+       (void) __raw_readl(base + reg);
+
+       spin_unlock_irqrestore(&ar71xx_gpio_lock, flags);
+}
+
 void __init ar71xx_gpio_init(void)
 {
        int err;
@@ -199,9 +254,12 @@ void __init ar71xx_gpio_init(void)
                break;
 
        case AR71XX_SOC_AR7240:
+               ar71xx_gpio_chip.ngpio = AR7240_GPIO_COUNT;
+               break;
+
        case AR71XX_SOC_AR7241:
        case AR71XX_SOC_AR7242:
-               ar71xx_gpio_chip.ngpio = AR724X_GPIO_COUNT;
+               ar71xx_gpio_chip.ngpio = AR7241_GPIO_COUNT;
                break;
 
        case AR71XX_SOC_AR9130:
@@ -230,3 +288,15 @@ void __init ar71xx_gpio_init(void)
        if (err)
                panic("cannot add AR71xx GPIO chip, error=%d", err);
 }
+
+int gpio_to_irq(unsigned gpio)
+{
+       return AR71XX_GPIO_IRQ(gpio);
+}
+EXPORT_SYMBOL(gpio_to_irq);
+
+int irq_to_gpio(unsigned irq)
+{
+       return irq - AR71XX_GPIO_IRQ_BASE;
+}
+EXPORT_SYMBOL(irq_to_gpio);