diff options
Diffstat (limited to 'firmware/target/arm/ipod/usb-ipod.c')
-rw-r--r-- | firmware/target/arm/ipod/usb-ipod.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/firmware/target/arm/ipod/usb-ipod.c b/firmware/target/arm/ipod/usb-ipod.c new file mode 100644 index 0000000000..c481355768 --- /dev/null +++ b/firmware/target/arm/ipod/usb-ipod.c | |||
@@ -0,0 +1,114 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * iPod driver based on code from the ipodlinux project - http://ipodlinux.org | ||
13 | * Adapted for Rockbox in January 2006 | ||
14 | * Original file: podzilla/usb.c | ||
15 | * Copyright (C) 2005 Adam Johnston | ||
16 | * | ||
17 | * All files in this archive are subject to the GNU General Public License. | ||
18 | * See the file COPYING in the source tree root for full license agreement. | ||
19 | * | ||
20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
21 | * KIND, either express or implied. | ||
22 | * | ||
23 | ****************************************************************************/ | ||
24 | #include "config.h" | ||
25 | #include "cpu.h" | ||
26 | #include "kernel.h" | ||
27 | #include "thread.h" | ||
28 | #include "system.h" | ||
29 | #include "debug.h" | ||
30 | #include "ata.h" | ||
31 | #include "fat.h" | ||
32 | #include "disk.h" | ||
33 | #include "panic.h" | ||
34 | #include "lcd.h" | ||
35 | #include "adc.h" | ||
36 | #include "usb.h" | ||
37 | #include "button.h" | ||
38 | #include "sprintf.h" | ||
39 | #include "string.h" | ||
40 | #include "hwcompat.h" | ||
41 | |||
42 | void usb_init_device(void) | ||
43 | { | ||
44 | int r0; | ||
45 | outl(inl(0x70000084) | 0x200, 0x70000084); | ||
46 | |||
47 | outl(inl(0x7000002C) | 0x3000000, 0x7000002C); | ||
48 | outl(inl(0x6000600C) | 0x400000, 0x6000600C); | ||
49 | |||
50 | outl(inl(0x60006004) | 0x400000, 0x60006004); /* reset usb start */ | ||
51 | outl(inl(0x60006004) & ~0x400000, 0x60006004); /* reset usb end */ | ||
52 | |||
53 | outl(inl(0x70000020) | 0x80000000, 0x70000020); | ||
54 | while ((inl(0x70000028) & 0x80) == 0); | ||
55 | |||
56 | outl(inl(0xc5000184) | 0x100, 0xc5000184); | ||
57 | while ((inl(0xc5000184) & 0x100) != 0); | ||
58 | |||
59 | outl(inl(0xc50001A4) | 0x5F000000, 0xc50001A4); | ||
60 | if ((inl(0xc50001A4) & 0x100) == 0) { | ||
61 | outl(inl(0xc50001A8) & ~0x3, 0xc50001A8); | ||
62 | outl(inl(0xc50001A8) | 0x2, 0xc50001A8); | ||
63 | outl(inl(0x70000028) | 0x4000, 0x70000028); | ||
64 | outl(inl(0x70000028) | 0x2, 0x70000028); | ||
65 | } else { | ||
66 | outl(inl(0xc50001A8) | 0x3, 0xc50001A8); | ||
67 | outl(inl(0x70000028) &~0x4000, 0x70000028); | ||
68 | outl(inl(0x70000028) | 0x2, 0x70000028); | ||
69 | } | ||
70 | outl(inl(0xc5000140) | 0x2, 0xc5000140); | ||
71 | while((inl(0xc5000140) & 0x2) != 0); | ||
72 | r0 = inl(0xc5000184); | ||
73 | |||
74 | /* Note from IPL source (referring to next 5 lines of code: | ||
75 | THIS NEEDS TO BE CHANGED ONCE THERE IS KERNEL USB */ | ||
76 | outl(inl(0x70000020) | 0x80000000, 0x70000020); | ||
77 | outl(inl(0x6000600C) | 0x400000, 0x6000600C); | ||
78 | while ((inl(0x70000028) & 0x80) == 0); | ||
79 | outl(inl(0x70000028) | 0x2, 0x70000028); | ||
80 | |||
81 | udelay(0x186A0); | ||
82 | } | ||
83 | |||
84 | void usb_enable(bool on) | ||
85 | { | ||
86 | /* For the ipod, we can only do one thing with USB mode - reboot | ||
87 | into Apple's flash-based disk-mode. This does not return. */ | ||
88 | if (on) | ||
89 | { | ||
90 | /* The following code is copied from ipodlinux */ | ||
91 | #if defined(IPOD_COLOR) || defined(IPOD_3G) || \ | ||
92 | defined(IPOD_4G) || defined(IPOD_MINI) | ||
93 | unsigned char* storage_ptr = (unsigned char *)0x40017F00; | ||
94 | #elif defined(IPOD_NANO) || defined(IPOD_VIDEO) || defined(IPOD_MINI2G) | ||
95 | unsigned char* storage_ptr = (unsigned char *)0x4001FF00; | ||
96 | #endif | ||
97 | memcpy(storage_ptr, "diskmode\0\0hotstuff\0\0\1", 21); | ||
98 | DEV_RS |= 4; /* Reboot */ | ||
99 | } | ||
100 | } | ||
101 | |||
102 | bool usb_detect(void) | ||
103 | { | ||
104 | bool current_status; | ||
105 | |||
106 | /* The following check is in the ipodlinux source, with the | ||
107 | comment "USB2D_IDENT is bad" if USB2D_IDENT != 0x22FA05 */ | ||
108 | if (USB2D_IDENT != 0x22FA05) { | ||
109 | return false; | ||
110 | } | ||
111 | current_status = (USB_STATUS & 0x800)?true:false; | ||
112 | |||
113 | return current_status; | ||
114 | } | ||