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