Gigabeat S: Revert removal of usb_plugged in r31489

Synchronous cable read is still required because the timing of the receipt of
the cable event cannot be known for sure-- basically it introduced a thread
race between main and pmic. If a keypress is desired instead to enter BL USB
mode a la AS3525, then it's possible to remove that.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31510 a1c6a512-1295-4272-9138-f99709370657
diff --git a/bootloader/gigabeat-s.c b/bootloader/gigabeat-s.c
index 5b53615..909194e 100644
--- a/bootloader/gigabeat-s.c
+++ b/bootloader/gigabeat-s.c
@@ -109,7 +109,7 @@
             break;
         }
 
-        if (usb_detect() == USB_EXTRACTED)
+        if (usb_plugged() == USB_EXTRACTED)
             break; /* Cable pulled */
     }
 
@@ -376,7 +376,7 @@
 
     /* Do USB first since a tar or binary could be added to the MTP directory
      * at the time and we can untar or move after unplugging. */
-    if (usb_detect() == USB_INSERTED)
+    if (usb_plugged() == USB_INSERTED)
         handle_usb(HZ*2);
 
     handle_untar();
diff --git a/firmware/target/arm/imx31/gigabeat-s/system-target.h b/firmware/target/arm/imx31/gigabeat-s/system-target.h
index 533b2a1..44a97c7 100644
--- a/firmware/target/arm/imx31/gigabeat-s/system-target.h
+++ b/firmware/target/arm/imx31/gigabeat-s/system-target.h
@@ -85,6 +85,7 @@
 
 void dumpregs(void);
 
+bool usb_plugged(void);
 void usb_connect_event(void);
 
 /** Sector read/write filters **/
diff --git a/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c
index d967cd6..b157544 100644
--- a/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c
+++ b/firmware/target/arm/imx31/gigabeat-s/usb-gigabeat-s.c
@@ -53,11 +53,16 @@
     }
 }
 
+/* Read the immediate state of the cable from the PMIC */
+bool usb_plugged(void)
+{
+    return mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_USB4V4S;
+}
+
 void usb_connect_event(void)
 {
     /* Read the immediate state of the cable from the PMIC */
-    int status = (mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_USB4V4S)
-        ? USB_INSERTED : USB_EXTRACTED;
+    int status = usb_plugged() ? USB_INSERTED : USB_EXTRACTED;
     usb_status = status;
     /* Notify power that USB charging is potentially available */
     charger_usb_detect_event(status);