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