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