summaryrefslogtreecommitdiff
path: root/firmware/usbstack
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2009-01-13 16:27:35 +0000
committerMichael Sevakis <jethead71@rockbox.org>2009-01-13 16:27:35 +0000
commit6da8b4eb4925f167588c868a64d2d057ca3bf85f (patch)
tree1441169e97f7ece3422a49e51dc512c8be0b31ae /firmware/usbstack
parent30414d56c9f8b4fc35ac2918c4d22e5e2ded0eb6 (diff)
downloadrockbox-6da8b4eb4925f167588c868a64d2d057ca3bf85f.tar.gz
rockbox-6da8b4eb4925f167588c868a64d2d057ca3bf85f.zip
USB retweaking: Take out the USB_REQUEST/RELEASE_DISK scheme and simply ask the USB core whether or not any drivers require exclusive access at the moment of connect. Doing anthing else just produces nasty effects on Windows because it expects some communication just for enabling the PHY and not allowing it to mount volumes if a thread doesn't ack causes annoying error message boxes. Make behavior of each USB type identical from the system perspective. Some miscellaneous changes (simplify, ata->storage naming, define only used USB_* enums values were possible).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19762 a1c6a512-1295-4272-9138-f99709370657
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 8bdf58ff1d..839e07dae4 100644
--- a/firmware/usbstack/usb_charging_only.h
+++ b/firmware/usbstack/usb_charging_only.h
@@ -5,7 +5,7 @@
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id: $ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2008 by Frank Gevaerts 10 * Copyright (C) 2008 by Frank Gevaerts
11 * 11 *
diff --git a/firmware/usbstack/usb_class_driver.h b/firmware/usbstack/usb_class_driver.h
index e089c488a8..b037e1dec2 100644
--- a/firmware/usbstack/usb_class_driver.h
+++ b/firmware/usbstack/usb_class_driver.h
@@ -33,7 +33,7 @@ struct usb_class_driver {
33 /* Driver api starts here */ 33 /* Driver api starts here */
34 34
35 /* Set this to true if the driver needs exclusive disk access (e.g. usb storage) */ 35 /* Set this to true if the driver needs exclusive disk access (e.g. usb storage) */
36 bool needs_exclusive_ata; 36 bool needs_exclusive_storage;
37 37
38 /* Let the driver request endpoints it need. Returns zero on success */ 38 /* Let the driver request endpoints it need. Returns zero on success */
39 int (*request_endpoints)(struct usb_class_driver *); 39 int (*request_endpoints)(struct usb_class_driver *);
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 {
diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c
index 8a4915123c..a70681d3e0 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))
293#endif 293#endif
294} 294}
295 295
296#if 0
296static void try_release_ata(void) 297static void try_release_ata(void)
297{ 298{
298 /* Check if there is a connected drive left. If not, 299 /* Check if there is a connected drive left. If not,
@@ -310,6 +311,7 @@ static void try_release_ata(void)
310 usb_release_exclusive_ata(); 311 usb_release_exclusive_ata();
311 } 312 }
312} 313}
314#endif
313 315
314#ifdef HAVE_HOTSWAP 316#ifdef HAVE_HOTSWAP
315void usb_storage_notify_hotswap(int volume,bool inserted) 317void usb_storage_notify_hotswap(int volume,bool inserted)
@@ -320,9 +322,7 @@ void usb_storage_notify_hotswap(int volume,bool inserted)
320 } 322 }
321 else { 323 else {
322 ejected[volume] = true; 324 ejected[volume] = true;
323 try_release_ata();
324 } 325 }
325
326} 326}
327#endif 327#endif
328 328
@@ -334,7 +334,6 @@ void usb_storage_reconnect(void)
334 for(i=0;i<NUM_VOLUMES;i++) 334 for(i=0;i<NUM_VOLUMES;i++)
335 ejected[i] = !check_disk_present(IF_MV(i)); 335 ejected[i] = !check_disk_present(IF_MV(i));
336 logf("%s", __func__); 336 logf("%s", __func__);
337 usb_request_exclusive_ata();
338 } 337 }
339} 338}
340 339
@@ -682,7 +681,6 @@ static void handle_scsi(struct command_block_wrapper* cbw)
682#ifdef HAVE_HOTSWAP 681#ifdef HAVE_HOTSWAP
683 if(storage_removable(lun) && !storage_present(lun)) { 682 if(storage_removable(lun) && !storage_present(lun)) {
684 ejected[lun] = true; 683 ejected[lun] = true;
685 try_release_ata();
686 } 684 }
687#endif 685#endif
688 686
@@ -699,7 +697,7 @@ static void handle_scsi(struct command_block_wrapper* cbw)
699 switch (cbw->command_block[0]) { 697 switch (cbw->command_block[0]) {
700 case SCSI_TEST_UNIT_READY: 698 case SCSI_TEST_UNIT_READY:
701 logf("scsi test_unit_ready %d",lun); 699 logf("scsi test_unit_ready %d",lun);
702 if(!usb_exclusive_ata()) { 700 if(!usb_exclusive_storage()) {
703 send_csw(UMS_STATUS_FAIL); 701 send_csw(UMS_STATUS_FAIL);
704 cur_sense_data.sense_key=SENSE_NOT_READY; 702 cur_sense_data.sense_key=SENSE_NOT_READY;
705 cur_sense_data.asc=ASC_MEDIUM_NOT_PRESENT; 703 cur_sense_data.asc=ASC_MEDIUM_NOT_PRESENT;
@@ -885,7 +883,6 @@ static void handle_scsi(struct command_block_wrapper* cbw)
885 { 883 {
886 logf("scsi eject"); 884 logf("scsi eject");
887 ejected[lun]=true; 885 ejected[lun]=true;
888 try_release_ata();
889 } 886 }
890 } 887 }
891 } 888 }