17 #include <linux/module.h>
32 #define MCIR2_UNIT 333333
33 #define MCIR2_HEADER_NBITS 5
34 #define MCIR2_MOUSE_NBITS 29
35 #define MCIR2_KEYBOARD_NBITS 32
36 #define MCIR2_PREFIX_PULSE (8 * MCIR2_UNIT)
37 #define MCIR2_PREFIX_SPACE (1 * MCIR2_UNIT)
38 #define MCIR2_MAX_LEN (3 * MCIR2_UNIT)
39 #define MCIR2_BIT_START (1 * MCIR2_UNIT)
40 #define MCIR2_BIT_END (1 * MCIR2_UNIT)
41 #define MCIR2_BIT_0 (1 * MCIR2_UNIT)
42 #define MCIR2_BIT_SET (2 * MCIR2_UNIT)
43 #define MCIR2_MODE_MASK 0xf
44 #define MCIR2_KEYBOARD_HEADER 0x4
45 #define MCIR2_MOUSE_HEADER 0x1
46 #define MCIR2_MASK_KEYS_START 0xe0
63 static unsigned char kbd_keycodes[256] = {
118 static void mce_kbd_rx_timeout(
unsigned long data)
120 struct mce_kbd_dec *mce_kbd = (
struct mce_kbd_dec *)data;
122 unsigned char maskcode;
124 IR_dprintk(2,
"timer callback clearing all keys\n");
126 for (i = 0; i < 7; i++) {
128 input_report_key(mce_kbd->idev, maskcode, 0);
132 input_report_key(mce_kbd->idev, kbd_keycodes[i], 0);
147 static void ir_mce_kbd_process_keyboard_data(
struct input_dev *
idev,
150 u8 keydata = (scancode >> 8) & 0xff;
151 u8 shiftmask = scancode & 0xff;
152 unsigned char keycode, maskcode;
155 IR_dprintk(1,
"keyboard: keydata = 0x%02x, shiftmask = 0x%02x\n",
158 for (i = 0; i < 7; i++) {
159 maskcode = kbd_keycodes[MCIR2_MASK_KEYS_START +
i];
160 if (shiftmask & (1 << i))
164 input_report_key(idev, maskcode, keystate);
168 keycode = kbd_keycodes[keydata];
169 input_report_key(idev, keycode, 1);
172 input_report_key(idev, kbd_keycodes[i], 0);
176 static void ir_mce_kbd_process_mouse_data(
struct input_dev *idev,
u32 scancode)
179 u8 xdata = (scancode >> 7) & 0x7f;
180 u8 ydata = (scancode >> 14) & 0x7f;
183 bool right = scancode & 0x40;
184 bool left = scancode & 0x20;
187 x = -((~xdata & 0x7f) + 1);
192 y = -((~ydata & 0x7f) + 1);
196 IR_dprintk(1,
"mouse: x = %d, y = %d, btns = %s%s\n",
197 x, y, left ?
"L" :
"", right ?
"R" :
"");
199 input_report_rel(idev,
REL_X, x);
200 input_report_rel(idev,
REL_Y, y);
202 input_report_key(idev,
BTN_LEFT, left);
203 input_report_key(idev,
BTN_RIGHT, right);
215 struct mce_kbd_dec *data = &dev->
raw->mce_kbd;
222 if (!is_timing_event(ev)) {
232 IR_dprintk(2,
"started at state %i (%uus %s)\n",
238 switch (data->state) {
267 if (!is_transition(&ev, &dev->
raw->prev_ev))
285 IR_dprintk(1,
"not keyboard or mouse data\n");
306 if (!is_transition(&ev, &dev->
raw->prev_ev))
309 if (data->count == data->wanted_bits)
321 switch (data->wanted_bits) {
323 scancode = data->body & 0xffff;
324 IR_dprintk(1,
"keyboard data 0x%08x\n", data->body);
329 mod_timer(&data->rx_timeout, jiffies + delay);
331 ir_mce_kbd_process_keyboard_data(data->idev, scancode);
334 scancode = data->body & 0x1fffff;
335 IR_dprintk(1,
"mouse data 0x%06x\n", scancode);
337 ir_mce_kbd_process_mouse_data(data->idev, scancode);
340 IR_dprintk(1,
"not keyboard or mouse data\n");
345 input_sync(data->idev);
350 IR_dprintk(1,
"failed at state %i (%uus %s)\n",
353 input_sync(data->idev);
357 static int ir_mce_kbd_register(
struct rc_dev *dev)
359 struct mce_kbd_dec *mce_kbd = &dev->
raw->mce_kbd;
360 struct input_dev *
idev;
363 idev = input_allocate_device();
367 snprintf(mce_kbd->name,
sizeof(mce_kbd->name),
369 strlcat(mce_kbd->phys,
"/input0",
sizeof(mce_kbd->phys));
371 idev->name = mce_kbd->name;
372 idev->phys = mce_kbd->phys;
377 for (i = 0; i <
sizeof(kbd_keycodes); i++)
378 set_bit(kbd_keycodes[i], idev->keybit);
391 setup_timer(&mce_kbd->rx_timeout, mce_kbd_rx_timeout,
392 (
unsigned long)mce_kbd);
394 input_set_drvdata(idev, mce_kbd);
399 idev->dev.parent = &dev->
dev;
402 ret = input_register_device(idev);
404 input_free_device(idev);
408 mce_kbd->idev =
idev;
413 static int ir_mce_kbd_unregister(
struct rc_dev *dev)
415 struct mce_kbd_dec *mce_kbd = &dev->
raw->mce_kbd;
416 struct input_dev *idev = mce_kbd->idev;
419 input_unregister_device(idev);
426 .decode = ir_mce_kbd_decode,
427 .raw_register = ir_mce_kbd_register,
428 .raw_unregister = ir_mce_kbd_unregister,
431 static int __init ir_mce_kbd_decode_init(
void)
435 printk(
KERN_INFO "IR MCE Keyboard/mouse protocol handler initialized\n");
439 static void __exit ir_mce_kbd_decode_exit(
void)