blob: a808baf5d3095cbbade21655e716ef9a4a8a8859 [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)
Michael Hennerich8c613622007-08-03 17:48:09 +0800259 return strncmp(str_ident[ident].name,
Michael Hennerichc58c2142007-10-04 00:35:05 +0800260 label, strlen(label));
261 else
262 return -EINVAL;
263}
264
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800265#if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800266static void port_setup(unsigned gpio, unsigned short usage)
Bryan Wu1394f032007-05-06 14:50:22 -0700267{
Michael Hennerichcda6a202007-10-04 00:36:18 +0800268 if (!check_gpio(gpio)) {
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800269 if (usage == GPIO_USAGE)
Michael Hennerichcda6a202007-10-04 00:36:18 +0800270 *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800271 else
Michael Hennerichcda6a202007-10-04 00:36:18 +0800272 *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio);
273 SSYNC();
274 }
Bryan Wu1394f032007-05-06 14:50:22 -0700275}
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800276#elif defined(BF548_FAMILY)
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800277static void port_setup(unsigned gpio, unsigned short usage)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800278{
279 if (usage == GPIO_USAGE)
280 gpio_array[gpio_bank(gpio)]->port_fer &= ~gpio_bit(gpio);
281 else
282 gpio_array[gpio_bank(gpio)]->port_fer |= gpio_bit(gpio);
283 SSYNC();
284}
Bryan Wu1394f032007-05-06 14:50:22 -0700285#else
286# define port_setup(...) do { } while (0)
287#endif
288
Michael Hennerichc58c2142007-10-04 00:35:05 +0800289#ifdef BF537_FAMILY
Michael Hennerich8c613622007-08-03 17:48:09 +0800290static struct {
291 unsigned short res;
292 unsigned short offset;
293} port_mux_lut[] = {
294 {.res = P_PPI0_D13, .offset = 11},
295 {.res = P_PPI0_D14, .offset = 11},
296 {.res = P_PPI0_D15, .offset = 11},
297 {.res = P_SPORT1_TFS, .offset = 11},
298 {.res = P_SPORT1_TSCLK, .offset = 11},
299 {.res = P_SPORT1_DTPRI, .offset = 11},
300 {.res = P_PPI0_D10, .offset = 10},
301 {.res = P_PPI0_D11, .offset = 10},
302 {.res = P_PPI0_D12, .offset = 10},
303 {.res = P_SPORT1_RSCLK, .offset = 10},
304 {.res = P_SPORT1_RFS, .offset = 10},
305 {.res = P_SPORT1_DRPRI, .offset = 10},
306 {.res = P_PPI0_D8, .offset = 9},
307 {.res = P_PPI0_D9, .offset = 9},
308 {.res = P_SPORT1_DRSEC, .offset = 9},
309 {.res = P_SPORT1_DTSEC, .offset = 9},
310 {.res = P_TMR2, .offset = 8},
311 {.res = P_PPI0_FS3, .offset = 8},
312 {.res = P_TMR3, .offset = 7},
313 {.res = P_SPI0_SSEL4, .offset = 7},
314 {.res = P_TMR4, .offset = 6},
315 {.res = P_SPI0_SSEL5, .offset = 6},
316 {.res = P_TMR5, .offset = 5},
317 {.res = P_SPI0_SSEL6, .offset = 5},
318 {.res = P_UART1_RX, .offset = 4},
319 {.res = P_UART1_TX, .offset = 4},
320 {.res = P_TMR6, .offset = 4},
321 {.res = P_TMR7, .offset = 4},
322 {.res = P_UART0_RX, .offset = 3},
323 {.res = P_UART0_TX, .offset = 3},
324 {.res = P_DMAR0, .offset = 3},
325 {.res = P_DMAR1, .offset = 3},
326 {.res = P_SPORT0_DTSEC, .offset = 1},
327 {.res = P_SPORT0_DRSEC, .offset = 1},
328 {.res = P_CAN0_RX, .offset = 1},
329 {.res = P_CAN0_TX, .offset = 1},
330 {.res = P_SPI0_SSEL7, .offset = 1},
331 {.res = P_SPORT0_TFS, .offset = 0},
332 {.res = P_SPORT0_DTPRI, .offset = 0},
333 {.res = P_SPI0_SSEL2, .offset = 0},
334 {.res = P_SPI0_SSEL3, .offset = 0},
Michael Hennerichc58c2142007-10-04 00:35:05 +0800335};
336
337static void portmux_setup(unsigned short per, unsigned short function)
338{
Michael Hennerich8c613622007-08-03 17:48:09 +0800339 u16 y, offset, muxreg;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800340
Michael Hennerich8c613622007-08-03 17:48:09 +0800341 for (y = 0; y < ARRAY_SIZE(port_mux_lut); y++) {
342 if (port_mux_lut[y].res == per) {
Michael Hennerichc58c2142007-10-04 00:35:05 +0800343
344 /* SET PORTMUX REG */
345
Michael Hennerich8c613622007-08-03 17:48:09 +0800346 offset = port_mux_lut[y].offset;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800347 muxreg = bfin_read_PORT_MUX();
348
Mike Frysingerd171c232008-03-26 08:35:46 +0800349 if (offset != 1)
Michael Hennerichc58c2142007-10-04 00:35:05 +0800350 muxreg &= ~(1 << offset);
Mike Frysingerd171c232008-03-26 08:35:46 +0800351 else
Michael Hennerichc58c2142007-10-04 00:35:05 +0800352 muxreg &= ~(3 << 1);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800353
354 muxreg |= (function << offset);
355 bfin_write_PORT_MUX(muxreg);
356 }
357 }
358}
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800359#elif defined(BF548_FAMILY)
360inline void portmux_setup(unsigned short portno, unsigned short function)
361{
362 u32 pmux;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800363
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800364 pmux = gpio_array[gpio_bank(portno)]->port_mux;
365
366 pmux &= ~(0x3 << (2 * gpio_sub_n(portno)));
367 pmux |= (function & 0x3) << (2 * gpio_sub_n(portno));
368
369 gpio_array[gpio_bank(portno)]->port_mux = pmux;
370}
371
372inline u16 get_portmux(unsigned short portno)
373{
374 u32 pmux;
375
376 pmux = gpio_array[gpio_bank(portno)]->port_mux;
377
378 return (pmux >> (2 * gpio_sub_n(portno)) & 0x3);
379}
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800380#elif defined(BF527_FAMILY) || defined(BF518_FAMILY)
Michael Hennerich59003142007-10-21 16:54:27 +0800381inline void portmux_setup(unsigned short portno, unsigned short function)
382{
383 u16 pmux, ident = P_IDENT(portno);
384 u8 offset = pmux_offset[gpio_bank(ident)][gpio_sub_n(ident)];
385
386 pmux = *port_mux[gpio_bank(ident)];
387 pmux &= ~(3 << offset);
388 pmux |= (function & 3) << offset;
389 *port_mux[gpio_bank(ident)] = pmux;
390 SSYNC();
391}
Michael Hennerichc58c2142007-10-04 00:35:05 +0800392#else
393# define portmux_setup(...) do { } while (0)
394#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700395
Mike Frysingera161bb02007-05-21 18:09:14 +0800396static int __init bfin_gpio_init(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700397{
Bryan Wu1394f032007-05-06 14:50:22 -0700398 printk(KERN_INFO "Blackfin GPIO Controller\n");
399
Bryan Wu1394f032007-05-06 14:50:22 -0700400 return 0;
401}
Bryan Wu1394f032007-05-06 14:50:22 -0700402arch_initcall(bfin_gpio_init);
403
404
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800405#ifndef BF548_FAMILY
Bryan Wu1394f032007-05-06 14:50:22 -0700406/***********************************************************
407*
408* FUNCTIONS: Blackfin General Purpose Ports Access Functions
409*
410* INPUTS/OUTPUTS:
411* gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
412*
413*
414* DESCRIPTION: These functions abstract direct register access
415* to Blackfin processor General Purpose
416* Ports Regsiters
417*
418* CAUTION: These functions do not belong to the GPIO Driver API
419*************************************************************
420* MODIFICATION HISTORY :
421**************************************************************/
422
423/* Set a specific bit */
424
425#define SET_GPIO(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800426void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
Bryan Wu1394f032007-05-06 14:50:22 -0700427{ \
428 unsigned long flags; \
Bryan Wu1394f032007-05-06 14:50:22 -0700429 local_irq_save(flags); \
430 if (arg) \
431 gpio_bankb[gpio_bank(gpio)]->name |= gpio_bit(gpio); \
432 else \
433 gpio_bankb[gpio_bank(gpio)]->name &= ~gpio_bit(gpio); \
Michael Hennerich2b393312007-10-10 16:58:49 +0800434 AWA_DUMMY_READ(name); \
Bryan Wu1394f032007-05-06 14:50:22 -0700435 local_irq_restore(flags); \
436} \
437EXPORT_SYMBOL(set_gpio_ ## name);
438
439SET_GPIO(dir)
440SET_GPIO(inen)
441SET_GPIO(polar)
442SET_GPIO(edge)
443SET_GPIO(both)
444
445
Michael Hennerich2b393312007-10-10 16:58:49 +0800446#if ANOMALY_05000311 || ANOMALY_05000323
447#define SET_GPIO_SC(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800448void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800449{ \
450 unsigned long flags; \
Michael Hennerich2b393312007-10-10 16:58:49 +0800451 local_irq_save(flags); \
452 if (arg) \
453 gpio_bankb[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \
454 else \
455 gpio_bankb[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \
456 AWA_DUMMY_READ(name); \
457 local_irq_restore(flags); \
458} \
459EXPORT_SYMBOL(set_gpio_ ## name);
460#else
Bryan Wu1394f032007-05-06 14:50:22 -0700461#define SET_GPIO_SC(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800462void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
Bryan Wu1394f032007-05-06 14:50:22 -0700463{ \
Bryan Wu1394f032007-05-06 14:50:22 -0700464 if (arg) \
465 gpio_bankb[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \
466 else \
467 gpio_bankb[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \
468} \
469EXPORT_SYMBOL(set_gpio_ ## name);
Michael Hennerich2b393312007-10-10 16:58:49 +0800470#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700471
472SET_GPIO_SC(maska)
473SET_GPIO_SC(maskb)
Bryan Wu1394f032007-05-06 14:50:22 -0700474SET_GPIO_SC(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700475
Michael Hennerich2b393312007-10-10 16:58:49 +0800476#if ANOMALY_05000311 || ANOMALY_05000323
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800477void set_gpio_toggle(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -0700478{
479 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700480 local_irq_save(flags);
481 gpio_bankb[gpio_bank(gpio)]->toggle = gpio_bit(gpio);
Michael Hennerich2b393312007-10-10 16:58:49 +0800482 AWA_DUMMY_READ(toggle);
Bryan Wu1394f032007-05-06 14:50:22 -0700483 local_irq_restore(flags);
484}
485#else
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800486void set_gpio_toggle(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -0700487{
Bryan Wu1394f032007-05-06 14:50:22 -0700488 gpio_bankb[gpio_bank(gpio)]->toggle = gpio_bit(gpio);
489}
490#endif
491EXPORT_SYMBOL(set_gpio_toggle);
492
493
494/*Set current PORT date (16-bit word)*/
495
Michael Hennerich2b393312007-10-10 16:58:49 +0800496#if ANOMALY_05000311 || ANOMALY_05000323
497#define SET_GPIO_P(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800498void set_gpiop_ ## name(unsigned gpio, unsigned short arg) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800499{ \
500 unsigned long flags; \
501 local_irq_save(flags); \
502 gpio_bankb[gpio_bank(gpio)]->name = arg; \
503 AWA_DUMMY_READ(name); \
504 local_irq_restore(flags); \
505} \
506EXPORT_SYMBOL(set_gpiop_ ## name);
507#else
Bryan Wu1394f032007-05-06 14:50:22 -0700508#define SET_GPIO_P(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800509void set_gpiop_ ## name(unsigned gpio, unsigned short arg) \
Bryan Wu1394f032007-05-06 14:50:22 -0700510{ \
511 gpio_bankb[gpio_bank(gpio)]->name = arg; \
512} \
513EXPORT_SYMBOL(set_gpiop_ ## name);
Michael Hennerich2b393312007-10-10 16:58:49 +0800514#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700515
Michael Hennerich2b393312007-10-10 16:58:49 +0800516SET_GPIO_P(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700517SET_GPIO_P(dir)
518SET_GPIO_P(inen)
519SET_GPIO_P(polar)
520SET_GPIO_P(edge)
521SET_GPIO_P(both)
522SET_GPIO_P(maska)
523SET_GPIO_P(maskb)
524
Bryan Wu1394f032007-05-06 14:50:22 -0700525/* Get a specific bit */
Michael Hennerich2b393312007-10-10 16:58:49 +0800526#if ANOMALY_05000311 || ANOMALY_05000323
527#define GET_GPIO(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800528unsigned short get_gpio_ ## name(unsigned gpio) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800529{ \
530 unsigned long flags; \
531 unsigned short ret; \
532 local_irq_save(flags); \
533 ret = 0x01 & (gpio_bankb[gpio_bank(gpio)]->name >> gpio_sub_n(gpio)); \
534 AWA_DUMMY_READ(name); \
535 local_irq_restore(flags); \
536 return ret; \
537} \
538EXPORT_SYMBOL(get_gpio_ ## name);
539#else
Bryan Wu1394f032007-05-06 14:50:22 -0700540#define GET_GPIO(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800541unsigned short get_gpio_ ## name(unsigned gpio) \
Bryan Wu1394f032007-05-06 14:50:22 -0700542{ \
543 return (0x01 & (gpio_bankb[gpio_bank(gpio)]->name >> gpio_sub_n(gpio))); \
544} \
545EXPORT_SYMBOL(get_gpio_ ## name);
Michael Hennerich2b393312007-10-10 16:58:49 +0800546#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700547
Michael Hennerich2b393312007-10-10 16:58:49 +0800548GET_GPIO(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700549GET_GPIO(dir)
550GET_GPIO(inen)
551GET_GPIO(polar)
552GET_GPIO(edge)
553GET_GPIO(both)
554GET_GPIO(maska)
555GET_GPIO(maskb)
556
Bryan Wu1394f032007-05-06 14:50:22 -0700557/*Get current PORT date (16-bit word)*/
558
Michael Hennerich2b393312007-10-10 16:58:49 +0800559#if ANOMALY_05000311 || ANOMALY_05000323
560#define GET_GPIO_P(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800561unsigned short get_gpiop_ ## name(unsigned gpio) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800562{ \
563 unsigned long flags; \
564 unsigned short ret; \
565 local_irq_save(flags); \
566 ret = (gpio_bankb[gpio_bank(gpio)]->name); \
567 AWA_DUMMY_READ(name); \
568 local_irq_restore(flags); \
569 return ret; \
570} \
571EXPORT_SYMBOL(get_gpiop_ ## name);
572#else
Bryan Wu1394f032007-05-06 14:50:22 -0700573#define GET_GPIO_P(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800574unsigned short get_gpiop_ ## name(unsigned gpio) \
Bryan Wu1394f032007-05-06 14:50:22 -0700575{ \
576 return (gpio_bankb[gpio_bank(gpio)]->name);\
577} \
578EXPORT_SYMBOL(get_gpiop_ ## name);
Michael Hennerich2b393312007-10-10 16:58:49 +0800579#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700580
Michael Hennerich2b393312007-10-10 16:58:49 +0800581GET_GPIO_P(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700582GET_GPIO_P(dir)
583GET_GPIO_P(inen)
584GET_GPIO_P(polar)
585GET_GPIO_P(edge)
586GET_GPIO_P(both)
587GET_GPIO_P(maska)
588GET_GPIO_P(maskb)
589
Bryan Wu1394f032007-05-06 14:50:22 -0700590
591#ifdef CONFIG_PM
592/***********************************************************
593*
594* FUNCTIONS: Blackfin PM Setup API
595*
596* INPUTS/OUTPUTS:
597* gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
598* type -
599* PM_WAKE_RISING
600* PM_WAKE_FALLING
601* PM_WAKE_HIGH
602* PM_WAKE_LOW
603* PM_WAKE_BOTH_EDGES
604*
605* DESCRIPTION: Blackfin PM Driver API
606*
607* CAUTION:
608*************************************************************
609* MODIFICATION HISTORY :
610**************************************************************/
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800611int gpio_pm_wakeup_request(unsigned gpio, unsigned char type)
Bryan Wu1394f032007-05-06 14:50:22 -0700612{
613 unsigned long flags;
614
615 if ((check_gpio(gpio) < 0) || !type)
616 return -EINVAL;
617
618 local_irq_save(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700619 wakeup_map[gpio_bank(gpio)] |= gpio_bit(gpio);
620 wakeup_flags_map[gpio] = type;
621 local_irq_restore(flags);
622
623 return 0;
624}
625EXPORT_SYMBOL(gpio_pm_wakeup_request);
626
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800627void gpio_pm_wakeup_free(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -0700628{
629 unsigned long flags;
630
631 if (check_gpio(gpio) < 0)
632 return;
633
634 local_irq_save(flags);
635
636 wakeup_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
637
638 local_irq_restore(flags);
639}
640EXPORT_SYMBOL(gpio_pm_wakeup_free);
641
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800642static int bfin_gpio_wakeup_type(unsigned gpio, unsigned char type)
Bryan Wu1394f032007-05-06 14:50:22 -0700643{
644 port_setup(gpio, GPIO_USAGE);
645 set_gpio_dir(gpio, 0);
646 set_gpio_inen(gpio, 1);
647
648 if (type & (PM_WAKE_RISING | PM_WAKE_FALLING))
649 set_gpio_edge(gpio, 1);
650 else
651 set_gpio_edge(gpio, 0);
652
653 if ((type & (PM_WAKE_BOTH_EDGES)) == (PM_WAKE_BOTH_EDGES))
654 set_gpio_both(gpio, 1);
655 else
656 set_gpio_both(gpio, 0);
657
658 if ((type & (PM_WAKE_FALLING | PM_WAKE_LOW)))
659 set_gpio_polar(gpio, 1);
660 else
661 set_gpio_polar(gpio, 0);
662
663 SSYNC();
664
665 return 0;
666}
667
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800668u32 bfin_pm_standby_setup(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700669{
Bryan Wu1394f032007-05-06 14:50:22 -0700670 u16 bank, mask, i, gpio;
671
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800672 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Bryan Wu1394f032007-05-06 14:50:22 -0700673 mask = wakeup_map[gpio_bank(i)];
674 bank = gpio_bank(i);
675
676 gpio_bank_saved[bank].maskb = gpio_bankb[bank]->maskb;
677 gpio_bankb[bank]->maskb = 0;
678
679 if (mask) {
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800680#if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
Bryan Wu1394f032007-05-06 14:50:22 -0700681 gpio_bank_saved[bank].fer = *port_fer[bank];
682#endif
683 gpio_bank_saved[bank].inen = gpio_bankb[bank]->inen;
684 gpio_bank_saved[bank].polar = gpio_bankb[bank]->polar;
685 gpio_bank_saved[bank].dir = gpio_bankb[bank]->dir;
686 gpio_bank_saved[bank].edge = gpio_bankb[bank]->edge;
687 gpio_bank_saved[bank].both = gpio_bankb[bank]->both;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800688 gpio_bank_saved[bank].reserved =
689 reserved_gpio_map[bank];
Bryan Wu1394f032007-05-06 14:50:22 -0700690
691 gpio = i;
692
693 while (mask) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800694 if ((mask & 1) && (wakeup_flags_map[gpio] !=
695 PM_WAKE_IGNORE)) {
Michael Hennerichc58c2142007-10-04 00:35:05 +0800696 reserved_gpio_map[gpio_bank(gpio)] |=
Michael Hennerich581d62a2007-06-14 13:30:23 +0800697 gpio_bit(gpio);
698 bfin_gpio_wakeup_type(gpio,
699 wakeup_flags_map[gpio]);
Bryan Wu1394f032007-05-06 14:50:22 -0700700 set_gpio_data(gpio, 0); /*Clear*/
701 }
702 gpio++;
703 mask >>= 1;
704 }
705
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800706 bfin_internal_set_wake(sic_iwr_irqs[bank], 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700707 gpio_bankb[bank]->maskb_set = wakeup_map[gpio_bank(i)];
708 }
709 }
710
Michael Hennerich2b393312007-10-10 16:58:49 +0800711 AWA_DUMMY_READ(maskb_set);
712
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800713 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700714}
715
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800716void bfin_pm_standby_restore(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700717{
718 u16 bank, mask, i;
719
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800720 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Bryan Wu1394f032007-05-06 14:50:22 -0700721 mask = wakeup_map[gpio_bank(i)];
722 bank = gpio_bank(i);
723
724 if (mask) {
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800725#if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
Bryan Wu1394f032007-05-06 14:50:22 -0700726 *port_fer[bank] = gpio_bank_saved[bank].fer;
727#endif
728 gpio_bankb[bank]->inen = gpio_bank_saved[bank].inen;
729 gpio_bankb[bank]->dir = gpio_bank_saved[bank].dir;
730 gpio_bankb[bank]->polar = gpio_bank_saved[bank].polar;
731 gpio_bankb[bank]->edge = gpio_bank_saved[bank].edge;
732 gpio_bankb[bank]->both = gpio_bank_saved[bank].both;
Michael Hennerich581d62a2007-06-14 13:30:23 +0800733
Michael Hennerichc58c2142007-10-04 00:35:05 +0800734 reserved_gpio_map[bank] =
735 gpio_bank_saved[bank].reserved;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800736 bfin_internal_set_wake(sic_iwr_irqs[bank], 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700737 }
738
739 gpio_bankb[bank]->maskb = gpio_bank_saved[bank].maskb;
740 }
Michael Hennerich2b393312007-10-10 16:58:49 +0800741 AWA_DUMMY_READ(maskb);
Bryan Wu1394f032007-05-06 14:50:22 -0700742}
743
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800744void bfin_gpio_pm_hibernate_suspend(void)
745{
746 int i, bank;
747
748 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
749 bank = gpio_bank(i);
750
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800751#if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800752 gpio_bank_saved[bank].fer = *port_fer[bank];
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800753#if defined(BF527_FAMILY) || defined(BF518_FAMILY)
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800754 gpio_bank_saved[bank].mux = *port_mux[bank];
755#else
756 if (bank == 0)
757 gpio_bank_saved[bank].mux = bfin_read_PORT_MUX();
758#endif
759#endif
760 gpio_bank_saved[bank].data = gpio_bankb[bank]->data;
761 gpio_bank_saved[bank].inen = gpio_bankb[bank]->inen;
762 gpio_bank_saved[bank].polar = gpio_bankb[bank]->polar;
763 gpio_bank_saved[bank].dir = gpio_bankb[bank]->dir;
764 gpio_bank_saved[bank].edge = gpio_bankb[bank]->edge;
765 gpio_bank_saved[bank].both = gpio_bankb[bank]->both;
766 gpio_bank_saved[bank].maska = gpio_bankb[bank]->maska;
767 }
768
769 AWA_DUMMY_READ(maska);
770}
771
772void bfin_gpio_pm_hibernate_restore(void)
773{
774 int i, bank;
775
776 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
777 bank = gpio_bank(i);
778
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800779#if defined(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
780#if defined(BF527_FAMILY) || defined(BF518_FAMILY)
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800781 *port_mux[bank] = gpio_bank_saved[bank].mux;
782#else
783 if (bank == 0)
784 bfin_write_PORT_MUX(gpio_bank_saved[bank].mux);
785#endif
786 *port_fer[bank] = gpio_bank_saved[bank].fer;
787#endif
788 gpio_bankb[bank]->inen = gpio_bank_saved[bank].inen;
789 gpio_bankb[bank]->dir = gpio_bank_saved[bank].dir;
790 gpio_bankb[bank]->polar = gpio_bank_saved[bank].polar;
791 gpio_bankb[bank]->edge = gpio_bank_saved[bank].edge;
792 gpio_bankb[bank]->both = gpio_bank_saved[bank].both;
793
794 gpio_bankb[bank]->data_set = gpio_bank_saved[bank].data
795 | gpio_bank_saved[bank].dir;
796
797 gpio_bankb[bank]->maska = gpio_bank_saved[bank].maska;
798 }
799 AWA_DUMMY_READ(maska);
800}
801
802
Bryan Wu1394f032007-05-06 14:50:22 -0700803#endif
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800804#else /* BF548_FAMILY */
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800805#ifdef CONFIG_PM
806
807u32 bfin_pm_standby_setup(void)
808{
809 return 0;
810}
811
812void bfin_pm_standby_restore(void)
813{
814
815}
816
817void bfin_gpio_pm_hibernate_suspend(void)
818{
819 int i, bank;
820
821 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
822 bank = gpio_bank(i);
823
824 gpio_bank_saved[bank].fer = gpio_array[bank]->port_fer;
825 gpio_bank_saved[bank].mux = gpio_array[bank]->port_mux;
826 gpio_bank_saved[bank].data = gpio_array[bank]->port_data;
827 gpio_bank_saved[bank].data = gpio_array[bank]->port_data;
828 gpio_bank_saved[bank].inen = gpio_array[bank]->port_inen;
829 gpio_bank_saved[bank].dir = gpio_array[bank]->port_dir_set;
830 }
831}
832
833void bfin_gpio_pm_hibernate_restore(void)
834{
835 int i, bank;
836
837 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
838 bank = gpio_bank(i);
839
840 gpio_array[bank]->port_mux = gpio_bank_saved[bank].mux;
841 gpio_array[bank]->port_fer = gpio_bank_saved[bank].fer;
842 gpio_array[bank]->port_inen = gpio_bank_saved[bank].inen;
843 gpio_array[bank]->port_dir_set = gpio_bank_saved[bank].dir;
844 gpio_array[bank]->port_set = gpio_bank_saved[bank].data
845 | gpio_bank_saved[bank].dir;
846 }
847}
848#endif
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800849
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800850unsigned short get_gpio_dir(unsigned gpio)
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800851{
852 return (0x01 & (gpio_array[gpio_bank(gpio)]->port_dir_clear >> gpio_sub_n(gpio)));
853}
854EXPORT_SYMBOL(get_gpio_dir);
855
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800856#endif /* BF548_FAMILY */
Bryan Wu1394f032007-05-06 14:50:22 -0700857
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800858/***********************************************************
859*
860* FUNCTIONS: Blackfin Peripheral Resource Allocation
861* and PortMux Setup
862*
863* INPUTS/OUTPUTS:
864* per Peripheral Identifier
865* label String
866*
867* DESCRIPTION: Blackfin Peripheral Resource Allocation and Setup API
868*
869* CAUTION:
870*************************************************************
871* MODIFICATION HISTORY :
872**************************************************************/
Michael Hennerichc58c2142007-10-04 00:35:05 +0800873
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800874#ifdef BF548_FAMILY
875int peripheral_request(unsigned short per, const char *label)
876{
877 unsigned long flags;
878 unsigned short ident = P_IDENT(per);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800879
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800880 /*
881 * Don't cares are pins with only one dedicated function
882 */
883
884 if (per & P_DONTCARE)
885 return 0;
886
887 if (!(per & P_DEFINED))
888 return -ENODEV;
889
890 if (check_gpio(ident) < 0)
891 return -EINVAL;
892
893 local_irq_save(flags);
894
895 if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
Mike Frysingerf85c4ab2008-03-26 08:34:23 +0800896 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800897 printk(KERN_ERR
898 "%s: Peripheral %d is already reserved as GPIO by %s !\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800899 __func__, ident, get_label(ident));
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800900 local_irq_restore(flags);
901 return -EBUSY;
902 }
903
904 if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) {
905
906 u16 funct = get_portmux(ident);
907
Mike Frysingerd171c232008-03-26 08:35:46 +0800908 /*
909 * Pin functions like AMC address strobes my
910 * be requested and used by several drivers
911 */
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800912
913 if (!((per & P_MAYSHARE) && (funct == P_FUNCT2MUX(per)))) {
914
Mike Frysingerd171c232008-03-26 08:35:46 +0800915 /*
916 * Allow that the identical pin function can
917 * be requested from the same driver twice
918 */
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800919
Mike Frysingerd171c232008-03-26 08:35:46 +0800920 if (cmp_label(ident, label) == 0)
921 goto anyway;
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800922
Mike Frysingerf85c4ab2008-03-26 08:34:23 +0800923 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800924 printk(KERN_ERR
925 "%s: Peripheral %d function %d is already reserved by %s !\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800926 __func__, ident, P_FUNCT2MUX(per), get_label(ident));
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800927 local_irq_restore(flags);
928 return -EBUSY;
929 }
930 }
931
Mike Frysingerd171c232008-03-26 08:35:46 +0800932 anyway:
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800933 reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident);
934
935 portmux_setup(ident, P_FUNCT2MUX(per));
936 port_setup(ident, PERIPHERAL_USAGE);
937
938 local_irq_restore(flags);
939 set_label(ident, label);
940
941 return 0;
942}
943EXPORT_SYMBOL(peripheral_request);
944#else
Michael Hennerichc58c2142007-10-04 00:35:05 +0800945
946int peripheral_request(unsigned short per, const char *label)
947{
948 unsigned long flags;
949 unsigned short ident = P_IDENT(per);
950
951 /*
952 * Don't cares are pins with only one dedicated function
953 */
954
955 if (per & P_DONTCARE)
956 return 0;
957
958 if (!(per & P_DEFINED))
959 return -ENODEV;
960
Michael Hennerichc58c2142007-10-04 00:35:05 +0800961 local_irq_save(flags);
962
Michael Hennerichcda6a202007-10-04 00:36:18 +0800963 if (!check_gpio(ident)) {
964
Mike Frysingerd171c232008-03-26 08:35:46 +0800965 if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
966 dump_stack();
967 printk(KERN_ERR
968 "%s: Peripheral %d is already reserved as GPIO by %s !\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800969 __func__, ident, get_label(ident));
Mike Frysingerd171c232008-03-26 08:35:46 +0800970 local_irq_restore(flags);
971 return -EBUSY;
972 }
Michael Hennerichc58c2142007-10-04 00:35:05 +0800973
Michael Hennerichcda6a202007-10-04 00:36:18 +0800974 }
975
Michael Hennerichc58c2142007-10-04 00:35:05 +0800976 if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) {
977
Mike Frysingerd171c232008-03-26 08:35:46 +0800978 /*
979 * Pin functions like AMC address strobes my
980 * be requested and used by several drivers
981 */
Michael Hennerichc58c2142007-10-04 00:35:05 +0800982
Mike Frysingerd171c232008-03-26 08:35:46 +0800983 if (!(per & P_MAYSHARE)) {
Michael Hennerichc58c2142007-10-04 00:35:05 +0800984
Mike Frysingerd171c232008-03-26 08:35:46 +0800985 /*
986 * Allow that the identical pin function can
987 * be requested from the same driver twice
988 */
Michael Hennerichc58c2142007-10-04 00:35:05 +0800989
Mike Frysingerd171c232008-03-26 08:35:46 +0800990 if (cmp_label(ident, label) == 0)
991 goto anyway;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800992
Mike Frysingerf85c4ab2008-03-26 08:34:23 +0800993 dump_stack();
Michael Hennerichc58c2142007-10-04 00:35:05 +0800994 printk(KERN_ERR
995 "%s: Peripheral %d function %d is already"
Michael Hennerich8c613622007-08-03 17:48:09 +0800996 " reserved by %s !\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800997 __func__, ident, P_FUNCT2MUX(per),
Michael Hennerichc58c2142007-10-04 00:35:05 +0800998 get_label(ident));
Michael Hennerichc58c2142007-10-04 00:35:05 +0800999 local_irq_restore(flags);
1000 return -EBUSY;
1001 }
1002
1003 }
1004
Mike Frysingerd171c232008-03-26 08:35:46 +08001005 anyway:
Michael Hennerichc58c2142007-10-04 00:35:05 +08001006 portmux_setup(per, P_FUNCT2MUX(per));
1007
1008 port_setup(ident, PERIPHERAL_USAGE);
1009
1010 reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident);
1011 local_irq_restore(flags);
1012 set_label(ident, label);
1013
1014 return 0;
1015}
1016EXPORT_SYMBOL(peripheral_request);
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001017#endif
Michael Hennerichc58c2142007-10-04 00:35:05 +08001018
Mike Frysinger68179372008-04-24 05:04:24 +08001019int peripheral_request_list(const unsigned short per[], const char *label)
Michael Hennerichc58c2142007-10-04 00:35:05 +08001020{
1021 u16 cnt;
1022 int ret;
1023
1024 for (cnt = 0; per[cnt] != 0; cnt++) {
Michael Hennerich314c98d2007-07-24 18:03:45 +08001025
Michael Hennerichc58c2142007-10-04 00:35:05 +08001026 ret = peripheral_request(per[cnt], label);
Michael Hennerich314c98d2007-07-24 18:03:45 +08001027
1028 if (ret < 0) {
Mike Frysingerd171c232008-03-26 08:35:46 +08001029 for ( ; cnt > 0; cnt--)
Michael Hennerich314c98d2007-07-24 18:03:45 +08001030 peripheral_free(per[cnt - 1]);
Mike Frysingerd171c232008-03-26 08:35:46 +08001031
1032 return ret;
Michael Hennerich314c98d2007-07-24 18:03:45 +08001033 }
Michael Hennerichc58c2142007-10-04 00:35:05 +08001034 }
1035
1036 return 0;
1037}
1038EXPORT_SYMBOL(peripheral_request_list);
1039
1040void peripheral_free(unsigned short per)
1041{
1042 unsigned long flags;
1043 unsigned short ident = P_IDENT(per);
1044
1045 if (per & P_DONTCARE)
1046 return;
1047
1048 if (!(per & P_DEFINED))
1049 return;
1050
1051 if (check_gpio(ident) < 0)
1052 return;
1053
1054 local_irq_save(flags);
1055
Mike Frysingerd171c232008-03-26 08:35:46 +08001056 if (unlikely(!(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident)))) {
Michael Hennerichc58c2142007-10-04 00:35:05 +08001057 local_irq_restore(flags);
1058 return;
1059 }
1060
Mike Frysingerd171c232008-03-26 08:35:46 +08001061 if (!(per & P_MAYSHARE))
Michael Hennerichc58c2142007-10-04 00:35:05 +08001062 port_setup(ident, GPIO_USAGE);
Michael Hennerichc58c2142007-10-04 00:35:05 +08001063
1064 reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident);
1065
Michael Hennerich2acde902007-10-11 00:24:40 +08001066 set_label(ident, "free");
1067
Michael Hennerichc58c2142007-10-04 00:35:05 +08001068 local_irq_restore(flags);
1069}
1070EXPORT_SYMBOL(peripheral_free);
1071
Mike Frysinger68179372008-04-24 05:04:24 +08001072void peripheral_free_list(const unsigned short per[])
Michael Hennerichc58c2142007-10-04 00:35:05 +08001073{
1074 u16 cnt;
Mike Frysingerd171c232008-03-26 08:35:46 +08001075 for (cnt = 0; per[cnt] != 0; cnt++)
Michael Hennerichc58c2142007-10-04 00:35:05 +08001076 peripheral_free(per[cnt]);
Michael Hennerichc58c2142007-10-04 00:35:05 +08001077}
1078EXPORT_SYMBOL(peripheral_free_list);
1079
Bryan Wu1394f032007-05-06 14:50:22 -07001080/***********************************************************
1081*
1082* FUNCTIONS: Blackfin GPIO Driver
1083*
1084* INPUTS/OUTPUTS:
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001085* gpio PIO Number between 0 and MAX_BLACKFIN_GPIOS
1086* label String
Bryan Wu1394f032007-05-06 14:50:22 -07001087*
1088* DESCRIPTION: Blackfin GPIO Driver API
1089*
1090* CAUTION:
1091*************************************************************
1092* MODIFICATION HISTORY :
1093**************************************************************/
1094
Michael Hennerichacbcd262008-01-22 18:36:20 +08001095int gpio_request(unsigned gpio, const char *label)
Bryan Wu1394f032007-05-06 14:50:22 -07001096{
1097 unsigned long flags;
1098
1099 if (check_gpio(gpio) < 0)
1100 return -EINVAL;
1101
1102 local_irq_save(flags);
1103
Michael Hennerich2acde902007-10-11 00:24:40 +08001104 /*
1105 * Allow that the identical GPIO can
1106 * be requested from the same driver twice
1107 * Do nothing and return -
1108 */
1109
1110 if (cmp_label(gpio, label) == 0) {
1111 local_irq_restore(flags);
1112 return 0;
1113 }
1114
Michael Hennerichc58c2142007-10-04 00:35:05 +08001115 if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
Mike Frysingerf85c4ab2008-03-26 08:34:23 +08001116 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001117 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
1118 gpio, get_label(gpio));
Bryan Wu1394f032007-05-06 14:50:22 -07001119 local_irq_restore(flags);
1120 return -EBUSY;
1121 }
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001122 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
Mike Frysingerf85c4ab2008-03-26 08:34:23 +08001123 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001124 printk(KERN_ERR
1125 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
1126 gpio, get_label(gpio));
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001127 local_irq_restore(flags);
1128 return -EBUSY;
1129 }
1130
Michael Hennerichc58c2142007-10-04 00:35:05 +08001131 reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio);
Bryan Wu1394f032007-05-06 14:50:22 -07001132
1133 local_irq_restore(flags);
1134
1135 port_setup(gpio, GPIO_USAGE);
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001136 set_label(gpio, label);
Bryan Wu1394f032007-05-06 14:50:22 -07001137
1138 return 0;
1139}
1140EXPORT_SYMBOL(gpio_request);
1141
Michael Hennerichacbcd262008-01-22 18:36:20 +08001142void gpio_free(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -07001143{
1144 unsigned long flags;
1145
1146 if (check_gpio(gpio) < 0)
1147 return;
1148
1149 local_irq_save(flags);
1150
Michael Hennerichc58c2142007-10-04 00:35:05 +08001151 if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
Bryan Wu1394f032007-05-06 14:50:22 -07001152 dump_stack();
Mike Frysingerf85c4ab2008-03-26 08:34:23 +08001153 gpio_error(gpio);
Bryan Wu1394f032007-05-06 14:50:22 -07001154 local_irq_restore(flags);
1155 return;
1156 }
1157
Michael Hennerichc58c2142007-10-04 00:35:05 +08001158 reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
Bryan Wu1394f032007-05-06 14:50:22 -07001159
Michael Hennerich2acde902007-10-11 00:24:40 +08001160 set_label(gpio, "free");
1161
Bryan Wu1394f032007-05-06 14:50:22 -07001162 local_irq_restore(flags);
1163}
1164EXPORT_SYMBOL(gpio_free);
1165
Michael Hennerichacbcd262008-01-22 18:36:20 +08001166
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001167#ifdef BF548_FAMILY
Michael Hennerichacbcd262008-01-22 18:36:20 +08001168int gpio_direction_input(unsigned gpio)
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001169{
1170 unsigned long flags;
1171
Michael Hennerichacbcd262008-01-22 18:36:20 +08001172 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1173 gpio_error(gpio);
1174 return -EINVAL;
1175 }
1176
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001177 local_irq_save(flags);
1178 gpio_array[gpio_bank(gpio)]->port_dir_clear = gpio_bit(gpio);
1179 gpio_array[gpio_bank(gpio)]->port_inen |= gpio_bit(gpio);
1180 local_irq_restore(flags);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001181
1182 return 0;
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001183}
1184EXPORT_SYMBOL(gpio_direction_input);
1185
Michael Hennerichacbcd262008-01-22 18:36:20 +08001186int gpio_direction_output(unsigned gpio, int value)
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001187{
1188 unsigned long flags;
1189
Michael Hennerichacbcd262008-01-22 18:36:20 +08001190 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1191 gpio_error(gpio);
1192 return -EINVAL;
1193 }
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001194
1195 local_irq_save(flags);
1196 gpio_array[gpio_bank(gpio)]->port_inen &= ~gpio_bit(gpio);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001197 gpio_set_value(gpio, value);
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001198 gpio_array[gpio_bank(gpio)]->port_dir_set = gpio_bit(gpio);
1199 local_irq_restore(flags);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001200
1201 return 0;
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001202}
1203EXPORT_SYMBOL(gpio_direction_output);
1204
Michael Hennerichacbcd262008-01-22 18:36:20 +08001205void gpio_set_value(unsigned gpio, int arg)
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001206{
1207 if (arg)
1208 gpio_array[gpio_bank(gpio)]->port_set = gpio_bit(gpio);
1209 else
1210 gpio_array[gpio_bank(gpio)]->port_clear = gpio_bit(gpio);
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001211}
1212EXPORT_SYMBOL(gpio_set_value);
1213
Michael Hennerichacbcd262008-01-22 18:36:20 +08001214int gpio_get_value(unsigned gpio)
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001215{
1216 return (1 & (gpio_array[gpio_bank(gpio)]->port_data >> gpio_sub_n(gpio)));
1217}
1218EXPORT_SYMBOL(gpio_get_value);
1219
Michael Hennerichaffee2b2008-04-24 08:10:10 +08001220void bfin_gpio_irq_prepare(unsigned gpio)
1221{
1222 unsigned long flags;
1223
1224 port_setup(gpio, GPIO_USAGE);
1225
1226 local_irq_save(flags);
1227 gpio_array[gpio_bank(gpio)]->port_dir_clear = gpio_bit(gpio);
1228 gpio_array[gpio_bank(gpio)]->port_inen |= gpio_bit(gpio);
1229 local_irq_restore(flags);
1230}
1231
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001232#else
1233
Michael Hennerich803a8d22008-05-17 16:01:51 +08001234int gpio_get_value(unsigned gpio)
1235{
1236 unsigned long flags;
1237 int ret;
1238
1239 if (unlikely(get_gpio_edge(gpio))) {
1240 local_irq_save(flags);
1241 set_gpio_edge(gpio, 0);
1242 ret = get_gpio_data(gpio);
1243 set_gpio_edge(gpio, 1);
1244 local_irq_restore(flags);
1245
1246 return ret;
1247 } else
1248 return get_gpio_data(gpio);
1249}
1250EXPORT_SYMBOL(gpio_get_value);
1251
1252
Michael Hennerichacbcd262008-01-22 18:36:20 +08001253int gpio_direction_input(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -07001254{
1255 unsigned long flags;
1256
Michael Hennerichacbcd262008-01-22 18:36:20 +08001257 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1258 gpio_error(gpio);
1259 return -EINVAL;
1260 }
Bryan Wu1394f032007-05-06 14:50:22 -07001261
1262 local_irq_save(flags);
1263 gpio_bankb[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio);
1264 gpio_bankb[gpio_bank(gpio)]->inen |= gpio_bit(gpio);
Michael Hennerich2b393312007-10-10 16:58:49 +08001265 AWA_DUMMY_READ(inen);
Bryan Wu1394f032007-05-06 14:50:22 -07001266 local_irq_restore(flags);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001267
1268 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -07001269}
1270EXPORT_SYMBOL(gpio_direction_input);
1271
Michael Hennerichacbcd262008-01-22 18:36:20 +08001272int gpio_direction_output(unsigned gpio, int value)
Bryan Wu1394f032007-05-06 14:50:22 -07001273{
1274 unsigned long flags;
1275
Michael Hennerichacbcd262008-01-22 18:36:20 +08001276 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1277 gpio_error(gpio);
1278 return -EINVAL;
1279 }
Bryan Wu1394f032007-05-06 14:50:22 -07001280
1281 local_irq_save(flags);
1282 gpio_bankb[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio);
Michael Hennericha2c8cfe2008-01-22 17:20:10 +08001283
1284 if (value)
1285 gpio_bankb[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
1286 else
1287 gpio_bankb[gpio_bank(gpio)]->data_clear = gpio_bit(gpio);
1288
Bryan Wu1394f032007-05-06 14:50:22 -07001289 gpio_bankb[gpio_bank(gpio)]->dir |= gpio_bit(gpio);
Michael Hennerich2b393312007-10-10 16:58:49 +08001290 AWA_DUMMY_READ(dir);
Bryan Wu1394f032007-05-06 14:50:22 -07001291 local_irq_restore(flags);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001292
1293 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -07001294}
1295EXPORT_SYMBOL(gpio_direction_output);
Mike Frysinger168f1212007-10-11 00:22:35 +08001296
1297/* If we are booting from SPI and our board lacks a strong enough pull up,
1298 * the core can reset and execute the bootrom faster than the resistor can
1299 * pull the signal logically high. To work around this (common) error in
1300 * board design, we explicitly set the pin back to GPIO mode, force /CS
1301 * high, and wait for the electrons to do their thing.
1302 *
1303 * This function only makes sense to be called from reset code, but it
1304 * lives here as we need to force all the GPIO states w/out going through
1305 * BUG() checks and such.
1306 */
1307void bfin_gpio_reset_spi0_ssel1(void)
1308{
Michael Hennerich4d5f4ed2007-08-27 16:46:17 +08001309 u16 gpio = P_IDENT(P_SPI0_SSEL1);
1310
1311 port_setup(gpio, GPIO_USAGE);
1312 gpio_bankb[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
Michael Hennericha2c8cfe2008-01-22 17:20:10 +08001313 AWA_DUMMY_READ(data_set);
Mike Frysinger168f1212007-10-11 00:22:35 +08001314 udelay(1);
1315}
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001316
Michael Hennerichaffee2b2008-04-24 08:10:10 +08001317void bfin_gpio_irq_prepare(unsigned gpio)
1318{
1319 port_setup(gpio, GPIO_USAGE);
1320}
1321
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001322#endif /*BF548_FAMILY */
Mike Frysinger1545a112007-12-24 16:54:48 +08001323
1324#if defined(CONFIG_PROC_FS)
1325static int gpio_proc_read(char *buf, char **start, off_t offset,
1326 int len, int *unused_i, void *unused_v)
1327{
1328 int c, outlen = 0;
1329
1330 for (c = 0; c < MAX_RESOURCES; c++) {
1331 if (!check_gpio(c) && (reserved_gpio_map[gpio_bank(c)] & gpio_bit(c)))
Michael Hennerichfac3cf42007-12-24 20:07:03 +08001332 len = sprintf(buf, "GPIO_%d: %s \t\tGPIO %s\n", c,
Mike Frysinger1545a112007-12-24 16:54:48 +08001333 get_label(c), get_gpio_dir(c) ? "OUTPUT" : "INPUT");
1334 else if (reserved_peri_map[gpio_bank(c)] & gpio_bit(c))
Michael Hennerichfac3cf42007-12-24 20:07:03 +08001335 len = sprintf(buf, "GPIO_%d: %s \t\tPeripheral\n", c, get_label(c));
Mike Frysinger1545a112007-12-24 16:54:48 +08001336 else
1337 continue;
1338 buf += len;
1339 outlen += len;
1340 }
1341 return outlen;
1342}
1343
1344static __init int gpio_register_proc(void)
1345{
1346 struct proc_dir_entry *proc_gpio;
1347
1348 proc_gpio = create_proc_entry("gpio", S_IRUGO, NULL);
1349 if (proc_gpio)
1350 proc_gpio->read_proc = gpio_proc_read;
1351 return proc_gpio != NULL;
1352}
Mike Frysinger1545a112007-12-24 16:54:48 +08001353__initcall(gpio_register_proc);
1354#endif