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