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