A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+245 -245
+2 -2
apps/debug_menu.c
··· 2575 2575 } 2576 2576 #endif 2577 2577 2578 - #if defined(HAVE_USBSTACK) && defined(USB_STORAGE) 2578 + #if 0 && defined(HAVE_USBSTACK) && defined(USB_STORAGE) 2579 2579 static bool usb_reconnect(void) 2580 2580 { 2581 2581 splash(HZ, "Reconnect mass storage"); ··· 2720 2720 #if defined(HAVE_USBSTACK) && defined(ROCKBOX_HAS_LOGF) && defined(USB_SERIAL) 2721 2721 {"logf over usb",logf_usb_serial }, 2722 2722 #endif 2723 - #if defined(HAVE_USBSTACK) && defined(USB_STORAGE) 2723 + #if 0 && defined(HAVE_USBSTACK) && defined(USB_STORAGE) 2724 2724 {"reconnect usb storage",usb_reconnect}, 2725 2725 #endif 2726 2726 #ifdef CPU_BOOST_LOGGING
+22 -13
firmware/drivers/ata.c
··· 61 61 #define CMD_SET_FEATURES 0xEF 62 62 #define CMD_SECURITY_FREEZE_LOCK 0xF5 63 63 64 - #define Q_SLEEP 0 65 - #define Q_CLOSE 1 64 + /* Should all be < 0x100 (which are reserved for control messages) */ 65 + #define Q_SLEEP 0 66 + #define Q_CLOSE 1 66 67 67 68 #define READ_TIMEOUT 5*HZ 68 69 ··· 143 144 #define mutex_unlock ata_lock_unlock 144 145 #endif /* MAX_PHYS_SECTOR_SIZE */ 145 146 146 - #if defined(HAVE_USBSTACK) && defined(USE_ROCKBOX_USB) && !defined(BOOTLOADER) 147 + #if defined(HAVE_USBSTACK) && defined(USE_ROCKBOX_USB) 147 148 #define ALLOW_USB_SPINDOWN 148 149 #endif 149 150 ··· 164 165 #endif 165 166 static long ata_stack[(DEFAULT_STACK_SIZE*3)/sizeof(long)]; 166 167 static const char ata_thread_name[] = "ata"; 167 - static struct event_queue ata_queue; 168 + static struct event_queue ata_queue SHAREDBSS_ATTR; 168 169 static bool initialized = false; 169 170 170 171 static long last_user_activity = -1; ··· 910 911 #ifdef ALLOW_USB_SPINDOWN 911 912 if(!usb_mode) 912 913 #endif 914 + { 913 915 call_storage_idle_notifys(false); 916 + } 914 917 last_seen_mtx_unlock = 0; 915 918 } 916 919 } ··· 923 926 #ifdef ALLOW_USB_SPINDOWN 924 927 if(!usb_mode) 925 928 #endif 929 + { 926 930 call_storage_idle_notifys(true); 931 + } 927 932 ata_perform_sleep(); 928 933 last_sleep = current_tick; 929 934 } ··· 935 940 { 936 941 mutex_lock(&ata_mtx); 937 942 ide_power_enable(false); 938 - mutex_unlock(&ata_mtx); 939 943 poweroff = true; 944 + mutex_unlock(&ata_mtx); 940 945 } 941 946 #endif 942 947 break; 943 948 944 949 #ifndef USB_NONE 945 950 case SYS_USB_CONNECTED: 951 + /* Tell the USB thread that we are safe */ 952 + DEBUGF("ata_thread got SYS_USB_CONNECTED\n"); 953 + #ifdef ALLOW_USB_SPINDOWN 954 + usb_mode = true; 955 + usb_acknowledge(SYS_USB_CONNECTED_ACK); 956 + /* There is no need to force ATA power on */ 957 + #else 946 958 if (poweroff) { 947 959 mutex_lock(&ata_mtx); 948 960 ata_led(true); ··· 951 963 mutex_unlock(&ata_mtx); 952 964 } 953 965 954 - /* Tell the USB thread that we are safe */ 955 - DEBUGF("ata_thread got SYS_USB_CONNECTED\n"); 966 + /* Wait until the USB cable is extracted again */ 956 967 usb_acknowledge(SYS_USB_CONNECTED_ACK); 957 - 958 - #ifdef ALLOW_USB_SPINDOWN 959 - usb_mode = true; 960 - #else 961 - /* Wait until the USB cable is extracted again */ 962 968 usb_wait_for_disconnect(&ata_queue); 963 969 #endif 964 970 break; ··· 971 977 usb_mode = false; 972 978 break; 973 979 #endif 974 - #endif 980 + #endif /* USB_NONE */ 981 + 975 982 case Q_SLEEP: 976 983 #ifdef ALLOW_USB_SPINDOWN 977 984 if(!usb_mode) 978 985 #endif 986 + { 979 987 call_storage_idle_notifys(false); 988 + } 980 989 last_disk_activity = current_tick - sleep_timeout + (HZ/2); 981 990 break; 982 991
+25 -15
firmware/export/usb.h
··· 24 24 #include "kernel.h" 25 25 #include "button.h" 26 26 27 + #if defined(IPOD_COLOR) || defined(IPOD_4G) \ 28 + || defined(IPOD_MINI) || defined(IPOD_MINI2G) 29 + #define USB_FIREWIRE_HANDLING 30 + #endif 31 + 27 32 /* Messages from usb_tick and thread states */ 28 33 enum { 29 - USB_INSERTED, 30 - USB_EXTRACTED, 31 - USB_REENABLE, 32 - USB_POWERED, 33 - USB_TRANSFER_COMPLETION, 34 - USB_REQUEST_DISK, 35 - USB_RELEASE_DISK, 36 - USB_REQUEST_REBOOT, 37 - USB_QUIT, 34 + USB_INSERTED, /* Event+State */ 35 + USB_EXTRACTED, /* Event+State */ 36 + #ifdef HAVE_USB_POWER 37 + USB_POWERED, /* State */ 38 + #endif 39 + #ifdef HAVE_LCD_BITMAP 40 + USB_SCREENDUMP, /* State */ 41 + #endif 42 + #if (CONFIG_STORAGE & STORAGE_MMC) 43 + USB_REENABLE, /* Event */ 44 + #endif 45 + #ifdef HAVE_USBSTACK 46 + USB_TRANSFER_COMPLETION, /* Event */ 47 + #endif 48 + #ifdef USB_FIREWIRE_HANDLING 49 + USB_REQUEST_REBOOT, /* Event */ 50 + #endif 51 + USB_QUIT, /* Event */ 38 52 }; 39 - 40 53 41 54 #ifdef HAVE_USB_POWER 42 55 #if CONFIG_KEYPAD == RECORDER_PAD ··· 111 124 #ifdef HAVE_USBSTACK 112 125 void usb_signal_transfer_completion(struct usb_transfer_completion_event_data* event_data); 113 126 bool usb_driver_enabled(int driver); 114 - bool usb_exclusive_ata(void); /* ata is available for usb */ 115 - void usb_request_exclusive_ata(void); 116 - void usb_release_exclusive_ata(void); 127 + bool usb_exclusive_storage(void); /* storage is available for usb */ 117 128 #endif 118 129 119 - #if defined(IPOD_COLOR) || defined(IPOD_4G) \ 120 - || defined(IPOD_MINI) || defined(IPOD_MINI2G) 130 + #ifdef USB_FIREWIRE_HANDLING 121 131 bool firewire_detect(void); 122 132 #endif 123 133
+1 -1
firmware/export/usb_core.h
··· 52 52 void usb_core_control_request(struct usb_ctrlrequest* req); 53 53 void usb_core_transfer_complete(int endpoint, int dir, int status, int length); 54 54 void usb_core_bus_reset(void); 55 - bool usb_core_exclusive_connection(void); 55 + bool usb_core_any_exclusive_storage(void); 56 56 void usb_core_enable_driver(int driver,bool enabled); 57 57 bool usb_core_driver_enabled (int driver); 58 58 void usb_core_handle_transfer_completion(
+164 -193
firmware/usb.c
··· 79 79 static long usb_stack[(DEFAULT_STACK_SIZE + 0x800)/sizeof(long)]; 80 80 static const char usb_thread_name[] = "usb"; 81 81 static unsigned int usb_thread_entry = 0; 82 - #endif 82 + #endif /* USB_FULL_INIT */ 83 83 static struct event_queue usb_queue; 84 84 static int last_usb_status; 85 85 static bool usb_monitor_enabled; ··· 87 87 static bool exclusive_storage_access; 88 88 #endif 89 89 90 - 91 - #if defined(IPOD_COLOR) || defined(IPOD_4G) \ 92 - || defined(IPOD_MINI) || defined(IPOD_MINI2G) 90 + #ifdef USB_FIREWIRE_HANDLING 93 91 static int firewire_countdown; 94 92 static bool last_firewire_status; 95 93 #endif 96 94 97 95 #ifdef USB_FULL_INIT 98 - #ifndef HAVE_USBSTACK 99 - static void usb_slave_mode(bool on) 96 + 97 + #if defined(USB_FIREWIRE_HANDLING) \ 98 + || (defined(HAVE_USBSTACK) && !defined(USE_ROCKBOX_USB)) 99 + static void try_reboot(void) 100 + { 101 + #ifdef HAVE_DISK_STORAGE 102 + storage_sleepnow(); /* Immediately spindown the disk. */ 103 + sleep(HZ*2); 104 + #endif 105 + 106 + #ifdef IPOD_ARCH /* The following code is based on ipodlinux */ 107 + #if CONFIG_CPU == PP5020 108 + memcpy((void *)0x40017f00, "diskmode\0\0hotstuff\0\0\1", 21); 109 + #elif CONFIG_CPU == PP5022 110 + memcpy((void *)0x4001ff00, "diskmode\0\0hotstuff\0\0\1", 21); 111 + #endif /* CONFIG_CPU */ 112 + #endif /* IPOD_ARCH */ 113 + 114 + system_reboot(); /* Reboot */ 115 + } 116 + #endif /* USB_FIRWIRE_HANDLING || (HAVE_USBSTACK && !USE_ROCKBOX_USB) */ 117 + 118 + #ifdef HAVE_USBSTACK 119 + /* inline since branch is chosen at compile time */ 120 + static inline void usb_slave_mode(bool on) 121 + { 122 + #ifdef USE_ROCKBOX_USB 123 + int rc; 124 + 125 + if (on) 126 + { 127 + trigger_cpu_boost(); 128 + #ifdef HAVE_PRIORITY_SCHEDULING 129 + thread_set_priority(THREAD_ID_CURRENT, PRIORITY_REALTIME); 130 + #endif 131 + usb_enable(true); 132 + } 133 + else /* usb_state == USB_INSERTED (only!) */ 134 + { 135 + usb_enable(false); 136 + #ifdef HAVE_PRIORITY_SCHEDULING 137 + thread_set_priority(THREAD_ID_CURRENT, PRIORITY_SYSTEM); 138 + #endif 139 + /* Entered exclusive mode */ 140 + rc = disk_mount_all(); 141 + if (rc <= 0) /* no partition */ 142 + panicf("mount: %d",rc); 143 + 144 + cancel_cpu_boost(); 145 + } 146 + #else /* !USB_ROCKBOX_USB */ 147 + if (on) 148 + { 149 + /* until we have native mass-storage mode, we want to reboot on 150 + usb host connect */ 151 + try_reboot(); 152 + } 153 + #endif /* USE_ROCKBOX_USB */ 154 + } 155 + 156 + void usb_signal_transfer_completion( 157 + struct usb_transfer_completion_event_data* event_data) 158 + { 159 + queue_post(&usb_queue, USB_TRANSFER_COMPLETION, (intptr_t)event_data); 160 + } 161 + #else /* !HAVE_USBSTACK */ 162 + /* inline since branch is chosen at compile time */ 163 + static inline void usb_slave_mode(bool on) 100 164 { 101 165 int rc; 102 166 ··· 107 171 storage_init(); 108 172 storage_enable(false); 109 173 usb_enable(true); 174 + cpu_idle_mode(true); 110 175 } 111 176 else 112 177 { 113 178 DEBUGF("Leaving USB slave mode\n"); 179 + 180 + cpu_idle_mode(false); 114 181 115 182 /* Let the ISDx00 settle */ 116 183 sleep(HZ*1); ··· 126 193 panicf("mount: %d",rc); 127 194 } 128 195 } 129 - #endif 196 + #endif /* HAVE_USBSTACK */ 130 197 131 - static void try_reboot(void) 198 + #ifdef HAVE_USB_POWER 199 + static inline bool usb_power_button(void) 132 200 { 133 - #ifdef HAVE_DISK_STORAGE 134 - storage_sleepnow(); /* Immediately spindown the disk. */ 135 - sleep(HZ*2); 201 + #if defined(IRIVER_H10) || defined (IRIVER_H10_5GB) 202 + return (button_status() & ~USBPOWER_BTN_IGNORE) != USBPOWER_BUTTON; 203 + #else 204 + return (button_status() & ~USBPOWER_BTN_IGNORE) == USBPOWER_BUTTON; 136 205 #endif 206 + } 137 207 138 - #ifdef IPOD_ARCH /* The following code is based on ipodlinux */ 139 - #if CONFIG_CPU == PP5020 140 - memcpy((void *)0x40017f00, "diskmode\0\0hotstuff\0\0\1", 21); 141 - #elif CONFIG_CPU == PP5022 142 - memcpy((void *)0x4001ff00, "diskmode\0\0hotstuff\0\0\1", 21); 143 - #endif /* CONFIG_CPU */ 144 - #endif /* IPOD_ARCH */ 145 - 146 - system_reboot(); /* Reboot */ 208 + #ifdef USB_FIREWIRE_HANDLING 209 + static inline bool usb_reboot_button(void) 210 + { 211 + return (button_status() & ~USBPOWER_BTN_IGNORE) != USBPOWER_BUTTON; 147 212 } 213 + #endif 214 + #endif /* HAVE_USB_POWER */ 148 215 149 216 static void usb_thread(void) 150 217 { 151 - int num_acks_to_expect = -1; 152 - bool waiting_for_ack; 218 + int num_acks_to_expect = 0; 153 219 struct queue_event ev; 154 - 155 - waiting_for_ack = false; 156 220 157 221 while(1) 158 222 { ··· 165 229 #endif 166 230 #ifdef HAVE_USBSTACK 167 231 case USB_TRANSFER_COMPLETION: 168 - usb_core_handle_transfer_completion((struct usb_transfer_completion_event_data*)ev.data); 169 - break; 170 - #endif 171 - #ifdef HAVE_USB_POWER 172 - case USB_POWERED: 173 - usb_state = USB_POWERED; 232 + usb_core_handle_transfer_completion( 233 + (struct usb_transfer_completion_event_data*)ev.data); 174 234 break; 175 235 #endif 176 236 case USB_INSERTED: 177 237 #ifdef HAVE_LCD_BITMAP 178 238 if(do_screendump_instead_of_usb) 179 239 { 240 + usb_state = USB_SCREENDUMP; 180 241 screen_dump(); 242 + break; 181 243 } 182 - else 183 244 #endif 184 245 #ifdef HAVE_USB_POWER 185 - #if defined(IRIVER_H10) || defined (IRIVER_H10_5GB) 186 - if((button_status() & ~USBPOWER_BTN_IGNORE) != USBPOWER_BUTTON) 187 - #else 188 - if((button_status() & ~USBPOWER_BTN_IGNORE) == USBPOWER_BUTTON) 189 - #endif 246 + if (usb_power_button()) 190 247 { 248 + /* Only charging is desired */ 191 249 usb_state = USB_POWERED; 192 250 #ifdef HAVE_USBSTACK 193 - usb_core_enable_driver(USB_DRIVER_MASS_STORAGE,false); 194 - usb_core_enable_driver(USB_DRIVER_CHARGING_ONLY,true); 251 + usb_core_enable_driver(USB_DRIVER_MASS_STORAGE, false); 252 + usb_core_enable_driver(USB_DRIVER_CHARGING_ONLY, true); 195 253 usb_enable(true); 196 254 #endif 255 + break; 197 256 } 198 - else 199 - #endif 200 - { 257 + #endif /* HAVE_USB_POWER */ 201 258 #ifdef HAVE_USBSTACK 202 - /* Set the state to USB_POWERED for now. if a real 203 - connection is detected it will switch to USB_INSERTED */ 204 - usb_state = USB_POWERED; 205 - usb_core_enable_driver(USB_DRIVER_MASS_STORAGE,true); 206 - usb_core_enable_driver(USB_DRIVER_CHARGING_ONLY,false); 207 - usb_enable(true); 208 - #else 209 - /* Tell all threads that they have to back off the ATA. 259 + /* Set the state to USB_POWERED for now. If permission to connect 260 + * by threads and storage is granted it will be changed to 261 + * USB_CONNECTED. */ 262 + usb_state = USB_POWERED; 263 + usb_core_enable_driver(USB_DRIVER_MASS_STORAGE, true); 264 + usb_core_enable_driver(USB_DRIVER_CHARGING_ONLY, false); 265 + 266 + /* Check any drivers enabled at this point for exclusive storage 267 + * access requirements. */ 268 + exclusive_storage_access = usb_core_any_exclusive_storage(); 269 + 270 + if (exclusive_storage_access) 271 + #endif /* HAVE_USBSTACK */ 272 + { 273 + /* Tell all threads that they have to back off the storage. 210 274 We subtract one for our own thread. */ 211 - num_acks_to_expect = 212 - queue_broadcast(SYS_USB_CONNECTED, 0) - 1; 213 - waiting_for_ack = true; 275 + num_acks_to_expect = queue_broadcast(SYS_USB_CONNECTED, 0) - 1; 214 276 DEBUGF("USB inserted. Waiting for ack from %d threads...\n", 215 - num_acks_to_expect); 216 - #endif 277 + num_acks_for_connect); 217 278 } 218 279 break; 219 - #ifdef HAVE_USBSTACK 220 - case USB_REQUEST_DISK: 221 - if(!waiting_for_ack) 280 + 281 + case SYS_USB_CONNECTED_ACK: 282 + if(num_acks_to_expect > 0 && --num_acks_to_expect == 0) 222 283 { 223 - /* Tell all threads that they have to back off the ATA. 224 - We subtract one for our own thread. */ 225 - num_acks_to_expect = 226 - queue_broadcast(SYS_USB_CONNECTED, 0) - 1; 227 - waiting_for_ack = true; 228 - DEBUGF("USB inserted. Waiting for ack from %d threads...\n", 229 - num_acks_to_expect); 284 + DEBUGF("All threads have acknowledged the connect.\n"); 285 + usb_slave_mode(true); 286 + usb_state = USB_INSERTED; 230 287 } 231 - break; 232 - case USB_RELEASE_DISK: 233 - if(!waiting_for_ack) 288 + else 234 289 { 235 - /* Tell all threads that they have to back off the ATA. 236 - We subtract one for our own thread. */ 237 - num_acks_to_expect = 238 - queue_broadcast(SYS_USB_DISCONNECTED, 0) - 1; 239 - waiting_for_ack = true; 240 - DEBUGF("USB inserted. Waiting for ack from %d threads...\n", 290 + DEBUGF("usb: got ack, %d to go...\n", 241 291 num_acks_to_expect); 242 292 } 243 293 break; 244 - #endif 245 - case SYS_USB_CONNECTED_ACK: 246 - if(waiting_for_ack) 247 - { 248 - num_acks_to_expect--; 249 - if(num_acks_to_expect == 0) 250 - { 251 - DEBUGF("All threads have acknowledged the connect.\n"); 252 - #ifdef HAVE_USBSTACK 253 - #ifndef USE_ROCKBOX_USB 254 - /* until we have native mass-storage mode, we want to reboot on 255 - usb host connect */ 256 - try_reboot(); 257 - #endif /* USE_ROCKBOX_USB */ 258 - #ifdef HAVE_PRIORITY_SCHEDULING 259 - thread_set_priority(usb_thread_entry,PRIORITY_REALTIME); 260 - #endif 261 - exclusive_storage_access = true; 262 - 263 - #else 264 - usb_slave_mode(true); 265 - cpu_idle_mode(true); 266 - #endif 267 - usb_state = USB_INSERTED; 268 - waiting_for_ack = false; 269 - } 270 - else 271 - { 272 - DEBUGF("usb: got ack, %d to go...\n", 273 - num_acks_to_expect); 274 - } 275 - } 276 - break; 277 294 278 295 case USB_EXTRACTED: 279 - #ifdef HAVE_USBSTACK 280 - usb_enable(false); 281 - #ifdef HAVE_PRIORITY_SCHEDULING 282 - thread_set_priority(usb_thread_entry,PRIORITY_SYSTEM); 283 - #endif 284 - #endif 285 296 #ifdef HAVE_LCD_BITMAP 286 - if(do_screendump_instead_of_usb) 287 - break; 288 - #endif 289 - #ifdef HAVE_USB_POWER 297 + if(usb_state == USB_SCREENDUMP) 298 + { 299 + usb_state = USB_EXTRACTED; 300 + break; /* Connected for screendump only */ 301 + } 302 + #endif /* HAVE_LCD_BITMAP */ 303 + #ifndef HAVE_USBSTACK /* Stack must undo this if POWERED state was transitional */ 290 304 if(usb_state == USB_POWERED) 291 305 { 292 306 usb_state = USB_EXTRACTED; 293 307 break; 294 308 } 295 - #endif 296 - #ifndef HAVE_USBSTACK 309 + #endif /* HAVE_USBSTACK */ 297 310 if(usb_state == USB_INSERTED) 298 311 { 299 312 /* Only disable the USB mode if we really have enabled it 300 313 some threads might not have acknowledged the 301 314 insertion */ 302 315 usb_slave_mode(false); 303 - cpu_idle_mode(false); 304 316 } 305 - #endif 306 317 307 318 usb_state = USB_EXTRACTED; 308 319 #ifdef HAVE_USBSTACK 309 - if(exclusive_storage_access) 310 - { 311 - int rc = disk_mount_all(); 312 - if (rc <= 0) /* no partition */ 313 - panicf("mount: %d",rc); 314 - exclusive_storage_access = false; 315 - #endif 316 - /* Tell all threads that we are back in business */ 317 - num_acks_to_expect = 318 - queue_broadcast(SYS_USB_DISCONNECTED, 0) - 1; 319 - waiting_for_ack = true; 320 - DEBUGF("USB extracted. Waiting for ack from %d threads...\n", 321 - num_acks_to_expect); 322 - #ifdef HAVE_USBSTACK 323 - } 324 - #endif 320 + if (!exclusive_storage_access) 321 + break; 322 + 323 + exclusive_storage_access = false; 324 + #endif /* HAVE_USBSTACK */ 325 + /* Tell all threads that we are back in business */ 326 + num_acks_to_expect = 327 + queue_broadcast(SYS_USB_DISCONNECTED, 0) - 1; 328 + DEBUGF("USB extracted. Waiting for ack from %d threads...\n", 329 + num_acks_to_expect); 325 330 break; 326 331 327 332 case SYS_USB_DISCONNECTED_ACK: 328 - if(waiting_for_ack) 333 + if(num_acks_to_expect > 0 && --num_acks_to_expect == 0) 334 + { 335 + DEBUGF("All threads have acknowledged. " 336 + "We're in business.\n"); 337 + } 338 + else 329 339 { 330 - num_acks_to_expect--; 331 - if(num_acks_to_expect == 0) 332 - { 333 - DEBUGF("All threads have acknowledged. " 334 - "We're in business.\n"); 335 - waiting_for_ack = false; 336 - } 337 - else 338 - { 339 - DEBUGF("usb: got ack, %d to go...\n", 340 - num_acks_to_expect); 341 - } 340 + DEBUGF("usb: got ack, %d to go...\n", 341 + num_acks_to_expect); 342 342 } 343 343 break; 344 344 ··· 347 347 case SYS_HOTSWAP_EXTRACTED: 348 348 #ifdef HAVE_USBSTACK 349 349 usb_core_hotswap_event(1,ev.id == SYS_HOTSWAP_INSERTED); 350 - #else 350 + #else /* !HAVE_USBSTACK */ 351 351 if(usb_state == USB_INSERTED) 352 352 { 353 353 usb_enable(false); 354 354 #if (CONFIG_STORAGE & STORAGE_MMC) 355 355 usb_mmc_countdown = HZ/2; /* re-enable after 0.5 sec */ 356 - #endif 356 + #endif /* STORAGE_MMC */ 357 357 } 358 - #endif 358 + #endif /* HAVE_USBSTACK */ 359 359 break; 360 360 361 + #if (CONFIG_STORAGE & STORAGE_MMC) 361 362 case USB_REENABLE: 362 363 if(usb_state == USB_INSERTED) 363 364 usb_enable(true); /* reenable only if still inserted */ 364 365 break; 366 + #endif /* STORAGE_MMC */ 365 367 #endif /* HAVE_HOTSWAP */ 368 + 369 + #ifdef USB_FIREWIRE_HANDLING 366 370 case USB_REQUEST_REBOOT: 367 371 #ifdef HAVE_USB_POWER 368 - if((button_status() & ~USBPOWER_BTN_IGNORE) != USBPOWER_BUTTON) 372 + if (usb_reboot_button()) 369 373 #endif 370 374 try_reboot(); 371 375 break; 376 + #endif /* USB_FIREWIRE_HANDLING */ 372 377 } 373 378 } 374 379 } 375 - #endif 376 380 377 - #ifdef HAVE_USBSTACK 378 - void usb_signal_transfer_completion(struct usb_transfer_completion_event_data* event_data) 379 - { 380 - queue_post(&usb_queue, USB_TRANSFER_COMPLETION, (intptr_t)event_data); 381 - } 382 - #endif 383 - 384 - #ifdef USB_FULL_INIT 385 381 static void usb_tick(void) 386 382 { 387 383 int current_status; 388 384 389 385 if(usb_monitor_enabled) 390 386 { 391 - #if defined(IPOD_COLOR) || defined(IPOD_4G) \ 392 - || defined(IPOD_MINI) || defined(IPOD_MINI2G) 387 + #ifdef USB_FIREWIRE_HANDLING 393 388 int current_firewire_status = firewire_detect(); 394 389 if(current_firewire_status != last_firewire_status) 395 390 { ··· 409 404 queue_post(&usb_queue, USB_REQUEST_REBOOT, 0); 410 405 } 411 406 } 412 - #endif 407 + #endif /* USB_FIREWIRE_HANDLING */ 413 408 414 409 current_status = usb_detect(); 415 410 ··· 442 437 } 443 438 #endif 444 439 } 445 - #endif 440 + #endif /* USB_FULL_INIT */ 446 441 447 442 void usb_acknowledge(long id) 448 443 { ··· 458 453 usb_monitor_enabled = false; 459 454 countdown = -1; 460 455 461 - #if defined(IPOD_COLOR) || defined(IPOD_4G) \ 462 - || defined(IPOD_MINI) || defined(IPOD_MINI2G) 456 + #ifdef USB_FIREWIRE_HANDLING 463 457 firewire_countdown = -1; 464 458 last_firewire_status = false; 465 459 #endif ··· 480 474 IF_PRIO(, PRIORITY_SYSTEM) IF_COP(, CPU)); 481 475 482 476 tick_add_task(usb_tick); 483 - #endif 484 - 477 + #endif /* USB_FULL_INIT */ 485 478 } 486 479 487 480 void usb_wait_for_disconnect(struct event_queue *q) ··· 518 511 case SYS_USB_DISCONNECTED: 519 512 usb_acknowledge(SYS_USB_DISCONNECTED_ACK); 520 513 return 0; 521 - break; 522 514 case SYS_TIMEOUT: 523 515 return 1; 524 - break; 525 516 } 526 517 } 527 518 #else ··· 562 553 } 563 554 564 555 #ifdef HAVE_USBSTACK 565 - void usb_request_exclusive_ata(void) 566 - { 567 - /* This is not really a clean place to start boosting the cpu. but it's 568 - * currently the best one. We want to get rid of having to boost the cpu 569 - * for usb anyway */ 570 - trigger_cpu_boost(); 571 - if(!exclusive_storage_access) { 572 - queue_post(&usb_queue, USB_REQUEST_DISK, 0); 573 - } 574 - } 575 - 576 - void usb_release_exclusive_ata(void) 577 - { 578 - cancel_cpu_boost(); 579 - if(exclusive_storage_access) { 580 - queue_post(&usb_queue, USB_RELEASE_DISK, 0); 581 - exclusive_storage_access = false; 582 - } 583 - } 584 - 585 - bool usb_exclusive_ata(void) 556 + bool usb_exclusive_storage(void) 586 557 { 587 558 return exclusive_storage_access; 588 559 }
+1 -1
firmware/usbstack/usb_charging_only.h
··· 5 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 7 * \/ \/ \/ \/ \/ 8 - * $Id: $ 8 + * $Id$ 9 9 * 10 10 * Copyright (C) 2008 by Frank Gevaerts 11 11 *
+1 -1
firmware/usbstack/usb_class_driver.h
··· 33 33 /* Driver api starts here */ 34 34 35 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 38 /* Let the driver request endpoints it need. Returns zero on success */ 39 39 int (*request_endpoints)(struct usb_class_driver *);
+26 -13
firmware/usbstack/usb_core.c
··· 54 54 #include "ata.h" 55 55 #endif 56 56 57 + #ifndef USB_MAX_CURRENT 58 + #define USB_MAX_CURRENT 500 59 + #endif 57 60 58 61 /*-------------------------------------------------------------------------*/ 59 62 /* USB protocol descriptors: */ ··· 94 97 .bConfigurationValue = 1, 95 98 .iConfiguration = 0, 96 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 182 #ifdef USB_STORAGE 180 183 [USB_DRIVER_MASS_STORAGE] = { 181 184 .enabled = false, 182 - .needs_exclusive_ata = true, 185 + .needs_exclusive_storage = true, 183 186 .first_interface = 0, 184 187 .last_interface = 0, 185 188 .request_endpoints = usb_storage_request_endpoints, ··· 198 201 #ifdef USB_SERIAL 199 202 [USB_DRIVER_SERIAL] = { 200 203 .enabled = false, 201 - .needs_exclusive_ata = false, 204 + .needs_exclusive_storage = false, 202 205 .first_interface = 0, 203 206 .last_interface = 0, 204 207 .request_endpoints = usb_serial_request_endpoints, ··· 217 220 #ifdef USB_CHARGING_ONLY 218 221 [USB_DRIVER_CHARGING_ONLY] = { 219 222 .enabled = false, 220 - .needs_exclusive_ata = false, 223 + .needs_exclusive_storage = false, 221 224 .first_interface = 0, 222 225 .last_interface = 0, 223 226 .request_endpoints = usb_charging_only_request_endpoints, ··· 353 356 int i; 354 357 for(i=0;i<USB_NUM_DRIVERS;i++) { 355 358 if(drivers[i].enabled && drivers[i].disconnect != NULL) 359 + { 356 360 drivers[i].disconnect (); 361 + drivers[i].enabled = false; 362 + } 357 363 } 358 364 359 365 if (initialized) { 360 366 usb_drv_exit(); 361 367 } 362 368 initialized = false; 369 + usb_state = DEFAULT; 363 370 logf("usb_core_exit() finished"); 364 371 } 365 372 ··· 392 399 return drivers[driver].enabled; 393 400 } 394 401 402 + bool 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 416 #ifdef HAVE_HOTSWAP 396 417 void usb_core_hotswap_event(int volume,bool inserted) 397 418 { ··· 484 505 usb_core_set_serial_function_id(); 485 506 486 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 510 switch(req->bRequestType & 0x1f) { ··· 788 801 { 789 802 if (usb_state == CONFIGURED) 790 803 { 791 - return 500; 804 + return MAX(USB_MAX_CURRENT, 100); 792 805 } 793 806 else 794 807 {
+3 -6
firmware/usbstack/usb_storage.c
··· 293 293 #endif 294 294 } 295 295 296 + #if 0 296 297 static void try_release_ata(void) 297 298 { 298 299 /* Check if there is a connected drive left. If not, ··· 310 311 usb_release_exclusive_ata(); 311 312 } 312 313 } 314 + #endif 313 315 314 316 #ifdef HAVE_HOTSWAP 315 317 void usb_storage_notify_hotswap(int volume,bool inserted) ··· 320 322 } 321 323 else { 322 324 ejected[volume] = true; 323 - try_release_ata(); 324 325 } 325 - 326 326 } 327 327 #endif 328 328 ··· 334 334 for(i=0;i<NUM_VOLUMES;i++) 335 335 ejected[i] = !check_disk_present(IF_MV(i)); 336 336 logf("%s", __func__); 337 - usb_request_exclusive_ata(); 338 337 } 339 338 } 340 339 ··· 682 681 #ifdef HAVE_HOTSWAP 683 682 if(storage_removable(lun) && !storage_present(lun)) { 684 683 ejected[lun] = true; 685 - try_release_ata(); 686 684 } 687 685 #endif 688 686 ··· 699 697 switch (cbw->command_block[0]) { 700 698 case SCSI_TEST_UNIT_READY: 701 699 logf("scsi test_unit_ready %d",lun); 702 - if(!usb_exclusive_ata()) { 700 + if(!usb_exclusive_storage()) { 703 701 send_csw(UMS_STATUS_FAIL); 704 702 cur_sense_data.sense_key=SENSE_NOT_READY; 705 703 cur_sense_data.asc=ASC_MEDIUM_NOT_PRESENT; ··· 885 883 { 886 884 logf("scsi eject"); 887 885 ejected[lun]=true; 888 - try_release_ata(); 889 886 } 890 887 } 891 888 }