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