blob: 4aa3c053297f366208d9611a6aacfc8175a6906f [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
2 * File: arch/blackfin/kernel/bfin_gpio.c
3 * Based on:
4 * Author: Michael Hennerich (hennerich@blackfin.uclinux.org)
5 *
6 * Created:
7 * Description: GPIO Abstraction Layer
8 *
9 * Modified:
Michael Hennericha2c8cfe2008-01-22 17:20:10 +080010 * Copyright 2008 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -070011 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30/*
Michael Hennerichd2b11a42007-08-28 16:47:46 +080031* Number BF537/6/4 BF561 BF533/2/1 BF549/8/4/2
Bryan Wu1394f032007-05-06 14:50:22 -070032*
Michael Hennerichd2b11a42007-08-28 16:47:46 +080033* GPIO_0 PF0 PF0 PF0 PA0...PJ13
Bryan Wu1394f032007-05-06 14:50:22 -070034* GPIO_1 PF1 PF1 PF1
35* GPIO_2 PF2 PF2 PF2
36* GPIO_3 PF3 PF3 PF3
37* GPIO_4 PF4 PF4 PF4
38* GPIO_5 PF5 PF5 PF5
39* GPIO_6 PF6 PF6 PF6
40* GPIO_7 PF7 PF7 PF7
41* GPIO_8 PF8 PF8 PF8
42* GPIO_9 PF9 PF9 PF9
43* GPIO_10 PF10 PF10 PF10
44* GPIO_11 PF11 PF11 PF11
45* GPIO_12 PF12 PF12 PF12
46* GPIO_13 PF13 PF13 PF13
47* GPIO_14 PF14 PF14 PF14
48* GPIO_15 PF15 PF15 PF15
49* GPIO_16 PG0 PF16
50* GPIO_17 PG1 PF17
51* GPIO_18 PG2 PF18
52* GPIO_19 PG3 PF19
53* GPIO_20 PG4 PF20
54* GPIO_21 PG5 PF21
55* GPIO_22 PG6 PF22
56* GPIO_23 PG7 PF23
57* GPIO_24 PG8 PF24
58* GPIO_25 PG9 PF25
59* GPIO_26 PG10 PF26
60* GPIO_27 PG11 PF27
61* GPIO_28 PG12 PF28
62* GPIO_29 PG13 PF29
63* GPIO_30 PG14 PF30
64* GPIO_31 PG15 PF31
65* GPIO_32 PH0 PF32
66* GPIO_33 PH1 PF33
67* GPIO_34 PH2 PF34
68* GPIO_35 PH3 PF35
69* GPIO_36 PH4 PF36
70* GPIO_37 PH5 PF37
71* GPIO_38 PH6 PF38
72* GPIO_39 PH7 PF39
73* GPIO_40 PH8 PF40
74* GPIO_41 PH9 PF41
75* GPIO_42 PH10 PF42
76* GPIO_43 PH11 PF43
77* GPIO_44 PH12 PF44
78* GPIO_45 PH13 PF45
79* GPIO_46 PH14 PF46
80* GPIO_47 PH15 PF47
81*/
82
Mike Frysinger168f1212007-10-11 00:22:35 +080083#include <linux/delay.h>
Bryan Wu1394f032007-05-06 14:50:22 -070084#include <linux/module.h>
85#include <linux/err.h>
Mike Frysinger1545a112007-12-24 16:54:48 +080086#include <linux/proc_fs.h>
Bryan Wu1394f032007-05-06 14:50:22 -070087#include <asm/blackfin.h>
88#include <asm/gpio.h>
Michael Hennerichc58c2142007-10-04 00:35:05 +080089#include <asm/portmux.h>
Bryan Wu1394f032007-05-06 14:50:22 -070090#include <linux/irq.h>
91
Michael Hennerich2b393312007-10-10 16:58:49 +080092#if ANOMALY_05000311 || ANOMALY_05000323
93enum {
94 AWA_data = SYSCR,
95 AWA_data_clear = SYSCR,
96 AWA_data_set = SYSCR,
97 AWA_toggle = SYSCR,
Graf Yang6ed83942008-04-24 04:43:14 +080098 AWA_maska = BFIN_UART_SCR,
99 AWA_maska_clear = BFIN_UART_SCR,
100 AWA_maska_set = BFIN_UART_SCR,
101 AWA_maska_toggle = BFIN_UART_SCR,
102 AWA_maskb = BFIN_UART_GCTL,
103 AWA_maskb_clear = BFIN_UART_GCTL,
104 AWA_maskb_set = BFIN_UART_GCTL,
105 AWA_maskb_toggle = BFIN_UART_GCTL,
Michael Hennerich2b393312007-10-10 16:58:49 +0800106 AWA_dir = SPORT1_STAT,
107 AWA_polar = SPORT1_STAT,
108 AWA_edge = SPORT1_STAT,
109 AWA_both = SPORT1_STAT,
110#if ANOMALY_05000311
111 AWA_inen = TIMER_ENABLE,
112#elif ANOMALY_05000323
113 AWA_inen = DMA1_1_CONFIG,
114#endif
115};
116 /* Anomaly Workaround */
117#define AWA_DUMMY_READ(name) bfin_read16(AWA_ ## name)
118#else
119#define AWA_DUMMY_READ(...) do { } while (0)
120#endif
121
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800122#if defined(BF533_FAMILY) || defined(BF538_FAMILY)
Bryan Wu1394f032007-05-06 14:50:22 -0700123static struct gpio_port_t *gpio_bankb[gpio_bank(MAX_BLACKFIN_GPIOS)] = {
124 (struct gpio_port_t *) FIO_FLAG_D,
125};
126#endif
127
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800128#if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
Bryan Wu1394f032007-05-06 14:50:22 -0700129static struct gpio_port_t *gpio_bankb[gpio_bank(MAX_BLACKFIN_GPIOS)] = {
130 (struct gpio_port_t *) PORTFIO,
131 (struct gpio_port_t *) PORTGIO,
132 (struct gpio_port_t *) PORTHIO,
133};
134
135static unsigned short *port_fer[gpio_bank(MAX_BLACKFIN_GPIOS)] = {
136 (unsigned short *) PORTF_FER,
137 (unsigned short *) PORTG_FER,
138 (unsigned short *) PORTH_FER,
139};
Bryan Wu1394f032007-05-06 14:50:22 -0700140#endif
141
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800142#if defined(BF527_FAMILY) || defined(BF518_FAMILY)
Michael Hennerich59003142007-10-21 16:54:27 +0800143static unsigned short *port_mux[gpio_bank(MAX_BLACKFIN_GPIOS)] = {
144 (unsigned short *) PORTF_MUX,
145 (unsigned short *) PORTG_MUX,
146 (unsigned short *) PORTH_MUX,
147};
148
149static const
150u8 pmux_offset[][16] =
151 {{ 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 4, 6, 8, 8, 10, 10 }, /* PORTF */
152 { 0, 0, 0, 0, 0, 2, 2, 4, 4, 6, 8, 10, 10, 10, 12, 12 }, /* PORTG */
153 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4 }, /* PORTH */
154 };
155#endif
156
Bryan Wu1394f032007-05-06 14:50:22 -0700157#ifdef BF561_FAMILY
158static struct gpio_port_t *gpio_bankb[gpio_bank(MAX_BLACKFIN_GPIOS)] = {
159 (struct gpio_port_t *) FIO0_FLAG_D,
160 (struct gpio_port_t *) FIO1_FLAG_D,
161 (struct gpio_port_t *) FIO2_FLAG_D,
162};
163#endif
164
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800165#ifdef BF548_FAMILY
166static struct gpio_port_t *gpio_array[gpio_bank(MAX_BLACKFIN_GPIOS)] = {
167 (struct gpio_port_t *)PORTA_FER,
168 (struct gpio_port_t *)PORTB_FER,
169 (struct gpio_port_t *)PORTC_FER,
170 (struct gpio_port_t *)PORTD_FER,
171 (struct gpio_port_t *)PORTE_FER,
172 (struct gpio_port_t *)PORTF_FER,
173 (struct gpio_port_t *)PORTG_FER,
174 (struct gpio_port_t *)PORTH_FER,
175 (struct gpio_port_t *)PORTI_FER,
176 (struct gpio_port_t *)PORTJ_FER,
177};
178#endif
179
Michael Hennerichc58c2142007-10-04 00:35:05 +0800180static unsigned short reserved_gpio_map[gpio_bank(MAX_BLACKFIN_GPIOS)];
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800181static unsigned short reserved_peri_map[gpio_bank(MAX_RESOURCES)];
Michael Hennerichc58c2142007-10-04 00:35:05 +0800182
Michael Hennerich8c613622007-08-03 17:48:09 +0800183#define RESOURCE_LABEL_SIZE 16
184
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800185static struct str_ident {
Michael Hennerich8c613622007-08-03 17:48:09 +0800186 char name[RESOURCE_LABEL_SIZE];
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800187} str_ident[MAX_RESOURCES];
Bryan Wu1394f032007-05-06 14:50:22 -0700188
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800189#if defined(CONFIG_PM)
190#if defined(CONFIG_BF54x)
191static struct gpio_port_s gpio_bank_saved[gpio_bank(MAX_BLACKFIN_GPIOS)];
192#else
Bryan Wu1394f032007-05-06 14:50:22 -0700193static unsigned short wakeup_map[gpio_bank(MAX_BLACKFIN_GPIOS)];
194static unsigned char wakeup_flags_map[MAX_BLACKFIN_GPIOS];
195static struct gpio_port_s gpio_bank_saved[gpio_bank(MAX_BLACKFIN_GPIOS)];
196
197#ifdef BF533_FAMILY
198static unsigned int sic_iwr_irqs[gpio_bank(MAX_BLACKFIN_GPIOS)] = {IRQ_PROG_INTB};
199#endif
200
201#ifdef BF537_FAMILY
202static unsigned int sic_iwr_irqs[gpio_bank(MAX_BLACKFIN_GPIOS)] = {IRQ_PROG_INTB, IRQ_PORTG_INTB, IRQ_MAC_TX};
203#endif
204
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800205#ifdef BF538_FAMILY
206static unsigned int sic_iwr_irqs[gpio_bank(MAX_BLACKFIN_GPIOS)] = {IRQ_PORTF_INTB};
207#endif
208
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800209#if defined(BF527_FAMILY) || defined(BF518_FAMILY)
Michael Hennerich59003142007-10-21 16:54:27 +0800210static unsigned int sic_iwr_irqs[gpio_bank(MAX_BLACKFIN_GPIOS)] = {IRQ_PORTF_INTB, IRQ_PORTG_INTB, IRQ_PORTH_INTB};
211#endif
212
Bryan Wu1394f032007-05-06 14:50:22 -0700213#ifdef BF561_FAMILY
214static unsigned int sic_iwr_irqs[gpio_bank(MAX_BLACKFIN_GPIOS)] = {IRQ_PROG0_INTB, IRQ_PROG1_INTB, IRQ_PROG2_INTB};
215#endif
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800216#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700217#endif /* CONFIG_PM */
218
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800219inline int check_gpio(unsigned gpio)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800220{
Mike Frysinger27228b22008-10-28 15:45:42 +0800221#if defined(BF548_FAMILY)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800222 if (gpio == GPIO_PB15 || gpio == GPIO_PC14 || gpio == GPIO_PC15
223 || gpio == GPIO_PH14 || gpio == GPIO_PH15
Mike Frysinger27228b22008-10-28 15:45:42 +0800224 || gpio == GPIO_PJ14 || gpio == GPIO_PJ15)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800225 return -EINVAL;
Mike Frysinger27228b22008-10-28 15:45:42 +0800226#endif
Michael Henneriche7613aa2007-06-11 16:37:57 +0800227 if (gpio >= MAX_BLACKFIN_GPIOS)
Bryan Wu1394f032007-05-06 14:50:22 -0700228 return -EINVAL;
229 return 0;
230}
231
Mike Frysinger74c04502008-10-08 16:13:17 +0800232static void gpio_error(unsigned gpio)
Michael Hennerichacbcd262008-01-22 18:36:20 +0800233{
234 printk(KERN_ERR "bfin-gpio: GPIO %d wasn't requested!\n", gpio);
235}
236
Michael Hennerichc58c2142007-10-04 00:35:05 +0800237static void set_label(unsigned short ident, const char *label)
238{
Michael Henneriche9fae182008-10-13 11:35:22 +0800239 if (label) {
Michael Hennerich8c613622007-08-03 17:48:09 +0800240 strncpy(str_ident[ident].name, label,
Michael Hennerichc58c2142007-10-04 00:35:05 +0800241 RESOURCE_LABEL_SIZE);
Michael Hennerich8c613622007-08-03 17:48:09 +0800242 str_ident[ident].name[RESOURCE_LABEL_SIZE - 1] = 0;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800243 }
244}
245
246static char *get_label(unsigned short ident)
247{
Michael Hennerich8c613622007-08-03 17:48:09 +0800248 return (*str_ident[ident].name ? str_ident[ident].name : "UNKNOWN");
Michael Hennerichc58c2142007-10-04 00:35:05 +0800249}
250
251static int cmp_label(unsigned short ident, const char *label)
252{
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800253 if (label == NULL) {
254 dump_stack();
255 printk(KERN_ERR "Please provide none-null label\n");
256 }
257
Michael Henneriche9fae182008-10-13 11:35:22 +0800258 if (label)
Mike Frysinger1f7d3732008-10-28 15:47:11 +0800259 return strcmp(str_ident[ident].name, label);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800260 else
261 return -EINVAL;
262}
263
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800264#if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800265static void port_setup(unsigned gpio, unsigned short usage)
Bryan Wu1394f032007-05-06 14:50:22 -0700266{
Michael Hennerichcda6a202007-10-04 00:36:18 +0800267 if (!check_gpio(gpio)) {
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800268 if (usage == GPIO_USAGE)
Michael Hennerichcda6a202007-10-04 00:36:18 +0800269 *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800270 else
Michael Hennerichcda6a202007-10-04 00:36:18 +0800271 *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio);
272 SSYNC();
273 }
Bryan Wu1394f032007-05-06 14:50:22 -0700274}
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800275#elif defined(BF548_FAMILY)
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800276static void port_setup(unsigned gpio, unsigned short usage)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800277{
278 if (usage == GPIO_USAGE)
279 gpio_array[gpio_bank(gpio)]->port_fer &= ~gpio_bit(gpio);
280 else
281 gpio_array[gpio_bank(gpio)]->port_fer |= gpio_bit(gpio);
282 SSYNC();
283}
Bryan Wu1394f032007-05-06 14:50:22 -0700284#else
285# define port_setup(...) do { } while (0)
286#endif
287
Michael Hennerichc58c2142007-10-04 00:35:05 +0800288#ifdef BF537_FAMILY
Michael Hennerich8c613622007-08-03 17:48:09 +0800289static struct {
290 unsigned short res;
291 unsigned short offset;
292} port_mux_lut[] = {
293 {.res = P_PPI0_D13, .offset = 11},
294 {.res = P_PPI0_D14, .offset = 11},
295 {.res = P_PPI0_D15, .offset = 11},
296 {.res = P_SPORT1_TFS, .offset = 11},
297 {.res = P_SPORT1_TSCLK, .offset = 11},
298 {.res = P_SPORT1_DTPRI, .offset = 11},
299 {.res = P_PPI0_D10, .offset = 10},
300 {.res = P_PPI0_D11, .offset = 10},
301 {.res = P_PPI0_D12, .offset = 10},
302 {.res = P_SPORT1_RSCLK, .offset = 10},
303 {.res = P_SPORT1_RFS, .offset = 10},
304 {.res = P_SPORT1_DRPRI, .offset = 10},
305 {.res = P_PPI0_D8, .offset = 9},
306 {.res = P_PPI0_D9, .offset = 9},
307 {.res = P_SPORT1_DRSEC, .offset = 9},
308 {.res = P_SPORT1_DTSEC, .offset = 9},
309 {.res = P_TMR2, .offset = 8},
310 {.res = P_PPI0_FS3, .offset = 8},
311 {.res = P_TMR3, .offset = 7},
312 {.res = P_SPI0_SSEL4, .offset = 7},
313 {.res = P_TMR4, .offset = 6},
314 {.res = P_SPI0_SSEL5, .offset = 6},
315 {.res = P_TMR5, .offset = 5},
316 {.res = P_SPI0_SSEL6, .offset = 5},
317 {.res = P_UART1_RX, .offset = 4},
318 {.res = P_UART1_TX, .offset = 4},
319 {.res = P_TMR6, .offset = 4},
320 {.res = P_TMR7, .offset = 4},
321 {.res = P_UART0_RX, .offset = 3},
322 {.res = P_UART0_TX, .offset = 3},
323 {.res = P_DMAR0, .offset = 3},
324 {.res = P_DMAR1, .offset = 3},
325 {.res = P_SPORT0_DTSEC, .offset = 1},
326 {.res = P_SPORT0_DRSEC, .offset = 1},
327 {.res = P_CAN0_RX, .offset = 1},
328 {.res = P_CAN0_TX, .offset = 1},
329 {.res = P_SPI0_SSEL7, .offset = 1},
330 {.res = P_SPORT0_TFS, .offset = 0},
331 {.res = P_SPORT0_DTPRI, .offset = 0},
332 {.res = P_SPI0_SSEL2, .offset = 0},
333 {.res = P_SPI0_SSEL3, .offset = 0},
Michael Hennerichc58c2142007-10-04 00:35:05 +0800334};
335
336static void portmux_setup(unsigned short per, unsigned short function)
337{
Michael Hennerich8c613622007-08-03 17:48:09 +0800338 u16 y, offset, muxreg;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800339
Michael Hennerich8c613622007-08-03 17:48:09 +0800340 for (y = 0; y < ARRAY_SIZE(port_mux_lut); y++) {
341 if (port_mux_lut[y].res == per) {
Michael Hennerichc58c2142007-10-04 00:35:05 +0800342
343 /* SET PORTMUX REG */
344
Michael Hennerich8c613622007-08-03 17:48:09 +0800345 offset = port_mux_lut[y].offset;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800346 muxreg = bfin_read_PORT_MUX();
347
Mike Frysingerd171c232008-03-26 08:35:46 +0800348 if (offset != 1)
Michael Hennerichc58c2142007-10-04 00:35:05 +0800349 muxreg &= ~(1 << offset);
Mike Frysingerd171c232008-03-26 08:35:46 +0800350 else
Michael Hennerichc58c2142007-10-04 00:35:05 +0800351 muxreg &= ~(3 << 1);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800352
353 muxreg |= (function << offset);
354 bfin_write_PORT_MUX(muxreg);
355 }
356 }
357}
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800358#elif defined(BF548_FAMILY)
359inline void portmux_setup(unsigned short portno, unsigned short function)
360{
361 u32 pmux;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800362
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800363 pmux = gpio_array[gpio_bank(portno)]->port_mux;
364
365 pmux &= ~(0x3 << (2 * gpio_sub_n(portno)));
366 pmux |= (function & 0x3) << (2 * gpio_sub_n(portno));
367
368 gpio_array[gpio_bank(portno)]->port_mux = pmux;
369}
370
371inline u16 get_portmux(unsigned short portno)
372{
373 u32 pmux;
374
375 pmux = gpio_array[gpio_bank(portno)]->port_mux;
376
377 return (pmux >> (2 * gpio_sub_n(portno)) & 0x3);
378}
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800379#elif defined(BF527_FAMILY) || defined(BF518_FAMILY)
Michael Hennerich59003142007-10-21 16:54:27 +0800380inline void portmux_setup(unsigned short portno, unsigned short function)
381{
382 u16 pmux, ident = P_IDENT(portno);
383 u8 offset = pmux_offset[gpio_bank(ident)][gpio_sub_n(ident)];
384
385 pmux = *port_mux[gpio_bank(ident)];
386 pmux &= ~(3 << offset);
387 pmux |= (function & 3) << offset;
388 *port_mux[gpio_bank(ident)] = pmux;
389 SSYNC();
390}
Michael Hennerichc58c2142007-10-04 00:35:05 +0800391#else
392# define portmux_setup(...) do { } while (0)
393#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700394
Mike Frysingera161bb02007-05-21 18:09:14 +0800395static int __init bfin_gpio_init(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700396{
Bryan Wu1394f032007-05-06 14:50:22 -0700397 printk(KERN_INFO "Blackfin GPIO Controller\n");
398
Bryan Wu1394f032007-05-06 14:50:22 -0700399 return 0;
400}
Bryan Wu1394f032007-05-06 14:50:22 -0700401arch_initcall(bfin_gpio_init);
402
403
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800404#ifndef BF548_FAMILY
Bryan Wu1394f032007-05-06 14:50:22 -0700405/***********************************************************
406*
407* FUNCTIONS: Blackfin General Purpose Ports Access Functions
408*
409* INPUTS/OUTPUTS:
410* gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
411*
412*
413* DESCRIPTION: These functions abstract direct register access
414* to Blackfin processor General Purpose
415* Ports Regsiters
416*
417* CAUTION: These functions do not belong to the GPIO Driver API
418*************************************************************
419* MODIFICATION HISTORY :
420**************************************************************/
421
422/* Set a specific bit */
423
424#define SET_GPIO(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800425void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
Bryan Wu1394f032007-05-06 14:50:22 -0700426{ \
427 unsigned long flags; \
Bryan Wu1394f032007-05-06 14:50:22 -0700428 local_irq_save(flags); \
429 if (arg) \
430 gpio_bankb[gpio_bank(gpio)]->name |= gpio_bit(gpio); \
431 else \
432 gpio_bankb[gpio_bank(gpio)]->name &= ~gpio_bit(gpio); \
Michael Hennerich2b393312007-10-10 16:58:49 +0800433 AWA_DUMMY_READ(name); \
Bryan Wu1394f032007-05-06 14:50:22 -0700434 local_irq_restore(flags); \
435} \
436EXPORT_SYMBOL(set_gpio_ ## name);
437
438SET_GPIO(dir)
439SET_GPIO(inen)
440SET_GPIO(polar)
441SET_GPIO(edge)
442SET_GPIO(both)
443
444
Michael Hennerich2b393312007-10-10 16:58:49 +0800445#if ANOMALY_05000311 || ANOMALY_05000323
446#define SET_GPIO_SC(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800447void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800448{ \
449 unsigned long flags; \
Michael Hennerich2b393312007-10-10 16:58:49 +0800450 local_irq_save(flags); \
451 if (arg) \
452 gpio_bankb[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \
453 else \
454 gpio_bankb[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \
455 AWA_DUMMY_READ(name); \
456 local_irq_restore(flags); \
457} \
458EXPORT_SYMBOL(set_gpio_ ## name);
459#else
Bryan Wu1394f032007-05-06 14:50:22 -0700460#define SET_GPIO_SC(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800461void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
Bryan Wu1394f032007-05-06 14:50:22 -0700462{ \
Bryan Wu1394f032007-05-06 14:50:22 -0700463 if (arg) \
464 gpio_bankb[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \
465 else \
466 gpio_bankb[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \
467} \
468EXPORT_SYMBOL(set_gpio_ ## name);
Michael Hennerich2b393312007-10-10 16:58:49 +0800469#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700470
471SET_GPIO_SC(maska)
472SET_GPIO_SC(maskb)
Bryan Wu1394f032007-05-06 14:50:22 -0700473SET_GPIO_SC(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700474
Michael Hennerich2b393312007-10-10 16:58:49 +0800475#if ANOMALY_05000311 || ANOMALY_05000323
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800476void set_gpio_toggle(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -0700477{
478 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700479 local_irq_save(flags);
480 gpio_bankb[gpio_bank(gpio)]->toggle = gpio_bit(gpio);
Michael Hennerich2b393312007-10-10 16:58:49 +0800481 AWA_DUMMY_READ(toggle);
Bryan Wu1394f032007-05-06 14:50:22 -0700482 local_irq_restore(flags);
483}
484#else
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800485void set_gpio_toggle(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -0700486{
Bryan Wu1394f032007-05-06 14:50:22 -0700487 gpio_bankb[gpio_bank(gpio)]->toggle = gpio_bit(gpio);
488}
489#endif
490EXPORT_SYMBOL(set_gpio_toggle);
491
492
493/*Set current PORT date (16-bit word)*/
494
Michael Hennerich2b393312007-10-10 16:58:49 +0800495#if ANOMALY_05000311 || ANOMALY_05000323
496#define SET_GPIO_P(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800497void set_gpiop_ ## name(unsigned gpio, unsigned short arg) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800498{ \
499 unsigned long flags; \
500 local_irq_save(flags); \
501 gpio_bankb[gpio_bank(gpio)]->name = arg; \
502 AWA_DUMMY_READ(name); \
503 local_irq_restore(flags); \
504} \
505EXPORT_SYMBOL(set_gpiop_ ## name);
506#else
Bryan Wu1394f032007-05-06 14:50:22 -0700507#define SET_GPIO_P(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800508void set_gpiop_ ## name(unsigned gpio, unsigned short arg) \
Bryan Wu1394f032007-05-06 14:50:22 -0700509{ \
510 gpio_bankb[gpio_bank(gpio)]->name = arg; \
511} \
512EXPORT_SYMBOL(set_gpiop_ ## name);
Michael Hennerich2b393312007-10-10 16:58:49 +0800513#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700514
Michael Hennerich2b393312007-10-10 16:58:49 +0800515SET_GPIO_P(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700516SET_GPIO_P(dir)
517SET_GPIO_P(inen)
518SET_GPIO_P(polar)
519SET_GPIO_P(edge)
520SET_GPIO_P(both)
521SET_GPIO_P(maska)
522SET_GPIO_P(maskb)
523
Bryan Wu1394f032007-05-06 14:50:22 -0700524/* Get a specific bit */
Michael Hennerich2b393312007-10-10 16:58:49 +0800525#if ANOMALY_05000311 || ANOMALY_05000323
526#define GET_GPIO(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800527unsigned short get_gpio_ ## name(unsigned gpio) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800528{ \
529 unsigned long flags; \
530 unsigned short ret; \
531 local_irq_save(flags); \
532 ret = 0x01 & (gpio_bankb[gpio_bank(gpio)]->name >> gpio_sub_n(gpio)); \
533 AWA_DUMMY_READ(name); \
534 local_irq_restore(flags); \
535 return ret; \
536} \
537EXPORT_SYMBOL(get_gpio_ ## name);
538#else
Bryan Wu1394f032007-05-06 14:50:22 -0700539#define GET_GPIO(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800540unsigned short get_gpio_ ## name(unsigned gpio) \
Bryan Wu1394f032007-05-06 14:50:22 -0700541{ \
542 return (0x01 & (gpio_bankb[gpio_bank(gpio)]->name >> gpio_sub_n(gpio))); \
543} \
544EXPORT_SYMBOL(get_gpio_ ## name);
Michael Hennerich2b393312007-10-10 16:58:49 +0800545#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700546
Michael Hennerich2b393312007-10-10 16:58:49 +0800547GET_GPIO(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700548GET_GPIO(dir)
549GET_GPIO(inen)
550GET_GPIO(polar)
551GET_GPIO(edge)
552GET_GPIO(both)
553GET_GPIO(maska)
554GET_GPIO(maskb)
555
Bryan Wu1394f032007-05-06 14:50:22 -0700556/*Get current PORT date (16-bit word)*/
557
Michael Hennerich2b393312007-10-10 16:58:49 +0800558#if ANOMALY_05000311 || ANOMALY_05000323
559#define GET_GPIO_P(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800560unsigned short get_gpiop_ ## name(unsigned gpio) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800561{ \
562 unsigned long flags; \
563 unsigned short ret; \
564 local_irq_save(flags); \
565 ret = (gpio_bankb[gpio_bank(gpio)]->name); \
566 AWA_DUMMY_READ(name); \
567 local_irq_restore(flags); \
568 return ret; \
569} \
570EXPORT_SYMBOL(get_gpiop_ ## name);
571#else
Bryan Wu1394f032007-05-06 14:50:22 -0700572#define GET_GPIO_P(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800573unsigned short get_gpiop_ ## name(unsigned gpio) \
Bryan Wu1394f032007-05-06 14:50:22 -0700574{ \
575 return (gpio_bankb[gpio_bank(gpio)]->name);\
576} \
577EXPORT_SYMBOL(get_gpiop_ ## name);
Michael Hennerich2b393312007-10-10 16:58:49 +0800578#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700579
Michael Hennerich2b393312007-10-10 16:58:49 +0800580GET_GPIO_P(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700581GET_GPIO_P(dir)
582GET_GPIO_P(inen)
583GET_GPIO_P(polar)
584GET_GPIO_P(edge)
585GET_GPIO_P(both)
586GET_GPIO_P(maska)
587GET_GPIO_P(maskb)
588
Bryan Wu1394f032007-05-06 14:50:22 -0700589
590#ifdef CONFIG_PM
591/***********************************************************
592*
593* FUNCTIONS: Blackfin PM Setup API
594*
595* INPUTS/OUTPUTS:
596* gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
597* type -
598* PM_WAKE_RISING
599* PM_WAKE_FALLING
600* PM_WAKE_HIGH
601* PM_WAKE_LOW
602* PM_WAKE_BOTH_EDGES
603*
604* DESCRIPTION: Blackfin PM Driver API
605*
606* CAUTION:
607*************************************************************
608* MODIFICATION HISTORY :
609**************************************************************/
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800610int gpio_pm_wakeup_request(unsigned gpio, unsigned char type)
Bryan Wu1394f032007-05-06 14:50:22 -0700611{
612 unsigned long flags;
613
614 if ((check_gpio(gpio) < 0) || !type)
615 return -EINVAL;
616
617 local_irq_save(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700618 wakeup_map[gpio_bank(gpio)] |= gpio_bit(gpio);
619 wakeup_flags_map[gpio] = type;
620 local_irq_restore(flags);
621
622 return 0;
623}
624EXPORT_SYMBOL(gpio_pm_wakeup_request);
625
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800626void gpio_pm_wakeup_free(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -0700627{
628 unsigned long flags;
629
630 if (check_gpio(gpio) < 0)
631 return;
632
633 local_irq_save(flags);
634
635 wakeup_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
636
637 local_irq_restore(flags);
638}
639EXPORT_SYMBOL(gpio_pm_wakeup_free);
640
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800641static int bfin_gpio_wakeup_type(unsigned gpio, unsigned char type)
Bryan Wu1394f032007-05-06 14:50:22 -0700642{
643 port_setup(gpio, GPIO_USAGE);
644 set_gpio_dir(gpio, 0);
645 set_gpio_inen(gpio, 1);
646
647 if (type & (PM_WAKE_RISING | PM_WAKE_FALLING))
648 set_gpio_edge(gpio, 1);
649 else
650 set_gpio_edge(gpio, 0);
651
652 if ((type & (PM_WAKE_BOTH_EDGES)) == (PM_WAKE_BOTH_EDGES))
653 set_gpio_both(gpio, 1);
654 else
655 set_gpio_both(gpio, 0);
656
657 if ((type & (PM_WAKE_FALLING | PM_WAKE_LOW)))
658 set_gpio_polar(gpio, 1);
659 else
660 set_gpio_polar(gpio, 0);
661
662 SSYNC();
663
664 return 0;
665}
666
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800667u32 bfin_pm_standby_setup(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700668{
Bryan Wu1394f032007-05-06 14:50:22 -0700669 u16 bank, mask, i, gpio;
670
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800671 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Bryan Wu1394f032007-05-06 14:50:22 -0700672 mask = wakeup_map[gpio_bank(i)];
673 bank = gpio_bank(i);
674
675 gpio_bank_saved[bank].maskb = gpio_bankb[bank]->maskb;
676 gpio_bankb[bank]->maskb = 0;
677
678 if (mask) {
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800679#if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
Bryan Wu1394f032007-05-06 14:50:22 -0700680 gpio_bank_saved[bank].fer = *port_fer[bank];
681#endif
682 gpio_bank_saved[bank].inen = gpio_bankb[bank]->inen;
683 gpio_bank_saved[bank].polar = gpio_bankb[bank]->polar;
684 gpio_bank_saved[bank].dir = gpio_bankb[bank]->dir;
685 gpio_bank_saved[bank].edge = gpio_bankb[bank]->edge;
686 gpio_bank_saved[bank].both = gpio_bankb[bank]->both;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800687 gpio_bank_saved[bank].reserved =
688 reserved_gpio_map[bank];
Bryan Wu1394f032007-05-06 14:50:22 -0700689
690 gpio = i;
691
692 while (mask) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800693 if ((mask & 1) && (wakeup_flags_map[gpio] !=
694 PM_WAKE_IGNORE)) {
Michael Hennerichc58c2142007-10-04 00:35:05 +0800695 reserved_gpio_map[gpio_bank(gpio)] |=
Michael Hennerich581d62a2007-06-14 13:30:23 +0800696 gpio_bit(gpio);
697 bfin_gpio_wakeup_type(gpio,
698 wakeup_flags_map[gpio]);
Bryan Wu1394f032007-05-06 14:50:22 -0700699 set_gpio_data(gpio, 0); /*Clear*/
700 }
701 gpio++;
702 mask >>= 1;
703 }
704
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800705 bfin_internal_set_wake(sic_iwr_irqs[bank], 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700706 gpio_bankb[bank]->maskb_set = wakeup_map[gpio_bank(i)];
707 }
708 }
709
Michael Hennerich2b393312007-10-10 16:58:49 +0800710 AWA_DUMMY_READ(maskb_set);
711
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800712 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700713}
714
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800715void bfin_pm_standby_restore(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700716{
717 u16 bank, mask, i;
718
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800719 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Bryan Wu1394f032007-05-06 14:50:22 -0700720 mask = wakeup_map[gpio_bank(i)];
721 bank = gpio_bank(i);
722
723 if (mask) {
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800724#if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
Bryan Wu1394f032007-05-06 14:50:22 -0700725 *port_fer[bank] = gpio_bank_saved[bank].fer;
726#endif
727 gpio_bankb[bank]->inen = gpio_bank_saved[bank].inen;
728 gpio_bankb[bank]->dir = gpio_bank_saved[bank].dir;
729 gpio_bankb[bank]->polar = gpio_bank_saved[bank].polar;
730 gpio_bankb[bank]->edge = gpio_bank_saved[bank].edge;
731 gpio_bankb[bank]->both = gpio_bank_saved[bank].both;
Michael Hennerich581d62a2007-06-14 13:30:23 +0800732
Michael Hennerichc58c2142007-10-04 00:35:05 +0800733 reserved_gpio_map[bank] =
734 gpio_bank_saved[bank].reserved;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800735 bfin_internal_set_wake(sic_iwr_irqs[bank], 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700736 }
737
738 gpio_bankb[bank]->maskb = gpio_bank_saved[bank].maskb;
739 }
Michael Hennerich2b393312007-10-10 16:58:49 +0800740 AWA_DUMMY_READ(maskb);
Bryan Wu1394f032007-05-06 14:50:22 -0700741}
742
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800743void bfin_gpio_pm_hibernate_suspend(void)
744{
745 int i, bank;
746
747 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
748 bank = gpio_bank(i);
749
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800750#if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800751 gpio_bank_saved[bank].fer = *port_fer[bank];
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800752#if defined(BF527_FAMILY) || defined(BF518_FAMILY)
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800753 gpio_bank_saved[bank].mux = *port_mux[bank];
754#else
755 if (bank == 0)
756 gpio_bank_saved[bank].mux = bfin_read_PORT_MUX();
757#endif
758#endif
759 gpio_bank_saved[bank].data = gpio_bankb[bank]->data;
760 gpio_bank_saved[bank].inen = gpio_bankb[bank]->inen;
761 gpio_bank_saved[bank].polar = gpio_bankb[bank]->polar;
762 gpio_bank_saved[bank].dir = gpio_bankb[bank]->dir;
763 gpio_bank_saved[bank].edge = gpio_bankb[bank]->edge;
764 gpio_bank_saved[bank].both = gpio_bankb[bank]->both;
765 gpio_bank_saved[bank].maska = gpio_bankb[bank]->maska;
766 }
767
768 AWA_DUMMY_READ(maska);
769}
770
771void bfin_gpio_pm_hibernate_restore(void)
772{
773 int i, bank;
774
775 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
776 bank = gpio_bank(i);
777
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800778#if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
779#if defined(BF527_FAMILY) || defined(BF518_FAMILY)
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800780 *port_mux[bank] = gpio_bank_saved[bank].mux;
781#else
782 if (bank == 0)
783 bfin_write_PORT_MUX(gpio_bank_saved[bank].mux);
784#endif
785 *port_fer[bank] = gpio_bank_saved[bank].fer;
786#endif
787 gpio_bankb[bank]->inen = gpio_bank_saved[bank].inen;
788 gpio_bankb[bank]->dir = gpio_bank_saved[bank].dir;
789 gpio_bankb[bank]->polar = gpio_bank_saved[bank].polar;
790 gpio_bankb[bank]->edge = gpio_bank_saved[bank].edge;
791 gpio_bankb[bank]->both = gpio_bank_saved[bank].both;
792
793 gpio_bankb[bank]->data_set = gpio_bank_saved[bank].data
794 | gpio_bank_saved[bank].dir;
795
796 gpio_bankb[bank]->maska = gpio_bank_saved[bank].maska;
797 }
798 AWA_DUMMY_READ(maska);
799}
800
801
Bryan Wu1394f032007-05-06 14:50:22 -0700802#endif
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800803#else /* BF548_FAMILY */
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800804#ifdef CONFIG_PM
805
806u32 bfin_pm_standby_setup(void)
807{
808 return 0;
809}
810
811void bfin_pm_standby_restore(void)
812{
813
814}
815
816void bfin_gpio_pm_hibernate_suspend(void)
817{
818 int i, bank;
819
820 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
821 bank = gpio_bank(i);
822
823 gpio_bank_saved[bank].fer = gpio_array[bank]->port_fer;
824 gpio_bank_saved[bank].mux = gpio_array[bank]->port_mux;
825 gpio_bank_saved[bank].data = gpio_array[bank]->port_data;
826 gpio_bank_saved[bank].data = gpio_array[bank]->port_data;
827 gpio_bank_saved[bank].inen = gpio_array[bank]->port_inen;
828 gpio_bank_saved[bank].dir = gpio_array[bank]->port_dir_set;
829 }
830}
831
832void bfin_gpio_pm_hibernate_restore(void)
833{
834 int i, bank;
835
836 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
837 bank = gpio_bank(i);
838
839 gpio_array[bank]->port_mux = gpio_bank_saved[bank].mux;
840 gpio_array[bank]->port_fer = gpio_bank_saved[bank].fer;
841 gpio_array[bank]->port_inen = gpio_bank_saved[bank].inen;
842 gpio_array[bank]->port_dir_set = gpio_bank_saved[bank].dir;
843 gpio_array[bank]->port_set = gpio_bank_saved[bank].data
844 | gpio_bank_saved[bank].dir;
845 }
846}
847#endif
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800848
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800849unsigned short get_gpio_dir(unsigned gpio)
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800850{
851 return (0x01 & (gpio_array[gpio_bank(gpio)]->port_dir_clear >> gpio_sub_n(gpio)));
852}
853EXPORT_SYMBOL(get_gpio_dir);
854
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800855#endif /* BF548_FAMILY */
Bryan Wu1394f032007-05-06 14:50:22 -0700856
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800857/***********************************************************
858*
859* FUNCTIONS: Blackfin Peripheral Resource Allocation
860* and PortMux Setup
861*
862* INPUTS/OUTPUTS:
863* per Peripheral Identifier
864* label String
865*
866* DESCRIPTION: Blackfin Peripheral Resource Allocation and Setup API
867*
868* CAUTION:
869*************************************************************
870* MODIFICATION HISTORY :
871**************************************************************/
Michael Hennerichc58c2142007-10-04 00:35:05 +0800872
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800873#ifdef BF548_FAMILY
874int peripheral_request(unsigned short per, const char *label)
875{
876 unsigned long flags;
877 unsigned short ident = P_IDENT(per);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800878
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800879 /*
880 * Don't cares are pins with only one dedicated function
881 */
882
883 if (per & P_DONTCARE)
884 return 0;
885
886 if (!(per & P_DEFINED))
887 return -ENODEV;
888
889 if (check_gpio(ident) < 0)
890 return -EINVAL;
891
892 local_irq_save(flags);
893
894 if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
Mike Frysingerf85c4ab2008-03-26 08:34:23 +0800895 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800896 printk(KERN_ERR
897 "%s: Peripheral %d is already reserved as GPIO by %s !\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800898 __func__, ident, get_label(ident));
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800899 local_irq_restore(flags);
900 return -EBUSY;
901 }
902
903 if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) {
904
905 u16 funct = get_portmux(ident);
906
Mike Frysingerd171c232008-03-26 08:35:46 +0800907 /*
908 * Pin functions like AMC address strobes my
909 * be requested and used by several drivers
910 */
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800911
912 if (!((per & P_MAYSHARE) && (funct == P_FUNCT2MUX(per)))) {
913
Mike Frysingerd171c232008-03-26 08:35:46 +0800914 /*
915 * Allow that the identical pin function can
916 * be requested from the same driver twice
917 */
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800918
Mike Frysingerd171c232008-03-26 08:35:46 +0800919 if (cmp_label(ident, label) == 0)
920 goto anyway;
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800921
Mike Frysingerf85c4ab2008-03-26 08:34:23 +0800922 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800923 printk(KERN_ERR
924 "%s: Peripheral %d function %d is already reserved by %s !\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800925 __func__, ident, P_FUNCT2MUX(per), get_label(ident));
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800926 local_irq_restore(flags);
927 return -EBUSY;
928 }
929 }
930
Mike Frysingerd171c232008-03-26 08:35:46 +0800931 anyway:
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800932 reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident);
933
934 portmux_setup(ident, P_FUNCT2MUX(per));
935 port_setup(ident, PERIPHERAL_USAGE);
936
937 local_irq_restore(flags);
938 set_label(ident, label);
939
940 return 0;
941}
942EXPORT_SYMBOL(peripheral_request);
943#else
Michael Hennerichc58c2142007-10-04 00:35:05 +0800944
945int peripheral_request(unsigned short per, const char *label)
946{
947 unsigned long flags;
948 unsigned short ident = P_IDENT(per);
949
950 /*
951 * Don't cares are pins with only one dedicated function
952 */
953
954 if (per & P_DONTCARE)
955 return 0;
956
957 if (!(per & P_DEFINED))
958 return -ENODEV;
959
Michael Hennerichc58c2142007-10-04 00:35:05 +0800960 local_irq_save(flags);
961
Michael Hennerichcda6a202007-10-04 00:36:18 +0800962 if (!check_gpio(ident)) {
963
Mike Frysingerd171c232008-03-26 08:35:46 +0800964 if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
965 dump_stack();
966 printk(KERN_ERR
967 "%s: Peripheral %d is already reserved as GPIO by %s !\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800968 __func__, ident, get_label(ident));
Mike Frysingerd171c232008-03-26 08:35:46 +0800969 local_irq_restore(flags);
970 return -EBUSY;
971 }
Michael Hennerichc58c2142007-10-04 00:35:05 +0800972
Michael Hennerichcda6a202007-10-04 00:36:18 +0800973 }
974
Michael Hennerichc58c2142007-10-04 00:35:05 +0800975 if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) {
976
Mike Frysingerd171c232008-03-26 08:35:46 +0800977 /*
978 * Pin functions like AMC address strobes my
979 * be requested and used by several drivers
980 */
Michael Hennerichc58c2142007-10-04 00:35:05 +0800981
Mike Frysingerd171c232008-03-26 08:35:46 +0800982 if (!(per & P_MAYSHARE)) {
Michael Hennerichc58c2142007-10-04 00:35:05 +0800983
Mike Frysingerd171c232008-03-26 08:35:46 +0800984 /*
985 * Allow that the identical pin function can
986 * be requested from the same driver twice
987 */
Michael Hennerichc58c2142007-10-04 00:35:05 +0800988
Mike Frysingerd171c232008-03-26 08:35:46 +0800989 if (cmp_label(ident, label) == 0)
990 goto anyway;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800991
Mike Frysingerf85c4ab2008-03-26 08:34:23 +0800992 dump_stack();
Michael Hennerichc58c2142007-10-04 00:35:05 +0800993 printk(KERN_ERR
994 "%s: Peripheral %d function %d is already"
Michael Hennerich8c613622007-08-03 17:48:09 +0800995 " reserved by %s !\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800996 __func__, ident, P_FUNCT2MUX(per),
Michael Hennerichc58c2142007-10-04 00:35:05 +0800997 get_label(ident));
Michael Hennerichc58c2142007-10-04 00:35:05 +0800998 local_irq_restore(flags);
999 return -EBUSY;
1000 }
1001
1002 }
1003
Mike Frysingerd171c232008-03-26 08:35:46 +08001004 anyway:
Michael Hennerichc58c2142007-10-04 00:35:05 +08001005 portmux_setup(per, P_FUNCT2MUX(per));
1006
1007 port_setup(ident, PERIPHERAL_USAGE);
1008
1009 reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident);
1010 local_irq_restore(flags);
1011 set_label(ident, label);
1012
1013 return 0;
1014}
1015EXPORT_SYMBOL(peripheral_request);
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001016#endif
Michael Hennerichc58c2142007-10-04 00:35:05 +08001017
Mike Frysinger68179372008-04-24 05:04:24 +08001018int peripheral_request_list(const unsigned short per[], const char *label)
Michael Hennerichc58c2142007-10-04 00:35:05 +08001019{
1020 u16 cnt;
1021 int ret;
1022
1023 for (cnt = 0; per[cnt] != 0; cnt++) {
Michael Hennerich314c98d2007-07-24 18:03:45 +08001024
Michael Hennerichc58c2142007-10-04 00:35:05 +08001025 ret = peripheral_request(per[cnt], label);
Michael Hennerich314c98d2007-07-24 18:03:45 +08001026
1027 if (ret < 0) {
Mike Frysingerd171c232008-03-26 08:35:46 +08001028 for ( ; cnt > 0; cnt--)
Michael Hennerich314c98d2007-07-24 18:03:45 +08001029 peripheral_free(per[cnt - 1]);
Mike Frysingerd171c232008-03-26 08:35:46 +08001030
1031 return ret;
Michael Hennerich314c98d2007-07-24 18:03:45 +08001032 }
Michael Hennerichc58c2142007-10-04 00:35:05 +08001033 }
1034
1035 return 0;
1036}
1037EXPORT_SYMBOL(peripheral_request_list);
1038
1039void peripheral_free(unsigned short per)
1040{
1041 unsigned long flags;
1042 unsigned short ident = P_IDENT(per);
1043
1044 if (per & P_DONTCARE)
1045 return;
1046
1047 if (!(per & P_DEFINED))
1048 return;
1049
1050 if (check_gpio(ident) < 0)
1051 return;
1052
1053 local_irq_save(flags);
1054
Mike Frysingerd171c232008-03-26 08:35:46 +08001055 if (unlikely(!(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident)))) {
Michael Hennerichc58c2142007-10-04 00:35:05 +08001056 local_irq_restore(flags);
1057 return;
1058 }
1059
Mike Frysingerd171c232008-03-26 08:35:46 +08001060 if (!(per & P_MAYSHARE))
Michael Hennerichc58c2142007-10-04 00:35:05 +08001061 port_setup(ident, GPIO_USAGE);
Michael Hennerichc58c2142007-10-04 00:35:05 +08001062
1063 reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident);
1064
Michael Hennerich2acde902007-10-11 00:24:40 +08001065 set_label(ident, "free");
1066
Michael Hennerichc58c2142007-10-04 00:35:05 +08001067 local_irq_restore(flags);
1068}
1069EXPORT_SYMBOL(peripheral_free);
1070
Mike Frysinger68179372008-04-24 05:04:24 +08001071void peripheral_free_list(const unsigned short per[])
Michael Hennerichc58c2142007-10-04 00:35:05 +08001072{
1073 u16 cnt;
Mike Frysingerd171c232008-03-26 08:35:46 +08001074 for (cnt = 0; per[cnt] != 0; cnt++)
Michael Hennerichc58c2142007-10-04 00:35:05 +08001075 peripheral_free(per[cnt]);
Michael Hennerichc58c2142007-10-04 00:35:05 +08001076}
1077EXPORT_SYMBOL(peripheral_free_list);
1078
Bryan Wu1394f032007-05-06 14:50:22 -07001079/***********************************************************
1080*
1081* FUNCTIONS: Blackfin GPIO Driver
1082*
1083* INPUTS/OUTPUTS:
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001084* gpio PIO Number between 0 and MAX_BLACKFIN_GPIOS
1085* label String
Bryan Wu1394f032007-05-06 14:50:22 -07001086*
1087* DESCRIPTION: Blackfin GPIO Driver API
1088*
1089* CAUTION:
1090*************************************************************
1091* MODIFICATION HISTORY :
1092**************************************************************/
1093
Michael Hennerichacbcd262008-01-22 18:36:20 +08001094int gpio_request(unsigned gpio, const char *label)
Bryan Wu1394f032007-05-06 14:50:22 -07001095{
1096 unsigned long flags;
1097
1098 if (check_gpio(gpio) < 0)
1099 return -EINVAL;
1100
1101 local_irq_save(flags);
1102
Michael Hennerich2acde902007-10-11 00:24:40 +08001103 /*
1104 * Allow that the identical GPIO can
1105 * be requested from the same driver twice
1106 * Do nothing and return -
1107 */
1108
1109 if (cmp_label(gpio, label) == 0) {
1110 local_irq_restore(flags);
1111 return 0;
1112 }
1113
Michael Hennerichc58c2142007-10-04 00:35:05 +08001114 if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
Mike Frysingerf85c4ab2008-03-26 08:34:23 +08001115 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001116 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
1117 gpio, get_label(gpio));
Bryan Wu1394f032007-05-06 14:50:22 -07001118 local_irq_restore(flags);
1119 return -EBUSY;
1120 }
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001121 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
Mike Frysingerf85c4ab2008-03-26 08:34:23 +08001122 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001123 printk(KERN_ERR
1124 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
1125 gpio, get_label(gpio));
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001126 local_irq_restore(flags);
1127 return -EBUSY;
1128 }
1129
Michael Hennerichc58c2142007-10-04 00:35:05 +08001130 reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio);
Bryan Wu1394f032007-05-06 14:50:22 -07001131
1132 local_irq_restore(flags);
1133
1134 port_setup(gpio, GPIO_USAGE);
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001135 set_label(gpio, label);
Bryan Wu1394f032007-05-06 14:50:22 -07001136
1137 return 0;
1138}
1139EXPORT_SYMBOL(gpio_request);
1140
Michael Hennerichacbcd262008-01-22 18:36:20 +08001141void gpio_free(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -07001142{
1143 unsigned long flags;
1144
1145 if (check_gpio(gpio) < 0)
1146 return;
1147
1148 local_irq_save(flags);
1149
Michael Hennerichc58c2142007-10-04 00:35:05 +08001150 if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
Bryan Wu1394f032007-05-06 14:50:22 -07001151 dump_stack();
Mike Frysingerf85c4ab2008-03-26 08:34:23 +08001152 gpio_error(gpio);
Bryan Wu1394f032007-05-06 14:50:22 -07001153 local_irq_restore(flags);
1154 return;
1155 }
1156
Michael Hennerichc58c2142007-10-04 00:35:05 +08001157 reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
Bryan Wu1394f032007-05-06 14:50:22 -07001158
Michael Hennerich2acde902007-10-11 00:24:40 +08001159 set_label(gpio, "free");
1160
Bryan Wu1394f032007-05-06 14:50:22 -07001161 local_irq_restore(flags);
1162}
1163EXPORT_SYMBOL(gpio_free);
1164
Michael Hennerichacbcd262008-01-22 18:36:20 +08001165
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001166#ifdef BF548_FAMILY
Michael Hennerichacbcd262008-01-22 18:36:20 +08001167int gpio_direction_input(unsigned gpio)
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001168{
1169 unsigned long flags;
1170
Michael Hennerichacbcd262008-01-22 18:36:20 +08001171 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1172 gpio_error(gpio);
1173 return -EINVAL;
1174 }
1175
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001176 local_irq_save(flags);
1177 gpio_array[gpio_bank(gpio)]->port_dir_clear = gpio_bit(gpio);
1178 gpio_array[gpio_bank(gpio)]->port_inen |= gpio_bit(gpio);
1179 local_irq_restore(flags);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001180
1181 return 0;
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001182}
1183EXPORT_SYMBOL(gpio_direction_input);
1184
Michael Hennerichacbcd262008-01-22 18:36:20 +08001185int gpio_direction_output(unsigned gpio, int value)
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001186{
1187 unsigned long flags;
1188
Michael Hennerichacbcd262008-01-22 18:36:20 +08001189 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1190 gpio_error(gpio);
1191 return -EINVAL;
1192 }
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001193
1194 local_irq_save(flags);
1195 gpio_array[gpio_bank(gpio)]->port_inen &= ~gpio_bit(gpio);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001196 gpio_set_value(gpio, value);
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001197 gpio_array[gpio_bank(gpio)]->port_dir_set = gpio_bit(gpio);
1198 local_irq_restore(flags);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001199
1200 return 0;
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001201}
1202EXPORT_SYMBOL(gpio_direction_output);
1203
Michael Hennerichacbcd262008-01-22 18:36:20 +08001204void gpio_set_value(unsigned gpio, int arg)
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001205{
1206 if (arg)
1207 gpio_array[gpio_bank(gpio)]->port_set = gpio_bit(gpio);
1208 else
1209 gpio_array[gpio_bank(gpio)]->port_clear = gpio_bit(gpio);
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001210}
1211EXPORT_SYMBOL(gpio_set_value);
1212
Michael Hennerichacbcd262008-01-22 18:36:20 +08001213int gpio_get_value(unsigned gpio)
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001214{
1215 return (1 & (gpio_array[gpio_bank(gpio)]->port_data >> gpio_sub_n(gpio)));
1216}
1217EXPORT_SYMBOL(gpio_get_value);
1218
Michael Hennerichaffee2b2008-04-24 08:10:10 +08001219void bfin_gpio_irq_prepare(unsigned gpio)
1220{
1221 unsigned long flags;
1222
1223 port_setup(gpio, GPIO_USAGE);
1224
1225 local_irq_save(flags);
1226 gpio_array[gpio_bank(gpio)]->port_dir_clear = gpio_bit(gpio);
1227 gpio_array[gpio_bank(gpio)]->port_inen |= gpio_bit(gpio);
1228 local_irq_restore(flags);
1229}
1230
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001231#else
1232
Michael Hennerich803a8d22008-05-17 16:01:51 +08001233int gpio_get_value(unsigned gpio)
1234{
1235 unsigned long flags;
1236 int ret;
1237
1238 if (unlikely(get_gpio_edge(gpio))) {
1239 local_irq_save(flags);
1240 set_gpio_edge(gpio, 0);
1241 ret = get_gpio_data(gpio);
1242 set_gpio_edge(gpio, 1);
1243 local_irq_restore(flags);
1244
1245 return ret;
1246 } else
1247 return get_gpio_data(gpio);
1248}
1249EXPORT_SYMBOL(gpio_get_value);
1250
1251
Michael Hennerichacbcd262008-01-22 18:36:20 +08001252int gpio_direction_input(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -07001253{
1254 unsigned long flags;
1255
Michael Hennerichacbcd262008-01-22 18:36:20 +08001256 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1257 gpio_error(gpio);
1258 return -EINVAL;
1259 }
Bryan Wu1394f032007-05-06 14:50:22 -07001260
1261 local_irq_save(flags);
1262 gpio_bankb[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio);
1263 gpio_bankb[gpio_bank(gpio)]->inen |= gpio_bit(gpio);
Michael Hennerich2b393312007-10-10 16:58:49 +08001264 AWA_DUMMY_READ(inen);
Bryan Wu1394f032007-05-06 14:50:22 -07001265 local_irq_restore(flags);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001266
1267 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -07001268}
1269EXPORT_SYMBOL(gpio_direction_input);
1270
Michael Hennerichacbcd262008-01-22 18:36:20 +08001271int gpio_direction_output(unsigned gpio, int value)
Bryan Wu1394f032007-05-06 14:50:22 -07001272{
1273 unsigned long flags;
1274
Michael Hennerichacbcd262008-01-22 18:36:20 +08001275 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1276 gpio_error(gpio);
1277 return -EINVAL;
1278 }
Bryan Wu1394f032007-05-06 14:50:22 -07001279
1280 local_irq_save(flags);
1281 gpio_bankb[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio);
Michael Hennericha2c8cfe2008-01-22 17:20:10 +08001282
1283 if (value)
1284 gpio_bankb[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
1285 else
1286 gpio_bankb[gpio_bank(gpio)]->data_clear = gpio_bit(gpio);
1287
Bryan Wu1394f032007-05-06 14:50:22 -07001288 gpio_bankb[gpio_bank(gpio)]->dir |= gpio_bit(gpio);
Michael Hennerich2b393312007-10-10 16:58:49 +08001289 AWA_DUMMY_READ(dir);
Bryan Wu1394f032007-05-06 14:50:22 -07001290 local_irq_restore(flags);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001291
1292 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -07001293}
1294EXPORT_SYMBOL(gpio_direction_output);
Mike Frysinger168f1212007-10-11 00:22:35 +08001295
1296/* If we are booting from SPI and our board lacks a strong enough pull up,
1297 * the core can reset and execute the bootrom faster than the resistor can
1298 * pull the signal logically high. To work around this (common) error in
1299 * board design, we explicitly set the pin back to GPIO mode, force /CS
1300 * high, and wait for the electrons to do their thing.
1301 *
1302 * This function only makes sense to be called from reset code, but it
1303 * lives here as we need to force all the GPIO states w/out going through
1304 * BUG() checks and such.
1305 */
1306void bfin_gpio_reset_spi0_ssel1(void)
1307{
Michael Hennerich4d5f4ed2007-08-27 16:46:17 +08001308 u16 gpio = P_IDENT(P_SPI0_SSEL1);
1309
1310 port_setup(gpio, GPIO_USAGE);
1311 gpio_bankb[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
Michael Hennericha2c8cfe2008-01-22 17:20:10 +08001312 AWA_DUMMY_READ(data_set);
Mike Frysinger168f1212007-10-11 00:22:35 +08001313 udelay(1);
1314}
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001315
Michael Hennerichaffee2b2008-04-24 08:10:10 +08001316void bfin_gpio_irq_prepare(unsigned gpio)
1317{
1318 port_setup(gpio, GPIO_USAGE);
1319}
1320
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001321#endif /*BF548_FAMILY */
Mike Frysinger1545a112007-12-24 16:54:48 +08001322
1323#if defined(CONFIG_PROC_FS)
1324static int gpio_proc_read(char *buf, char **start, off_t offset,
1325 int len, int *unused_i, void *unused_v)
1326{
1327 int c, outlen = 0;
1328
1329 for (c = 0; c < MAX_RESOURCES; c++) {
1330 if (!check_gpio(c) && (reserved_gpio_map[gpio_bank(c)] & gpio_bit(c)))
Michael Hennerichfac3cf42007-12-24 20:07:03 +08001331 len = sprintf(buf, "GPIO_%d: %s \t\tGPIO %s\n", c,
Mike Frysinger1545a112007-12-24 16:54:48 +08001332 get_label(c), get_gpio_dir(c) ? "OUTPUT" : "INPUT");
1333 else if (reserved_peri_map[gpio_bank(c)] & gpio_bit(c))
Michael Hennerichfac3cf42007-12-24 20:07:03 +08001334 len = sprintf(buf, "GPIO_%d: %s \t\tPeripheral\n", c, get_label(c));
Mike Frysinger1545a112007-12-24 16:54:48 +08001335 else
1336 continue;
1337 buf += len;
1338 outlen += len;
1339 }
1340 return outlen;
1341}
1342
1343static __init int gpio_register_proc(void)
1344{
1345 struct proc_dir_entry *proc_gpio;
1346
1347 proc_gpio = create_proc_entry("gpio", S_IRUGO, NULL);
1348 if (proc_gpio)
1349 proc_gpio->read_proc = gpio_proc_read;
1350 return proc_gpio != NULL;
1351}
Mike Frysinger1545a112007-12-24 16:54:48 +08001352__initcall(gpio_register_proc);
1353#endif