diff options
Diffstat (limited to 'firmware/target/arm/usb-fw-pp502x.c')
-rw-r--r-- | firmware/target/arm/usb-fw-pp502x.c | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/firmware/target/arm/usb-fw-pp502x.c b/firmware/target/arm/usb-fw-pp502x.c new file mode 100644 index 0000000000..92e3dee562 --- /dev/null +++ b/firmware/target/arm/usb-fw-pp502x.c | |||
@@ -0,0 +1,168 @@ | |||
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 | #include "arcotg_udc.h" | ||
44 | |||
45 | void usb_init_device(void) | ||
46 | { | ||
47 | int r0; | ||
48 | outl(inl(0x70000084) | 0x200, 0x70000084); | ||
49 | |||
50 | outl(inl(0x7000002C) | 0x3000000, 0x7000002C); | ||
51 | DEV_EN |= DEV_USB; | ||
52 | |||
53 | DEV_RS |= DEV_USB; /* reset usb start */ | ||
54 | DEV_RS &=~DEV_USB;/* reset usb end */ | ||
55 | |||
56 | DEV_INIT |= INIT_USB; | ||
57 | while ((inl(0x70000028) & 0x80) == 0); | ||
58 | |||
59 | UDC_PORTSC1 |= PORTSCX_PORT_RESET; | ||
60 | while ((UDC_PORTSC1 & PORTSCX_PORT_RESET) != 0); | ||
61 | |||
62 | UDC_OTGSC |= 0x5F000000; | ||
63 | if( (UDC_OTGSC & 0x100) == 0) { | ||
64 | UDC_USBMODE &=~ USB_MODE_CTRL_MODE_HOST; | ||
65 | UDC_USBMODE |= USB_MODE_CTRL_MODE_DEVICE; | ||
66 | outl(inl(0x70000028) | 0x4000, 0x70000028); | ||
67 | outl(inl(0x70000028) | 0x2, 0x70000028); | ||
68 | } else { | ||
69 | UDC_USBMODE |= USB_MODE_CTRL_MODE_DEVICE; | ||
70 | outl(inl(0x70000028) &~0x4000, 0x70000028); | ||
71 | outl(inl(0x70000028) | 0x2, 0x70000028); | ||
72 | } | ||
73 | |||
74 | |||
75 | UDC_USBCMD |= USB_CMD_CTRL_RESET; | ||
76 | while((UDC_USBCMD & USB_CMD_CTRL_RESET) != 0); | ||
77 | |||
78 | r0 = UDC_PORTSC1; | ||
79 | |||
80 | /* Note from IPL source (referring to next 5 lines of code: | ||
81 | THIS NEEDS TO BE CHANGED ONCE THERE IS KERNEL USB */ | ||
82 | DEV_INIT |= INIT_USB; | ||
83 | DEV_EN |= DEV_USB; | ||
84 | while ((inl(0x70000028) & 0x80) == 0); | ||
85 | outl(inl(0x70000028) | 0x2, 0x70000028); | ||
86 | |||
87 | udelay(0x186A0); | ||
88 | |||
89 | dr_controller_setup(); | ||
90 | |||
91 | #if defined(IPOD_COLOR) || defined(IPOD_4G) \ | ||
92 | || defined(IPOD_MINI) || defined(IPOD_MINI2G) | ||
93 | /* GPIO C bit 1 is firewire detect */ | ||
94 | GPIOC_ENABLE |= 0x02; | ||
95 | GPIOC_OUTPUT_EN &= ~0x02; | ||
96 | #endif | ||
97 | } | ||
98 | |||
99 | void usb_enable(bool on) | ||
100 | { | ||
101 | /* This device specific code will eventually give way to proper USB | ||
102 | handling, which should be the same for all PP502x targets. */ | ||
103 | if (on) | ||
104 | { | ||
105 | #if defined(IPOD_ARCH) || defined(IRIVER_H10) || defined (IRIVER_H10_5GB) | ||
106 | /* For the H10 and iPod, we can only do one thing with USB mode - reboot | ||
107 | into the flash-based disk-mode. This does not return. */ | ||
108 | |||
109 | #if defined(IRIVER_H10) || defined (IRIVER_H10_5GB) | ||
110 | if(button_status()==BUTTON_RIGHT) | ||
111 | #endif | ||
112 | { | ||
113 | ata_sleepnow(); /* Immediately spindown the disk. */ | ||
114 | sleep(HZ*2); | ||
115 | |||
116 | #ifdef IPOD_ARCH /* The following code is based on ipodlinux */ | ||
117 | #if CONFIG_CPU == PP5020 | ||
118 | memcpy((void *)0x40017f00, "diskmode\0\0hotstuff\0\0\1", 21); | ||
119 | #elif CONFIG_CPU == PP5022 | ||
120 | memcpy((void *)0x4001ff00, "diskmode\0\0hotstuff\0\0\1", 21); | ||
121 | #endif | ||
122 | #endif | ||
123 | |||
124 | system_reboot(); /* Reboot */ | ||
125 | } | ||
126 | #endif | ||
127 | } | ||
128 | } | ||
129 | |||
130 | bool usb_detect(void) | ||
131 | { | ||
132 | static bool prev_usbstatus1 = false; | ||
133 | bool usbstatus1,usbstatus2; | ||
134 | |||
135 | #if defined(IPOD_COLOR) || defined(IPOD_4G) \ | ||
136 | || defined(IPOD_MINI) || defined(IPOD_MINI2G) | ||
137 | /* GPIO C bit 1 is firewire detect */ | ||
138 | if (!(GPIOC_INPUT_VAL & 0x02)) | ||
139 | return true; | ||
140 | #endif | ||
141 | |||
142 | /* UDC_ID should have the bit format: | ||
143 | [31:24] = 0x0 | ||
144 | [23:16] = 0x22 (Revision number) | ||
145 | [15:14] = 0x3 (Reserved) | ||
146 | [13:8] = 0x3a (NID - 1's compliment of ID) | ||
147 | [7:6] = 0x0 (Reserved) | ||
148 | [5:0] = 0x05 (ID) */ | ||
149 | if (UDC_ID != 0x22FA05) { | ||
150 | return false; | ||
151 | } | ||
152 | |||
153 | usbstatus1 = (UDC_OTGSC & 0x800) ? true : false; | ||
154 | if ((usbstatus1 == true) && (prev_usbstatus1 == false)) { | ||
155 | dr_controller_run(); | ||
156 | } else if ((usbstatus1 == false) && (prev_usbstatus1 == true)) { | ||
157 | dr_controller_stop(); | ||
158 | } | ||
159 | |||
160 | prev_usbstatus1 = usbstatus1; | ||
161 | usbstatus2 = (UDC_PORTSC1 & PORTSCX_CURRENT_CONNECT_STATUS) ? true : false; | ||
162 | |||
163 | if (usbstatus1 && usbstatus2) { | ||
164 | return true; | ||
165 | } else { | ||
166 | return false; | ||
167 | } | ||
168 | } | ||