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
|
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/input.h>
#include <linux/platform_device.h>
#include <linux/jiffies.h>
#include <linux/io.h>
#include <linux/kthread.h>
#include <linux/i2c.h>
#include <linux/gpio.h>
#include <linux/delay.h>
#include <linux/wakelock.h>
#include <linux/slab.h>
#include <linux/irq.h>
#include <linux/errno.h>
#include <linux/gpio.h>
#include <mach/wmt_iomux.h>
#include <linux/input/mt.h>
#include <mach/hardware.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <asm/uaccess.h>
#define INPUT_IOC_MAGIC 'x'
#define INPUT_IOC_CMD_INPUT _IOR(INPUT_IOC_MAGIC, 1, int)
#define INPUT_IOC_MAXNR 1
static struct input_dev *g_input = NULL;
static int lcdX, lcdY;
static int g_Major;
static struct mutex ioc_mutex;
static struct class *dev_class = NULL;
extern int wmt_getsyspara(char *varname, unsigned char *varval, int *varlen);
static struct input_dev *input_dev_alloc(void)
{
int err;
struct input_dev *input_dev;
input_dev = input_allocate_device();
if (!input_dev) {
printk("failed to allocate input device\n");
return NULL;
}
input_dev->name = "remote_input";
input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) | BIT_MASK(EV_REL);
set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
//set_bit(ABS_MT_TRACKING_ID, input_dev->absbit);
input_set_abs_params(input_dev,
ABS_MT_POSITION_X, 0, lcdX, 0, 0);
input_set_abs_params(input_dev,
ABS_MT_POSITION_Y, 0, lcdY, 0, 0);
//input_set_abs_params(input_dev,
// ABS_MT_TRACKING_ID, 0, 5, 0, 0);
set_bit(KEY_BACK, input_dev->keybit);
set_bit(KEY_HOME, input_dev->keybit);
set_bit(KEY_MENU, input_dev->keybit);
set_bit(KEY_SEARCH, input_dev->keybit);
set_bit(KEY_ENTER, input_dev->keybit);
set_bit(KEY_UP, input_dev->keybit);
set_bit(KEY_PAGEUP, input_dev->keybit);
set_bit(KEY_LEFT, input_dev->keybit);
set_bit(KEY_RIGHT, input_dev->keybit);
set_bit(KEY_DOWN, input_dev->keybit);
set_bit(KEY_PAGEDOWN, input_dev->keybit);
set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
set_bit(KEY_VOLUMEUP, input_dev->keybit);
set_bit(BTN_LEFT, input_dev->keybit);
set_bit(BTN_RIGHT, input_dev->keybit);
set_bit(BTN_MIDDLE, input_dev->keybit);
set_bit(BTN_SIDE, input_dev->keybit);
set_bit(REL_X, input_dev->relbit);
set_bit(REL_Y, input_dev->relbit);
set_bit(REL_WHEEL, input_dev->relbit);
err = input_register_device(input_dev);
if (err) {
printk("input_dev_alloc: failed to register input device.\n");
input_free_device(input_dev);
input_dev = NULL;
}
return input_dev;
}
static long input_ioctl(struct file *dev, unsigned int cmd, unsigned long arg)
{
struct input_event event;
if (_IOC_TYPE(cmd) != INPUT_IOC_MAGIC){
printk("CMD ERROR!");
return -ENOTTY;
}
if (_IOC_NR(cmd) > INPUT_IOC_MAXNR){
printk("NO SUCH IO CMD!\n");
return -ENOTTY;
}
switch (cmd) {
case INPUT_IOC_CMD_INPUT:
copy_from_user(&event, (struct input_event*)arg, sizeof(struct input_event));
mutex_lock(&ioc_mutex);
input_event(g_input, event.type, event.code, event.value);
mutex_unlock(&ioc_mutex);
return 0;
}
return -EINVAL;
}
static int input_open(struct inode *inode, struct file *filp)
{
int ret = 0;
return ret;
}
static int input_close(struct inode *inode, struct file *filp)
{
return 0;
}
static struct file_operations input_fops = {
.unlocked_ioctl = input_ioctl,
.open = input_open,
.release = input_close,
};
static int __init remote_init(void)
{
struct device *dev = NULL;
int len = 127;
char retval[128] = {0},*p=NULL;
int tmp[6];
mutex_init(&ioc_mutex);
if (wmt_getsyspara("wmt.display.fb0", retval, &len)) {
printk(KERN_ERR "Can't get display param. \n");
return -EIO;
}
p = retval;
sscanf(p, "%d:[%d:%d:%d:%d:%d", &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
lcdX = tmp[4];
lcdY = tmp[5];
g_input = input_dev_alloc();
if (!g_input){
printk(KERN_ERR "Alloc input device failed. \n");
return -ENODEV;
}
if ((g_Major = register_chrdev(0, "remote_input", &input_fops)) < 0) {
printk(KERN_ERR "Can't register char device. \n");
return -EIO;
}
dev_class = class_create(THIS_MODULE,"remote_input");
if (IS_ERR(dev_class)) {
unregister_chrdev(g_Major, "remote_input");
printk(KERN_ERR "Class create failed. \n");
return PTR_ERR(dev_class);
}
dev = device_create(dev_class, NULL, MKDEV(g_Major, 0), NULL,"remote_input");
if(!dev){
printk(KERN_ERR "Create device failed. \n");
return -ENODEV;
}
return 0;
}
module_init(remote_init);
static void __exit remote_exit(void)
{
device_destroy(dev_class, MKDEV(g_Major, 0));
class_destroy(dev_class);
unregister_chrdev(g_Major, "remote_input");
input_unregister_device(g_input);
//input_free_device(g_input);
mutex_destroy(&ioc_mutex);
}
module_exit(remote_exit);
MODULE_DESCRIPTION("Remote Input driver");
MODULE_LICENSE("GPL v2");
|