summaryrefslogtreecommitdiff
path: root/firmware/usbstack/usb_core.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/usbstack/usb_core.c')
-rw-r--r--firmware/usbstack/usb_core.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c
index ea5d6590f6..50c9d8589c 100644
--- a/firmware/usbstack/usb_core.c
+++ b/firmware/usbstack/usb_core.c
@@ -54,6 +54,9 @@
54#include "ata.h" 54#include "ata.h"
55#endif 55#endif
56 56
57#ifndef USB_MAX_CURRENT
58#define USB_MAX_CURRENT 500
59#endif
57 60
58/*-------------------------------------------------------------------------*/ 61/*-------------------------------------------------------------------------*/
59/* USB protocol descriptors: */ 62/* USB protocol descriptors: */
@@ -94,7 +97,7 @@ static struct usb_config_descriptor __attribute__((aligned(2)))
94 .bConfigurationValue = 1, 97 .bConfigurationValue = 1,
95 .iConfiguration = 0, 98 .iConfiguration = 0,
96 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, 99 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
97 .bMaxPower = 250, /* 500mA in 2mA units */ 100 .bMaxPower = (USB_MAX_CURRENT+1) / 2, /* In 2mA units */
98}; 101};
99 102
100 103
@@ -179,7 +182,7 @@ static struct usb_class_driver drivers[USB_NUM_DRIVERS] =
179#ifdef USB_STORAGE 182#ifdef USB_STORAGE
180 [USB_DRIVER_MASS_STORAGE] = { 183 [USB_DRIVER_MASS_STORAGE] = {
181 .enabled = false, 184 .enabled = false,
182 .needs_exclusive_ata = true, 185 .needs_exclusive_storage = true,
183 .first_interface = 0, 186 .first_interface = 0,
184 .last_interface = 0, 187 .last_interface = 0,
185 .request_endpoints = usb_storage_request_endpoints, 188 .request_endpoints = usb_storage_request_endpoints,
@@ -198,7 +201,7 @@ static struct usb_class_driver drivers[USB_NUM_DRIVERS] =
198#ifdef USB_SERIAL 201#ifdef USB_SERIAL
199 [USB_DRIVER_SERIAL] = { 202 [USB_DRIVER_SERIAL] = {
200 .enabled = false, 203 .enabled = false,
201 .needs_exclusive_ata = false, 204 .needs_exclusive_storage = false,
202 .first_interface = 0, 205 .first_interface = 0,
203 .last_interface = 0, 206 .last_interface = 0,
204 .request_endpoints = usb_serial_request_endpoints, 207 .request_endpoints = usb_serial_request_endpoints,
@@ -217,7 +220,7 @@ static struct usb_class_driver drivers[USB_NUM_DRIVERS] =
217#ifdef USB_CHARGING_ONLY 220#ifdef USB_CHARGING_ONLY
218 [USB_DRIVER_CHARGING_ONLY] = { 221 [USB_DRIVER_CHARGING_ONLY] = {
219 .enabled = false, 222 .enabled = false,
220 .needs_exclusive_ata = false, 223 .needs_exclusive_storage = false,
221 .first_interface = 0, 224 .first_interface = 0,
222 .last_interface = 0, 225 .last_interface = 0,
223 .request_endpoints = usb_charging_only_request_endpoints, 226 .request_endpoints = usb_charging_only_request_endpoints,
@@ -353,13 +356,17 @@ void usb_core_exit(void)
353 int i; 356 int i;
354 for(i=0;i<USB_NUM_DRIVERS;i++) { 357 for(i=0;i<USB_NUM_DRIVERS;i++) {
355 if(drivers[i].enabled && drivers[i].disconnect != NULL) 358 if(drivers[i].enabled && drivers[i].disconnect != NULL)
359 {
356 drivers[i].disconnect (); 360 drivers[i].disconnect ();
361 drivers[i].enabled = false;
362 }
357 } 363 }
358 364
359 if (initialized) { 365 if (initialized) {
360 usb_drv_exit(); 366 usb_drv_exit();
361 } 367 }
362 initialized = false; 368 initialized = false;
369 usb_state = DEFAULT;
363 logf("usb_core_exit() finished"); 370 logf("usb_core_exit() finished");
364} 371}
365 372
@@ -392,6 +399,20 @@ bool usb_core_driver_enabled(int driver)
392 return drivers[driver].enabled; 399 return drivers[driver].enabled;
393} 400}
394 401
402bool usb_core_any_exclusive_storage(void)
403{
404 int i;
405 for(i=0;i<USB_NUM_DRIVERS;i++) {
406 if(drivers[i].enabled &&
407 drivers[i].needs_exclusive_storage)
408 {
409 return true;
410 }
411 }
412
413 return false;
414}
415
395#ifdef HAVE_HOTSWAP 416#ifdef HAVE_HOTSWAP
396void usb_core_hotswap_event(int volume,bool inserted) 417void usb_core_hotswap_event(int volume,bool inserted)
397{ 418{
@@ -484,14 +505,6 @@ static void usb_core_control_request_handler(struct usb_ctrlrequest* req)
484 usb_core_set_serial_function_id(); 505 usb_core_set_serial_function_id();
485 506
486 allocate_interfaces_and_endpoints(); 507 allocate_interfaces_and_endpoints();
487
488 for(i=0;i<USB_NUM_DRIVERS;i++) {
489 if(drivers[i].enabled &&
490 drivers[i].needs_exclusive_ata) {
491 usb_request_exclusive_ata();
492 break;
493 }
494 }
495 } 508 }
496 509
497 switch(req->bRequestType & 0x1f) { 510 switch(req->bRequestType & 0x1f) {
@@ -788,7 +801,7 @@ unsigned short usb_allowed_current()
788{ 801{
789 if (usb_state == CONFIGURED) 802 if (usb_state == CONFIGURED)
790 { 803 {
791 return 500; 804 return MAX(USB_MAX_CURRENT, 100);
792 } 805 }
793 else 806 else
794 { 807 {