diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/export/usb.h | 14 | ||||
-rw-r--r-- | firmware/target/arm/as3525/usb-as3525.c | 6 | ||||
-rw-r--r-- | firmware/target/arm/imx233/usb-imx233.c | 6 | ||||
-rw-r--r-- | firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c | 6 | ||||
-rw-r--r-- | firmware/target/arm/usb-fw-pp502x.c | 4 | ||||
-rw-r--r-- | firmware/usb.c | 151 |
6 files changed, 83 insertions, 104 deletions
diff --git a/firmware/export/usb.h b/firmware/export/usb.h index d68ac7d910..3baacc5420 100644 --- a/firmware/export/usb.h +++ b/firmware/export/usb.h | |||
@@ -30,15 +30,16 @@ | |||
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | /* Messages from usb_tick and thread states */ | 32 | /* Messages from usb_tick and thread states */ |
33 | enum { | 33 | enum |
34 | { | ||
35 | #ifdef HAVE_LCD_BITMAP | ||
36 | USB_SCREENDUMP = -1, /* State */ | ||
37 | #endif | ||
34 | USB_EXTRACTED = 0, /* Event+State */ | 38 | USB_EXTRACTED = 0, /* Event+State */ |
35 | USB_INSERTED, /* Event+State */ | 39 | USB_INSERTED, /* Event+State */ |
36 | USB_POWERED, /* Event+State - transitional indicator if no power */ | 40 | USB_POWERED, /* State - transitional indicator if no power */ |
37 | #ifdef USB_DETECT_BY_CORE | 41 | #ifdef USB_DETECT_BY_CORE |
38 | USB_UNPOWERED, /* Event */ | 42 | USB_HOSTED, /* Event - host presence was detected */ |
39 | #endif | ||
40 | #ifdef HAVE_LCD_BITMAP | ||
41 | USB_SCREENDUMP, /* State */ | ||
42 | #endif | 43 | #endif |
43 | #if (CONFIG_STORAGE & STORAGE_MMC) | 44 | #if (CONFIG_STORAGE & STORAGE_MMC) |
44 | USB_REENABLE, /* Event */ | 45 | USB_REENABLE, /* Event */ |
@@ -57,6 +58,7 @@ enum { | |||
57 | USB_HANDLED, /* Bootloader status code */ | 58 | USB_HANDLED, /* Bootloader status code */ |
58 | #endif | 59 | #endif |
59 | }; | 60 | }; |
61 | |||
60 | #ifdef HAVE_USB_POWER | 62 | #ifdef HAVE_USB_POWER |
61 | #if CONFIG_KEYPAD == RECORDER_PAD | 63 | #if CONFIG_KEYPAD == RECORDER_PAD |
62 | #define USBPOWER_BUTTON BUTTON_F1 | 64 | #define USBPOWER_BUTTON BUTTON_F1 |
diff --git a/firmware/target/arm/as3525/usb-as3525.c b/firmware/target/arm/as3525/usb-as3525.c index 6ff235dfce..6c39150c28 100644 --- a/firmware/target/arm/as3525/usb-as3525.c +++ b/firmware/target/arm/as3525/usb-as3525.c | |||
@@ -46,7 +46,7 @@ void usb_insert_int(void) | |||
46 | { | 46 | { |
47 | usb_status = USB_INSERTED; | 47 | usb_status = USB_INSERTED; |
48 | #ifdef USB_STATUS_BY_EVENT | 48 | #ifdef USB_STATUS_BY_EVENT |
49 | usb_status_event(USB_POWERED); | 49 | usb_status_event(USB_INSERTED); |
50 | #endif | 50 | #endif |
51 | } | 51 | } |
52 | 52 | ||
@@ -54,7 +54,7 @@ void usb_remove_int(void) | |||
54 | { | 54 | { |
55 | usb_status = USB_EXTRACTED; | 55 | usb_status = USB_EXTRACTED; |
56 | #ifdef USB_STATUS_BY_EVENT | 56 | #ifdef USB_STATUS_BY_EVENT |
57 | usb_status_event(USB_UNPOWERED); | 57 | usb_status_event(USB_EXTRACTED); |
58 | #endif | 58 | #endif |
59 | } | 59 | } |
60 | 60 | ||
@@ -68,7 +68,7 @@ void usb_drv_usb_detect_event(void) | |||
68 | int oldstatus = disable_irq_save(); /* May come via USB thread */ | 68 | int oldstatus = disable_irq_save(); /* May come via USB thread */ |
69 | 69 | ||
70 | if (usb_status == USB_INSERTED) | 70 | if (usb_status == USB_INSERTED) |
71 | usb_status_event(USB_INSERTED); | 71 | usb_status_event(USB_HOSTED); |
72 | 72 | ||
73 | restore_irq(oldstatus); | 73 | restore_irq(oldstatus); |
74 | #endif | 74 | #endif |
diff --git a/firmware/target/arm/imx233/usb-imx233.c b/firmware/target/arm/imx233/usb-imx233.c index c275f76916..91fb770190 100644 --- a/firmware/target/arm/imx233/usb-imx233.c +++ b/firmware/target/arm/imx233/usb-imx233.c | |||
@@ -33,17 +33,17 @@ | |||
33 | 33 | ||
34 | void usb_insert_int(void) | 34 | void usb_insert_int(void) |
35 | { | 35 | { |
36 | usb_status_event(USB_POWERED); | 36 | usb_status_event(USB_INSERTED); |
37 | } | 37 | } |
38 | 38 | ||
39 | void usb_remove_int(void) | 39 | void usb_remove_int(void) |
40 | { | 40 | { |
41 | usb_status_event(USB_UNPOWERED); | 41 | usb_status_event(USB_EXTRACTED); |
42 | } | 42 | } |
43 | 43 | ||
44 | void usb_drv_usb_detect_event() | 44 | void usb_drv_usb_detect_event() |
45 | { | 45 | { |
46 | usb_status_event(USB_INSERTED); | 46 | usb_status_event(USB_HOSTED); |
47 | } | 47 | } |
48 | 48 | ||
49 | void usb_attach(void) | 49 | void usb_attach(void) |
diff --git a/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c index c52a9a6dec..19c3b3173f 100644 --- a/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c +++ b/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c | |||
@@ -66,7 +66,7 @@ void usb_connect_event(void) | |||
66 | usb_status = status; | 66 | usb_status = status; |
67 | /* Notify power that USB charging is potentially available */ | 67 | /* Notify power that USB charging is potentially available */ |
68 | charger_usb_detect_event(status); | 68 | charger_usb_detect_event(status); |
69 | usb_status_event((status == USB_INSERTED) ? USB_POWERED : USB_UNPOWERED); | 69 | usb_status_event(status); |
70 | } | 70 | } |
71 | 71 | ||
72 | int usb_detect(void) | 72 | int usb_detect(void) |
@@ -138,11 +138,11 @@ void usb_drv_int_enable(bool enable) | |||
138 | } | 138 | } |
139 | } | 139 | } |
140 | 140 | ||
141 | /* Called during the bus reset interrupt when in detect mode */ | 141 | /* Called during the setup packet request by the host */ |
142 | void usb_drv_usb_detect_event(void) | 142 | void usb_drv_usb_detect_event(void) |
143 | { | 143 | { |
144 | if (usb_drv_powered()) | 144 | if (usb_drv_powered()) |
145 | usb_status_event(USB_INSERTED); | 145 | usb_status_event(USB_HOSTED); |
146 | } | 146 | } |
147 | 147 | ||
148 | /* Called when reading the MBR */ | 148 | /* Called when reading the MBR */ |
diff --git a/firmware/target/arm/usb-fw-pp502x.c b/firmware/target/arm/usb-fw-pp502x.c index f1d250d3ec..2ba537f286 100644 --- a/firmware/target/arm/usb-fw-pp502x.c +++ b/firmware/target/arm/usb-fw-pp502x.c | |||
@@ -212,7 +212,7 @@ static int usb_status = USB_EXTRACTED; | |||
212 | 212 | ||
213 | static int usb_timeout_event(struct timeout *tmo) | 213 | static int usb_timeout_event(struct timeout *tmo) |
214 | { | 214 | { |
215 | usb_status_event(tmo->data == USB_GPIO_VAL ? USB_POWERED : USB_UNPOWERED); | 215 | usb_status_event(tmo->data == USB_GPIO_VAL ? USB_INSERTED : USB_EXTRACTED); |
216 | return 0; | 216 | return 0; |
217 | } | 217 | } |
218 | 218 | ||
@@ -231,7 +231,7 @@ void usb_drv_usb_detect_event(void) | |||
231 | { | 231 | { |
232 | /* Filter for invalid bus reset when unplugging by checking the pin state. */ | 232 | /* Filter for invalid bus reset when unplugging by checking the pin state. */ |
233 | if(usb_plugged()) { | 233 | if(usb_plugged()) { |
234 | usb_status_event(USB_INSERTED); | 234 | usb_status_event(USB_HOSTED); |
235 | } | 235 | } |
236 | } | 236 | } |
237 | #endif /* USB_STATUS_BY_EVENT */ | 237 | #endif /* USB_STATUS_BY_EVENT */ |
diff --git a/firmware/usb.c b/firmware/usb.c index c7326c548b..ec81ba6f58 100644 --- a/firmware/usb.c +++ b/firmware/usb.c | |||
@@ -110,29 +110,46 @@ static void try_reboot(void) | |||
110 | } | 110 | } |
111 | #endif /* USB_FIRWIRE_HANDLING || (HAVE_USBSTACK && !USE_ROCKBOX_USB) */ | 111 | #endif /* USB_FIRWIRE_HANDLING || (HAVE_USBSTACK && !USE_ROCKBOX_USB) */ |
112 | 112 | ||
113 | 113 | /* Screen dump */ | |
114 | #ifdef HAVE_LCD_BITMAP | ||
115 | static inline bool usb_do_screendump(void) | 114 | static inline bool usb_do_screendump(void) |
116 | { | 115 | { |
116 | #ifdef HAVE_LCD_BITMAP | ||
117 | if(do_screendump_instead_of_usb) | 117 | if(do_screendump_instead_of_usb) |
118 | { | 118 | { |
119 | usb_state = USB_SCREENDUMP; | 119 | usb_state = USB_SCREENDUMP; |
120 | screen_dump(); | 120 | screen_dump(); |
121 | #ifdef HAVE_REMOTE_LCD | 121 | #ifdef HAVE_REMOTE_LCD |
122 | remote_screen_dump(); | 122 | remote_screen_dump(); |
123 | #endif | 123 | #endif /* HAVE_REMOTE_LCD */ |
124 | return true; | 124 | return true; |
125 | } | 125 | } |
126 | #endif /* HAVE_LCD_BITMAP */ | ||
127 | return false; | ||
128 | } | ||
126 | 129 | ||
130 | /* Power (charging-only) button */ | ||
131 | static inline bool usb_power_button(void) | ||
132 | { | ||
133 | #ifdef HAVE_USB_POWER | ||
134 | return (button_status() & ~USBPOWER_BTN_IGNORE); | ||
135 | #else | ||
127 | return false; | 136 | return false; |
137 | #endif | ||
128 | } | 138 | } |
129 | #else /* !HAVE_LCD_BITMAP */ | 139 | |
130 | static inline bool usb_do_screendump(void) | 140 | #ifdef USB_FIREWIRE_HANDLING |
141 | static inline bool usb_reboot_button(void) | ||
131 | { | 142 | { |
143 | #ifdef HAVE_USB_POWER | ||
144 | return (button_status() & ~USBPOWER_BTN_IGNORE); | ||
145 | #else | ||
132 | return false; | 146 | return false; |
147 | #endif | ||
133 | } | 148 | } |
134 | #endif /* HAVE_LCD_BITMAP */ | 149 | #endif /* USB_FIREWIRE_HANDLING */ |
150 | |||
135 | 151 | ||
152 | /*--- Routines that differ depending upon the presence of a USB stack ---*/ | ||
136 | 153 | ||
137 | #ifdef HAVE_USBSTACK | 154 | #ifdef HAVE_USBSTACK |
138 | /* Enable / disable USB when the stack is enabled - otherwise a noop */ | 155 | /* Enable / disable USB when the stack is enabled - otherwise a noop */ |
@@ -241,12 +258,10 @@ static inline void usb_slave_mode(bool on) | |||
241 | #else /* !USE_ROCKBOX_USB */ | 258 | #else /* !USE_ROCKBOX_USB */ |
242 | static inline void usb_slave_mode(bool on) | 259 | static inline void usb_slave_mode(bool on) |
243 | { | 260 | { |
261 | /* Until we have native mass-storage mode, we want to reboot on USB host | ||
262 | * connect */ | ||
244 | if(on) | 263 | if(on) |
245 | { | ||
246 | /* until we have native mass-storage mode, we want to reboot on | ||
247 | usb host connect */ | ||
248 | try_reboot(); | 264 | try_reboot(); |
249 | } | ||
250 | } | 265 | } |
251 | #endif /* USE_ROCKBOX_USB */ | 266 | #endif /* USE_ROCKBOX_USB */ |
252 | 267 | ||
@@ -343,68 +358,34 @@ static inline void usb_slave_mode(bool on) | |||
343 | } | 358 | } |
344 | #endif /* HAVE_USBSTACK */ | 359 | #endif /* HAVE_USBSTACK */ |
345 | 360 | ||
346 | #ifdef HAVE_USB_POWER | ||
347 | static inline bool usb_power_button(void) | ||
348 | { | ||
349 | return (button_status() & ~USBPOWER_BTN_IGNORE); | ||
350 | } | ||
351 | 361 | ||
352 | #ifdef USB_FIREWIRE_HANDLING | 362 | /*--- General driver code ---*/ |
353 | static inline bool usb_reboot_button(void) | 363 | static void NORETURN_ATTR usb_thread(void) |
354 | { | 364 | { |
355 | return (button_status() & ~USBPOWER_BTN_IGNORE); | ||
356 | } | ||
357 | #endif | ||
358 | #else /* !HAVE_USB_POWER */ | ||
359 | static inline bool usb_power_button(void) | ||
360 | { | ||
361 | return false; | ||
362 | } | ||
363 | |||
364 | #ifdef USB_FIREWIRE_HANDLING | ||
365 | static inline bool usb_reboot_button(void) | ||
366 | { | ||
367 | return false; | ||
368 | } | ||
369 | #endif | ||
370 | #endif /* HAVE_USB_POWER */ | ||
371 | |||
372 | #ifndef USB_DRIVER_CLOSE | ||
373 | static void usb_thread(void) NORETURN_ATTR; | ||
374 | #endif | ||
375 | static void usb_thread(void) | ||
376 | { | ||
377 | #ifdef USB_DETECT_BY_CORE | ||
378 | bool host_detected = false; | ||
379 | #endif | ||
380 | int num_acks_to_expect = 0; | 365 | int num_acks_to_expect = 0; |
381 | long last_broadcast_tick = current_tick; | 366 | long last_broadcast_tick = current_tick; |
367 | bool host_detected = false; | ||
382 | struct queue_event ev; | 368 | struct queue_event ev; |
383 | 369 | ||
384 | while(1) | 370 | while(1) |
385 | { | 371 | { |
386 | queue_wait(&usb_queue, &ev); | 372 | queue_wait(&usb_queue, &ev); |
373 | |||
387 | switch(ev.id) | 374 | switch(ev.id) |
388 | { | 375 | { |
389 | /*** Main USB thread duties ***/ | 376 | /*** Main USB thread duties ***/ |
390 | 377 | ||
391 | #ifdef HAVE_USBSTACK | 378 | #ifdef HAVE_USBSTACK |
392 | case USB_TRANSFER_COMPLETION: | 379 | case USB_TRANSFER_COMPLETION: |
380 | if(usb_state <= USB_EXTRACTED) | ||
381 | break; | ||
382 | |||
393 | usb_core_handle_transfer_completion( | 383 | usb_core_handle_transfer_completion( |
394 | (struct usb_transfer_completion_event_data*)ev.data); | 384 | (struct usb_transfer_completion_event_data*)ev.data); |
395 | break; | 385 | break; |
396 | #endif /* HAVE_USBSTACK */ | 386 | #endif /* HAVE_USBSTACK */ |
397 | 387 | ||
398 | case USB_INSERTED: | 388 | case USB_INSERTED: |
399 | #ifdef USB_DETECT_BY_CORE | ||
400 | if(usb_state != USB_POWERED) | ||
401 | break; | ||
402 | |||
403 | if (host_detected) | ||
404 | break; /* Drivers configured but we're still USB_POWERED */ | ||
405 | |||
406 | host_detected = true; | ||
407 | #else /* !USB_DETECT_BY_CORE */ | ||
408 | if(usb_state != USB_EXTRACTED) | 389 | if(usb_state != USB_EXTRACTED) |
409 | break; | 390 | break; |
410 | 391 | ||
@@ -413,8 +394,21 @@ static void usb_thread(void) | |||
413 | 394 | ||
414 | usb_state = USB_POWERED; | 395 | usb_state = USB_POWERED; |
415 | usb_stack_enable(true); | 396 | usb_stack_enable(true); |
397 | |||
398 | #ifdef USB_DETECT_BY_CORE | ||
399 | /* Wait for USB core to detect the host */ | ||
400 | break; | ||
401 | |||
402 | case USB_HOSTED: | ||
403 | if(usb_state != USB_POWERED) | ||
404 | break; | ||
416 | #endif /* USB_DETECT_BY_CORE */ | 405 | #endif /* USB_DETECT_BY_CORE */ |
417 | 406 | ||
407 | if(host_detected) | ||
408 | break; | ||
409 | |||
410 | host_detected = true; | ||
411 | |||
418 | if(usb_power_button()) | 412 | if(usb_power_button()) |
419 | { | 413 | { |
420 | /* Only charging is desired */ | 414 | /* Only charging is desired */ |
@@ -440,19 +434,18 @@ static void usb_thread(void) | |||
440 | } | 434 | } |
441 | 435 | ||
442 | num_acks_to_expect += queue_broadcast(SYS_USB_CONNECTED, 0) - 1; | 436 | num_acks_to_expect += queue_broadcast(SYS_USB_CONNECTED, 0) - 1; |
443 | DEBUGF("USB inserted. Waiting for %d acks...\n", | 437 | DEBUGF("usb: waiting for %d acks...\n", num_acks_to_expect); |
444 | num_acks_to_expect); | ||
445 | 438 | ||
446 | /* Leave the state as USB_POWERED until the expected number of | 439 | /* Leave the state as USB_POWERED until the expected number of |
447 | ACKS are received. */ | 440 | ACKS are received. */ |
448 | break; | 441 | break; |
449 | /* USB_INSERTED: */ | 442 | /* USB_INSERTED: or USB_HOSTED: */ |
450 | 443 | ||
451 | case SYS_USB_CONNECTED_ACK: | 444 | case SYS_USB_CONNECTED_ACK: |
452 | if(num_acks_to_expect > 0 && --num_acks_to_expect == 0) | 445 | if(num_acks_to_expect > 0 && --num_acks_to_expect == 0) |
453 | { | 446 | { |
454 | DEBUGF("All threads have acknowledged the connect.\n"); | 447 | DEBUGF("usb: all threads have acknowledged the connect.\n"); |
455 | if(usb_state == USB_POWERED) | 448 | if(host_detected) |
456 | { | 449 | { |
457 | usb_slave_mode(true); | 450 | usb_slave_mode(true); |
458 | usb_state = USB_INSERTED; | 451 | usb_state = USB_INSERTED; |
@@ -460,29 +453,11 @@ static void usb_thread(void) | |||
460 | } | 453 | } |
461 | else | 454 | else |
462 | { | 455 | { |
463 | DEBUGF("usb: got ack, %d to go...\n", | 456 | DEBUGF("usb: got ack, %d to go...\n", num_acks_to_expect); |
464 | num_acks_to_expect); | ||
465 | } | 457 | } |
466 | break; | 458 | break; |
467 | /* SYS_USB_CONNECTED_ACK */ | 459 | /* SYS_USB_CONNECTED_ACK */ |
468 | 460 | ||
469 | #ifdef USB_DETECT_BY_CORE | ||
470 | /* In this case, these events handle cable insertion. USB driver or | ||
471 | core determines USB_INSERTED. */ | ||
472 | case USB_POWERED: | ||
473 | if(usb_state != USB_EXTRACTED) | ||
474 | break; | ||
475 | |||
476 | if(usb_do_screendump()) | ||
477 | break; | ||
478 | |||
479 | usb_state = USB_POWERED; | ||
480 | usb_stack_enable(true); | ||
481 | break; | ||
482 | /* USB_POWERED: */ | ||
483 | |||
484 | case USB_UNPOWERED: | ||
485 | #endif /* USB_DETECT_BY_CORE */ | ||
486 | case USB_EXTRACTED: | 461 | case USB_EXTRACTED: |
487 | if(usb_state == USB_EXTRACTED) | 462 | if(usb_state == USB_EXTRACTED) |
488 | break; | 463 | break; |
@@ -497,13 +472,15 @@ static void usb_thread(void) | |||
497 | 472 | ||
498 | usb_state = USB_EXTRACTED; | 473 | usb_state = USB_EXTRACTED; |
499 | 474 | ||
500 | /* Ok to broadcast disconnect now */ | 475 | if(host_detected) |
501 | usb_configure_drivers(USB_EXTRACTED); | 476 | { |
502 | #ifdef USB_DETECT_BY_CORE | 477 | /* Ok to broadcast disconnect now */ |
503 | host_detected = false; | 478 | usb_configure_drivers(USB_EXTRACTED); |
504 | #endif | 479 | host_detected = false; |
480 | } | ||
481 | |||
505 | break; | 482 | break; |
506 | /* USB_UNPOWERED: USB_EXTRACTED: */ | 483 | /* USB_EXTRACTED: */ |
507 | 484 | ||
508 | /*** Miscellaneous USB thread duties ***/ | 485 | /*** Miscellaneous USB thread duties ***/ |
509 | 486 | ||
@@ -536,7 +513,8 @@ static void usb_thread(void) | |||
536 | /* CLOSE */ | 513 | /* CLOSE */ |
537 | #ifdef USB_DRIVER_CLOSE | 514 | #ifdef USB_DRIVER_CLOSE |
538 | case USB_QUIT: | 515 | case USB_QUIT: |
539 | return; | 516 | thread_exit(); |
517 | break; | ||
540 | #endif | 518 | #endif |
541 | } /* switch */ | 519 | } /* switch */ |
542 | } /* while */ | 520 | } /* while */ |
@@ -554,9 +532,8 @@ void usb_status_event(int current_status) | |||
554 | { | 532 | { |
555 | /* Caller isn't expected to filter for changes in status. | 533 | /* Caller isn't expected to filter for changes in status. |
556 | * current_status: | 534 | * current_status: |
557 | * USB_DETECT_BY_CORE: USB_POWERED, USB_UNPOWERED, | 535 | * all: USB_INSERTED, USB_EXTRACTED |
558 | USB_INSERTED (core) | 536 | * USB_DETECT_BY_CORE: USB_HOSTED (from core) |
559 | * else: USB_INSERTED, USB_EXTRACTED | ||
560 | */ | 537 | */ |
561 | if(usb_monitor_enabled) | 538 | if(usb_monitor_enabled) |
562 | { | 539 | { |
@@ -578,8 +555,8 @@ void usb_start_monitoring(void) | |||
578 | * was enabled due to the connector already having been inserted before | 555 | * was enabled due to the connector already having been inserted before |
579 | * before or during boot. */ | 556 | * before or during boot. */ |
580 | #ifdef USB_DETECT_BY_CORE | 557 | #ifdef USB_DETECT_BY_CORE |
581 | /* Filter the status - USB_INSERTED may happen later */ | 558 | /* Filter the status - USB_HOSTED may happen later */ |
582 | status = (status == USB_EXTRACTED) ? USB_UNPOWERED : USB_POWERED; | 559 | status = (status == USB_INSERTED) ? : USB_EXTRACTED; |
583 | #endif | 560 | #endif |
584 | usb_status_event(status); | 561 | usb_status_event(status); |
585 | 562 | ||