diff options
Diffstat (limited to 'arch/blackfin/kernel/bfin_gpio.c')
-rw-r--r-- | arch/blackfin/kernel/bfin_gpio.c | 578 |
1 files changed, 223 insertions, 355 deletions
diff --git a/arch/blackfin/kernel/bfin_gpio.c b/arch/blackfin/kernel/bfin_gpio.c index 4c14331978f6..51dac55c524a 100644 --- a/arch/blackfin/kernel/bfin_gpio.c +++ b/arch/blackfin/kernel/bfin_gpio.c | |||
@@ -27,59 +27,6 @@ | |||
27 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 27 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
28 | */ | 28 | */ |
29 | 29 | ||
30 | /* | ||
31 | * Number BF537/6/4 BF561 BF533/2/1 BF549/8/4/2 | ||
32 | * | ||
33 | * GPIO_0 PF0 PF0 PF0 PA0...PJ13 | ||
34 | * GPIO_1 PF1 PF1 PF1 | ||
35 | * GPIO_2 PF2 PF2 PF2 | ||
36 | * GPIO_3 PF3 PF3 PF3 | ||
37 | * GPIO_4 PF4 PF4 PF4 | ||
38 | * GPIO_5 PF5 PF5 PF5 | ||
39 | * GPIO_6 PF6 PF6 PF6 | ||
40 | * GPIO_7 PF7 PF7 PF7 | ||
41 | * GPIO_8 PF8 PF8 PF8 | ||
42 | * GPIO_9 PF9 PF9 PF9 | ||
43 | * GPIO_10 PF10 PF10 PF10 | ||
44 | * GPIO_11 PF11 PF11 PF11 | ||
45 | * GPIO_12 PF12 PF12 PF12 | ||
46 | * GPIO_13 PF13 PF13 PF13 | ||
47 | * GPIO_14 PF14 PF14 PF14 | ||
48 | * GPIO_15 PF15 PF15 PF15 | ||
49 | * GPIO_16 PG0 PF16 | ||
50 | * GPIO_17 PG1 PF17 | ||
51 | * GPIO_18 PG2 PF18 | ||
52 | * GPIO_19 PG3 PF19 | ||
53 | * GPIO_20 PG4 PF20 | ||
54 | * GPIO_21 PG5 PF21 | ||
55 | * GPIO_22 PG6 PF22 | ||
56 | * GPIO_23 PG7 PF23 | ||
57 | * GPIO_24 PG8 PF24 | ||
58 | * GPIO_25 PG9 PF25 | ||
59 | * GPIO_26 PG10 PF26 | ||
60 | * GPIO_27 PG11 PF27 | ||
61 | * GPIO_28 PG12 PF28 | ||
62 | * GPIO_29 PG13 PF29 | ||
63 | * GPIO_30 PG14 PF30 | ||
64 | * GPIO_31 PG15 PF31 | ||
65 | * GPIO_32 PH0 PF32 | ||
66 | * GPIO_33 PH1 PF33 | ||
67 | * GPIO_34 PH2 PF34 | ||
68 | * GPIO_35 PH3 PF35 | ||
69 | * GPIO_36 PH4 PF36 | ||
70 | * GPIO_37 PH5 PF37 | ||
71 | * GPIO_38 PH6 PF38 | ||
72 | * GPIO_39 PH7 PF39 | ||
73 | * GPIO_40 PH8 PF40 | ||
74 | * GPIO_41 PH9 PF41 | ||
75 | * GPIO_42 PH10 PF42 | ||
76 | * GPIO_43 PH11 PF43 | ||
77 | * GPIO_44 PH12 PF44 | ||
78 | * GPIO_45 PH13 PF45 | ||
79 | * GPIO_46 PH14 PF46 | ||
80 | * GPIO_47 PH15 PF47 | ||
81 | */ | ||
82 | |||
83 | #include <linux/delay.h> | 30 | #include <linux/delay.h> |
84 | #include <linux/module.h> | 31 | #include <linux/module.h> |
85 | #include <linux/err.h> | 32 | #include <linux/err.h> |
@@ -119,62 +66,61 @@ enum { | |||
119 | #define AWA_DUMMY_READ(...) do { } while (0) | 66 | #define AWA_DUMMY_READ(...) do { } while (0) |
120 | #endif | 67 | #endif |
121 | 68 | ||
69 | static struct gpio_port_t * const gpio_array[] = { | ||
122 | #if defined(BF533_FAMILY) || defined(BF538_FAMILY) | 70 | #if defined(BF533_FAMILY) || defined(BF538_FAMILY) |
123 | static struct gpio_port_t *gpio_bankb[] = { | ||
124 | (struct gpio_port_t *) FIO_FLAG_D, | 71 | (struct gpio_port_t *) FIO_FLAG_D, |
125 | }; | 72 | #elif defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY) |
126 | #endif | ||
127 | |||
128 | #if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY) | ||
129 | static struct gpio_port_t *gpio_bankb[] = { | ||
130 | (struct gpio_port_t *) PORTFIO, | 73 | (struct gpio_port_t *) PORTFIO, |
131 | (struct gpio_port_t *) PORTGIO, | 74 | (struct gpio_port_t *) PORTGIO, |
132 | (struct gpio_port_t *) PORTHIO, | 75 | (struct gpio_port_t *) PORTHIO, |
76 | #elif defined(BF561_FAMILY) | ||
77 | (struct gpio_port_t *) FIO0_FLAG_D, | ||
78 | (struct gpio_port_t *) FIO1_FLAG_D, | ||
79 | (struct gpio_port_t *) FIO2_FLAG_D, | ||
80 | #elif defined(BF548_FAMILY) | ||
81 | (struct gpio_port_t *)PORTA_FER, | ||
82 | (struct gpio_port_t *)PORTB_FER, | ||
83 | (struct gpio_port_t *)PORTC_FER, | ||
84 | (struct gpio_port_t *)PORTD_FER, | ||
85 | (struct gpio_port_t *)PORTE_FER, | ||
86 | (struct gpio_port_t *)PORTF_FER, | ||
87 | (struct gpio_port_t *)PORTG_FER, | ||
88 | (struct gpio_port_t *)PORTH_FER, | ||
89 | (struct gpio_port_t *)PORTI_FER, | ||
90 | (struct gpio_port_t *)PORTJ_FER, | ||
91 | #else | ||
92 | # error no gpio arrays defined | ||
93 | #endif | ||
133 | }; | 94 | }; |
134 | 95 | ||
135 | static unsigned short *port_fer[] = { | 96 | #if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY) |
97 | static unsigned short * const port_fer[] = { | ||
136 | (unsigned short *) PORTF_FER, | 98 | (unsigned short *) PORTF_FER, |
137 | (unsigned short *) PORTG_FER, | 99 | (unsigned short *) PORTG_FER, |
138 | (unsigned short *) PORTH_FER, | 100 | (unsigned short *) PORTH_FER, |
139 | }; | 101 | }; |
140 | #endif | ||
141 | 102 | ||
142 | #if defined(BF527_FAMILY) || defined(BF518_FAMILY) | 103 | # if !defined(BF537_FAMILY) |
143 | static unsigned short *port_mux[] = { | 104 | static unsigned short * const port_mux[] = { |
144 | (unsigned short *) PORTF_MUX, | 105 | (unsigned short *) PORTF_MUX, |
145 | (unsigned short *) PORTG_MUX, | 106 | (unsigned short *) PORTG_MUX, |
146 | (unsigned short *) PORTH_MUX, | 107 | (unsigned short *) PORTH_MUX, |
147 | }; | 108 | }; |
148 | 109 | ||
149 | static const | 110 | static const |
150 | u8 pmux_offset[][16] = | 111 | u8 pmux_offset[][16] = { |
151 | {{ 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 4, 6, 8, 8, 10, 10 }, /* PORTF */ | 112 | # if defined(BF527_FAMILY) |
152 | { 0, 0, 0, 0, 0, 2, 2, 4, 4, 6, 8, 10, 10, 10, 12, 12 }, /* PORTG */ | 113 | { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 4, 6, 8, 8, 10, 10 }, /* PORTF */ |
153 | { 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4 }, /* PORTH */ | 114 | { 0, 0, 0, 0, 0, 2, 2, 4, 4, 6, 8, 10, 10, 10, 12, 12 }, /* PORTG */ |
154 | }; | 115 | { 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4 }, /* PORTH */ |
155 | #endif | 116 | # elif defined(BF518_FAMILY) |
156 | 117 | { 0, 2, 2, 2, 2, 2, 2, 4, 6, 6, 6, 8, 8, 8, 8, 10 }, /* PORTF */ | |
157 | #ifdef BF561_FAMILY | 118 | { 0, 0, 0, 2, 4, 6, 6, 6, 8, 10, 10, 12, 14, 14, 14, 14 }, /* PORTG */ |
158 | static struct gpio_port_t *gpio_bankb[] = { | 119 | { 0, 0, 0, 0, 2, 2, 4, 6, 10, 10, 10, 10, 10, 10, 10, 10 }, /* PORTH */ |
159 | (struct gpio_port_t *) FIO0_FLAG_D, | 120 | # endif |
160 | (struct gpio_port_t *) FIO1_FLAG_D, | ||
161 | (struct gpio_port_t *) FIO2_FLAG_D, | ||
162 | }; | 121 | }; |
163 | #endif | 122 | # endif |
164 | 123 | ||
165 | #ifdef BF548_FAMILY | ||
166 | static struct gpio_port_t *gpio_array[] = { | ||
167 | (struct gpio_port_t *)PORTA_FER, | ||
168 | (struct gpio_port_t *)PORTB_FER, | ||
169 | (struct gpio_port_t *)PORTC_FER, | ||
170 | (struct gpio_port_t *)PORTD_FER, | ||
171 | (struct gpio_port_t *)PORTE_FER, | ||
172 | (struct gpio_port_t *)PORTF_FER, | ||
173 | (struct gpio_port_t *)PORTG_FER, | ||
174 | (struct gpio_port_t *)PORTH_FER, | ||
175 | (struct gpio_port_t *)PORTI_FER, | ||
176 | (struct gpio_port_t *)PORTJ_FER, | ||
177 | }; | ||
178 | #endif | 124 | #endif |
179 | 125 | ||
180 | static unsigned short reserved_gpio_map[GPIO_BANK_NUM]; | 126 | static unsigned short reserved_gpio_map[GPIO_BANK_NUM]; |
@@ -188,35 +134,9 @@ static struct str_ident { | |||
188 | } str_ident[MAX_RESOURCES]; | 134 | } str_ident[MAX_RESOURCES]; |
189 | 135 | ||
190 | #if defined(CONFIG_PM) | 136 | #if defined(CONFIG_PM) |
191 | #if defined(CONFIG_BF54x) | ||
192 | static struct gpio_port_s gpio_bank_saved[GPIO_BANK_NUM]; | ||
193 | #else | ||
194 | static unsigned short wakeup_map[GPIO_BANK_NUM]; | ||
195 | static unsigned char wakeup_flags_map[MAX_BLACKFIN_GPIOS]; | ||
196 | static struct gpio_port_s gpio_bank_saved[GPIO_BANK_NUM]; | 137 | static struct gpio_port_s gpio_bank_saved[GPIO_BANK_NUM]; |
197 | |||
198 | #ifdef BF533_FAMILY | ||
199 | static unsigned int sic_iwr_irqs[] = {IRQ_PROG_INTB}; | ||
200 | #endif | ||
201 | |||
202 | #ifdef BF537_FAMILY | ||
203 | static unsigned int sic_iwr_irqs[] = {IRQ_PROG_INTB, IRQ_PORTG_INTB, IRQ_MAC_TX}; | ||
204 | #endif | ||
205 | |||
206 | #ifdef BF538_FAMILY | ||
207 | static unsigned int sic_iwr_irqs[] = {IRQ_PORTF_INTB}; | ||
208 | #endif | 138 | #endif |
209 | 139 | ||
210 | #if defined(BF527_FAMILY) || defined(BF518_FAMILY) | ||
211 | static unsigned int sic_iwr_irqs[] = {IRQ_PORTF_INTB, IRQ_PORTG_INTB, IRQ_PORTH_INTB}; | ||
212 | #endif | ||
213 | |||
214 | #ifdef BF561_FAMILY | ||
215 | static unsigned int sic_iwr_irqs[] = {IRQ_PROG0_INTB, IRQ_PROG1_INTB, IRQ_PROG2_INTB}; | ||
216 | #endif | ||
217 | #endif | ||
218 | #endif /* CONFIG_PM */ | ||
219 | |||
220 | inline int check_gpio(unsigned gpio) | 140 | inline int check_gpio(unsigned gpio) |
221 | { | 141 | { |
222 | #if defined(BF548_FAMILY) | 142 | #if defined(BF548_FAMILY) |
@@ -330,9 +250,10 @@ static struct { | |||
330 | {.res = P_SPI0_SSEL3, .offset = 0}, | 250 | {.res = P_SPI0_SSEL3, .offset = 0}, |
331 | }; | 251 | }; |
332 | 252 | ||
333 | static void portmux_setup(unsigned short per, unsigned short function) | 253 | static void portmux_setup(unsigned short per) |
334 | { | 254 | { |
335 | u16 y, offset, muxreg; | 255 | u16 y, offset, muxreg; |
256 | u16 function = P_FUNCT2MUX(per); | ||
336 | 257 | ||
337 | for (y = 0; y < ARRAY_SIZE(port_mux_lut); y++) { | 258 | for (y = 0; y < ARRAY_SIZE(port_mux_lut); y++) { |
338 | if (port_mux_lut[y].res == per) { | 259 | if (port_mux_lut[y].res == per) { |
@@ -353,30 +274,33 @@ static void portmux_setup(unsigned short per, unsigned short function) | |||
353 | } | 274 | } |
354 | } | 275 | } |
355 | #elif defined(BF548_FAMILY) | 276 | #elif defined(BF548_FAMILY) |
356 | inline void portmux_setup(unsigned short portno, unsigned short function) | 277 | inline void portmux_setup(unsigned short per) |
357 | { | 278 | { |
358 | u32 pmux; | 279 | u32 pmux; |
280 | u16 ident = P_IDENT(per); | ||
281 | u16 function = P_FUNCT2MUX(per); | ||
359 | 282 | ||
360 | pmux = gpio_array[gpio_bank(portno)]->port_mux; | 283 | pmux = gpio_array[gpio_bank(ident)]->port_mux; |
361 | 284 | ||
362 | pmux &= ~(0x3 << (2 * gpio_sub_n(portno))); | 285 | pmux &= ~(0x3 << (2 * gpio_sub_n(ident))); |
363 | pmux |= (function & 0x3) << (2 * gpio_sub_n(portno)); | 286 | pmux |= (function & 0x3) << (2 * gpio_sub_n(ident)); |
364 | 287 | ||
365 | gpio_array[gpio_bank(portno)]->port_mux = pmux; | 288 | gpio_array[gpio_bank(ident)]->port_mux = pmux; |
366 | } | 289 | } |
367 | 290 | ||
368 | inline u16 get_portmux(unsigned short portno) | 291 | inline u16 get_portmux(unsigned short per) |
369 | { | 292 | { |
370 | u32 pmux; | 293 | u32 pmux; |
294 | u16 ident = P_IDENT(per); | ||
371 | 295 | ||
372 | pmux = gpio_array[gpio_bank(portno)]->port_mux; | 296 | pmux = gpio_array[gpio_bank(ident)]->port_mux; |
373 | 297 | ||
374 | return (pmux >> (2 * gpio_sub_n(portno)) & 0x3); | 298 | return (pmux >> (2 * gpio_sub_n(ident)) & 0x3); |
375 | } | 299 | } |
376 | #elif defined(BF527_FAMILY) || defined(BF518_FAMILY) | 300 | #elif defined(BF527_FAMILY) || defined(BF518_FAMILY) |
377 | inline void portmux_setup(unsigned short portno, unsigned short function) | 301 | inline void portmux_setup(unsigned short per) |
378 | { | 302 | { |
379 | u16 pmux, ident = P_IDENT(portno); | 303 | u16 pmux, ident = P_IDENT(per), function = P_FUNCT2MUX(per); |
380 | u8 offset = pmux_offset[gpio_bank(ident)][gpio_sub_n(ident)]; | 304 | u8 offset = pmux_offset[gpio_bank(ident)][gpio_sub_n(ident)]; |
381 | 305 | ||
382 | pmux = *port_mux[gpio_bank(ident)]; | 306 | pmux = *port_mux[gpio_bank(ident)]; |
@@ -424,90 +348,71 @@ void set_gpio_ ## name(unsigned gpio, unsigned short arg) \ | |||
424 | unsigned long flags; \ | 348 | unsigned long flags; \ |
425 | local_irq_save_hw(flags); \ | 349 | local_irq_save_hw(flags); \ |
426 | if (arg) \ | 350 | if (arg) \ |
427 | gpio_bankb[gpio_bank(gpio)]->name |= gpio_bit(gpio); \ | 351 | gpio_array[gpio_bank(gpio)]->name |= gpio_bit(gpio); \ |
428 | else \ | 352 | else \ |
429 | gpio_bankb[gpio_bank(gpio)]->name &= ~gpio_bit(gpio); \ | 353 | gpio_array[gpio_bank(gpio)]->name &= ~gpio_bit(gpio); \ |
430 | AWA_DUMMY_READ(name); \ | 354 | AWA_DUMMY_READ(name); \ |
431 | local_irq_restore_hw(flags); \ | 355 | local_irq_restore_hw(flags); \ |
432 | } \ | 356 | } \ |
433 | EXPORT_SYMBOL(set_gpio_ ## name); | 357 | EXPORT_SYMBOL(set_gpio_ ## name); |
434 | 358 | ||
435 | SET_GPIO(dir) | 359 | SET_GPIO(dir) /* set_gpio_dir() */ |
436 | SET_GPIO(inen) | 360 | SET_GPIO(inen) /* set_gpio_inen() */ |
437 | SET_GPIO(polar) | 361 | SET_GPIO(polar) /* set_gpio_polar() */ |
438 | SET_GPIO(edge) | 362 | SET_GPIO(edge) /* set_gpio_edge() */ |
439 | SET_GPIO(both) | 363 | SET_GPIO(both) /* set_gpio_both() */ |
440 | 364 | ||
441 | 365 | ||
442 | #if ANOMALY_05000311 || ANOMALY_05000323 | ||
443 | #define SET_GPIO_SC(name) \ | 366 | #define SET_GPIO_SC(name) \ |
444 | void set_gpio_ ## name(unsigned gpio, unsigned short arg) \ | 367 | void set_gpio_ ## name(unsigned gpio, unsigned short arg) \ |
445 | { \ | 368 | { \ |
446 | unsigned long flags; \ | 369 | unsigned long flags; \ |
447 | local_irq_save_hw(flags); \ | 370 | if (ANOMALY_05000311 || ANOMALY_05000323) \ |
448 | if (arg) \ | 371 | local_irq_save_hw(flags); \ |
449 | gpio_bankb[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \ | ||
450 | else \ | ||
451 | gpio_bankb[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \ | ||
452 | AWA_DUMMY_READ(name); \ | ||
453 | local_irq_restore_hw(flags); \ | ||
454 | } \ | ||
455 | EXPORT_SYMBOL(set_gpio_ ## name); | ||
456 | #else | ||
457 | #define SET_GPIO_SC(name) \ | ||
458 | void set_gpio_ ## name(unsigned gpio, unsigned short arg) \ | ||
459 | { \ | ||
460 | if (arg) \ | 372 | if (arg) \ |
461 | gpio_bankb[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \ | 373 | gpio_array[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \ |
462 | else \ | 374 | else \ |
463 | gpio_bankb[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \ | 375 | gpio_array[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \ |
376 | if (ANOMALY_05000311 || ANOMALY_05000323) { \ | ||
377 | AWA_DUMMY_READ(name); \ | ||
378 | local_irq_restore_hw(flags); \ | ||
379 | } \ | ||
464 | } \ | 380 | } \ |
465 | EXPORT_SYMBOL(set_gpio_ ## name); | 381 | EXPORT_SYMBOL(set_gpio_ ## name); |
466 | #endif | ||
467 | 382 | ||
468 | SET_GPIO_SC(maska) | 383 | SET_GPIO_SC(maska) |
469 | SET_GPIO_SC(maskb) | 384 | SET_GPIO_SC(maskb) |
470 | SET_GPIO_SC(data) | 385 | SET_GPIO_SC(data) |
471 | 386 | ||
472 | #if ANOMALY_05000311 || ANOMALY_05000323 | ||
473 | void set_gpio_toggle(unsigned gpio) | 387 | void set_gpio_toggle(unsigned gpio) |
474 | { | 388 | { |
475 | unsigned long flags; | 389 | unsigned long flags; |
476 | local_irq_save_hw(flags); | 390 | if (ANOMALY_05000311 || ANOMALY_05000323) |
477 | gpio_bankb[gpio_bank(gpio)]->toggle = gpio_bit(gpio); | 391 | local_irq_save_hw(flags); |
478 | AWA_DUMMY_READ(toggle); | 392 | gpio_array[gpio_bank(gpio)]->toggle = gpio_bit(gpio); |
479 | local_irq_restore_hw(flags); | 393 | if (ANOMALY_05000311 || ANOMALY_05000323) { |
480 | } | 394 | AWA_DUMMY_READ(toggle); |
481 | #else | 395 | local_irq_restore_hw(flags); |
482 | void set_gpio_toggle(unsigned gpio) | 396 | } |
483 | { | ||
484 | gpio_bankb[gpio_bank(gpio)]->toggle = gpio_bit(gpio); | ||
485 | } | 397 | } |
486 | #endif | ||
487 | EXPORT_SYMBOL(set_gpio_toggle); | 398 | EXPORT_SYMBOL(set_gpio_toggle); |
488 | 399 | ||
489 | 400 | ||
490 | /*Set current PORT date (16-bit word)*/ | 401 | /*Set current PORT date (16-bit word)*/ |
491 | 402 | ||
492 | #if ANOMALY_05000311 || ANOMALY_05000323 | ||
493 | #define SET_GPIO_P(name) \ | 403 | #define SET_GPIO_P(name) \ |
494 | void set_gpiop_ ## name(unsigned gpio, unsigned short arg) \ | 404 | void set_gpiop_ ## name(unsigned gpio, unsigned short arg) \ |
495 | { \ | 405 | { \ |
496 | unsigned long flags; \ | 406 | unsigned long flags; \ |
497 | local_irq_save_hw(flags); \ | 407 | if (ANOMALY_05000311 || ANOMALY_05000323) \ |
498 | gpio_bankb[gpio_bank(gpio)]->name = arg; \ | 408 | local_irq_save_hw(flags); \ |
499 | AWA_DUMMY_READ(name); \ | 409 | gpio_array[gpio_bank(gpio)]->name = arg; \ |
500 | local_irq_restore_hw(flags); \ | 410 | if (ANOMALY_05000311 || ANOMALY_05000323) { \ |
411 | AWA_DUMMY_READ(name); \ | ||
412 | local_irq_restore_hw(flags); \ | ||
413 | } \ | ||
501 | } \ | 414 | } \ |
502 | EXPORT_SYMBOL(set_gpiop_ ## name); | 415 | EXPORT_SYMBOL(set_gpiop_ ## name); |
503 | #else | ||
504 | #define SET_GPIO_P(name) \ | ||
505 | void set_gpiop_ ## name(unsigned gpio, unsigned short arg) \ | ||
506 | { \ | ||
507 | gpio_bankb[gpio_bank(gpio)]->name = arg; \ | ||
508 | } \ | ||
509 | EXPORT_SYMBOL(set_gpiop_ ## name); | ||
510 | #endif | ||
511 | 416 | ||
512 | SET_GPIO_P(data) | 417 | SET_GPIO_P(data) |
513 | SET_GPIO_P(dir) | 418 | SET_GPIO_P(dir) |
@@ -519,27 +424,21 @@ SET_GPIO_P(maska) | |||
519 | SET_GPIO_P(maskb) | 424 | SET_GPIO_P(maskb) |
520 | 425 | ||
521 | /* Get a specific bit */ | 426 | /* Get a specific bit */ |
522 | #if ANOMALY_05000311 || ANOMALY_05000323 | ||
523 | #define GET_GPIO(name) \ | 427 | #define GET_GPIO(name) \ |
524 | unsigned short get_gpio_ ## name(unsigned gpio) \ | 428 | unsigned short get_gpio_ ## name(unsigned gpio) \ |
525 | { \ | 429 | { \ |
526 | unsigned long flags; \ | 430 | unsigned long flags; \ |
527 | unsigned short ret; \ | 431 | unsigned short ret; \ |
528 | local_irq_save_hw(flags); \ | 432 | if (ANOMALY_05000311 || ANOMALY_05000323) \ |
529 | ret = 0x01 & (gpio_bankb[gpio_bank(gpio)]->name >> gpio_sub_n(gpio)); \ | 433 | local_irq_save_hw(flags); \ |
530 | AWA_DUMMY_READ(name); \ | 434 | ret = 0x01 & (gpio_array[gpio_bank(gpio)]->name >> gpio_sub_n(gpio)); \ |
531 | local_irq_restore_hw(flags); \ | 435 | if (ANOMALY_05000311 || ANOMALY_05000323) { \ |
436 | AWA_DUMMY_READ(name); \ | ||
437 | local_irq_restore_hw(flags); \ | ||
438 | } \ | ||
532 | return ret; \ | 439 | return ret; \ |
533 | } \ | 440 | } \ |
534 | EXPORT_SYMBOL(get_gpio_ ## name); | 441 | EXPORT_SYMBOL(get_gpio_ ## name); |
535 | #else | ||
536 | #define GET_GPIO(name) \ | ||
537 | unsigned short get_gpio_ ## name(unsigned gpio) \ | ||
538 | { \ | ||
539 | return (0x01 & (gpio_bankb[gpio_bank(gpio)]->name >> gpio_sub_n(gpio))); \ | ||
540 | } \ | ||
541 | EXPORT_SYMBOL(get_gpio_ ## name); | ||
542 | #endif | ||
543 | 442 | ||
544 | GET_GPIO(data) | 443 | GET_GPIO(data) |
545 | GET_GPIO(dir) | 444 | GET_GPIO(dir) |
@@ -552,27 +451,21 @@ GET_GPIO(maskb) | |||
552 | 451 | ||
553 | /*Get current PORT date (16-bit word)*/ | 452 | /*Get current PORT date (16-bit word)*/ |
554 | 453 | ||
555 | #if ANOMALY_05000311 || ANOMALY_05000323 | ||
556 | #define GET_GPIO_P(name) \ | 454 | #define GET_GPIO_P(name) \ |
557 | unsigned short get_gpiop_ ## name(unsigned gpio) \ | 455 | unsigned short get_gpiop_ ## name(unsigned gpio) \ |
558 | { \ | 456 | { \ |
559 | unsigned long flags; \ | 457 | unsigned long flags; \ |
560 | unsigned short ret; \ | 458 | unsigned short ret; \ |
561 | local_irq_save_hw(flags); \ | 459 | if (ANOMALY_05000311 || ANOMALY_05000323) \ |
562 | ret = (gpio_bankb[gpio_bank(gpio)]->name); \ | 460 | local_irq_save_hw(flags); \ |
563 | AWA_DUMMY_READ(name); \ | 461 | ret = (gpio_array[gpio_bank(gpio)]->name); \ |
564 | local_irq_restore_hw(flags); \ | 462 | if (ANOMALY_05000311 || ANOMALY_05000323) { \ |
463 | AWA_DUMMY_READ(name); \ | ||
464 | local_irq_restore_hw(flags); \ | ||
465 | } \ | ||
565 | return ret; \ | 466 | return ret; \ |
566 | } \ | 467 | } \ |
567 | EXPORT_SYMBOL(get_gpiop_ ## name); | 468 | EXPORT_SYMBOL(get_gpiop_ ## name); |
568 | #else | ||
569 | #define GET_GPIO_P(name) \ | ||
570 | unsigned short get_gpiop_ ## name(unsigned gpio) \ | ||
571 | { \ | ||
572 | return (gpio_bankb[gpio_bank(gpio)]->name);\ | ||
573 | } \ | ||
574 | EXPORT_SYMBOL(get_gpiop_ ## name); | ||
575 | #endif | ||
576 | 469 | ||
577 | GET_GPIO_P(data) | 470 | GET_GPIO_P(data) |
578 | GET_GPIO_P(dir) | 471 | GET_GPIO_P(dir) |
@@ -585,6 +478,26 @@ GET_GPIO_P(maskb) | |||
585 | 478 | ||
586 | 479 | ||
587 | #ifdef CONFIG_PM | 480 | #ifdef CONFIG_PM |
481 | |||
482 | static unsigned short wakeup_map[GPIO_BANK_NUM]; | ||
483 | static unsigned char wakeup_flags_map[MAX_BLACKFIN_GPIOS]; | ||
484 | |||
485 | static const unsigned int sic_iwr_irqs[] = { | ||
486 | #if defined(BF533_FAMILY) | ||
487 | IRQ_PROG_INTB | ||
488 | #elif defined(BF537_FAMILY) | ||
489 | IRQ_PROG_INTB, IRQ_PORTG_INTB, IRQ_MAC_TX | ||
490 | #elif defined(BF538_FAMILY) | ||
491 | IRQ_PORTF_INTB | ||
492 | #elif defined(BF527_FAMILY) || defined(BF518_FAMILY) | ||
493 | IRQ_PORTF_INTB, IRQ_PORTG_INTB, IRQ_PORTH_INTB | ||
494 | #elif defined(BF561_FAMILY) | ||
495 | IRQ_PROG0_INTB, IRQ_PROG1_INTB, IRQ_PROG2_INTB | ||
496 | #else | ||
497 | # error no SIC_IWR defined | ||
498 | #endif | ||
499 | }; | ||
500 | |||
588 | /*********************************************************** | 501 | /*********************************************************** |
589 | * | 502 | * |
590 | * FUNCTIONS: Blackfin PM Setup API | 503 | * FUNCTIONS: Blackfin PM Setup API |
@@ -669,18 +582,18 @@ u32 bfin_pm_standby_setup(void) | |||
669 | mask = wakeup_map[gpio_bank(i)]; | 582 | mask = wakeup_map[gpio_bank(i)]; |
670 | bank = gpio_bank(i); | 583 | bank = gpio_bank(i); |
671 | 584 | ||
672 | gpio_bank_saved[bank].maskb = gpio_bankb[bank]->maskb; | 585 | gpio_bank_saved[bank].maskb = gpio_array[bank]->maskb; |
673 | gpio_bankb[bank]->maskb = 0; | 586 | gpio_array[bank]->maskb = 0; |
674 | 587 | ||
675 | if (mask) { | 588 | if (mask) { |
676 | #if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY) | 589 | #if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY) |
677 | gpio_bank_saved[bank].fer = *port_fer[bank]; | 590 | gpio_bank_saved[bank].fer = *port_fer[bank]; |
678 | #endif | 591 | #endif |
679 | gpio_bank_saved[bank].inen = gpio_bankb[bank]->inen; | 592 | gpio_bank_saved[bank].inen = gpio_array[bank]->inen; |
680 | gpio_bank_saved[bank].polar = gpio_bankb[bank]->polar; | 593 | gpio_bank_saved[bank].polar = gpio_array[bank]->polar; |
681 | gpio_bank_saved[bank].dir = gpio_bankb[bank]->dir; | 594 | gpio_bank_saved[bank].dir = gpio_array[bank]->dir; |
682 | gpio_bank_saved[bank].edge = gpio_bankb[bank]->edge; | 595 | gpio_bank_saved[bank].edge = gpio_array[bank]->edge; |
683 | gpio_bank_saved[bank].both = gpio_bankb[bank]->both; | 596 | gpio_bank_saved[bank].both = gpio_array[bank]->both; |
684 | gpio_bank_saved[bank].reserved = | 597 | gpio_bank_saved[bank].reserved = |
685 | reserved_gpio_map[bank]; | 598 | reserved_gpio_map[bank]; |
686 | 599 | ||
@@ -700,7 +613,7 @@ u32 bfin_pm_standby_setup(void) | |||
700 | } | 613 | } |
701 | 614 | ||
702 | bfin_internal_set_wake(sic_iwr_irqs[bank], 1); | 615 | bfin_internal_set_wake(sic_iwr_irqs[bank], 1); |
703 | gpio_bankb[bank]->maskb_set = wakeup_map[gpio_bank(i)]; | 616 | gpio_array[bank]->maskb_set = wakeup_map[gpio_bank(i)]; |
704 | } | 617 | } |
705 | } | 618 | } |
706 | 619 | ||
@@ -721,18 +634,18 @@ void bfin_pm_standby_restore(void) | |||
721 | #if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY) | 634 | #if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY) |
722 | *port_fer[bank] = gpio_bank_saved[bank].fer; | 635 | *port_fer[bank] = gpio_bank_saved[bank].fer; |
723 | #endif | 636 | #endif |
724 | gpio_bankb[bank]->inen = gpio_bank_saved[bank].inen; | 637 | gpio_array[bank]->inen = gpio_bank_saved[bank].inen; |
725 | gpio_bankb[bank]->dir = gpio_bank_saved[bank].dir; | 638 | gpio_array[bank]->dir = gpio_bank_saved[bank].dir; |
726 | gpio_bankb[bank]->polar = gpio_bank_saved[bank].polar; | 639 | gpio_array[bank]->polar = gpio_bank_saved[bank].polar; |
727 | gpio_bankb[bank]->edge = gpio_bank_saved[bank].edge; | 640 | gpio_array[bank]->edge = gpio_bank_saved[bank].edge; |
728 | gpio_bankb[bank]->both = gpio_bank_saved[bank].both; | 641 | gpio_array[bank]->both = gpio_bank_saved[bank].both; |
729 | 642 | ||
730 | reserved_gpio_map[bank] = | 643 | reserved_gpio_map[bank] = |
731 | gpio_bank_saved[bank].reserved; | 644 | gpio_bank_saved[bank].reserved; |
732 | bfin_internal_set_wake(sic_iwr_irqs[bank], 0); | 645 | bfin_internal_set_wake(sic_iwr_irqs[bank], 0); |
733 | } | 646 | } |
734 | 647 | ||
735 | gpio_bankb[bank]->maskb = gpio_bank_saved[bank].maskb; | 648 | gpio_array[bank]->maskb = gpio_bank_saved[bank].maskb; |
736 | } | 649 | } |
737 | AWA_DUMMY_READ(maskb); | 650 | AWA_DUMMY_READ(maskb); |
738 | } | 651 | } |
@@ -745,21 +658,21 @@ void bfin_gpio_pm_hibernate_suspend(void) | |||
745 | bank = gpio_bank(i); | 658 | bank = gpio_bank(i); |
746 | 659 | ||
747 | #if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY) | 660 | #if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY) |
748 | gpio_bank_saved[bank].fer = *port_fer[bank]; | 661 | gpio_bank_saved[bank].fer = *port_fer[bank]; |
749 | #if defined(BF527_FAMILY) || defined(BF518_FAMILY) | 662 | #if defined(BF527_FAMILY) || defined(BF518_FAMILY) |
750 | gpio_bank_saved[bank].mux = *port_mux[bank]; | 663 | gpio_bank_saved[bank].mux = *port_mux[bank]; |
751 | #else | 664 | #else |
752 | if (bank == 0) | 665 | if (bank == 0) |
753 | gpio_bank_saved[bank].mux = bfin_read_PORT_MUX(); | 666 | gpio_bank_saved[bank].mux = bfin_read_PORT_MUX(); |
754 | #endif | 667 | #endif |
755 | #endif | 668 | #endif |
756 | gpio_bank_saved[bank].data = gpio_bankb[bank]->data; | 669 | gpio_bank_saved[bank].data = gpio_array[bank]->data; |
757 | gpio_bank_saved[bank].inen = gpio_bankb[bank]->inen; | 670 | gpio_bank_saved[bank].inen = gpio_array[bank]->inen; |
758 | gpio_bank_saved[bank].polar = gpio_bankb[bank]->polar; | 671 | gpio_bank_saved[bank].polar = gpio_array[bank]->polar; |
759 | gpio_bank_saved[bank].dir = gpio_bankb[bank]->dir; | 672 | gpio_bank_saved[bank].dir = gpio_array[bank]->dir; |
760 | gpio_bank_saved[bank].edge = gpio_bankb[bank]->edge; | 673 | gpio_bank_saved[bank].edge = gpio_array[bank]->edge; |
761 | gpio_bank_saved[bank].both = gpio_bankb[bank]->both; | 674 | gpio_bank_saved[bank].both = gpio_array[bank]->both; |
762 | gpio_bank_saved[bank].maska = gpio_bankb[bank]->maska; | 675 | gpio_bank_saved[bank].maska = gpio_array[bank]->maska; |
763 | } | 676 | } |
764 | 677 | ||
765 | AWA_DUMMY_READ(maska); | 678 | AWA_DUMMY_READ(maska); |
@@ -770,27 +683,27 @@ void bfin_gpio_pm_hibernate_restore(void) | |||
770 | int i, bank; | 683 | int i, bank; |
771 | 684 | ||
772 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { | 685 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { |
773 | bank = gpio_bank(i); | 686 | bank = gpio_bank(i); |
774 | 687 | ||
775 | #if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY) | 688 | #if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY) |
776 | #if defined(BF527_FAMILY) || defined(BF518_FAMILY) | 689 | #if defined(BF527_FAMILY) || defined(BF518_FAMILY) |
777 | *port_mux[bank] = gpio_bank_saved[bank].mux; | 690 | *port_mux[bank] = gpio_bank_saved[bank].mux; |
778 | #else | 691 | #else |
779 | if (bank == 0) | 692 | if (bank == 0) |
780 | bfin_write_PORT_MUX(gpio_bank_saved[bank].mux); | 693 | bfin_write_PORT_MUX(gpio_bank_saved[bank].mux); |
781 | #endif | 694 | #endif |
782 | *port_fer[bank] = gpio_bank_saved[bank].fer; | 695 | *port_fer[bank] = gpio_bank_saved[bank].fer; |
783 | #endif | 696 | #endif |
784 | gpio_bankb[bank]->inen = gpio_bank_saved[bank].inen; | 697 | gpio_array[bank]->inen = gpio_bank_saved[bank].inen; |
785 | gpio_bankb[bank]->dir = gpio_bank_saved[bank].dir; | 698 | gpio_array[bank]->dir = gpio_bank_saved[bank].dir; |
786 | gpio_bankb[bank]->polar = gpio_bank_saved[bank].polar; | 699 | gpio_array[bank]->polar = gpio_bank_saved[bank].polar; |
787 | gpio_bankb[bank]->edge = gpio_bank_saved[bank].edge; | 700 | gpio_array[bank]->edge = gpio_bank_saved[bank].edge; |
788 | gpio_bankb[bank]->both = gpio_bank_saved[bank].both; | 701 | gpio_array[bank]->both = gpio_bank_saved[bank].both; |
789 | 702 | ||
790 | gpio_bankb[bank]->data_set = gpio_bank_saved[bank].data | 703 | gpio_array[bank]->data_set = gpio_bank_saved[bank].data |
791 | | gpio_bank_saved[bank].dir; | 704 | | gpio_bank_saved[bank].dir; |
792 | 705 | ||
793 | gpio_bankb[bank]->maska = gpio_bank_saved[bank].maska; | 706 | gpio_array[bank]->maska = gpio_bank_saved[bank].maska; |
794 | } | 707 | } |
795 | AWA_DUMMY_READ(maska); | 708 | AWA_DUMMY_READ(maska); |
796 | } | 709 | } |
@@ -817,12 +730,12 @@ void bfin_gpio_pm_hibernate_suspend(void) | |||
817 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { | 730 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { |
818 | bank = gpio_bank(i); | 731 | bank = gpio_bank(i); |
819 | 732 | ||
820 | gpio_bank_saved[bank].fer = gpio_array[bank]->port_fer; | 733 | gpio_bank_saved[bank].fer = gpio_array[bank]->port_fer; |
821 | gpio_bank_saved[bank].mux = gpio_array[bank]->port_mux; | 734 | gpio_bank_saved[bank].mux = gpio_array[bank]->port_mux; |
822 | gpio_bank_saved[bank].data = gpio_array[bank]->port_data; | 735 | gpio_bank_saved[bank].data = gpio_array[bank]->data; |
823 | gpio_bank_saved[bank].data = gpio_array[bank]->port_data; | 736 | gpio_bank_saved[bank].data = gpio_array[bank]->data; |
824 | gpio_bank_saved[bank].inen = gpio_array[bank]->port_inen; | 737 | gpio_bank_saved[bank].inen = gpio_array[bank]->inen; |
825 | gpio_bank_saved[bank].dir = gpio_array[bank]->port_dir_set; | 738 | gpio_bank_saved[bank].dir = gpio_array[bank]->dir_set; |
826 | } | 739 | } |
827 | } | 740 | } |
828 | 741 | ||
@@ -831,21 +744,21 @@ void bfin_gpio_pm_hibernate_restore(void) | |||
831 | int i, bank; | 744 | int i, bank; |
832 | 745 | ||
833 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { | 746 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { |
834 | bank = gpio_bank(i); | 747 | bank = gpio_bank(i); |
835 | 748 | ||
836 | gpio_array[bank]->port_mux = gpio_bank_saved[bank].mux; | 749 | gpio_array[bank]->port_mux = gpio_bank_saved[bank].mux; |
837 | gpio_array[bank]->port_fer = gpio_bank_saved[bank].fer; | 750 | gpio_array[bank]->port_fer = gpio_bank_saved[bank].fer; |
838 | gpio_array[bank]->port_inen = gpio_bank_saved[bank].inen; | 751 | gpio_array[bank]->inen = gpio_bank_saved[bank].inen; |
839 | gpio_array[bank]->port_dir_set = gpio_bank_saved[bank].dir; | 752 | gpio_array[bank]->dir_set = gpio_bank_saved[bank].dir; |
840 | gpio_array[bank]->port_set = gpio_bank_saved[bank].data | 753 | gpio_array[bank]->data_set = gpio_bank_saved[bank].data |
841 | | gpio_bank_saved[bank].dir; | 754 | | gpio_bank_saved[bank].dir; |
842 | } | 755 | } |
843 | } | 756 | } |
844 | #endif | 757 | #endif |
845 | 758 | ||
846 | unsigned short get_gpio_dir(unsigned gpio) | 759 | unsigned short get_gpio_dir(unsigned gpio) |
847 | { | 760 | { |
848 | return (0x01 & (gpio_array[gpio_bank(gpio)]->port_dir_clear >> gpio_sub_n(gpio))); | 761 | return (0x01 & (gpio_array[gpio_bank(gpio)]->dir_clear >> gpio_sub_n(gpio))); |
849 | } | 762 | } |
850 | EXPORT_SYMBOL(get_gpio_dir); | 763 | EXPORT_SYMBOL(get_gpio_dir); |
851 | 764 | ||
@@ -905,9 +818,7 @@ int peripheral_request(unsigned short per, const char *label) | |||
905 | */ | 818 | */ |
906 | 819 | ||
907 | #ifdef BF548_FAMILY | 820 | #ifdef BF548_FAMILY |
908 | u16 funct = get_portmux(ident); | 821 | if (!((per & P_MAYSHARE) && get_portmux(per) == P_FUNCT2MUX(per))) { |
909 | |||
910 | if (!((per & P_MAYSHARE) && (funct == P_FUNCT2MUX(per)))) { | ||
911 | #else | 822 | #else |
912 | if (!(per & P_MAYSHARE)) { | 823 | if (!(per & P_MAYSHARE)) { |
913 | #endif | 824 | #endif |
@@ -931,11 +842,7 @@ int peripheral_request(unsigned short per, const char *label) | |||
931 | anyway: | 842 | anyway: |
932 | reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident); | 843 | reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident); |
933 | 844 | ||
934 | #ifdef BF548_FAMILY | 845 | portmux_setup(per); |
935 | portmux_setup(ident, P_FUNCT2MUX(per)); | ||
936 | #else | ||
937 | portmux_setup(per, P_FUNCT2MUX(per)); | ||
938 | #endif | ||
939 | port_setup(ident, PERIPHERAL_USAGE); | 846 | port_setup(ident, PERIPHERAL_USAGE); |
940 | 847 | ||
941 | local_irq_restore_hw(flags); | 848 | local_irq_restore_hw(flags); |
@@ -977,9 +884,6 @@ void peripheral_free(unsigned short per) | |||
977 | if (!(per & P_DEFINED)) | 884 | if (!(per & P_DEFINED)) |
978 | return; | 885 | return; |
979 | 886 | ||
980 | if (check_gpio(ident) < 0) | ||
981 | return; | ||
982 | |||
983 | local_irq_save_hw(flags); | 887 | local_irq_save_hw(flags); |
984 | 888 | ||
985 | if (unlikely(!(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident)))) { | 889 | if (unlikely(!(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident)))) { |
@@ -1056,9 +960,15 @@ int bfin_gpio_request(unsigned gpio, const char *label) | |||
1056 | local_irq_restore_hw(flags); | 960 | local_irq_restore_hw(flags); |
1057 | return -EBUSY; | 961 | return -EBUSY; |
1058 | } | 962 | } |
1059 | if (unlikely(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio))) | 963 | if (unlikely(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio))) { |
1060 | printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved as gpio-irq!" | 964 | printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved as gpio-irq!" |
1061 | " (Documentation/blackfin/bfin-gpio-notes.txt)\n", gpio); | 965 | " (Documentation/blackfin/bfin-gpio-notes.txt)\n", gpio); |
966 | } | ||
967 | #ifndef BF548_FAMILY | ||
968 | else { /* Reset POLAR setting when acquiring a gpio for the first time */ | ||
969 | set_gpio_polar(gpio, 0); | ||
970 | } | ||
971 | #endif | ||
1062 | 972 | ||
1063 | reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio); | 973 | reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio); |
1064 | set_label(gpio, label); | 974 | set_label(gpio, label); |
@@ -1078,6 +988,8 @@ void bfin_gpio_free(unsigned gpio) | |||
1078 | if (check_gpio(gpio) < 0) | 988 | if (check_gpio(gpio) < 0) |
1079 | return; | 989 | return; |
1080 | 990 | ||
991 | might_sleep(); | ||
992 | |||
1081 | local_irq_save_hw(flags); | 993 | local_irq_save_hw(flags); |
1082 | 994 | ||
1083 | if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) { | 995 | if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) { |
@@ -1158,8 +1070,16 @@ void bfin_gpio_irq_free(unsigned gpio) | |||
1158 | local_irq_restore_hw(flags); | 1070 | local_irq_restore_hw(flags); |
1159 | } | 1071 | } |
1160 | 1072 | ||
1161 | 1073 | static inline void __bfin_gpio_direction_input(unsigned gpio) | |
1074 | { | ||
1162 | #ifdef BF548_FAMILY | 1075 | #ifdef BF548_FAMILY |
1076 | gpio_array[gpio_bank(gpio)]->dir_clear = gpio_bit(gpio); | ||
1077 | #else | ||
1078 | gpio_array[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio); | ||
1079 | #endif | ||
1080 | gpio_array[gpio_bank(gpio)]->inen |= gpio_bit(gpio); | ||
1081 | } | ||
1082 | |||
1163 | int bfin_gpio_direction_input(unsigned gpio) | 1083 | int bfin_gpio_direction_input(unsigned gpio) |
1164 | { | 1084 | { |
1165 | unsigned long flags; | 1085 | unsigned long flags; |
@@ -1170,125 +1090,85 @@ int bfin_gpio_direction_input(unsigned gpio) | |||
1170 | } | 1090 | } |
1171 | 1091 | ||
1172 | local_irq_save_hw(flags); | 1092 | local_irq_save_hw(flags); |
1173 | gpio_array[gpio_bank(gpio)]->port_dir_clear = gpio_bit(gpio); | 1093 | __bfin_gpio_direction_input(gpio); |
1174 | gpio_array[gpio_bank(gpio)]->port_inen |= gpio_bit(gpio); | 1094 | AWA_DUMMY_READ(inen); |
1175 | local_irq_restore_hw(flags); | 1095 | local_irq_restore_hw(flags); |
1176 | 1096 | ||
1177 | return 0; | 1097 | return 0; |
1178 | } | 1098 | } |
1179 | EXPORT_SYMBOL(bfin_gpio_direction_input); | 1099 | EXPORT_SYMBOL(bfin_gpio_direction_input); |
1180 | 1100 | ||
1181 | int bfin_gpio_direction_output(unsigned gpio, int value) | 1101 | void bfin_gpio_irq_prepare(unsigned gpio) |
1182 | { | 1102 | { |
1103 | #ifdef BF548_FAMILY | ||
1183 | unsigned long flags; | 1104 | unsigned long flags; |
1105 | #endif | ||
1184 | 1106 | ||
1185 | if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { | 1107 | port_setup(gpio, GPIO_USAGE); |
1186 | gpio_error(gpio); | ||
1187 | return -EINVAL; | ||
1188 | } | ||
1189 | 1108 | ||
1109 | #ifdef BF548_FAMILY | ||
1190 | local_irq_save_hw(flags); | 1110 | local_irq_save_hw(flags); |
1191 | gpio_array[gpio_bank(gpio)]->port_inen &= ~gpio_bit(gpio); | 1111 | __bfin_gpio_direction_input(gpio); |
1192 | gpio_set_value(gpio, value); | ||
1193 | gpio_array[gpio_bank(gpio)]->port_dir_set = gpio_bit(gpio); | ||
1194 | local_irq_restore_hw(flags); | 1112 | local_irq_restore_hw(flags); |
1195 | 1113 | #endif | |
1196 | return 0; | ||
1197 | } | 1114 | } |
1198 | EXPORT_SYMBOL(bfin_gpio_direction_output); | ||
1199 | 1115 | ||
1200 | void bfin_gpio_set_value(unsigned gpio, int arg) | 1116 | void bfin_gpio_set_value(unsigned gpio, int arg) |
1201 | { | 1117 | { |
1202 | if (arg) | 1118 | if (arg) |
1203 | gpio_array[gpio_bank(gpio)]->port_set = gpio_bit(gpio); | 1119 | gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio); |
1204 | else | 1120 | else |
1205 | gpio_array[gpio_bank(gpio)]->port_clear = gpio_bit(gpio); | 1121 | gpio_array[gpio_bank(gpio)]->data_clear = gpio_bit(gpio); |
1206 | } | 1122 | } |
1207 | EXPORT_SYMBOL(bfin_gpio_set_value); | 1123 | EXPORT_SYMBOL(bfin_gpio_set_value); |
1208 | 1124 | ||
1209 | int bfin_gpio_get_value(unsigned gpio) | 1125 | int bfin_gpio_direction_output(unsigned gpio, int value) |
1210 | { | ||
1211 | return (1 & (gpio_array[gpio_bank(gpio)]->port_data >> gpio_sub_n(gpio))); | ||
1212 | } | ||
1213 | EXPORT_SYMBOL(bfin_gpio_get_value); | ||
1214 | |||
1215 | void bfin_gpio_irq_prepare(unsigned gpio) | ||
1216 | { | 1126 | { |
1217 | unsigned long flags; | 1127 | unsigned long flags; |
1218 | 1128 | ||
1219 | port_setup(gpio, GPIO_USAGE); | 1129 | if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { |
1130 | gpio_error(gpio); | ||
1131 | return -EINVAL; | ||
1132 | } | ||
1220 | 1133 | ||
1221 | local_irq_save_hw(flags); | 1134 | local_irq_save_hw(flags); |
1222 | gpio_array[gpio_bank(gpio)]->port_dir_clear = gpio_bit(gpio); | ||
1223 | gpio_array[gpio_bank(gpio)]->port_inen |= gpio_bit(gpio); | ||
1224 | local_irq_restore_hw(flags); | ||
1225 | } | ||
1226 | 1135 | ||
1136 | gpio_array[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio); | ||
1137 | gpio_set_value(gpio, value); | ||
1138 | #ifdef BF548_FAMILY | ||
1139 | gpio_array[gpio_bank(gpio)]->dir_set = gpio_bit(gpio); | ||
1227 | #else | 1140 | #else |
1141 | gpio_array[gpio_bank(gpio)]->dir |= gpio_bit(gpio); | ||
1142 | #endif | ||
1143 | |||
1144 | AWA_DUMMY_READ(dir); | ||
1145 | local_irq_restore_hw(flags); | ||
1146 | |||
1147 | return 0; | ||
1148 | } | ||
1149 | EXPORT_SYMBOL(bfin_gpio_direction_output); | ||
1228 | 1150 | ||
1229 | int bfin_gpio_get_value(unsigned gpio) | 1151 | int bfin_gpio_get_value(unsigned gpio) |
1230 | { | 1152 | { |
1153 | #ifdef BF548_FAMILY | ||
1154 | return (1 & (gpio_array[gpio_bank(gpio)]->data >> gpio_sub_n(gpio))); | ||
1155 | #else | ||
1231 | unsigned long flags; | 1156 | unsigned long flags; |
1232 | int ret; | ||
1233 | 1157 | ||
1234 | if (unlikely(get_gpio_edge(gpio))) { | 1158 | if (unlikely(get_gpio_edge(gpio))) { |
1159 | int ret; | ||
1235 | local_irq_save_hw(flags); | 1160 | local_irq_save_hw(flags); |
1236 | set_gpio_edge(gpio, 0); | 1161 | set_gpio_edge(gpio, 0); |
1237 | ret = get_gpio_data(gpio); | 1162 | ret = get_gpio_data(gpio); |
1238 | set_gpio_edge(gpio, 1); | 1163 | set_gpio_edge(gpio, 1); |
1239 | local_irq_restore_hw(flags); | 1164 | local_irq_restore_hw(flags); |
1240 | |||
1241 | return ret; | 1165 | return ret; |
1242 | } else | 1166 | } else |
1243 | return get_gpio_data(gpio); | 1167 | return get_gpio_data(gpio); |
1168 | #endif | ||
1244 | } | 1169 | } |
1245 | EXPORT_SYMBOL(bfin_gpio_get_value); | 1170 | EXPORT_SYMBOL(bfin_gpio_get_value); |
1246 | 1171 | ||
1247 | |||
1248 | int bfin_gpio_direction_input(unsigned gpio) | ||
1249 | { | ||
1250 | unsigned long flags; | ||
1251 | |||
1252 | if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { | ||
1253 | gpio_error(gpio); | ||
1254 | return -EINVAL; | ||
1255 | } | ||
1256 | |||
1257 | local_irq_save_hw(flags); | ||
1258 | gpio_bankb[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio); | ||
1259 | gpio_bankb[gpio_bank(gpio)]->inen |= gpio_bit(gpio); | ||
1260 | AWA_DUMMY_READ(inen); | ||
1261 | local_irq_restore_hw(flags); | ||
1262 | |||
1263 | return 0; | ||
1264 | } | ||
1265 | EXPORT_SYMBOL(bfin_gpio_direction_input); | ||
1266 | |||
1267 | int bfin_gpio_direction_output(unsigned gpio, int value) | ||
1268 | { | ||
1269 | unsigned long flags; | ||
1270 | |||
1271 | if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { | ||
1272 | gpio_error(gpio); | ||
1273 | return -EINVAL; | ||
1274 | } | ||
1275 | |||
1276 | local_irq_save_hw(flags); | ||
1277 | gpio_bankb[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio); | ||
1278 | |||
1279 | if (value) | ||
1280 | gpio_bankb[gpio_bank(gpio)]->data_set = gpio_bit(gpio); | ||
1281 | else | ||
1282 | gpio_bankb[gpio_bank(gpio)]->data_clear = gpio_bit(gpio); | ||
1283 | |||
1284 | gpio_bankb[gpio_bank(gpio)]->dir |= gpio_bit(gpio); | ||
1285 | AWA_DUMMY_READ(dir); | ||
1286 | local_irq_restore_hw(flags); | ||
1287 | |||
1288 | return 0; | ||
1289 | } | ||
1290 | EXPORT_SYMBOL(bfin_gpio_direction_output); | ||
1291 | |||
1292 | /* If we are booting from SPI and our board lacks a strong enough pull up, | 1172 | /* If we are booting from SPI and our board lacks a strong enough pull up, |
1293 | * the core can reset and execute the bootrom faster than the resistor can | 1173 | * the core can reset and execute the bootrom faster than the resistor can |
1294 | * pull the signal logically high. To work around this (common) error in | 1174 | * pull the signal logically high. To work around this (common) error in |
@@ -1299,23 +1179,15 @@ EXPORT_SYMBOL(bfin_gpio_direction_output); | |||
1299 | * lives here as we need to force all the GPIO states w/out going through | 1179 | * lives here as we need to force all the GPIO states w/out going through |
1300 | * BUG() checks and such. | 1180 | * BUG() checks and such. |
1301 | */ | 1181 | */ |
1302 | void bfin_gpio_reset_spi0_ssel1(void) | 1182 | void bfin_reset_boot_spi_cs(unsigned short pin) |
1303 | { | 1183 | { |
1304 | u16 gpio = P_IDENT(P_SPI0_SSEL1); | 1184 | unsigned short gpio = P_IDENT(pin); |
1305 | |||
1306 | port_setup(gpio, GPIO_USAGE); | 1185 | port_setup(gpio, GPIO_USAGE); |
1307 | gpio_bankb[gpio_bank(gpio)]->data_set = gpio_bit(gpio); | 1186 | gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio); |
1308 | AWA_DUMMY_READ(data_set); | 1187 | AWA_DUMMY_READ(data_set); |
1309 | udelay(1); | 1188 | udelay(1); |
1310 | } | 1189 | } |
1311 | 1190 | ||
1312 | void bfin_gpio_irq_prepare(unsigned gpio) | ||
1313 | { | ||
1314 | port_setup(gpio, GPIO_USAGE); | ||
1315 | } | ||
1316 | |||
1317 | #endif /*BF548_FAMILY */ | ||
1318 | |||
1319 | #if defined(CONFIG_PROC_FS) | 1191 | #if defined(CONFIG_PROC_FS) |
1320 | static int gpio_proc_read(char *buf, char **start, off_t offset, | 1192 | static int gpio_proc_read(char *buf, char **start, off_t offset, |
1321 | int len, int *unused_i, void *unused_v) | 1193 | int len, int *unused_i, void *unused_v) |
@@ -1369,11 +1241,7 @@ int bfin_gpiolib_get_value(struct gpio_chip *chip, unsigned gpio) | |||
1369 | 1241 | ||
1370 | void bfin_gpiolib_set_value(struct gpio_chip *chip, unsigned gpio, int value) | 1242 | void bfin_gpiolib_set_value(struct gpio_chip *chip, unsigned gpio, int value) |
1371 | { | 1243 | { |
1372 | #ifdef BF548_FAMILY | ||
1373 | return bfin_gpio_set_value(gpio, value); | 1244 | return bfin_gpio_set_value(gpio, value); |
1374 | #else | ||
1375 | return set_gpio_data(gpio, value); | ||
1376 | #endif | ||
1377 | } | 1245 | } |
1378 | 1246 | ||
1379 | int bfin_gpiolib_gpio_request(struct gpio_chip *chip, unsigned gpio) | 1247 | int bfin_gpiolib_gpio_request(struct gpio_chip *chip, unsigned gpio) |