1 /***************************************************************************/
4 * linux/drivers/char/resetswitch.c
6 * Basic driver to support the Moxart software reset button.
8 * Jimmy_chen@moxa.com.tw
11 /***************************************************************************/
13 #if 1 // add by Victor Yu. 02-09-2007
14 #include <linux/version.h>
16 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) // add by Victor Yu. 02-09-2007
17 #include <linux/config.h>
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>
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>
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)
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)
46 #define RESET_IO PIO(25)
47 #define LED_READY PIO(27)
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] ;
61 envp
[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin" ;
62 envp
[2] = "TERM=console" ;
65 argv
[0] = "ldfactory" ;
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
);
85 } else if ( time_after(jiffies
, intervaltime
) ) {
88 mcpu_gpio_set(LED_READY
, MCPU_GPIO_HIGH
);
91 mcpu_gpio_set(LED_READY
, MCPU_GPIO_LOW
);
93 intervaltime
= jiffies
+ HZ
;
95 } else if ( endresettime
) {
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
);
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
);
126 init_timer(&resettimer
);
127 resettimer
.function
= reset_poll
;
128 resettimer
.expires
= jiffies
+ RESET_POLL_TIME
;
129 add_timer(&resettimer
);
130 spin_unlock(&resetlock
);
135 module_init(resetswitch_init
);
136 module_exit(resetswitch_exit
);
138 /***************************************************************************/