1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
29 #include "usb-target.h"
30 #include "ccm-imx31.h"
31 #include "power-imx31.h"
32 #include "avic-imx31.h"
35 static int usb_status
= USB_EXTRACTED
;
37 static void enable_transceiver(bool enable
)
41 if (GPIO1_DR
& (1 << 30))
43 imx31_regclr32(&GPIO3_DR
, (1 << 16)); /* Reset ISP1504 */
45 imx31_regset32(&GPIO3_DR
, (1 << 16));
47 imx31_regclr32(&GPIO1_DR
, (1 << 30)); /* Select ISP1504 */
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
;
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
);
76 void usb_init_device(void)
78 /* Do one-time inits */
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);
102 enable_transceiver(false);
103 ccm_module_clock_gating(CG_USBOTG
, CGM_OFF
);
107 void usb_attach(void)
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
)
121 avic_enable_int(INT_USB_OTG
, INT_TYPE_IRQ
, INT_PRIO_DEFAULT
,
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
);