summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2007-04-11 20:44:32 +0000
committerJens Arnold <amiconn@rockbox.org>2007-04-11 20:44:32 +0000
commitfad79dc6364e1e0d42216f4636a4fc504a594307 (patch)
tree37e17308c021f63c69f63fa8658c572d879dcce2
parentdfa9f440349d7532423373b2bac5993ee5e958a9 (diff)
downloadrockbox-fad79dc6364e1e0d42216f4636a4fc504a594307.tar.gz
rockbox-fad79dc6364e1e0d42216f4636a4fc504a594307.zip
Moved archos USB handling to target tree. Minor simplification for coldfire (only one usb-target.h).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13110 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/SOURCES4
-rw-r--r--firmware/target/coldfire/usb-target.h (renamed from firmware/target/coldfire/iaudio/usb-target.h)0
-rw-r--r--firmware/target/sh/archos/fm_v2/usb-fm_v2.c46
-rw-r--r--firmware/target/sh/archos/ondio/usb-ondio.c58
-rw-r--r--firmware/target/sh/archos/player/usb-player.c41
-rw-r--r--firmware/target/sh/archos/recorder/usb-recorder.c46
-rw-r--r--firmware/target/sh/usb-target.h (renamed from firmware/target/coldfire/iriver/usb-target.h)2
-rw-r--r--firmware/usb.c78
8 files changed, 197 insertions, 78 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 9f90919817..a05314160d 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -318,6 +318,7 @@ target/sh/archos/ata-as-archos.S
318target/sh/archos/player/button-player.c 318target/sh/archos/player/button-player.c
319target/sh/archos/player/lcd-as-player.S 319target/sh/archos/player/lcd-as-player.S
320target/sh/archos/player/lcd-player.c 320target/sh/archos/player/lcd-player.c
321target/sh/archos/player/usb-player.c
321#endif /* SIMULATOR */ 322#endif /* SIMULATOR */
322#endif /* ARCHOS_PLAYER */ 323#endif /* ARCHOS_PLAYER */
323 324
@@ -328,6 +329,7 @@ target/sh/archos/ata-as-archos.S
328target/sh/archos/lcd-archos-bitmap.c 329target/sh/archos/lcd-archos-bitmap.c
329target/sh/archos/lcd-as-archos-bitmap.S 330target/sh/archos/lcd-as-archos-bitmap.S
330target/sh/archos/recorder/button-recorder.c 331target/sh/archos/recorder/button-recorder.c
332target/sh/archos/recorder/usb-recorder.c
331#endif /* SIMULATOR */ 333#endif /* SIMULATOR */
332#endif /* ARCHOS_RECORDER */ 334#endif /* ARCHOS_RECORDER */
333 335
@@ -338,6 +340,7 @@ target/sh/archos/ata-as-archos.S
338target/sh/archos/lcd-archos-bitmap.c 340target/sh/archos/lcd-archos-bitmap.c
339target/sh/archos/lcd-as-archos-bitmap.S 341target/sh/archos/lcd-as-archos-bitmap.S
340target/sh/archos/fm_v2/button-fm_v2.c 342target/sh/archos/fm_v2/button-fm_v2.c
343target/sh/archos/fm_v2/usb-fm_v2.c
341#endif /* SIMULATOR */ 344#endif /* SIMULATOR */
342#endif /* ARCHOS_FMRECORDER || ARCHOS_RECORDERV2 */ 345#endif /* ARCHOS_FMRECORDER || ARCHOS_RECORDERV2 */
343 346
@@ -346,6 +349,7 @@ target/sh/archos/fm_v2/button-fm_v2.c
346target/sh/archos/lcd-archos-bitmap.c 349target/sh/archos/lcd-archos-bitmap.c
347target/sh/archos/lcd-as-archos-bitmap.S 350target/sh/archos/lcd-as-archos-bitmap.S
348target/sh/archos/ondio/button-ondio.c 351target/sh/archos/ondio/button-ondio.c
352target/sh/archos/ondio/usb-ondio.c
349#endif /* SIMULATOR */ 353#endif /* SIMULATOR */
350#endif /* ARCHOS_ONDIOFM || ARCHOS_ONDIOFM */ 354#endif /* ARCHOS_ONDIOFM || ARCHOS_ONDIOFM */
351 355
diff --git a/firmware/target/coldfire/iaudio/usb-target.h b/firmware/target/coldfire/usb-target.h
index ab8cac6f99..ab8cac6f99 100644
--- a/firmware/target/coldfire/iaudio/usb-target.h
+++ b/firmware/target/coldfire/usb-target.h
diff --git a/firmware/target/sh/archos/fm_v2/usb-fm_v2.c b/firmware/target/sh/archos/fm_v2/usb-fm_v2.c
new file mode 100644
index 0000000000..2b4632e4f7
--- /dev/null
+++ b/firmware/target/sh/archos/fm_v2/usb-fm_v2.c
@@ -0,0 +1,46 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Jens Arnold
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include <stdbool.h>
21#include "adc.h"
22#include "cpu.h"
23#include "hwcompat.h"
24#include "system.h"
25
26bool usb_detect(void)
27{
28 return (adc_read(ADC_USB_POWER) <= 512) ? true : false;
29}
30
31void usb_enable(bool on)
32{
33 if(read_hw_mask() & USB_ACTIVE_HIGH)
34 on = !on;
35
36 if(on)
37 and_b(~0x04, &PADRH); /* enable USB */
38 else
39 or_b(0x04, &PADRH);
40}
41
42void usb_init_device(void)
43{
44 usb_enable(false);
45 or_b(0x04, &PAIORH);
46}
diff --git a/firmware/target/sh/archos/ondio/usb-ondio.c b/firmware/target/sh/archos/ondio/usb-ondio.c
new file mode 100644
index 0000000000..7c09bf3877
--- /dev/null
+++ b/firmware/target/sh/archos/ondio/usb-ondio.c
@@ -0,0 +1,58 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Jens Arnold
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include <stdbool.h>
21#include "adc.h"
22#include "ata_mmc.h"
23#include "cpu.h"
24#include "hwcompat.h"
25#include "system.h"
26
27bool usb_detect(void)
28{
29 return (adc_read(ADC_USB_POWER) <= 512) ? true : false;
30}
31
32void usb_enable(bool on)
33{
34 if (on)
35 {
36 mmc_enable_int_flash_clock(!mmc_detect());
37
38 if (!(read_hw_mask() & MMC_CLOCK_POLARITY))
39 and_b(~0x20, &PBDRH); /* old circuit needs SCK1 = low while on USB */
40 or_b(0x20, &PADRL); /* enable USB */
41 and_b(~0x08, &PADRL); /* assert card detect */
42 }
43 else
44 {
45 if (!(read_hw_mask() & MMC_CLOCK_POLARITY))
46 or_b(0x20, &PBDRH); /* reset SCK1 = high for old circuit */
47 and_b(~0x20, &PADRL); /* disable USB */
48 or_b(0x08, &PADRL); /* deassert card detect */
49 }
50}
51
52void usb_init_device(void)
53{
54 PACR2 &= ~0x04C0; /* use PA3 (card detect) and PA5 (USB enabled) as GPIO */
55 and_b(~0x20, &PADRL); /* disable USB */
56 or_b(0x08, &PADRL); /* deassert card detect */
57 or_b(0x28, &PAIORL); /* output for USB enable and card detect */
58}
diff --git a/firmware/target/sh/archos/player/usb-player.c b/firmware/target/sh/archos/player/usb-player.c
new file mode 100644
index 0000000000..c10e222f0a
--- /dev/null
+++ b/firmware/target/sh/archos/player/usb-player.c
@@ -0,0 +1,41 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Jens Arnold
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include <stdbool.h>
21#include "cpu.h"
22#include "system.h"
23
24bool usb_detect(void)
25{
26 return (PADR & 0x8000) ? false : true;
27}
28
29void usb_enable(bool on)
30{
31 if(on)
32 and_b(~0x04, &PADRH);
33 else
34 or_b(0x04, &PADRH);
35}
36
37void usb_init_device(void)
38{
39 or_b(0x04, &PADRH);
40 or_b(0x04, &PAIORH);
41}
diff --git a/firmware/target/sh/archos/recorder/usb-recorder.c b/firmware/target/sh/archos/recorder/usb-recorder.c
new file mode 100644
index 0000000000..2934b32a3c
--- /dev/null
+++ b/firmware/target/sh/archos/recorder/usb-recorder.c
@@ -0,0 +1,46 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Jens Arnold
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include <stdbool.h>
21#include "adc.h"
22#include "cpu.h"
23#include "hwcompat.h"
24#include "system.h"
25
26bool usb_detect(void)
27{
28 return (adc_read(ADC_USB_POWER) > 500) ? true : false;
29}
30
31void usb_enable(bool on)
32{
33 if(read_hw_mask() & USB_ACTIVE_HIGH)
34 on = !on;
35
36 if(on)
37 and_b(~0x04, &PADRH); /* enable USB */
38 else
39 or_b(0x04, &PADRH);
40}
41
42void usb_init_device(void)
43{
44 usb_enable(false);
45 or_b(0x04, &PAIORH);
46}
diff --git a/firmware/target/coldfire/iriver/usb-target.h b/firmware/target/sh/usb-target.h
index ab8cac6f99..65fa31fb85 100644
--- a/firmware/target/coldfire/iriver/usb-target.h
+++ b/firmware/target/sh/usb-target.h
@@ -7,7 +7,7 @@
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2006 by Linus Nielsen Feltzing 10 * Copyright (C) 2007 by Jens Arnold
11 * 11 *
12 * All files in this archive are subject to the GNU General Public License. 12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement. 13 * See the file COPYING in the source tree root for full license agreement.
diff --git a/firmware/usb.c b/firmware/usb.c
index 13adc3b391..217aaf8b84 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -32,18 +32,11 @@
32#include "disk.h" 32#include "disk.h"
33#include "panic.h" 33#include "panic.h"
34#include "lcd.h" 34#include "lcd.h"
35#include "adc.h"
36#include "usb.h" 35#include "usb.h"
37#include "button.h" 36#include "button.h"
38#include "sprintf.h" 37#include "sprintf.h"
39#include "string.h" 38#include "string.h"
40#include "hwcompat.h"
41#ifdef HAVE_MMC
42#include "ata_mmc.h"
43#endif
44#ifdef TARGET_TREE
45#include "usb-target.h" 39#include "usb-target.h"
46#endif
47#ifdef IRIVER_H300_SERIES 40#ifdef IRIVER_H300_SERIES
48#include "pcf50606.h" /* for pcf50606_usb_charging_... */ 41#include "pcf50606.h" /* for pcf50606_usb_charging_... */
49#endif 42#endif
@@ -56,8 +49,6 @@ bool do_screendump_instead_of_usb = false;
56void screen_dump(void); /* Nasty again. Defined in apps/ too */ 49void screen_dump(void); /* Nasty again. Defined in apps/ too */
57#endif 50#endif
58 51
59#define USB_REALLY_BRAVE
60
61#if !defined(SIMULATOR) && !defined(USB_NONE) 52#if !defined(SIMULATOR) && !defined(USB_NONE)
62 53
63/* Messages from usb_tick and thread states */ 54/* Messages from usb_tick and thread states */
@@ -93,10 +84,7 @@ void screen_dump(void); /* Nasty again. Defined in apps/ too */
93#endif 84#endif
94#endif /* HAVE_USB_POWER */ 85#endif /* HAVE_USB_POWER */
95 86
96/* The ADC tick reads one channel per tick, and we want to check 3 successive 87#define NUM_POLL_READINGS (HZ/5)
97 readings on the USB voltage channel. This doesn't apply to the Player, but
98 debouncing the USB detection port won't hurt us either. */
99#define NUM_POLL_READINGS (NUM_ADC_CHANNELS * 3)
100static int countdown; 88static int countdown;
101 89
102static int usb_state; 90static int usb_state;
@@ -115,46 +103,6 @@ static struct event_queue usb_queue;
115static bool last_usb_status; 103static bool last_usb_status;
116static bool usb_monitor_enabled; 104static bool usb_monitor_enabled;
117 105
118#ifndef TARGET_TREE
119void usb_enable(bool on)
120{
121#ifdef USB_ENABLE_ONDIOSTYLE
122 PACR2 &= ~0x04C0; /* use PA3, PA5 as GPIO */
123 if(on)
124 {
125#ifdef HAVE_MMC
126 mmc_enable_int_flash_clock(!mmc_detect());
127#endif
128 if (!(read_hw_mask() & MMC_CLOCK_POLARITY))
129 and_b(~0x20, &PBDRH); /* old circuit needs SCK1 = low while on USB */
130 or_b(0x20, &PADRL); /* enable USB */
131 and_b(~0x08, &PADRL); /* assert card detect */
132 }
133 else
134 {
135 if (!(read_hw_mask() & MMC_CLOCK_POLARITY))
136 or_b(0x20, &PBDRH); /* reset SCK1 = high for old circuit */
137 and_b(~0x20, &PADRL); /* disable USB */
138 or_b(0x08, &PADRL); /* deassert card detect */
139 }
140 or_b(0x28, &PAIORL); /* output for USB enable and card detect */
141#else
142#ifdef HAVE_LCD_BITMAP
143 if(read_hw_mask() & USB_ACTIVE_HIGH)
144 on = !on;
145#endif
146 if(on)
147 {
148 and_b(~0x04, &PADRH); /* enable USB */
149 }
150 else
151 {
152 or_b(0x04, &PADRH);
153 }
154 or_b(0x04, &PAIORH);
155#endif
156}
157#endif
158 106
159#ifndef BOOTLOADER 107#ifndef BOOTLOADER
160static void usb_slave_mode(bool on) 108static void usb_slave_mode(bool on)
@@ -246,13 +194,9 @@ static void usb_thread(void)
246 if(num_acks_to_expect == 0) 194 if(num_acks_to_expect == 0)
247 { 195 {
248 DEBUGF("All threads have acknowledged the connect.\n"); 196 DEBUGF("All threads have acknowledged the connect.\n");
249#ifdef USB_REALLY_BRAVE
250 usb_slave_mode(true); 197 usb_slave_mode(true);
251 usb_state = USB_INSERTED; 198 usb_state = USB_INSERTED;
252 cpu_idle_mode(true); 199 cpu_idle_mode(true);
253#else
254 system_reboot();
255#endif
256 } 200 }
257 else 201 else
258 { 202 {
@@ -330,23 +274,6 @@ static void usb_thread(void)
330} 274}
331#endif 275#endif
332 276
333#ifndef TARGET_TREE
334bool usb_detect(void)
335{
336 bool current_status;
337
338#ifdef USB_RECORDERSTYLE
339 current_status = (adc_read(ADC_USB_POWER) > 500)?true:false;
340#endif
341#ifdef USB_FMRECORDERSTYLE
342 current_status = (adc_read(ADC_USB_POWER) <= 512)?true:false;
343#endif
344#ifdef USB_PLAYERSTYLE
345 current_status = (PADR & 0x8000)?false:true;
346#endif
347 return current_status;
348}
349#endif
350 277
351#ifndef BOOTLOADER 278#ifndef BOOTLOADER
352static void usb_tick(void) 279static void usb_tick(void)
@@ -402,10 +329,7 @@ void usb_init(void)
402 usb_monitor_enabled = false; 329 usb_monitor_enabled = false;
403 countdown = -1; 330 countdown = -1;
404 331
405#ifdef TARGET_TREE
406 usb_init_device(); 332 usb_init_device();
407#endif
408
409 usb_enable(false); 333 usb_enable(false);
410 334
411 /* We assume that the USB cable is extracted */ 335 /* We assume that the USB cable is extracted */