summaryrefslogtreecommitdiffstats
path: root/firmware/target
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c4
-rw-r--r--firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c8
-rw-r--r--firmware/target/arm/s3c2440/gigabeat-fx/usb-target.h1
-rw-r--r--firmware/target/arm/usb-fw-pp5002.c6
-rw-r--r--firmware/target/arm/usb-fw-pp502x.c88
-rw-r--r--firmware/target/coldfire/iaudio/usb-iaudio.c5
-rw-r--r--firmware/target/coldfire/iriver/h100/usb-h100.c5
-rw-r--r--firmware/target/coldfire/iriver/h300/usb-h300.c5
-rw-r--r--firmware/target/sh/archos/fm_v2/usb-fm_v2.c5
-rw-r--r--firmware/target/sh/archos/ondio/usb-ondio.c5
-rw-r--r--firmware/target/sh/archos/player/usb-player.c5
-rw-r--r--firmware/target/sh/archos/recorder/usb-recorder.c5
12 files changed, 99 insertions, 43 deletions
diff --git a/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c b/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c
index a22a227b15..3761c84a50 100644
--- a/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c
+++ b/firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c
@@ -37,10 +37,10 @@ void usb_init_device(void)
{
}
-bool usb_detect(void)
+int usb_detect(void)
{
/* TODO: Implement USB_ISP1582 */
- return false;
+ return USB_EXTRACTED;
}
void usb_enable(bool on)
diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c
index 566d25eecb..217a7d3cef 100644
--- a/firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c
+++ b/firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c
@@ -21,6 +21,7 @@
#include "system.h"
#include "kernel.h"
#include "ata.h"
+#include "usb.h"
#define USB_RST_ASSERT GPBDAT &= ~(1 << 4)
#define USB_RST_DEASSERT GPBDAT |= (1 << 4)
@@ -35,9 +36,12 @@
#define USB_CRADLE_BUS_DISABLE GPHDAT &= ~(1 << 8)
/* The usb detect is one pin to the cpu active low */
-inline bool usb_detect(void)
+int usb_detect(void)
{
- return USB_UNIT_IS_PRESENT | USB_CRADLE_IS_PRESENT;
+ if (USB_UNIT_IS_PRESENT | USB_CRADLE_IS_PRESENT)
+ return USB_INSERTED;
+ else
+ return USB_EXTRACTED;
}
void usb_init_device(void)
diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/usb-target.h b/firmware/target/arm/s3c2440/gigabeat-fx/usb-target.h
index baeb539b38..65690dc86b 100644
--- a/firmware/target/arm/s3c2440/gigabeat-fx/usb-target.h
+++ b/firmware/target/arm/s3c2440/gigabeat-fx/usb-target.h
@@ -20,7 +20,6 @@
#define USB_TARGET_H
bool usb_init_device(void);
-bool usb_detect(void);
void usb_enable(bool on);
#endif
diff --git a/firmware/target/arm/usb-fw-pp5002.c b/firmware/target/arm/usb-fw-pp5002.c
index e64d4f8f81..2a216c4d9b 100644
--- a/firmware/target/arm/usb-fw-pp5002.c
+++ b/firmware/target/arm/usb-fw-pp5002.c
@@ -56,15 +56,15 @@ void usb_enable(bool on)
}
}
-bool usb_detect(void)
+int usb_detect(void)
{
#if defined(IPOD_1G2G) || defined(IPOD_3G)
/* GPIO C bit 7 is firewire detect */
if (!(GPIOC_INPUT_VAL & 0x80))
- return true;
+ return USB_INSERTED;
#endif
/* TODO: add USB detection for iPod 3rd gen */
- return false;
+ return USB_EXTRACTED;
}
diff --git a/firmware/target/arm/usb-fw-pp502x.c b/firmware/target/arm/usb-fw-pp502x.c
index 76bd7281f5..ad2a10599f 100644
--- a/firmware/target/arm/usb-fw-pp502x.c
+++ b/firmware/target/arm/usb-fw-pp502x.c
@@ -92,7 +92,7 @@ void usb_init_device(void)
void usb_enable(bool on)
{
#ifdef HAVE_USBSTACK
- (void)on;
+ (void)on;
#else
/* This device specific code will eventually give way to proper USB
handling, which should be the same for all PP502x targets. */
@@ -124,18 +124,42 @@ void usb_enable(bool on)
#endif /* !HAVE_USBSTACK */
}
-bool usb_detect(void)
+int usb_detect(void)
{
+ static int countdown = 0;
+ static int status = USB_EXTRACTED;
static bool prev_usbstatus1 = false;
- bool usbstatus1,usbstatus2;
+ bool usbstatus1, usbstatus2;
#if defined(IPOD_COLOR) || defined(IPOD_4G) \
|| defined(IPOD_MINI) || defined(IPOD_MINI2G)
/* GPIO C bit 1 is firewire detect */
if (!(GPIOC_INPUT_VAL & 0x02))
- return true;
+ return USB_INSERTED;
#endif
+ if (countdown > 0)
+ {
+ countdown--;
+
+ usbstatus2 = (UDC_PORTSC1 & PORTSCX_CURRENT_CONNECT_STATUS) ? true : false;
+ if ((countdown == 0) || usbstatus2)
+ {
+ countdown = 0;
+ status = usbstatus2 ? USB_INSERTED : USB_POWERED;
+ dr_controller_stop();
+
+#ifdef HAVE_USBSTACK
+ /* TODO: Move this call - it shouldn't be done in this function */
+ if (status == USB_INSERTED)
+ {
+ usb_stack_start();
+ }
+#endif
+ }
+ return status;
+ }
+
/* UDC_ID should have the bit format:
[31:24] = 0x0
[23:16] = 0x22 (Revision number)
@@ -144,29 +168,51 @@ bool usb_detect(void)
[7:6] = 0x0 (Reserved)
[5:0] = 0x05 (ID) */
if (UDC_ID != 0x22FA05) {
- return false;
+ /* This should never occur - do we even need to test? */
+ return USB_EXTRACTED;
}
usbstatus1 = (UDC_OTGSC & 0x800) ? true : false;
+
+ if (usbstatus1 == prev_usbstatus1)
+ {
+ /* Nothing has changed, so just return previous status */
+ return status;
+ }
+ prev_usbstatus1 = usbstatus1;
+
+ if (!usbstatus1)
+ { /* We have just been disconnected */
+ status = USB_EXTRACTED;
#ifdef HAVE_USBSTACK
- if ((usbstatus1 == true) && (prev_usbstatus1 == false)) {
- usb_stack_start();
- } else if ((usbstatus1 == false) && (prev_usbstatus1 == true)) {
+ /* TODO: Move this call - it shouldn't be done in this function */
usb_stack_stop();
- }
-#else
- if ((usbstatus1 == true) && (prev_usbstatus1 == false)) {
- dr_controller_run();
- } else if ((usbstatus1 == false) && (prev_usbstatus1 == true)) {
- dr_controller_stop();
- }
#endif
- prev_usbstatus1 = usbstatus1;
- usbstatus2 = (UDC_PORTSC1 & PORTSCX_CURRENT_CONNECT_STATUS) ? true : false;
+ return status;
+ }
+
+ /* We now know that we have just been connected to either a charger
+ or a computer */
- if (usbstatus1 && usbstatus2) {
- return true;
- } else {
- return false;
+ if((button_status() & ~USBPOWER_BTN_IGNORE) == USBPOWER_BUTTON)
+ {
+ /* The user wants to charge, so it doesn't matter what we are
+ connected to. */
+
+ status = USB_POWERED;
+ return status;
}
+
+ /* Run the USB controller for long enough to detect if we're connected
+ to a computer, then stop it again. */
+
+ dr_controller_run();
+
+ /* Wait for 50 ticks (500ms) before deciding there is no computer
+ attached. The required value varied a lot between different users
+ when this feature was being tested. */
+
+ countdown = 50;
+
+ return status;
}
diff --git a/firmware/target/coldfire/iaudio/usb-iaudio.c b/firmware/target/coldfire/iaudio/usb-iaudio.c
index 3bd1a7a458..21d69611b7 100644
--- a/firmware/target/coldfire/iaudio/usb-iaudio.c
+++ b/firmware/target/coldfire/iaudio/usb-iaudio.c
@@ -20,6 +20,7 @@
#include <stdbool.h>
#include "cpu.h"
#include "system.h"
+#include "usb.h"
void usb_init_device(void)
{
@@ -30,9 +31,9 @@ void usb_init_device(void)
or_l(0x00800000, &GPIO1_FUNCTION); /* USB detect */
}
-bool usb_detect(void)
+int usb_detect(void)
{
- return (GPIO1_READ & 0x00800000)?true:false;
+ return (GPIO1_READ & 0x00800000) ? USB_INSERTED : USB_EXTRACTED;
}
void usb_enable(bool on)
diff --git a/firmware/target/coldfire/iriver/h100/usb-h100.c b/firmware/target/coldfire/iriver/h100/usb-h100.c
index 3b00e967da..5a2f7f500b 100644
--- a/firmware/target/coldfire/iriver/h100/usb-h100.c
+++ b/firmware/target/coldfire/iriver/h100/usb-h100.c
@@ -21,6 +21,7 @@
#include "cpu.h"
#include "system.h"
#include "kernel.h"
+#include "usb.h"
void usb_init_device(void)
{
@@ -30,9 +31,9 @@ void usb_init_device(void)
or_l(0x01000040, &GPIO_FUNCTION);
}
-bool usb_detect(void)
+int usb_detect(void)
{
- return (GPIO1_READ & 0x80)?true:false;
+ return (GPIO1_READ & 0x80) ? USB_INSERTED : USB_EXTRACTED;
}
void usb_enable(bool on)
diff --git a/firmware/target/coldfire/iriver/h300/usb-h300.c b/firmware/target/coldfire/iriver/h300/usb-h300.c
index d08cc24dba..d50b7bc808 100644
--- a/firmware/target/coldfire/iriver/h300/usb-h300.c
+++ b/firmware/target/coldfire/iriver/h300/usb-h300.c
@@ -21,6 +21,7 @@
#include "cpu.h"
#include "system.h"
#include "kernel.h"
+#include "usb.h"
void usb_init_device(void)
{
@@ -35,9 +36,9 @@ void usb_init_device(void)
or_l(0x03000000, &GPIO_FUNCTION);
}
-bool usb_detect(void)
+int usb_detect(void)
{
- return (GPIO1_READ & 0x80)?true:false;
+ return (GPIO1_READ & 0x80) ? USB_INSERTED : USB_EXTRACTED;
}
void usb_enable(bool on)
diff --git a/firmware/target/sh/archos/fm_v2/usb-fm_v2.c b/firmware/target/sh/archos/fm_v2/usb-fm_v2.c
index 3dcc3559a3..9c641b925a 100644
--- a/firmware/target/sh/archos/fm_v2/usb-fm_v2.c
+++ b/firmware/target/sh/archos/fm_v2/usb-fm_v2.c
@@ -22,10 +22,11 @@
#include "cpu.h"
#include "hwcompat.h"
#include "system.h"
+#include "usb.h"
-bool usb_detect(void)
+int usb_detect(void)
{
- return (adc_read(ADC_USB_POWER) <= 512) ? true : false;
+ return (adc_read(ADC_USB_POWER) <= 512) ? USB_INSERTED : USB_EXTRACTED;
}
void usb_enable(bool on)
diff --git a/firmware/target/sh/archos/ondio/usb-ondio.c b/firmware/target/sh/archos/ondio/usb-ondio.c
index c856f3ae2c..b370fec3d9 100644
--- a/firmware/target/sh/archos/ondio/usb-ondio.c
+++ b/firmware/target/sh/archos/ondio/usb-ondio.c
@@ -23,10 +23,11 @@
#include "cpu.h"
#include "hwcompat.h"
#include "system.h"
+#include "usb.h"
-bool usb_detect(void)
+int usb_detect(void)
{
- return (adc_read(ADC_USB_POWER) <= 512) ? true : false;
+ return (adc_read(ADC_USB_POWER) <= 512) ? USB_INSERTED : USB_EXTRACTED;
}
void usb_enable(bool on)
diff --git a/firmware/target/sh/archos/player/usb-player.c b/firmware/target/sh/archos/player/usb-player.c
index c10e222f0a..e86003f2c2 100644
--- a/firmware/target/sh/archos/player/usb-player.c
+++ b/firmware/target/sh/archos/player/usb-player.c
@@ -20,10 +20,11 @@
#include <stdbool.h>
#include "cpu.h"
#include "system.h"
+#include "usb.h"
-bool usb_detect(void)
+int usb_detect(void)
{
- return (PADR & 0x8000) ? false : true;
+ return (PADR & 0x8000) ? USB_INSERTED : USB_EXTRACTED;
}
void usb_enable(bool on)
diff --git a/firmware/target/sh/archos/recorder/usb-recorder.c b/firmware/target/sh/archos/recorder/usb-recorder.c
index 7ed237068e..dfa8462203 100644
--- a/firmware/target/sh/archos/recorder/usb-recorder.c
+++ b/firmware/target/sh/archos/recorder/usb-recorder.c
@@ -22,10 +22,11 @@
#include "cpu.h"
#include "hwcompat.h"
#include "system.h"
+#include "usb.h"
-bool usb_detect(void)
+int usb_detect(void)
{
- return (adc_read(ADC_USB_POWER) > 500) ? true : false;
+ return (adc_read(ADC_USB_POWER) > 500) ? USB_INSERTED : USB_EXTRACTED;
}
void usb_enable(bool on)