2 * GPIO Abstraction Layer
4 * Copyright 2006-2010 Analog Devices Inc.
6 * Licensed under the GPL-2 or later
10 #include <asm/errno.h>
12 #include <asm/portmux.h>
14 #if ANOMALY_05000311 || ANOMALY_05000323
17 AWA_data_clear = SYSCR,
21 AWA_maska_clear = UART_SCR,
22 AWA_maska_set = UART_SCR,
23 AWA_maska_toggle = UART_SCR,
24 AWA_maskb = UART_GCTL,
25 AWA_maskb_clear = UART_GCTL,
26 AWA_maskb_set = UART_GCTL,
27 AWA_maskb_toggle = UART_GCTL,
28 AWA_dir = SPORT1_STAT,
29 AWA_polar = SPORT1_STAT,
30 AWA_edge = SPORT1_STAT,
31 AWA_both = SPORT1_STAT,
33 AWA_inen = TIMER_ENABLE,
34 #elif ANOMALY_05000323
35 AWA_inen = DMA1_1_CONFIG,
38 /* Anomaly Workaround */
39 #define AWA_DUMMY_READ(name) bfin_read16(AWA_ ## name)
41 #define AWA_DUMMY_READ(...) do { } while (0)
44 static struct gpio_port_t * const gpio_array[] = {
45 #if defined(BF533_FAMILY)
46 (struct gpio_port_t *) FIO_FLAG_D,
47 #elif defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x) \
48 || defined(BF538_FAMILY) || defined(CONFIG_BF50x)
49 (struct gpio_port_t *) PORTFIO,
50 # if !defined(BF538_FAMILY)
51 (struct gpio_port_t *) PORTGIO,
52 (struct gpio_port_t *) PORTHIO,
54 #elif defined(BF561_FAMILY)
55 (struct gpio_port_t *) FIO0_FLAG_D,
56 (struct gpio_port_t *) FIO1_FLAG_D,
57 (struct gpio_port_t *) FIO2_FLAG_D,
58 #elif defined(CONFIG_BF54x)
59 (struct gpio_port_t *)PORTA_FER,
60 (struct gpio_port_t *)PORTB_FER,
61 (struct gpio_port_t *)PORTC_FER,
62 (struct gpio_port_t *)PORTD_FER,
63 (struct gpio_port_t *)PORTE_FER,
64 (struct gpio_port_t *)PORTF_FER,
65 (struct gpio_port_t *)PORTG_FER,
66 (struct gpio_port_t *)PORTH_FER,
67 (struct gpio_port_t *)PORTI_FER,
68 (struct gpio_port_t *)PORTJ_FER,
69 #elif defined(CONFIG_BF60x)
70 (struct gpio_port_t *)PORTA_FER,
71 (struct gpio_port_t *)PORTB_FER,
72 (struct gpio_port_t *)PORTC_FER,
73 (struct gpio_port_t *)PORTD_FER,
74 (struct gpio_port_t *)PORTE_FER,
75 (struct gpio_port_t *)PORTF_FER,
76 (struct gpio_port_t *)PORTG_FER,
78 # error no gpio arrays defined
82 #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x) || \
84 static unsigned short * const port_fer[] = {
85 (unsigned short *) PORTF_FER,
86 (unsigned short *) PORTG_FER,
87 (unsigned short *) PORTH_FER,
90 # if !defined(BF537_FAMILY)
91 static unsigned short * const port_mux[] = {
92 (unsigned short *) PORTF_MUX,
93 (unsigned short *) PORTG_MUX,
94 (unsigned short *) PORTH_MUX,
98 u8 pmux_offset[][16] = {
99 # if defined(CONFIG_BF52x)
100 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 4, 6, 8, 8, 10, 10 }, /* PORTF */
101 { 0, 0, 0, 0, 0, 2, 2, 4, 4, 6, 8, 10, 10, 10, 12, 12 }, /* PORTG */
102 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4 }, /* PORTH */
103 # elif defined(CONFIG_BF51x)
104 { 0, 2, 2, 2, 2, 2, 2, 4, 6, 6, 6, 8, 8, 8, 8, 10 }, /* PORTF */
105 { 0, 0, 0, 2, 4, 6, 6, 6, 8, 10, 10, 12, 14, 14, 14, 14 }, /* PORTG */
106 { 0, 0, 0, 0, 2, 2, 4, 6, 10, 10, 10, 10, 10, 10, 10, 10 }, /* PORTH */
111 #elif defined(BF538_FAMILY)
112 static unsigned short * const port_fer[] = {
113 (unsigned short *) PORTCIO_FER,
114 (unsigned short *) PORTDIO_FER,
115 (unsigned short *) PORTEIO_FER,
119 #ifdef CONFIG_BFIN_GPIO_TRACK
120 #define RESOURCE_LABEL_SIZE 16
122 static struct str_ident {
123 char name[RESOURCE_LABEL_SIZE];
124 } str_ident[MAX_RESOURCES];
126 static void gpio_error(unsigned gpio)
128 printf("bfin-gpio: GPIO %d wasn't requested!\n", gpio);
131 static void set_label(unsigned short ident, const char *label)
134 strncpy(str_ident[ident].name, label,
135 RESOURCE_LABEL_SIZE);
136 str_ident[ident].name[RESOURCE_LABEL_SIZE - 1] = 0;
140 static char *get_label(unsigned short ident)
142 return (*str_ident[ident].name ? str_ident[ident].name : "UNKNOWN");
145 static int cmp_label(unsigned short ident, const char *label)
148 printf("bfin-gpio: please provide none-null label\n");
151 return strcmp(str_ident[ident].name, label);
156 #define map_entry(m, i) reserved_##m##_map[gpio_bank(i)]
157 #define is_reserved(m, i, e) (map_entry(m, i) & gpio_bit(i))
158 #define reserve(m, i) (map_entry(m, i) |= gpio_bit(i))
159 #define unreserve(m, i) (map_entry(m, i) &= ~gpio_bit(i))
160 #define DECLARE_RESERVED_MAP(m, c) static unsigned short reserved_##m##_map[c]
162 #define is_reserved(m, i, e) (!(e))
163 #define reserve(m, i)
164 #define unreserve(m, i)
165 #define DECLARE_RESERVED_MAP(m, c)
166 #define gpio_error(gpio)
167 #define set_label(...)
168 #define get_label(...) ""
169 #define cmp_label(...) 1
172 DECLARE_RESERVED_MAP(gpio, GPIO_BANK_NUM);
173 DECLARE_RESERVED_MAP(peri, gpio_bank(MAX_RESOURCES));
175 inline int check_gpio(unsigned gpio)
177 #if defined(CONFIG_BF54x)
178 if (gpio == GPIO_PB15 || gpio == GPIO_PC14 || gpio == GPIO_PC15
179 || gpio == GPIO_PH14 || gpio == GPIO_PH15
180 || gpio == GPIO_PJ14 || gpio == GPIO_PJ15)
183 if (gpio >= MAX_BLACKFIN_GPIOS)
188 static void port_setup(unsigned gpio, unsigned short usage)
190 #if defined(BF538_FAMILY)
192 * BF538/9 Port C,D and E are special.
193 * Inverted PORT_FER polarity on CDE and no PORF_FER on F
194 * Regular PORT F GPIOs are handled here, CDE are exclusively
198 if (gpio < MAX_BLACKFIN_GPIOS || gpio >= MAX_RESOURCES)
201 gpio -= MAX_BLACKFIN_GPIOS;
203 if (usage == GPIO_USAGE)
204 *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio);
206 *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio);
211 if (check_gpio(gpio))
214 #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x) || \
215 defined(CONFIG_BF50x)
216 if (usage == GPIO_USAGE)
217 *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio);
219 *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio);
221 #elif defined(CONFIG_BF54x)
222 if (usage == GPIO_USAGE)
223 gpio_array[gpio_bank(gpio)]->port_fer &= ~gpio_bit(gpio);
225 gpio_array[gpio_bank(gpio)]->port_fer |= gpio_bit(gpio);
227 #elif defined(CONFIG_BF60x)
228 if (usage == GPIO_USAGE)
229 gpio_array[gpio_bank(gpio)]->port_fer_clear = gpio_bit(gpio);
231 gpio_array[gpio_bank(gpio)]->port_fer_set = gpio_bit(gpio);
239 unsigned short offset;
241 {.res = P_PPI0_D13, .offset = 11},
242 {.res = P_PPI0_D14, .offset = 11},
243 {.res = P_PPI0_D15, .offset = 11},
244 {.res = P_SPORT1_TFS, .offset = 11},
245 {.res = P_SPORT1_TSCLK, .offset = 11},
246 {.res = P_SPORT1_DTPRI, .offset = 11},
247 {.res = P_PPI0_D10, .offset = 10},
248 {.res = P_PPI0_D11, .offset = 10},
249 {.res = P_PPI0_D12, .offset = 10},
250 {.res = P_SPORT1_RSCLK, .offset = 10},
251 {.res = P_SPORT1_RFS, .offset = 10},
252 {.res = P_SPORT1_DRPRI, .offset = 10},
253 {.res = P_PPI0_D8, .offset = 9},
254 {.res = P_PPI0_D9, .offset = 9},
255 {.res = P_SPORT1_DRSEC, .offset = 9},
256 {.res = P_SPORT1_DTSEC, .offset = 9},
257 {.res = P_TMR2, .offset = 8},
258 {.res = P_PPI0_FS3, .offset = 8},
259 {.res = P_TMR3, .offset = 7},
260 {.res = P_SPI0_SSEL4, .offset = 7},
261 {.res = P_TMR4, .offset = 6},
262 {.res = P_SPI0_SSEL5, .offset = 6},
263 {.res = P_TMR5, .offset = 5},
264 {.res = P_SPI0_SSEL6, .offset = 5},
265 {.res = P_UART1_RX, .offset = 4},
266 {.res = P_UART1_TX, .offset = 4},
267 {.res = P_TMR6, .offset = 4},
268 {.res = P_TMR7, .offset = 4},
269 {.res = P_UART0_RX, .offset = 3},
270 {.res = P_UART0_TX, .offset = 3},
271 {.res = P_DMAR0, .offset = 3},
272 {.res = P_DMAR1, .offset = 3},
273 {.res = P_SPORT0_DTSEC, .offset = 1},
274 {.res = P_SPORT0_DRSEC, .offset = 1},
275 {.res = P_CAN0_RX, .offset = 1},
276 {.res = P_CAN0_TX, .offset = 1},
277 {.res = P_SPI0_SSEL7, .offset = 1},
278 {.res = P_SPORT0_TFS, .offset = 0},
279 {.res = P_SPORT0_DTPRI, .offset = 0},
280 {.res = P_SPI0_SSEL2, .offset = 0},
281 {.res = P_SPI0_SSEL3, .offset = 0},
284 static void portmux_setup(unsigned short per)
286 u16 y, offset, muxreg;
287 u16 function = P_FUNCT2MUX(per);
289 for (y = 0; y < ARRAY_SIZE(port_mux_lut); y++) {
290 if (port_mux_lut[y].res == per) {
292 /* SET PORTMUX REG */
294 offset = port_mux_lut[y].offset;
295 muxreg = bfin_read_PORT_MUX();
298 muxreg &= ~(1 << offset);
302 muxreg |= (function << offset);
303 bfin_write_PORT_MUX(muxreg);
307 #elif defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
308 inline void portmux_setup(unsigned short per)
311 u16 ident = P_IDENT(per);
312 u16 function = P_FUNCT2MUX(per);
314 pmux = gpio_array[gpio_bank(ident)]->port_mux;
316 pmux &= ~(0x3 << (2 * gpio_sub_n(ident)));
317 pmux |= (function & 0x3) << (2 * gpio_sub_n(ident));
319 gpio_array[gpio_bank(ident)]->port_mux = pmux;
322 inline u16 get_portmux(unsigned short per)
325 u16 ident = P_IDENT(per);
327 pmux = gpio_array[gpio_bank(ident)]->port_mux;
329 return (pmux >> (2 * gpio_sub_n(ident)) & 0x3);
331 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
332 inline void portmux_setup(unsigned short per)
334 u16 pmux, ident = P_IDENT(per), function = P_FUNCT2MUX(per);
335 u8 offset = pmux_offset[gpio_bank(ident)][gpio_sub_n(ident)];
337 pmux = *port_mux[gpio_bank(ident)];
338 pmux &= ~(3 << offset);
339 pmux |= (function & 3) << offset;
340 *port_mux[gpio_bank(ident)] = pmux;
344 # define portmux_setup(...) do { } while (0)
347 #if !defined(CONFIG_BF54x) && !defined(CONFIG_BF60x)
348 /***********************************************************
350 * FUNCTIONS: Blackfin General Purpose Ports Access Functions
353 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
356 * DESCRIPTION: These functions abstract direct register access
357 * to Blackfin processor General Purpose
360 * CAUTION: These functions do not belong to the GPIO Driver API
361 *************************************************************
362 * MODIFICATION HISTORY :
363 **************************************************************/
365 /* Set a specific bit */
367 #define SET_GPIO(name) \
368 void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
370 unsigned long flags; \
371 local_irq_save(flags); \
373 gpio_array[gpio_bank(gpio)]->name |= gpio_bit(gpio); \
375 gpio_array[gpio_bank(gpio)]->name &= ~gpio_bit(gpio); \
376 AWA_DUMMY_READ(name); \
377 local_irq_restore(flags); \
380 SET_GPIO(dir) /* set_gpio_dir() */
381 SET_GPIO(inen) /* set_gpio_inen() */
382 SET_GPIO(polar) /* set_gpio_polar() */
383 SET_GPIO(edge) /* set_gpio_edge() */
384 SET_GPIO(both) /* set_gpio_both() */
387 #define SET_GPIO_SC(name) \
388 void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
390 unsigned long flags; \
391 if (ANOMALY_05000311 || ANOMALY_05000323) \
392 local_irq_save(flags); \
394 gpio_array[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \
396 gpio_array[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \
397 if (ANOMALY_05000311 || ANOMALY_05000323) { \
398 AWA_DUMMY_READ(name); \
399 local_irq_restore(flags); \
407 void set_gpio_toggle(unsigned gpio)
410 if (ANOMALY_05000311 || ANOMALY_05000323)
411 local_irq_save(flags);
412 gpio_array[gpio_bank(gpio)]->toggle = gpio_bit(gpio);
413 if (ANOMALY_05000311 || ANOMALY_05000323) {
414 AWA_DUMMY_READ(toggle);
415 local_irq_restore(flags);
419 /* Set current PORT date (16-bit word) */
421 #define SET_GPIO_P(name) \
422 void set_gpiop_ ## name(unsigned gpio, unsigned short arg) \
424 unsigned long flags; \
425 if (ANOMALY_05000311 || ANOMALY_05000323) \
426 local_irq_save(flags); \
427 gpio_array[gpio_bank(gpio)]->name = arg; \
428 if (ANOMALY_05000311 || ANOMALY_05000323) { \
429 AWA_DUMMY_READ(name); \
430 local_irq_restore(flags); \
443 /* Get a specific bit */
444 #define GET_GPIO(name) \
445 unsigned short get_gpio_ ## name(unsigned gpio) \
447 unsigned long flags; \
448 unsigned short ret; \
449 if (ANOMALY_05000311 || ANOMALY_05000323) \
450 local_irq_save(flags); \
451 ret = 0x01 & (gpio_array[gpio_bank(gpio)]->name >> gpio_sub_n(gpio)); \
452 if (ANOMALY_05000311 || ANOMALY_05000323) { \
453 AWA_DUMMY_READ(name); \
454 local_irq_restore(flags); \
468 /* Get current PORT date (16-bit word) */
470 #define GET_GPIO_P(name) \
471 unsigned short get_gpiop_ ## name(unsigned gpio) \
473 unsigned long flags; \
474 unsigned short ret; \
475 if (ANOMALY_05000311 || ANOMALY_05000323) \
476 local_irq_save(flags); \
477 ret = (gpio_array[gpio_bank(gpio)]->name); \
478 if (ANOMALY_05000311 || ANOMALY_05000323) { \
479 AWA_DUMMY_READ(name); \
480 local_irq_restore(flags); \
494 #else /* CONFIG_BF54x */
496 unsigned short get_gpio_dir(unsigned gpio)
498 return (0x01 & (gpio_array[gpio_bank(gpio)]->dir_clear >> gpio_sub_n(gpio)));
501 #endif /* CONFIG_BF54x */
503 /***********************************************************
505 * FUNCTIONS: Blackfin Peripheral Resource Allocation
509 * per Peripheral Identifier
512 * DESCRIPTION: Blackfin Peripheral Resource Allocation and Setup API
515 *************************************************************
516 * MODIFICATION HISTORY :
517 **************************************************************/
519 int peripheral_request(unsigned short per, const char *label)
521 unsigned short ident = P_IDENT(per);
524 * Don't cares are pins with only one dedicated function
527 if (per & P_DONTCARE)
530 if (!(per & P_DEFINED))
533 BUG_ON(ident >= MAX_RESOURCES);
535 /* If a pin can be muxed as either GPIO or peripheral, make
536 * sure it is not already a GPIO pin when we request it.
538 if (unlikely(!check_gpio(ident) && is_reserved(gpio, ident, 1))) {
539 printf("%s: Peripheral %d is already reserved as GPIO by %s !\n",
540 __func__, ident, get_label(ident));
544 if (unlikely(is_reserved(peri, ident, 1))) {
547 * Pin functions like AMC address strobes my
548 * be requested and used by several drivers
551 #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
552 if (!((per & P_MAYSHARE) && get_portmux(per) == P_FUNCT2MUX(per))) {
554 if (!(per & P_MAYSHARE)) {
557 * Allow that the identical pin function can
558 * be requested from the same driver twice
561 if (cmp_label(ident, label) == 0)
564 printf("%s: Peripheral %d function %d is already reserved by %s !\n",
565 __func__, ident, P_FUNCT2MUX(per), get_label(ident));
571 reserve(peri, ident);
574 port_setup(ident, PERIPHERAL_USAGE);
576 set_label(ident, label);
581 int peripheral_request_list(const unsigned short per[], const char *label)
586 for (cnt = 0; per[cnt] != 0; cnt++) {
588 ret = peripheral_request(per[cnt], label);
591 for ( ; cnt > 0; cnt--)
592 peripheral_free(per[cnt - 1]);
601 void peripheral_free(unsigned short per)
603 unsigned short ident = P_IDENT(per);
605 if (per & P_DONTCARE)
608 if (!(per & P_DEFINED))
611 if (unlikely(!is_reserved(peri, ident, 0)))
614 if (!(per & P_MAYSHARE))
615 port_setup(ident, GPIO_USAGE);
617 unreserve(peri, ident);
619 set_label(ident, "free");
622 void peripheral_free_list(const unsigned short per[])
625 for (cnt = 0; per[cnt] != 0; cnt++)
626 peripheral_free(per[cnt]);
629 /***********************************************************
631 * FUNCTIONS: Blackfin GPIO Driver
634 * gpio PIO Number between 0 and MAX_BLACKFIN_GPIOS
637 * DESCRIPTION: Blackfin GPIO Driver API
640 *************************************************************
641 * MODIFICATION HISTORY :
642 **************************************************************/
644 int bfin_gpio_request(unsigned gpio, const char *label)
646 if (check_gpio(gpio) < 0)
650 * Allow that the identical GPIO can
651 * be requested from the same driver twice
652 * Do nothing and return -
655 if (cmp_label(gpio, label) == 0)
658 if (unlikely(is_reserved(gpio, gpio, 1))) {
659 printf("bfin-gpio: GPIO %d is already reserved by %s !\n",
660 gpio, get_label(gpio));
663 if (unlikely(is_reserved(peri, gpio, 1))) {
664 printf("bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
665 gpio, get_label(gpio));
668 #if !defined(CONFIG_BF54x) && !defined(CONFIG_BF60x)
669 else { /* Reset POLAR setting when acquiring a gpio for the first time */
670 set_gpio_polar(gpio, 0);
675 set_label(gpio, label);
677 port_setup(gpio, GPIO_USAGE);
682 #ifdef CONFIG_BFIN_GPIO_TRACK
683 void bfin_gpio_free(unsigned gpio)
685 if (check_gpio(gpio) < 0)
688 if (unlikely(!is_reserved(gpio, gpio, 0))) {
693 unreserve(gpio, gpio);
695 set_label(gpio, "free");
699 #ifdef BFIN_SPECIAL_GPIO_BANKS
700 DECLARE_RESERVED_MAP(special_gpio, gpio_bank(MAX_RESOURCES));
702 int bfin_special_gpio_request(unsigned gpio, const char *label)
705 * Allow that the identical GPIO can
706 * be requested from the same driver twice
707 * Do nothing and return -
710 if (cmp_label(gpio, label) == 0)
713 if (unlikely(is_reserved(special_gpio, gpio, 1))) {
714 printf("bfin-gpio: GPIO %d is already reserved by %s !\n",
715 gpio, get_label(gpio));
718 if (unlikely(is_reserved(peri, gpio, 1))) {
719 printf("bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
720 gpio, get_label(gpio));
725 reserve(special_gpio, gpio);
728 set_label(gpio, label);
729 port_setup(gpio, GPIO_USAGE);
734 void bfin_special_gpio_free(unsigned gpio)
736 if (unlikely(!is_reserved(special_gpio, gpio, 0))) {
741 reserve(special_gpio, gpio);
743 set_label(gpio, "free");
747 static inline void __bfin_gpio_direction_input(unsigned gpio)
749 #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
750 gpio_array[gpio_bank(gpio)]->dir_clear = gpio_bit(gpio);
752 gpio_array[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio);
754 #if defined(CONFIG_BF60x)
755 gpio_array[gpio_bank(gpio)]->inen_set = gpio_bit(gpio);
757 gpio_array[gpio_bank(gpio)]->inen |= gpio_bit(gpio);
761 int bfin_gpio_direction_input(unsigned gpio)
765 if (!is_reserved(gpio, gpio, 0)) {
770 local_irq_save(flags);
771 __bfin_gpio_direction_input(gpio);
772 AWA_DUMMY_READ(inen);
773 local_irq_restore(flags);
778 void bfin_gpio_toggle_value(unsigned gpio)
781 gpio_set_value(gpio, !gpio_get_value(gpio));
783 gpio_array[gpio_bank(gpio)]->toggle = gpio_bit(gpio);
787 void bfin_gpio_set_value(unsigned gpio, int arg)
790 gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
792 gpio_array[gpio_bank(gpio)]->data_clear = gpio_bit(gpio);
795 int bfin_gpio_direction_output(unsigned gpio, int value)
799 if (!is_reserved(gpio, gpio, 0)) {
804 local_irq_save(flags);
806 #if defined(CONFIG_BF60x)
807 gpio_array[gpio_bank(gpio)]->inen_clear = gpio_bit(gpio);
809 gpio_array[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio);
811 gpio_set_value(gpio, value);
812 #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
813 gpio_array[gpio_bank(gpio)]->dir_set = gpio_bit(gpio);
815 gpio_array[gpio_bank(gpio)]->dir |= gpio_bit(gpio);
819 local_irq_restore(flags);
824 int bfin_gpio_get_value(unsigned gpio)
826 #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
827 return (1 & (gpio_array[gpio_bank(gpio)]->data >> gpio_sub_n(gpio)));
831 if (unlikely(get_gpio_edge(gpio))) {
833 local_irq_save(flags);
834 set_gpio_edge(gpio, 0);
835 ret = get_gpio_data(gpio);
836 set_gpio_edge(gpio, 1);
837 local_irq_restore(flags);
840 return get_gpio_data(gpio);
844 /* If we are booting from SPI and our board lacks a strong enough pull up,
845 * the core can reset and execute the bootrom faster than the resistor can
846 * pull the signal logically high. To work around this (common) error in
847 * board design, we explicitly set the pin back to GPIO mode, force /CS
848 * high, and wait for the electrons to do their thing.
850 * This function only makes sense to be called from reset code, but it
851 * lives here as we need to force all the GPIO states w/out going through
852 * BUG() checks and such.
854 void bfin_reset_boot_spi_cs(unsigned short pin)
856 unsigned short gpio = P_IDENT(pin);
857 port_setup(gpio, GPIO_USAGE);
858 gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
859 AWA_DUMMY_READ(data_set);
863 #ifdef CONFIG_BFIN_GPIO_TRACK
864 void bfin_gpio_labels(void)
868 for (c = 0; c < MAX_RESOURCES; c++) {
869 gpio = is_reserved(gpio, c, 1);
870 if (!check_gpio(c) && gpio)
871 printf("GPIO_%d:\t%s\tGPIO %s\n", c,
873 get_gpio_dir(c) ? "OUTPUT" : "INPUT");
874 else if (is_reserved(peri, c, 1))
875 printf("GPIO_%d:\t%s\tPeripheral\n", c, get_label(c));