1 #include <linux/module.h>
2 #include <linux/version.h>
3
4 #include <linux/init.h>
5 #include <linux/fs.h>
6 #include <linux/interrupt.h>
7 #include <linux/irq.h>
8 #include <linux/sched.h>
9 #include <linux/pm.h>
10 #include <linux/sysctl.h>
11 #include <linux/proc_fs.h>
12 #include <linux/delay.h>
13 #include <linux/platform_device.h>
14 #include <linux/input.h>
15 #include <linux/irq.h>
16
17 #include <asm/gpio.h>
18 #include <asm/io.h>
19 #include <asm/arch/regs-gpio.h>
20
21
22 struct pin_desc{
23 int irq;
24 char *name;
25 unsigned int pin;
26 unsigned int key_val;
27 };
28
29 struct pin_desc pins_desc[4] = {
30 {IRQ_EINT0, "S2", S3C2410_GPF0, KEY_L},
31 {IRQ_EINT2, "S3", S3C2410_GPF2, KEY_S},
32 {IRQ_EINT11, "S4", S3C2410_GPG3, KEY_ENTER},
33 {IRQ_EINT19, "S5", S3C2410_GPG11, KEY_LEFTSHIFT},
34 };
35
36 static struct input_dev *input_subsys_dev;
37 static struct pin_desc *irq_pd;
38 static struct timer_list buttons_timer;
39
40 static irqreturn_t buttons_irq(int irq, void *dev_id)
41 {
42 /* [cgw]: 按键IO发生边沿中断时重新设置定时间隔
43 * 用于按键消抖
44 */
45 irq_pd = (struct pin_desc *)dev_id;
46 buttons_timer.data = irq_pd->pin;
47 mod_timer(&buttons_timer, jiffies+HZ/100);
48 return IRQ_RETVAL(IRQ_HANDLED);
49 }
50
51 static void buttons_timer_function(unsigned long data)
52 {
53 struct pin_desc * pindesc = irq_pd;
54 unsigned int pinval;
55
56 if (!pindesc)
57 return;
58
59 /* [cgw]: 获取按键IO状态 */
60 pinval = s3c2410_gpio_getpin((unsigned int)data);
61
62 /* [cgw]: 根据按键IO状态上报按键事件 */
63 if (pinval)
64 {
65 /* [cgw]: 上报按键弹起 */
66 input_report_key(input_subsys_dev, pindesc->key_val, 0);
67 //input_sync(input_subsys_dev);
68 }
69 else
70 {
71 /* [cgw]: 上报按键按下 */
72 input_report_key(input_subsys_dev, pindesc->key_val, 1);
73 //input_sync(input_subsys_dev);
74 }
75
76 //printk("timer occur!\n");
77 }
78
79
80 static int led_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
81 {
82 printk("led event!\n");
83 printk("value: 0x%x\n", value);
84
85 /* [cgw]: 根据应用程序下发的LED控制事件
86 * 亮灭LED
87 */
88 //if (code == SND_BELL) {
89 if (code == LED_MUTE) {
90 if (value == 0xAA) {
91 /* [cgw]: 点亮 */
92 s3c2410_gpio_setpin(S3C2410_GPF4, 0);
93 } else if (value == 0xEE) {
94 /* [cgw]: 熄灭 */
95 s3c2410_gpio_setpin(S3C2410_GPF4, 1);
96 }
97
98 return 0;
99 }
100
101 return -1;
102 }
103
104 int input_subsys_open(struct input_dev *dev)
105 {
106 int i, retval;
107
108 /* [cgw]: 设置按键IO为中断输入 */
109 s3c2410_gpio_cfgpin(S3C2410_GPF0, S3C2410_GPF0_EINT0);
110 s3c2410_gpio_cfgpin(S3C2410_GPF2, S3C2410_GPF2_EINT2);
111 s3c2410_gpio_cfgpin(S3C2410_GPG3, S3C2410_GPG3_EINT11);
112 s3c2410_gpio_cfgpin(S3C2410_GPG11, S3C2410_GPG11_EINT19);
113
114 /* [cgw]: 设置LED IO为输出,初始为熄灭LED */
115 s3c2410_gpio_cfgpin(S3C2410_GPF4, S3C2410_GPF4_OUTP);
116 s3c2410_gpio_setpin(S3C2410_GPF4, 1);
117
118 s3c2410_gpio_cfgpin(S3C2410_GPF5, S3C2410_GPF5_OUTP);
119 s3c2410_gpio_setpin(S3C