Make the inital connect problem go away on Gigabeat S. Would be nice if a better...
[kugel-rb.git] / firmware / target / arm / usb-fw-pp502x.c
blob1caba023e218680c4af71c2790a444c0d8c29b33
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 "usb_core.h"
31 #include "usb_drv.h"
33 void usb_init_device(void)
35 /* enable usb module */
36 outl(inl(0x7000002C) | 0x3000000, 0x7000002C);
38 DEV_EN |= DEV_USB0;
39 DEV_EN |= DEV_USB1;
41 /* reset both USBs */
42 DEV_RS |= DEV_USB0;
43 DEV_RS &=~DEV_USB0;
44 DEV_RS |= DEV_USB1;
45 DEV_RS &=~DEV_USB1;
47 DEV_INIT2 |= INIT_USB;
49 while ((inl(0x70000028) & 0x80) == 0);
50 outl(inl(0x70000028) | 0x2, 0x70000028);
51 udelay(100000);
53 /* disable USB-devices until USB is detected via GPIO */
54 #ifndef BOOTLOADER
55 /* Disabling USB0 in the bootloader makes the OF not load,
56 Also something here breaks usb pin detect in bootloader.
57 leave it all enabled untill rockbox main loads */
58 DEV_EN &= ~DEV_USB0;
59 DEV_EN &= ~DEV_USB1;
60 DEV_INIT2 &= ~INIT_USB;
61 #endif
63 #if defined(IPOD_COLOR) || defined(IPOD_4G) \
64 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
65 /* GPIO C bit 1 is firewire detect */
66 GPIOC_ENABLE |= 0x02;
67 GPIOC_OUTPUT_EN &= ~0x02;
68 #endif
70 #ifdef HAVE_USBSTACK
71 /* Do one-time inits */
72 usb_drv_startup();
73 #endif
76 void usb_enable(bool on)
78 if (on) {
79 /* if USB is detected, re-enable the USB-devices, otherwise make sure it's disabled */
80 DEV_EN |= DEV_USB0;
81 DEV_EN |= DEV_USB1;
82 DEV_INIT2 |= INIT_USB;
83 usb_core_init();
85 else {
86 usb_core_exit();
87 /* Disable USB devices */
88 DEV_EN &=~ DEV_USB0;
89 DEV_EN &=~ DEV_USB1;
90 DEV_INIT2 &=~ INIT_USB;
94 static bool usb_pin_detect(void)
96 bool retval = false;
98 #if defined(IPOD_4G) || defined(IPOD_COLOR) \
99 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
100 /* GPIO D bit 3 is usb detect */
101 if (GPIOD_INPUT_VAL & 0x08)
102 retval = true;
104 #elif defined(IPOD_NANO) || defined(IPOD_VIDEO)
105 /* GPIO L bit 4 is usb detect */
106 if (GPIOL_INPUT_VAL & 0x10)
107 retval = true;
109 #elif defined(SANSA_C200)
110 /* GPIO H bit 1 is usb detect */
111 if (GPIOH_INPUT_VAL & 0x02)
112 retval = true;
114 #elif defined(SANSA_E200)
115 /* GPIO B bit 4 is usb detect */
116 if (GPIOB_INPUT_VAL & 0x10)
117 retval = true;
119 #elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB) || defined(MROBE_100)
120 /* GPIO L bit 2 is usb detect */
121 if (GPIOL_INPUT_VAL & 0x4)
122 retval = true;
123 #endif
125 return retval;
128 /* detect host or charger (INSERTED or POWERED) */
129 int usb_detect(void)
131 if(usb_pin_detect()) {
132 return USB_INSERTED;
134 else {
135 return USB_EXTRACTED;
139 #if defined(IPOD_COLOR) || defined(IPOD_4G) \
140 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
141 bool firewire_detect(void)
143 /* GPIO C bit 1 is firewire detect */
144 if (!(GPIOC_INPUT_VAL & 0x02))
145 /* no charger detection needed for firewire */
146 return true;
147 else
148 return false;
150 #endif