Full support for Ginger Console
[linux-ginger.git] / arch / mips / pmc-sierra / msp71xx / msp_hwbutton.c
blob11769b55438c27da2c113da9d21c39e21affa31e
1 /*
2 * Sets up interrupt handlers for various hardware switches which are
3 * connected to interrupt lines.
5 * Copyright 2005-2207 PMC-Sierra, Inc.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
12 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
15 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <linux/kernel.h>
29 #include <linux/init.h>
30 #include <linux/interrupt.h>
32 #include <msp_int.h>
33 #include <msp_regs.h>
34 #include <msp_regops.h>
35 #ifdef CONFIG_PMCTWILED
36 #include <msp_led_macros.h>
37 #endif
39 /* For hwbutton_interrupt->initial_state */
40 #define HWBUTTON_HI 0x1
41 #define HWBUTTON_LO 0x2
44 * This struct describes a hardware button
46 struct hwbutton_interrupt {
47 char *name; /* Name of button */
48 int irq; /* Actual LINUX IRQ */
49 int eirq; /* Extended IRQ number (0-7) */
50 int initial_state; /* The "normal" state of the switch */
51 void (*handle_hi)(void *); /* Handler: switch input has gone HI */
52 void (*handle_lo)(void *); /* Handler: switch input has gone LO */
53 void *data; /* Optional data to pass to handler */
56 #ifdef CONFIG_PMC_MSP7120_GW
57 extern void msp_restart(char *);
59 static void softreset_push(void *data)
61 printk(KERN_WARNING "SOFTRESET switch was pushed\n");
64 * In the future you could move this to the release handler,
65 * timing the difference between the 'push' and 'release', and only
66 * doing this ungraceful restart if the button has been down for
67 * a certain amount of time; otherwise doing a graceful restart.
70 msp_restart(NULL);
73 static void softreset_release(void *data)
75 printk(KERN_WARNING "SOFTRESET switch was released\n");
77 /* Do nothing */
80 static void standby_on(void *data)
82 printk(KERN_WARNING "STANDBY switch was set to ON (not implemented)\n");
84 /* TODO: Put board in standby mode */
85 #ifdef CONFIG_PMCTWILED
86 msp_led_turn_off(MSP_LED_PWRSTANDBY_GREEN);
87 msp_led_turn_on(MSP_LED_PWRSTANDBY_RED);
88 #endif
91 static void standby_off(void *data)
93 printk(KERN_WARNING
94 "STANDBY switch was set to OFF (not implemented)\n");
96 /* TODO: Take out of standby mode */
97 #ifdef CONFIG_PMCTWILED
98 msp_led_turn_on(MSP_LED_PWRSTANDBY_GREEN);
99 msp_led_turn_off(MSP_LED_PWRSTANDBY_RED);
100 #endif
103 static struct hwbutton_interrupt softreset_sw = {
104 .name = "Softreset button",
105 .irq = MSP_INT_EXT0,
106 .eirq = 0,
107 .initial_state = HWBUTTON_HI,
108 .handle_hi = softreset_release,
109 .handle_lo = softreset_push,
110 .data = NULL,
113 static struct hwbutton_interrupt standby_sw = {
114 .name = "Standby switch",
115 .irq = MSP_INT_EXT1,
116 .eirq = 1,
117 .initial_state = HWBUTTON_HI,
118 .handle_hi = standby_off,
119 .handle_lo = standby_on,
120 .data = NULL,
122 #endif /* CONFIG_PMC_MSP7120_GW */
124 static irqreturn_t hwbutton_handler(int irq, void *data)
126 struct hwbutton_interrupt *hirq = data;
127 unsigned long cic_ext = *CIC_EXT_CFG_REG;
129 if (CIC_EXT_IS_ACTIVE_HI(cic_ext, hirq->eirq)) {
130 /* Interrupt: pin is now HI */
131 CIC_EXT_SET_ACTIVE_LO(cic_ext, hirq->eirq);
132 hirq->handle_hi(hirq->data);
133 } else {
134 /* Interrupt: pin is now LO */
135 CIC_EXT_SET_ACTIVE_HI(cic_ext, hirq->eirq);
136 hirq->handle_lo(hirq->data);
140 * Invert the POLARITY of this level interrupt to ack the interrupt
141 * Thus next state change will invoke the opposite message
143 *CIC_EXT_CFG_REG = cic_ext;
145 return IRQ_HANDLED;
148 static int msp_hwbutton_register(struct hwbutton_interrupt *hirq)
150 unsigned long cic_ext;
152 if (hirq->handle_hi == NULL || hirq->handle_lo == NULL)
153 return -EINVAL;
155 cic_ext = *CIC_EXT_CFG_REG;
156 CIC_EXT_SET_TRIGGER_LEVEL(cic_ext, hirq->eirq);
157 if (hirq->initial_state == HWBUTTON_HI)
158 CIC_EXT_SET_ACTIVE_LO(cic_ext, hirq->eirq);
159 else
160 CIC_EXT_SET_ACTIVE_HI(cic_ext, hirq->eirq);
161 *CIC_EXT_CFG_REG = cic_ext;
163 return request_irq(hirq->irq, hwbutton_handler, IRQF_DISABLED,
164 hirq->name, hirq);
167 static int __init msp_hwbutton_setup(void)
169 #ifdef CONFIG_PMC_MSP7120_GW
170 msp_hwbutton_register(&softreset_sw);
171 msp_hwbutton_register(&standby_sw);
172 #endif
173 return 0;
176 subsys_initcall(msp_hwbutton_setup);