MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / drivers / char / resetswitch.c
blobde1f7fbb23d87b52a2c582ac2a95f89b04acd04c
1 /***************************************************************************/
3 /*
4 * linux/drivers/char/resetswitch.c
6 * Basic driver to support the Moxart software reset button.
8 * Jimmy_chen@moxa.com.tw
9 */
11 /***************************************************************************/
13 #if 1 // add by Victor Yu. 02-09-2007
14 #include <linux/version.h>
15 #endif
16 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) // add by Victor Yu. 02-09-2007
17 #include <linux/config.h>
18 #endif
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/param.h>
23 #include <linux/init.h>
24 #include <asm/irq.h>
25 #include <asm/traps.h>
26 #include <linux/delay.h>
27 #include <linux/sched.h>
28 #include <linux/interrupt.h>
29 #include <linux/timer.h>
30 #include <linux/syscalls.h>
31 #include <linux/reboot.h>
32 #include <asm/uaccess.h>
33 #include <asm/io.h>
34 #include <asm/arch/moxa.h>
35 #include <asm/arch/gpio.h>
37 #define RESET_POLL_TIME (HZ/5)
38 #define RESET_TIMEOUT (HZ * 5)
40 #define PIO(x) 1<<x
42 #if defined(CONFIG_ARCH_W311_TEST) // add by VIctor Yu. 07-05-2008
43 #define RESET_IO PIO(23)
44 #define LED_READY PIO(4)
45 #else
46 #define RESET_IO PIO(25)
47 #define LED_READY PIO(27)
48 #endif
50 struct work_struct resetqueue;
51 static struct timer_list resettimer;
52 static spinlock_t resetlock=SPIN_LOCK_UNLOCKED;
53 static unsigned long endresettime, intervaltime;
54 static int ledonoffflag;
56 static void reset_to_default(void)
58 char *argv[3] , *envp[4] ;
60 envp[0] = "HOME=/" ;
61 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin" ;
62 envp[2] = "TERM=console" ;
63 envp[3] = NULL ;
65 argv[0] = "ldfactory" ;
66 argv[1] = NULL ;
68 printk("reset to default\n") ;
69 if(call_usermodehelper("/bin/ldfactory",argv,envp,0)==-1)
70 printk("set to default failure\n") ;
73 static void reset_poll(unsigned long ingore)
75 spin_lock(&resetlock);
76 del_timer(&resettimer);
77 if ( !mcpu_gpio_get(RESET_IO) ) {
78 if ( endresettime == 0 ) {
79 endresettime = jiffies + RESET_TIMEOUT;
80 intervaltime = jiffies + HZ;
81 } else if ( time_after(jiffies, endresettime) ){
82 mcpu_gpio_set(LED_READY, MCPU_GPIO_HIGH);
83 schedule_work(&resetqueue);
84 goto poll_exit;
85 } else if ( time_after(jiffies, intervaltime) ) {
86 if ( ledonoffflag ) {
87 ledonoffflag = 0;
88 mcpu_gpio_set(LED_READY, MCPU_GPIO_HIGH);
89 } else {
90 ledonoffflag = 1;
91 mcpu_gpio_set(LED_READY, MCPU_GPIO_LOW);
93 intervaltime = jiffies + HZ;
95 } else if ( endresettime ) {
96 endresettime = 0;
97 ledonoffflag = 1;
98 mcpu_gpio_set(LED_READY, MCPU_GPIO_LOW);
100 resettimer.function = reset_poll;
101 resettimer.expires = jiffies + RESET_POLL_TIME;
102 add_timer(&resettimer);
103 poll_exit:
104 spin_unlock(&resetlock);
107 /***************************************************************************/
108 static void __exit resetswitch_exit(void)
110 spin_lock(&resetlock);
111 del_timer(&resettimer);
112 spin_unlock(&resetlock);
115 static int resetswitch_init(void)
117 // initialize the GPIO mode and directly
118 mcpu_gpio_mp_set(RESET_IO|LED_READY);
119 mcpu_gpio_inout(RESET_IO, MCPU_GPIO_INPUT);
120 mcpu_gpio_inout(LED_READY, MCPU_GPIO_OUTPUT);
122 INIT_WORK(&resetqueue, reset_to_default, NULL);
123 spin_lock(&resetlock);
124 endresettime = 0;
125 ledonoffflag = 1;
126 init_timer(&resettimer);
127 resettimer.function = reset_poll;
128 resettimer.expires = jiffies + RESET_POLL_TIME;
129 add_timer(&resettimer);
130 spin_unlock(&resetlock);
132 return 0;
135 module_init(resetswitch_init);
136 module_exit(resetswitch_exit);
138 /***************************************************************************/