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: |
| 10 | * Copyright 2006 Analog Devices Inc. |
| 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 | /* |
| 31 | * Number BF537/6/4 BF561 BF533/2/1 |
| 32 | * |
| 33 | * GPIO_0 PF0 PF0 PF0 |
| 34 | * GPIO_1 PF1 PF1 PF1 |
| 35 | * GPIO_2 PF2 PF2 PF2 |
| 36 | * GPIO_3 PF3 PF3 PF3 |
| 37 | * GPIO_4 PF4 PF4 PF4 |
| 38 | * GPIO_5 PF5 PF5 PF5 |
| 39 | * GPIO_6 PF6 PF6 PF6 |
| 40 | * GPIO_7 PF7 PF7 PF7 |
| 41 | * GPIO_8 PF8 PF8 PF8 |
| 42 | * GPIO_9 PF9 PF9 PF9 |
| 43 | * GPIO_10 PF10 PF10 PF10 |
| 44 | * GPIO_11 PF11 PF11 PF11 |
| 45 | * GPIO_12 PF12 PF12 PF12 |
| 46 | * GPIO_13 PF13 PF13 PF13 |
| 47 | * GPIO_14 PF14 PF14 PF14 |
| 48 | * GPIO_15 PF15 PF15 PF15 |
| 49 | * GPIO_16 PG0 PF16 |
| 50 | * GPIO_17 PG1 PF17 |
| 51 | * GPIO_18 PG2 PF18 |
| 52 | * GPIO_19 PG3 PF19 |
| 53 | * GPIO_20 PG4 PF20 |
| 54 | * GPIO_21 PG5 PF21 |
| 55 | * GPIO_22 PG6 PF22 |
| 56 | * GPIO_23 PG7 PF23 |
| 57 | * GPIO_24 PG8 PF24 |
| 58 | * GPIO_25 PG9 PF25 |
| 59 | * GPIO_26 PG10 PF26 |
| 60 | * GPIO_27 PG11 PF27 |
| 61 | * GPIO_28 PG12 PF28 |
| 62 | * GPIO_29 PG13 PF29 |
| 63 | * GPIO_30 PG14 PF30 |
| 64 | * GPIO_31 PG15 PF31 |
| 65 | * GPIO_32 PH0 PF32 |
| 66 | * GPIO_33 PH1 PF33 |
| 67 | * GPIO_34 PH2 PF34 |
| 68 | * GPIO_35 PH3 PF35 |
| 69 | * GPIO_36 PH4 PF36 |
| 70 | * GPIO_37 PH5 PF37 |
| 71 | * GPIO_38 PH6 PF38 |
| 72 | * GPIO_39 PH7 PF39 |
| 73 | * GPIO_40 PH8 PF40 |
| 74 | * GPIO_41 PH9 PF41 |
| 75 | * GPIO_42 PH10 PF42 |
| 76 | * GPIO_43 PH11 PF43 |
| 77 | * GPIO_44 PH12 PF44 |
| 78 | * GPIO_45 PH13 PF45 |
| 79 | * GPIO_46 PH14 PF46 |
| 80 | * GPIO_47 PH15 PF47 |
| 81 | */ |
| 82 | |
| 83 | #include <linux/module.h> |
| 84 | #include <linux/err.h> |
| 85 | #include <asm/blackfin.h> |
| 86 | #include <asm/gpio.h> |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 87 | #include <asm/portmux.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 88 | #include <linux/irq.h> |
| 89 | |
| 90 | #ifdef BF533_FAMILY |
| 91 | static struct gpio_port_t *gpio_bankb[gpio_bank(MAX_BLACKFIN_GPIOS)] = { |
| 92 | (struct gpio_port_t *) FIO_FLAG_D, |
| 93 | }; |
| 94 | #endif |
| 95 | |
| 96 | #ifdef BF537_FAMILY |
| 97 | static struct gpio_port_t *gpio_bankb[gpio_bank(MAX_BLACKFIN_GPIOS)] = { |
| 98 | (struct gpio_port_t *) PORTFIO, |
| 99 | (struct gpio_port_t *) PORTGIO, |
| 100 | (struct gpio_port_t *) PORTHIO, |
| 101 | }; |
| 102 | |
| 103 | static unsigned short *port_fer[gpio_bank(MAX_BLACKFIN_GPIOS)] = { |
| 104 | (unsigned short *) PORTF_FER, |
| 105 | (unsigned short *) PORTG_FER, |
| 106 | (unsigned short *) PORTH_FER, |
| 107 | }; |
| 108 | |
| 109 | #endif |
| 110 | |
| 111 | #ifdef BF561_FAMILY |
| 112 | static struct gpio_port_t *gpio_bankb[gpio_bank(MAX_BLACKFIN_GPIOS)] = { |
| 113 | (struct gpio_port_t *) FIO0_FLAG_D, |
| 114 | (struct gpio_port_t *) FIO1_FLAG_D, |
| 115 | (struct gpio_port_t *) FIO2_FLAG_D, |
| 116 | }; |
| 117 | #endif |
| 118 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 119 | static unsigned short reserved_gpio_map[gpio_bank(MAX_BLACKFIN_GPIOS)]; |
| 120 | static unsigned short reserved_peri_map[gpio_bank(MAX_BLACKFIN_GPIOS + 16)]; |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 121 | |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame^] | 122 | #define MAX_RESOURCES 256 |
| 123 | #define RESOURCE_LABEL_SIZE 16 |
| 124 | |
| 125 | struct str_ident { |
| 126 | char name[RESOURCE_LABEL_SIZE]; |
| 127 | } *str_ident; |
| 128 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 129 | |
| 130 | #ifdef CONFIG_PM |
| 131 | static unsigned short wakeup_map[gpio_bank(MAX_BLACKFIN_GPIOS)]; |
| 132 | static unsigned char wakeup_flags_map[MAX_BLACKFIN_GPIOS]; |
| 133 | static struct gpio_port_s gpio_bank_saved[gpio_bank(MAX_BLACKFIN_GPIOS)]; |
| 134 | |
| 135 | #ifdef BF533_FAMILY |
| 136 | static unsigned int sic_iwr_irqs[gpio_bank(MAX_BLACKFIN_GPIOS)] = {IRQ_PROG_INTB}; |
| 137 | #endif |
| 138 | |
| 139 | #ifdef BF537_FAMILY |
| 140 | static unsigned int sic_iwr_irqs[gpio_bank(MAX_BLACKFIN_GPIOS)] = {IRQ_PROG_INTB, IRQ_PORTG_INTB, IRQ_MAC_TX}; |
| 141 | #endif |
| 142 | |
| 143 | #ifdef BF561_FAMILY |
| 144 | static unsigned int sic_iwr_irqs[gpio_bank(MAX_BLACKFIN_GPIOS)] = {IRQ_PROG0_INTB, IRQ_PROG1_INTB, IRQ_PROG2_INTB}; |
| 145 | #endif |
| 146 | |
| 147 | #endif /* CONFIG_PM */ |
| 148 | |
| 149 | inline int check_gpio(unsigned short gpio) |
| 150 | { |
Michael Hennerich | e7613aa | 2007-06-11 16:37:57 +0800 | [diff] [blame] | 151 | if (gpio >= MAX_BLACKFIN_GPIOS) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 152 | return -EINVAL; |
| 153 | return 0; |
| 154 | } |
| 155 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 156 | static void set_label(unsigned short ident, const char *label) |
| 157 | { |
| 158 | |
| 159 | if (label && str_ident) { |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame^] | 160 | strncpy(str_ident[ident].name, label, |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 161 | RESOURCE_LABEL_SIZE); |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame^] | 162 | str_ident[ident].name[RESOURCE_LABEL_SIZE - 1] = 0; |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | static char *get_label(unsigned short ident) |
| 167 | { |
| 168 | if (!str_ident) |
| 169 | return "UNKNOWN"; |
| 170 | |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame^] | 171 | return (*str_ident[ident].name ? str_ident[ident].name : "UNKNOWN"); |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static int cmp_label(unsigned short ident, const char *label) |
| 175 | { |
| 176 | if (label && str_ident) |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame^] | 177 | return strncmp(str_ident[ident].name, |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 178 | label, strlen(label)); |
| 179 | else |
| 180 | return -EINVAL; |
| 181 | } |
| 182 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 183 | #ifdef BF537_FAMILY |
Mike Frysinger | a161bb0 | 2007-05-21 18:09:14 +0800 | [diff] [blame] | 184 | static void port_setup(unsigned short gpio, unsigned short usage) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 185 | { |
Michael Hennerich | cda6a20 | 2007-10-04 00:36:18 +0800 | [diff] [blame] | 186 | if (!check_gpio(gpio)) { |
| 187 | if (usage == GPIO_USAGE) { |
| 188 | *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio); |
| 189 | } else |
| 190 | *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio); |
| 191 | SSYNC(); |
| 192 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 193 | } |
| 194 | #else |
| 195 | # define port_setup(...) do { } while (0) |
| 196 | #endif |
| 197 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 198 | #ifdef BF537_FAMILY |
| 199 | |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame^] | 200 | static struct { |
| 201 | unsigned short res; |
| 202 | unsigned short offset; |
| 203 | } port_mux_lut[] = { |
| 204 | {.res = P_PPI0_D13, .offset = 11}, |
| 205 | {.res = P_PPI0_D14, .offset = 11}, |
| 206 | {.res = P_PPI0_D15, .offset = 11}, |
| 207 | {.res = P_SPORT1_TFS, .offset = 11}, |
| 208 | {.res = P_SPORT1_TSCLK, .offset = 11}, |
| 209 | {.res = P_SPORT1_DTPRI, .offset = 11}, |
| 210 | {.res = P_PPI0_D10, .offset = 10}, |
| 211 | {.res = P_PPI0_D11, .offset = 10}, |
| 212 | {.res = P_PPI0_D12, .offset = 10}, |
| 213 | {.res = P_SPORT1_RSCLK, .offset = 10}, |
| 214 | {.res = P_SPORT1_RFS, .offset = 10}, |
| 215 | {.res = P_SPORT1_DRPRI, .offset = 10}, |
| 216 | {.res = P_PPI0_D8, .offset = 9}, |
| 217 | {.res = P_PPI0_D9, .offset = 9}, |
| 218 | {.res = P_SPORT1_DRSEC, .offset = 9}, |
| 219 | {.res = P_SPORT1_DTSEC, .offset = 9}, |
| 220 | {.res = P_TMR2, .offset = 8}, |
| 221 | {.res = P_PPI0_FS3, .offset = 8}, |
| 222 | {.res = P_TMR3, .offset = 7}, |
| 223 | {.res = P_SPI0_SSEL4, .offset = 7}, |
| 224 | {.res = P_TMR4, .offset = 6}, |
| 225 | {.res = P_SPI0_SSEL5, .offset = 6}, |
| 226 | {.res = P_TMR5, .offset = 5}, |
| 227 | {.res = P_SPI0_SSEL6, .offset = 5}, |
| 228 | {.res = P_UART1_RX, .offset = 4}, |
| 229 | {.res = P_UART1_TX, .offset = 4}, |
| 230 | {.res = P_TMR6, .offset = 4}, |
| 231 | {.res = P_TMR7, .offset = 4}, |
| 232 | {.res = P_UART0_RX, .offset = 3}, |
| 233 | {.res = P_UART0_TX, .offset = 3}, |
| 234 | {.res = P_DMAR0, .offset = 3}, |
| 235 | {.res = P_DMAR1, .offset = 3}, |
| 236 | {.res = P_SPORT0_DTSEC, .offset = 1}, |
| 237 | {.res = P_SPORT0_DRSEC, .offset = 1}, |
| 238 | {.res = P_CAN0_RX, .offset = 1}, |
| 239 | {.res = P_CAN0_TX, .offset = 1}, |
| 240 | {.res = P_SPI0_SSEL7, .offset = 1}, |
| 241 | {.res = P_SPORT0_TFS, .offset = 0}, |
| 242 | {.res = P_SPORT0_DTPRI, .offset = 0}, |
| 243 | {.res = P_SPI0_SSEL2, .offset = 0}, |
| 244 | {.res = P_SPI0_SSEL3, .offset = 0}, |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | static void portmux_setup(unsigned short per, unsigned short function) |
| 248 | { |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame^] | 249 | u16 y, offset, muxreg; |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 250 | |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame^] | 251 | for (y = 0; y < ARRAY_SIZE(port_mux_lut); y++) { |
| 252 | if (port_mux_lut[y].res == per) { |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 253 | |
| 254 | /* SET PORTMUX REG */ |
| 255 | |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame^] | 256 | offset = port_mux_lut[y].offset; |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 257 | muxreg = bfin_read_PORT_MUX(); |
| 258 | |
| 259 | if (offset != 1) { |
| 260 | muxreg &= ~(1 << offset); |
| 261 | } else { |
| 262 | muxreg &= ~(3 << 1); |
| 263 | } |
| 264 | |
| 265 | muxreg |= (function << offset); |
| 266 | bfin_write_PORT_MUX(muxreg); |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | #else |
| 272 | # define portmux_setup(...) do { } while (0) |
| 273 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 274 | |
Mike Frysinger | a161bb0 | 2007-05-21 18:09:14 +0800 | [diff] [blame] | 275 | static void default_gpio(unsigned short gpio) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 276 | { |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 277 | unsigned short bank, bitmask; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 278 | |
| 279 | bank = gpio_bank(gpio); |
| 280 | bitmask = gpio_bit(gpio); |
| 281 | |
| 282 | gpio_bankb[bank]->maska_clear = bitmask; |
| 283 | gpio_bankb[bank]->maskb_clear = bitmask; |
| 284 | SSYNC(); |
| 285 | gpio_bankb[bank]->inen &= ~bitmask; |
| 286 | gpio_bankb[bank]->dir &= ~bitmask; |
| 287 | gpio_bankb[bank]->polar &= ~bitmask; |
| 288 | gpio_bankb[bank]->both &= ~bitmask; |
| 289 | gpio_bankb[bank]->edge &= ~bitmask; |
| 290 | } |
| 291 | |
Mike Frysinger | a161bb0 | 2007-05-21 18:09:14 +0800 | [diff] [blame] | 292 | static int __init bfin_gpio_init(void) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 293 | { |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame^] | 294 | str_ident = kcalloc(MAX_RESOURCES, |
| 295 | sizeof(struct str_ident), GFP_KERNEL); |
| 296 | if (str_ident == NULL) |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 297 | return -ENOMEM; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 298 | |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame^] | 299 | memset(str_ident, 0, MAX_RESOURCES * sizeof(struct str_ident)); |
| 300 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 301 | printk(KERN_INFO "Blackfin GPIO Controller\n"); |
| 302 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 303 | return 0; |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 304 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 305 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 306 | arch_initcall(bfin_gpio_init); |
| 307 | |
| 308 | |
| 309 | /*********************************************************** |
| 310 | * |
| 311 | * FUNCTIONS: Blackfin General Purpose Ports Access Functions |
| 312 | * |
| 313 | * INPUTS/OUTPUTS: |
| 314 | * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS |
| 315 | * |
| 316 | * |
| 317 | * DESCRIPTION: These functions abstract direct register access |
| 318 | * to Blackfin processor General Purpose |
| 319 | * Ports Regsiters |
| 320 | * |
| 321 | * CAUTION: These functions do not belong to the GPIO Driver API |
| 322 | ************************************************************* |
| 323 | * MODIFICATION HISTORY : |
| 324 | **************************************************************/ |
| 325 | |
| 326 | /* Set a specific bit */ |
| 327 | |
| 328 | #define SET_GPIO(name) \ |
| 329 | void set_gpio_ ## name(unsigned short gpio, unsigned short arg) \ |
| 330 | { \ |
| 331 | unsigned long flags; \ |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 332 | BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))); \ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 333 | local_irq_save(flags); \ |
| 334 | if (arg) \ |
| 335 | gpio_bankb[gpio_bank(gpio)]->name |= gpio_bit(gpio); \ |
| 336 | else \ |
| 337 | gpio_bankb[gpio_bank(gpio)]->name &= ~gpio_bit(gpio); \ |
| 338 | local_irq_restore(flags); \ |
| 339 | } \ |
| 340 | EXPORT_SYMBOL(set_gpio_ ## name); |
| 341 | |
| 342 | SET_GPIO(dir) |
| 343 | SET_GPIO(inen) |
| 344 | SET_GPIO(polar) |
| 345 | SET_GPIO(edge) |
| 346 | SET_GPIO(both) |
| 347 | |
| 348 | |
| 349 | #define SET_GPIO_SC(name) \ |
| 350 | void set_gpio_ ## name(unsigned short gpio, unsigned short arg) \ |
| 351 | { \ |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 352 | BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))); \ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 353 | if (arg) \ |
| 354 | gpio_bankb[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \ |
| 355 | else \ |
| 356 | gpio_bankb[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \ |
| 357 | } \ |
| 358 | EXPORT_SYMBOL(set_gpio_ ## name); |
| 359 | |
| 360 | SET_GPIO_SC(maska) |
| 361 | SET_GPIO_SC(maskb) |
| 362 | |
Mike Frysinger | 1aafd90 | 2007-07-25 11:19:14 +0800 | [diff] [blame] | 363 | #if ANOMALY_05000311 |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 364 | void set_gpio_data(unsigned short gpio, unsigned short arg) |
| 365 | { |
| 366 | unsigned long flags; |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 367 | BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 368 | local_irq_save(flags); |
| 369 | if (arg) |
| 370 | gpio_bankb[gpio_bank(gpio)]->data_set = gpio_bit(gpio); |
| 371 | else |
| 372 | gpio_bankb[gpio_bank(gpio)]->data_clear = gpio_bit(gpio); |
| 373 | bfin_read_CHIPID(); |
| 374 | local_irq_restore(flags); |
| 375 | } |
| 376 | EXPORT_SYMBOL(set_gpio_data); |
| 377 | #else |
| 378 | SET_GPIO_SC(data) |
| 379 | #endif |
| 380 | |
| 381 | |
Mike Frysinger | 1aafd90 | 2007-07-25 11:19:14 +0800 | [diff] [blame] | 382 | #if ANOMALY_05000311 |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 383 | void set_gpio_toggle(unsigned short gpio) |
| 384 | { |
| 385 | unsigned long flags; |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 386 | BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 387 | local_irq_save(flags); |
| 388 | gpio_bankb[gpio_bank(gpio)]->toggle = gpio_bit(gpio); |
| 389 | bfin_read_CHIPID(); |
| 390 | local_irq_restore(flags); |
| 391 | } |
| 392 | #else |
| 393 | void set_gpio_toggle(unsigned short gpio) |
| 394 | { |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 395 | BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 396 | gpio_bankb[gpio_bank(gpio)]->toggle = gpio_bit(gpio); |
| 397 | } |
| 398 | #endif |
| 399 | EXPORT_SYMBOL(set_gpio_toggle); |
| 400 | |
| 401 | |
| 402 | /*Set current PORT date (16-bit word)*/ |
| 403 | |
| 404 | #define SET_GPIO_P(name) \ |
| 405 | void set_gpiop_ ## name(unsigned short gpio, unsigned short arg) \ |
| 406 | { \ |
| 407 | gpio_bankb[gpio_bank(gpio)]->name = arg; \ |
| 408 | } \ |
| 409 | EXPORT_SYMBOL(set_gpiop_ ## name); |
| 410 | |
| 411 | SET_GPIO_P(dir) |
| 412 | SET_GPIO_P(inen) |
| 413 | SET_GPIO_P(polar) |
| 414 | SET_GPIO_P(edge) |
| 415 | SET_GPIO_P(both) |
| 416 | SET_GPIO_P(maska) |
| 417 | SET_GPIO_P(maskb) |
| 418 | |
| 419 | |
Mike Frysinger | 1aafd90 | 2007-07-25 11:19:14 +0800 | [diff] [blame] | 420 | #if ANOMALY_05000311 |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 421 | void set_gpiop_data(unsigned short gpio, unsigned short arg) |
| 422 | { |
| 423 | unsigned long flags; |
| 424 | local_irq_save(flags); |
| 425 | gpio_bankb[gpio_bank(gpio)]->data = arg; |
| 426 | bfin_read_CHIPID(); |
| 427 | local_irq_restore(flags); |
| 428 | } |
| 429 | EXPORT_SYMBOL(set_gpiop_data); |
| 430 | #else |
| 431 | SET_GPIO_P(data) |
| 432 | #endif |
| 433 | |
| 434 | |
| 435 | |
| 436 | /* Get a specific bit */ |
| 437 | |
| 438 | #define GET_GPIO(name) \ |
| 439 | unsigned short get_gpio_ ## name(unsigned short gpio) \ |
| 440 | { \ |
| 441 | return (0x01 & (gpio_bankb[gpio_bank(gpio)]->name >> gpio_sub_n(gpio))); \ |
| 442 | } \ |
| 443 | EXPORT_SYMBOL(get_gpio_ ## name); |
| 444 | |
| 445 | GET_GPIO(dir) |
| 446 | GET_GPIO(inen) |
| 447 | GET_GPIO(polar) |
| 448 | GET_GPIO(edge) |
| 449 | GET_GPIO(both) |
| 450 | GET_GPIO(maska) |
| 451 | GET_GPIO(maskb) |
| 452 | |
| 453 | |
Mike Frysinger | 1aafd90 | 2007-07-25 11:19:14 +0800 | [diff] [blame] | 454 | #if ANOMALY_05000311 |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 455 | unsigned short get_gpio_data(unsigned short gpio) |
| 456 | { |
| 457 | unsigned long flags; |
| 458 | unsigned short ret; |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 459 | BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 460 | local_irq_save(flags); |
| 461 | ret = 0x01 & (gpio_bankb[gpio_bank(gpio)]->data >> gpio_sub_n(gpio)); |
| 462 | bfin_read_CHIPID(); |
| 463 | local_irq_restore(flags); |
| 464 | return ret; |
| 465 | } |
| 466 | EXPORT_SYMBOL(get_gpio_data); |
| 467 | #else |
| 468 | GET_GPIO(data) |
| 469 | #endif |
| 470 | |
| 471 | /*Get current PORT date (16-bit word)*/ |
| 472 | |
| 473 | #define GET_GPIO_P(name) \ |
| 474 | unsigned short get_gpiop_ ## name(unsigned short gpio) \ |
| 475 | { \ |
| 476 | return (gpio_bankb[gpio_bank(gpio)]->name);\ |
| 477 | } \ |
| 478 | EXPORT_SYMBOL(get_gpiop_ ## name); |
| 479 | |
| 480 | GET_GPIO_P(dir) |
| 481 | GET_GPIO_P(inen) |
| 482 | GET_GPIO_P(polar) |
| 483 | GET_GPIO_P(edge) |
| 484 | GET_GPIO_P(both) |
| 485 | GET_GPIO_P(maska) |
| 486 | GET_GPIO_P(maskb) |
| 487 | |
Mike Frysinger | 1aafd90 | 2007-07-25 11:19:14 +0800 | [diff] [blame] | 488 | #if ANOMALY_05000311 |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 489 | unsigned short get_gpiop_data(unsigned short gpio) |
| 490 | { |
| 491 | unsigned long flags; |
| 492 | unsigned short ret; |
| 493 | local_irq_save(flags); |
| 494 | ret = gpio_bankb[gpio_bank(gpio)]->data; |
| 495 | bfin_read_CHIPID(); |
| 496 | local_irq_restore(flags); |
| 497 | return ret; |
| 498 | } |
| 499 | EXPORT_SYMBOL(get_gpiop_data); |
| 500 | #else |
| 501 | GET_GPIO_P(data) |
| 502 | #endif |
| 503 | |
| 504 | #ifdef CONFIG_PM |
| 505 | /*********************************************************** |
| 506 | * |
| 507 | * FUNCTIONS: Blackfin PM Setup API |
| 508 | * |
| 509 | * INPUTS/OUTPUTS: |
| 510 | * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS |
| 511 | * type - |
| 512 | * PM_WAKE_RISING |
| 513 | * PM_WAKE_FALLING |
| 514 | * PM_WAKE_HIGH |
| 515 | * PM_WAKE_LOW |
| 516 | * PM_WAKE_BOTH_EDGES |
| 517 | * |
| 518 | * DESCRIPTION: Blackfin PM Driver API |
| 519 | * |
| 520 | * CAUTION: |
| 521 | ************************************************************* |
| 522 | * MODIFICATION HISTORY : |
| 523 | **************************************************************/ |
| 524 | int gpio_pm_wakeup_request(unsigned short gpio, unsigned char type) |
| 525 | { |
| 526 | unsigned long flags; |
| 527 | |
| 528 | if ((check_gpio(gpio) < 0) || !type) |
| 529 | return -EINVAL; |
| 530 | |
| 531 | local_irq_save(flags); |
| 532 | |
| 533 | wakeup_map[gpio_bank(gpio)] |= gpio_bit(gpio); |
| 534 | wakeup_flags_map[gpio] = type; |
| 535 | local_irq_restore(flags); |
| 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | EXPORT_SYMBOL(gpio_pm_wakeup_request); |
| 540 | |
| 541 | void gpio_pm_wakeup_free(unsigned short gpio) |
| 542 | { |
| 543 | unsigned long flags; |
| 544 | |
| 545 | if (check_gpio(gpio) < 0) |
| 546 | return; |
| 547 | |
| 548 | local_irq_save(flags); |
| 549 | |
| 550 | wakeup_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); |
| 551 | |
| 552 | local_irq_restore(flags); |
| 553 | } |
| 554 | EXPORT_SYMBOL(gpio_pm_wakeup_free); |
| 555 | |
| 556 | static int bfin_gpio_wakeup_type(unsigned short gpio, unsigned char type) |
| 557 | { |
| 558 | port_setup(gpio, GPIO_USAGE); |
| 559 | set_gpio_dir(gpio, 0); |
| 560 | set_gpio_inen(gpio, 1); |
| 561 | |
| 562 | if (type & (PM_WAKE_RISING | PM_WAKE_FALLING)) |
| 563 | set_gpio_edge(gpio, 1); |
| 564 | else |
| 565 | set_gpio_edge(gpio, 0); |
| 566 | |
| 567 | if ((type & (PM_WAKE_BOTH_EDGES)) == (PM_WAKE_BOTH_EDGES)) |
| 568 | set_gpio_both(gpio, 1); |
| 569 | else |
| 570 | set_gpio_both(gpio, 0); |
| 571 | |
| 572 | if ((type & (PM_WAKE_FALLING | PM_WAKE_LOW))) |
| 573 | set_gpio_polar(gpio, 1); |
| 574 | else |
| 575 | set_gpio_polar(gpio, 0); |
| 576 | |
| 577 | SSYNC(); |
| 578 | |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | u32 gpio_pm_setup(void) |
| 583 | { |
| 584 | u32 sic_iwr = 0; |
| 585 | u16 bank, mask, i, gpio; |
| 586 | |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 587 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 588 | mask = wakeup_map[gpio_bank(i)]; |
| 589 | bank = gpio_bank(i); |
| 590 | |
| 591 | gpio_bank_saved[bank].maskb = gpio_bankb[bank]->maskb; |
| 592 | gpio_bankb[bank]->maskb = 0; |
| 593 | |
| 594 | if (mask) { |
| 595 | #ifdef BF537_FAMILY |
| 596 | gpio_bank_saved[bank].fer = *port_fer[bank]; |
| 597 | #endif |
| 598 | gpio_bank_saved[bank].inen = gpio_bankb[bank]->inen; |
| 599 | gpio_bank_saved[bank].polar = gpio_bankb[bank]->polar; |
| 600 | gpio_bank_saved[bank].dir = gpio_bankb[bank]->dir; |
| 601 | gpio_bank_saved[bank].edge = gpio_bankb[bank]->edge; |
| 602 | gpio_bank_saved[bank].both = gpio_bankb[bank]->both; |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 603 | gpio_bank_saved[bank].reserved = |
| 604 | reserved_gpio_map[bank]; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 605 | |
| 606 | gpio = i; |
| 607 | |
| 608 | while (mask) { |
| 609 | if (mask & 1) { |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 610 | reserved_gpio_map[gpio_bank(gpio)] |= |
Michael Hennerich | 581d62a | 2007-06-14 13:30:23 +0800 | [diff] [blame] | 611 | gpio_bit(gpio); |
| 612 | bfin_gpio_wakeup_type(gpio, |
| 613 | wakeup_flags_map[gpio]); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 614 | set_gpio_data(gpio, 0); /*Clear*/ |
| 615 | } |
| 616 | gpio++; |
| 617 | mask >>= 1; |
| 618 | } |
| 619 | |
Michael Hennerich | 581d62a | 2007-06-14 13:30:23 +0800 | [diff] [blame] | 620 | sic_iwr |= 1 << |
| 621 | (sic_iwr_irqs[bank] - (IRQ_CORETMR + 1)); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 622 | gpio_bankb[bank]->maskb_set = wakeup_map[gpio_bank(i)]; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | if (sic_iwr) |
| 627 | return sic_iwr; |
| 628 | else |
| 629 | return IWR_ENABLE_ALL; |
| 630 | } |
| 631 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 632 | void gpio_pm_restore(void) |
| 633 | { |
| 634 | u16 bank, mask, i; |
| 635 | |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 636 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 637 | mask = wakeup_map[gpio_bank(i)]; |
| 638 | bank = gpio_bank(i); |
| 639 | |
| 640 | if (mask) { |
| 641 | #ifdef BF537_FAMILY |
| 642 | *port_fer[bank] = gpio_bank_saved[bank].fer; |
| 643 | #endif |
| 644 | gpio_bankb[bank]->inen = gpio_bank_saved[bank].inen; |
| 645 | gpio_bankb[bank]->dir = gpio_bank_saved[bank].dir; |
| 646 | gpio_bankb[bank]->polar = gpio_bank_saved[bank].polar; |
| 647 | gpio_bankb[bank]->edge = gpio_bank_saved[bank].edge; |
| 648 | gpio_bankb[bank]->both = gpio_bank_saved[bank].both; |
Michael Hennerich | 581d62a | 2007-06-14 13:30:23 +0800 | [diff] [blame] | 649 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 650 | reserved_gpio_map[bank] = |
| 651 | gpio_bank_saved[bank].reserved; |
Michael Hennerich | 581d62a | 2007-06-14 13:30:23 +0800 | [diff] [blame] | 652 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | gpio_bankb[bank]->maskb = gpio_bank_saved[bank].maskb; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | #endif |
| 660 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 661 | |
| 662 | |
| 663 | |
| 664 | int peripheral_request(unsigned short per, const char *label) |
| 665 | { |
| 666 | unsigned long flags; |
| 667 | unsigned short ident = P_IDENT(per); |
| 668 | |
| 669 | /* |
| 670 | * Don't cares are pins with only one dedicated function |
| 671 | */ |
| 672 | |
| 673 | if (per & P_DONTCARE) |
| 674 | return 0; |
| 675 | |
| 676 | if (!(per & P_DEFINED)) |
| 677 | return -ENODEV; |
| 678 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 679 | local_irq_save(flags); |
| 680 | |
Michael Hennerich | cda6a20 | 2007-10-04 00:36:18 +0800 | [diff] [blame] | 681 | if (!check_gpio(ident)) { |
| 682 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 683 | if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) { |
| 684 | printk(KERN_ERR |
| 685 | "%s: Peripheral %d is already reserved as GPIO by %s !\n", |
| 686 | __FUNCTION__, ident, get_label(ident)); |
| 687 | dump_stack(); |
| 688 | local_irq_restore(flags); |
| 689 | return -EBUSY; |
| 690 | } |
| 691 | |
Michael Hennerich | cda6a20 | 2007-10-04 00:36:18 +0800 | [diff] [blame] | 692 | } |
| 693 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 694 | if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) { |
| 695 | |
| 696 | /* |
| 697 | * Pin functions like AMC address strobes my |
| 698 | * be requested and used by several drivers |
| 699 | */ |
| 700 | |
| 701 | if (!(per & P_MAYSHARE)) { |
| 702 | |
| 703 | /* |
| 704 | * Allow that the identical pin function can |
| 705 | * be requested from the same driver twice |
| 706 | */ |
| 707 | |
| 708 | if (cmp_label(ident, label) == 0) |
| 709 | goto anyway; |
| 710 | |
| 711 | printk(KERN_ERR |
| 712 | "%s: Peripheral %d function %d is already" |
Michael Hennerich | 8c61362 | 2007-08-03 17:48:09 +0800 | [diff] [blame^] | 713 | " reserved by %s !\n", |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 714 | __FUNCTION__, ident, P_FUNCT2MUX(per), |
| 715 | get_label(ident)); |
| 716 | dump_stack(); |
| 717 | local_irq_restore(flags); |
| 718 | return -EBUSY; |
| 719 | } |
| 720 | |
| 721 | } |
| 722 | |
| 723 | anyway: |
| 724 | |
| 725 | |
| 726 | portmux_setup(per, P_FUNCT2MUX(per)); |
| 727 | |
| 728 | port_setup(ident, PERIPHERAL_USAGE); |
| 729 | |
| 730 | reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident); |
| 731 | local_irq_restore(flags); |
| 732 | set_label(ident, label); |
| 733 | |
| 734 | return 0; |
| 735 | } |
| 736 | EXPORT_SYMBOL(peripheral_request); |
| 737 | |
| 738 | int peripheral_request_list(unsigned short per[], const char *label) |
| 739 | { |
| 740 | u16 cnt; |
| 741 | int ret; |
| 742 | |
| 743 | for (cnt = 0; per[cnt] != 0; cnt++) { |
Michael Hennerich | 314c98d | 2007-07-24 18:03:45 +0800 | [diff] [blame] | 744 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 745 | ret = peripheral_request(per[cnt], label); |
Michael Hennerich | 314c98d | 2007-07-24 18:03:45 +0800 | [diff] [blame] | 746 | |
| 747 | if (ret < 0) { |
| 748 | for ( ; cnt > 0; cnt--) { |
| 749 | peripheral_free(per[cnt - 1]); |
| 750 | } |
| 751 | return ret; |
| 752 | } |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | return 0; |
| 756 | } |
| 757 | EXPORT_SYMBOL(peripheral_request_list); |
| 758 | |
| 759 | void peripheral_free(unsigned short per) |
| 760 | { |
| 761 | unsigned long flags; |
| 762 | unsigned short ident = P_IDENT(per); |
| 763 | |
| 764 | if (per & P_DONTCARE) |
| 765 | return; |
| 766 | |
| 767 | if (!(per & P_DEFINED)) |
| 768 | return; |
| 769 | |
| 770 | if (check_gpio(ident) < 0) |
| 771 | return; |
| 772 | |
| 773 | local_irq_save(flags); |
| 774 | |
| 775 | if (unlikely(!(reserved_peri_map[gpio_bank(ident)] |
| 776 | & gpio_bit(ident)))) { |
| 777 | local_irq_restore(flags); |
| 778 | return; |
| 779 | } |
| 780 | |
| 781 | if (!(per & P_MAYSHARE)) { |
| 782 | port_setup(ident, GPIO_USAGE); |
| 783 | } |
| 784 | |
| 785 | reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident); |
| 786 | |
| 787 | local_irq_restore(flags); |
| 788 | } |
| 789 | EXPORT_SYMBOL(peripheral_free); |
| 790 | |
| 791 | void peripheral_free_list(unsigned short per[]) |
| 792 | { |
| 793 | u16 cnt; |
| 794 | |
| 795 | for (cnt = 0; per[cnt] != 0; cnt++) { |
| 796 | peripheral_free(per[cnt]); |
| 797 | } |
| 798 | |
| 799 | } |
| 800 | EXPORT_SYMBOL(peripheral_free_list); |
| 801 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 802 | /*********************************************************** |
| 803 | * |
| 804 | * FUNCTIONS: Blackfin GPIO Driver |
| 805 | * |
| 806 | * INPUTS/OUTPUTS: |
| 807 | * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS |
| 808 | * |
| 809 | * |
| 810 | * DESCRIPTION: Blackfin GPIO Driver API |
| 811 | * |
| 812 | * CAUTION: |
| 813 | ************************************************************* |
| 814 | * MODIFICATION HISTORY : |
| 815 | **************************************************************/ |
| 816 | |
| 817 | int gpio_request(unsigned short gpio, const char *label) |
| 818 | { |
| 819 | unsigned long flags; |
| 820 | |
| 821 | if (check_gpio(gpio) < 0) |
| 822 | return -EINVAL; |
| 823 | |
| 824 | local_irq_save(flags); |
| 825 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 826 | if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 827 | printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved!\n", gpio); |
| 828 | dump_stack(); |
| 829 | local_irq_restore(flags); |
| 830 | return -EBUSY; |
| 831 | } |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 832 | reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 833 | |
| 834 | local_irq_restore(flags); |
| 835 | |
| 836 | port_setup(gpio, GPIO_USAGE); |
| 837 | |
| 838 | return 0; |
| 839 | } |
| 840 | EXPORT_SYMBOL(gpio_request); |
| 841 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 842 | void gpio_free(unsigned short gpio) |
| 843 | { |
| 844 | unsigned long flags; |
| 845 | |
| 846 | if (check_gpio(gpio) < 0) |
| 847 | return; |
| 848 | |
| 849 | local_irq_save(flags); |
| 850 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 851 | if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 852 | printk(KERN_ERR "bfin-gpio: GPIO %d wasn't reserved!\n", gpio); |
| 853 | dump_stack(); |
| 854 | local_irq_restore(flags); |
| 855 | return; |
| 856 | } |
| 857 | |
| 858 | default_gpio(gpio); |
| 859 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 860 | reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 861 | |
| 862 | local_irq_restore(flags); |
| 863 | } |
| 864 | EXPORT_SYMBOL(gpio_free); |
| 865 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 866 | void gpio_direction_input(unsigned short gpio) |
| 867 | { |
| 868 | unsigned long flags; |
| 869 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 870 | BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 871 | |
| 872 | local_irq_save(flags); |
| 873 | gpio_bankb[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio); |
| 874 | gpio_bankb[gpio_bank(gpio)]->inen |= gpio_bit(gpio); |
| 875 | local_irq_restore(flags); |
| 876 | } |
| 877 | EXPORT_SYMBOL(gpio_direction_input); |
| 878 | |
| 879 | void gpio_direction_output(unsigned short gpio) |
| 880 | { |
| 881 | unsigned long flags; |
| 882 | |
Michael Hennerich | c58c214 | 2007-10-04 00:35:05 +0800 | [diff] [blame] | 883 | BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 884 | |
| 885 | local_irq_save(flags); |
| 886 | gpio_bankb[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio); |
| 887 | gpio_bankb[gpio_bank(gpio)]->dir |= gpio_bit(gpio); |
| 888 | local_irq_restore(flags); |
| 889 | } |
| 890 | EXPORT_SYMBOL(gpio_direction_output); |