usbkbd.c (42f06a13445bffae96c5e42fdd721ef65fed6abf) | usbkbd.c (c196adf87514560f867492978ae350d4bbced0bd) |
---|---|
1/* 2 * Copyright (c) 1999-2001 Vojtech Pavlik 3 * 4 * USB HIDBP Keyboard support 5 */ 6 7/* 8 * This program is free software; you can redistribute it and/or modify --- 50 unchanged lines hidden (view full) --- 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 65}; 66 | 1/* 2 * Copyright (c) 1999-2001 Vojtech Pavlik 3 * 4 * USB HIDBP Keyboard support 5 */ 6 7/* 8 * This program is free software; you can redistribute it and/or modify --- 50 unchanged lines hidden (view full) --- 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 65}; 66 |
67 68/** 69 * struct usb_kbd - state of each attached keyboard 70 * @dev: input device associated with this keyboard 71 * @usbdev: usb device associated with this keyboard 72 * @old: data received in the past from the @irq URB representing which 73 * keys were pressed. By comparing with the current list of keys 74 * that are pressed, we are able to see key releases. 75 * @irq: URB for receiving a list of keys that are pressed when a 76 * new key is pressed or a key that was pressed is released. 77 * @led: URB for sending LEDs (e.g. numlock, ...) 78 * @newleds: data that will be sent with the @led URB representing which LEDs 79 should be on 80 * @name: Name of the keyboard. @dev's name field points to this buffer 81 * @phys: Physical path of the keyboard. @dev's phys field points to this 82 * buffer 83 * @new: Buffer for the @irq URB 84 * @cr: Control request for @led URB 85 * @leds: Buffer for the @led URB 86 * @new_dma: DMA address for @irq URB 87 * @leds_dma: DMA address for @led URB 88 * @leds_lock: spinlock that protects @leds, @newleds, and @led_urb_submitted 89 * @led_urb_submitted: indicates whether @led is in progress, i.e. it has been 90 * submitted and its completion handler has not returned yet 91 * without resubmitting @led 92 */ |
|
67struct usb_kbd { 68 struct input_dev *dev; 69 struct usb_device *usbdev; 70 unsigned char old[8]; 71 struct urb *irq, *led; 72 unsigned char newleds; 73 char name[128]; 74 char phys[64]; 75 76 unsigned char *new; 77 struct usb_ctrlrequest *cr; 78 unsigned char *leds; 79 dma_addr_t new_dma; 80 dma_addr_t leds_dma; | 93struct usb_kbd { 94 struct input_dev *dev; 95 struct usb_device *usbdev; 96 unsigned char old[8]; 97 struct urb *irq, *led; 98 unsigned char newleds; 99 char name[128]; 100 char phys[64]; 101 102 unsigned char *new; 103 struct usb_ctrlrequest *cr; 104 unsigned char *leds; 105 dma_addr_t new_dma; 106 dma_addr_t leds_dma; |
107 108 spinlock_t leds_lock; 109 bool led_urb_submitted; 110 |
|
81}; 82 83static void usb_kbd_irq(struct urb *urb) 84{ 85 struct usb_kbd *kbd = urb->context; 86 int i; 87 88 switch (urb->status) { --- 42 unchanged lines hidden (view full) --- 131 hid_err(urb->dev, "can't resubmit intr, %s-%s/input0, status %d", 132 kbd->usbdev->bus->bus_name, 133 kbd->usbdev->devpath, i); 134} 135 136static int usb_kbd_event(struct input_dev *dev, unsigned int type, 137 unsigned int code, int value) 138{ | 111}; 112 113static void usb_kbd_irq(struct urb *urb) 114{ 115 struct usb_kbd *kbd = urb->context; 116 int i; 117 118 switch (urb->status) { --- 42 unchanged lines hidden (view full) --- 161 hid_err(urb->dev, "can't resubmit intr, %s-%s/input0, status %d", 162 kbd->usbdev->bus->bus_name, 163 kbd->usbdev->devpath, i); 164} 165 166static int usb_kbd_event(struct input_dev *dev, unsigned int type, 167 unsigned int code, int value) 168{ |
169 unsigned long flags; |
|
139 struct usb_kbd *kbd = input_get_drvdata(dev); 140 141 if (type != EV_LED) 142 return -1; 143 | 170 struct usb_kbd *kbd = input_get_drvdata(dev); 171 172 if (type != EV_LED) 173 return -1; 174 |
175 spin_lock_irqsave(&kbd->leds_lock, flags); |
|
144 kbd->newleds = (!!test_bit(LED_KANA, dev->led) << 3) | (!!test_bit(LED_COMPOSE, dev->led) << 3) | 145 (!!test_bit(LED_SCROLLL, dev->led) << 2) | (!!test_bit(LED_CAPSL, dev->led) << 1) | 146 (!!test_bit(LED_NUML, dev->led)); 147 | 176 kbd->newleds = (!!test_bit(LED_KANA, dev->led) << 3) | (!!test_bit(LED_COMPOSE, dev->led) << 3) | 177 (!!test_bit(LED_SCROLLL, dev->led) << 2) | (!!test_bit(LED_CAPSL, dev->led) << 1) | 178 (!!test_bit(LED_NUML, dev->led)); 179 |
148 if (kbd->led->status == -EINPROGRESS) | 180 if (kbd->led_urb_submitted){ 181 spin_unlock_irqrestore(&kbd->leds_lock, flags); |
149 return 0; | 182 return 0; |
183 } |
|
150 | 184 |
151 if (*(kbd->leds) == kbd->newleds) | 185 if (*(kbd->leds) == kbd->newleds){ 186 spin_unlock_irqrestore(&kbd->leds_lock, flags); |
152 return 0; | 187 return 0; |
188 } |
|
153 154 *(kbd->leds) = kbd->newleds; | 189 190 *(kbd->leds) = kbd->newleds; |
191 |
|
155 kbd->led->dev = kbd->usbdev; 156 if (usb_submit_urb(kbd->led, GFP_ATOMIC)) 157 pr_err("usb_submit_urb(leds) failed\n"); | 192 kbd->led->dev = kbd->usbdev; 193 if (usb_submit_urb(kbd->led, GFP_ATOMIC)) 194 pr_err("usb_submit_urb(leds) failed\n"); |
158 | 195 else 196 kbd->led_urb_submitted = true; 197 198 spin_unlock_irqrestore(&kbd->leds_lock, flags); 199 |
159 return 0; 160} 161 162static void usb_kbd_led(struct urb *urb) 163{ | 200 return 0; 201} 202 203static void usb_kbd_led(struct urb *urb) 204{ |
205 unsigned long flags; |
|
164 struct usb_kbd *kbd = urb->context; 165 166 if (urb->status) 167 hid_warn(urb->dev, "led urb status %d received\n", 168 urb->status); 169 | 206 struct usb_kbd *kbd = urb->context; 207 208 if (urb->status) 209 hid_warn(urb->dev, "led urb status %d received\n", 210 urb->status); 211 |
170 if (*(kbd->leds) == kbd->newleds) | 212 spin_lock_irqsave(&kbd->leds_lock, flags); 213 214 if (*(kbd->leds) == kbd->newleds){ 215 kbd->led_urb_submitted = false; 216 spin_unlock_irqrestore(&kbd->leds_lock, flags); |
171 return; | 217 return; |
218 } |
|
172 173 *(kbd->leds) = kbd->newleds; | 219 220 *(kbd->leds) = kbd->newleds; |
221 |
|
174 kbd->led->dev = kbd->usbdev; | 222 kbd->led->dev = kbd->usbdev; |
175 if (usb_submit_urb(kbd->led, GFP_ATOMIC)) | 223 if (usb_submit_urb(kbd->led, GFP_ATOMIC)){ |
176 hid_err(urb->dev, "usb_submit_urb(leds) failed\n"); | 224 hid_err(urb->dev, "usb_submit_urb(leds) failed\n"); |
225 kbd->led_urb_submitted = false; 226 } 227 spin_unlock_irqrestore(&kbd->leds_lock, flags); 228 |
|
177} 178 179static int usb_kbd_open(struct input_dev *dev) 180{ 181 struct usb_kbd *kbd = input_get_drvdata(dev); 182 183 kbd->irq->dev = kbd->usbdev; 184 if (usb_submit_urb(kbd->irq, GFP_KERNEL)) --- 62 unchanged lines hidden (view full) --- 247 if (!kbd || !input_dev) 248 goto fail1; 249 250 if (usb_kbd_alloc_mem(dev, kbd)) 251 goto fail2; 252 253 kbd->usbdev = dev; 254 kbd->dev = input_dev; | 229} 230 231static int usb_kbd_open(struct input_dev *dev) 232{ 233 struct usb_kbd *kbd = input_get_drvdata(dev); 234 235 kbd->irq->dev = kbd->usbdev; 236 if (usb_submit_urb(kbd->irq, GFP_KERNEL)) --- 62 unchanged lines hidden (view full) --- 299 if (!kbd || !input_dev) 300 goto fail1; 301 302 if (usb_kbd_alloc_mem(dev, kbd)) 303 goto fail2; 304 305 kbd->usbdev = dev; 306 kbd->dev = input_dev; |
307 spin_lock_init(&kbd->leds_lock); |
|
255 256 if (dev->manufacturer) 257 strlcpy(kbd->name, dev->manufacturer, sizeof(kbd->name)); 258 259 if (dev->product) { 260 if (dev->manufacturer) 261 strlcat(kbd->name, " ", sizeof(kbd->name)); 262 strlcat(kbd->name, dev->product, sizeof(kbd->name)); --- 86 unchanged lines hidden (view full) --- 349 350static struct usb_driver usb_kbd_driver = { 351 .name = "usbkbd", 352 .probe = usb_kbd_probe, 353 .disconnect = usb_kbd_disconnect, 354 .id_table = usb_kbd_id_table, 355}; 356 | 308 309 if (dev->manufacturer) 310 strlcpy(kbd->name, dev->manufacturer, sizeof(kbd->name)); 311 312 if (dev->product) { 313 if (dev->manufacturer) 314 strlcat(kbd->name, " ", sizeof(kbd->name)); 315 strlcat(kbd->name, dev->product, sizeof(kbd->name)); --- 86 unchanged lines hidden (view full) --- 402 403static struct usb_driver usb_kbd_driver = { 404 .name = "usbkbd", 405 .probe = usb_kbd_probe, 406 .disconnect = usb_kbd_disconnect, 407 .id_table = usb_kbd_id_table, 408}; 409 |
357module_usb_driver(usb_kbd_driver); | 410static int __init usb_kbd_init(void) 411{ 412 int result = usb_register(&usb_kbd_driver); 413 if (result == 0) 414 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" 415 DRIVER_DESC "\n"); 416 return result; 417} 418 419static void __exit usb_kbd_exit(void) 420{ 421 usb_deregister(&usb_kbd_driver); 422} 423 424module_init(usb_kbd_init); 425module_exit(usb_kbd_exit); |