netns xfrm: fix "ip xfrm state|policy count" misreport
[safe/jmp/linux-2.6] / arch / arm / mach-pxa / mfp-pxa2xx.c
index 28d1067..cf6b720 100644 (file)
 #include <linux/init.h>
 #include <linux/sysdev.h>
 
-#include <mach/hardware.h>
-#include <mach/pxa-regs.h>
+#include <mach/gpio.h>
 #include <mach/pxa2xx-regs.h>
 #include <mach/mfp-pxa2xx.h>
 
 #include "generic.h"
 
-#define gpio_to_bank(gpio)     ((gpio) >> 5)
-
 #define PGSR(x)                __REG2(0x40F00020, (x) << 2)
 #define __GAFR(u, x)   __REG2((u) ? 0x40E00058 : 0x40E00054, (x) << 3)
 #define GAFR_L(x)      __GAFR(0, x)
@@ -38,13 +35,13 @@ struct gpio_desc {
        unsigned        valid           : 1;
        unsigned        can_wakeup      : 1;
        unsigned        keypad_gpio     : 1;
+       unsigned        dir_inverted    : 1;
        unsigned int    mask; /* bit mask in PWER or PKWR */
        unsigned int    mux_mask; /* bit mask of muxed gpio bits, 0 if no mux */
        unsigned long   config;
 };
 
 static struct gpio_desc gpio_desc[MFP_PIN_GPIO127 + 1];
-static int gpio_nr;
 
 static unsigned long gpdr_lpm[4];
 
@@ -55,7 +52,7 @@ static int __mfp_config_gpio(unsigned gpio, unsigned long c)
        int uorl = !!(gpio & 0x10); /* GAFRx_U or GAFRx_L ? */
        int shft = (gpio & 0xf) << 1;
        int fn = MFP_AF(c);
-       int dir = c & MFP_DIR_OUT;
+       int is_out = (c & MFP_DIR_OUT) ? 1 : 0;
 
        if (fn > 3)
                return -EINVAL;
@@ -69,7 +66,7 @@ static int __mfp_config_gpio(unsigned gpio, unsigned long c)
        else
                GAFR_U(bank) = gafr;
 
-       if (dir == MFP_DIR_OUT)
+       if (is_out ^ gpio_desc[gpio].dir_inverted)
                GPDR(gpio) |= mask;
        else
                GPDR(gpio) &= ~mask;
@@ -78,11 +75,11 @@ static int __mfp_config_gpio(unsigned gpio, unsigned long c)
        switch (c & MFP_LPM_STATE_MASK) {
        case MFP_LPM_DRIVE_HIGH:
                PGSR(bank) |= mask;
-               dir = MFP_DIR_OUT;
+               is_out = 1;
                break;
        case MFP_LPM_DRIVE_LOW:
                PGSR(bank) &= ~mask;
-               dir = MFP_DIR_OUT;
+               is_out = 1;
                break;
        case MFP_LPM_DEFAULT:
                break;
@@ -93,7 +90,7 @@ static int __mfp_config_gpio(unsigned gpio, unsigned long c)
                break;
        }
 
-       if (dir == MFP_DIR_OUT)
+       if (is_out ^ gpio_desc[gpio].dir_inverted)
                gpdr_lpm[bank] |= mask;
        else
                gpdr_lpm[bank] &= ~mask;
@@ -107,7 +104,7 @@ static int __mfp_config_gpio(unsigned gpio, unsigned long c)
                return -EINVAL;
        }
 
-       if ((c & MFP_LPM_CAN_WAKEUP) && (dir == MFP_DIR_OUT)) {
+       if ((c & MFP_LPM_CAN_WAKEUP) && is_out) {
                pr_warning("%s: output GPIO%d unable to wakeup\n",
                                __func__, gpio);
                return -EINVAL;
@@ -215,7 +212,7 @@ static void __init pxa25x_mfp_init(void)
 {
        int i;
 
-       for (i = 0; i <= 84; i++)
+       for (i = 0; i <= pxa_last_gpio; i++)
                gpio_desc[i].valid = 1;
 
        for (i = 0; i <= 15; i++) {
@@ -223,7 +220,11 @@ static void __init pxa25x_mfp_init(void)
                gpio_desc[i].mask = GPIO_bit(i);
        }
 
-       gpio_nr = 85;
+       /* PXA26x has additional 4 GPIOs (86/87/88/89) which has the
+        * direction bit inverted in GPDR2. See PXA26x DM 4.1.1.
+        */
+       for (i = 86; i <= pxa_last_gpio; i++)
+               gpio_desc[i].dir_inverted = 1;
 }
 #else
 static inline void pxa25x_mfp_init(void) {}
@@ -276,7 +277,7 @@ static void __init pxa27x_mfp_init(void)
 {
        int i, gpio;
 
-       for (i = 0; i <= 120; i++) {
+       for (i = 0; i <= pxa_last_gpio; i++) {
                /* skip GPIO2, 5, 6, 7, 8, they are not
                 * valid pins allow configuration
                 */
@@ -313,7 +314,6 @@ static void __init pxa27x_mfp_init(void)
        INIT_GPIO_DESC_MUXED(WEMUX2, 53);
        INIT_GPIO_DESC_MUXED(WEMUX2, 40);
        INIT_GPIO_DESC_MUXED(WEMUX2, 36);
-       gpio_nr = 121;
 }
 #else
 static inline void pxa27x_mfp_init(void) {}
@@ -322,16 +322,18 @@ static inline void pxa27x_mfp_init(void) {}
 #ifdef CONFIG_PM
 static unsigned long saved_gafr[2][4];
 static unsigned long saved_gpdr[4];
+static unsigned long saved_pgsr[4];
 
 static int pxa2xx_mfp_suspend(struct sys_device *d, pm_message_t state)
 {
        int i;
 
-       for (i = 0; i <= gpio_to_bank(gpio_nr); i++) {
+       for (i = 0; i <= gpio_to_bank(pxa_last_gpio); i++) {
 
                saved_gafr[0][i] = GAFR_L(i);
                saved_gafr[1][i] = GAFR_U(i);
                saved_gpdr[i] = GPDR(i * 32);
+               saved_pgsr[i] = PGSR(i);
 
                GPDR(i * 32) = gpdr_lpm[i];
        }
@@ -342,10 +344,11 @@ static int pxa2xx_mfp_resume(struct sys_device *d)
 {
        int i;
 
-       for (i = 0; i <= gpio_to_bank(gpio_nr); i++) {
+       for (i = 0; i <= gpio_to_bank(pxa_last_gpio); i++) {
                GAFR_L(i) = saved_gafr[0][i];
                GAFR_U(i) = saved_gafr[1][i];
                GPDR(i * 32) = saved_gpdr[i];
+               PGSR(i) = saved_pgsr[i];
        }
        PSSR = PSSR_RDH | PSSR_PH;
        return 0;
@@ -374,8 +377,11 @@ static int __init pxa2xx_mfp_init(void)
        if (cpu_is_pxa27x())
                pxa27x_mfp_init();
 
+       /* clear RDH bit to enable GPIO receivers after reset/sleep exit */
+       PSSR = PSSR_RDH;
+
        /* initialize gafr_run[], pgsr_lpm[] from existing values */
-       for (i = 0; i <= gpio_to_bank(gpio_nr); i++)
+       for (i = 0; i <= gpio_to_bank(pxa_last_gpio); i++)
                gpdr_lpm[i] = GPDR(i * 32);
 
        return sysdev_class_register(&pxa2xx_mfp_sysclass);