usb: Clean up the pile of USB_FULL_INIT exceptions

The intent here is that when HAVE_USBSTACK is not defined, or we are
in a bootloader wthout HAVE_BOOTLOADER_USB_MODE, a device may still
some of USB subsystem initialized.  For example, this may be needed
to enable USB-based charging functionality.

So, get rid of the blanket enables of USB_FULL_INIT based on target SoC,
enabling HAVE_BOOTLOADER_USB_MODE on targets that need it, and clean up
the initial mess. Most of this mess is because usb_core.c has no sense
of USB_FULL_INIT or not, and is always included when HAVE_USBSTACK is
set (even in bootloaders without BOOTLOADER_USB_MODE), but dealing with
that latter case will come later.

Change-Id: I7f805b89dded39aeea2db9038209780069e3b600
This commit is contained in:
Solomon Peachy 2026-01-27 07:50:53 -05:00
parent 7b77752aff
commit 41f9285def
7 changed files with 42 additions and 35 deletions

View file

@ -216,7 +216,7 @@ target/hosted/xduoo/xduoolinux_codec.c
target/hosted/button-devinput.c target/hosted/button-devinput.c
#endif #endif
#if defined(HIBY_LINUX) && !defined(HIBY_R3PROII) && !defined(HIBY_R1) && !defined(SIMULATOR) #if defined(HIBY_LINUX) && !defined(HIBY_R3PROII) && !defined(HIBY_R1) && !defined(SIMULATOR)
target/hosted/usb-hiby.c target/hosted/usb-hiby.c
#endif #endif
@ -949,6 +949,7 @@ target/arm/s5l8702/lcd-asm-s5l8702.S
#endif #endif
/* USB Stack */ /* USB Stack */
// TODO: This needs to be HAVE_USBSTACK && (!BOOTLOADER || HAVE_USB_BOOTLOADER_MODE)
#ifdef HAVE_USBSTACK #ifdef HAVE_USBSTACK
usbstack/usb_core.c usbstack/usb_core.c
#ifdef USB_ENABLE_STORAGE #ifdef USB_ENABLE_STORAGE

View file

@ -222,7 +222,7 @@
/* logf() over USB serial (http://www.rockbox.org/wiki/PortalPlayerUsb) */ /* logf() over USB serial (http://www.rockbox.org/wiki/PortalPlayerUsb) */
//#define USB_ENABLE_SERIAL //#define USB_ENABLE_SERIAL
#define HAVE_USBSTACK #define HAVE_USBSTACK
#define HAVE_BOOTLOADER_USB_MODE //#define HAVE_BOOTLOADER_USB_MODE
#define HAVE_USB_HID_MOUSE #define HAVE_USB_HID_MOUSE
#define USB_VENDOR_ID 0x05AC #define USB_VENDOR_ID 0x05AC
#define USB_PRODUCT_ID 0x1260 #define USB_PRODUCT_ID 0x1260

View file

@ -157,7 +157,7 @@
#define CONFIG_USBOTG USBOTG_ISP1583 #define CONFIG_USBOTG USBOTG_ISP1583
#define HAVE_USBSTACK #define HAVE_USBSTACK
#define HAVE_BOOTLOADER_USB_MODE //#define HAVE_BOOTLOADER_USB_MODE
#define USB_VENDOR_ID 0x041e #define USB_VENDOR_ID 0x041e
#define USB_PRODUCT_ID 0x4133 #define USB_PRODUCT_ID 0x4133
#define USB_NUM_ENDPOINTS 7 #define USB_NUM_ENDPOINTS 7

View file

@ -158,7 +158,7 @@
#define CONFIG_USBOTG USBOTG_ISP1583 #define CONFIG_USBOTG USBOTG_ISP1583
#define HAVE_USBSTACK #define HAVE_USBSTACK
#define HAVE_BOOTLOADER_USB_MODE //#define HAVE_BOOTLOADER_USB_MODE
#define USB_VENDOR_ID 0x041e #define USB_VENDOR_ID 0x041e
#define USB_PRODUCT_ID 0x4133 #define USB_PRODUCT_ID 0x4133
#define USB_NUM_ENDPOINTS 7 #define USB_NUM_ENDPOINTS 7

View file

@ -158,7 +158,7 @@
/* #define CONFIG_USBOTG USBOTG_ISP1761 */ /* #define CONFIG_USBOTG USBOTG_ISP1761 */
#define CONFIG_USBOTG USBOTG_ISP1583 #define CONFIG_USBOTG USBOTG_ISP1583
#define HAVE_USBSTACK #define HAVE_USBSTACK
#define HAVE_BOOTLOADER_USB_MODE //#define HAVE_BOOTLOADER_USB_MODE
#define USB_VENDOR_ID 0x041e #define USB_VENDOR_ID 0x041e
#define USB_PRODUCT_ID 0x4133 #define USB_PRODUCT_ID 0x4133
#define USB_NUM_ENDPOINTS 7 #define USB_NUM_ENDPOINTS 7

View file

@ -58,8 +58,10 @@ void usb_core_transfer_complete(int endpoint,int dir,int status,int length);
void usb_core_bus_reset(void); void usb_core_bus_reset(void);
void usb_core_enable_driver(int driver,bool enabled); void usb_core_enable_driver(int driver,bool enabled);
bool usb_core_driver_enabled(int driver); bool usb_core_driver_enabled(int driver);
#ifdef HAVE_USBSTACK
void usb_core_handle_transfer_completion( void usb_core_handle_transfer_completion(
struct usb_transfer_completion_event_data* event); struct usb_transfer_completion_event_data* event);
#endif
void usb_core_handle_notify(long id, intptr_t data); void usb_core_handle_notify(long id, intptr_t data);
/* For controllers which handle SET ADDR and/or SET CONFIG in hardware */ /* For controllers which handle SET ADDR and/or SET CONFIG in hardware */
void usb_core_notify_set_address(uint8_t addr); void usb_core_notify_set_address(uint8_t addr);
@ -70,4 +72,3 @@ void usb_core_hotswap_event(int volume,bool inserted);
#endif #endif
#endif #endif

View file

@ -59,17 +59,7 @@
#include "iap.h" #include "iap.h"
#endif #endif
/* Conditions under which we want the entire driver */ #if defined(HAVE_USBSTACK) && (!defined(BOOTLOADER) || defined(HAVE_BOOTLOADER_USB_MODE))
#if !defined(BOOTLOADER) || \
(defined(HAVE_USBSTACK) && defined(HAVE_BOOTLOADER_USB_MODE)) || \
(defined(HAVE_USBSTACK) && defined(IPOD_NANO2G)) || \
(defined(HAVE_USBSTACK) && (defined(CREATIVE_ZVx))) || \
(defined(HAVE_USBSTACK) && (defined(OLYMPUS_MROBE_500))) || \
defined(CPU_TCC780X) || \
(CONFIG_USBOTG == USBOTG_JZ4740) || \
(CONFIG_USBOTG == USBOTG_JZ4760)
/* TODO: condition should be reset to be only the original
(defined(HAVE_USBSTACK) && defined(HAVE_BOOTLOADER_USB_MODE)) */
#define USB_FULL_INIT #define USB_FULL_INIT
#endif #endif
@ -91,8 +81,8 @@ static int usb_state = USB_EXTRACTED;
static int usb_mmc_countdown = 0; static int usb_mmc_countdown = 0;
#endif #endif
/* Make sure there's enough stack space for screendump */
#ifdef USB_FULL_INIT #ifdef USB_FULL_INIT
/* Make sure there's enough stack space for screendump */
#ifndef USB_EXTRA_STACK #ifndef USB_EXTRA_STACK
# define USB_EXTRA_STACK 0x0 /*Define in firmware/export/config/[target].h*/ # define USB_EXTRA_STACK 0x0 /*Define in firmware/export/config/[target].h*/
#endif #endif
@ -101,26 +91,20 @@ static const char usb_thread_name[] = "usb";
static unsigned int usb_thread_entry = 0; static unsigned int usb_thread_entry = 0;
static bool usb_monitor_enabled = false; static bool usb_monitor_enabled = false;
static bool exclusive_storage_enabled = false; static bool exclusive_storage_enabled = false;
#endif /* USB_FULL_INIT */
static struct event_queue usb_queue SHAREDBSS_ATTR;
static bool exclusive_storage_requested = false; static bool exclusive_storage_requested = false;
static struct event_queue usb_queue SHAREDBSS_ATTR;
#ifdef USB_ENABLE_HID #ifdef USB_ENABLE_HID
static bool usb_hid = true; static bool usb_hid = true;
#endif #endif
#ifdef USB_ENABLE_AUDIO #ifdef USB_ENABLE_AUDIO
static int usb_audio = 0; static int usb_audio = 0;
#endif #endif
#ifdef HAVE_USB_POWER
static bool usb_power_only = false;
#endif
#ifdef USB_FULL_INIT
static bool usb_host_present = false; static bool usb_host_present = false;
static int usb_num_acks_to_expect = 0; static int usb_num_acks_to_expect = 0;
static uint32_t usb_broadcast_seqnum = 0x80000000; static uint32_t usb_broadcast_seqnum = 0x80000000;
#ifdef HAVE_USB_POWER #ifdef HAVE_USB_POWER
static int usb_mode = USBMODE_DEFAULT; static int usb_mode = USBMODE_DEFAULT;
static bool usb_power_only = false;
#endif #endif
#if defined(USB_FIREWIRE_HANDLING) #if defined(USB_FIREWIRE_HANDLING)
@ -492,7 +476,6 @@ static void NORETURN_ATTR usb_thread(void)
/* USB_INSERTED */ /* USB_INSERTED */
case SYS_USB_CONNECTED_ACK: case SYS_USB_CONNECTED_ACK:
#ifdef USB_FULL_INIT
if((uint32_t)ev.data != usb_broadcast_seqnum) { if((uint32_t)ev.data != usb_broadcast_seqnum) {
DEBUGF("usb: late ack %lX < %lX", ev.data, usb_broadcast_seqnum); DEBUGF("usb: late ack %lX < %lX", ev.data, usb_broadcast_seqnum);
break; break;
@ -507,7 +490,6 @@ static void NORETURN_ATTR usb_thread(void)
} }
DEBUGF("usb: all threads have acknowledged the connect.\n"); DEBUGF("usb: all threads have acknowledged the connect.\n");
#endif
if(usb_host_present && exclusive_storage_requested) { if(usb_host_present && exclusive_storage_requested) {
usb_slave_mode(true); usb_slave_mode(true);
exclusive_storage_enabled = true; exclusive_storage_enabled = true;
@ -712,19 +694,45 @@ static void usb_tick(void)
} }
#endif #endif
} }
void usb_start_monitoring(void) void usb_start_monitoring(void)
{ {
usb_monitor_enabled = true; usb_monitor_enabled = true;
} }
#endif /* USB_STATUS_BY_EVENT */ #endif /* USB_STATUS_BY_EVENT */
#endif /* USB_FULL_INIT */
void usb_acknowledge(long id, intptr_t seqnum) void usb_acknowledge(long id, intptr_t seqnum)
{ {
queue_post(&usb_queue, id, seqnum); queue_post(&usb_queue, id, seqnum);
} }
#else /* !USB_FULL_INIT */
/* TODO: All of this can go away once usb_core.c is no longer built
with BOOTLOADER && !HAVE_USB_BOOTLOADER_MODE */
#ifdef HAVE_USBSTACK
void usb_signal_transfer_completion(
struct usb_transfer_completion_event_data* event_data)
{
(void)event_data;
}
#endif
void usb_clear_pending_transfer_completion_events(void)
{
}
void usb_release_exclusive_storage(void)
{
}
void usb_signal_notify(long id, intptr_t data)
{
(void)id;
(void)data;
}
void usb_acknowledge(long id, intptr_t seqnum)
{
(void)id;
(void)seqnum;
}
#endif /* !USB_FULL_INIT */
void usb_init(void) void usb_init(void)
{ {
/* Do required hardware inits first. For software USB the driver has /* Do required hardware inits first. For software USB the driver has
@ -814,7 +822,6 @@ bool usb_exclusive_storage(void)
/* Storage isn't actually exclusive until slave mode has been entered */ /* Storage isn't actually exclusive until slave mode has been entered */
return exclusive_storage_enabled; return exclusive_storage_enabled;
} }
#endif /* HAVE_USBSTACK */
/* exclusive storage mode transision /* exclusive storage mode transision
* HAVE_USBSTACK: * HAVE_USBSTACK:
@ -863,14 +870,11 @@ bool usb_exclusive_storage(void)
void usb_request_exclusive_storage(void) void usb_request_exclusive_storage(void)
{ {
exclusive_storage_requested = true; exclusive_storage_requested = true;
#ifdef USB_FULL_INIT
usb_broadcast_seqnum += 1; usb_broadcast_seqnum += 1;
usb_num_acks_to_expect = queue_broadcast(SYS_USB_CONNECTED, usb_broadcast_seqnum) - 1; usb_num_acks_to_expect = queue_broadcast(SYS_USB_CONNECTED, usb_broadcast_seqnum) - 1;
DEBUGF("usb: waiting for %d acks...\n", usb_num_acks_to_expect); DEBUGF("usb: waiting for %d acks...\n", usb_num_acks_to_expect);
#endif
} }
#ifdef USB_FULL_INIT
void usb_release_exclusive_storage(void) void usb_release_exclusive_storage(void)
{ {
if(!exclusive_storage_requested) { if(!exclusive_storage_requested) {
@ -890,7 +894,6 @@ void usb_release_exclusive_storage(void)
#endif #endif
return; return;
} }
#endif
#ifdef USB_ENABLE_HID #ifdef USB_ENABLE_HID
void usb_set_hid(bool enable) void usb_set_hid(bool enable)
@ -914,6 +917,8 @@ bool usb_powered_only(void)
} }
#endif /* HAVE_USB_POWER */ #endif /* HAVE_USB_POWER */
#endif /* HAVE_USBSTACK && defined(USB_FULL_INIT) */
#elif defined(USB_NONE) #elif defined(USB_NONE)
/* Dummy functions for USB_NONE */ /* Dummy functions for USB_NONE */