Make the inital connect problem go away on Gigabeat S. Would be nice if a better...
[kugel-rb.git] / firmware / target / arm / imx31 / gigabeat-s / usb-imx31.c
blobdae5f4676259ed20d6d743944e2e09579936f615
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "config.h"
20 #include "cpu.h"
21 #include "system.h"
22 #include "kernel.h"
23 #include "ata.h"
24 #include "usb.h"
25 #include "usb_core.h"
26 #include "clkctl-imx31.h"
27 #include "mc13783.h"
29 static int usb_status = USB_EXTRACTED;
31 static void enable_transceiver(bool enable)
33 if (enable)
35 if (GPIO1_DR & (1 << 30))
37 GPIO3_DR &= ~(1 << 16); /* Reset ISP1504 */
38 GPIO3_DR |= (1 << 16);
39 GPIO1_DR &= ~(1 << 30); /* Select ISP1504 */
42 else
44 GPIO1_DR |= (1 << 30); /* Deselect ISP1504 */
48 void usb_set_status(bool plugged)
50 usb_status = plugged ? USB_INSERTED : USB_EXTRACTED;
53 int usb_detect(void)
55 return usb_status;
58 /* Read the immediate state of the cable from the PMIC */
59 bool usb_plugged(void)
61 return mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_USB4V4;
64 extern void usb_drv_startup(void);
66 void usb_init_device(void)
68 imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_ON_ALL);
70 enable_transceiver(true);
72 /* Module will be turned off later after firmware init */
73 usb_drv_startup();
75 mc13783_clear(MC13783_INTERRUPT_MASK0, MC13783_USB4V4);
78 void usb_enable(bool on)
80 if (on)
82 imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_ON_ALL);
83 enable_transceiver(true);
84 usb_core_init();
86 else
88 /* Module clock should be on since this could be called first */
89 imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_ON_ALL);
90 enable_transceiver(true);
91 usb_core_exit();
92 enable_transceiver(false);
93 imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_OFF);