1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <linux/kernel.h>
29#include <linux/init.h>
30#include <linux/interrupt.h>
31
32#include <msp_int.h>
33#include <msp_regs.h>
34#include <msp_regops.h>
35
36
37#define HWBUTTON_HI 0x1
38#define HWBUTTON_LO 0x2
39
40
41
42
43struct hwbutton_interrupt {
44 char *name;
45 int irq;
46 int eirq;
47 int initial_state;
48 void (*handle_hi)(void *);
49 void (*handle_lo)(void *);
50 void *data;
51};
52
53#ifdef CONFIG_PMC_MSP7120_GW
54extern void msp_restart(char *);
55
56static void softreset_push(void *data)
57{
58 printk(KERN_WARNING "SOFTRESET switch was pushed\n");
59
60
61
62
63
64
65
66
67 msp_restart(NULL);
68}
69
70static void softreset_release(void *data)
71{
72 printk(KERN_WARNING "SOFTRESET switch was released\n");
73
74
75}
76
77static void standby_on(void *data)
78{
79 printk(KERN_WARNING "STANDBY switch was set to ON (not implemented)\n");
80
81
82}
83
84static void standby_off(void *data)
85{
86 printk(KERN_WARNING
87 "STANDBY switch was set to OFF (not implemented)\n");
88
89
90}
91
92static struct hwbutton_interrupt softreset_sw = {
93 .name = "Softreset button",
94 .irq = MSP_INT_EXT0,
95 .eirq = 0,
96 .initial_state = HWBUTTON_HI,
97 .handle_hi = softreset_release,
98 .handle_lo = softreset_push,
99 .data = NULL,
100};
101
102static struct hwbutton_interrupt standby_sw = {
103 .name = "Standby switch",
104 .irq = MSP_INT_EXT1,
105 .eirq = 1,
106 .initial_state = HWBUTTON_HI,
107 .handle_hi = standby_off,
108 .handle_lo = standby_on,
109 .data = NULL,
110};
111#endif
112
113static irqreturn_t hwbutton_handler(int irq, void *data)
114{
115 struct hwbutton_interrupt *hirq = data;
116 unsigned long cic_ext = *CIC_EXT_CFG_REG;
117
118 if (CIC_EXT_IS_ACTIVE_HI(cic_ext, hirq->eirq)) {
119
120 CIC_EXT_SET_ACTIVE_LO(cic_ext, hirq->eirq);
121 hirq->handle_hi(hirq->data);
122 } else {
123
124 CIC_EXT_SET_ACTIVE_HI(cic_ext, hirq->eirq);
125 hirq->handle_lo(hirq->data);
126 }
127
128
129
130
131
132 *CIC_EXT_CFG_REG = cic_ext;
133
134 return IRQ_HANDLED;
135}
136
137static int msp_hwbutton_register(struct hwbutton_interrupt *hirq)
138{
139 unsigned long cic_ext;
140
141 if (hirq->handle_hi == NULL || hirq->handle_lo == NULL)
142 return -EINVAL;
143
144 cic_ext = *CIC_EXT_CFG_REG;
145 CIC_EXT_SET_TRIGGER_LEVEL(cic_ext, hirq->eirq);
146 if (hirq->initial_state == HWBUTTON_HI)
147 CIC_EXT_SET_ACTIVE_LO(cic_ext, hirq->eirq);
148 else
149 CIC_EXT_SET_ACTIVE_HI(cic_ext, hirq->eirq);
150 *CIC_EXT_CFG_REG = cic_ext;
151
152 return request_irq(hirq->irq, hwbutton_handler, 0,
153 hirq->name, hirq);
154}
155
156static int __init msp_hwbutton_setup(void)
157{
158#ifdef CONFIG_PMC_MSP7120_GW
159 msp_hwbutton_register(&softreset_sw);
160 msp_hwbutton_register(&standby_sw);
161#endif
162 return 0;
163}
164
165subsys_initcall(msp_hwbutton_setup);
166