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