imx31: Rename clkctl-imx31.* to ccm-imx31.* and move up from ...imx31/gigabeat-s...
[kugel-rb.git] / firmware / target / arm / imx31 / gigabeat-s / usb-imx31.c
blob64ff04e7aee909f07831e9d5ebe6b739910d4647
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Linus Nielsen Feltzing
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
22 #include "cpu.h"
23 #include "system.h"
24 #include "kernel.h"
25 #include "ata.h"
26 #include "usb.h"
27 #include "usb_core.h"
28 #include "usb_drv.h"
29 #include "usb-target.h"
30 #include "ccm-imx31.h"
31 #include "power-imx31.h"
32 #include "avic-imx31.h"
33 #include "mc13783.h"
35 static int usb_status = USB_EXTRACTED;
37 static void enable_transceiver(bool enable)
39 if (enable)
41 if (GPIO1_DR & (1 << 30))
43 imx31_regclr32(&GPIO3_DR, (1 << 16)); /* Reset ISP1504 */
44 sleep(HZ/100);
45 imx31_regset32(&GPIO3_DR, (1 << 16));
46 sleep(HZ/10);
47 imx31_regclr32(&GPIO1_DR, (1 << 30)); /* Select ISP1504 */
50 else
52 imx31_regset32(&GPIO1_DR, (1 << 30)); /* Deselect ISP1504 */
56 /* Read the immediate state of the cable from the PMIC */
57 bool usb_plugged(void)
59 return mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_USB4V4S;
62 void usb_connect_event(void)
64 int status = usb_plugged() ? USB_INSERTED : USB_EXTRACTED;
65 usb_status = status;
66 /* Notify power that USB charging is potentially available */
67 charger_usb_detect_event(status);
68 usb_status_event((status == USB_INSERTED) ? USB_POWERED : USB_UNPOWERED);
71 int usb_detect(void)
73 return usb_status;
76 void usb_init_device(void)
78 /* Do one-time inits */
79 usb_drv_startup();
81 /* Initially poll */
82 usb_connect_event();
84 /* Enable PMIC event */
85 mc13783_enable_event(MC13783_USB_EVENT);
88 void usb_enable(bool on)
90 /* Module clock should be on since since this could be called with
91 * OFF initially and writing module registers would hardlock otherwise. */
92 ccm_module_clock_gating(CG_USBOTG, CGM_ON_RUN_WAIT);
93 enable_transceiver(true);
95 if (on)
97 usb_core_init();
99 else
101 usb_core_exit();
102 enable_transceiver(false);
103 ccm_module_clock_gating(CG_USBOTG, CGM_OFF);
107 void usb_attach(void)
109 usb_drv_attach();
112 static void __attribute__((interrupt("IRQ"))) USB_OTG_HANDLER(void)
114 usb_drv_int(); /* Call driver handler */
117 void usb_drv_int_enable(bool enable)
119 if (enable)
121 avic_enable_int(INT_USB_OTG, INT_TYPE_IRQ, INT_PRIO_DEFAULT,
122 USB_OTG_HANDLER);
124 else
126 avic_disable_int(INT_USB_OTG);
130 /* Called during the bus reset interrupt when in detect mode */
131 void usb_drv_usb_detect_event(void)
133 if (usb_drv_powered())
134 usb_status_event(USB_INSERTED);