New USB stack
[kugel-rb.git] / firmware / target / arm / usb-fw-pp502x.c
blob2d9a52ead8a2984165587c3f8fd6de2cbb25048c
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 #ifdef HAVE_USBSTACK
31 #include "usb_core.h"
32 #endif
34 void usb_init_device(void)
36 /* enable usb module */
37 GPO32_ENABLE |= 0x200;
39 outl(inl(0x7000002C) | 0x3000000, 0x7000002C);
40 DEV_EN |= DEV_USB;
42 DEV_RS |= DEV_USB; /* reset usb start */
43 DEV_RS &=~DEV_USB;/* reset usb end */
45 DEV_INIT2 |= INIT_USB;
46 while ((inl(0x70000028) & 0x80) == 0);
47 outl(inl(0x70000028) | 0x2, 0x70000028);
48 udelay(0x186A0);
50 #if defined(IPOD_COLOR) || defined(IPOD_4G) \
51 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
52 /* GPIO C bit 1 is firewire detect */
53 GPIOC_ENABLE |= 0x02;
54 GPIOC_OUTPUT_EN &= ~0x02;
55 #endif
58 void usb_enable(bool on)
60 #ifdef HAVE_USBSTACK
61 if (on)
62 usb_core_init();
63 else
64 usb_core_exit();
65 #else
66 /* This device specific code will eventually give way to proper USB
67 handling, which should be the same for all PP502x targets. */
68 if (on)
70 #if defined(IPOD_ARCH) || defined(IRIVER_H10) || defined (IRIVER_H10_5GB) ||\
71 defined(SANSA_C200)
72 /* For the H10 and iPod, we can only do one thing with USB mode - reboot
73 into the flash-based disk-mode. This does not return. */
75 #if defined(IRIVER_H10) || defined (IRIVER_H10_5GB)
76 if(button_status()==BUTTON_RIGHT)
77 #endif /* defined(IRIVER_H10) || defined (IRIVER_H10_5GB) */
79 #ifndef HAVE_FLASH_STORAGE
80 ata_sleepnow(); /* Immediately spindown the disk. */
81 sleep(HZ*2);
82 #endif
84 #ifdef IPOD_ARCH /* The following code is based on ipodlinux */
85 #if CONFIG_CPU == PP5020
86 memcpy((void *)0x40017f00, "diskmode\0\0hotstuff\0\0\1", 21);
87 #elif CONFIG_CPU == PP5022
88 memcpy((void *)0x4001ff00, "diskmode\0\0hotstuff\0\0\1", 21);
89 #endif /* CONFIG_CPU */
90 #endif /* IPOD_ARCH */
92 system_reboot(); /* Reboot */
94 #endif /*defined(IPOD_ARCH) || defined(IRIVER_H10) || defined (IRIVER_H10_5GB)*/
96 #endif /* !HAVE_USBSTACK */
99 int usb_detect(void)
101 #if defined(IPOD_COLOR) || defined(IPOD_4G) \
102 || defined(IPOD_MINI) || defined(IPOD_MINI2G)
103 /* GPIO C bit 1 is firewire detect */
104 if (!(GPIOC_INPUT_VAL & 0x02))
105 return USB_INSERTED;
106 #endif
108 #if defined(SANSA_C200)
109 /* GPIO H bit 1 is usb detect */
110 if (GPIOH_INPUT_VAL & 0x02)
111 return USB_INSERTED;
112 #elif defined(SANSA_E200)
113 /* GPIO B bit 4 is usb detect */
114 if (GPIOB_INPUT_VAL & 0x10)
115 return USB_INSERTED;
116 #elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
117 /* GPIO L bit 2 is usb detect */
118 if (GPIOL_INPUT_VAL & 0x4)
119 return USB_INSERTED;
120 #endif
122 return USB_EXTRACTED;