2010-05-18 09:58:52 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright © 2010 Amaury Pouly
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "usb.h"
|
|
|
|
#include "usb_drv.h"
|
|
|
|
#include "as3525v2.h"
|
|
|
|
#include "clock-target.h"
|
|
|
|
#include "ascodec.h"
|
|
|
|
#include "as3514.h"
|
2010-06-12 05:26:23 +00:00
|
|
|
#include "stdbool.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "stdio.h"
|
2010-05-18 09:58:52 +00:00
|
|
|
#include "panic.h"
|
2010-06-12 05:26:23 +00:00
|
|
|
#include "mmu-arm.h"
|
|
|
|
#include "system.h"
|
2010-05-18 09:58:52 +00:00
|
|
|
#define LOGF_ENABLE
|
|
|
|
#include "logf.h"
|
|
|
|
#include "usb-drv-as3525v2.h"
|
2010-06-19 20:39:32 +00:00
|
|
|
#include "usb_core.h"
|
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
static int __in_ep_list[NUM_IN_EP] = {IN_EP_LIST};
|
|
|
|
static int __out_ep_list[NUM_OUT_EP] = {OUT_EP_LIST};
|
2010-06-19 20:39:32 +00:00
|
|
|
|
|
|
|
/* iterate through each in/out ep except EP0
|
|
|
|
* 'counter' is the counter, 'ep' is the actual value */
|
|
|
|
#define FOR_EACH_IN_EP(counter, ep) \
|
2010-06-19 20:39:57 +00:00
|
|
|
for(counter = 0, ep = __in_ep_list[0]; counter < NUM_IN_EP; counter++, ep = __in_ep_list[counter])
|
2010-06-19 20:39:32 +00:00
|
|
|
|
|
|
|
#define FOR_EACH_OUT_EP(counter, ep) \
|
2010-06-19 20:39:57 +00:00
|
|
|
for(counter = 0, ep = __out_ep_list[0]; counter < NUM_OUT_EP; counter++, ep = __out_ep_list[counter])
|
2010-05-18 09:58:52 +00:00
|
|
|
|
|
|
|
struct usb_endpoint
|
|
|
|
{
|
|
|
|
void *buf;
|
|
|
|
unsigned int len;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
unsigned int sent;
|
|
|
|
unsigned int received;
|
|
|
|
};
|
|
|
|
bool wait;
|
|
|
|
bool busy;
|
|
|
|
};
|
|
|
|
|
2010-05-18 12:56:14 +00:00
|
|
|
#if 0
|
2010-05-18 09:58:52 +00:00
|
|
|
static struct usb_endpoint endpoints[USB_NUM_ENDPOINTS*2];
|
2010-05-18 12:56:14 +00:00
|
|
|
#endif
|
2010-06-12 05:26:23 +00:00
|
|
|
static struct usb_ctrlrequest ep0_setup_pkt;
|
2010-05-18 09:58:52 +00:00
|
|
|
|
|
|
|
void usb_attach(void)
|
|
|
|
{
|
2010-06-12 05:26:23 +00:00
|
|
|
logf("usb: attach");
|
2010-05-18 09:58:52 +00:00
|
|
|
usb_enable(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usb_delay(void)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
while(i < 0x300)
|
2010-06-19 20:39:32 +00:00
|
|
|
{
|
|
|
|
asm volatile("nop");
|
2010-05-18 09:58:52 +00:00
|
|
|
i++;
|
2010-06-19 20:39:32 +00:00
|
|
|
}
|
2010-05-18 09:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-21 20:25:37 +00:00
|
|
|
#if AS3525_MCLK_SEL != AS3525_CLK_PLLB
|
|
|
|
static inline void usb_enable_pll(void)
|
|
|
|
{
|
|
|
|
CGU_COUNTB = CGU_LOCK_CNT;
|
|
|
|
CGU_PLLB = AS3525_PLLB_SETTING;
|
|
|
|
CGU_PLLBSUP = 0; /* enable PLLB */
|
|
|
|
while(!(CGU_INTCTRL & CGU_PLLB_LOCK)); /* wait until PLLB is locked */
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void usb_disable_pll(void)
|
|
|
|
{
|
|
|
|
CGU_PLLBSUP = CGU_PLL_POWERDOWN;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void usb_enable_pll(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void usb_disable_pll(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif /* AS3525_MCLK_SEL != AS3525_CLK_PLLB */
|
|
|
|
|
2010-05-18 09:58:52 +00:00
|
|
|
static void as3525v2_connect(void)
|
|
|
|
{
|
|
|
|
logf("usb: init as3525v2");
|
|
|
|
/* 1) enable usb core clock */
|
|
|
|
CGU_PERI |= CGU_USB_CLOCK_ENABLE;
|
|
|
|
usb_delay();
|
|
|
|
/* 2) enable usb phy clock */
|
2010-06-21 20:25:37 +00:00
|
|
|
/* PHY clock */
|
|
|
|
#if 0
|
|
|
|
usb_enable_pll();
|
|
|
|
CGU_USB = 1<<5 /* enable */
|
|
|
|
| (CLK_DIV(AS3525_PLLB_FREQ, 48000000) / 2) << 2
|
|
|
|
| 2; /* source = PLLB */
|
|
|
|
#else
|
|
|
|
CGU_USB = 0x20;
|
|
|
|
#endif
|
2010-05-18 09:58:52 +00:00
|
|
|
usb_delay();
|
|
|
|
/* 3) clear "stop pclk" */
|
2010-06-19 20:39:57 +00:00
|
|
|
PCGCCTL &= ~0x1;
|
2010-05-18 09:58:52 +00:00
|
|
|
usb_delay();
|
|
|
|
/* 4) clear "power clamp" */
|
2010-06-19 20:39:57 +00:00
|
|
|
PCGCCTL &= ~0x4;
|
2010-05-18 09:58:52 +00:00
|
|
|
usb_delay();
|
|
|
|
/* 5) clear "reset power down module" */
|
2010-06-19 20:39:57 +00:00
|
|
|
PCGCCTL &= ~0x8;
|
2010-05-18 09:58:52 +00:00
|
|
|
usb_delay();
|
|
|
|
/* 6) set "power on program done" */
|
2010-06-19 20:39:57 +00:00
|
|
|
DCTL |= DCTL_pwronprgdone;
|
2010-05-18 09:58:52 +00:00
|
|
|
usb_delay();
|
|
|
|
/* 7) core soft reset */
|
2010-06-19 20:39:57 +00:00
|
|
|
GRSTCTL |= GRSTCTL_csftrst;
|
2010-05-18 09:58:52 +00:00
|
|
|
usb_delay();
|
|
|
|
/* 8) hclk soft reset */
|
2010-06-19 20:39:57 +00:00
|
|
|
GRSTCTL |= GRSTCTL_hsftrst;
|
2010-05-18 09:58:52 +00:00
|
|
|
usb_delay();
|
|
|
|
/* 9) flush and reset everything */
|
2010-06-19 20:39:57 +00:00
|
|
|
GRSTCTL |= 0x3f;
|
2010-05-18 09:58:52 +00:00
|
|
|
usb_delay();
|
|
|
|
/* 10) force device mode*/
|
2010-06-19 20:39:57 +00:00
|
|
|
GUSBCFG &= ~GUSBCFG_force_host_mode;
|
|
|
|
GUSBCFG |= GUSBCFG_force_device_mode;
|
2010-05-18 09:58:52 +00:00
|
|
|
usb_delay();
|
|
|
|
/* 11) Do something that is probably CCU related but undocumented*/
|
|
|
|
CCU_USB_THINGY &= ~0x1000;
|
|
|
|
usb_delay();
|
2010-05-20 14:54:32 +00:00
|
|
|
CCU_USB_THINGY &= ~0x300000;
|
|
|
|
usb_delay();
|
2010-05-18 09:58:52 +00:00
|
|
|
/* 12) reset usb core parameters (dev addr, speed, ...) */
|
2010-06-19 20:39:57 +00:00
|
|
|
DCFG = 0;
|
2010-05-18 09:58:52 +00:00
|
|
|
usb_delay();
|
|
|
|
}
|
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
static void enable_device_interrupts(void)
|
2010-05-20 14:54:32 +00:00
|
|
|
{
|
|
|
|
/* Clear any pending interrupt */
|
2010-06-19 20:39:57 +00:00
|
|
|
GINTSTS = 0xffffffff;
|
2010-06-19 20:39:32 +00:00
|
|
|
/* Clear any pending otg interrupt */
|
2010-06-19 20:39:57 +00:00
|
|
|
GOTGINT = 0xffffffff;
|
2010-05-20 14:54:32 +00:00
|
|
|
/* Enable interrupts */
|
2010-06-19 20:39:57 +00:00
|
|
|
GINTMSK = GINTMSK_usbreset
|
|
|
|
| GINTMSK_enumdone
|
|
|
|
| GINTMSK_inepintr
|
|
|
|
| GINTMSK_outepintr
|
|
|
|
| GINTMSK_otgintr
|
|
|
|
| GINTMSK_disconnect;
|
2010-05-20 14:54:32 +00:00
|
|
|
}
|
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
static void flush_tx_fifos(int nums)
|
2010-05-19 08:33:50 +00:00
|
|
|
{
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
2010-06-21 20:25:37 +00:00
|
|
|
GRSTCTL = (nums << GRSTCTL_txfnum_bitp)
|
|
|
|
| GRSTCTL_txfflsh_flush;
|
2010-06-19 20:39:57 +00:00
|
|
|
while(GRSTCTL & GRSTCTL_txfflsh_flush && i < 0x300)
|
2010-05-19 08:33:50 +00:00
|
|
|
i++;
|
2010-06-19 20:39:57 +00:00
|
|
|
if(GRSTCTL & GRSTCTL_txfflsh_flush)
|
2010-05-19 08:33:50 +00:00
|
|
|
panicf("usb: hang of flush tx fifos (%x)", nums);
|
|
|
|
/* wait 3 phy clocks */
|
2010-06-12 05:26:23 +00:00
|
|
|
udelay(1);
|
2010-05-19 08:33:50 +00:00
|
|
|
}
|
|
|
|
|
2010-06-19 20:39:32 +00:00
|
|
|
static void reset_endpoints(void)
|
|
|
|
{
|
|
|
|
int i, ep;
|
|
|
|
/* disable all endpoints except EP0 */
|
|
|
|
FOR_EACH_IN_EP(i, ep)
|
2010-06-19 20:39:57 +00:00
|
|
|
if(DIEPCTL(ep) & DEPCTL_epena)
|
|
|
|
DIEPCTL(ep) = DEPCTL_epdis | DEPCTL_snak;
|
2010-06-19 20:39:32 +00:00
|
|
|
else
|
2010-06-19 20:39:57 +00:00
|
|
|
DIEPCTL(ep) = 0;
|
2010-06-19 20:39:32 +00:00
|
|
|
|
|
|
|
FOR_EACH_OUT_EP(i, ep)
|
2010-06-19 20:39:57 +00:00
|
|
|
if(DOEPCTL(ep) & DEPCTL_epena)
|
|
|
|
DOEPCTL(ep) = DEPCTL_epdis | DEPCTL_snak;
|
2010-06-19 20:39:32 +00:00
|
|
|
else
|
2010-06-19 20:39:57 +00:00
|
|
|
DOEPCTL(ep) = 0;
|
2010-06-19 20:39:32 +00:00
|
|
|
/* Setup EP0 OUT with the following parameters:
|
|
|
|
* packet count = 1
|
|
|
|
* setup packet count = 1
|
|
|
|
* transfer size = 64
|
|
|
|
* Setup EP0 IN/OUT with 64 byte maximum packet size and activate both. Enable transfer on EP0 OUT
|
|
|
|
*/
|
|
|
|
|
2010-06-19 20:40:07 +00:00
|
|
|
DOEPTSIZ(0) = (1 << DEPTSIZ0_supcnt_bitp)
|
2010-06-21 20:25:37 +00:00
|
|
|
| (1 << DEPTSIZ0_pkcnt_bitp)
|
|
|
|
| 8;
|
2010-06-19 20:39:32 +00:00
|
|
|
|
|
|
|
/* setup DMA */
|
|
|
|
clean_dcache_range((void*)&ep0_setup_pkt, sizeof ep0_setup_pkt); /* force write back */
|
2010-06-19 20:39:57 +00:00
|
|
|
DOEPDMA(0) = (unsigned long)&ep0_setup_pkt; /* virtual address=physical address */
|
2010-06-19 20:39:32 +00:00
|
|
|
|
|
|
|
/* Enable endpoint, clear nak */
|
2010-06-19 20:39:57 +00:00
|
|
|
DOEPCTL(0) = DEPCTL_epena | DEPCTL_cnak | DEPCTL_usbactep
|
2010-06-21 20:25:37 +00:00
|
|
|
| (DEPCTL_MPS_64 << DEPCTL_mps_bitp);
|
2010-06-19 20:39:32 +00:00
|
|
|
|
|
|
|
/* 64 bytes packet size, active endpoint */
|
2010-06-21 20:25:37 +00:00
|
|
|
DIEPCTL(0) = (DEPCTL_MPS_64 << DEPCTL_mps_bitp)
|
|
|
|
| DEPCTL_usbactep;
|
2010-06-19 20:39:38 +00:00
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
DCTL = DCTL_cgnpinnak | DCTL_cgoutnak;
|
2010-06-19 20:39:32 +00:00
|
|
|
}
|
|
|
|
|
2010-05-20 14:54:32 +00:00
|
|
|
static void core_dev_init(void)
|
|
|
|
{
|
2010-06-19 20:39:57 +00:00
|
|
|
unsigned int num_in_ep = 0;
|
|
|
|
unsigned int num_out_ep = 0;
|
2010-05-20 14:54:32 +00:00
|
|
|
unsigned int i;
|
|
|
|
/* Restart the phy clock */
|
2010-06-19 20:39:57 +00:00
|
|
|
PCGCCTL = 0;
|
2010-05-20 14:54:32 +00:00
|
|
|
/* Set phy speed : high speed */
|
2010-06-19 20:40:07 +00:00
|
|
|
DCFG = (DCFG & ~bitm(DCFG, devspd)) | DCFG_devspd_hs_phy_hs;
|
2010-05-20 14:54:32 +00:00
|
|
|
|
|
|
|
/* Check hardware capabilities */
|
2010-06-19 20:40:07 +00:00
|
|
|
if(extract(GHWCFG2, arch) != GHWCFG2_ARCH_INTERNAL_DMA)
|
|
|
|
panicf("usb: wrong architecture (%ld)", extract(GHWCFG2, arch));
|
|
|
|
if(extract(GHWCFG2, hs_phy_type) != GHWCFG2_PHY_TYPE_UTMI)
|
|
|
|
panicf("usb: wrong HS phy type (%ld)", extract(GHWCFG2, hs_phy_type));
|
|
|
|
if(extract(GHWCFG2, fs_phy_type) != GHWCFG2_PHY_TYPE_UNSUPPORTED)
|
|
|
|
panicf("usb: wrong FS phy type (%ld)", extract(GHWCFG2, fs_phy_type));
|
|
|
|
if(extract(GHWCFG4, utmi_phy_data_width) != 0x2)
|
|
|
|
panicf("usb: wrong utmi data width (%ld)", extract(GHWCFG4, utmi_phy_data_width));
|
|
|
|
if(!(GHWCFG4 & GHWCFG4_ded_fifo_en)) /* it seems to be multiple tx fifo support */
|
2010-05-19 08:33:50 +00:00
|
|
|
panicf("usb: no multiple tx fifo");
|
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
#ifdef USE_CUSTOM_FIFO_LAYOUT
|
2010-06-19 20:40:07 +00:00
|
|
|
if(!(GHWCFG2 & GHWCFG2_dyn_fifo))
|
2010-06-19 20:39:38 +00:00
|
|
|
panicf("usb: no dynamic fifo");
|
2010-06-19 20:39:57 +00:00
|
|
|
if(GRXFSIZ != DATA_FIFO_DEPTH)
|
2010-06-19 20:39:38 +00:00
|
|
|
panicf("usb: wrong data fifo size");
|
2010-06-19 20:39:57 +00:00
|
|
|
#endif /* USE_CUSTOM_FIFO_LAYOUT */
|
2010-06-19 20:39:38 +00:00
|
|
|
|
2010-06-19 20:39:32 +00:00
|
|
|
/* do some logging */
|
2010-06-19 20:39:57 +00:00
|
|
|
logf("hwcfg1: %08lx", GHWCFG1);
|
|
|
|
logf("hwcfg2: %08lx", GHWCFG2);
|
|
|
|
logf("hwcfg3: %08lx", GHWCFG3);
|
|
|
|
logf("hwcfg4: %08lx", GHWCFG4);
|
|
|
|
|
2010-06-19 20:40:07 +00:00
|
|
|
logf("%ld endpoints", extract(GHWCFG2, num_ep));
|
2010-06-19 20:39:57 +00:00
|
|
|
num_in_ep = 0;
|
|
|
|
num_out_ep = 0;
|
2010-06-19 20:40:07 +00:00
|
|
|
for(i = 0; i < extract(GHWCFG2, num_ep); i++)
|
2010-05-19 08:33:50 +00:00
|
|
|
{
|
2010-06-21 20:25:37 +00:00
|
|
|
bool in = false, out = false;
|
|
|
|
switch((GHWCFG1 >> GHWCFG1_epdir_bitp(i)) & GHWCFG1_epdir_bits)
|
|
|
|
{
|
|
|
|
case GHWCFG1_EPDIR_BIDIR: in = out = true; break;
|
|
|
|
case GHWCFG1_EPDIR_IN: in = true; break;
|
|
|
|
case GHWCFG1_EPDIR_OUT: out = true; break;
|
|
|
|
default: panicf("usb: invalid epdir");
|
|
|
|
}
|
|
|
|
/* don't count EP0 which is special and always bidirectional */
|
|
|
|
if(in && i != 0)
|
2010-06-19 20:39:57 +00:00
|
|
|
num_in_ep++;
|
2010-06-21 20:25:37 +00:00
|
|
|
if(out && i != 0)
|
2010-06-19 20:39:57 +00:00
|
|
|
num_out_ep++;
|
2010-06-21 20:25:37 +00:00
|
|
|
logf(" EP%d: IN=%s OUT=%s", i, in ? "yes" : "no", out ? "yes" : "no");
|
2010-05-19 08:33:50 +00:00
|
|
|
}
|
|
|
|
|
2010-06-19 20:40:07 +00:00
|
|
|
if(num_in_ep != extract(GHWCFG4, num_in_ep))
|
|
|
|
panicf("usb: num in ep mismatch(%d,%lu)", num_in_ep, extract(GHWCFG4, num_in_ep));
|
2010-06-19 20:39:57 +00:00
|
|
|
if(num_in_ep != NUM_IN_EP)
|
|
|
|
panicf("usb: num in ep static mismatch(%u,%u)", num_in_ep, NUM_IN_EP);
|
|
|
|
if(num_out_ep != NUM_OUT_EP)
|
|
|
|
panicf("usb: num out ep static mismatch(%u,%u)", num_out_ep, NUM_OUT_EP);
|
2010-05-19 08:33:50 +00:00
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
logf("%d in ep, %d out ep", num_in_ep, num_out_ep);
|
2010-06-19 20:39:38 +00:00
|
|
|
|
2010-05-19 08:33:50 +00:00
|
|
|
logf("initial:");
|
2010-06-19 20:40:07 +00:00
|
|
|
logf(" tot fifo sz: %lx", extract(GHWCFG3, dfifo_len));
|
2010-06-19 20:39:57 +00:00
|
|
|
logf(" rx fifo: [%04x,+%4lx]", 0, GRXFSIZ);
|
|
|
|
logf(" nptx fifo: [%04lx,+%4lx]", GET_FIFOSIZE_START_ADR(GNPTXFSIZ),
|
|
|
|
GET_FIFOSIZE_DEPTH(GNPTXFSIZ));
|
2010-06-19 20:39:38 +00:00
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
#ifdef USE_CUSTOM_FIFO_LAYOUT
|
2010-06-19 20:39:38 +00:00
|
|
|
/* Setup FIFOs */
|
|
|
|
/* Organize FIFO as follow:
|
|
|
|
* 0 -> rxfsize : RX fifo
|
|
|
|
* rxfsize -> rxfsize + nptxfsize : TX fifo for first IN ep
|
|
|
|
* rxfsize + nptxfsize -> rxfsize + 2 * nptxfsize : TX fifo for second IN ep
|
|
|
|
* rxfsize + 2 * nptxfsize -> rxfsize + 3 * nptxfsize : TX fifo for third IN ep
|
|
|
|
* ...
|
|
|
|
*/
|
|
|
|
|
|
|
|
unsigned short adr = 0;
|
2010-06-19 20:39:57 +00:00
|
|
|
unsigned short depth = RX_FIFO_SIZE;
|
|
|
|
GRXFSIZ = depth;
|
2010-06-19 20:39:38 +00:00
|
|
|
adr += depth;
|
2010-06-19 20:39:57 +00:00
|
|
|
depth = NPTX_FIFO_SIZE;
|
|
|
|
GNPTXFSIZ = MAKE_FIFOSIZE_DATA(adr, depth);
|
2010-06-19 20:39:38 +00:00
|
|
|
adr += depth;
|
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
for(i = 1; i <= NUM_IN_EP; i++)
|
2010-06-19 20:39:38 +00:00
|
|
|
{
|
2010-06-19 20:39:57 +00:00
|
|
|
depth = EPTX_FIFO_SIZE;
|
|
|
|
DIEPTXFSIZ(i) = MAKE_FIFOSIZE_DATA(adr, depth);
|
2010-06-19 20:39:38 +00:00
|
|
|
adr += depth;
|
|
|
|
}
|
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
if(adr > DATA_FIFO_DEPTH)
|
2010-06-19 20:39:38 +00:00
|
|
|
panicf("usb: total data fifo size exceeded");
|
2010-06-19 20:39:57 +00:00
|
|
|
#endif /* USE_CUSTOM_FIFO_LAYOUT */
|
2010-06-19 20:39:38 +00:00
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
for(i = 1; i <= NUM_IN_EP; i++)
|
2010-05-19 08:33:50 +00:00
|
|
|
{
|
2010-05-20 14:54:32 +00:00
|
|
|
logf(" dieptx fifo(%2u): [%04lx,+%4lx]", i,
|
2010-06-19 20:39:57 +00:00
|
|
|
GET_FIFOSIZE_START_ADR(DIEPTXFSIZ(i)),
|
|
|
|
GET_FIFOSIZE_DEPTH(DIEPTXFSIZ(i)));
|
2010-05-19 08:33:50 +00:00
|
|
|
}
|
|
|
|
|
2010-06-19 20:39:38 +00:00
|
|
|
/* Setup interrupt masks for endpoints */
|
2010-06-19 20:39:32 +00:00
|
|
|
/* Setup interrupt masks */
|
2010-06-19 20:39:57 +00:00
|
|
|
DOEPMSK = DOEPINT_setup | DOEPINT_xfercompl | DOEPINT_ahberr
|
|
|
|
| DOEPINT_epdisabled;
|
|
|
|
DIEPMSK = DIEPINT_xfercompl | DIEPINT_timeout
|
|
|
|
| DIEPINT_epdisabled | DIEPINT_ahberr;
|
|
|
|
DAINTMSK = 0xffffffff;
|
2010-05-19 08:33:50 +00:00
|
|
|
|
2010-06-19 20:39:32 +00:00
|
|
|
reset_endpoints();
|
2010-05-19 08:33:50 +00:00
|
|
|
|
2010-05-20 14:54:32 +00:00
|
|
|
/* fixme: threshold tweaking only takes place if we use multiple tx fifos it seems */
|
|
|
|
/* only dump them for now, leave threshold disabled */
|
2010-06-19 20:39:32 +00:00
|
|
|
/*
|
2010-05-20 14:54:32 +00:00
|
|
|
logf("threshold control:");
|
2010-06-19 20:39:57 +00:00
|
|
|
logf(" non_iso_thr_en: %d", (DTHRCTL & DTHRCTL_non_iso_thr_en) ? 1 : 0);
|
|
|
|
logf(" iso_thr_en: %d", (DTHRCTL & DTHRCTL_iso_thr_en) ? 1 : 0);
|
2010-06-19 20:40:07 +00:00
|
|
|
logf(" tx_thr_len: %lu", extract(DTHRCTL, tx_thr_len));
|
2010-06-19 20:39:57 +00:00
|
|
|
logf(" rx_thr_en: %d", (DTHRCTL & DTHRCTL_rx_thr_en) ? 1 : 0);
|
2010-06-19 20:40:07 +00:00
|
|
|
logf(" rx_thr_len: %lu", extract(DTHRCTL, rx_thr_len));
|
2010-06-19 20:39:32 +00:00
|
|
|
*/
|
2010-05-20 14:54:32 +00:00
|
|
|
|
|
|
|
/* enable USB interrupts */
|
2010-06-19 20:39:57 +00:00
|
|
|
enable_device_interrupts();
|
2010-05-18 09:58:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void core_init(void)
|
|
|
|
{
|
2010-06-19 20:39:38 +00:00
|
|
|
/* Disconnect */
|
2010-06-19 20:39:57 +00:00
|
|
|
DCTL |= DCTL_sftdiscon;
|
2010-06-12 05:26:23 +00:00
|
|
|
/* Select UTMI+ 16 */
|
2010-06-19 20:39:57 +00:00
|
|
|
GUSBCFG |= GUSBCFG_phy_if;
|
2010-06-19 20:39:38 +00:00
|
|
|
|
2010-05-18 09:58:52 +00:00
|
|
|
/* fixme: the current code is for internal DMA only, the clip+ architecture
|
|
|
|
* define the internal DMA model */
|
2010-06-12 05:26:23 +00:00
|
|
|
/* Set burstlen and enable DMA*/
|
2010-06-19 20:40:07 +00:00
|
|
|
GAHBCFG = (GAHBCFG_INT_DMA_BURST_INCR4 << GAHBCFG_hburstlen_bitp)
|
2010-06-19 20:39:57 +00:00
|
|
|
| GAHBCFG_dma_enable;
|
2010-05-18 09:58:52 +00:00
|
|
|
/* Disable HNP and SRP, not sure it's useful because we already forced dev mode */
|
2010-06-19 20:39:57 +00:00
|
|
|
GUSBCFG &= ~(GUSBCFG_srpcap | GUSBCFG_hnpcapp);
|
2010-05-19 08:33:50 +00:00
|
|
|
|
|
|
|
/* perform device model specific init */
|
|
|
|
core_dev_init();
|
2010-06-19 20:39:38 +00:00
|
|
|
|
|
|
|
/* Reconnect */
|
2010-06-19 20:39:57 +00:00
|
|
|
DCTL &= ~DCTL_sftdiscon;
|
2010-05-18 09:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
static void enable_global_interrupts(void)
|
2010-05-20 14:54:32 +00:00
|
|
|
{
|
|
|
|
VIC_INT_ENABLE = INTERRUPT_USB;
|
2010-06-19 20:39:57 +00:00
|
|
|
GAHBCFG |= GAHBCFG_glblintrmsk;
|
2010-05-20 14:54:32 +00:00
|
|
|
}
|
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
static void disable_global_interrupts(void)
|
2010-05-20 14:54:32 +00:00
|
|
|
{
|
2010-06-19 20:39:57 +00:00
|
|
|
GAHBCFG &= ~GAHBCFG_glblintrmsk;
|
2010-05-20 14:54:32 +00:00
|
|
|
VIC_INT_EN_CLEAR = INTERRUPT_USB;
|
|
|
|
}
|
|
|
|
|
2010-05-18 09:58:52 +00:00
|
|
|
void usb_drv_init(void)
|
|
|
|
{
|
|
|
|
logf("usb_drv_init");
|
2010-05-20 14:54:32 +00:00
|
|
|
/* Enable PHY and clocks (but leave pullups disabled) */
|
2010-05-18 09:58:52 +00:00
|
|
|
as3525v2_connect();
|
2010-06-19 20:39:57 +00:00
|
|
|
logf("usb: synopsis id: %lx", GSNPSID);
|
2010-05-20 14:54:32 +00:00
|
|
|
/* Core init */
|
2010-05-18 09:58:52 +00:00
|
|
|
core_init();
|
2010-05-20 14:54:32 +00:00
|
|
|
/* Enable global interrupts */
|
2010-06-19 20:39:57 +00:00
|
|
|
enable_global_interrupts();
|
2010-05-18 09:58:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void usb_drv_exit(void)
|
|
|
|
{
|
|
|
|
logf("usb_drv_exit");
|
2010-06-19 20:49:06 +00:00
|
|
|
|
|
|
|
disable_global_interrupts();
|
2010-05-18 09:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
static bool handle_reset(void)
|
2010-06-12 05:26:23 +00:00
|
|
|
{
|
|
|
|
logf("usb: bus reset");
|
2010-06-19 20:39:32 +00:00
|
|
|
|
2010-06-12 05:26:23 +00:00
|
|
|
/* Clear the Remote Wakeup Signalling */
|
2010-06-19 20:39:57 +00:00
|
|
|
DCTL &= ~DCTL_rmtwkupsig;
|
2010-06-12 05:26:23 +00:00
|
|
|
|
2010-06-19 20:39:38 +00:00
|
|
|
/* Flush FIFOs */
|
2010-06-19 20:39:57 +00:00
|
|
|
flush_tx_fifos(0x10);
|
2010-06-12 05:26:23 +00:00
|
|
|
|
2010-06-19 20:39:32 +00:00
|
|
|
reset_endpoints();
|
2010-06-12 05:26:23 +00:00
|
|
|
|
|
|
|
/* Reset Device Address */
|
2010-06-19 20:40:07 +00:00
|
|
|
DCFG &= bitm(DCFG, devadr);
|
2010-06-12 05:26:23 +00:00
|
|
|
|
2010-06-19 20:39:32 +00:00
|
|
|
usb_core_bus_reset();
|
2010-06-12 05:26:23 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-19 20:39:32 +00:00
|
|
|
static bool handle_enum_done(void)
|
|
|
|
{
|
|
|
|
logf("usb: enum done");
|
2010-06-12 05:26:23 +00:00
|
|
|
|
2010-06-19 20:39:32 +00:00
|
|
|
/* read speed */
|
2010-06-19 20:39:57 +00:00
|
|
|
logf("DSTS: %lx", DSTS);
|
|
|
|
logf("DOEPCTL0=%lx", DOEPCTL(0));
|
|
|
|
logf("DOEPTSIZ=%lx", DOEPTSIZ(0));
|
|
|
|
logf("DIEPCTL0=%lx", DIEPCTL(0));
|
|
|
|
logf("DOEPMSK=%lx", DOEPMSK);
|
|
|
|
logf("DIEPMSK=%lx", DIEPMSK);
|
|
|
|
logf("DAINTMSK=%lx", DAINTMSK);
|
|
|
|
logf("DAINT=%lx", DAINT);
|
|
|
|
logf("GINTSTS=%lx", GINTSTS);
|
|
|
|
logf("GINTMSK=%lx", GINTMSK);
|
|
|
|
logf("DCTL=%lx", DCTL);
|
|
|
|
logf("GAHBCFG=%lx", GAHBCFG);
|
|
|
|
logf("GUSBCFG=%lx", GUSBCFG);
|
|
|
|
logf("DCFG=%lx", DCFG);
|
|
|
|
logf("DTHRCTL=%lx", DTHRCTL);
|
|
|
|
|
2010-06-19 20:40:07 +00:00
|
|
|
switch(extract(DSTS, enumspd))
|
2010-06-19 20:39:38 +00:00
|
|
|
{
|
2010-06-19 20:39:57 +00:00
|
|
|
case DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
|
2010-06-19 20:39:38 +00:00
|
|
|
logf("usb: HS");
|
|
|
|
break;
|
2010-06-19 20:39:57 +00:00
|
|
|
case DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
|
|
|
|
case DSTS_ENUMSPD_FS_PHY_48MHZ:
|
2010-06-19 20:39:38 +00:00
|
|
|
logf("usb: FS");
|
|
|
|
break;
|
2010-06-19 20:39:57 +00:00
|
|
|
case DSTS_ENUMSPD_LS_PHY_6MHZ:
|
2010-06-19 20:39:38 +00:00
|
|
|
panicf("usb: LS is not supported");
|
|
|
|
}
|
|
|
|
|
2010-06-19 20:40:07 +00:00
|
|
|
/* fixme: change EP0 mps here */
|
2010-06-12 05:26:23 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool handle_in_ep_int(void)
|
|
|
|
{
|
2010-06-19 20:39:28 +00:00
|
|
|
panicf("usb: in ep int");
|
2010-06-12 05:26:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool handle_out_ep_int(void)
|
|
|
|
{
|
2010-06-19 20:39:28 +00:00
|
|
|
panicf("usb: out ep int");
|
2010-06-12 05:26:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-18 09:58:52 +00:00
|
|
|
/* interrupt service routine */
|
|
|
|
void INT_USB(void)
|
|
|
|
{
|
2010-06-12 05:26:23 +00:00
|
|
|
/* some bits in GINTSTS can be set even though we didn't enable the interrupt source
|
|
|
|
* so AND it with the actual mask */
|
2010-06-19 20:39:57 +00:00
|
|
|
unsigned long sts = GINTSTS & GINTMSK;
|
2010-06-12 05:26:23 +00:00
|
|
|
unsigned long handled_one = 0; /* mask of all listed one (either handled or not) */
|
|
|
|
|
|
|
|
#define HANDLED_CASE(bitmask, callfn) \
|
|
|
|
handled_one |= bitmask; \
|
|
|
|
if(sts & bitmask) \
|
|
|
|
{ \
|
|
|
|
if(!callfn()) \
|
|
|
|
goto Lerr; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define UNHANDLED_CASE(bitmask) \
|
|
|
|
handled_one |= bitmask; \
|
|
|
|
if(sts & bitmask) \
|
|
|
|
goto Lunhandled;
|
|
|
|
|
|
|
|
/* device part */
|
2010-06-19 20:39:57 +00:00
|
|
|
HANDLED_CASE(GINTMSK_usbreset, handle_reset)
|
|
|
|
HANDLED_CASE(GINTMSK_enumdone, handle_enum_done)
|
|
|
|
HANDLED_CASE(GINTMSK_inepintr, handle_in_ep_int)
|
|
|
|
HANDLED_CASE(GINTMSK_outepintr, handle_out_ep_int)
|
2010-06-12 05:26:23 +00:00
|
|
|
|
|
|
|
/* common part */
|
2010-06-19 20:39:57 +00:00
|
|
|
UNHANDLED_CASE(GINTMSK_otgintr)
|
|
|
|
UNHANDLED_CASE(GINTMSK_conidstschng)
|
|
|
|
UNHANDLED_CASE(GINTMSK_disconnect)
|
2010-06-12 05:26:23 +00:00
|
|
|
|
|
|
|
/* unlisted ones */
|
|
|
|
if(sts & ~handled_one)
|
|
|
|
goto Lunhandled;
|
|
|
|
|
2010-06-19 20:39:57 +00:00
|
|
|
GINTSTS = GINTSTS;
|
2010-06-19 20:39:32 +00:00
|
|
|
|
2010-06-12 05:26:23 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Lunhandled:
|
2010-06-19 20:39:32 +00:00
|
|
|
panicf("unhandled usb int: %lx", sts);
|
2010-06-12 05:26:23 +00:00
|
|
|
|
|
|
|
Lerr:
|
2010-06-19 20:39:32 +00:00
|
|
|
panicf("error in usb int: %lx", sts);
|
2010-05-18 09:58:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-19 20:39:28 +00:00
|
|
|
int usb_drv_port_speed(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_drv_request_endpoint(int type, int dir)
|
|
|
|
{
|
|
|
|
(void) type;
|
|
|
|
(void) dir;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_drv_release_endpoint(int ep)
|
|
|
|
{
|
|
|
|
(void) ep;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_drv_cancel_all_transfers(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_drv_recv(int ep, void *ptr, int len)
|
|
|
|
{
|
|
|
|
(void) ep;
|
|
|
|
(void) ptr;
|
|
|
|
(void) len;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_drv_send(int ep, void *ptr, int len)
|
|
|
|
{
|
|
|
|
(void) ep;
|
|
|
|
(void) ptr;
|
|
|
|
(void) len;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usb_drv_send_nonblocking(int ep, void *ptr, int len)
|
|
|
|
{
|
|
|
|
(void) ep;
|
|
|
|
(void) ptr;
|
|
|
|
(void) len;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-18 09:58:52 +00:00
|
|
|
void usb_drv_set_test_mode(int mode)
|
|
|
|
{
|
|
|
|
(void) mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_drv_set_address(int address)
|
|
|
|
{
|
|
|
|
(void) address;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_drv_stall(int ep, bool stall, bool in)
|
|
|
|
{
|
|
|
|
(void) ep;
|
|
|
|
(void) stall;
|
|
|
|
(void) in;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool usb_drv_stalled(int ep, bool in)
|
|
|
|
{
|
|
|
|
(void) ep;
|
|
|
|
(void) in;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|