2008-11-10 11:04:43 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright © 2008 Rafaël Carré
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2009-04-12 19:08:26 +00:00
|
|
|
#include "config.h"
|
2011-01-29 00:44:59 +00:00
|
|
|
#include "system.h"
|
2008-11-10 11:04:43 +00:00
|
|
|
#include "usb.h"
|
2009-10-15 10:23:18 +00:00
|
|
|
#ifdef HAVE_USBSTACK
|
2009-10-15 10:03:20 +00:00
|
|
|
#include "usb_core.h"
|
2009-10-15 10:23:18 +00:00
|
|
|
#endif
|
2008-11-10 11:04:43 +00:00
|
|
|
#include "power.h"
|
2008-12-29 23:32:11 +00:00
|
|
|
#include "as3525.h"
|
2011-12-21 18:02:50 +00:00
|
|
|
#include "usb_drv.h"
|
2016-07-31 01:52:22 +00:00
|
|
|
#if CONFIG_USBOTG == USBOTG_DESIGNWARE
|
|
|
|
#include "usb-designware.h"
|
|
|
|
|
|
|
|
const struct usb_dw_config usb_dw_config =
|
|
|
|
{
|
|
|
|
.phytype = DWC_PHYTYPE_UTMI_16,
|
|
|
|
|
|
|
|
/* Available FIFO memory: 0x535 words */
|
|
|
|
.rx_fifosz = 0x215,
|
|
|
|
.nptx_fifosz = 0x20, /* 1 dedicated FIFO for IN0 */
|
|
|
|
.ptx_fifosz = 0x100, /* 3 dedicated FIFOs for IN1,IN3,IN5 */
|
|
|
|
|
|
|
|
#ifdef USB_DW_ARCH_SLAVE
|
|
|
|
.disable_double_buffering = false,
|
|
|
|
#else
|
|
|
|
.ahb_burst_len = HBSTLEN_INCR8,
|
|
|
|
.ahb_threshold = 8,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
#endif /* USBOTG_DESIGNWARE */
|
2008-11-10 11:04:43 +00:00
|
|
|
|
2011-01-29 00:44:59 +00:00
|
|
|
static int usb_status = USB_EXTRACTED;
|
|
|
|
|
2008-11-10 11:04:43 +00:00
|
|
|
void usb_enable(bool on)
|
|
|
|
{
|
2014-12-30 16:36:59 +00:00
|
|
|
#if defined(HAVE_USBSTACK)
|
2016-01-18 22:55:22 +00:00
|
|
|
if (on){
|
|
|
|
cpu_boost(1);
|
2009-10-15 10:03:20 +00:00
|
|
|
usb_core_init();
|
2016-01-18 22:55:22 +00:00
|
|
|
} else {
|
2009-10-15 10:03:20 +00:00
|
|
|
usb_core_exit();
|
2016-01-18 22:55:22 +00:00
|
|
|
cpu_boost(0);
|
|
|
|
}
|
2009-10-15 10:23:18 +00:00
|
|
|
#else
|
|
|
|
(void)on;
|
|
|
|
#endif
|
2008-11-10 11:04:43 +00:00
|
|
|
}
|
|
|
|
|
2010-03-23 05:02:37 +00:00
|
|
|
void usb_insert_int(void)
|
|
|
|
{
|
2011-09-14 15:26:57 +00:00
|
|
|
usb_status = USB_INSERTED;
|
2011-09-14 16:00:26 +00:00
|
|
|
#ifdef USB_STATUS_BY_EVENT
|
2011-12-15 00:14:36 +00:00
|
|
|
usb_status_event(USB_INSERTED);
|
2011-09-14 16:00:26 +00:00
|
|
|
#endif
|
2010-03-23 05:02:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void usb_remove_int(void)
|
|
|
|
{
|
2011-01-29 00:44:59 +00:00
|
|
|
usb_status = USB_EXTRACTED;
|
2011-09-14 16:00:26 +00:00
|
|
|
#ifdef USB_STATUS_BY_EVENT
|
2011-12-15 00:14:36 +00:00
|
|
|
usb_status_event(USB_EXTRACTED);
|
2011-09-14 16:00:26 +00:00
|
|
|
#endif
|
2010-12-12 20:03:42 +00:00
|
|
|
}
|
|
|
|
|
2010-03-23 11:13:17 +00:00
|
|
|
int usb_detect(void)
|
2008-11-10 11:04:43 +00:00
|
|
|
{
|
2011-01-29 00:44:59 +00:00
|
|
|
return usb_status;
|
2008-11-10 11:04:43 +00:00
|
|
|
}
|
2011-12-31 18:43:41 +00:00
|
|
|
|
|
|
|
void usb_init_device(void)
|
|
|
|
{
|
2016-07-31 01:52:22 +00:00
|
|
|
#if CONFIG_USBOTG == USBOTG_DESIGNWARE
|
|
|
|
/* Power up the core clocks to allow writing
|
|
|
|
to some registers needed to power it down */
|
|
|
|
usb_dw_target_disable_irq();
|
|
|
|
usb_dw_target_enable_clocks();
|
|
|
|
|
|
|
|
usb_drv_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_dw_target_enable_clocks()
|
|
|
|
{
|
|
|
|
bitset32(&CGU_PERI, CGU_USB_CLOCK_ENABLE);
|
|
|
|
CCU_USB = (CCU_USB & ~(3<<24)) | (1 << 24); /* ?? */
|
|
|
|
/* PHY clock */
|
|
|
|
CGU_USB = 1<<5 /* enable */
|
|
|
|
| 0 << 2
|
|
|
|
| 0; /* source = ? (24MHz crystal?) */
|
|
|
|
|
|
|
|
/* Do something that is probably CCU related but undocumented*/
|
|
|
|
CCU_USB |= 0x1000;
|
|
|
|
CCU_USB &= ~0x300000;
|
|
|
|
|
|
|
|
udelay(400);
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_dw_target_disable_clocks()
|
|
|
|
{
|
|
|
|
CGU_USB = 0;
|
|
|
|
bitclr32(&CGU_PERI, CGU_USB_CLOCK_ENABLE);
|
|
|
|
|
|
|
|
/* reset USB_PHY to prevent power consumption */
|
|
|
|
CCU_SRC = CCU_SRC_USB_PHY_EN;
|
|
|
|
CCU_SRL = CCU_SRL_MAGIC_NUMBER;
|
|
|
|
CCU_SRL = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_dw_target_enable_irq()
|
|
|
|
{
|
|
|
|
VIC_INT_ENABLE = INTERRUPT_USB;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_dw_target_disable_irq()
|
|
|
|
{
|
|
|
|
VIC_INT_EN_CLEAR = INTERRUPT_USB;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_dw_target_clear_irq()
|
|
|
|
{
|
|
|
|
#endif /* USBOTG_DESIGNWARE */
|
2011-12-31 18:43:41 +00:00
|
|
|
}
|