blob: 437bbd163972071a316de08bd90a1eb37904a2d2 [file] [log] [blame]
Will Robertson590501c2007-09-21 15:51:53 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Linus Nielsen Feltzing
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Will Robertson590501c2007-09-21 15:51:53 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "config.h"
22#include "cpu.h"
23#include "system.h"
24#include "kernel.h"
25#include "ata.h"
Michael Sevakis1cc949c2008-04-01 07:26:24 +000026#include "usb.h"
Michael Sevakis94f7d0f2008-04-18 16:42:50 +000027#include "usb_core.h"
Michael Sevakis0e71c582008-04-20 03:35:21 +000028#include "usb_drv.h"
Michael Sevakis94f7d0f2008-04-18 16:42:50 +000029#include "clkctl-imx31.h"
30#include "mc13783.h"
Will Robertson590501c2007-09-21 15:51:53 +000031
Michael Sevakis94f7d0f2008-04-18 16:42:50 +000032static int usb_status = USB_EXTRACTED;
33
Michael Sevakis9003dbe2008-04-20 03:30:57 +000034static void enable_transceiver(bool enable)
35{
36 if (enable)
37 {
38 if (GPIO1_DR & (1 << 30))
39 {
Michael Sevakis86680e72008-05-08 09:03:19 +000040 imx31_regmod32(&GPIO3_DR, 0, (1 << 16)); /* Reset ISP1504 */
41 sleep(HZ/100);
42 imx31_regmod32(&GPIO3_DR, (1 << 16), (1 << 16));
43 sleep(HZ/10);
44 imx31_regmod32(&GPIO1_DR, 0, (1 << 30)); /* Select ISP1504 */
Michael Sevakis9003dbe2008-04-20 03:30:57 +000045 }
46 }
47 else
48 {
Michael Sevakis86680e72008-05-08 09:03:19 +000049 imx31_regmod32(&GPIO1_DR, (1 << 30), (1 << 30)); /* Deselect ISP1504 */
Michael Sevakis9003dbe2008-04-20 03:30:57 +000050 }
51}
52
Michael Sevakisa9c20f52008-05-21 08:42:11 +000053void usb_connect_event(void)
Will Robertson590501c2007-09-21 15:51:53 +000054{
Michael Sevakisa9c20f52008-05-21 08:42:11 +000055 uint32_t status = mc13783_read(MC13783_INTERRUPT_SENSE0);
56 usb_status = (status & MC13783_USB4V4S) ? USB_INSERTED : USB_EXTRACTED;
Michael Sevakis94f7d0f2008-04-18 16:42:50 +000057}
58
59int usb_detect(void)
60{
61 return usb_status;
62}
63
64/* Read the immediate state of the cable from the PMIC */
65bool usb_plugged(void)
66{
Michael Sevakiscda664b2008-05-16 06:21:11 +000067 return mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_USB4V4S;
Will Robertson590501c2007-09-21 15:51:53 +000068}
69
70void usb_init_device(void)
71{
Michael Sevakis9003dbe2008-04-20 03:30:57 +000072 imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_ON_ALL);
73
74 enable_transceiver(true);
75
76 /* Module will be turned off later after firmware init */
77 usb_drv_startup();
78
Michael Sevakisa9c20f52008-05-21 08:42:11 +000079 /* Initially poll */
80 usb_connect_event();
81
82 /* Enable PMIC event */
83 mc13783_enable_event(MC13783_USB4V4_EVENT);
Will Robertson590501c2007-09-21 15:51:53 +000084}
85
86void usb_enable(bool on)
87{
Michael Sevakis94f7d0f2008-04-18 16:42:50 +000088 if (on)
89 {
90 imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_ON_ALL);
Michael Sevakis9003dbe2008-04-20 03:30:57 +000091 enable_transceiver(true);
Michael Sevakis94f7d0f2008-04-18 16:42:50 +000092 usb_core_init();
93 }
94 else
95 {
96 /* Module clock should be on since this could be called first */
97 imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_ON_ALL);
Michael Sevakis9003dbe2008-04-20 03:30:57 +000098 enable_transceiver(true);
Michael Sevakis94f7d0f2008-04-18 16:42:50 +000099 usb_core_exit();
Michael Sevakis9003dbe2008-04-20 03:30:57 +0000100 enable_transceiver(false);
Michael Sevakis94f7d0f2008-04-18 16:42:50 +0000101 imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_OFF);
102 }
Will Robertson590501c2007-09-21 15:51:53 +0000103}