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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
/*++
*
* WonderMedia input remote control driver
*
* Copyright c 2010 WonderMedia Technologies, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* WonderMedia Technologies, Inc.
* 4F, 533, Chung-Cheng Road, Hsin-Tien, Taipei 231, R.O.C
--*/
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/device.h>
#include <linux/version.h>
#include <linux/input.h>
#include <linux/platform_device.h>
#include <asm/irq.h>
#include <mach/hardware.h>
#include <mach/wmt_pmc.h>
#include <linux/delay.h>
#include <linux/firmware.h>
#include <linux/workqueue.h>
#include <linux/slab.h>
#include <linux/gpio.h>
#include <linux/delay.h>
#include <mach/wmt_iomux.h>
#include <linux/irq.h>
static struct pkey_pdata {
unsigned int gpio_no;
struct input_dev *idev;
struct timer_list *p_key_timer;
unsigned long timer_expires;
};
static int key_codes[2]={KEY_F1,KEY_BACK};
static inline void physics_key_timeout(unsigned long fcontext)
{
struct pkey_pdata *p_key = (struct pkey_pdata *)fcontext;
int keycode;
keycode = __gpio_get_value(p_key->gpio_no)?key_codes[1]:key_codes[0];
input_report_key(p_key->idev, keycode, 1);
input_sync(p_key->idev);
mdelay(50);
input_report_key(p_key->idev, keycode, 0);
input_sync(p_key->idev);
p_key->timer_expires = 0;
}
static irqreturn_t physics_key_isr(int irq, void *dev_id)
{
unsigned long expires;
struct pkey_pdata *p_key = (struct pkey_pdata *)dev_id;
if(gpio_irqstatus(p_key->gpio_no))
{
wmt_gpio_ack_irq(p_key->gpio_no);
expires = jiffies + msecs_to_jiffies(50);
if (!expires)
expires = 1;
if(!(p_key->timer_expires) || time_after(expires, p_key->timer_expires)){
mod_timer(p_key->p_key_timer, expires);
p_key->timer_expires = expires;
}
return IRQ_HANDLED;
}
return IRQ_NONE;
}
static int hw_init(struct platform_device *pdev)
{
struct pkey_pdata *p_key = pdev->dev.platform_data;
int ret = gpio_request(p_key->gpio_no,"physics_key");
if(ret < 0) {
printk(KERN_ERR"gpio request fail for physics_key\n");
return ret;
}
gpio_direction_input(p_key->gpio_no);
wmt_gpio_set_irq_type(p_key->gpio_no,IRQ_TYPE_EDGE_BOTH);
wmt_gpio_unmask_irq(p_key->gpio_no);
request_irq(IRQ_GPIO, physics_key_isr, IRQF_SHARED, "physics_key", p_key);
return 0;
}
static int physics_key_probe(struct platform_device *pdev)
{
int i;
struct pkey_pdata *p_key = pdev->dev.platform_data;
hw_init(pdev);
if ((p_key->idev = input_allocate_device()) == NULL)
return -ENOMEM;
set_bit(EV_KEY, p_key->idev->evbit);
for (i = 0; i < ARRAY_SIZE(key_codes); i++) {
set_bit(key_codes[i], p_key->idev->keybit);
}
p_key->idev->name = "physics_key";
p_key->idev->phys = "physics_key";
input_register_device(p_key->idev);
p_key->p_key_timer = (struct timer_list *)kzalloc(sizeof(struct timer_list), GFP_KERNEL);
init_timer(p_key->p_key_timer);
p_key->p_key_timer->data = (unsigned long)p_key;
p_key->p_key_timer->function = physics_key_timeout;
return 0;
}
static int physics_key_remove(struct platform_device *dev)
{
struct pkey_pdata *p_key = dev->dev.platform_data;
if(p_key->p_key_timer)
{
del_timer_sync(p_key->p_key_timer);
free_irq(IRQ_GPIO, p_key);
input_unregister_device(p_key->idev);
input_free_device(p_key->idev);
kfree(p_key);
}
return 0;
}
void pkey_pdevice_release(struct device *dev)
{
}
#ifdef CONFIG_PM
static int physics_key_suspend(struct platform_device *dev, pm_message_t state)
{
struct pkey_pdata *p_key = dev->dev.platform_data;
del_timer_sync(p_key->p_key_timer);
wmt_gpio_mask_irq(p_key->gpio_no);
return 0;
}
static int physics_key_resume(struct platform_device *dev)
{
struct pkey_pdata *p_key = dev->dev.platform_data;
wmt_gpio_set_irq_type(p_key->gpio_no,IRQ_TYPE_EDGE_BOTH);
wmt_gpio_unmask_irq(p_key->gpio_no);
return 0;
}
#else
#define physics_key_suspend NULL
#define physics_key_resume NULL
#endif
static struct platform_device pkey_pdevice = {
.name = "physics_key",
.id = 0,
.dev = {
.release = pkey_pdevice_release,
},
};
static struct platform_driver pkey_driver = {
.probe = physics_key_probe,
.remove = physics_key_remove,
.suspend = physics_key_suspend,
.resume = physics_key_resume,
.driver = {
.name = "physics_key",
},
};
extern int wmt_getsyspara(char *varname, unsigned char *varval, int *varlen);
static int __init physics_key_init(void)
{
char buf[128];
int ret = 0;
int varlen;
int ubootvar[1];
memset(buf ,0, sizeof(buf));
varlen = sizeof(buf);
if (wmt_getsyspara("wmt.gpo.physics_switch", buf, &varlen)) {
printk(KERN_ERR"wmt.gpo.physics_switch isn't set in u-boot env! -> Use default\n");
return -1;
}
ret = sscanf(buf, "%d",
&ubootvar[0]
);
struct pkey_pdata *p_key = (struct pkey_pdata *)kzalloc(sizeof(struct pkey_pdata), GFP_KERNEL);
if (p_key == NULL)
return -ENOMEM;
p_key->gpio_no = ubootvar[0];
pkey_pdevice.dev.platform_data = (void *)p_key;
if (platform_device_register(&pkey_pdevice))
return -1;
ret = platform_driver_register(&pkey_driver);
return ret;
}
static void __exit physics_key_exit(void)
{
platform_driver_unregister(&pkey_driver);
platform_device_unregister(&pkey_pdevice);
}
module_init(physics_key_init);
module_exit(physics_key_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("WonderMedia Technologies, Inc.");
MODULE_DESCRIPTION("WMT driver");
|