xref: /linux/drivers/hid/usbhid/usbkbd.c (revision b0e668240949f69e84d69f998aa9af759e8be635)
16db3dfefSJiri Kosina /*
26db3dfefSJiri Kosina  * $Id: usbkbd.c,v 1.27 2001/12/27 10:37:41 vojtech Exp $
36db3dfefSJiri Kosina  *
46db3dfefSJiri Kosina  *  Copyright (c) 1999-2001 Vojtech Pavlik
56db3dfefSJiri Kosina  *
66db3dfefSJiri Kosina  *  USB HIDBP Keyboard support
76db3dfefSJiri Kosina  */
86db3dfefSJiri Kosina 
96db3dfefSJiri Kosina /*
106db3dfefSJiri Kosina  * This program is free software; you can redistribute it and/or modify
116db3dfefSJiri Kosina  * it under the terms of the GNU General Public License as published by
126db3dfefSJiri Kosina  * the Free Software Foundation; either version 2 of the License, or
136db3dfefSJiri Kosina  * (at your option) any later version.
146db3dfefSJiri Kosina  *
156db3dfefSJiri Kosina  * This program is distributed in the hope that it will be useful,
166db3dfefSJiri Kosina  * but WITHOUT ANY WARRANTY; without even the implied warranty of
176db3dfefSJiri Kosina  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
186db3dfefSJiri Kosina  * GNU General Public License for more details.
196db3dfefSJiri Kosina  *
206db3dfefSJiri Kosina  * You should have received a copy of the GNU General Public License
216db3dfefSJiri Kosina  * along with this program; if not, write to the Free Software
226db3dfefSJiri Kosina  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
236db3dfefSJiri Kosina  *
246db3dfefSJiri Kosina  * Should you need to contact me, the author, you can do so either by
256db3dfefSJiri Kosina  * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
266db3dfefSJiri Kosina  * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
276db3dfefSJiri Kosina  */
286db3dfefSJiri Kosina 
296db3dfefSJiri Kosina #include <linux/kernel.h>
306db3dfefSJiri Kosina #include <linux/slab.h>
316db3dfefSJiri Kosina #include <linux/module.h>
326db3dfefSJiri Kosina #include <linux/init.h>
336db3dfefSJiri Kosina #include <linux/usb/input.h>
346db3dfefSJiri Kosina #include <linux/hid.h>
356db3dfefSJiri Kosina 
366db3dfefSJiri Kosina /*
376db3dfefSJiri Kosina  * Version Information
386db3dfefSJiri Kosina  */
396db3dfefSJiri Kosina #define DRIVER_VERSION ""
406db3dfefSJiri Kosina #define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
416db3dfefSJiri Kosina #define DRIVER_DESC "USB HID Boot Protocol keyboard driver"
426db3dfefSJiri Kosina #define DRIVER_LICENSE "GPL"
436db3dfefSJiri Kosina 
446db3dfefSJiri Kosina MODULE_AUTHOR(DRIVER_AUTHOR);
456db3dfefSJiri Kosina MODULE_DESCRIPTION(DRIVER_DESC);
466db3dfefSJiri Kosina MODULE_LICENSE(DRIVER_LICENSE);
476db3dfefSJiri Kosina 
486db3dfefSJiri Kosina static unsigned char usb_kbd_keycode[256] = {
496db3dfefSJiri Kosina 	  0,  0,  0,  0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
506db3dfefSJiri Kosina 	 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44,  2,  3,
516db3dfefSJiri Kosina 	  4,  5,  6,  7,  8,  9, 10, 11, 28,  1, 14, 15, 57, 12, 13, 26,
526db3dfefSJiri Kosina 	 27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
536db3dfefSJiri Kosina 	 65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
546db3dfefSJiri Kosina 	105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
556db3dfefSJiri Kosina 	 72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190,
566db3dfefSJiri Kosina 	191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113,
576db3dfefSJiri Kosina 	115,114,  0,  0,  0,121,  0, 89, 93,124, 92, 94, 95,  0,  0,  0,
586db3dfefSJiri Kosina 	122,123, 90, 91, 85,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
596db3dfefSJiri Kosina 	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
606db3dfefSJiri Kosina 	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
616db3dfefSJiri Kosina 	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
626db3dfefSJiri Kosina 	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
636db3dfefSJiri Kosina 	 29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
646db3dfefSJiri Kosina 	150,158,159,128,136,177,178,176,142,152,173,140
656db3dfefSJiri Kosina };
666db3dfefSJiri Kosina 
676db3dfefSJiri Kosina struct usb_kbd {
686db3dfefSJiri Kosina 	struct input_dev *dev;
696db3dfefSJiri Kosina 	struct usb_device *usbdev;
706db3dfefSJiri Kosina 	unsigned char old[8];
716db3dfefSJiri Kosina 	struct urb *irq, *led;
726db3dfefSJiri Kosina 	unsigned char newleds;
736db3dfefSJiri Kosina 	char name[128];
746db3dfefSJiri Kosina 	char phys[64];
756db3dfefSJiri Kosina 
766db3dfefSJiri Kosina 	unsigned char *new;
776db3dfefSJiri Kosina 	struct usb_ctrlrequest *cr;
786db3dfefSJiri Kosina 	unsigned char *leds;
796db3dfefSJiri Kosina 	dma_addr_t cr_dma;
806db3dfefSJiri Kosina 	dma_addr_t new_dma;
816db3dfefSJiri Kosina 	dma_addr_t leds_dma;
826db3dfefSJiri Kosina };
836db3dfefSJiri Kosina 
846db3dfefSJiri Kosina static void usb_kbd_irq(struct urb *urb)
856db3dfefSJiri Kosina {
866db3dfefSJiri Kosina 	struct usb_kbd *kbd = urb->context;
876db3dfefSJiri Kosina 	int i;
886db3dfefSJiri Kosina 
896db3dfefSJiri Kosina 	switch (urb->status) {
906db3dfefSJiri Kosina 	case 0:			/* success */
916db3dfefSJiri Kosina 		break;
926db3dfefSJiri Kosina 	case -ECONNRESET:	/* unlink */
936db3dfefSJiri Kosina 	case -ENOENT:
946db3dfefSJiri Kosina 	case -ESHUTDOWN:
956db3dfefSJiri Kosina 		return;
966db3dfefSJiri Kosina 	/* -EPIPE:  should clear the halt */
976db3dfefSJiri Kosina 	default:		/* error */
986db3dfefSJiri Kosina 		goto resubmit;
996db3dfefSJiri Kosina 	}
1006db3dfefSJiri Kosina 
1016db3dfefSJiri Kosina 	for (i = 0; i < 8; i++)
1026db3dfefSJiri Kosina 		input_report_key(kbd->dev, usb_kbd_keycode[i + 224], (kbd->new[0] >> i) & 1);
1036db3dfefSJiri Kosina 
1046db3dfefSJiri Kosina 	for (i = 2; i < 8; i++) {
1056db3dfefSJiri Kosina 
1066db3dfefSJiri Kosina 		if (kbd->old[i] > 3 && memscan(kbd->new + 2, kbd->old[i], 6) == kbd->new + 8) {
1076db3dfefSJiri Kosina 			if (usb_kbd_keycode[kbd->old[i]])
1086db3dfefSJiri Kosina 				input_report_key(kbd->dev, usb_kbd_keycode[kbd->old[i]], 0);
1096db3dfefSJiri Kosina 			else
1106db3dfefSJiri Kosina 				info("Unknown key (scancode %#x) released.", kbd->old[i]);
1116db3dfefSJiri Kosina 		}
1126db3dfefSJiri Kosina 
1136db3dfefSJiri Kosina 		if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) == kbd->old + 8) {
1146db3dfefSJiri Kosina 			if (usb_kbd_keycode[kbd->new[i]])
1156db3dfefSJiri Kosina 				input_report_key(kbd->dev, usb_kbd_keycode[kbd->new[i]], 1);
1166db3dfefSJiri Kosina 			else
1176db3dfefSJiri Kosina 				info("Unknown key (scancode %#x) pressed.", kbd->new[i]);
1186db3dfefSJiri Kosina 		}
1196db3dfefSJiri Kosina 	}
1206db3dfefSJiri Kosina 
1216db3dfefSJiri Kosina 	input_sync(kbd->dev);
1226db3dfefSJiri Kosina 
1236db3dfefSJiri Kosina 	memcpy(kbd->old, kbd->new, 8);
1246db3dfefSJiri Kosina 
1256db3dfefSJiri Kosina resubmit:
1266db3dfefSJiri Kosina 	i = usb_submit_urb (urb, GFP_ATOMIC);
1276db3dfefSJiri Kosina 	if (i)
12858037eb9SJiri Kosina 		err_hid ("can't resubmit intr, %s-%s/input0, status %d",
1296db3dfefSJiri Kosina 				kbd->usbdev->bus->bus_name,
1306db3dfefSJiri Kosina 				kbd->usbdev->devpath, i);
1316db3dfefSJiri Kosina }
1326db3dfefSJiri Kosina 
1336db3dfefSJiri Kosina static int usb_kbd_event(struct input_dev *dev, unsigned int type,
1346db3dfefSJiri Kosina 			 unsigned int code, int value)
1356db3dfefSJiri Kosina {
136e0712985SDmitry Torokhov 	struct usb_kbd *kbd = input_get_drvdata(dev);
1376db3dfefSJiri Kosina 
1386db3dfefSJiri Kosina 	if (type != EV_LED)
1396db3dfefSJiri Kosina 		return -1;
1406db3dfefSJiri Kosina 
1416db3dfefSJiri Kosina 	kbd->newleds = (!!test_bit(LED_KANA,    dev->led) << 3) | (!!test_bit(LED_COMPOSE, dev->led) << 3) |
1426db3dfefSJiri Kosina 		       (!!test_bit(LED_SCROLLL, dev->led) << 2) | (!!test_bit(LED_CAPSL,   dev->led) << 1) |
1436db3dfefSJiri Kosina 		       (!!test_bit(LED_NUML,    dev->led));
1446db3dfefSJiri Kosina 
1456db3dfefSJiri Kosina 	if (kbd->led->status == -EINPROGRESS)
1466db3dfefSJiri Kosina 		return 0;
1476db3dfefSJiri Kosina 
1486db3dfefSJiri Kosina 	if (*(kbd->leds) == kbd->newleds)
1496db3dfefSJiri Kosina 		return 0;
1506db3dfefSJiri Kosina 
1516db3dfefSJiri Kosina 	*(kbd->leds) = kbd->newleds;
1526db3dfefSJiri Kosina 	kbd->led->dev = kbd->usbdev;
1536db3dfefSJiri Kosina 	if (usb_submit_urb(kbd->led, GFP_ATOMIC))
15458037eb9SJiri Kosina 		err_hid("usb_submit_urb(leds) failed");
1556db3dfefSJiri Kosina 
1566db3dfefSJiri Kosina 	return 0;
1576db3dfefSJiri Kosina }
1586db3dfefSJiri Kosina 
1596db3dfefSJiri Kosina static void usb_kbd_led(struct urb *urb)
1606db3dfefSJiri Kosina {
1616db3dfefSJiri Kosina 	struct usb_kbd *kbd = urb->context;
1626db3dfefSJiri Kosina 
1636db3dfefSJiri Kosina 	if (urb->status)
1646db3dfefSJiri Kosina 		warn("led urb status %d received", urb->status);
1656db3dfefSJiri Kosina 
1666db3dfefSJiri Kosina 	if (*(kbd->leds) == kbd->newleds)
1676db3dfefSJiri Kosina 		return;
1686db3dfefSJiri Kosina 
1696db3dfefSJiri Kosina 	*(kbd->leds) = kbd->newleds;
1706db3dfefSJiri Kosina 	kbd->led->dev = kbd->usbdev;
1716db3dfefSJiri Kosina 	if (usb_submit_urb(kbd->led, GFP_ATOMIC))
17258037eb9SJiri Kosina 		err_hid("usb_submit_urb(leds) failed");
1736db3dfefSJiri Kosina }
1746db3dfefSJiri Kosina 
1756db3dfefSJiri Kosina static int usb_kbd_open(struct input_dev *dev)
1766db3dfefSJiri Kosina {
177e0712985SDmitry Torokhov 	struct usb_kbd *kbd = input_get_drvdata(dev);
1786db3dfefSJiri Kosina 
1796db3dfefSJiri Kosina 	kbd->irq->dev = kbd->usbdev;
1806db3dfefSJiri Kosina 	if (usb_submit_urb(kbd->irq, GFP_KERNEL))
1816db3dfefSJiri Kosina 		return -EIO;
1826db3dfefSJiri Kosina 
1836db3dfefSJiri Kosina 	return 0;
1846db3dfefSJiri Kosina }
1856db3dfefSJiri Kosina 
1866db3dfefSJiri Kosina static void usb_kbd_close(struct input_dev *dev)
1876db3dfefSJiri Kosina {
188e0712985SDmitry Torokhov 	struct usb_kbd *kbd = input_get_drvdata(dev);
1896db3dfefSJiri Kosina 
1906db3dfefSJiri Kosina 	usb_kill_urb(kbd->irq);
1916db3dfefSJiri Kosina }
1926db3dfefSJiri Kosina 
1936db3dfefSJiri Kosina static int usb_kbd_alloc_mem(struct usb_device *dev, struct usb_kbd *kbd)
1946db3dfefSJiri Kosina {
1956db3dfefSJiri Kosina 	if (!(kbd->irq = usb_alloc_urb(0, GFP_KERNEL)))
1966db3dfefSJiri Kosina 		return -1;
1976db3dfefSJiri Kosina 	if (!(kbd->led = usb_alloc_urb(0, GFP_KERNEL)))
1986db3dfefSJiri Kosina 		return -1;
1996db3dfefSJiri Kosina 	if (!(kbd->new = usb_buffer_alloc(dev, 8, GFP_ATOMIC, &kbd->new_dma)))
2006db3dfefSJiri Kosina 		return -1;
2016db3dfefSJiri Kosina 	if (!(kbd->cr = usb_buffer_alloc(dev, sizeof(struct usb_ctrlrequest), GFP_ATOMIC, &kbd->cr_dma)))
2026db3dfefSJiri Kosina 		return -1;
2036db3dfefSJiri Kosina 	if (!(kbd->leds = usb_buffer_alloc(dev, 1, GFP_ATOMIC, &kbd->leds_dma)))
2046db3dfefSJiri Kosina 		return -1;
2056db3dfefSJiri Kosina 
2066db3dfefSJiri Kosina 	return 0;
2076db3dfefSJiri Kosina }
2086db3dfefSJiri Kosina 
2096db3dfefSJiri Kosina static void usb_kbd_free_mem(struct usb_device *dev, struct usb_kbd *kbd)
2106db3dfefSJiri Kosina {
2116db3dfefSJiri Kosina 	usb_free_urb(kbd->irq);
2126db3dfefSJiri Kosina 	usb_free_urb(kbd->led);
2136db3dfefSJiri Kosina 	usb_buffer_free(dev, 8, kbd->new, kbd->new_dma);
2146db3dfefSJiri Kosina 	usb_buffer_free(dev, sizeof(struct usb_ctrlrequest), kbd->cr, kbd->cr_dma);
2156db3dfefSJiri Kosina 	usb_buffer_free(dev, 1, kbd->leds, kbd->leds_dma);
2166db3dfefSJiri Kosina }
2176db3dfefSJiri Kosina 
2186db3dfefSJiri Kosina static int usb_kbd_probe(struct usb_interface *iface,
2196db3dfefSJiri Kosina 			 const struct usb_device_id *id)
2206db3dfefSJiri Kosina {
2216db3dfefSJiri Kosina 	struct usb_device *dev = interface_to_usbdev(iface);
2226db3dfefSJiri Kosina 	struct usb_host_interface *interface;
2236db3dfefSJiri Kosina 	struct usb_endpoint_descriptor *endpoint;
2246db3dfefSJiri Kosina 	struct usb_kbd *kbd;
2256db3dfefSJiri Kosina 	struct input_dev *input_dev;
2266db3dfefSJiri Kosina 	int i, pipe, maxp;
2275d6341c6SDmitry Torokhov 	int error = -ENOMEM;
2286db3dfefSJiri Kosina 
2296db3dfefSJiri Kosina 	interface = iface->cur_altsetting;
2306db3dfefSJiri Kosina 
2316db3dfefSJiri Kosina 	if (interface->desc.bNumEndpoints != 1)
2326db3dfefSJiri Kosina 		return -ENODEV;
2336db3dfefSJiri Kosina 
2346db3dfefSJiri Kosina 	endpoint = &interface->endpoint[0].desc;
2356db3dfefSJiri Kosina 	if (!usb_endpoint_is_int_in(endpoint))
2366db3dfefSJiri Kosina 		return -ENODEV;
2376db3dfefSJiri Kosina 
238*b0e66824SJiri Kosina #ifdef CONFIG_USB_HID
2399f6b3727SPascal Terjan 	if (usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor),
2409f6b3727SPascal Terjan 				le16_to_cpu(dev->descriptor.idProduct))
2419f6b3727SPascal Terjan 			& HID_QUIRK_IGNORE) {
2429f6b3727SPascal Terjan 		return -ENODEV;
2439f6b3727SPascal Terjan 	}
244*b0e66824SJiri Kosina #endif
2459f6b3727SPascal Terjan 
2466db3dfefSJiri Kosina 	pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
2476db3dfefSJiri Kosina 	maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
2486db3dfefSJiri Kosina 
2496db3dfefSJiri Kosina 	kbd = kzalloc(sizeof(struct usb_kbd), GFP_KERNEL);
2506db3dfefSJiri Kosina 	input_dev = input_allocate_device();
2516db3dfefSJiri Kosina 	if (!kbd || !input_dev)
2526db3dfefSJiri Kosina 		goto fail1;
2536db3dfefSJiri Kosina 
2546db3dfefSJiri Kosina 	if (usb_kbd_alloc_mem(dev, kbd))
2556db3dfefSJiri Kosina 		goto fail2;
2566db3dfefSJiri Kosina 
2576db3dfefSJiri Kosina 	kbd->usbdev = dev;
2586db3dfefSJiri Kosina 	kbd->dev = input_dev;
2596db3dfefSJiri Kosina 
2606db3dfefSJiri Kosina 	if (dev->manufacturer)
2616db3dfefSJiri Kosina 		strlcpy(kbd->name, dev->manufacturer, sizeof(kbd->name));
2626db3dfefSJiri Kosina 
2636db3dfefSJiri Kosina 	if (dev->product) {
2646db3dfefSJiri Kosina 		if (dev->manufacturer)
2656db3dfefSJiri Kosina 			strlcat(kbd->name, " ", sizeof(kbd->name));
2666db3dfefSJiri Kosina 		strlcat(kbd->name, dev->product, sizeof(kbd->name));
2676db3dfefSJiri Kosina 	}
2686db3dfefSJiri Kosina 
2696db3dfefSJiri Kosina 	if (!strlen(kbd->name))
2706db3dfefSJiri Kosina 		snprintf(kbd->name, sizeof(kbd->name),
2716db3dfefSJiri Kosina 			 "USB HIDBP Keyboard %04x:%04x",
2726db3dfefSJiri Kosina 			 le16_to_cpu(dev->descriptor.idVendor),
2736db3dfefSJiri Kosina 			 le16_to_cpu(dev->descriptor.idProduct));
2746db3dfefSJiri Kosina 
2756db3dfefSJiri Kosina 	usb_make_path(dev, kbd->phys, sizeof(kbd->phys));
2766db3dfefSJiri Kosina 	strlcpy(kbd->phys, "/input0", sizeof(kbd->phys));
2776db3dfefSJiri Kosina 
2786db3dfefSJiri Kosina 	input_dev->name = kbd->name;
2796db3dfefSJiri Kosina 	input_dev->phys = kbd->phys;
2806db3dfefSJiri Kosina 	usb_to_input_id(dev, &input_dev->id);
281e0712985SDmitry Torokhov 	input_dev->dev.parent = &iface->dev;
282e0712985SDmitry Torokhov 
283e0712985SDmitry Torokhov 	input_set_drvdata(input_dev, kbd);
2846db3dfefSJiri Kosina 
2857b19ada2SJiri Slaby 	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_LED) |
2867b19ada2SJiri Slaby 		BIT_MASK(EV_REP);
2877b19ada2SJiri Slaby 	input_dev->ledbit[0] = BIT_MASK(LED_NUML) | BIT_MASK(LED_CAPSL) |
2887b19ada2SJiri Slaby 		BIT_MASK(LED_SCROLLL) | BIT_MASK(LED_COMPOSE) |
2897b19ada2SJiri Slaby 		BIT_MASK(LED_KANA);
2906db3dfefSJiri Kosina 
2916db3dfefSJiri Kosina 	for (i = 0; i < 255; i++)
2926db3dfefSJiri Kosina 		set_bit(usb_kbd_keycode[i], input_dev->keybit);
2936db3dfefSJiri Kosina 	clear_bit(0, input_dev->keybit);
2946db3dfefSJiri Kosina 
2956db3dfefSJiri Kosina 	input_dev->event = usb_kbd_event;
2966db3dfefSJiri Kosina 	input_dev->open = usb_kbd_open;
2976db3dfefSJiri Kosina 	input_dev->close = usb_kbd_close;
2986db3dfefSJiri Kosina 
2996db3dfefSJiri Kosina 	usb_fill_int_urb(kbd->irq, dev, pipe,
3006db3dfefSJiri Kosina 			 kbd->new, (maxp > 8 ? 8 : maxp),
3016db3dfefSJiri Kosina 			 usb_kbd_irq, kbd, endpoint->bInterval);
3026db3dfefSJiri Kosina 	kbd->irq->transfer_dma = kbd->new_dma;
3036db3dfefSJiri Kosina 	kbd->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
3046db3dfefSJiri Kosina 
3056db3dfefSJiri Kosina 	kbd->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE;
3066db3dfefSJiri Kosina 	kbd->cr->bRequest = 0x09;
3076db3dfefSJiri Kosina 	kbd->cr->wValue = cpu_to_le16(0x200);
3086db3dfefSJiri Kosina 	kbd->cr->wIndex = cpu_to_le16(interface->desc.bInterfaceNumber);
3096db3dfefSJiri Kosina 	kbd->cr->wLength = cpu_to_le16(1);
3106db3dfefSJiri Kosina 
3116db3dfefSJiri Kosina 	usb_fill_control_urb(kbd->led, dev, usb_sndctrlpipe(dev, 0),
3126db3dfefSJiri Kosina 			     (void *) kbd->cr, kbd->leds, 1,
3136db3dfefSJiri Kosina 			     usb_kbd_led, kbd);
3146db3dfefSJiri Kosina 	kbd->led->setup_dma = kbd->cr_dma;
3156db3dfefSJiri Kosina 	kbd->led->transfer_dma = kbd->leds_dma;
3166db3dfefSJiri Kosina 	kbd->led->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
3176db3dfefSJiri Kosina 
3185d6341c6SDmitry Torokhov 	error = input_register_device(kbd->dev);
3195d6341c6SDmitry Torokhov 	if (error)
3205d6341c6SDmitry Torokhov 		goto fail2;
3216db3dfefSJiri Kosina 
3226db3dfefSJiri Kosina 	usb_set_intfdata(iface, kbd);
3236db3dfefSJiri Kosina 	return 0;
3246db3dfefSJiri Kosina 
3255d6341c6SDmitry Torokhov fail2:
3265d6341c6SDmitry Torokhov 	usb_kbd_free_mem(dev, kbd);
3275d6341c6SDmitry Torokhov fail1:
3285d6341c6SDmitry Torokhov 	input_free_device(input_dev);
3296db3dfefSJiri Kosina 	kfree(kbd);
3305d6341c6SDmitry Torokhov 	return error;
3316db3dfefSJiri Kosina }
3326db3dfefSJiri Kosina 
3336db3dfefSJiri Kosina static void usb_kbd_disconnect(struct usb_interface *intf)
3346db3dfefSJiri Kosina {
3356db3dfefSJiri Kosina 	struct usb_kbd *kbd = usb_get_intfdata (intf);
3366db3dfefSJiri Kosina 
3376db3dfefSJiri Kosina 	usb_set_intfdata(intf, NULL);
3386db3dfefSJiri Kosina 	if (kbd) {
3396db3dfefSJiri Kosina 		usb_kill_urb(kbd->irq);
3406db3dfefSJiri Kosina 		input_unregister_device(kbd->dev);
3416db3dfefSJiri Kosina 		usb_kbd_free_mem(interface_to_usbdev(intf), kbd);
3426db3dfefSJiri Kosina 		kfree(kbd);
3436db3dfefSJiri Kosina 	}
3446db3dfefSJiri Kosina }
3456db3dfefSJiri Kosina 
3466db3dfefSJiri Kosina static struct usb_device_id usb_kbd_id_table [] = {
3476db3dfefSJiri Kosina 	{ USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID, USB_INTERFACE_SUBCLASS_BOOT,
3486db3dfefSJiri Kosina 		USB_INTERFACE_PROTOCOL_KEYBOARD) },
3496db3dfefSJiri Kosina 	{ }						/* Terminating entry */
3506db3dfefSJiri Kosina };
3516db3dfefSJiri Kosina 
3526db3dfefSJiri Kosina MODULE_DEVICE_TABLE (usb, usb_kbd_id_table);
3536db3dfefSJiri Kosina 
3546db3dfefSJiri Kosina static struct usb_driver usb_kbd_driver = {
3556db3dfefSJiri Kosina 	.name =		"usbkbd",
3566db3dfefSJiri Kosina 	.probe =	usb_kbd_probe,
3576db3dfefSJiri Kosina 	.disconnect =	usb_kbd_disconnect,
3586db3dfefSJiri Kosina 	.id_table =	usb_kbd_id_table,
3596db3dfefSJiri Kosina };
3606db3dfefSJiri Kosina 
3616db3dfefSJiri Kosina static int __init usb_kbd_init(void)
3626db3dfefSJiri Kosina {
3636db3dfefSJiri Kosina 	int result = usb_register(&usb_kbd_driver);
3646db3dfefSJiri Kosina 	if (result == 0)
3656db3dfefSJiri Kosina 		info(DRIVER_VERSION ":" DRIVER_DESC);
3666db3dfefSJiri Kosina 	return result;
3676db3dfefSJiri Kosina }
3686db3dfefSJiri Kosina 
3696db3dfefSJiri Kosina static void __exit usb_kbd_exit(void)
3706db3dfefSJiri Kosina {
3716db3dfefSJiri Kosina 	usb_deregister(&usb_kbd_driver);
3726db3dfefSJiri Kosina }
3736db3dfefSJiri Kosina 
3746db3dfefSJiri Kosina module_init(usb_kbd_init);
3756db3dfefSJiri Kosina module_exit(usb_kbd_exit);
376