Hopefully fix FS#8506 (OF cant be loaded on some PP targets). also hopefully fixes...
[Rockbox.git] / firmware / target / arm / usb-fw-pp502x.c
blob47c120715e73a49e130c9152021666097f530006
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
71 void usb_enable(bool on)
73 if (on) {
74 /* if USB is detected, re-enable the USB-devices, otherwise make sure it's disabled */
75 DEV_EN |= DEV_USB0;
76 DEV_EN |= DEV_USB1;
77 DEV_INIT2 |= INIT_USB;
78 usb_core_init();
80 else {
81 usb_core_exit();
82 /* Disable USB devices */
83 DEV_EN &=~ DEV_USB0;
84 DEV_EN &=~ DEV_USB1;
85 DEV_INIT2 &=~ INIT_USB;
89 static bool usb_pin_detect(void)
91 bool retval = false;
93 #if defined(IPOD_4G) || defined(IPOD_COLOR) \
94 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
95 /* GPIO D bit 3 is usb detect */
96 if (GPIOD_INPUT_VAL & 0x08)
97 retval = true;
99 #elif defined(IPOD_NANO) || defined(IPOD_VIDEO)
100 /* GPIO L bit 4 is usb detect */
101 if (GPIOL_INPUT_VAL & 0x10)
102 retval = true;
104 #elif defined(SANSA_C200)
105 /* GPIO H bit 1 is usb detect */
106 if (GPIOH_INPUT_VAL & 0x02)
107 retval = true;
109 #elif defined(SANSA_E200)
110 /* GPIO B bit 4 is usb detect */
111 if (GPIOB_INPUT_VAL & 0x10)
112 retval = true;
114 #elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB) || defined(MROBE_100)
115 /* GPIO L bit 2 is usb detect */
116 if (GPIOL_INPUT_VAL & 0x4)
117 retval = true;
118 #endif
120 return retval;
123 /* detect host or charger (INSERTED or POWERED) */
124 int usb_detect(void)
126 if(usb_pin_detect()) {
127 return USB_INSERTED;
129 else {
130 return USB_EXTRACTED;
134 #if defined(IPOD_COLOR) || defined(IPOD_4G) \
135 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
136 bool firewire_detect(void)
138 /* GPIO C bit 1 is firewire detect */
139 if (!(GPIOC_INPUT_VAL & 0x02))
140 /* no charger detection needed for firewire */
141 return true;
142 else
143 return false;
145 #endif