]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/blackfin/kernel/bfin_gpio.c
Merge branch 'audit.b51' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/audit...
[linux-2.6-omap-h63xx.git] / arch / blackfin / kernel / bfin_gpio.c
index 6bbe0a2fccb8f14c7774d4198377b64bc761d111..b6d89d1644cc8515c1909865e01fdf83e9ede39f 100644 (file)
@@ -95,14 +95,14 @@ enum {
        AWA_data_clear = SYSCR,
        AWA_data_set = SYSCR,
        AWA_toggle = SYSCR,
-       AWA_maska = UART_SCR,
-       AWA_maska_clear = UART_SCR,
-       AWA_maska_set = UART_SCR,
-       AWA_maska_toggle = UART_SCR,
-       AWA_maskb = UART_GCTL,
-       AWA_maskb_clear = UART_GCTL,
-       AWA_maskb_set = UART_GCTL,
-       AWA_maskb_toggle = UART_GCTL,
+       AWA_maska = BFIN_UART_SCR,
+       AWA_maska_clear = BFIN_UART_SCR,
+       AWA_maska_set = BFIN_UART_SCR,
+       AWA_maska_toggle = BFIN_UART_SCR,
+       AWA_maskb = BFIN_UART_GCTL,
+       AWA_maskb_clear = BFIN_UART_GCTL,
+       AWA_maskb_set = BFIN_UART_GCTL,
+       AWA_maskb_toggle = BFIN_UART_GCTL,
        AWA_dir = SPORT1_STAT,
        AWA_polar = SPORT1_STAT,
        AWA_edge = SPORT1_STAT,
@@ -186,7 +186,7 @@ static struct str_ident {
        char name[RESOURCE_LABEL_SIZE];
 } str_ident[MAX_RESOURCES];
 
-#ifdef CONFIG_PM
+#if defined(CONFIG_PM) && !defined(CONFIG_BF54x)
 static unsigned short wakeup_map[gpio_bank(MAX_BLACKFIN_GPIOS)];
 static unsigned char wakeup_flags_map[MAX_BLACKFIN_GPIOS];
 static struct gpio_port_s gpio_bank_saved[gpio_bank(MAX_BLACKFIN_GPIOS)];
@@ -348,11 +348,10 @@ static void portmux_setup(unsigned short per, unsigned short function)
                        offset = port_mux_lut[y].offset;
                        muxreg = bfin_read_PORT_MUX();
 
-                       if (offset != 1) {
+                       if (offset != 1)
                                muxreg &= ~(1 << offset);
-                       } else {
+                       else
                                muxreg &= ~(3 << 1);
-                       }
 
                        muxreg |= (function << offset);
                        bfin_write_PORT_MUX(muxreg);
@@ -396,39 +395,11 @@ inline void portmux_setup(unsigned short portno, unsigned short function)
 # define portmux_setup(...)  do { } while (0)
 #endif
 
-#ifndef BF548_FAMILY
-static void default_gpio(unsigned gpio)
-{
-       unsigned short bank, bitmask;
-       unsigned long flags;
-
-       bank = gpio_bank(gpio);
-       bitmask = gpio_bit(gpio);
-
-       local_irq_save(flags);
-
-       gpio_bankb[bank]->maska_clear = bitmask;
-       gpio_bankb[bank]->maskb_clear = bitmask;
-       SSYNC();
-       gpio_bankb[bank]->inen &= ~bitmask;
-       gpio_bankb[bank]->dir &= ~bitmask;
-       gpio_bankb[bank]->polar &= ~bitmask;
-       gpio_bankb[bank]->both &= ~bitmask;
-       gpio_bankb[bank]->edge &= ~bitmask;
-       AWA_DUMMY_READ(edge);
-       local_irq_restore(flags);
-}
-#else
-# define default_gpio(...)  do { } while (0)
-#endif
-
 static int __init bfin_gpio_init(void)
 {
-
        printk(KERN_INFO "Blackfin GPIO Controller\n");
 
        return 0;
-
 }
 arch_initcall(bfin_gpio_init);
 
@@ -696,9 +667,8 @@ static int bfin_gpio_wakeup_type(unsigned gpio, unsigned char type)
        return 0;
 }
 
-u32 gpio_pm_setup(void)
+u32 bfin_pm_setup(void)
 {
-       u32 sic_iwr = 0;
        u16 bank, mask, i, gpio;
 
        for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
@@ -723,7 +693,8 @@ u32 gpio_pm_setup(void)
                        gpio = i;
 
                        while (mask) {
-                               if (mask & 1) {
+                               if ((mask & 1) && (wakeup_flags_map[gpio] !=
+                                       PM_WAKE_IGNORE)) {
                                        reserved_gpio_map[gpio_bank(gpio)] |=
                                                        gpio_bit(gpio);
                                        bfin_gpio_wakeup_type(gpio,
@@ -734,21 +705,17 @@ u32 gpio_pm_setup(void)
                                mask >>= 1;
                        }
 
-                       sic_iwr |= 1 <<
-                               (sic_iwr_irqs[bank] - (IRQ_CORETMR + 1));
+                       bfin_internal_set_wake(sic_iwr_irqs[bank], 1);
                        gpio_bankb[bank]->maskb_set = wakeup_map[gpio_bank(i)];
                }
        }
 
        AWA_DUMMY_READ(maskb_set);
 
-       if (sic_iwr)
-               return sic_iwr;
-       else
-               return IWR_ENABLE_ALL;
+       return 0;
 }
 
-void gpio_pm_restore(void)
+void bfin_pm_restore(void)
 {
        u16 bank, mask, i;
 
@@ -768,7 +735,7 @@ void gpio_pm_restore(void)
 
                        reserved_gpio_map[bank] =
                                        gpio_bank_saved[bank].reserved;
-
+                       bfin_internal_set_wake(sic_iwr_irqs[bank], 0);
                }
 
                gpio_bankb[bank]->maskb = gpio_bank_saved[bank].maskb;
@@ -825,10 +792,10 @@ int peripheral_request(unsigned short per, const char *label)
        local_irq_save(flags);
 
        if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
+               dump_stack();
                printk(KERN_ERR
                    "%s: Peripheral %d is already reserved as GPIO by %s !\n",
-                      __FUNCTION__, ident, get_label(ident));
-               dump_stack();
+                      __func__, ident, get_label(ident));
                local_irq_restore(flags);
                return -EBUSY;
        }
@@ -837,31 +804,31 @@ int peripheral_request(unsigned short per, const char *label)
 
                u16 funct = get_portmux(ident);
 
-       /*
-        * Pin functions like AMC address strobes my
-        * be requested and used by several drivers
-        */
+               /*
+                * Pin functions like AMC address strobes my
+                * be requested and used by several drivers
+                */
 
                if (!((per & P_MAYSHARE) && (funct == P_FUNCT2MUX(per)))) {
 
-               /*
-                * Allow that the identical pin function can
-                * be requested from the same driver twice
-                */
+                       /*
+                        * Allow that the identical pin function can
+                        * be requested from the same driver twice
+                        */
 
-               if (cmp_label(ident, label) == 0)
-                       goto anyway;
+                       if (cmp_label(ident, label) == 0)
+                               goto anyway;
 
+                       dump_stack();
                        printk(KERN_ERR
                               "%s: Peripheral %d function %d is already reserved by %s !\n",
-                              __FUNCTION__, ident, P_FUNCT2MUX(per), get_label(ident));
-                       dump_stack();
+                              __func__, ident, P_FUNCT2MUX(per), get_label(ident));
                        local_irq_restore(flags);
                        return -EBUSY;
                }
        }
 
-anyway:
+ anyway:
        reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident);
 
        portmux_setup(ident, P_FUNCT2MUX(per));
@@ -894,47 +861,47 @@ int peripheral_request(unsigned short per, const char *label)
 
        if (!check_gpio(ident)) {
 
-       if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
-               printk(KERN_ERR
-                      "%s: Peripheral %d is already reserved as GPIO by %s !\n",
-                      __FUNCTION__, ident, get_label(ident));
-               dump_stack();
-               local_irq_restore(flags);
-               return -EBUSY;
-       }
+               if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
+                       dump_stack();
+                       printk(KERN_ERR
+                              "%s: Peripheral %d is already reserved as GPIO by %s !\n",
+                              __func__, ident, get_label(ident));
+                       local_irq_restore(flags);
+                       return -EBUSY;
+               }
 
        }
 
        if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) {
 
-       /*
-        * Pin functions like AMC address strobes my
-        * be requested and used by several drivers
-        */
+               /*
+                * Pin functions like AMC address strobes my
+                * be requested and used by several drivers
+                */
 
-       if (!(per & P_MAYSHARE)) {
+               if (!(per & P_MAYSHARE)) {
 
-       /*
-        * Allow that the identical pin function can
-        * be requested from the same driver twice
-        */
+                       /*
+                        * Allow that the identical pin function can
+                        * be requested from the same driver twice
+                        */
 
-               if (cmp_label(ident, label) == 0)
-                       goto anyway;
+                       if (cmp_label(ident, label) == 0)
+                               goto anyway;
 
+                       dump_stack();
                        printk(KERN_ERR
                               "%s: Peripheral %d function %d is already"
                               " reserved by %s !\n",
-                              __FUNCTION__, ident, P_FUNCT2MUX(per),
+                              __func__, ident, P_FUNCT2MUX(per),
                                get_label(ident));
-                       dump_stack();
                        local_irq_restore(flags);
                        return -EBUSY;
                }
 
        }
 
-anyway:
+ anyway:
        portmux_setup(per, P_FUNCT2MUX(per));
 
        port_setup(ident, PERIPHERAL_USAGE);
@@ -948,7 +915,7 @@ anyway:
 EXPORT_SYMBOL(peripheral_request);
 #endif
 
-int peripheral_request_list(unsigned short per[], const char *label)
+int peripheral_request_list(const unsigned short per[], const char *label)
 {
        u16 cnt;
        int ret;
@@ -958,10 +925,10 @@ int peripheral_request_list(unsigned short per[], const char *label)
                ret = peripheral_request(per[cnt], label);
 
                if (ret < 0) {
-                       for ( ; cnt > 0; cnt--) {
+                       for ( ; cnt > 0; cnt--)
                                peripheral_free(per[cnt - 1]);
-                       }
-               return ret;
+
+                       return ret;
                }
        }
 
@@ -985,15 +952,13 @@ void peripheral_free(unsigned short per)
 
        local_irq_save(flags);
 
-       if (unlikely(!(reserved_peri_map[gpio_bank(ident)]
-                        & gpio_bit(ident)))) {
+       if (unlikely(!(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident)))) {
                local_irq_restore(flags);
                return;
        }
 
-       if (!(per & P_MAYSHARE)) {
+       if (!(per & P_MAYSHARE))
                port_setup(ident, GPIO_USAGE);
-       }
 
        reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident);
 
@@ -1003,14 +968,11 @@ void peripheral_free(unsigned short per)
 }
 EXPORT_SYMBOL(peripheral_free);
 
-void peripheral_free_list(unsigned short per[])
+void peripheral_free_list(const unsigned short per[])
 {
        u16 cnt;
-
-       for (cnt = 0; per[cnt] != 0; cnt++) {
+       for (cnt = 0; per[cnt] != 0; cnt++)
                peripheral_free(per[cnt]);
-       }
-
 }
 EXPORT_SYMBOL(peripheral_free_list);
 
@@ -1050,17 +1012,17 @@ int gpio_request(unsigned gpio, const char *label)
        }
 
        if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
+               dump_stack();
                printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
                         gpio, get_label(gpio));
-               dump_stack();
                local_irq_restore(flags);
                return -EBUSY;
        }
        if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
+               dump_stack();
                printk(KERN_ERR
                       "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
                       gpio, get_label(gpio));
-               dump_stack();
                local_irq_restore(flags);
                return -EBUSY;
        }
@@ -1086,14 +1048,12 @@ void gpio_free(unsigned gpio)
        local_irq_save(flags);
 
        if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
-               gpio_error(gpio);
                dump_stack();
+               gpio_error(gpio);
                local_irq_restore(flags);
                return;
        }
 
-       default_gpio(gpio);
-
        reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
 
        set_label(gpio, "free");
@@ -1156,8 +1116,39 @@ int gpio_get_value(unsigned gpio)
 }
 EXPORT_SYMBOL(gpio_get_value);
 
+void bfin_gpio_irq_prepare(unsigned gpio)
+{
+       unsigned long flags;
+
+       port_setup(gpio, GPIO_USAGE);
+
+       local_irq_save(flags);
+       gpio_array[gpio_bank(gpio)]->port_dir_clear = gpio_bit(gpio);
+       gpio_array[gpio_bank(gpio)]->port_inen |= gpio_bit(gpio);
+       local_irq_restore(flags);
+}
+
 #else
 
+int gpio_get_value(unsigned gpio)
+{
+       unsigned long flags;
+       int ret;
+
+       if (unlikely(get_gpio_edge(gpio))) {
+               local_irq_save(flags);
+               set_gpio_edge(gpio, 0);
+               ret = get_gpio_data(gpio);
+               set_gpio_edge(gpio, 1);
+               local_irq_restore(flags);
+
+               return ret;
+       } else
+               return get_gpio_data(gpio);
+}
+EXPORT_SYMBOL(gpio_get_value);
+
+
 int gpio_direction_input(unsigned gpio)
 {
        unsigned long flags;
@@ -1222,6 +1213,11 @@ void bfin_gpio_reset_spi0_ssel1(void)
        udelay(1);
 }
 
+void bfin_gpio_irq_prepare(unsigned gpio)
+{
+       port_setup(gpio, GPIO_USAGE);
+}
+
 #endif /*BF548_FAMILY */
 
 #if defined(CONFIG_PROC_FS)