diff options
author | Dave Chapman <dave@dchapman.com> | 2007-09-04 08:03:07 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2007-09-04 08:03:07 +0000 |
commit | 1672350378c1eb218db319e35e7bf8fa457b1142 (patch) | |
tree | ccffc78a046ce73aa8f49784d5b2a2d26a2bc4d6 /firmware/target | |
parent | 946a815cd4166f8761fac0c9cba0092b871cf900 (diff) | |
download | rockbox-1672350378c1eb218db319e35e7bf8fa457b1142.tar.gz rockbox-1672350378c1eb218db319e35e7bf8fa457b1142.zip |
FS #7691 - improved USB detection on PP devices. This patch modifies the target-tree function usb_detect() on all targets from bool to int, returning USB_INSERTED or USB_EXTRACTED instead of true or false. This was done to enable the PP usb_detect() to check for USB_POWER (either a connection to a USB wall charger, or the user holding "charge mode" button) and return that as a third value.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14600 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target')
-rw-r--r-- | firmware/target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c | 4 | ||||
-rw-r--r-- | firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c | 8 | ||||
-rw-r--r-- | firmware/target/arm/s3c2440/gigabeat-fx/usb-target.h | 1 | ||||
-rw-r--r-- | firmware/target/arm/usb-fw-pp5002.c | 6 | ||||
-rw-r--r-- | firmware/target/arm/usb-fw-pp502x.c | 88 | ||||
-rw-r--r-- | firmware/target/coldfire/iaudio/usb-iaudio.c | 5 | ||||
-rw-r--r-- | firmware/target/coldfire/iriver/h100/usb-h100.c | 5 | ||||
-rw-r--r-- | firmware/target/coldfire/iriver/h300/usb-h300.c | 5 | ||||
-rw-r--r-- | firmware/target/sh/archos/fm_v2/usb-fm_v2.c | 5 | ||||
-rw-r--r-- | firmware/target/sh/archos/ondio/usb-ondio.c | 5 | ||||
-rw-r--r-- | firmware/target/sh/archos/player/usb-player.c | 5 | ||||
-rw-r--r-- | firmware/target/sh/archos/recorder/usb-recorder.c | 5 |
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) | |||
37 | { | 37 | { |
38 | } | 38 | } |
39 | 39 | ||
40 | bool usb_detect(void) | 40 | int usb_detect(void) |
41 | { | 41 | { |
42 | /* TODO: Implement USB_ISP1582 */ | 42 | /* TODO: Implement USB_ISP1582 */ |
43 | return false; | 43 | return USB_EXTRACTED; |
44 | } | 44 | } |
45 | 45 | ||
46 | void usb_enable(bool on) | 46 | 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 @@ | |||
21 | #include "system.h" | 21 | #include "system.h" |
22 | #include "kernel.h" | 22 | #include "kernel.h" |
23 | #include "ata.h" | 23 | #include "ata.h" |
24 | #include "usb.h" | ||
24 | 25 | ||
25 | #define USB_RST_ASSERT GPBDAT &= ~(1 << 4) | 26 | #define USB_RST_ASSERT GPBDAT &= ~(1 << 4) |
26 | #define USB_RST_DEASSERT GPBDAT |= (1 << 4) | 27 | #define USB_RST_DEASSERT GPBDAT |= (1 << 4) |
@@ -35,9 +36,12 @@ | |||
35 | #define USB_CRADLE_BUS_DISABLE GPHDAT &= ~(1 << 8) | 36 | #define USB_CRADLE_BUS_DISABLE GPHDAT &= ~(1 << 8) |
36 | 37 | ||
37 | /* The usb detect is one pin to the cpu active low */ | 38 | /* The usb detect is one pin to the cpu active low */ |
38 | inline bool usb_detect(void) | 39 | int usb_detect(void) |
39 | { | 40 | { |
40 | return USB_UNIT_IS_PRESENT | USB_CRADLE_IS_PRESENT; | 41 | if (USB_UNIT_IS_PRESENT | USB_CRADLE_IS_PRESENT) |
42 | return USB_INSERTED; | ||
43 | else | ||
44 | return USB_EXTRACTED; | ||
41 | } | 45 | } |
42 | 46 | ||
43 | void usb_init_device(void) | 47 | 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 @@ | |||
20 | #define USB_TARGET_H | 20 | #define USB_TARGET_H |
21 | 21 | ||
22 | bool usb_init_device(void); | 22 | bool usb_init_device(void); |
23 | bool usb_detect(void); | ||
24 | void usb_enable(bool on); | 23 | void usb_enable(bool on); |
25 | 24 | ||
26 | #endif | 25 | #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) | |||
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | bool usb_detect(void) | 59 | int usb_detect(void) |
60 | { | 60 | { |
61 | #if defined(IPOD_1G2G) || defined(IPOD_3G) | 61 | #if defined(IPOD_1G2G) || defined(IPOD_3G) |
62 | /* GPIO C bit 7 is firewire detect */ | 62 | /* GPIO C bit 7 is firewire detect */ |
63 | if (!(GPIOC_INPUT_VAL & 0x80)) | 63 | if (!(GPIOC_INPUT_VAL & 0x80)) |
64 | return true; | 64 | return USB_INSERTED; |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | /* TODO: add USB detection for iPod 3rd gen */ | 67 | /* TODO: add USB detection for iPod 3rd gen */ |
68 | 68 | ||
69 | return false; | 69 | return USB_EXTRACTED; |
70 | } | 70 | } |
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) | |||
92 | void usb_enable(bool on) | 92 | void usb_enable(bool on) |
93 | { | 93 | { |
94 | #ifdef HAVE_USBSTACK | 94 | #ifdef HAVE_USBSTACK |
95 | (void)on; | 95 | (void)on; |
96 | #else | 96 | #else |
97 | /* This device specific code will eventually give way to proper USB | 97 | /* This device specific code will eventually give way to proper USB |
98 | handling, which should be the same for all PP502x targets. */ | 98 | handling, which should be the same for all PP502x targets. */ |
@@ -124,18 +124,42 @@ void usb_enable(bool on) | |||
124 | #endif /* !HAVE_USBSTACK */ | 124 | #endif /* !HAVE_USBSTACK */ |
125 | } | 125 | } |
126 | 126 | ||
127 | bool usb_detect(void) | 127 | int usb_detect(void) |
128 | { | 128 | { |
129 | static int countdown = 0; | ||
130 | static int status = USB_EXTRACTED; | ||
129 | static bool prev_usbstatus1 = false; | 131 | static bool prev_usbstatus1 = false; |
130 | bool usbstatus1,usbstatus2; | 132 | bool usbstatus1, usbstatus2; |
131 | 133 | ||
132 | #if defined(IPOD_COLOR) || defined(IPOD_4G) \ | 134 | #if defined(IPOD_COLOR) || defined(IPOD_4G) \ |
133 | || defined(IPOD_MINI) || defined(IPOD_MINI2G) | 135 | || defined(IPOD_MINI) || defined(IPOD_MINI2G) |
134 | /* GPIO C bit 1 is firewire detect */ | 136 | /* GPIO C bit 1 is firewire detect */ |
135 | if (!(GPIOC_INPUT_VAL & 0x02)) | 137 | if (!(GPIOC_INPUT_VAL & 0x02)) |
136 | return true; | 138 | return USB_INSERTED; |
137 | #endif | 139 | #endif |
138 | 140 | ||
141 | if (countdown > 0) | ||
142 | { | ||
143 | countdown--; | ||
144 | |||
145 | usbstatus2 = (UDC_PORTSC1 & PORTSCX_CURRENT_CONNECT_STATUS) ? true : false; | ||
146 | if ((countdown == 0) || usbstatus2) | ||
147 | { | ||
148 | countdown = 0; | ||
149 | status = usbstatus2 ? USB_INSERTED : USB_POWERED; | ||
150 | dr_controller_stop(); | ||
151 | |||
152 | #ifdef HAVE_USBSTACK | ||
153 | /* TODO: Move this call - it shouldn't be done in this function */ | ||
154 | if (status == USB_INSERTED) | ||
155 | { | ||
156 | usb_stack_start(); | ||
157 | } | ||
158 | #endif | ||
159 | } | ||
160 | return status; | ||
161 | } | ||
162 | |||
139 | /* UDC_ID should have the bit format: | 163 | /* UDC_ID should have the bit format: |
140 | [31:24] = 0x0 | 164 | [31:24] = 0x0 |
141 | [23:16] = 0x22 (Revision number) | 165 | [23:16] = 0x22 (Revision number) |
@@ -144,29 +168,51 @@ bool usb_detect(void) | |||
144 | [7:6] = 0x0 (Reserved) | 168 | [7:6] = 0x0 (Reserved) |
145 | [5:0] = 0x05 (ID) */ | 169 | [5:0] = 0x05 (ID) */ |
146 | if (UDC_ID != 0x22FA05) { | 170 | if (UDC_ID != 0x22FA05) { |
147 | return false; | 171 | /* This should never occur - do we even need to test? */ |
172 | return USB_EXTRACTED; | ||
148 | } | 173 | } |
149 | 174 | ||
150 | usbstatus1 = (UDC_OTGSC & 0x800) ? true : false; | 175 | usbstatus1 = (UDC_OTGSC & 0x800) ? true : false; |
176 | |||
177 | if (usbstatus1 == prev_usbstatus1) | ||
178 | { | ||
179 | /* Nothing has changed, so just return previous status */ | ||
180 | return status; | ||
181 | } | ||
182 | prev_usbstatus1 = usbstatus1; | ||
183 | |||
184 | if (!usbstatus1) | ||
185 | { /* We have just been disconnected */ | ||
186 | status = USB_EXTRACTED; | ||
151 | #ifdef HAVE_USBSTACK | 187 | #ifdef HAVE_USBSTACK |
152 | if ((usbstatus1 == true) && (prev_usbstatus1 == false)) { | 188 | /* TODO: Move this call - it shouldn't be done in this function */ |
153 | usb_stack_start(); | ||
154 | } else if ((usbstatus1 == false) && (prev_usbstatus1 == true)) { | ||
155 | usb_stack_stop(); | 189 | usb_stack_stop(); |
156 | } | ||
157 | #else | ||
158 | if ((usbstatus1 == true) && (prev_usbstatus1 == false)) { | ||
159 | dr_controller_run(); | ||
160 | } else if ((usbstatus1 == false) && (prev_usbstatus1 == true)) { | ||
161 | dr_controller_stop(); | ||
162 | } | ||
163 | #endif | 190 | #endif |
164 | prev_usbstatus1 = usbstatus1; | 191 | return status; |
165 | usbstatus2 = (UDC_PORTSC1 & PORTSCX_CURRENT_CONNECT_STATUS) ? true : false; | 192 | } |
193 | |||
194 | /* We now know that we have just been connected to either a charger | ||
195 | or a computer */ | ||
166 | 196 | ||
167 | if (usbstatus1 && usbstatus2) { | 197 | if((button_status() & ~USBPOWER_BTN_IGNORE) == USBPOWER_BUTTON) |
168 | return true; | 198 | { |
169 | } else { | 199 | /* The user wants to charge, so it doesn't matter what we are |
170 | return false; | 200 | connected to. */ |
201 | |||
202 | status = USB_POWERED; | ||
203 | return status; | ||
171 | } | 204 | } |
205 | |||
206 | /* Run the USB controller for long enough to detect if we're connected | ||
207 | to a computer, then stop it again. */ | ||
208 | |||
209 | dr_controller_run(); | ||
210 | |||
211 | /* Wait for 50 ticks (500ms) before deciding there is no computer | ||
212 | attached. The required value varied a lot between different users | ||
213 | when this feature was being tested. */ | ||
214 | |||
215 | countdown = 50; | ||
216 | |||
217 | return status; | ||
172 | } | 218 | } |
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 @@ | |||
20 | #include <stdbool.h> | 20 | #include <stdbool.h> |
21 | #include "cpu.h" | 21 | #include "cpu.h" |
22 | #include "system.h" | 22 | #include "system.h" |
23 | #include "usb.h" | ||
23 | 24 | ||
24 | void usb_init_device(void) | 25 | void usb_init_device(void) |
25 | { | 26 | { |
@@ -30,9 +31,9 @@ void usb_init_device(void) | |||
30 | or_l(0x00800000, &GPIO1_FUNCTION); /* USB detect */ | 31 | or_l(0x00800000, &GPIO1_FUNCTION); /* USB detect */ |
31 | } | 32 | } |
32 | 33 | ||
33 | bool usb_detect(void) | 34 | int usb_detect(void) |
34 | { | 35 | { |
35 | return (GPIO1_READ & 0x00800000)?true:false; | 36 | return (GPIO1_READ & 0x00800000) ? USB_INSERTED : USB_EXTRACTED; |
36 | } | 37 | } |
37 | 38 | ||
38 | void usb_enable(bool on) | 39 | 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 @@ | |||
21 | #include "cpu.h" | 21 | #include "cpu.h" |
22 | #include "system.h" | 22 | #include "system.h" |
23 | #include "kernel.h" | 23 | #include "kernel.h" |
24 | #include "usb.h" | ||
24 | 25 | ||
25 | void usb_init_device(void) | 26 | void usb_init_device(void) |
26 | { | 27 | { |
@@ -30,9 +31,9 @@ void usb_init_device(void) | |||
30 | or_l(0x01000040, &GPIO_FUNCTION); | 31 | or_l(0x01000040, &GPIO_FUNCTION); |
31 | } | 32 | } |
32 | 33 | ||
33 | bool usb_detect(void) | 34 | int usb_detect(void) |
34 | { | 35 | { |
35 | return (GPIO1_READ & 0x80)?true:false; | 36 | return (GPIO1_READ & 0x80) ? USB_INSERTED : USB_EXTRACTED; |
36 | } | 37 | } |
37 | 38 | ||
38 | void usb_enable(bool on) | 39 | 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 @@ | |||
21 | #include "cpu.h" | 21 | #include "cpu.h" |
22 | #include "system.h" | 22 | #include "system.h" |
23 | #include "kernel.h" | 23 | #include "kernel.h" |
24 | #include "usb.h" | ||
24 | 25 | ||
25 | void usb_init_device(void) | 26 | void usb_init_device(void) |
26 | { | 27 | { |
@@ -35,9 +36,9 @@ void usb_init_device(void) | |||
35 | or_l(0x03000000, &GPIO_FUNCTION); | 36 | or_l(0x03000000, &GPIO_FUNCTION); |
36 | } | 37 | } |
37 | 38 | ||
38 | bool usb_detect(void) | 39 | int usb_detect(void) |
39 | { | 40 | { |
40 | return (GPIO1_READ & 0x80)?true:false; | 41 | return (GPIO1_READ & 0x80) ? USB_INSERTED : USB_EXTRACTED; |
41 | } | 42 | } |
42 | 43 | ||
43 | void usb_enable(bool on) | 44 | 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 @@ | |||
22 | #include "cpu.h" | 22 | #include "cpu.h" |
23 | #include "hwcompat.h" | 23 | #include "hwcompat.h" |
24 | #include "system.h" | 24 | #include "system.h" |
25 | #include "usb.h" | ||
25 | 26 | ||
26 | bool usb_detect(void) | 27 | int usb_detect(void) |
27 | { | 28 | { |
28 | return (adc_read(ADC_USB_POWER) <= 512) ? true : false; | 29 | return (adc_read(ADC_USB_POWER) <= 512) ? USB_INSERTED : USB_EXTRACTED; |
29 | } | 30 | } |
30 | 31 | ||
31 | void usb_enable(bool on) | 32 | 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 @@ | |||
23 | #include "cpu.h" | 23 | #include "cpu.h" |
24 | #include "hwcompat.h" | 24 | #include "hwcompat.h" |
25 | #include "system.h" | 25 | #include "system.h" |
26 | #include "usb.h" | ||
26 | 27 | ||
27 | bool usb_detect(void) | 28 | int usb_detect(void) |
28 | { | 29 | { |
29 | return (adc_read(ADC_USB_POWER) <= 512) ? true : false; | 30 | return (adc_read(ADC_USB_POWER) <= 512) ? USB_INSERTED : USB_EXTRACTED; |
30 | } | 31 | } |
31 | 32 | ||
32 | void usb_enable(bool on) | 33 | 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 @@ | |||
20 | #include <stdbool.h> | 20 | #include <stdbool.h> |
21 | #include "cpu.h" | 21 | #include "cpu.h" |
22 | #include "system.h" | 22 | #include "system.h" |
23 | #include "usb.h" | ||
23 | 24 | ||
24 | bool usb_detect(void) | 25 | int usb_detect(void) |
25 | { | 26 | { |
26 | return (PADR & 0x8000) ? false : true; | 27 | return (PADR & 0x8000) ? USB_INSERTED : USB_EXTRACTED; |
27 | } | 28 | } |
28 | 29 | ||
29 | void usb_enable(bool on) | 30 | 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 @@ | |||
22 | #include "cpu.h" | 22 | #include "cpu.h" |
23 | #include "hwcompat.h" | 23 | #include "hwcompat.h" |
24 | #include "system.h" | 24 | #include "system.h" |
25 | #include "usb.h" | ||
25 | 26 | ||
26 | bool usb_detect(void) | 27 | int usb_detect(void) |
27 | { | 28 | { |
28 | return (adc_read(ADC_USB_POWER) > 500) ? true : false; | 29 | return (adc_read(ADC_USB_POWER) > 500) ? USB_INSERTED : USB_EXTRACTED; |
29 | } | 30 | } |
30 | 31 | ||
31 | void usb_enable(bool on) | 32 | void usb_enable(bool on) |