Commit 8f8d7d2451115059c36e0551eea9d8770c346ea2
Committed by
Marek Vasut
1 parent
88274b6c43
Exists in
v2017.01-smarct4x
and in
37 other branches
usb: kbd: Cache pipe, interval and packetsize
Instead of looking them up every time we need them. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Showing 1 changed file with 13 additions and 21 deletions Side-by-side Diff
common/usb_kbd.c
... | ... | @@ -99,6 +99,10 @@ |
99 | 99 | #define USB_KBD_BOOT_REPORT_SIZE 8 |
100 | 100 | |
101 | 101 | struct usb_kbd_pdata { |
102 | + unsigned long intpipe; | |
103 | + int intpktsize; | |
104 | + int intinterval; | |
105 | + | |
102 | 106 | uint32_t repeat_delay; |
103 | 107 | |
104 | 108 | uint32_t usb_in_pointer; |
105 | 109 | |
106 | 110 | |
... | ... | @@ -305,23 +309,11 @@ |
305 | 309 | static inline void usb_kbd_poll_for_event(struct usb_device *dev) |
306 | 310 | { |
307 | 311 | #if defined(CONFIG_SYS_USB_EVENT_POLL) |
308 | - struct usb_interface *iface; | |
309 | - struct usb_endpoint_descriptor *ep; | |
310 | - struct usb_kbd_pdata *data; | |
311 | - int pipe; | |
312 | - int maxp; | |
312 | + struct usb_kbd_pdata *data = dev->privptr; | |
313 | 313 | |
314 | - /* Get the pointer to USB Keyboard device pointer */ | |
315 | - data = dev->privptr; | |
316 | - iface = &dev->config.if_desc[0]; | |
317 | - ep = &iface->ep_desc[0]; | |
318 | - pipe = usb_rcvintpipe(dev, ep->bEndpointAddress); | |
319 | - | |
320 | 314 | /* Submit a interrupt transfer request */ |
321 | - maxp = usb_maxpacket(dev, pipe); | |
322 | - usb_submit_int_msg(dev, pipe, &data->new[0], | |
323 | - min(maxp, USB_KBD_BOOT_REPORT_SIZE), | |
324 | - ep->bInterval); | |
315 | + usb_submit_int_msg(dev, data->intpipe, &data->new[0], data->intpktsize, | |
316 | + data->intinterval); | |
325 | 317 | |
326 | 318 | usb_kbd_irq_worker(dev); |
327 | 319 | #elif defined(CONFIG_SYS_USB_EVENT_POLL_VIA_CONTROL_EP) |
... | ... | @@ -389,7 +381,6 @@ |
389 | 381 | struct usb_interface *iface; |
390 | 382 | struct usb_endpoint_descriptor *ep; |
391 | 383 | struct usb_kbd_pdata *data; |
392 | - int pipe, maxp; | |
393 | 384 | |
394 | 385 | if (dev->descriptor.bNumConfigurations != 1) |
395 | 386 | return 0; |
... | ... | @@ -438,8 +429,10 @@ |
438 | 429 | /* Set IRQ handler */ |
439 | 430 | dev->irq_handle = usb_kbd_irq; |
440 | 431 | |
441 | - pipe = usb_rcvintpipe(dev, ep->bEndpointAddress); | |
442 | - maxp = usb_maxpacket(dev, pipe); | |
432 | + data->intpipe = usb_rcvintpipe(dev, ep->bEndpointAddress); | |
433 | + data->intpktsize = min(usb_maxpacket(dev, data->intpipe), | |
434 | + USB_KBD_BOOT_REPORT_SIZE); | |
435 | + data->intinterval = ep->bInterval; | |
443 | 436 | |
444 | 437 | /* We found a USB Keyboard, install it. */ |
445 | 438 | usb_set_protocol(dev, iface->desc.bInterfaceNumber, 0); |
... | ... | @@ -448,9 +441,8 @@ |
448 | 441 | usb_set_idle(dev, iface->desc.bInterfaceNumber, REPEAT_RATE, 0); |
449 | 442 | |
450 | 443 | debug("USB KBD: enable interrupt pipe...\n"); |
451 | - if (usb_submit_int_msg(dev, pipe, data->new, | |
452 | - min(maxp, USB_KBD_BOOT_REPORT_SIZE), | |
453 | - ep->bInterval) < 0) { | |
444 | + if (usb_submit_int_msg(dev, data->intpipe, data->new, data->intpktsize, | |
445 | + data->intinterval) < 0) { | |
454 | 446 | printf("Failed to get keyboard state from device %04x:%04x\n", |
455 | 447 | dev->descriptor.idVendor, dev->descriptor.idProduct); |
456 | 448 | /* Abort, we don't want to use that non-functional keyboard. */ |