usb: enter to exclusive disk mode only when required by usb config

currently, exclusive disk mode was enabled at the same time as the
usb insertion. when multiple usb configurations exist, this is not
appropriate.

manage it in the core and enable it only when necessary.

Change-Id: Iadbec05fad1d1319471233227ae0e72c12079295
This commit is contained in:
mojyack 2026-01-16 17:08:12 +09:00 committed by Solomon Peachy
parent 1951c17e0b
commit 33d0a3efa3
4 changed files with 129 additions and 113 deletions

View file

@ -544,16 +544,6 @@ 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)
{
@ -874,16 +864,28 @@ static int usb_core_do_set_config(uint8_t new_config)
usb_config = new_config;
usb_state = usb_config == 0 ? ADDRESS : CONFIGURED;
bool require_exclusive = false;
/* activate new config */
if(usb_config != 0) {
init_deinit_endpoints(usb_config - 1, true);
for(int i = 0; i < USB_NUM_DRIVERS; i++) {
if(is_active(drivers[i]) && drivers[i].init_connection != NULL) {
drivers[i].init_connection();
require_exclusive |= drivers[i].needs_exclusive_storage;
}
}
}
if(require_exclusive) {
if(!usb_exclusive_storage()) {
usb_release_exclusive_storage();
usb_request_exclusive_storage();
}
} else {
usb_release_exclusive_storage();
}
#ifdef HAVE_USB_CHARGING_ENABLE
usb_charging_maxcurrent_change(usb_charging_maxcurrent());
#endif