diff options
Diffstat (limited to 'firmware/target/arm/usb-pp.c')
-rw-r--r-- | firmware/target/arm/usb-pp.c | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/firmware/target/arm/usb-pp.c b/firmware/target/arm/usb-pp.c new file mode 100644 index 0000000000..f8d0a836ad --- /dev/null +++ b/firmware/target/arm/usb-pp.c | |||
@@ -0,0 +1,136 @@ | |||
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 | #include "usb-target.h" | ||
43 | |||
44 | void usb_init_device(void) | ||
45 | { | ||
46 | int r0; | ||
47 | outl(inl(0x70000084) | 0x200, 0x70000084); | ||
48 | |||
49 | outl(inl(0x7000002C) | 0x3000000, 0x7000002C); | ||
50 | DEV_EN |= DEV_USB; | ||
51 | |||
52 | DEV_RS |= DEV_USB; /* reset usb start */ | ||
53 | DEV_RS &=~DEV_USB;/* reset usb end */ | ||
54 | |||
55 | DEV_INIT |= INIT_USB; | ||
56 | while ((inl(0x70000028) & 0x80) == 0); | ||
57 | |||
58 | UOG_PORTSC1 |= 0x100; | ||
59 | while ((UOG_PORTSC1 & 0x100) != 0); | ||
60 | |||
61 | UOG_OTGSC |= 0x5F000000; | ||
62 | if( (UOG_OTGSC & 0x100) == 0) { | ||
63 | UOG_USBMODE &=~ 0x3; | ||
64 | UOG_USBMODE |= 0x2; | ||
65 | outl(inl(0x70000028) | 0x4000, 0x70000028); | ||
66 | outl(inl(0x70000028) | 0x2, 0x70000028); | ||
67 | } else { | ||
68 | UOG_USBMODE |= 0x2; | ||
69 | outl(inl(0x70000028) &~0x4000, 0x70000028); | ||
70 | outl(inl(0x70000028) | 0x2, 0x70000028); | ||
71 | } | ||
72 | UOG_USBCMD |= 0x2; | ||
73 | while((UOG_USBCMD & 0x2) != 0); | ||
74 | r0 = UOG_PORTSC1; | ||
75 | |||
76 | /* Note from IPL source (referring to next 5 lines of code: | ||
77 | THIS NEEDS TO BE CHANGED ONCE THERE IS KERNEL USB */ | ||
78 | outl(inl(0x70000020) | 0x80000000, 0x70000020); | ||
79 | DEV_EN |= DEV_USB; | ||
80 | while ((inl(0x70000028) & 0x80) == 0); | ||
81 | outl(inl(0x70000028) | 0x2, 0x70000028); | ||
82 | |||
83 | udelay(0x186A0); | ||
84 | } | ||
85 | |||
86 | void usb_enable(bool on) | ||
87 | { | ||
88 | /* This device specific code will eventually give way to proper USB | ||
89 | handling, which should be the same for all PortalPlayer targets. */ | ||
90 | if (on) | ||
91 | { | ||
92 | #if IPOD_ARCH || defined(IRIVER_H10) || defined (IRIVER_H10_5GB) | ||
93 | /* For the H10 and iPod, we can only do one thing with USB mode - reboot | ||
94 | into the flash-based disk-mode. This does not return. */ | ||
95 | |||
96 | /* The following code is copied from ipodlinux */ | ||
97 | #if defined(IPOD_COLOR) || defined(IPOD_3G) || \ | ||
98 | defined(IPOD_4G) || defined(IPOD_MINI) | ||
99 | unsigned char* storage_ptr = (unsigned char *)0x40017F00; | ||
100 | #elif defined(IPOD_NANO) || defined(IPOD_VIDEO) || defined(IPOD_MINI2G) | ||
101 | unsigned char* storage_ptr = (unsigned char *)0x4001FF00; | ||
102 | #endif | ||
103 | |||
104 | #if defined(IRIVER_H10) || defined (IRIVER_H10_5GB) | ||
105 | if(button_status()==BUTTON_RIGHT) | ||
106 | #endif | ||
107 | { | ||
108 | ata_sleepnow(); /* Immediately spindown the disk. */ | ||
109 | sleep(HZ*2); | ||
110 | #ifdef IPOD_ARCH | ||
111 | memcpy(storage_ptr, "diskmode\0\0hotstuff\0\0\1", 21); | ||
112 | #endif | ||
113 | system_reboot(); /* Reboot */ | ||
114 | } | ||
115 | #endif | ||
116 | } | ||
117 | } | ||
118 | |||
119 | bool usb_detect(void) | ||
120 | { | ||
121 | bool current_status; | ||
122 | |||
123 | /* UOG_ID should have the bit format: | ||
124 | [31:24] = 0x0 | ||
125 | [23:16] = 0x22 (Revision number) | ||
126 | [15:14] = 0x3 (Reserved) | ||
127 | [13:8] = 0x3a (NID - 1's compliment of ID) | ||
128 | [7:6] = 0x0 (Reserved) | ||
129 | [5:0] = 0x05 (ID) */ | ||
130 | if (UOG_ID != 0x22FA05) { | ||
131 | return false; | ||
132 | } | ||
133 | current_status = (UOG_OTGSC & 0x800)?true:false; | ||
134 | |||
135 | return current_status; | ||
136 | } | ||