aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard/maple_keyb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/keyboard/maple_keyb.c')
-rw-r--r--drivers/input/keyboard/maple_keyb.c72
1 files changed, 31 insertions, 41 deletions
diff --git a/drivers/input/keyboard/maple_keyb.c b/drivers/input/keyboard/maple_keyb.c
index eecbde294f1f..cc6aaf9e85be 100644
--- a/drivers/input/keyboard/maple_keyb.c
+++ b/drivers/input/keyboard/maple_keyb.c
@@ -37,7 +37,7 @@ static unsigned char dc_kbd_keycode[256] = {
37 37
38 38
39struct dc_kbd { 39struct dc_kbd {
40 struct input_dev dev; 40 struct input_dev *dev;
41 unsigned char new[8]; 41 unsigned char new[8];
42 unsigned char old[8]; 42 unsigned char old[8];
43}; 43};
@@ -46,30 +46,24 @@ struct dc_kbd {
46static void dc_scan_kbd(struct dc_kbd *kbd) 46static void dc_scan_kbd(struct dc_kbd *kbd)
47{ 47{
48 int i; 48 int i;
49 struct input_dev *dev = &kbd->dev; 49 struct input_dev *dev = kbd->dev;
50 50
51 for(i=0; i<8; i++) 51 for (i = 0; i < 8; i++)
52 input_report_key(dev, 52 input_report_key(dev, dc_kbd_keycode[i + 224], (kbd->new[0] >> i) & 1);
53 dc_kbd_keycode[i+224],
54 (kbd->new[0]>>i)&1);
55 53
56 for(i=2; i<8; i++) { 54 for (i = 2; i < 8; i++) {
57 55
58 if(kbd->old[i]>3&&memscan(kbd->new+2, kbd->old[i], 6)==NULL) { 56 if (kbd->old[i] > 3 && memscan(kbd->new + 2, kbd->old[i], 6) == NULL) {
59 if(dc_kbd_keycode[kbd->old[i]]) 57 if (dc_kbd_keycode[kbd->old[i]])
60 input_report_key(dev, 58 input_report_key(dev, dc_kbd_keycode[kbd->old[i]], 0);
61 dc_kbd_keycode[kbd->old[i]],
62 0);
63 else 59 else
64 printk("Unknown key (scancode %#x) released.", 60 printk("Unknown key (scancode %#x) released.",
65 kbd->old[i]); 61 kbd->old[i]);
66 } 62 }
67 63
68 if(kbd->new[i]>3&&memscan(kbd->old+2, kbd->new[i], 6)!=NULL) { 64 if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) != NULL) {
69 if(dc_kbd_keycode[kbd->new[i]]) 65 if(dc_kbd_keycode[kbd->new[i]])
70 input_report_key(dev, 66 input_report_key(dev, dc_kbd_keycode[kbd->new[i]], 1);
71 dc_kbd_keycode[kbd->new[i]],
72 1);
73 else 67 else
74 printk("Unknown key (scancode %#x) pressed.", 68 printk("Unknown key (scancode %#x) pressed.",
75 kbd->new[i]); 69 kbd->new[i]);
@@ -89,43 +83,39 @@ static void dc_kbd_callback(struct mapleq *mq)
89 unsigned long *buf = mq->recvbuf; 83 unsigned long *buf = mq->recvbuf;
90 84
91 if (buf[1] == mapledev->function) { 85 if (buf[1] == mapledev->function) {
92 memcpy(kbd->new, buf+2, 8); 86 memcpy(kbd->new, buf + 2, 8);
93 dc_scan_kbd(kbd); 87 dc_scan_kbd(kbd);
94 } 88 }
95} 89}
96 90
97static int dc_kbd_connect(struct maple_device *dev) 91static int dc_kbd_connect(struct maple_device *dev)
98{ 92{
99 int i;
100 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
101 struct dc_kbd *kbd; 93 struct dc_kbd *kbd;
94 struct input_dev *input_dev;
95 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
96 int i;
102 97
103 if (!(kbd = kmalloc(sizeof(struct dc_kbd), GFP_KERNEL))) 98 dev->private_data = kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL);
104 return -1; 99 input_dev = input_allocate_device();
105 memset(kbd, 0, sizeof(struct dc_kbd)); 100 if (!kbd || !input_dev) {
106 101 kfree(kbd);
107 dev->private_data = kbd; 102 input_free_device(input_dev);
108 103 return -ENOMEM;
109 kbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 104 }
110
111 init_input_dev(&kbd->dev);
112
113 for (i=0; i<255; i++)
114 set_bit(dc_kbd_keycode[i], kbd->dev.keybit);
115
116 clear_bit(0, kbd->dev.keybit);
117 105
118 kbd->dev.private = kbd; 106 kbd->dev = input_dev;
119 107
120 kbd->dev.name = dev->product_name; 108 input_dev->name = dev->product_name;
121 kbd->dev.id.bustype = BUS_MAPLE; 109 input_dev->id.bustype = BUS_MAPLE;
110 input_dev->private = kbd;
111 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
112 for (i = 0; i < 255; i++)
113 set_bit(dc_kbd_keycode[i], input_dev->keybit);
114 clear_bit(0, input_dev->keybit);
122 115
123 input_register_device(&kbd->dev); 116 input_register_device(kbd->dev);
124 117
125 maple_getcond_callback(dev, dc_kbd_callback, 1, MAPLE_FUNC_KEYBOARD); 118 maple_getcond_callback(dev, dc_kbd_callback, 1, MAPLE_FUNC_KEYBOARD);
126
127 printk(KERN_INFO "input: keyboard(0x%lx): %s\n", data, kbd->dev.name);
128
129 return 0; 119 return 0;
130} 120}
131 121
@@ -134,7 +124,7 @@ static void dc_kbd_disconnect(struct maple_device *dev)
134{ 124{
135 struct dc_kbd *kbd = dev->private_data; 125 struct dc_kbd *kbd = dev->private_data;
136 126
137 input_unregister_device(&kbd->dev); 127 input_unregister_device(kbd->dev);
138 kfree(kbd); 128 kfree(kbd);
139} 129}
140 130