summaryrefslogtreecommitdiff
path: root/firmware/usbstack
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/usbstack')
-rw-r--r--firmware/usbstack/usb_charging_only.h2
-rw-r--r--firmware/usbstack/usb_class_driver.h2
-rw-r--r--firmware/usbstack/usb_core.c39
-rw-r--r--firmware/usbstack/usb_storage.c9
4 files changed, 31 insertions, 21 deletions
diff --git a/firmware/usbstack/usb_charging_only.h b/firmware/usbstack/usb_charging_only.h
index 8bdf58f..839e07d 100644
--- a/firmware/usbstack/usb_charging_only.h
+++ b/firmware/usbstack/usb_charging_only.h
@@ -5,7 +5,7 @@
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
- * $Id: $
+ * $Id$
*
* Copyright (C) 2008 by Frank Gevaerts
*
diff --git a/firmware/usbstack/usb_class_driver.h b/firmware/usbstack/usb_class_driver.h
index e089c48..b037e1d 100644
--- a/firmware/usbstack/usb_class_driver.h
+++ b/firmware/usbstack/usb_class_driver.h
@@ -33,7 +33,7 @@ struct usb_class_driver {
/* Driver api starts here */
/* Set this to true if the driver needs exclusive disk access (e.g. usb storage) */
- bool needs_exclusive_ata;
+ bool needs_exclusive_storage;
/* Let the driver request endpoints it need. Returns zero on success */
int (*request_endpoints)(struct usb_class_driver *);
diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c
index ea5d659..50c9d85 100644
--- a/firmware/usbstack/usb_core.c
+++ b/firmware/usbstack/usb_core.c
@@ -54,6 +54,9 @@
#include "ata.h"
#endif
+#ifndef USB_MAX_CURRENT
+#define USB_MAX_CURRENT 500
+#endif
/*-------------------------------------------------------------------------*/
/* USB protocol descriptors: */
@@ -94,7 +97,7 @@ static struct usb_config_descriptor __attribute__((aligned(2)))
.bConfigurationValue = 1,
.iConfiguration = 0,
.bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
- .bMaxPower = 250, /* 500mA in 2mA units */
+ .bMaxPower = (USB_MAX_CURRENT+1) / 2, /* In 2mA units */
};
@@ -179,7 +182,7 @@ static struct usb_class_driver drivers[USB_NUM_DRIVERS] =
#ifdef USB_STORAGE
[USB_DRIVER_MASS_STORAGE] = {
.enabled = false,
- .needs_exclusive_ata = true,
+ .needs_exclusive_storage = true,
.first_interface = 0,
.last_interface = 0,
.request_endpoints = usb_storage_request_endpoints,
@@ -198,7 +201,7 @@ static struct usb_class_driver drivers[USB_NUM_DRIVERS] =
#ifdef USB_SERIAL
[USB_DRIVER_SERIAL] = {
.enabled = false,
- .needs_exclusive_ata = false,
+ .needs_exclusive_storage = false,
.first_interface = 0,
.last_interface = 0,
.request_endpoints = usb_serial_request_endpoints,
@@ -217,7 +220,7 @@ static struct usb_class_driver drivers[USB_NUM_DRIVERS] =
#ifdef USB_CHARGING_ONLY
[USB_DRIVER_CHARGING_ONLY] = {
.enabled = false,
- .needs_exclusive_ata = false,
+ .needs_exclusive_storage = false,
.first_interface = 0,
.last_interface = 0,
.request_endpoints = usb_charging_only_request_endpoints,
@@ -353,13 +356,17 @@ void usb_core_exit(void)
int i;
for(i=0;i<USB_NUM_DRIVERS;i++) {
if(drivers[i].enabled && drivers[i].disconnect != NULL)
+ {
drivers[i].disconnect ();
+ drivers[i].enabled = false;
+ }
}
if (initialized) {
usb_drv_exit();
}
initialized = false;
+ usb_state = DEFAULT;
logf("usb_core_exit() finished");
}
@@ -392,6 +399,20 @@ bool usb_core_driver_enabled(int driver)
return drivers[driver].enabled;
}
+bool usb_core_any_exclusive_storage(void)
+{
+ int i;
+ for(i=0;i<USB_NUM_DRIVERS;i++) {
+ if(drivers[i].enabled &&
+ drivers[i].needs_exclusive_storage)
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
#ifdef HAVE_HOTSWAP
void usb_core_hotswap_event(int volume,bool inserted)
{
@@ -484,14 +505,6 @@ static void usb_core_control_request_handler(struct usb_ctrlrequest* req)
usb_core_set_serial_function_id();
allocate_interfaces_and_endpoints();
-
- for(i=0;i<USB_NUM_DRIVERS;i++) {
- if(drivers[i].enabled &&
- drivers[i].needs_exclusive_ata) {
- usb_request_exclusive_ata();
- break;
- }
- }
}
switch(req->bRequestType & 0x1f) {
@@ -788,7 +801,7 @@ unsigned short usb_allowed_current()
{
if (usb_state == CONFIGURED)
{
- return 500;
+ return MAX(USB_MAX_CURRENT, 100);
}
else
{
diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c
index 8a49151..a70681d 100644
--- a/firmware/usbstack/usb_storage.c
+++ b/firmware/usbstack/usb_storage.c
@@ -293,6 +293,7 @@ static bool check_disk_present(IF_MV_NONVOID(int volume))
#endif
}
+#if 0
static void try_release_ata(void)
{
/* Check if there is a connected drive left. If not,
@@ -310,6 +311,7 @@ static void try_release_ata(void)
usb_release_exclusive_ata();
}
}
+#endif
#ifdef HAVE_HOTSWAP
void usb_storage_notify_hotswap(int volume,bool inserted)
@@ -320,9 +322,7 @@ void usb_storage_notify_hotswap(int volume,bool inserted)
}
else {
ejected[volume] = true;
- try_release_ata();
}
-
}
#endif
@@ -334,7 +334,6 @@ void usb_storage_reconnect(void)
for(i=0;i<NUM_VOLUMES;i++)
ejected[i] = !check_disk_present(IF_MV(i));
logf("%s", __func__);
- usb_request_exclusive_ata();
}
}
@@ -682,7 +681,6 @@ static void handle_scsi(struct command_block_wrapper* cbw)
#ifdef HAVE_HOTSWAP
if(storage_removable(lun) && !storage_present(lun)) {
ejected[lun] = true;
- try_release_ata();
}
#endif
@@ -699,7 +697,7 @@ static void handle_scsi(struct command_block_wrapper* cbw)
switch (cbw->command_block[0]) {
case SCSI_TEST_UNIT_READY:
logf("scsi test_unit_ready %d",lun);
- if(!usb_exclusive_ata()) {
+ if(!usb_exclusive_storage()) {
send_csw(UMS_STATUS_FAIL);
cur_sense_data.sense_key=SENSE_NOT_READY;
cur_sense_data.asc=ASC_MEDIUM_NOT_PRESENT;
@@ -885,7 +883,6 @@ static void handle_scsi(struct command_block_wrapper* cbw)
{
logf("scsi eject");
ejected[lun]=true;
- try_release_ata();
}
}
}