diff options
Diffstat (limited to 'arch/arm/mach-pxa/mfp-pxa2xx.c')
-rw-r--r-- | arch/arm/mach-pxa/mfp-pxa2xx.c | 62 |
1 files changed, 46 insertions, 16 deletions
diff --git a/arch/arm/mach-pxa/mfp-pxa2xx.c b/arch/arm/mach-pxa/mfp-pxa2xx.c index 2061c00c8ead..33626de8cbf6 100644 --- a/arch/arm/mach-pxa/mfp-pxa2xx.c +++ b/arch/arm/mach-pxa/mfp-pxa2xx.c | |||
@@ -38,12 +38,13 @@ struct gpio_desc { | |||
38 | unsigned valid : 1; | 38 | unsigned valid : 1; |
39 | unsigned can_wakeup : 1; | 39 | unsigned can_wakeup : 1; |
40 | unsigned keypad_gpio : 1; | 40 | unsigned keypad_gpio : 1; |
41 | unsigned dir_inverted : 1; | ||
41 | unsigned int mask; /* bit mask in PWER or PKWR */ | 42 | unsigned int mask; /* bit mask in PWER or PKWR */ |
43 | unsigned int mux_mask; /* bit mask of muxed gpio bits, 0 if no mux */ | ||
42 | unsigned long config; | 44 | unsigned long config; |
43 | }; | 45 | }; |
44 | 46 | ||
45 | static struct gpio_desc gpio_desc[MFP_PIN_GPIO127 + 1]; | 47 | static struct gpio_desc gpio_desc[MFP_PIN_GPIO127 + 1]; |
46 | static int gpio_nr; | ||
47 | 48 | ||
48 | static unsigned long gpdr_lpm[4]; | 49 | static unsigned long gpdr_lpm[4]; |
49 | 50 | ||
@@ -54,7 +55,7 @@ static int __mfp_config_gpio(unsigned gpio, unsigned long c) | |||
54 | int uorl = !!(gpio & 0x10); /* GAFRx_U or GAFRx_L ? */ | 55 | int uorl = !!(gpio & 0x10); /* GAFRx_U or GAFRx_L ? */ |
55 | int shft = (gpio & 0xf) << 1; | 56 | int shft = (gpio & 0xf) << 1; |
56 | int fn = MFP_AF(c); | 57 | int fn = MFP_AF(c); |
57 | int dir = c & MFP_DIR_OUT; | 58 | int is_out = (c & MFP_DIR_OUT) ? 1 : 0; |
58 | 59 | ||
59 | if (fn > 3) | 60 | if (fn > 3) |
60 | return -EINVAL; | 61 | return -EINVAL; |
@@ -68,7 +69,7 @@ static int __mfp_config_gpio(unsigned gpio, unsigned long c) | |||
68 | else | 69 | else |
69 | GAFR_U(bank) = gafr; | 70 | GAFR_U(bank) = gafr; |
70 | 71 | ||
71 | if (dir == MFP_DIR_OUT) | 72 | if (is_out ^ gpio_desc[gpio].dir_inverted) |
72 | GPDR(gpio) |= mask; | 73 | GPDR(gpio) |= mask; |
73 | else | 74 | else |
74 | GPDR(gpio) &= ~mask; | 75 | GPDR(gpio) &= ~mask; |
@@ -77,11 +78,11 @@ static int __mfp_config_gpio(unsigned gpio, unsigned long c) | |||
77 | switch (c & MFP_LPM_STATE_MASK) { | 78 | switch (c & MFP_LPM_STATE_MASK) { |
78 | case MFP_LPM_DRIVE_HIGH: | 79 | case MFP_LPM_DRIVE_HIGH: |
79 | PGSR(bank) |= mask; | 80 | PGSR(bank) |= mask; |
80 | dir = MFP_DIR_OUT; | 81 | is_out = 1; |
81 | break; | 82 | break; |
82 | case MFP_LPM_DRIVE_LOW: | 83 | case MFP_LPM_DRIVE_LOW: |
83 | PGSR(bank) &= ~mask; | 84 | PGSR(bank) &= ~mask; |
84 | dir = MFP_DIR_OUT; | 85 | is_out = 1; |
85 | break; | 86 | break; |
86 | case MFP_LPM_DEFAULT: | 87 | case MFP_LPM_DEFAULT: |
87 | break; | 88 | break; |
@@ -92,7 +93,7 @@ static int __mfp_config_gpio(unsigned gpio, unsigned long c) | |||
92 | break; | 93 | break; |
93 | } | 94 | } |
94 | 95 | ||
95 | if (dir == MFP_DIR_OUT) | 96 | if (is_out ^ gpio_desc[gpio].dir_inverted) |
96 | gpdr_lpm[bank] |= mask; | 97 | gpdr_lpm[bank] |= mask; |
97 | else | 98 | else |
98 | gpdr_lpm[bank] &= ~mask; | 99 | gpdr_lpm[bank] &= ~mask; |
@@ -106,7 +107,7 @@ static int __mfp_config_gpio(unsigned gpio, unsigned long c) | |||
106 | return -EINVAL; | 107 | return -EINVAL; |
107 | } | 108 | } |
108 | 109 | ||
109 | if ((c & MFP_LPM_CAN_WAKEUP) && (dir == MFP_DIR_OUT)) { | 110 | if ((c & MFP_LPM_CAN_WAKEUP) && is_out) { |
110 | pr_warning("%s: output GPIO%d unable to wakeup\n", | 111 | pr_warning("%s: output GPIO%d unable to wakeup\n", |
111 | __func__, gpio); | 112 | __func__, gpio); |
112 | return -EINVAL; | 113 | return -EINVAL; |
@@ -169,7 +170,7 @@ void pxa2xx_mfp_set_lpm(int mfp, unsigned long lpm) | |||
169 | int gpio_set_wake(unsigned int gpio, unsigned int on) | 170 | int gpio_set_wake(unsigned int gpio, unsigned int on) |
170 | { | 171 | { |
171 | struct gpio_desc *d; | 172 | struct gpio_desc *d; |
172 | unsigned long c; | 173 | unsigned long c, mux_taken; |
173 | 174 | ||
174 | if (gpio > mfp_to_gpio(MFP_PIN_GPIO127)) | 175 | if (gpio > mfp_to_gpio(MFP_PIN_GPIO127)) |
175 | return -EINVAL; | 176 | return -EINVAL; |
@@ -183,9 +184,13 @@ int gpio_set_wake(unsigned int gpio, unsigned int on) | |||
183 | if (d->keypad_gpio) | 184 | if (d->keypad_gpio) |
184 | return -EINVAL; | 185 | return -EINVAL; |
185 | 186 | ||
187 | mux_taken = (PWER & d->mux_mask) & (~d->mask); | ||
188 | if (on && mux_taken) | ||
189 | return -EBUSY; | ||
190 | |||
186 | if (d->can_wakeup && (c & MFP_LPM_CAN_WAKEUP)) { | 191 | if (d->can_wakeup && (c & MFP_LPM_CAN_WAKEUP)) { |
187 | if (on) { | 192 | if (on) { |
188 | PWER |= d->mask; | 193 | PWER = (PWER & ~d->mux_mask) | d->mask; |
189 | 194 | ||
190 | if (c & MFP_LPM_EDGE_RISE) | 195 | if (c & MFP_LPM_EDGE_RISE) |
191 | PRER |= d->mask; | 196 | PRER |= d->mask; |
@@ -210,7 +215,7 @@ static void __init pxa25x_mfp_init(void) | |||
210 | { | 215 | { |
211 | int i; | 216 | int i; |
212 | 217 | ||
213 | for (i = 0; i <= 84; i++) | 218 | for (i = 0; i <= pxa_last_gpio; i++) |
214 | gpio_desc[i].valid = 1; | 219 | gpio_desc[i].valid = 1; |
215 | 220 | ||
216 | for (i = 0; i <= 15; i++) { | 221 | for (i = 0; i <= 15; i++) { |
@@ -218,7 +223,11 @@ static void __init pxa25x_mfp_init(void) | |||
218 | gpio_desc[i].mask = GPIO_bit(i); | 223 | gpio_desc[i].mask = GPIO_bit(i); |
219 | } | 224 | } |
220 | 225 | ||
221 | gpio_nr = 85; | 226 | /* PXA26x has additional 4 GPIOs (86/87/88/89) which has the |
227 | * direction bit inverted in GPDR2. See PXA26x DM 4.1.1. | ||
228 | */ | ||
229 | for (i = 86; i <= pxa_last_gpio; i++) | ||
230 | gpio_desc[i].dir_inverted = 1; | ||
222 | } | 231 | } |
223 | #else | 232 | #else |
224 | static inline void pxa25x_mfp_init(void) {} | 233 | static inline void pxa25x_mfp_init(void) {} |
@@ -251,11 +260,27 @@ int keypad_set_wake(unsigned int on) | |||
251 | return 0; | 260 | return 0; |
252 | } | 261 | } |
253 | 262 | ||
263 | #define PWER_WEMUX2_GPIO38 (1 << 16) | ||
264 | #define PWER_WEMUX2_GPIO53 (2 << 16) | ||
265 | #define PWER_WEMUX2_GPIO40 (3 << 16) | ||
266 | #define PWER_WEMUX2_GPIO36 (4 << 16) | ||
267 | #define PWER_WEMUX2_MASK (7 << 16) | ||
268 | #define PWER_WEMUX3_GPIO31 (1 << 19) | ||
269 | #define PWER_WEMUX3_GPIO113 (2 << 19) | ||
270 | #define PWER_WEMUX3_MASK (3 << 19) | ||
271 | |||
272 | #define INIT_GPIO_DESC_MUXED(mux, gpio) \ | ||
273 | do { \ | ||
274 | gpio_desc[(gpio)].can_wakeup = 1; \ | ||
275 | gpio_desc[(gpio)].mask = PWER_ ## mux ## _GPIO ##gpio; \ | ||
276 | gpio_desc[(gpio)].mux_mask = PWER_ ## mux ## _MASK; \ | ||
277 | } while (0) | ||
278 | |||
254 | static void __init pxa27x_mfp_init(void) | 279 | static void __init pxa27x_mfp_init(void) |
255 | { | 280 | { |
256 | int i, gpio; | 281 | int i, gpio; |
257 | 282 | ||
258 | for (i = 0; i <= 120; i++) { | 283 | for (i = 0; i <= pxa_last_gpio; i++) { |
259 | /* skip GPIO2, 5, 6, 7, 8, they are not | 284 | /* skip GPIO2, 5, 6, 7, 8, they are not |
260 | * valid pins allow configuration | 285 | * valid pins allow configuration |
261 | */ | 286 | */ |
@@ -286,7 +311,12 @@ static void __init pxa27x_mfp_init(void) | |||
286 | gpio_desc[35].can_wakeup = 1; | 311 | gpio_desc[35].can_wakeup = 1; |
287 | gpio_desc[35].mask = PWER_WE35; | 312 | gpio_desc[35].mask = PWER_WE35; |
288 | 313 | ||
289 | gpio_nr = 121; | 314 | INIT_GPIO_DESC_MUXED(WEMUX3, 31); |
315 | INIT_GPIO_DESC_MUXED(WEMUX3, 113); | ||
316 | INIT_GPIO_DESC_MUXED(WEMUX2, 38); | ||
317 | INIT_GPIO_DESC_MUXED(WEMUX2, 53); | ||
318 | INIT_GPIO_DESC_MUXED(WEMUX2, 40); | ||
319 | INIT_GPIO_DESC_MUXED(WEMUX2, 36); | ||
290 | } | 320 | } |
291 | #else | 321 | #else |
292 | static inline void pxa27x_mfp_init(void) {} | 322 | static inline void pxa27x_mfp_init(void) {} |
@@ -300,7 +330,7 @@ static int pxa2xx_mfp_suspend(struct sys_device *d, pm_message_t state) | |||
300 | { | 330 | { |
301 | int i; | 331 | int i; |
302 | 332 | ||
303 | for (i = 0; i <= gpio_to_bank(gpio_nr); i++) { | 333 | for (i = 0; i <= gpio_to_bank(pxa_last_gpio); i++) { |
304 | 334 | ||
305 | saved_gafr[0][i] = GAFR_L(i); | 335 | saved_gafr[0][i] = GAFR_L(i); |
306 | saved_gafr[1][i] = GAFR_U(i); | 336 | saved_gafr[1][i] = GAFR_U(i); |
@@ -315,7 +345,7 @@ static int pxa2xx_mfp_resume(struct sys_device *d) | |||
315 | { | 345 | { |
316 | int i; | 346 | int i; |
317 | 347 | ||
318 | for (i = 0; i <= gpio_to_bank(gpio_nr); i++) { | 348 | for (i = 0; i <= gpio_to_bank(pxa_last_gpio); i++) { |
319 | GAFR_L(i) = saved_gafr[0][i]; | 349 | GAFR_L(i) = saved_gafr[0][i]; |
320 | GAFR_U(i) = saved_gafr[1][i]; | 350 | GAFR_U(i) = saved_gafr[1][i]; |
321 | GPDR(i * 32) = saved_gpdr[i]; | 351 | GPDR(i * 32) = saved_gpdr[i]; |
@@ -348,7 +378,7 @@ static int __init pxa2xx_mfp_init(void) | |||
348 | pxa27x_mfp_init(); | 378 | pxa27x_mfp_init(); |
349 | 379 | ||
350 | /* initialize gafr_run[], pgsr_lpm[] from existing values */ | 380 | /* initialize gafr_run[], pgsr_lpm[] from existing values */ |
351 | for (i = 0; i <= gpio_to_bank(gpio_nr); i++) | 381 | for (i = 0; i <= gpio_to_bank(pxa_last_gpio); i++) |
352 | gpdr_lpm[i] = GPDR(i * 32); | 382 | gpdr_lpm[i] = GPDR(i * 32); |
353 | 383 | ||
354 | return sysdev_class_register(&pxa2xx_mfp_sysclass); | 384 | return sysdev_class_register(&pxa2xx_mfp_sysclass); |