27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 #include <linux/kernel.h>
30 #include <linux/slab.h>
31 #include <linux/module.h>
34 #include <linux/hid.h>
39 #define DRIVER_VERSION ""
41 #define DRIVER_DESC "USB HID Boot Protocol keyboard driver"
42 #define DRIVER_LICENSE "GPL"
48 static const unsigned char usb_kbd_keycode[256] = {
49 0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
50 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3,
51 4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26,
52 27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
53 65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
54 105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
55 72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190,
56 191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113,
57 115,114, 0, 0, 0,121, 0, 89, 93,124, 92, 94, 95, 0, 0, 0,
58 122,123, 90, 91, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
59 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
60 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
61 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63 29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
64 150,158,159,128,136,177,178,176,142,152,173,140
94 struct input_dev *
dev;
113 static void usb_kbd_irq(
struct urb *
urb)
115 struct usb_kbd *kbd = urb->context;
118 switch (urb->status) {
130 for (i = 0; i < 8; i++)
131 input_report_key(kbd->
dev, usb_kbd_keycode[i + 224], (kbd->
new[0] >> i) & 1);
133 for (i = 2; i < 8; i++) {
136 if (usb_kbd_keycode[kbd->
old[i]])
137 input_report_key(kbd->
dev, usb_kbd_keycode[kbd->
old[i]], 0);
140 "Unknown key (scancode %#x) released.\n",
145 if (usb_kbd_keycode[kbd->
new[i]])
146 input_report_key(kbd->
dev, usb_kbd_keycode[kbd->
new[i]], 1);
149 "Unknown key (scancode %#x) released.\n",
154 input_sync(kbd->
dev);
161 hid_err(urb->dev,
"can't resubmit intr, %s-%s/input0, status %d",
162 kbd->
usbdev->bus->bus_name,
166 static int usb_kbd_event(
struct input_dev *
dev,
unsigned int type,
170 struct usb_kbd *kbd = input_get_drvdata(dev);
181 spin_unlock_irqrestore(&kbd->
leds_lock, flags);
186 spin_unlock_irqrestore(&kbd->
leds_lock, flags);
194 pr_err(
"usb_submit_urb(leds) failed\n");
198 spin_unlock_irqrestore(&kbd->
leds_lock, flags);
203 static void usb_kbd_led(
struct urb *urb)
206 struct usb_kbd *kbd = urb->context;
209 hid_warn(urb->dev,
"led urb status %d received\n",
216 spin_unlock_irqrestore(&kbd->
leds_lock, flags);
224 hid_err(urb->dev,
"usb_submit_urb(leds) failed\n");
227 spin_unlock_irqrestore(&kbd->
leds_lock, flags);
231 static int usb_kbd_open(
struct input_dev *dev)
233 struct usb_kbd *kbd = input_get_drvdata(dev);
242 static void usb_kbd_close(
struct input_dev *dev)
244 struct usb_kbd *kbd = input_get_drvdata(dev);
249 static int usb_kbd_alloc_mem(
struct usb_device *dev,
struct usb_kbd *kbd)
265 static void usb_kbd_free_mem(
struct usb_device *dev,
struct usb_kbd *kbd)
277 struct usb_device *dev = interface_to_usbdev(iface);
281 struct input_dev *input_dev;
285 interface = iface->cur_altsetting;
287 if (interface->desc.bNumEndpoints != 1)
290 endpoint = &interface->endpoint[0].desc;
291 if (!usb_endpoint_is_int_in(endpoint))
295 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
298 input_dev = input_allocate_device();
299 if (!kbd || !input_dev)
302 if (usb_kbd_alloc_mem(dev, kbd))
306 kbd->
dev = input_dev;
309 if (dev->manufacturer)
313 if (dev->manufacturer)
320 "USB HIDBP Keyboard %04x:%04x",
324 usb_make_path(dev, kbd->
phys,
sizeof(kbd->
phys));
327 input_dev->name = kbd->
name;
328 input_dev->phys = kbd->
phys;
329 usb_to_input_id(dev, &input_dev->id);
330 input_dev->dev.parent = &iface->dev;
332 input_set_drvdata(input_dev, kbd);
340 for (i = 0; i < 255; i++)
341 set_bit(usb_kbd_keycode[i], input_dev->keybit);
344 input_dev->event = usb_kbd_event;
345 input_dev->open = usb_kbd_open;
346 input_dev->close = usb_kbd_close;
348 usb_fill_int_urb(kbd->
irq, dev, pipe,
349 kbd->
new, (maxp > 8 ? 8 : maxp),
352 kbd->
irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
355 kbd->
cr->bRequest = 0x09;
357 kbd->
cr->wIndex =
cpu_to_le16(interface->desc.bInterfaceNumber);
360 usb_fill_control_urb(kbd->
led, dev, usb_sndctrlpipe(dev, 0),
361 (
void *) kbd->
cr, kbd->
leds, 1,
364 kbd->
led->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
366 error = input_register_device(kbd->
dev);
370 usb_set_intfdata(iface, kbd);
375 usb_kbd_free_mem(dev, kbd);
377 input_free_device(input_dev);
384 struct usb_kbd *kbd = usb_get_intfdata (intf);
386 usb_set_intfdata(intf,
NULL);
389 input_unregister_device(kbd->
dev);
391 usb_kbd_free_mem(interface_to_usbdev(intf), kbd);
404 static struct usb_driver usb_kbd_driver = {
406 .probe = usb_kbd_probe,
407 .disconnect = usb_kbd_disconnect,
408 .id_table = usb_kbd_id_table,