usb: Clean up the pile of USB_FULL_INIT exceptions

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 41f9285def95ebab1ef4953f6110e70f46befcc9
Author: Solomon Peachy <[email protected]>
Date:   Tue Jan 27 07:50:53 2026 -0500

    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

diff --git a/firmware/SOURCES b/firmware/SOURCES
index 88927f7364..d62b8d254c 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -216,7 +216,7 @@ target/hosted/xduoo/xduoolinux_codec.c
 target/hosted/button-devinput.c
 #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
 #endif
 
@@ -949,6 +949,7 @@ target/arm/s5l8702/lcd-asm-s5l8702.S
 #endif
 
 /* USB Stack */
+// TODO:  This needs to be HAVE_USBSTACK && (!BOOTLOADER || HAVE_USB_BOOTLOADER_MODE)
 #ifdef HAVE_USBSTACK
 usbstack/usb_core.c
 #ifdef USB_ENABLE_STORAGE
diff --git a/firmware/export/config/ipodnano2g.h b/firmware/export/config/ipodnano2g.h
index 621f4e27a5..34e041912b 100644
--- a/firmware/export/config/ipodnano2g.h
+++ b/firmware/export/config/ipodnano2g.h
@@ -222,7 +222,7 @@
 /* logf() over USB serial (http://www.rockbox.org/wiki/PortalPlayerUsb) */
 //#define USB_ENABLE_SERIAL
 #define HAVE_USBSTACK
-#define HAVE_BOOTLOADER_USB_MODE
+//#define HAVE_BOOTLOADER_USB_MODE
 #define HAVE_USB_HID_MOUSE
 #define USB_VENDOR_ID 0x05AC
 #define USB_PRODUCT_ID 0x1260
diff --git a/firmware/export/config/zenvision.h b/firmware/export/config/zenvision.h
index d8b75876ae..eb94c84ca7 100644
--- a/firmware/export/config/zenvision.h
+++ b/firmware/export/config/zenvision.h
@@ -157,7 +157,7 @@
 
 #define CONFIG_USBOTG USBOTG_ISP1583
 #define HAVE_USBSTACK
-#define HAVE_BOOTLOADER_USB_MODE
+//#define HAVE_BOOTLOADER_USB_MODE
 #define USB_VENDOR_ID 0x041e
 #define USB_PRODUCT_ID 0x4133
 #define USB_NUM_ENDPOINTS 7
diff --git a/firmware/export/config/zenvisionm30gb.h b/firmware/export/config/zenvisionm30gb.h
index 974783540a..236a153a3c 100644
--- a/firmware/export/config/zenvisionm30gb.h
+++ b/firmware/export/config/zenvisionm30gb.h
@@ -158,7 +158,7 @@
 
 #define CONFIG_USBOTG USBOTG_ISP1583
 #define HAVE_USBSTACK
-#define HAVE_BOOTLOADER_USB_MODE
+//#define HAVE_BOOTLOADER_USB_MODE
 #define USB_VENDOR_ID 0x041e
 #define USB_PRODUCT_ID 0x4133
 #define USB_NUM_ENDPOINTS 7
diff --git a/firmware/export/config/zenvisionm60gb.h b/firmware/export/config/zenvisionm60gb.h
index 0209d8ed6e..64f6925328 100644
--- a/firmware/export/config/zenvisionm60gb.h
+++ b/firmware/export/config/zenvisionm60gb.h
@@ -158,7 +158,7 @@
 /* #define CONFIG_USBOTG    USBOTG_ISP1761 */
 #define CONFIG_USBOTG USBOTG_ISP1583
 #define HAVE_USBSTACK
-#define HAVE_BOOTLOADER_USB_MODE
+//#define HAVE_BOOTLOADER_USB_MODE
 #define USB_VENDOR_ID 0x041e
 #define USB_PRODUCT_ID 0x4133
 #define USB_NUM_ENDPOINTS 7
diff --git a/firmware/export/usb_core.h b/firmware/export/usb_core.h
index 1e940dc8e3..5aa6e4f33a 100644
--- a/firmware/export/usb_core.h
+++ b/firmware/export/usb_core.h
@@ -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_enable_driver(int driver,bool enabled);
 bool usb_core_driver_enabled(int driver);
+#ifdef HAVE_USBSTACK
 void usb_core_handle_transfer_completion(
         struct usb_transfer_completion_event_data* event);
+#endif
 void usb_core_handle_notify(long id, intptr_t data);
 /* For controllers which handle SET ADDR and/or SET CONFIG in hardware */
 void usb_core_notify_set_address(uint8_t addr);
@@ -70,4 +72,3 @@ void usb_core_hotswap_event(int volume,bool inserted);
 #endif
 
 #endif
-
diff --git a/firmware/usb.c b/firmware/usb.c
index 9d9b221e0a..318c3f07ac 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -59,17 +59,7 @@
 #include "iap.h"
 #endif
 
-/* Conditions under which we want the entire driver */
-#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)) */
+#if defined(HAVE_USBSTACK) && (!defined(BOOTLOADER) || defined(HAVE_BOOTLOADER_USB_MODE))
 #define USB_FULL_INIT
 #endif
 
@@ -91,8 +81,8 @@ static int usb_state = USB_EXTRACTED;
 static int usb_mmc_countdown = 0;
 #endif
 
-/* Make sure there's enough stack space for screendump */
 #ifdef USB_FULL_INIT
+/* Make sure there's enough stack space for screendump */
 #ifndef USB_EXTRA_STACK
 #   define USB_EXTRA_STACK 0x0 /*Define in firmware/export/config/[target].h*/
 #endif
@@ -101,26 +91,20 @@ static const char usb_thread_name[] = "usb";
 static unsigned int usb_thread_entry = 0;
 static bool usb_monitor_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 struct event_queue usb_queue SHAREDBSS_ATTR;
 #ifdef USB_ENABLE_HID
 static bool usb_hid = true;
 #endif
 #ifdef USB_ENABLE_AUDIO
 static int usb_audio = 0;
 #endif
-
-#ifdef HAVE_USB_POWER
-static bool usb_power_only = false;
-#endif
-
-#ifdef USB_FULL_INIT
 static bool usb_host_present = false;
 static int usb_num_acks_to_expect = 0;
 static uint32_t usb_broadcast_seqnum = 0x80000000;
 #ifdef HAVE_USB_POWER
 static int usb_mode = USBMODE_DEFAULT;
+static bool usb_power_only = false;
 #endif
 
 #if defined(USB_FIREWIRE_HANDLING)
@@ -492,7 +476,6 @@ static void NORETURN_ATTR usb_thread(void)
             /* USB_INSERTED */
 
         case SYS_USB_CONNECTED_ACK:
-#ifdef USB_FULL_INIT
             if((uint32_t)ev.data != usb_broadcast_seqnum) {
                 DEBUGF("usb: late ack %lX < %lX", ev.data, usb_broadcast_seqnum);
                 break;
@@ -507,7 +490,6 @@ static void NORETURN_ATTR usb_thread(void)
             }
 
             DEBUGF("usb: all threads have acknowledged the connect.\n");
-#endif
             if(usb_host_present && exclusive_storage_requested) {
                 usb_slave_mode(true);
                 exclusive_storage_enabled = true;
@@ -712,19 +694,45 @@ static void usb_tick(void)
     }
 #endif
 }
-
 void usb_start_monitoring(void)
 {
     usb_monitor_enabled = true;
 }
 #endif /* USB_STATUS_BY_EVENT */
-#endif /* USB_FULL_INIT */
 
 void usb_acknowledge(long id, intptr_t 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)
 {
     /* 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 */
     return exclusive_storage_enabled;
 }
-#endif /* HAVE_USBSTACK */
 
 /* exclusive storage mode transision
  * HAVE_USBSTACK:
@@ -863,14 +870,11 @@ bool usb_exclusive_storage(void)
 void usb_request_exclusive_storage(void)
 {
     exclusive_storage_requested = true;
-#ifdef USB_FULL_INIT
     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);
-#endif
 }
 
-#ifdef USB_FULL_INIT
 void usb_release_exclusive_storage(void)
 {
     if(!exclusive_storage_requested) {
@@ -890,7 +894,6 @@ void usb_release_exclusive_storage(void)
 #endif
     return;
 }
-#endif
 
 #ifdef USB_ENABLE_HID
 void usb_set_hid(bool enable)
@@ -914,6 +917,8 @@ bool usb_powered_only(void)
 }
 #endif /* HAVE_USB_POWER */
 
+#endif /* HAVE_USBSTACK && defined(USB_FULL_INIT) */
+
 #elif defined(USB_NONE)
 /* Dummy functions for USB_NONE  */
 
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.