Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 2 | * GPIO Abstraction Layer |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 3 | * |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 4 | * Copyright 2006-2009 Analog Devices Inc. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 5 | * |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 6 | * Licensed under the GPL-2 or later |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Mike Frysinger | 168f121 | 2007-10-11 00:22:35 +0800 | [diff] [blame] | 9 | #include <linux/delay.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 10 | #include <linux/module.h> |
| 11 | #include <linux/err.h> |
Mike Frysinger | 1545a11 | 2007-12-24 16:54:48 +0800 | [diff] [blame] | 12 | #include <linux/proc_fs.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 13 | #include <asm/blackfin.h> |
| 14 | #include <asm/gpio.h> |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 15 | #include <asm/portmux.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 16 | #include <linux/irq.h> |
| 17 | |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 18 | #if ANOMALY_05000311 || ANOMALY_05000323 |
| 19 | enum { |
| 20 | AWA_data = SYSCR, |
| 21 | AWA_data_clear = SYSCR, |
| 22 | AWA_data_set = SYSCR, |
| 23 | AWA_toggle = SYSCR, |
Graf Yang | 6ed8394 | 2008-04-24 04:43:14 +0800 | [diff] [blame] | 24 | AWA_maska = BFIN_UART_SCR, |
| 25 | AWA_maska_clear = BFIN_UART_SCR, |
| 26 | AWA_maska_set = BFIN_UART_SCR, |
| 27 | AWA_maska_toggle = BFIN_UART_SCR, |
| 28 | AWA_maskb = BFIN_UART_GCTL, |
| 29 | AWA_maskb_clear = BFIN_UART_GCTL, |
| 30 | AWA_maskb_set = BFIN_UART_GCTL, |
| 31 | AWA_maskb_toggle = BFIN_UART_GCTL, |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 32 | AWA_dir = SPORT1_STAT, |
| 33 | AWA_polar = SPORT1_STAT, |
| 34 | AWA_edge = SPORT1_STAT, |
| 35 | AWA_both = SPORT1_STAT, |
| 36 | #if ANOMALY_05000311 |
| 37 | AWA_inen = TIMER_ENABLE, |
| 38 | #elif ANOMALY_05000323 |
| 39 | AWA_inen = DMA1_1_CONFIG, |
| 40 | #endif |
| 41 | }; |
| 42 | /* Anomaly Workaround */ |
| 43 | #define AWA_DUMMY_READ(name) bfin_read16(AWA_ ## name) |
| 44 | #else |
| 45 | #define AWA_DUMMY_READ(...) do { } while (0) |
| 46 | #endif |
| 47 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 48 | static struct gpio_port_t * const gpio_array[] = { |
Michael Hennerich | dc26aec | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 49 | #if defined(BF533_FAMILY) || defined(BF538_FAMILY) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 50 | (struct gpio_port_t *) FIO_FLAG_D, |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 51 | #elif defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 52 | (struct gpio_port_t *) PORTFIO, |
| 53 | (struct gpio_port_t *) PORTGIO, |
| 54 | (struct gpio_port_t *) PORTHIO, |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 55 | #elif defined(BF561_FAMILY) |
| 56 | (struct gpio_port_t *) FIO0_FLAG_D, |
| 57 | (struct gpio_port_t *) FIO1_FLAG_D, |
| 58 | (struct gpio_port_t *) FIO2_FLAG_D, |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 59 | #elif defined(CONFIG_BF54x) |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 60 | (struct gpio_port_t *)PORTA_FER, |
| 61 | (struct gpio_port_t *)PORTB_FER, |
| 62 | (struct gpio_port_t *)PORTC_FER, |
| 63 | (struct gpio_port_t *)PORTD_FER, |
| 64 | (struct gpio_port_t *)PORTE_FER, |
| 65 | (struct gpio_port_t *)PORTF_FER, |
| 66 | (struct gpio_port_t *)PORTG_FER, |
| 67 | (struct gpio_port_t *)PORTH_FER, |
| 68 | (struct gpio_port_t *)PORTI_FER, |
| 69 | (struct gpio_port_t *)PORTJ_FER, |
| 70 | #else |
| 71 | # error no gpio arrays defined |
| 72 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 75 | #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x) |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 76 | static unsigned short * const port_fer[] = { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 77 | (unsigned short *) PORTF_FER, |
| 78 | (unsigned short *) PORTG_FER, |
| 79 | (unsigned short *) PORTH_FER, |
| 80 | }; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 81 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 82 | # if !defined(BF537_FAMILY) |
| 83 | static unsigned short * const port_mux[] = { |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 84 | (unsigned short *) PORTF_MUX, |
| 85 | (unsigned short *) PORTG_MUX, |
| 86 | (unsigned short *) PORTH_MUX, |
| 87 | }; |
| 88 | |
| 89 | static const |
Graf Yang | 0ce5eaf | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 90 | u8 pmux_offset[][16] = { |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 91 | # if defined(CONFIG_BF52x) |
Graf Yang | 0ce5eaf | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 92 | { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 4, 6, 8, 8, 10, 10 }, /* PORTF */ |
| 93 | { 0, 0, 0, 0, 0, 2, 2, 4, 4, 6, 8, 10, 10, 10, 12, 12 }, /* PORTG */ |
| 94 | { 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4 }, /* PORTH */ |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 95 | # elif defined(CONFIG_BF51x) |
Graf Yang | 0ce5eaf | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 96 | { 0, 2, 2, 2, 2, 2, 2, 4, 6, 6, 6, 8, 8, 8, 8, 10 }, /* PORTF */ |
| 97 | { 0, 0, 0, 2, 4, 6, 6, 6, 8, 10, 10, 12, 14, 14, 14, 14 }, /* PORTG */ |
| 98 | { 0, 0, 0, 0, 2, 2, 4, 6, 10, 10, 10, 10, 10, 10, 10, 10 }, /* PORTH */ |
| 99 | # endif |
| 100 | }; |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 101 | # endif |
Graf Yang | 0ce5eaf | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 102 | |
Michael Hennerich | 621dd24 | 2009-09-28 12:23:41 +0000 | [diff] [blame] | 103 | #elif defined(BF538_FAMILY) |
| 104 | static unsigned short * const port_fer[] = { |
| 105 | (unsigned short *) PORTCIO_FER, |
| 106 | (unsigned short *) PORTDIO_FER, |
| 107 | (unsigned short *) PORTEIO_FER, |
| 108 | }; |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 109 | #endif |
| 110 | |
Bryan Wu | 397861c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 111 | static unsigned short reserved_gpio_map[GPIO_BANK_NUM]; |
Michael Hennerich | fac3cf4 | 2007-12-24 20:07:03 +0800 | [diff] [blame] | 112 | static unsigned short reserved_peri_map[gpio_bank(MAX_RESOURCES)]; |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 113 | static unsigned short reserved_gpio_irq_map[GPIO_BANK_NUM]; |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 114 | |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame] | 115 | #define RESOURCE_LABEL_SIZE 16 |
| 116 | |
Michael Hennerich | fac3cf4 | 2007-12-24 20:07:03 +0800 | [diff] [blame] | 117 | static struct str_ident { |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame] | 118 | char name[RESOURCE_LABEL_SIZE]; |
Michael Hennerich | fac3cf4 | 2007-12-24 20:07:03 +0800 | [diff] [blame] | 119 | } str_ident[MAX_RESOURCES]; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 120 | |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 121 | #if defined(CONFIG_PM) |
Bryan Wu | 397861c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 122 | static struct gpio_port_s gpio_bank_saved[GPIO_BANK_NUM]; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 123 | #endif |
| 124 | |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 125 | inline int check_gpio(unsigned gpio) |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 126 | { |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 127 | #if defined(CONFIG_BF54x) |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 128 | if (gpio == GPIO_PB15 || gpio == GPIO_PC14 || gpio == GPIO_PC15 |
| 129 | || gpio == GPIO_PH14 || gpio == GPIO_PH15 |
Mike Frysinger | 27228b2 | 2008-10-28 15:45:42 +0800 | [diff] [blame] | 130 | || gpio == GPIO_PJ14 || gpio == GPIO_PJ15) |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 131 | return -EINVAL; |
Mike Frysinger | 27228b2 | 2008-10-28 15:45:42 +0800 | [diff] [blame] | 132 | #endif |
Michael Hennerich | e7613aa | 2007-06-11 16:37:57 +0800 | [diff] [blame] | 133 | if (gpio >= MAX_BLACKFIN_GPIOS) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 134 | return -EINVAL; |
| 135 | return 0; |
| 136 | } |
| 137 | |
Mike Frysinger | 74c0450 | 2008-10-08 16:13:17 +0800 | [diff] [blame] | 138 | static void gpio_error(unsigned gpio) |
Michael Hennerich | acbcd26 | 2008-01-22 18:36:20 +0800 | [diff] [blame] | 139 | { |
| 140 | printk(KERN_ERR "bfin-gpio: GPIO %d wasn't requested!\n", gpio); |
| 141 | } |
| 142 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 143 | static void set_label(unsigned short ident, const char *label) |
| 144 | { |
Michael Hennerich | e9fae18 | 2008-10-13 11:35:22 +0800 | [diff] [blame] | 145 | if (label) { |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame] | 146 | strncpy(str_ident[ident].name, label, |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 147 | RESOURCE_LABEL_SIZE); |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame] | 148 | str_ident[ident].name[RESOURCE_LABEL_SIZE - 1] = 0; |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
| 152 | static char *get_label(unsigned short ident) |
| 153 | { |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame] | 154 | return (*str_ident[ident].name ? str_ident[ident].name : "UNKNOWN"); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | static int cmp_label(unsigned short ident, const char *label) |
| 158 | { |
Michael Hennerich | fac3cf4 | 2007-12-24 20:07:03 +0800 | [diff] [blame] | 159 | if (label == NULL) { |
| 160 | dump_stack(); |
| 161 | printk(KERN_ERR "Please provide none-null label\n"); |
| 162 | } |
| 163 | |
Michael Hennerich | e9fae18 | 2008-10-13 11:35:22 +0800 | [diff] [blame] | 164 | if (label) |
Mike Frysinger | 1f7d373 | 2008-10-28 15:47:11 +0800 | [diff] [blame] | 165 | return strcmp(str_ident[ident].name, label); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 166 | else |
| 167 | return -EINVAL; |
| 168 | } |
| 169 | |
Mike Frysinger | a2d03a1 | 2008-10-28 15:53:37 +0800 | [diff] [blame] | 170 | static void port_setup(unsigned gpio, unsigned short usage) |
| 171 | { |
Michael Hennerich | 621dd24 | 2009-09-28 12:23:41 +0000 | [diff] [blame] | 172 | #if defined(BF538_FAMILY) |
| 173 | /* |
| 174 | * BF538/9 Port C,D and E are special. |
| 175 | * Inverted PORT_FER polarity on CDE and no PORF_FER on F |
| 176 | * Regular PORT F GPIOs are handled here, CDE are exclusively |
| 177 | * managed by GPIOLIB |
| 178 | */ |
| 179 | |
| 180 | if (gpio < MAX_BLACKFIN_GPIOS || gpio >= MAX_RESOURCES) |
| 181 | return; |
| 182 | |
| 183 | gpio -= MAX_BLACKFIN_GPIOS; |
| 184 | |
| 185 | if (usage == GPIO_USAGE) |
| 186 | *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio); |
| 187 | else |
| 188 | *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio); |
| 189 | SSYNC(); |
| 190 | return; |
| 191 | #endif |
| 192 | |
Mike Frysinger | a2d03a1 | 2008-10-28 15:53:37 +0800 | [diff] [blame] | 193 | if (check_gpio(gpio)) |
| 194 | return; |
| 195 | |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 196 | #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x) |
Mike Frysinger | a2d03a1 | 2008-10-28 15:53:37 +0800 | [diff] [blame] | 197 | if (usage == GPIO_USAGE) |
| 198 | *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio); |
| 199 | else |
| 200 | *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio); |
| 201 | SSYNC(); |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 202 | #elif defined(CONFIG_BF54x) |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 203 | if (usage == GPIO_USAGE) |
| 204 | gpio_array[gpio_bank(gpio)]->port_fer &= ~gpio_bit(gpio); |
| 205 | else |
| 206 | gpio_array[gpio_bank(gpio)]->port_fer |= gpio_bit(gpio); |
| 207 | SSYNC(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 208 | #endif |
Mike Frysinger | a2d03a1 | 2008-10-28 15:53:37 +0800 | [diff] [blame] | 209 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 210 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 211 | #ifdef BF537_FAMILY |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame] | 212 | static struct { |
| 213 | unsigned short res; |
| 214 | unsigned short offset; |
| 215 | } port_mux_lut[] = { |
| 216 | {.res = P_PPI0_D13, .offset = 11}, |
| 217 | {.res = P_PPI0_D14, .offset = 11}, |
| 218 | {.res = P_PPI0_D15, .offset = 11}, |
| 219 | {.res = P_SPORT1_TFS, .offset = 11}, |
| 220 | {.res = P_SPORT1_TSCLK, .offset = 11}, |
| 221 | {.res = P_SPORT1_DTPRI, .offset = 11}, |
| 222 | {.res = P_PPI0_D10, .offset = 10}, |
| 223 | {.res = P_PPI0_D11, .offset = 10}, |
| 224 | {.res = P_PPI0_D12, .offset = 10}, |
| 225 | {.res = P_SPORT1_RSCLK, .offset = 10}, |
| 226 | {.res = P_SPORT1_RFS, .offset = 10}, |
| 227 | {.res = P_SPORT1_DRPRI, .offset = 10}, |
| 228 | {.res = P_PPI0_D8, .offset = 9}, |
| 229 | {.res = P_PPI0_D9, .offset = 9}, |
| 230 | {.res = P_SPORT1_DRSEC, .offset = 9}, |
| 231 | {.res = P_SPORT1_DTSEC, .offset = 9}, |
| 232 | {.res = P_TMR2, .offset = 8}, |
| 233 | {.res = P_PPI0_FS3, .offset = 8}, |
| 234 | {.res = P_TMR3, .offset = 7}, |
| 235 | {.res = P_SPI0_SSEL4, .offset = 7}, |
| 236 | {.res = P_TMR4, .offset = 6}, |
| 237 | {.res = P_SPI0_SSEL5, .offset = 6}, |
| 238 | {.res = P_TMR5, .offset = 5}, |
| 239 | {.res = P_SPI0_SSEL6, .offset = 5}, |
| 240 | {.res = P_UART1_RX, .offset = 4}, |
| 241 | {.res = P_UART1_TX, .offset = 4}, |
| 242 | {.res = P_TMR6, .offset = 4}, |
| 243 | {.res = P_TMR7, .offset = 4}, |
| 244 | {.res = P_UART0_RX, .offset = 3}, |
| 245 | {.res = P_UART0_TX, .offset = 3}, |
| 246 | {.res = P_DMAR0, .offset = 3}, |
| 247 | {.res = P_DMAR1, .offset = 3}, |
| 248 | {.res = P_SPORT0_DTSEC, .offset = 1}, |
| 249 | {.res = P_SPORT0_DRSEC, .offset = 1}, |
| 250 | {.res = P_CAN0_RX, .offset = 1}, |
| 251 | {.res = P_CAN0_TX, .offset = 1}, |
| 252 | {.res = P_SPI0_SSEL7, .offset = 1}, |
| 253 | {.res = P_SPORT0_TFS, .offset = 0}, |
| 254 | {.res = P_SPORT0_DTPRI, .offset = 0}, |
| 255 | {.res = P_SPI0_SSEL2, .offset = 0}, |
| 256 | {.res = P_SPI0_SSEL3, .offset = 0}, |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 257 | }; |
| 258 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 259 | static void portmux_setup(unsigned short per) |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 260 | { |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame] | 261 | u16 y, offset, muxreg; |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 262 | u16 function = P_FUNCT2MUX(per); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 263 | |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame] | 264 | for (y = 0; y < ARRAY_SIZE(port_mux_lut); y++) { |
| 265 | if (port_mux_lut[y].res == per) { |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 266 | |
| 267 | /* SET PORTMUX REG */ |
| 268 | |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame] | 269 | offset = port_mux_lut[y].offset; |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 270 | muxreg = bfin_read_PORT_MUX(); |
| 271 | |
Mike Frysinger | d171c23 | 2008-03-26 08:35:46 +0800 | [diff] [blame] | 272 | if (offset != 1) |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 273 | muxreg &= ~(1 << offset); |
Mike Frysinger | d171c23 | 2008-03-26 08:35:46 +0800 | [diff] [blame] | 274 | else |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 275 | muxreg &= ~(3 << 1); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 276 | |
| 277 | muxreg |= (function << offset); |
| 278 | bfin_write_PORT_MUX(muxreg); |
| 279 | } |
| 280 | } |
| 281 | } |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 282 | #elif defined(CONFIG_BF54x) |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 283 | inline void portmux_setup(unsigned short per) |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 284 | { |
| 285 | u32 pmux; |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 286 | u16 ident = P_IDENT(per); |
| 287 | u16 function = P_FUNCT2MUX(per); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 288 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 289 | pmux = gpio_array[gpio_bank(ident)]->port_mux; |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 290 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 291 | pmux &= ~(0x3 << (2 * gpio_sub_n(ident))); |
| 292 | pmux |= (function & 0x3) << (2 * gpio_sub_n(ident)); |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 293 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 294 | gpio_array[gpio_bank(ident)]->port_mux = pmux; |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 295 | } |
| 296 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 297 | inline u16 get_portmux(unsigned short per) |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 298 | { |
| 299 | u32 pmux; |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 300 | u16 ident = P_IDENT(per); |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 301 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 302 | pmux = gpio_array[gpio_bank(ident)]->port_mux; |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 303 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 304 | return (pmux >> (2 * gpio_sub_n(ident)) & 0x3); |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 305 | } |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 306 | #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x) |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 307 | inline void portmux_setup(unsigned short per) |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 308 | { |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 309 | u16 pmux, ident = P_IDENT(per), function = P_FUNCT2MUX(per); |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 310 | u8 offset = pmux_offset[gpio_bank(ident)][gpio_sub_n(ident)]; |
| 311 | |
| 312 | pmux = *port_mux[gpio_bank(ident)]; |
| 313 | pmux &= ~(3 << offset); |
| 314 | pmux |= (function & 3) << offset; |
| 315 | *port_mux[gpio_bank(ident)] = pmux; |
| 316 | SSYNC(); |
| 317 | } |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 318 | #else |
| 319 | # define portmux_setup(...) do { } while (0) |
| 320 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 321 | |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 322 | #ifndef CONFIG_BF54x |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 323 | /*********************************************************** |
| 324 | * |
| 325 | * FUNCTIONS: Blackfin General Purpose Ports Access Functions |
| 326 | * |
| 327 | * INPUTS/OUTPUTS: |
| 328 | * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS |
| 329 | * |
| 330 | * |
| 331 | * DESCRIPTION: These functions abstract direct register access |
| 332 | * to Blackfin processor General Purpose |
| 333 | * Ports Regsiters |
| 334 | * |
| 335 | * CAUTION: These functions do not belong to the GPIO Driver API |
| 336 | ************************************************************* |
| 337 | * MODIFICATION HISTORY : |
| 338 | **************************************************************/ |
| 339 | |
| 340 | /* Set a specific bit */ |
| 341 | |
| 342 | #define SET_GPIO(name) \ |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 343 | void set_gpio_ ## name(unsigned gpio, unsigned short arg) \ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 344 | { \ |
| 345 | unsigned long flags; \ |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 346 | local_irq_save_hw(flags); \ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 347 | if (arg) \ |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 348 | gpio_array[gpio_bank(gpio)]->name |= gpio_bit(gpio); \ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 349 | else \ |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 350 | gpio_array[gpio_bank(gpio)]->name &= ~gpio_bit(gpio); \ |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 351 | AWA_DUMMY_READ(name); \ |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 352 | local_irq_restore_hw(flags); \ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 353 | } \ |
| 354 | EXPORT_SYMBOL(set_gpio_ ## name); |
| 355 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 356 | SET_GPIO(dir) /* set_gpio_dir() */ |
| 357 | SET_GPIO(inen) /* set_gpio_inen() */ |
| 358 | SET_GPIO(polar) /* set_gpio_polar() */ |
| 359 | SET_GPIO(edge) /* set_gpio_edge() */ |
| 360 | SET_GPIO(both) /* set_gpio_both() */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 361 | |
| 362 | |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 363 | #define SET_GPIO_SC(name) \ |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 364 | void set_gpio_ ## name(unsigned gpio, unsigned short arg) \ |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 365 | { \ |
| 366 | unsigned long flags; \ |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 367 | if (ANOMALY_05000311 || ANOMALY_05000323) \ |
| 368 | local_irq_save_hw(flags); \ |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 369 | if (arg) \ |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 370 | gpio_array[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \ |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 371 | else \ |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 372 | gpio_array[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \ |
| 373 | if (ANOMALY_05000311 || ANOMALY_05000323) { \ |
| 374 | AWA_DUMMY_READ(name); \ |
| 375 | local_irq_restore_hw(flags); \ |
| 376 | } \ |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 377 | } \ |
| 378 | EXPORT_SYMBOL(set_gpio_ ## name); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 379 | |
| 380 | SET_GPIO_SC(maska) |
| 381 | SET_GPIO_SC(maskb) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 382 | SET_GPIO_SC(data) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 383 | |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 384 | void set_gpio_toggle(unsigned gpio) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 385 | { |
| 386 | unsigned long flags; |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 387 | if (ANOMALY_05000311 || ANOMALY_05000323) |
| 388 | local_irq_save_hw(flags); |
| 389 | gpio_array[gpio_bank(gpio)]->toggle = gpio_bit(gpio); |
| 390 | if (ANOMALY_05000311 || ANOMALY_05000323) { |
| 391 | AWA_DUMMY_READ(toggle); |
| 392 | local_irq_restore_hw(flags); |
| 393 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 394 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 395 | EXPORT_SYMBOL(set_gpio_toggle); |
| 396 | |
| 397 | |
| 398 | /*Set current PORT date (16-bit word)*/ |
| 399 | |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 400 | #define SET_GPIO_P(name) \ |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 401 | void set_gpiop_ ## name(unsigned gpio, unsigned short arg) \ |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 402 | { \ |
| 403 | unsigned long flags; \ |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 404 | if (ANOMALY_05000311 || ANOMALY_05000323) \ |
| 405 | local_irq_save_hw(flags); \ |
| 406 | gpio_array[gpio_bank(gpio)]->name = arg; \ |
| 407 | if (ANOMALY_05000311 || ANOMALY_05000323) { \ |
| 408 | AWA_DUMMY_READ(name); \ |
| 409 | local_irq_restore_hw(flags); \ |
| 410 | } \ |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 411 | } \ |
| 412 | EXPORT_SYMBOL(set_gpiop_ ## name); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 413 | |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 414 | SET_GPIO_P(data) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 415 | SET_GPIO_P(dir) |
| 416 | SET_GPIO_P(inen) |
| 417 | SET_GPIO_P(polar) |
| 418 | SET_GPIO_P(edge) |
| 419 | SET_GPIO_P(both) |
| 420 | SET_GPIO_P(maska) |
| 421 | SET_GPIO_P(maskb) |
| 422 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 423 | /* Get a specific bit */ |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 424 | #define GET_GPIO(name) \ |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 425 | unsigned short get_gpio_ ## name(unsigned gpio) \ |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 426 | { \ |
| 427 | unsigned long flags; \ |
| 428 | unsigned short ret; \ |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 429 | if (ANOMALY_05000311 || ANOMALY_05000323) \ |
| 430 | local_irq_save_hw(flags); \ |
| 431 | ret = 0x01 & (gpio_array[gpio_bank(gpio)]->name >> gpio_sub_n(gpio)); \ |
| 432 | if (ANOMALY_05000311 || ANOMALY_05000323) { \ |
| 433 | AWA_DUMMY_READ(name); \ |
| 434 | local_irq_restore_hw(flags); \ |
| 435 | } \ |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 436 | return ret; \ |
| 437 | } \ |
| 438 | EXPORT_SYMBOL(get_gpio_ ## name); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 439 | |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 440 | GET_GPIO(data) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 441 | GET_GPIO(dir) |
| 442 | GET_GPIO(inen) |
| 443 | GET_GPIO(polar) |
| 444 | GET_GPIO(edge) |
| 445 | GET_GPIO(both) |
| 446 | GET_GPIO(maska) |
| 447 | GET_GPIO(maskb) |
| 448 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 449 | /*Get current PORT date (16-bit word)*/ |
| 450 | |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 451 | #define GET_GPIO_P(name) \ |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 452 | unsigned short get_gpiop_ ## name(unsigned gpio) \ |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 453 | { \ |
| 454 | unsigned long flags; \ |
| 455 | unsigned short ret; \ |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 456 | if (ANOMALY_05000311 || ANOMALY_05000323) \ |
| 457 | local_irq_save_hw(flags); \ |
| 458 | ret = (gpio_array[gpio_bank(gpio)]->name); \ |
| 459 | if (ANOMALY_05000311 || ANOMALY_05000323) { \ |
| 460 | AWA_DUMMY_READ(name); \ |
| 461 | local_irq_restore_hw(flags); \ |
| 462 | } \ |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 463 | return ret; \ |
| 464 | } \ |
| 465 | EXPORT_SYMBOL(get_gpiop_ ## name); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 466 | |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 467 | GET_GPIO_P(data) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 468 | GET_GPIO_P(dir) |
| 469 | GET_GPIO_P(inen) |
| 470 | GET_GPIO_P(polar) |
| 471 | GET_GPIO_P(edge) |
| 472 | GET_GPIO_P(both) |
| 473 | GET_GPIO_P(maska) |
| 474 | GET_GPIO_P(maskb) |
| 475 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 476 | |
| 477 | #ifdef CONFIG_PM |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 478 | static unsigned short wakeup_map[GPIO_BANK_NUM]; |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 479 | |
| 480 | static const unsigned int sic_iwr_irqs[] = { |
| 481 | #if defined(BF533_FAMILY) |
| 482 | IRQ_PROG_INTB |
| 483 | #elif defined(BF537_FAMILY) |
| 484 | IRQ_PROG_INTB, IRQ_PORTG_INTB, IRQ_MAC_TX |
| 485 | #elif defined(BF538_FAMILY) |
| 486 | IRQ_PORTF_INTB |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 487 | #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x) |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 488 | IRQ_PORTF_INTB, IRQ_PORTG_INTB, IRQ_PORTH_INTB |
| 489 | #elif defined(BF561_FAMILY) |
| 490 | IRQ_PROG0_INTB, IRQ_PROG1_INTB, IRQ_PROG2_INTB |
| 491 | #else |
| 492 | # error no SIC_IWR defined |
| 493 | #endif |
| 494 | }; |
| 495 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 496 | /*********************************************************** |
| 497 | * |
| 498 | * FUNCTIONS: Blackfin PM Setup API |
| 499 | * |
| 500 | * INPUTS/OUTPUTS: |
| 501 | * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS |
| 502 | * type - |
| 503 | * PM_WAKE_RISING |
| 504 | * PM_WAKE_FALLING |
| 505 | * PM_WAKE_HIGH |
| 506 | * PM_WAKE_LOW |
| 507 | * PM_WAKE_BOTH_EDGES |
| 508 | * |
| 509 | * DESCRIPTION: Blackfin PM Driver API |
| 510 | * |
| 511 | * CAUTION: |
| 512 | ************************************************************* |
| 513 | * MODIFICATION HISTORY : |
| 514 | **************************************************************/ |
Michael Hennerich | bb84dbf | 2010-03-10 14:26:06 +0000 | [diff] [blame^] | 515 | int gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 516 | { |
| 517 | unsigned long flags; |
| 518 | |
| 519 | if (check_gpio(gpio) < 0) |
Michael Hennerich | bb84dbf | 2010-03-10 14:26:06 +0000 | [diff] [blame^] | 520 | return -EINVAL; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 521 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 522 | local_irq_save_hw(flags); |
Michael Hennerich | bb84dbf | 2010-03-10 14:26:06 +0000 | [diff] [blame^] | 523 | if (ctrl) |
| 524 | wakeup_map[gpio_bank(gpio)] |= gpio_bit(gpio); |
| 525 | else |
| 526 | wakeup_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 527 | |
Michael Hennerich | bb84dbf | 2010-03-10 14:26:06 +0000 | [diff] [blame^] | 528 | set_gpio_maskb(gpio, ctrl); |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 529 | local_irq_restore_hw(flags); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 530 | |
| 531 | return 0; |
| 532 | } |
| 533 | |
Michael Hennerich | bb84dbf | 2010-03-10 14:26:06 +0000 | [diff] [blame^] | 534 | int bfin_pm_standby_ctrl(unsigned ctrl) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 535 | { |
| 536 | u16 bank, mask, i; |
| 537 | |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 538 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 539 | mask = wakeup_map[gpio_bank(i)]; |
| 540 | bank = gpio_bank(i); |
| 541 | |
Michael Hennerich | bb84dbf | 2010-03-10 14:26:06 +0000 | [diff] [blame^] | 542 | if (mask) |
| 543 | bfin_internal_set_wake(sic_iwr_irqs[bank], ctrl); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 544 | } |
Michael Hennerich | bb84dbf | 2010-03-10 14:26:06 +0000 | [diff] [blame^] | 545 | return 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 548 | void bfin_gpio_pm_hibernate_suspend(void) |
| 549 | { |
| 550 | int i, bank; |
| 551 | |
| 552 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { |
| 553 | bank = gpio_bank(i); |
| 554 | |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 555 | #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x) |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 556 | gpio_bank_saved[bank].fer = *port_fer[bank]; |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 557 | #if defined(CONFIG_BF52x) || defined(CONFIG_BF51x) |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 558 | gpio_bank_saved[bank].mux = *port_mux[bank]; |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 559 | #else |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 560 | if (bank == 0) |
| 561 | gpio_bank_saved[bank].mux = bfin_read_PORT_MUX(); |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 562 | #endif |
| 563 | #endif |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 564 | gpio_bank_saved[bank].data = gpio_array[bank]->data; |
| 565 | gpio_bank_saved[bank].inen = gpio_array[bank]->inen; |
| 566 | gpio_bank_saved[bank].polar = gpio_array[bank]->polar; |
| 567 | gpio_bank_saved[bank].dir = gpio_array[bank]->dir; |
| 568 | gpio_bank_saved[bank].edge = gpio_array[bank]->edge; |
| 569 | gpio_bank_saved[bank].both = gpio_array[bank]->both; |
| 570 | gpio_bank_saved[bank].maska = gpio_array[bank]->maska; |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | AWA_DUMMY_READ(maska); |
| 574 | } |
| 575 | |
| 576 | void bfin_gpio_pm_hibernate_restore(void) |
| 577 | { |
| 578 | int i, bank; |
| 579 | |
| 580 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 581 | bank = gpio_bank(i); |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 582 | |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 583 | #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x) |
| 584 | #if defined(CONFIG_BF52x) || defined(CONFIG_BF51x) |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 585 | *port_mux[bank] = gpio_bank_saved[bank].mux; |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 586 | #else |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 587 | if (bank == 0) |
| 588 | bfin_write_PORT_MUX(gpio_bank_saved[bank].mux); |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 589 | #endif |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 590 | *port_fer[bank] = gpio_bank_saved[bank].fer; |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 591 | #endif |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 592 | gpio_array[bank]->inen = gpio_bank_saved[bank].inen; |
Michael Hennerich | c03c2a8 | 2009-07-08 12:04:43 +0000 | [diff] [blame] | 593 | gpio_array[bank]->data_set = gpio_bank_saved[bank].data |
| 594 | & gpio_bank_saved[bank].dir; |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 595 | gpio_array[bank]->dir = gpio_bank_saved[bank].dir; |
| 596 | gpio_array[bank]->polar = gpio_bank_saved[bank].polar; |
| 597 | gpio_array[bank]->edge = gpio_bank_saved[bank].edge; |
| 598 | gpio_array[bank]->both = gpio_bank_saved[bank].both; |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 599 | gpio_array[bank]->maska = gpio_bank_saved[bank].maska; |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 600 | } |
| 601 | AWA_DUMMY_READ(maska); |
| 602 | } |
| 603 | |
| 604 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 605 | #endif |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 606 | #else /* CONFIG_BF54x */ |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 607 | #ifdef CONFIG_PM |
| 608 | |
Michael Hennerich | bb84dbf | 2010-03-10 14:26:06 +0000 | [diff] [blame^] | 609 | int bfin_pm_standby_ctrl(unsigned ctrl) |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 610 | { |
| 611 | return 0; |
| 612 | } |
| 613 | |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 614 | void bfin_gpio_pm_hibernate_suspend(void) |
| 615 | { |
| 616 | int i, bank; |
| 617 | |
| 618 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { |
| 619 | bank = gpio_bank(i); |
| 620 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 621 | gpio_bank_saved[bank].fer = gpio_array[bank]->port_fer; |
| 622 | gpio_bank_saved[bank].mux = gpio_array[bank]->port_mux; |
| 623 | gpio_bank_saved[bank].data = gpio_array[bank]->data; |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 624 | gpio_bank_saved[bank].inen = gpio_array[bank]->inen; |
| 625 | gpio_bank_saved[bank].dir = gpio_array[bank]->dir_set; |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | |
| 629 | void bfin_gpio_pm_hibernate_restore(void) |
| 630 | { |
| 631 | int i, bank; |
| 632 | |
| 633 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 634 | bank = gpio_bank(i); |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 635 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 636 | gpio_array[bank]->port_mux = gpio_bank_saved[bank].mux; |
| 637 | gpio_array[bank]->port_fer = gpio_bank_saved[bank].fer; |
| 638 | gpio_array[bank]->inen = gpio_bank_saved[bank].inen; |
| 639 | gpio_array[bank]->dir_set = gpio_bank_saved[bank].dir; |
| 640 | gpio_array[bank]->data_set = gpio_bank_saved[bank].data |
| 641 | | gpio_bank_saved[bank].dir; |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | #endif |
Michael Hennerich | fac3cf4 | 2007-12-24 20:07:03 +0800 | [diff] [blame] | 645 | |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 646 | unsigned short get_gpio_dir(unsigned gpio) |
Michael Hennerich | fac3cf4 | 2007-12-24 20:07:03 +0800 | [diff] [blame] | 647 | { |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 648 | return (0x01 & (gpio_array[gpio_bank(gpio)]->dir_clear >> gpio_sub_n(gpio))); |
Michael Hennerich | fac3cf4 | 2007-12-24 20:07:03 +0800 | [diff] [blame] | 649 | } |
| 650 | EXPORT_SYMBOL(get_gpio_dir); |
| 651 | |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 652 | #endif /* CONFIG_BF54x */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 653 | |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 654 | /*********************************************************** |
| 655 | * |
| 656 | * FUNCTIONS: Blackfin Peripheral Resource Allocation |
| 657 | * and PortMux Setup |
| 658 | * |
| 659 | * INPUTS/OUTPUTS: |
| 660 | * per Peripheral Identifier |
| 661 | * label String |
| 662 | * |
| 663 | * DESCRIPTION: Blackfin Peripheral Resource Allocation and Setup API |
| 664 | * |
| 665 | * CAUTION: |
| 666 | ************************************************************* |
| 667 | * MODIFICATION HISTORY : |
| 668 | **************************************************************/ |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 669 | |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 670 | int peripheral_request(unsigned short per, const char *label) |
| 671 | { |
| 672 | unsigned long flags; |
| 673 | unsigned short ident = P_IDENT(per); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 674 | |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 675 | /* |
| 676 | * Don't cares are pins with only one dedicated function |
| 677 | */ |
| 678 | |
| 679 | if (per & P_DONTCARE) |
| 680 | return 0; |
| 681 | |
| 682 | if (!(per & P_DEFINED)) |
| 683 | return -ENODEV; |
| 684 | |
Barry Song | 89e84ee | 2009-09-16 04:36:29 +0000 | [diff] [blame] | 685 | BUG_ON(ident >= MAX_RESOURCES); |
| 686 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 687 | local_irq_save_hw(flags); |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 688 | |
Mike Frysinger | 6a87d29 | 2008-10-28 16:16:29 +0800 | [diff] [blame] | 689 | /* If a pin can be muxed as either GPIO or peripheral, make |
| 690 | * sure it is not already a GPIO pin when we request it. |
| 691 | */ |
| 692 | if (unlikely(!check_gpio(ident) && |
| 693 | reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) { |
Robin Getz | d6879c5 | 2009-03-29 01:10:30 +0800 | [diff] [blame] | 694 | if (system_state == SYSTEM_BOOTING) |
| 695 | dump_stack(); |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 696 | printk(KERN_ERR |
Mike Frysinger | 6c7ec0e | 2008-10-28 15:49:59 +0800 | [diff] [blame] | 697 | "%s: Peripheral %d is already reserved as GPIO by %s !\n", |
Harvey Harrison | b85d858 | 2008-04-23 09:39:01 +0800 | [diff] [blame] | 698 | __func__, ident, get_label(ident)); |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 699 | local_irq_restore_hw(flags); |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 700 | return -EBUSY; |
| 701 | } |
| 702 | |
| 703 | if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) { |
| 704 | |
Mike Frysinger | d171c23 | 2008-03-26 08:35:46 +0800 | [diff] [blame] | 705 | /* |
| 706 | * Pin functions like AMC address strobes my |
| 707 | * be requested and used by several drivers |
| 708 | */ |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 709 | |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 710 | #ifdef CONFIG_BF54x |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 711 | if (!((per & P_MAYSHARE) && get_portmux(per) == P_FUNCT2MUX(per))) { |
Mike Frysinger | 6c7ec0e | 2008-10-28 15:49:59 +0800 | [diff] [blame] | 712 | #else |
| 713 | if (!(per & P_MAYSHARE)) { |
| 714 | #endif |
Mike Frysinger | d171c23 | 2008-03-26 08:35:46 +0800 | [diff] [blame] | 715 | /* |
| 716 | * Allow that the identical pin function can |
| 717 | * be requested from the same driver twice |
| 718 | */ |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 719 | |
Mike Frysinger | d171c23 | 2008-03-26 08:35:46 +0800 | [diff] [blame] | 720 | if (cmp_label(ident, label) == 0) |
| 721 | goto anyway; |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 722 | |
Robin Getz | d6879c5 | 2009-03-29 01:10:30 +0800 | [diff] [blame] | 723 | if (system_state == SYSTEM_BOOTING) |
| 724 | dump_stack(); |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 725 | printk(KERN_ERR |
| 726 | "%s: Peripheral %d function %d is already reserved by %s !\n", |
Harvey Harrison | b85d858 | 2008-04-23 09:39:01 +0800 | [diff] [blame] | 727 | __func__, ident, P_FUNCT2MUX(per), get_label(ident)); |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 728 | local_irq_restore_hw(flags); |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 729 | return -EBUSY; |
| 730 | } |
| 731 | } |
| 732 | |
Mike Frysinger | d171c23 | 2008-03-26 08:35:46 +0800 | [diff] [blame] | 733 | anyway: |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 734 | reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident); |
| 735 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 736 | portmux_setup(per); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 737 | port_setup(ident, PERIPHERAL_USAGE); |
| 738 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 739 | local_irq_restore_hw(flags); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 740 | set_label(ident, label); |
| 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | EXPORT_SYMBOL(peripheral_request); |
| 745 | |
Mike Frysinger | 6817937 | 2008-04-24 05:04:24 +0800 | [diff] [blame] | 746 | int peripheral_request_list(const unsigned short per[], const char *label) |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 747 | { |
| 748 | u16 cnt; |
| 749 | int ret; |
| 750 | |
| 751 | for (cnt = 0; per[cnt] != 0; cnt++) { |
Michael Hennerich | 314c98d | 2007-07-24 18:03:45 +0800 | [diff] [blame] | 752 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 753 | ret = peripheral_request(per[cnt], label); |
Michael Hennerich | 314c98d | 2007-07-24 18:03:45 +0800 | [diff] [blame] | 754 | |
| 755 | if (ret < 0) { |
Mike Frysinger | d171c23 | 2008-03-26 08:35:46 +0800 | [diff] [blame] | 756 | for ( ; cnt > 0; cnt--) |
Michael Hennerich | 314c98d | 2007-07-24 18:03:45 +0800 | [diff] [blame] | 757 | peripheral_free(per[cnt - 1]); |
Mike Frysinger | d171c23 | 2008-03-26 08:35:46 +0800 | [diff] [blame] | 758 | |
| 759 | return ret; |
Michael Hennerich | 314c98d | 2007-07-24 18:03:45 +0800 | [diff] [blame] | 760 | } |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | return 0; |
| 764 | } |
| 765 | EXPORT_SYMBOL(peripheral_request_list); |
| 766 | |
| 767 | void peripheral_free(unsigned short per) |
| 768 | { |
| 769 | unsigned long flags; |
| 770 | unsigned short ident = P_IDENT(per); |
| 771 | |
| 772 | if (per & P_DONTCARE) |
| 773 | return; |
| 774 | |
| 775 | if (!(per & P_DEFINED)) |
| 776 | return; |
| 777 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 778 | local_irq_save_hw(flags); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 779 | |
Mike Frysinger | d171c23 | 2008-03-26 08:35:46 +0800 | [diff] [blame] | 780 | if (unlikely(!(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident)))) { |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 781 | local_irq_restore_hw(flags); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 782 | return; |
| 783 | } |
| 784 | |
Mike Frysinger | d171c23 | 2008-03-26 08:35:46 +0800 | [diff] [blame] | 785 | if (!(per & P_MAYSHARE)) |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 786 | port_setup(ident, GPIO_USAGE); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 787 | |
| 788 | reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident); |
| 789 | |
Michael Hennerich | 2acde90 | 2007-10-11 00:24:40 +0800 | [diff] [blame] | 790 | set_label(ident, "free"); |
| 791 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 792 | local_irq_restore_hw(flags); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 793 | } |
| 794 | EXPORT_SYMBOL(peripheral_free); |
| 795 | |
Mike Frysinger | 6817937 | 2008-04-24 05:04:24 +0800 | [diff] [blame] | 796 | void peripheral_free_list(const unsigned short per[]) |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 797 | { |
| 798 | u16 cnt; |
Mike Frysinger | d171c23 | 2008-03-26 08:35:46 +0800 | [diff] [blame] | 799 | for (cnt = 0; per[cnt] != 0; cnt++) |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 800 | peripheral_free(per[cnt]); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 801 | } |
| 802 | EXPORT_SYMBOL(peripheral_free_list); |
| 803 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 804 | /*********************************************************** |
| 805 | * |
| 806 | * FUNCTIONS: Blackfin GPIO Driver |
| 807 | * |
| 808 | * INPUTS/OUTPUTS: |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 809 | * gpio PIO Number between 0 and MAX_BLACKFIN_GPIOS |
| 810 | * label String |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 811 | * |
| 812 | * DESCRIPTION: Blackfin GPIO Driver API |
| 813 | * |
| 814 | * CAUTION: |
| 815 | ************************************************************* |
| 816 | * MODIFICATION HISTORY : |
| 817 | **************************************************************/ |
| 818 | |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 819 | int bfin_gpio_request(unsigned gpio, const char *label) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 820 | { |
| 821 | unsigned long flags; |
| 822 | |
| 823 | if (check_gpio(gpio) < 0) |
| 824 | return -EINVAL; |
| 825 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 826 | local_irq_save_hw(flags); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 827 | |
Michael Hennerich | 2acde90 | 2007-10-11 00:24:40 +0800 | [diff] [blame] | 828 | /* |
| 829 | * Allow that the identical GPIO can |
| 830 | * be requested from the same driver twice |
| 831 | * Do nothing and return - |
| 832 | */ |
| 833 | |
| 834 | if (cmp_label(gpio, label) == 0) { |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 835 | local_irq_restore_hw(flags); |
Michael Hennerich | 2acde90 | 2007-10-11 00:24:40 +0800 | [diff] [blame] | 836 | return 0; |
| 837 | } |
| 838 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 839 | if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { |
Robin Getz | d6879c5 | 2009-03-29 01:10:30 +0800 | [diff] [blame] | 840 | if (system_state == SYSTEM_BOOTING) |
| 841 | dump_stack(); |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 842 | printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n", |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 843 | gpio, get_label(gpio)); |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 844 | local_irq_restore_hw(flags); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 845 | return -EBUSY; |
| 846 | } |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 847 | if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) { |
Robin Getz | d6879c5 | 2009-03-29 01:10:30 +0800 | [diff] [blame] | 848 | if (system_state == SYSTEM_BOOTING) |
| 849 | dump_stack(); |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 850 | printk(KERN_ERR |
| 851 | "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n", |
| 852 | gpio, get_label(gpio)); |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 853 | local_irq_restore_hw(flags); |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 854 | return -EBUSY; |
| 855 | } |
Michael Hennerich | a2be393 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 856 | if (unlikely(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio))) { |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 857 | printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved as gpio-irq!" |
| 858 | " (Documentation/blackfin/bfin-gpio-notes.txt)\n", gpio); |
Michael Hennerich | a2be393 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 859 | } |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 860 | #ifndef CONFIG_BF54x |
Michael Hennerich | a2be393 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 861 | else { /* Reset POLAR setting when acquiring a gpio for the first time */ |
| 862 | set_gpio_polar(gpio, 0); |
| 863 | } |
| 864 | #endif |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 865 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 866 | reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio); |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 867 | set_label(gpio, label); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 868 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 869 | local_irq_restore_hw(flags); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 870 | |
| 871 | port_setup(gpio, GPIO_USAGE); |
| 872 | |
| 873 | return 0; |
| 874 | } |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 875 | EXPORT_SYMBOL(bfin_gpio_request); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 876 | |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 877 | void bfin_gpio_free(unsigned gpio) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 878 | { |
| 879 | unsigned long flags; |
| 880 | |
| 881 | if (check_gpio(gpio) < 0) |
| 882 | return; |
| 883 | |
Uwe Kleine-Koenig | 45c4f2a | 2009-02-04 17:02:30 +0800 | [diff] [blame] | 884 | might_sleep(); |
| 885 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 886 | local_irq_save_hw(flags); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 887 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 888 | if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) { |
Robin Getz | d6879c5 | 2009-03-29 01:10:30 +0800 | [diff] [blame] | 889 | if (system_state == SYSTEM_BOOTING) |
| 890 | dump_stack(); |
Mike Frysinger | f85c4ab | 2008-03-26 08:34:23 +0800 | [diff] [blame] | 891 | gpio_error(gpio); |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 892 | local_irq_restore_hw(flags); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 893 | return; |
| 894 | } |
| 895 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 896 | reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 897 | |
Michael Hennerich | 2acde90 | 2007-10-11 00:24:40 +0800 | [diff] [blame] | 898 | set_label(gpio, "free"); |
| 899 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 900 | local_irq_restore_hw(flags); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 901 | } |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 902 | EXPORT_SYMBOL(bfin_gpio_free); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 903 | |
Michael Hennerich | 621dd24 | 2009-09-28 12:23:41 +0000 | [diff] [blame] | 904 | #ifdef BFIN_SPECIAL_GPIO_BANKS |
| 905 | static unsigned short reserved_special_gpio_map[gpio_bank(MAX_RESOURCES)]; |
| 906 | |
| 907 | int bfin_special_gpio_request(unsigned gpio, const char *label) |
| 908 | { |
| 909 | unsigned long flags; |
| 910 | |
| 911 | local_irq_save_hw(flags); |
| 912 | |
| 913 | /* |
| 914 | * Allow that the identical GPIO can |
| 915 | * be requested from the same driver twice |
| 916 | * Do nothing and return - |
| 917 | */ |
| 918 | |
| 919 | if (cmp_label(gpio, label) == 0) { |
| 920 | local_irq_restore_hw(flags); |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | if (unlikely(reserved_special_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { |
| 925 | local_irq_restore_hw(flags); |
| 926 | printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n", |
| 927 | gpio, get_label(gpio)); |
| 928 | |
| 929 | return -EBUSY; |
| 930 | } |
| 931 | if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) { |
| 932 | local_irq_restore_hw(flags); |
| 933 | printk(KERN_ERR |
| 934 | "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n", |
| 935 | gpio, get_label(gpio)); |
| 936 | |
| 937 | return -EBUSY; |
| 938 | } |
| 939 | |
| 940 | reserved_special_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio); |
| 941 | reserved_peri_map[gpio_bank(gpio)] |= gpio_bit(gpio); |
| 942 | |
| 943 | set_label(gpio, label); |
| 944 | local_irq_restore_hw(flags); |
| 945 | port_setup(gpio, GPIO_USAGE); |
| 946 | |
| 947 | return 0; |
| 948 | } |
| 949 | EXPORT_SYMBOL(bfin_special_gpio_request); |
| 950 | |
| 951 | void bfin_special_gpio_free(unsigned gpio) |
| 952 | { |
| 953 | unsigned long flags; |
| 954 | |
| 955 | might_sleep(); |
| 956 | |
| 957 | local_irq_save_hw(flags); |
| 958 | |
| 959 | if (unlikely(!(reserved_special_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) { |
| 960 | gpio_error(gpio); |
| 961 | local_irq_restore_hw(flags); |
| 962 | return; |
| 963 | } |
| 964 | |
| 965 | reserved_special_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); |
| 966 | reserved_peri_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); |
| 967 | set_label(gpio, "free"); |
| 968 | local_irq_restore_hw(flags); |
| 969 | } |
| 970 | EXPORT_SYMBOL(bfin_special_gpio_free); |
| 971 | #endif |
| 972 | |
| 973 | |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 974 | int bfin_gpio_irq_request(unsigned gpio, const char *label) |
| 975 | { |
| 976 | unsigned long flags; |
| 977 | |
| 978 | if (check_gpio(gpio) < 0) |
| 979 | return -EINVAL; |
| 980 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 981 | local_irq_save_hw(flags); |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 982 | |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 983 | if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) { |
Robin Getz | d6879c5 | 2009-03-29 01:10:30 +0800 | [diff] [blame] | 984 | if (system_state == SYSTEM_BOOTING) |
| 985 | dump_stack(); |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 986 | printk(KERN_ERR |
| 987 | "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n", |
| 988 | gpio, get_label(gpio)); |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 989 | local_irq_restore_hw(flags); |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 990 | return -EBUSY; |
| 991 | } |
| 992 | if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) |
| 993 | printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved by %s! " |
| 994 | "(Documentation/blackfin/bfin-gpio-notes.txt)\n", |
| 995 | gpio, get_label(gpio)); |
| 996 | |
| 997 | reserved_gpio_irq_map[gpio_bank(gpio)] |= gpio_bit(gpio); |
| 998 | set_label(gpio, label); |
| 999 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 1000 | local_irq_restore_hw(flags); |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 1001 | |
| 1002 | port_setup(gpio, GPIO_USAGE); |
| 1003 | |
| 1004 | return 0; |
| 1005 | } |
| 1006 | |
| 1007 | void bfin_gpio_irq_free(unsigned gpio) |
| 1008 | { |
| 1009 | unsigned long flags; |
| 1010 | |
| 1011 | if (check_gpio(gpio) < 0) |
| 1012 | return; |
| 1013 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 1014 | local_irq_save_hw(flags); |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 1015 | |
| 1016 | if (unlikely(!(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio)))) { |
Robin Getz | d6879c5 | 2009-03-29 01:10:30 +0800 | [diff] [blame] | 1017 | if (system_state == SYSTEM_BOOTING) |
| 1018 | dump_stack(); |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 1019 | gpio_error(gpio); |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 1020 | local_irq_restore_hw(flags); |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 1021 | return; |
| 1022 | } |
| 1023 | |
| 1024 | reserved_gpio_irq_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); |
| 1025 | |
| 1026 | set_label(gpio, "free"); |
| 1027 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 1028 | local_irq_restore_hw(flags); |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 1029 | } |
| 1030 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1031 | static inline void __bfin_gpio_direction_input(unsigned gpio) |
| 1032 | { |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 1033 | #ifdef CONFIG_BF54x |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1034 | gpio_array[gpio_bank(gpio)]->dir_clear = gpio_bit(gpio); |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 1035 | #else |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1036 | gpio_array[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio); |
| 1037 | #endif |
| 1038 | gpio_array[gpio_bank(gpio)]->inen |= gpio_bit(gpio); |
Michael Hennerich | 803a8d2 | 2008-05-17 16:01:51 +0800 | [diff] [blame] | 1039 | } |
Michael Hennerich | 803a8d2 | 2008-05-17 16:01:51 +0800 | [diff] [blame] | 1040 | |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1041 | int bfin_gpio_direction_input(unsigned gpio) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1042 | { |
| 1043 | unsigned long flags; |
| 1044 | |
Michael Hennerich | acbcd26 | 2008-01-22 18:36:20 +0800 | [diff] [blame] | 1045 | if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { |
| 1046 | gpio_error(gpio); |
| 1047 | return -EINVAL; |
| 1048 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1049 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 1050 | local_irq_save_hw(flags); |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1051 | __bfin_gpio_direction_input(gpio); |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 1052 | AWA_DUMMY_READ(inen); |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 1053 | local_irq_restore_hw(flags); |
Michael Hennerich | acbcd26 | 2008-01-22 18:36:20 +0800 | [diff] [blame] | 1054 | |
| 1055 | return 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1056 | } |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1057 | EXPORT_SYMBOL(bfin_gpio_direction_input); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1058 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1059 | void bfin_gpio_irq_prepare(unsigned gpio) |
| 1060 | { |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 1061 | #ifdef CONFIG_BF54x |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1062 | unsigned long flags; |
| 1063 | #endif |
| 1064 | |
| 1065 | port_setup(gpio, GPIO_USAGE); |
| 1066 | |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 1067 | #ifdef CONFIG_BF54x |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1068 | local_irq_save_hw(flags); |
| 1069 | __bfin_gpio_direction_input(gpio); |
| 1070 | local_irq_restore_hw(flags); |
| 1071 | #endif |
| 1072 | } |
| 1073 | |
| 1074 | void bfin_gpio_set_value(unsigned gpio, int arg) |
| 1075 | { |
| 1076 | if (arg) |
| 1077 | gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio); |
| 1078 | else |
| 1079 | gpio_array[gpio_bank(gpio)]->data_clear = gpio_bit(gpio); |
| 1080 | } |
| 1081 | EXPORT_SYMBOL(bfin_gpio_set_value); |
| 1082 | |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1083 | int bfin_gpio_direction_output(unsigned gpio, int value) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1084 | { |
| 1085 | unsigned long flags; |
| 1086 | |
Michael Hennerich | acbcd26 | 2008-01-22 18:36:20 +0800 | [diff] [blame] | 1087 | if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { |
| 1088 | gpio_error(gpio); |
| 1089 | return -EINVAL; |
| 1090 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1091 | |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 1092 | local_irq_save_hw(flags); |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 1093 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1094 | gpio_array[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio); |
| 1095 | gpio_set_value(gpio, value); |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 1096 | #ifdef CONFIG_BF54x |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1097 | gpio_array[gpio_bank(gpio)]->dir_set = gpio_bit(gpio); |
| 1098 | #else |
| 1099 | gpio_array[gpio_bank(gpio)]->dir |= gpio_bit(gpio); |
| 1100 | #endif |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 1101 | |
Michael Hennerich | 2b39331 | 2007-10-10 16:58:49 +0800 | [diff] [blame] | 1102 | AWA_DUMMY_READ(dir); |
Yi Li | 6a01f23 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 1103 | local_irq_restore_hw(flags); |
Michael Hennerich | acbcd26 | 2008-01-22 18:36:20 +0800 | [diff] [blame] | 1104 | |
| 1105 | return 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1106 | } |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1107 | EXPORT_SYMBOL(bfin_gpio_direction_output); |
Mike Frysinger | 168f121 | 2007-10-11 00:22:35 +0800 | [diff] [blame] | 1108 | |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1109 | int bfin_gpio_get_value(unsigned gpio) |
| 1110 | { |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 1111 | #ifdef CONFIG_BF54x |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1112 | return (1 & (gpio_array[gpio_bank(gpio)]->data >> gpio_sub_n(gpio))); |
| 1113 | #else |
| 1114 | unsigned long flags; |
| 1115 | |
| 1116 | if (unlikely(get_gpio_edge(gpio))) { |
| 1117 | int ret; |
| 1118 | local_irq_save_hw(flags); |
| 1119 | set_gpio_edge(gpio, 0); |
| 1120 | ret = get_gpio_data(gpio); |
| 1121 | set_gpio_edge(gpio, 1); |
| 1122 | local_irq_restore_hw(flags); |
| 1123 | return ret; |
| 1124 | } else |
| 1125 | return get_gpio_data(gpio); |
| 1126 | #endif |
| 1127 | } |
| 1128 | EXPORT_SYMBOL(bfin_gpio_get_value); |
| 1129 | |
Mike Frysinger | 168f121 | 2007-10-11 00:22:35 +0800 | [diff] [blame] | 1130 | /* If we are booting from SPI and our board lacks a strong enough pull up, |
| 1131 | * the core can reset and execute the bootrom faster than the resistor can |
| 1132 | * pull the signal logically high. To work around this (common) error in |
| 1133 | * board design, we explicitly set the pin back to GPIO mode, force /CS |
| 1134 | * high, and wait for the electrons to do their thing. |
| 1135 | * |
| 1136 | * This function only makes sense to be called from reset code, but it |
| 1137 | * lives here as we need to force all the GPIO states w/out going through |
| 1138 | * BUG() checks and such. |
| 1139 | */ |
Sonic Zhang | b52dae3 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1140 | void bfin_reset_boot_spi_cs(unsigned short pin) |
Mike Frysinger | 168f121 | 2007-10-11 00:22:35 +0800 | [diff] [blame] | 1141 | { |
Sonic Zhang | b52dae3 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1142 | unsigned short gpio = P_IDENT(pin); |
Michael Hennerich | 4d5f4ed | 2007-08-27 16:46:17 +0800 | [diff] [blame] | 1143 | port_setup(gpio, GPIO_USAGE); |
Mike Frysinger | f556309 | 2009-02-04 16:49:45 +0800 | [diff] [blame] | 1144 | gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio); |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 1145 | AWA_DUMMY_READ(data_set); |
Mike Frysinger | 168f121 | 2007-10-11 00:22:35 +0800 | [diff] [blame] | 1146 | udelay(1); |
| 1147 | } |
Michael Hennerich | d2b11a4 | 2007-08-28 16:47:46 +0800 | [diff] [blame] | 1148 | |
Mike Frysinger | 1545a11 | 2007-12-24 16:54:48 +0800 | [diff] [blame] | 1149 | #if defined(CONFIG_PROC_FS) |
| 1150 | static int gpio_proc_read(char *buf, char **start, off_t offset, |
| 1151 | int len, int *unused_i, void *unused_v) |
| 1152 | { |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 1153 | int c, irq, gpio, outlen = 0; |
Mike Frysinger | 1545a11 | 2007-12-24 16:54:48 +0800 | [diff] [blame] | 1154 | |
| 1155 | for (c = 0; c < MAX_RESOURCES; c++) { |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 1156 | irq = reserved_gpio_irq_map[gpio_bank(c)] & gpio_bit(c); |
| 1157 | gpio = reserved_gpio_map[gpio_bank(c)] & gpio_bit(c); |
| 1158 | if (!check_gpio(c) && (gpio || irq)) |
| 1159 | len = sprintf(buf, "GPIO_%d: \t%s%s \t\tGPIO %s\n", c, |
| 1160 | get_label(c), (gpio && irq) ? " *" : "", |
| 1161 | get_gpio_dir(c) ? "OUTPUT" : "INPUT"); |
Mike Frysinger | 1545a11 | 2007-12-24 16:54:48 +0800 | [diff] [blame] | 1162 | else if (reserved_peri_map[gpio_bank(c)] & gpio_bit(c)) |
Graf Yang | 8eb3e3b | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1163 | len = sprintf(buf, "GPIO_%d: \t%s \t\tPeripheral\n", c, get_label(c)); |
Mike Frysinger | 1545a11 | 2007-12-24 16:54:48 +0800 | [diff] [blame] | 1164 | else |
| 1165 | continue; |
| 1166 | buf += len; |
| 1167 | outlen += len; |
| 1168 | } |
| 1169 | return outlen; |
| 1170 | } |
| 1171 | |
| 1172 | static __init int gpio_register_proc(void) |
| 1173 | { |
| 1174 | struct proc_dir_entry *proc_gpio; |
| 1175 | |
| 1176 | proc_gpio = create_proc_entry("gpio", S_IRUGO, NULL); |
| 1177 | if (proc_gpio) |
| 1178 | proc_gpio->read_proc = gpio_proc_read; |
| 1179 | return proc_gpio != NULL; |
| 1180 | } |
Mike Frysinger | 1545a11 | 2007-12-24 16:54:48 +0800 | [diff] [blame] | 1181 | __initcall(gpio_register_proc); |
| 1182 | #endif |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1183 | |
| 1184 | #ifdef CONFIG_GPIOLIB |
Joachim Eastwood | f9c29e8 | 2010-02-11 12:41:11 +0100 | [diff] [blame] | 1185 | static int bfin_gpiolib_direction_input(struct gpio_chip *chip, unsigned gpio) |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1186 | { |
| 1187 | return bfin_gpio_direction_input(gpio); |
| 1188 | } |
| 1189 | |
Joachim Eastwood | f9c29e8 | 2010-02-11 12:41:11 +0100 | [diff] [blame] | 1190 | static int bfin_gpiolib_direction_output(struct gpio_chip *chip, unsigned gpio, int level) |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1191 | { |
| 1192 | return bfin_gpio_direction_output(gpio, level); |
| 1193 | } |
| 1194 | |
Joachim Eastwood | f9c29e8 | 2010-02-11 12:41:11 +0100 | [diff] [blame] | 1195 | static int bfin_gpiolib_get_value(struct gpio_chip *chip, unsigned gpio) |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1196 | { |
| 1197 | return bfin_gpio_get_value(gpio); |
| 1198 | } |
| 1199 | |
Joachim Eastwood | f9c29e8 | 2010-02-11 12:41:11 +0100 | [diff] [blame] | 1200 | static void bfin_gpiolib_set_value(struct gpio_chip *chip, unsigned gpio, int value) |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1201 | { |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1202 | return bfin_gpio_set_value(gpio, value); |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1203 | } |
| 1204 | |
Joachim Eastwood | f9c29e8 | 2010-02-11 12:41:11 +0100 | [diff] [blame] | 1205 | static int bfin_gpiolib_gpio_request(struct gpio_chip *chip, unsigned gpio) |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1206 | { |
| 1207 | return bfin_gpio_request(gpio, chip->label); |
| 1208 | } |
| 1209 | |
Joachim Eastwood | f9c29e8 | 2010-02-11 12:41:11 +0100 | [diff] [blame] | 1210 | static void bfin_gpiolib_gpio_free(struct gpio_chip *chip, unsigned gpio) |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1211 | { |
| 1212 | return bfin_gpio_free(gpio); |
| 1213 | } |
| 1214 | |
Joachim Eastwood | f9c29e8 | 2010-02-11 12:41:11 +0100 | [diff] [blame] | 1215 | static int bfin_gpiolib_gpio_to_irq(struct gpio_chip *chip, unsigned gpio) |
Joachim Eastwood | 7f4f69f | 2010-02-10 12:31:41 +0100 | [diff] [blame] | 1216 | { |
| 1217 | return gpio + GPIO_IRQ_BASE; |
| 1218 | } |
| 1219 | |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1220 | static struct gpio_chip bfin_chip = { |
Michael Hennerich | edd0799 | 2009-12-16 08:45:17 +0000 | [diff] [blame] | 1221 | .label = "BFIN-GPIO", |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1222 | .direction_input = bfin_gpiolib_direction_input, |
| 1223 | .get = bfin_gpiolib_get_value, |
| 1224 | .direction_output = bfin_gpiolib_direction_output, |
| 1225 | .set = bfin_gpiolib_set_value, |
| 1226 | .request = bfin_gpiolib_gpio_request, |
| 1227 | .free = bfin_gpiolib_gpio_free, |
Joachim Eastwood | 7f4f69f | 2010-02-10 12:31:41 +0100 | [diff] [blame] | 1228 | .to_irq = bfin_gpiolib_gpio_to_irq, |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1229 | .base = 0, |
| 1230 | .ngpio = MAX_BLACKFIN_GPIOS, |
| 1231 | }; |
| 1232 | |
| 1233 | static int __init bfin_gpiolib_setup(void) |
| 1234 | { |
| 1235 | return gpiochip_add(&bfin_chip); |
| 1236 | } |
| 1237 | arch_initcall(bfin_gpiolib_setup); |
| 1238 | #endif |