|
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/fs.h>
- #include <linux/interrupt.h>
- #include <linux/irq.h>
- #include <linux/sched.h>
- #include <linux/pm.h>
- #include <linux/sysctl.h>
- #include <linux/proc_fs.h>
- #include <linux/delay.h>
- #include <linux/platform_device.h>
- #include <linux/input.h>
- #include <linux/io.h>
- /* 参考drivers\input\keyboard\gpio_keys.c
- */
- struct pin_desc {
- int irq;
- int pin; /* */
- int val;
- char *name;
- };
- static struct pin_desc pins_desc[] = {
- {S3C_EINT(0), 0, KEY_TAB, "S2"},
- {S3C_EINT(1), 1, KEY_LEFTSHIFT, "S3"},
- {S3C_EINT(2), 2, KEY_L, "S4"},
- {S3C_EINT(3), 3, KEY_ENTER, "S5"},
- {S3C_EINT(4), 4, KEY_BACKSPACE, "S6"},
- {S3C_EINT(5), 5, KEY_S, "S7"},
- };
- static struct input_dev *buttons_dev;
- static volatile unsigned long *gpndat;
- static irqreturn_t buttons_irq(int irq, void *dev_id)
- {
- int pin_val;
- struct pin_desc *pd = (struct pin_desc *)dev_id;
- /* 确定按键值 */
- pin_val = *gpndat & (1<<pd->pin);
- /* 用input_event函数上报 */
- if (pin_val)
- {
- /* 松开 */
- /* 最后一个参数: 0-松开, 1-按下 */
- input_event(buttons_dev, EV_KEY, pd->val, 0);
- input_sync(buttons_dev);
- }
- else
- {
- /* 按下 */
- /* 最后一个参数: 0-松开, 1-按下 */
- input_event(buttons_dev, EV_KEY, pd->val, 1);
- input_sync(buttons_dev);
- }
- return IRQ_HANDLED;
- }
- static int buttons_init(void)
- {
- int i;
- /* 1. 分配input_dev */
- buttons_dev = input_allocate_device();
- /* 2. 设置 */
- /* 2.1 能产生哪类事件 */
- set_bit(EV_KEY, buttons_dev->evbit);
- set_bit(EV_REP, buttons_dev->evbit);
- /* 2.2 能产生这类事件里的哪些事件 */
- set_bit(KEY_L, buttons_dev->keybit);
- set_bit(KEY_S, buttons_dev->keybit);
- set_bit(KEY_ENTER, buttons_dev->keybit);
- set_bit(KEY_LEFTSHIFT, buttons_dev->keybit);
- set_bit(KEY_BACKSPACE, buttons_dev->keybit);
- set_bit(KEY_TAB, buttons_dev->keybit);
- /* 3. 注册 */
- input_register_device(buttons_dev);
- /* 4. 硬件相关的操作 */
- gpndat = ioremap(0x7F008834, 4);
- for (i = 0; i < 6; i++)
- {
- request_irq(pins_desc[i].irq, buttons_irq, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, pins_desc[i].name, &pins_desc[i]);
- }
- return 0;
- }
- static void buttons_exit(void)
- {
- int i;
- for (i = 0; i < 6; i++)
- {
- free_irq(pins_desc[i].irq, &pins_desc[i]);
- }
- iounmap(gpndat);
- input_unregister_device(buttons_dev);
- input_free_device(buttons_dev);
- }
- module_init(buttons_init);
- module_exit(buttons_exit);
- MODULE_LICENSE("GPL");
复制代码
|
|