Remove a warning when building the stack and add some comment in the ifdef hell
[maemo-rb.git] / firmware / target / arm / usb-fw-pp502x.c
blob76bd7281f5c2752a0f68ddc42509ca48ab2122ce
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
24 #include "config.h"
25 #include "system.h"
26 #include "usb.h"
27 #include "button.h"
28 #include "ata.h"
29 #include "string.h"
30 #include "arcotg_udc.h"
32 #ifdef HAVE_USBSTACK
33 #include "usbstack.h"
34 #endif
36 void usb_init_device(void)
38 int r0;
39 outl(inl(0x70000084) | 0x200, 0x70000084);
41 outl(inl(0x7000002C) | 0x3000000, 0x7000002C);
42 DEV_EN |= DEV_USB;
44 DEV_RS |= DEV_USB; /* reset usb start */
45 DEV_RS &=~DEV_USB;/* reset usb end */
47 DEV_INIT |= INIT_USB;
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);
59 } else {
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);
69 r0 = UDC_PORTSC1;
71 /* Note from IPL source (referring to next 5 lines of code:
72 THIS NEEDS TO BE CHANGED ONCE THERE IS KERNEL USB */
73 DEV_INIT |= INIT_USB;
74 DEV_EN |= DEV_USB;
75 while ((inl(0x70000028) & 0x80) == 0);
76 outl(inl(0x70000028) | 0x2, 0x70000028);
78 udelay(0x186A0);
80 #ifndef HAVE_USBSTACK
81 dr_controller_setup();
82 #endif
84 #if defined(IPOD_COLOR) || defined(IPOD_4G) \
85 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
86 /* GPIO C bit 1 is firewire detect */
87 GPIOC_ENABLE |= 0x02;
88 GPIOC_OUTPUT_EN &= ~0x02;
89 #endif
92 void usb_enable(bool on)
94 #ifdef HAVE_USBSTACK
95 (void)on;
96 #else
97 /* This device specific code will eventually give way to proper USB
98 handling, which should be the same for all PP502x targets. */
99 if (on)
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. */
110 sleep(HZ*2);
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))
136 return true;
137 #endif
139 /* UDC_ID should have the bit format:
140 [31:24] = 0x0
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)
145 [5:0] = 0x05 (ID) */
146 if (UDC_ID != 0x22FA05) {
147 return false;
150 usbstatus1 = (UDC_OTGSC & 0x800) ? true : false;
151 #ifdef HAVE_USBSTACK
152 if ((usbstatus1 == true) && (prev_usbstatus1 == false)) {
153 usb_stack_start();
154 } else if ((usbstatus1 == false) && (prev_usbstatus1 == true)) {
155 usb_stack_stop();
157 #else
158 if ((usbstatus1 == true) && (prev_usbstatus1 == false)) {
159 dr_controller_run();
160 } else if ((usbstatus1 == false) && (prev_usbstatus1 == true)) {
161 dr_controller_stop();
163 #endif
164 prev_usbstatus1 = usbstatus1;
165 usbstatus2 = (UDC_PORTSC1 & PORTSCX_CURRENT_CONNECT_STATUS) ? true : false;
167 if (usbstatus1 && usbstatus2) {
168 return true;
169 } else {
170 return false;