summaryrefslogtreecommitdiff
path: root/firmware/usb.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/usb.c')
-rw-r--r--firmware/usb.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/firmware/usb.c b/firmware/usb.c
index 10a7ae1bff..a1e552a321 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -416,9 +416,11 @@ static void usb_thread(void)
416#ifdef USB_STATUS_BY_EVENT 416#ifdef USB_STATUS_BY_EVENT
417void usb_status_event(int current_status) 417void usb_status_event(int current_status)
418{ 418{
419 /* Status should be USB_POWERED, USB_UNPOWERED, USB_INSERTED or 419 /* Caller isn't expected to filter for changes in status.
420 * USB_EXTRACTED. 420 * current_status:
421 * Caller isn't expected to filter for changes in status. */ 421 * USB_DETECT_BY_DRV: USB_POWERED, USB_UNPOWERED, USB_INSERTED (driver)
422 * else: USB_INSERTED, USB_EXTRACTED
423 */
422 if(usb_monitor_enabled) 424 if(usb_monitor_enabled)
423 { 425 {
424 int oldstatus = disable_irq_save(); /* Dual-use function */ 426 int oldstatus = disable_irq_save(); /* Dual-use function */
@@ -435,16 +437,30 @@ void usb_status_event(int current_status)
435 437
436void usb_start_monitoring(void) 438void usb_start_monitoring(void)
437{ 439{
440 int oldstatus = disable_irq_save(); /* Sync to event */
438 int status = usb_detect(); 441 int status = usb_detect();
442
443 usb_monitor_enabled = true;
444
439#ifdef USB_DETECT_BY_DRV 445#ifdef USB_DETECT_BY_DRV
440 /* USB detection begins by USB_POWERED, not USB_INSERTED. If it is 446 status = (status == USB_INSERTED) ? USB_POWERED : USB_UNPOWERED;
441 * USB_EXTRACTED, then nothing changes and post will be skipped. */
442 if(USB_INSERTED == status)
443 status = USB_POWERED;
444#endif 447#endif
445 usb_monitor_enabled = true;
446 usb_status_event(status); 448 usb_status_event(status);
449
450#ifdef USB_FIREWIRE_HANDLING
451 if (firewire_detect())
452 usb_firewire_connect_event();
453#endif
454
455 restore_irq(oldstatus);
447} 456}
457
458#ifdef USB_FIREWIRE_HANDLING
459void usb_firewire_connect_event(void)
460{
461 queue_post(&usb_queue, USB_REQUEST_REBOOT, 0);
462}
463#endif /* USB_FIREWIRE_HANDLING */
448#else /* !USB_STATUS_BY_EVENT */ 464#else /* !USB_STATUS_BY_EVENT */
449static void usb_tick(void) 465static void usb_tick(void)
450{ 466{
@@ -522,7 +538,11 @@ void usb_init(void)
522{ 538{
523 /* We assume that the USB cable is extracted */ 539 /* We assume that the USB cable is extracted */
524 usb_state = USB_EXTRACTED; 540 usb_state = USB_EXTRACTED;
541#ifdef USB_DETECT_BY_DRV
542 last_usb_status = USB_UNPOWERED;
543#else
525 last_usb_status = USB_EXTRACTED; 544 last_usb_status = USB_EXTRACTED;
545#endif
526 usb_monitor_enabled = false; 546 usb_monitor_enabled = false;
527 547
528#ifdef HAVE_USBSTACK 548#ifdef HAVE_USBSTACK