2 * Etrax general port I/O device
4 * Copyright (c) 1999-2007 Axis Communications AB
6 * Authors: Bjorn Wesen (initial version)
7 * Ola Knutsson (LED handling)
8 * Johan Adolfsson (read/set directions, write, port G)
12 #include <linux/module.h>
13 #include <linux/sched.h>
14 #include <linux/slab.h>
15 #include <linux/ioport.h>
16 #include <linux/errno.h>
17 #include <linux/kernel.h>
19 #include <linux/string.h>
20 #include <linux/poll.h>
21 #include <linux/init.h>
22 #include <linux/interrupt.h>
24 #include <asm/etraxgpio.h>
25 #include <arch/svinto.h>
27 #include <asm/system.h>
29 #include <arch/io_interface_mux.h>
31 #define GPIO_MAJOR 120 /* experimental MAJOR number */
37 #define DP(x) do { dp_cnt++; if (dp_cnt % 1000 == 0) x; }while(0)
42 static char gpio_name
[] = "etrax gpio";
45 static wait_queue_head_t
*gpio_wq
;
48 static long gpio_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
);
49 static ssize_t
gpio_write(struct file
*file
, const char __user
*buf
,
50 size_t count
, loff_t
*off
);
51 static int gpio_open(struct inode
*inode
, struct file
*filp
);
52 static int gpio_release(struct inode
*inode
, struct file
*filp
);
53 static unsigned int gpio_poll(struct file
*filp
, struct poll_table_struct
*wait
);
55 /* private data per open() of this driver */
58 struct gpio_private
*next
;
59 /* These fields are for PA and PB only */
60 volatile unsigned char *port
, *shadow
;
61 volatile unsigned char *dir
, *dir_shadow
;
62 unsigned char changeable_dir
;
63 unsigned char changeable_bits
;
64 unsigned char clk_mask
;
65 unsigned char data_mask
;
66 unsigned char write_msb
;
67 unsigned char pad1
, pad2
, pad3
;
68 /* These fields are generic */
69 unsigned long highalarm
, lowalarm
;
70 wait_queue_head_t alarm_wq
;
74 /* linked list of alarms to check for */
76 static struct gpio_private
*alarmlist
;
78 static int gpio_some_alarms
; /* Set if someone uses alarm */
79 static unsigned long gpio_pa_irq_enabled_mask
;
81 static DEFINE_SPINLOCK(gpio_lock
); /* Protect directions etc */
83 /* Port A and B use 8 bit access, but Port G is 32 bit */
84 #define NUM_PORTS (GPIO_MINOR_B+1)
86 static volatile unsigned char *ports
[NUM_PORTS
] = {
90 static volatile unsigned char *shads
[NUM_PORTS
] = {
95 /* What direction bits that are user changeable 1=changeable*/
96 #ifndef CONFIG_ETRAX_PA_CHANGEABLE_DIR
97 #define CONFIG_ETRAX_PA_CHANGEABLE_DIR 0x00
99 #ifndef CONFIG_ETRAX_PB_CHANGEABLE_DIR
100 #define CONFIG_ETRAX_PB_CHANGEABLE_DIR 0x00
103 #ifndef CONFIG_ETRAX_PA_CHANGEABLE_BITS
104 #define CONFIG_ETRAX_PA_CHANGEABLE_BITS 0xFF
106 #ifndef CONFIG_ETRAX_PB_CHANGEABLE_BITS
107 #define CONFIG_ETRAX_PB_CHANGEABLE_BITS 0xFF
111 static unsigned char changeable_dir
[NUM_PORTS
] = {
112 CONFIG_ETRAX_PA_CHANGEABLE_DIR
,
113 CONFIG_ETRAX_PB_CHANGEABLE_DIR
115 static unsigned char changeable_bits
[NUM_PORTS
] = {
116 CONFIG_ETRAX_PA_CHANGEABLE_BITS
,
117 CONFIG_ETRAX_PB_CHANGEABLE_BITS
120 static volatile unsigned char *dir
[NUM_PORTS
] = {
125 static volatile unsigned char *dir_shadow
[NUM_PORTS
] = {
130 /* All bits in port g that can change dir. */
131 static const unsigned long int changeable_dir_g_mask
= 0x01FFFF01;
133 /* Port G is 32 bit, handle it special, some bits are both inputs
134 and outputs at the same time, only some of the bits can change direction
135 and some of them in groups of 8 bit. */
136 static unsigned long changeable_dir_g
;
137 static unsigned long dir_g_in_bits
;
138 static unsigned long dir_g_out_bits
;
139 static unsigned long dir_g_shadow
; /* 1=output */
141 #define USE_PORTS(priv) ((priv)->minor <= GPIO_MINOR_B)
144 static unsigned int gpio_poll(struct file
*file
, poll_table
*wait
)
146 unsigned int mask
= 0;
147 struct gpio_private
*priv
= file
->private_data
;
151 spin_lock_irqsave(&gpio_lock
, flags
);
153 poll_wait(file
, &priv
->alarm_wq
, wait
);
154 if (priv
->minor
== GPIO_MINOR_A
) {
156 data
= *R_PORT_PA_DATA
;
157 /* PA has support for high level interrupt -
158 * lets activate for those low and with highalarm set
160 tmp
= ~data
& priv
->highalarm
& 0xFF;
161 tmp
= (tmp
<< R_IRQ_MASK1_SET__pa0__BITNR
);
163 gpio_pa_irq_enabled_mask
|= tmp
;
164 *R_IRQ_MASK1_SET
= tmp
;
165 } else if (priv
->minor
== GPIO_MINOR_B
)
166 data
= *R_PORT_PB_DATA
;
167 else if (priv
->minor
== GPIO_MINOR_G
)
168 data
= *R_PORT_G_DATA
;
174 if ((data
& priv
->highalarm
) ||
175 (~data
& priv
->lowalarm
)) {
176 mask
= POLLIN
|POLLRDNORM
;
180 spin_unlock_irqrestore(&gpio_lock
, flags
);
181 DP(printk("gpio_poll ready: mask 0x%08X\n", mask
));
186 int etrax_gpio_wake_up_check(void)
188 struct gpio_private
*priv
;
189 unsigned long data
= 0;
193 spin_lock_irqsave(&gpio_lock
, flags
);
198 else if (priv
->minor
== GPIO_MINOR_G
)
199 data
= *R_PORT_G_DATA
;
201 if ((data
& priv
->highalarm
) ||
202 (~data
& priv
->lowalarm
)) {
203 DP(printk("etrax_gpio_wake_up_check %i\n",priv
->minor
));
204 wake_up_interruptible(&priv
->alarm_wq
);
209 spin_unlock_irqrestore(&gpio_lock
, flags
);
214 gpio_poll_timer_interrupt(int irq
, void *dev_id
)
216 if (gpio_some_alarms
) {
217 etrax_gpio_wake_up_check();
224 gpio_interrupt(int irq
, void *dev_id
)
229 spin_lock_irqsave(&gpio_lock
, flags
);
231 /* Find what PA interrupts are active */
232 tmp
= (*R_IRQ_READ1
);
234 /* Find those that we have enabled */
235 tmp
&= gpio_pa_irq_enabled_mask
;
238 *R_IRQ_MASK1_CLR
= tmp
;
239 gpio_pa_irq_enabled_mask
&= ~tmp
;
241 spin_unlock_irqrestore(&gpio_lock
, flags
);
243 if (gpio_some_alarms
)
244 return IRQ_RETVAL(etrax_gpio_wake_up_check());
249 static void gpio_write_bit(struct gpio_private
*priv
,
250 unsigned char data
, int bit
)
252 *priv
->port
= *priv
->shadow
&= ~(priv
->clk_mask
);
254 *priv
->port
= *priv
->shadow
|= priv
->data_mask
;
256 *priv
->port
= *priv
->shadow
&= ~(priv
->data_mask
);
258 /* For FPGA: min 5.0ns (DCC) before CCLK high */
259 *priv
->port
= *priv
->shadow
|= priv
->clk_mask
;
262 static void gpio_write_byte(struct gpio_private
*priv
, unsigned char data
)
267 for (i
= 7; i
>= 0; i
--)
268 gpio_write_bit(priv
, data
, i
);
270 for (i
= 0; i
<= 7; i
++)
271 gpio_write_bit(priv
, data
, i
);
274 static ssize_t
gpio_write(struct file
*file
, const char __user
*buf
,
275 size_t count
, loff_t
*off
)
277 struct gpio_private
*priv
= file
->private_data
;
279 ssize_t retval
= count
;
281 if (priv
->minor
!= GPIO_MINOR_A
&& priv
->minor
!= GPIO_MINOR_B
)
284 if (!access_ok(VERIFY_READ
, buf
, count
))
287 spin_lock_irqsave(&gpio_lock
, flags
);
289 /* It must have been configured using the IO_CFG_WRITE_MODE */
290 /* Perhaps a better error code? */
291 if (priv
->clk_mask
== 0 || priv
->data_mask
== 0) {
296 D(printk(KERN_DEBUG
"gpio_write: %02X to data 0x%02X "
297 "clk 0x%02X msb: %i\n",
298 count
, priv
->data_mask
, priv
->clk_mask
, priv
->write_msb
));
301 gpio_write_byte(priv
, *buf
++);
304 spin_unlock_irqrestore(&gpio_lock
, flags
);
311 gpio_open(struct inode
*inode
, struct file
*filp
)
313 struct gpio_private
*priv
;
314 int p
= iminor(inode
);
317 if (p
> GPIO_MINOR_LAST
)
320 priv
= kzalloc(sizeof(struct gpio_private
), GFP_KERNEL
);
327 /* initialize the io/alarm struct */
329 if (USE_PORTS(priv
)) { /* A and B */
330 priv
->port
= ports
[p
];
331 priv
->shadow
= shads
[p
];
333 priv
->dir_shadow
= dir_shadow
[p
];
334 priv
->changeable_dir
= changeable_dir
[p
];
335 priv
->changeable_bits
= changeable_bits
[p
];
340 priv
->dir_shadow
= NULL
;
341 priv
->changeable_dir
= 0;
342 priv
->changeable_bits
= 0;
349 init_waitqueue_head(&priv
->alarm_wq
);
351 filp
->private_data
= priv
;
353 /* link it into our alarmlist */
354 spin_lock_irqsave(&gpio_lock
, flags
);
355 priv
->next
= alarmlist
;
357 spin_unlock_irqrestore(&gpio_lock
, flags
);
363 gpio_release(struct inode
*inode
, struct file
*filp
)
365 struct gpio_private
*p
;
366 struct gpio_private
*todel
;
369 spin_lock_irqsave(&gpio_lock
, flags
);
372 todel
= filp
->private_data
;
374 /* unlink from alarmlist and free the private structure */
377 alarmlist
= todel
->next
;
379 while (p
->next
!= todel
)
381 p
->next
= todel
->next
;
385 /* Check if there are still any alarms set */
388 if (p
->highalarm
| p
->lowalarm
) {
389 gpio_some_alarms
= 1;
394 gpio_some_alarms
= 0;
396 spin_unlock_irqrestore(&gpio_lock
, flags
);
400 /* Main device API. ioctl's to read/set/clear bits, as well as to
401 * set alarms to wait for using a subsequent select().
403 unsigned long inline setget_input(struct gpio_private
*priv
, unsigned long arg
)
405 /* Set direction 0=unchanged 1=input,
406 * return mask with 1=input */
407 if (USE_PORTS(priv
)) {
408 *priv
->dir
= *priv
->dir_shadow
&=
409 ~((unsigned char)arg
& priv
->changeable_dir
);
410 return ~(*priv
->dir_shadow
) & 0xFF; /* Only 8 bits */
413 if (priv
->minor
!= GPIO_MINOR_G
)
416 /* We must fiddle with R_GEN_CONFIG to change dir */
417 if (((arg
& dir_g_in_bits
) != arg
) &&
418 (arg
& changeable_dir_g
)) {
419 arg
&= changeable_dir_g
;
420 /* Clear bits in genconfig to set to input */
422 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, g0dir
);
423 dir_g_in_bits
|= (1<<0);
424 dir_g_out_bits
&= ~(1<<0);
426 if ((arg
& 0x0000FF00) == 0x0000FF00) {
427 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, g8_15dir
);
428 dir_g_in_bits
|= 0x0000FF00;
429 dir_g_out_bits
&= ~0x0000FF00;
431 if ((arg
& 0x00FF0000) == 0x00FF0000) {
432 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, g16_23dir
);
433 dir_g_in_bits
|= 0x00FF0000;
434 dir_g_out_bits
&= ~0x00FF0000;
437 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, g24dir
);
438 dir_g_in_bits
|= (1<<24);
439 dir_g_out_bits
&= ~(1<<24);
441 D(printk(KERN_DEBUG
"gpio: SETINPUT on port G set "
442 "genconfig to 0x%08lX "
444 "out_bits: 0x%08lX\n",
445 (unsigned long)genconfig_shadow
,
446 dir_g_in_bits
, dir_g_out_bits
));
447 *R_GEN_CONFIG
= genconfig_shadow
;
448 /* Must be a >120 ns delay before writing this again */
451 return dir_g_in_bits
;
454 unsigned long inline setget_output(struct gpio_private
*priv
, unsigned long arg
)
456 if (USE_PORTS(priv
)) {
457 *priv
->dir
= *priv
->dir_shadow
|=
458 ((unsigned char)arg
& priv
->changeable_dir
);
459 return *priv
->dir_shadow
;
461 if (priv
->minor
!= GPIO_MINOR_G
)
464 /* We must fiddle with R_GEN_CONFIG to change dir */
465 if (((arg
& dir_g_out_bits
) != arg
) &&
466 (arg
& changeable_dir_g
)) {
467 /* Set bits in genconfig to set to output */
469 genconfig_shadow
|= IO_MASK(R_GEN_CONFIG
, g0dir
);
470 dir_g_out_bits
|= (1<<0);
471 dir_g_in_bits
&= ~(1<<0);
473 if ((arg
& 0x0000FF00) == 0x0000FF00) {
474 genconfig_shadow
|= IO_MASK(R_GEN_CONFIG
, g8_15dir
);
475 dir_g_out_bits
|= 0x0000FF00;
476 dir_g_in_bits
&= ~0x0000FF00;
478 if ((arg
& 0x00FF0000) == 0x00FF0000) {
479 genconfig_shadow
|= IO_MASK(R_GEN_CONFIG
, g16_23dir
);
480 dir_g_out_bits
|= 0x00FF0000;
481 dir_g_in_bits
&= ~0x00FF0000;
484 genconfig_shadow
|= IO_MASK(R_GEN_CONFIG
, g24dir
);
485 dir_g_out_bits
|= (1<<24);
486 dir_g_in_bits
&= ~(1<<24);
488 D(printk(KERN_INFO
"gpio: SETOUTPUT on port G set "
489 "genconfig to 0x%08lX "
491 "out_bits: 0x%08lX\n",
492 (unsigned long)genconfig_shadow
,
493 dir_g_in_bits
, dir_g_out_bits
));
494 *R_GEN_CONFIG
= genconfig_shadow
;
495 /* Must be a >120 ns delay before writing this again */
497 return dir_g_out_bits
& 0x7FFFFFFF;
498 } /* setget_output */
501 gpio_leds_ioctl(unsigned int cmd
, unsigned long arg
);
503 static long gpio_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
509 struct gpio_private
*priv
= file
->private_data
;
510 if (_IOC_TYPE(cmd
) != ETRAXGPIO_IOCTYPE
)
513 switch (_IOC_NR(cmd
)) {
514 case IO_READBITS
: /* Use IO_READ_INBITS and IO_READ_OUTBITS instead */
516 spin_lock_irqsave(&gpio_lock
, flags
);
517 if (USE_PORTS(priv
)) {
519 } else if (priv
->minor
== GPIO_MINOR_G
) {
520 ret
= (*R_PORT_G_DATA
) & 0x7FFFFFFF;
522 spin_unlock_irqrestore(&gpio_lock
, flags
);
526 // set changeable bits with a 1 in arg
527 spin_lock_irqsave(&gpio_lock
, flags
);
529 if (USE_PORTS(priv
)) {
530 *priv
->port
= *priv
->shadow
|=
531 ((unsigned char)arg
& priv
->changeable_bits
);
532 } else if (priv
->minor
== GPIO_MINOR_G
) {
533 *R_PORT_G_DATA
= port_g_data_shadow
|= (arg
& dir_g_out_bits
);
535 spin_unlock_irqrestore(&gpio_lock
, flags
);
539 // clear changeable bits with a 1 in arg
540 spin_lock_irqsave(&gpio_lock
, flags
);
541 if (USE_PORTS(priv
)) {
542 *priv
->port
= *priv
->shadow
&=
543 ~((unsigned char)arg
& priv
->changeable_bits
);
544 } else if (priv
->minor
== GPIO_MINOR_G
) {
545 *R_PORT_G_DATA
= port_g_data_shadow
&= ~((unsigned long)arg
& dir_g_out_bits
);
547 spin_unlock_irqrestore(&gpio_lock
, flags
);
550 // set alarm when bits with 1 in arg go high
551 spin_lock_irqsave(&gpio_lock
, flags
);
552 priv
->highalarm
|= arg
;
553 gpio_some_alarms
= 1;
554 spin_unlock_irqrestore(&gpio_lock
, flags
);
557 // set alarm when bits with 1 in arg go low
558 spin_lock_irqsave(&gpio_lock
, flags
);
559 priv
->lowalarm
|= arg
;
560 gpio_some_alarms
= 1;
561 spin_unlock_irqrestore(&gpio_lock
, flags
);
564 /* clear alarm for bits with 1 in arg */
565 spin_lock_irqsave(&gpio_lock
, flags
);
566 priv
->highalarm
&= ~arg
;
567 priv
->lowalarm
&= ~arg
;
569 /* Must update gpio_some_alarms */
570 struct gpio_private
*p
= alarmlist
;
575 if (p
->highalarm
| p
->lowalarm
) {
581 gpio_some_alarms
= some_alarms
;
583 spin_unlock_irqrestore(&gpio_lock
, flags
);
585 case IO_READDIR
: /* Use IO_SETGET_INPUT/OUTPUT instead! */
586 /* Read direction 0=input 1=output */
587 spin_lock_irqsave(&gpio_lock
, flags
);
588 if (USE_PORTS(priv
)) {
589 ret
= *priv
->dir_shadow
;
590 } else if (priv
->minor
== GPIO_MINOR_G
) {
591 /* Note: Some bits are both in and out,
592 * Those that are dual is set here as well.
594 ret
= (dir_g_shadow
| dir_g_out_bits
) & 0x7FFFFFFF;
596 spin_unlock_irqrestore(&gpio_lock
, flags
);
598 case IO_SETINPUT
: /* Use IO_SETGET_INPUT instead! */
599 /* Set direction 0=unchanged 1=input,
600 * return mask with 1=input
602 spin_lock_irqsave(&gpio_lock
, flags
);
603 ret
= setget_input(priv
, arg
) & 0x7FFFFFFF;
604 spin_unlock_irqrestore(&gpio_lock
, flags
);
606 case IO_SETOUTPUT
: /* Use IO_SETGET_OUTPUT instead! */
607 /* Set direction 0=unchanged 1=output,
608 * return mask with 1=output
610 spin_lock_irqsave(&gpio_lock
, flags
);
611 ret
= setget_output(priv
, arg
) & 0x7FFFFFFF;
612 spin_unlock_irqrestore(&gpio_lock
, flags
);
615 spin_lock_irqsave(&gpio_lock
, flags
);
617 spin_unlock_irqrestore(&gpio_lock
, flags
);
620 spin_lock_irqsave(&gpio_lock
, flags
);
621 #if defined (CONFIG_ETRAX_SOFT_SHUTDOWN)
622 ret
= (*R_PORT_G_DATA
& ( 1 << CONFIG_ETRAX_POWERBUTTON_BIT
));
626 spin_unlock_irqrestore(&gpio_lock
, flags
);
628 case IO_CFG_WRITE_MODE
:
629 spin_lock_irqsave(&gpio_lock
, flags
);
630 priv
->clk_mask
= arg
& 0xFF;
631 priv
->data_mask
= (arg
>> 8) & 0xFF;
632 priv
->write_msb
= (arg
>> 16) & 0x01;
633 /* Check if we're allowed to change the bits and
634 * the direction is correct
636 if (!((priv
->clk_mask
& priv
->changeable_bits
) &&
637 (priv
->data_mask
& priv
->changeable_bits
) &&
638 (priv
->clk_mask
& *priv
->dir_shadow
) &&
639 (priv
->data_mask
& *priv
->dir_shadow
)))
645 spin_unlock_irqrestore(&gpio_lock
, flags
);
648 /* *arg is result of reading the input pins */
649 spin_lock_irqsave(&gpio_lock
, flags
);
650 if (USE_PORTS(priv
)) {
652 } else if (priv
->minor
== GPIO_MINOR_G
) {
653 val
= *R_PORT_G_DATA
;
655 spin_unlock_irqrestore(&gpio_lock
, flags
);
656 if (copy_to_user((void __user
*)arg
, &val
, sizeof(val
)))
659 case IO_READ_OUTBITS
:
660 /* *arg is result of reading the output shadow */
661 spin_lock_irqsave(&gpio_lock
, flags
);
662 if (USE_PORTS(priv
)) {
664 } else if (priv
->minor
== GPIO_MINOR_G
) {
665 val
= port_g_data_shadow
;
667 spin_unlock_irqrestore(&gpio_lock
, flags
);
668 if (copy_to_user((void __user
*)arg
, &val
, sizeof(val
)))
671 case IO_SETGET_INPUT
:
672 /* bits set in *arg is set to input,
673 * *arg updated with current input pins.
675 if (copy_from_user(&val
, (void __user
*)arg
, sizeof(val
)))
680 spin_lock_irqsave(&gpio_lock
, flags
);
681 val
= setget_input(priv
, val
);
682 spin_unlock_irqrestore(&gpio_lock
, flags
);
683 if (copy_to_user((void __user
*)arg
, &val
, sizeof(val
)))
686 case IO_SETGET_OUTPUT
:
687 /* bits set in *arg is set to output,
688 * *arg updated with current output pins.
690 if (copy_from_user(&val
, (void __user
*)arg
, sizeof(val
))) {
694 spin_lock_irqsave(&gpio_lock
, flags
);
695 val
= setget_output(priv
, val
);
696 spin_unlock_irqrestore(&gpio_lock
, flags
);
697 if (copy_to_user((void __user
*)arg
, &val
, sizeof(val
)))
701 spin_lock_irqsave(&gpio_lock
, flags
);
702 if (priv
->minor
== GPIO_MINOR_LEDS
)
703 ret
= gpio_leds_ioctl(cmd
, arg
);
706 spin_unlock_irqrestore(&gpio_lock
, flags
);
713 gpio_leds_ioctl(unsigned int cmd
, unsigned long arg
)
718 switch (_IOC_NR(cmd
)) {
719 case IO_LEDACTIVE_SET
:
720 green
= ((unsigned char)arg
) & 1;
721 red
= (((unsigned char)arg
) >> 1) & 1;
722 CRIS_LED_ACTIVE_SET_G(green
);
723 CRIS_LED_ACTIVE_SET_R(red
);
727 CRIS_LED_BIT_SET(arg
);
731 CRIS_LED_BIT_CLR(arg
);
741 static const struct file_operations gpio_fops
= {
742 .owner
= THIS_MODULE
,
744 .unlocked_ioctl
= gpio_ioctl
,
747 .release
= gpio_release
,
748 .llseek
= noop_llseek
,
751 static void ioif_watcher(const unsigned int gpio_in_available
,
752 const unsigned int gpio_out_available
,
753 const unsigned char pa_available
,
754 const unsigned char pb_available
)
756 unsigned long int flags
;
758 D(printk(KERN_DEBUG
"gpio.c: ioif_watcher called\n"));
759 D(printk(KERN_DEBUG
"gpio.c: G in: 0x%08x G out: 0x%08x "
760 "PA: 0x%02x PB: 0x%02x\n",
761 gpio_in_available
, gpio_out_available
,
762 pa_available
, pb_available
));
764 spin_lock_irqsave(&gpio_lock
, flags
);
766 dir_g_in_bits
= gpio_in_available
;
767 dir_g_out_bits
= gpio_out_available
;
769 /* Initialise the dir_g_shadow etc. depending on genconfig */
770 /* 0=input 1=output */
771 if (genconfig_shadow
& IO_STATE(R_GEN_CONFIG
, g0dir
, out
))
772 dir_g_shadow
|= (1 << 0);
773 if (genconfig_shadow
& IO_STATE(R_GEN_CONFIG
, g8_15dir
, out
))
774 dir_g_shadow
|= 0x0000FF00;
775 if (genconfig_shadow
& IO_STATE(R_GEN_CONFIG
, g16_23dir
, out
))
776 dir_g_shadow
|= 0x00FF0000;
777 if (genconfig_shadow
& IO_STATE(R_GEN_CONFIG
, g24dir
, out
))
778 dir_g_shadow
|= (1 << 24);
780 changeable_dir_g
= changeable_dir_g_mask
;
781 changeable_dir_g
&= dir_g_out_bits
;
782 changeable_dir_g
&= dir_g_in_bits
;
784 /* Correct the bits that can change direction */
785 dir_g_out_bits
&= ~changeable_dir_g
;
786 dir_g_out_bits
|= dir_g_shadow
;
787 dir_g_in_bits
&= ~changeable_dir_g
;
788 dir_g_in_bits
|= (~dir_g_shadow
& changeable_dir_g
);
790 spin_unlock_irqrestore(&gpio_lock
, flags
);
792 printk(KERN_INFO
"GPIO port G: in_bits: 0x%08lX out_bits: 0x%08lX "
794 dir_g_in_bits
, dir_g_out_bits
, (unsigned long)*R_PORT_G_DATA
);
795 printk(KERN_INFO
"GPIO port G: dir: %08lX changeable: %08lX\n",
796 dir_g_shadow
, changeable_dir_g
);
799 /* main driver initialization routine, called from mem.c */
801 static int __init
gpio_init(void)
804 #if defined (CONFIG_ETRAX_CSP0_LEDS)
808 res
= register_chrdev(GPIO_MAJOR
, gpio_name
, &gpio_fops
);
810 printk(KERN_ERR
"gpio: couldn't get a major number.\n");
815 #if defined (CONFIG_ETRAX_CSP0_LEDS) || defined (CONFIG_ETRAX_PA_LEDS) || defined (CONFIG_ETRAX_PB_LEDS)
816 CRIS_LED_NETWORK_SET(0);
817 CRIS_LED_ACTIVE_SET(0);
818 CRIS_LED_DISK_READ(0);
819 CRIS_LED_DISK_WRITE(0);
821 #if defined (CONFIG_ETRAX_CSP0_LEDS)
822 for (i
= 0; i
< 32; i
++)
827 /* The I/O interface allocation watcher will be called when
829 if (cris_io_interface_register_watcher(ioif_watcher
)){
830 printk(KERN_WARNING
"gpio_init: Failed to install IO "
831 "if allocator watcher\n");
834 printk(KERN_INFO
"ETRAX 100LX GPIO driver v2.5, (c) 2001-2008 "
835 "Axis Communications AB\n");
836 /* We call etrax_gpio_wake_up_check() from timer interrupt and
837 * from cpu_idle() in kernel/process.c
838 * The check in cpu_idle() reduces latency from ~15 ms to ~6 ms
841 res
= request_irq(TIMER0_IRQ_NBR
, gpio_poll_timer_interrupt
,
842 IRQF_SHARED
| IRQF_DISABLED
, "gpio poll", gpio_name
);
844 printk(KERN_CRIT
"err: timer0 irq for gpio\n");
847 res
= request_irq(PA_IRQ_NBR
, gpio_interrupt
,
848 IRQF_SHARED
| IRQF_DISABLED
, "gpio PA", gpio_name
);
850 printk(KERN_CRIT
"err: PA irq for gpio\n");
855 /* this makes sure that gpio_init is called during kernel boot */
856 module_init(gpio_init
);