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"
|
2010-04-09 01:21:53 +00:00
|
|
|
#include "mc13783.h"
|
2009-03-22 02:13:27 +00:00
|
|
|
#include "ccm-imx31.h"
|
2009-01-19 13:41:25 +00:00
|
|
|
#include "avic-imx31.h"
|
2010-04-09 01:21:53 +00:00
|
|
|
#include "power-gigabeat-s.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-12-19 15:30:30 +00:00
|
|
|
imx31_regclr32(&GPIO3_DR, (1 << 16)); /* Reset ISP1504 */
|
2008-05-08 09:03:19 +00:00
|
|
|
sleep(HZ/100);
|
2008-12-19 15:30:30 +00:00
|
|
|
imx31_regset32(&GPIO3_DR, (1 << 16));
|
2008-05-08 09:03:19 +00:00
|
|
|
sleep(HZ/10);
|
2008-12-19 15:30:30 +00:00
|
|
|
imx31_regclr32(&GPIO1_DR, (1 << 30)); /* Select ISP1504 */
|
2008-04-20 03:30:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-19 15:30:30 +00:00
|
|
|
imx31_regset32(&GPIO1_DR, (1 << 30)); /* Deselect ISP1504 */
|
2008-04-20 03:30:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-22 22:05:04 +00:00
|
|
|
/* Read the immediate state of the cable from the PMIC */
|
|
|
|
bool usb_plugged(void)
|
|
|
|
{
|
|
|
|
return mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_USB4V4S;
|
|
|
|
}
|
|
|
|
|
2008-05-21 08:42:11 +00:00
|
|
|
void usb_connect_event(void)
|
2008-04-18 16:42:50 +00:00
|
|
|
{
|
2009-01-22 22:05:04 +00:00
|
|
|
int status = usb_plugged() ? USB_INSERTED : USB_EXTRACTED;
|
|
|
|
usb_status = status;
|
2008-12-21 18:10:36 +00:00
|
|
|
/* Notify power that USB charging is potentially available */
|
2009-01-22 22:05:04 +00:00
|
|
|
charger_usb_detect_event(status);
|
|
|
|
usb_status_event((status == USB_INSERTED) ? USB_POWERED : USB_UNPOWERED);
|
2008-04-18 16:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int usb_detect(void)
|
|
|
|
{
|
|
|
|
return usb_status;
|
|
|
|
}
|
|
|
|
|
2007-09-21 15:51:53 +00:00
|
|
|
void usb_init_device(void)
|
|
|
|
{
|
2009-01-19 13:41:25 +00:00
|
|
|
/* Do one-time inits */
|
2008-04-20 03:30:57 +00:00
|
|
|
usb_drv_startup();
|
|
|
|
|
2008-05-21 08:42:11 +00:00
|
|
|
/* Initially poll */
|
|
|
|
usb_connect_event();
|
|
|
|
|
|
|
|
/* Enable PMIC event */
|
2008-12-21 18:10:36 +00:00
|
|
|
mc13783_enable_event(MC13783_USB_EVENT);
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void usb_enable(bool on)
|
|
|
|
{
|
2009-01-19 13:41:25 +00:00
|
|
|
/* Module clock should be on since since this could be called with
|
|
|
|
* OFF initially and writing module registers would hardlock otherwise. */
|
2009-03-22 01:50:48 +00:00
|
|
|
ccm_module_clock_gating(CG_USBOTG, CGM_ON_RUN_WAIT);
|
2009-01-19 13:41:25 +00:00
|
|
|
enable_transceiver(true);
|
|
|
|
|
2008-04-18 16:42:50 +00:00
|
|
|
if (on)
|
|
|
|
{
|
|
|
|
usb_core_init();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usb_core_exit();
|
2008-04-20 03:30:57 +00:00
|
|
|
enable_transceiver(false);
|
2009-03-22 01:50:48 +00:00
|
|
|
ccm_module_clock_gating(CG_USBOTG, CGM_OFF);
|
2008-04-18 16:42:50 +00:00
|
|
|
}
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
2009-01-19 13:41:25 +00:00
|
|
|
|
|
|
|
void usb_attach(void)
|
|
|
|
{
|
2009-01-22 22:05:04 +00:00
|
|
|
usb_drv_attach();
|
2009-01-19 13:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __attribute__((interrupt("IRQ"))) USB_OTG_HANDLER(void)
|
|
|
|
{
|
|
|
|
usb_drv_int(); /* Call driver handler */
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_drv_int_enable(bool enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
2009-03-22 01:50:48 +00:00
|
|
|
{
|
|
|
|
avic_enable_int(INT_USB_OTG, INT_TYPE_IRQ, INT_PRIO_DEFAULT,
|
|
|
|
USB_OTG_HANDLER);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
avic_disable_int(INT_USB_OTG);
|
|
|
|
}
|
2009-01-19 13:41:25 +00:00
|
|
|
}
|
2009-01-22 22:05:04 +00:00
|
|
|
|
|
|
|
/* Called during the bus reset interrupt when in detect mode */
|
|
|
|
void usb_drv_usb_detect_event(void)
|
|
|
|
{
|
2009-01-29 01:28:34 +00:00
|
|
|
if (usb_drv_powered())
|
|
|
|
usb_status_event(USB_INSERTED);
|
2009-01-22 22:05:04 +00:00
|
|
|
}
|