2007-09-21 15:51:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-09-21 15:51:53 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "ata.h"
|
2008-04-01 07:26:24 +00:00
|
|
|
#include "usb.h"
|
2008-04-18 16:42:50 +00:00
|
|
|
#include "usb_core.h"
|
2008-04-20 03:35:21 +00:00
|
|
|
#include "usb_drv.h"
|
2008-07-18 23:28:54 +00:00
|
|
|
#include "usb-target.h"
|
2008-04-18 16:42:50 +00:00
|
|
|
#include "clkctl-imx31.h"
|
|
|
|
#include "mc13783.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2008-04-18 16:42:50 +00:00
|
|
|
static int usb_status = USB_EXTRACTED;
|
|
|
|
|
2008-04-20 03:30:57 +00:00
|
|
|
static void enable_transceiver(bool enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
if (GPIO1_DR & (1 << 30))
|
|
|
|
{
|
2008-05-08 09:03:19 +00:00
|
|
|
imx31_regmod32(&GPIO3_DR, 0, (1 << 16)); /* Reset ISP1504 */
|
|
|
|
sleep(HZ/100);
|
|
|
|
imx31_regmod32(&GPIO3_DR, (1 << 16), (1 << 16));
|
|
|
|
sleep(HZ/10);
|
|
|
|
imx31_regmod32(&GPIO1_DR, 0, (1 << 30)); /* Select ISP1504 */
|
2008-04-20 03:30:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-05-08 09:03:19 +00:00
|
|
|
imx31_regmod32(&GPIO1_DR, (1 << 30), (1 << 30)); /* Deselect ISP1504 */
|
2008-04-20 03:30:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-21 08:42:11 +00:00
|
|
|
void usb_connect_event(void)
|
2008-04-18 16:42:50 +00:00
|
|
|
{
|
2008-05-21 08:42:11 +00:00
|
|
|
uint32_t status = mc13783_read(MC13783_INTERRUPT_SENSE0);
|
|
|
|
usb_status = (status & MC13783_USB4V4S) ? USB_INSERTED : USB_EXTRACTED;
|
2008-04-18 16:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int usb_detect(void)
|
|
|
|
{
|
|
|
|
return usb_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the immediate state of the cable from the PMIC */
|
|
|
|
bool usb_plugged(void)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2008-05-16 06:21:11 +00:00
|
|
|
return mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_USB4V4S;
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void usb_init_device(void)
|
|
|
|
{
|
2008-04-20 03:30:57 +00:00
|
|
|
imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_ON_ALL);
|
|
|
|
|
|
|
|
enable_transceiver(true);
|
|
|
|
|
|
|
|
/* Module will be turned off later after firmware init */
|
|
|
|
usb_drv_startup();
|
|
|
|
|
2008-05-21 08:42:11 +00:00
|
|
|
/* Initially poll */
|
|
|
|
usb_connect_event();
|
|
|
|
|
|
|
|
/* Enable PMIC event */
|
|
|
|
mc13783_enable_event(MC13783_USB4V4_EVENT);
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void usb_enable(bool on)
|
|
|
|
{
|
2008-04-18 16:42:50 +00:00
|
|
|
if (on)
|
|
|
|
{
|
|
|
|
imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_ON_ALL);
|
2008-04-20 03:30:57 +00:00
|
|
|
enable_transceiver(true);
|
2008-04-18 16:42:50 +00:00
|
|
|
usb_core_init();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Module clock should be on since this could be called first */
|
|
|
|
imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_ON_ALL);
|
2008-04-20 03:30:57 +00:00
|
|
|
enable_transceiver(true);
|
2008-04-18 16:42:50 +00:00
|
|
|
usb_core_exit();
|
2008-04-20 03:30:57 +00:00
|
|
|
enable_transceiver(false);
|
2008-04-18 16:42:50 +00:00
|
|
|
imx31_clkctl_module_clock_gating(CG_USBOTG, CGM_OFF);
|
|
|
|
}
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|