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-old
blob25b89dd9655d8af62c07a05c5d41d68b89f456f1
1 /***************************************************************************/
3 /*
4  *      linux/drivers/char/resetswitch.c
5  *
6  *      Basic driver to support the NETtel software reset button.
7  *
8  *      Copyright (C) 1999-2002, Greg Ungerer (gerg@snapgear.com)
9  */
11 /***************************************************************************/
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/param.h>
17 #include <linux/init.h>
18 #include <asm/irq.h>
19 #include <asm/traps.h>
20 #include <asm/machdep.h>
21 #include <asm/coldfire.h>
22 #include <asm/mcftimer.h>
23 #include <asm/mcfsim.h>
24 #include <asm/delay.h>
26 /***************************************************************************/
27 #ifdef CONFIG_M5272
28 /***************************************************************************/
31  *      Off-course the 5272 would have to deal with setting up and
32  *      acknowledging interrupts differently to all other ColdFIre's!
33  */
34 #define SWITCH_IRQ      65
36 static void __inline__ mcf_enablevector(int vecnr)
38         volatile unsigned long  *icrp;
39         icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
40         *icrp = (*icrp & 0x07777777) | 0xf0000000;
43 static void __inline__ mcf_disablevector(void)
45         volatile unsigned long  *icrp;
46         icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
47         *icrp = (*icrp & 0x07777777) | 0x80000000;
50 static void __inline__ mcf_ackvector(void)
52         volatile unsigned long  *icrp;
53         icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
54         *icrp = (*icrp & 0x07777777) | 0xf0000000;
57 static __inline__ int mcf_isvector(void)
59         return((*((volatile unsigned long *) (MCF_MBAR + MCFSIM_ISR)) & 0x80000000) == 0);
62 /***************************************************************************/
63 #else
64 /***************************************************************************/
67  *      Common vector setup for 5206e, 5307 and 5407.
68  */
69 #define SWITCH_IRQ      31
71 static void __inline__ mcf_enablevector(int vecnr)
75 static void __inline__ mcf_disablevec(void)
77         mcf_setimr(mcf_getimr() | MCFSIM_IMR_EINT7);
80 static void __inline__ mcf_ackvector(void)
82         mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_EINT7);
85 static __inline__ int mcf_isvector(void)
87         return(mcf_getipr() & MCFSIM_IMR_EINT7);
90 /***************************************************************************/
91 #endif /* !CONFIG_M5272 */
92 /***************************************************************************/
94 void resetswitch_button(int irq, void *dev_id, struct pt_regs *regs)
96         extern void     flash_eraseconfig(void);
97         static int      inbutton = 0;
99         /*
100          *      IRQ7 is not maskable by the CPU core. It is possible
101          *      that switch bounce mey get us back here before we have
102          *      really serviced the interrupt.
103          */
104         if (inbutton)
105                 return;
106         inbutton = 1;
108         /* Disable interrupt at SIM - best we can do... */
109 #if 0
110         mcf_disablevec();
111 #endif
113         /* Try and de-bounce the switch a little... */
114         udelay(10000);
116 #ifdef CONFIG_BLK_DEV_BLKMEM
117         flash_eraseconfig();
118 #endif
120         /* Don't leave here 'till button is no longer pushed! */
121         for (;;) {
122                 if (mcf_isvector() != 0)
123                         break;
124         }
126         HARD_RESET_NOW();
127         /* Should never get here... */
129         inbutton = 0;
131         mcf_ackvector();
134 /***************************************************************************/
136 int resetswitch_init(void)
138         mcf_enablevector(SWITCH_IRQ);
139         mcf_autovector(SWITCH_IRQ);
140         request_irq(SWITCH_IRQ, resetswitch_button,
141                 (SA_INTERRUPT | IRQ_FLG_FAST), "Reset Button", NULL);
142         return(0);
145 module_init(resetswitch_init);
147 /***************************************************************************/