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