1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
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
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.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
30 #include "arcotg_udc.h"
36 void usb_init_device(void)
39 outl(inl(0x70000084) | 0x200, 0x70000084);
41 outl(inl(0x7000002C) | 0x3000000, 0x7000002C);
44 DEV_RS
|= DEV_USB
; /* reset usb start */
45 DEV_RS
&=~DEV_USB
;/* reset usb end */
48 while ((inl(0x70000028) & 0x80) == 0);
50 UDC_PORTSC1
|= PORTSCX_PORT_RESET
;
51 while ((UDC_PORTSC1
& PORTSCX_PORT_RESET
) != 0);
53 UDC_OTGSC
|= 0x5F000000;
54 if( (UDC_OTGSC
& 0x100) == 0) {
55 UDC_USBMODE
&=~ USB_MODE_CTRL_MODE_HOST
;
56 UDC_USBMODE
|= USB_MODE_CTRL_MODE_DEVICE
;
57 outl(inl(0x70000028) | 0x4000, 0x70000028);
58 outl(inl(0x70000028) | 0x2, 0x70000028);
60 UDC_USBMODE
|= USB_MODE_CTRL_MODE_DEVICE
;
61 outl(inl(0x70000028) &~0x4000, 0x70000028);
62 outl(inl(0x70000028) | 0x2, 0x70000028);
66 UDC_USBCMD
|= USB_CMD_CTRL_RESET
;
67 while((UDC_USBCMD
& USB_CMD_CTRL_RESET
) != 0);
71 /* Note from IPL source (referring to next 5 lines of code:
72 THIS NEEDS TO BE CHANGED ONCE THERE IS KERNEL USB */
75 while ((inl(0x70000028) & 0x80) == 0);
76 outl(inl(0x70000028) | 0x2, 0x70000028);
81 dr_controller_setup();
84 #if defined(IPOD_COLOR) || defined(IPOD_4G) \
85 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
86 /* GPIO C bit 1 is firewire detect */
88 GPIOC_OUTPUT_EN
&= ~0x02;
92 void usb_enable(bool on
)
97 /* This device specific code will eventually give way to proper USB
98 handling, which should be the same for all PP502x targets. */
101 #if defined(IPOD_ARCH) || defined(IRIVER_H10) || defined (IRIVER_H10_5GB)
102 /* For the H10 and iPod, we can only do one thing with USB mode - reboot
103 into the flash-based disk-mode. This does not return. */
105 #if defined(IRIVER_H10) || defined (IRIVER_H10_5GB)
106 if(button_status()==BUTTON_RIGHT
)
107 #endif /* defined(IRIVER_H10) || defined (IRIVER_H10_5GB) */
109 ata_sleepnow(); /* Immediately spindown the disk. */
112 #ifdef IPOD_ARCH /* The following code is based on ipodlinux */
113 #if CONFIG_CPU == PP5020
114 memcpy((void *)0x40017f00, "diskmode\0\0hotstuff\0\0\1", 21);
115 #elif CONFIG_CPU == PP5022
116 memcpy((void *)0x4001ff00, "diskmode\0\0hotstuff\0\0\1", 21);
117 #endif /* CONFIG_CPU */
118 #endif /* IPOD_ARCH */
120 system_reboot(); /* Reboot */
122 #endif /*defined(IPOD_ARCH) || defined(IRIVER_H10) || defined (IRIVER_H10_5GB)*/
124 #endif /* !HAVE_USBSTACK */
127 bool usb_detect(void)
129 static bool prev_usbstatus1
= false;
130 bool usbstatus1
,usbstatus2
;
132 #if defined(IPOD_COLOR) || defined(IPOD_4G) \
133 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
134 /* GPIO C bit 1 is firewire detect */
135 if (!(GPIOC_INPUT_VAL
& 0x02))
139 /* UDC_ID should have the bit format:
141 [23:16] = 0x22 (Revision number)
142 [15:14] = 0x3 (Reserved)
143 [13:8] = 0x3a (NID - 1's compliment of ID)
144 [7:6] = 0x0 (Reserved)
146 if (UDC_ID
!= 0x22FA05) {
150 usbstatus1
= (UDC_OTGSC
& 0x800) ? true : false;
152 if ((usbstatus1
== true) && (prev_usbstatus1
== false)) {
154 } else if ((usbstatus1
== false) && (prev_usbstatus1
== true)) {
158 if ((usbstatus1
== true) && (prev_usbstatus1
== false)) {
160 } else if ((usbstatus1
== false) && (prev_usbstatus1
== true)) {
161 dr_controller_stop();
164 prev_usbstatus1
= usbstatus1
;
165 usbstatus2
= (UDC_PORTSC1
& PORTSCX_CURRENT_CONNECT_STATUS
) ? true : false;
167 if (usbstatus1
&& usbstatus2
) {