📄 hwinit.c
字号:
DEBUGMSG(ZONE_FUNCTION, (TEXT("ConfigOTGClient: Reset\r\n")));
// Do a reset first no matter what
{
temp = (DWORD *)&cmd;
*temp = INREG32(®s->OTG.USBCMD);
cmd.RST = 1;
OUTREG32(®s->OTG.USBCMD, *temp);
while ((INREG32(®s->OTG.USBCMD) & 0x1<<1) == (0x1<<1)){
//DEBUGMSG(ZONE_FUNCTION, (TEXT("USBCMD= 0x%x\r\n"), (INREG32(&(*regs)->OTG.USBCMD))));
Sleep(100);
}
}
// Enable power for OTG on port 1
temp=(DWORD *)&hcs;
*temp=INREG32(®s->OTG.HCSPARAMS);
if (hcs.PPC) {
WORD USB_OTG_PORTSC1_Write_MASK = (0x1<<1)+(0x1<<3)+(0x1<<5);
*temp=INREG32(®s->OTG.PORTSC[0]);
*temp&=~USB_OTG_PORTSC1_Write_MASK;
*temp|=1<<12;
SETREG32(®s->OTG.PORTSC[0], *temp);
}
// reset the usb otg
SETREG32(®s->OTG.USBCMD, (1<<1));
while(INREG32(®s->OTG.USBCMD) & (0x1<<1));
// Set USB Mode
temp=(DWORD *)&mode;
*temp=0;
//DEBUGMSG(ZONE_FUNCTION, (TEXT("Set USB Mode to 2\r\n")));
mode.CM=2;
mode.SLOM=1; // 2.3 hardware and later
OUTREG32(®s->OTG.USBMODE, *temp);
// otg_itc_setup(0);
temp=(DWORD *)&cmd;
*temp=INREG32(®s->OTG.USBCMD);
cmd.ITC=0;
OUTREG32(®s->OTG.USBCMD, *temp);
// otg_frindex_setup(1);
OUTREG32(®s->OTG.FRINDEX, 1);
// otg_set_configflag_on();
OUTREG32(®s->OTG.CONFIGFLAG, 1);
// for debug, just check the Port Reset bit
temp=(DWORD *)&port;
*temp=INREG32(®s->OTG.PORTSC[0]);
DEBUGMSG(ZONE_FUNCTION,(TEXT("ConfigOTGClient: PORTSC 0x%x PR=%d\r\n"), *temp, port.PR));
//DEBUGMSG(ZONE_FUNCTION, (TEXT("Initialize1504 OTG HighSpeed Client\r\n")));
//DumpUSBRegs((PCSP_USB_REGS)(regs));
Initialize1504Client(regs);
}
//-----------------------------------------------------------------------------
//
// Function: InitializeOTGTransceiver
//
// This function is to configure the OTG USB Core.
//
// Parameters:
// pRegs - Pointer to 3 USB Core Registers
// IsHost - TRUE: it is configured as host
// FALSE: it is configured as client
//
// Returns:
// TRUE: Success
// FALSE: Failure
//
//-----------------------------------------------------------------------------
BOOL InitializeOTGTransceiver(PCSP_USB_REGS* regs, BOOL IsHost)
{
// Clear USB Interrupt enable registers
OUTREG32(&(*regs)->OTG.USBINTR, 0);
InitializeCPLD(IsHost);
InitializeMux();
USBClockInit();
if (IsHost)
{
// Stop the controller first
{
USB_USBCMD_T cmd;
USB_USBSTS_T sts;
USB_USBMODE_T mode;
DWORD * temp = (DWORD *)&cmd;
DWORD * temp2 = (DWORD*)&sts;
DWORD *pTmpMode = (DWORD*)&mode;
int nAttempts = 0;
*temp = INREG32(&(*regs)->OTG.USBCMD);
cmd.RS = 0;
OUTREG32(&(*regs)->OTG.USBCMD, *temp);
*pTmpMode = INREG32(&(*regs)->OTG.USBMODE);
if ( mode.CM == 0x3 )
{
*temp2 = INREG32(&(*regs)->OTG.USBSTS);
while ( (sts.HCH == 0) && (nAttempts++ < 50) )
{
Sleep(10);
*temp2 = INREG32(&(*regs)->OTG.USBSTS);
}
}
}
// Do a reset first no matter what
{
USB_USBCMD_T cmd;
DWORD * temp = (DWORD *)&cmd;
*temp = INREG32(&(*regs)->OTG.USBCMD);
cmd.RST = 1;
OUTREG32(&(*regs)->OTG.USBCMD, *temp);
*temp = INREG32(&(*regs)->OTG.USBCMD);
while ( cmd.RST )
{
//DEBUGMSG(ZONE_FUNCTION, (TEXT("USBCMD= 0x%x\r\n"), (INREG32(&(*regs)->OTG.USBCMD))));
Sleep(10);
*temp = INREG32(&(*regs)->OTG.USBCMD);
}
}
// actually set the mode to HOST now
{
USB_USBMODE_T mode;
DWORD *temp = (DWORD *)&mode;
temp = (DWORD *)&mode;
*temp = INREG32(&(*regs)->OTG.USBMODE);
mode.CM = 0x3;
OUTREG32(&(*regs)->OTG.USBMODE, *temp);
}
ConfigOTGHost(*regs);
{ //usb_bypass_inactive()
USB_CTRL_T ctrl;
DWORD * temp=(DWORD *)&ctrl;
*temp=0;
ctrl.BPE=1; // Bypass Enable bit, clear it
CLRREG32(&(*regs)->USB_CTRL, *temp);
}
{
USB_USBMODE_T mode;
DWORD * temp=(DWORD *)&mode;
// Set USB Mode
*temp=0;
mode.CM=3; // Host
//DEBUGMSG(ZONE_FUNCTION, (TEXT("USBMode:H1[0x%x], H2[0x%x], OTG[0x%x]\r\n"),
//INREG32(&(*regs)->H1.USBMODE),INREG32(&(*regs)->H2.USBMODE), INREG32(&(*regs)->OTG.USBMODE)));
OUTREG32(&(*regs)->OTG.USBMODE, *temp);
}
//DEBUGMSG(ZONE_FUNCTION, (TEXT("PowerOnPort\r\n")));
// power on port
{
DWORD *temp;
USB_HCSPARAMS_T hcs;
temp=(DWORD *)&hcs;
*temp=INREG32(&(*regs)->OTG.HCSPARAMS);
if (hcs.PPC)
{
USB_PORTSC_T portsc;
DWORD * temp2= (DWORD *)&portsc;
*temp2 = INREG32(&(*regs)->OTG.PORTSC);
portsc.PP = 1;
SETREG32(&(*regs)->OTG.PORTSC, *temp2);
}
}
//DEBUGMSG(ZONE_FUNCTION, (TEXT("Initialize1504 Host\r\n")));
Initialize1504Host(*regs);
}
else
{
ConfigOTGClient(*regs);
// Reset all interrupts
{
USB_USBSTS_T temp;
DWORD *t=(DWORD*)&temp;
*t=0;
temp.UI=1; temp.UEI=1; temp.PCI=1; temp.FRI=1;
temp.SEI=1; temp.AAI=1; temp.URI=1; temp.SRI=1;
temp.SLI=1; temp.ULPII=1;
OUTREG32(&(*regs)->OTG.USBSTS, *t);
}
}
// Last to do: Enable the ID Pin Interrupt in OTGSC
{
USB_OTGSC_T temp;
DWORD *t = (DWORD *)&temp;
*t = INREG32(&(*regs)->OTG.OTGSC);
temp.IDIE = 1;
OUTREG32(&(*regs)->OTG.OTGSC, *t);
}
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: GetSysIntr
//
// This function is to return the SYSINTR value of the USB OTG Core.
//
// Parameters:
// NULL
//
// Returns:
// SYSINTR_USBOTG
//
//-----------------------------------------------------------------------------
DWORD GetSysIntr(void)
{
return SYSINTR_USBOTG;
}
//-------------------------------------------------------------------------------------------------------
// Function: BSPUsbXvrSetPhyPowerMode - function for platform to call when they want to suspend/resume
// the PHY
//
// Parameters:
// 1) regs - USB registers
// 2) bResume - TRUE - request to resume, FALSE - request suspend
//
// Return:
// NULL
//-----------------------------------------------------------------------------------------------------------
static void BSPUsbXvrSetPhyPowerMode(CSP_USB_REGS *pUSBRegs, BOOL bResume)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("BSPUsbXvrSetPhyPowerMode bResume = %d\r\n"),bResume));
if (bResume)
{
if (INREG32(&pUSBRegs->OTG.PORTSC[0]) & 0x800000)
{
// Clear the PHCD
CLRREG32(&pUSBRegs->OTG.PORTSC[0], INREG32(&pUSBRegs->OTG.PORTSC[0]) & 0x800000);
// Force Resume bit
OUTREG32(&pUSBRegs->OTG.PORTSC[0], INREG32(&pUSBRegs->OTG.PORTSC[0])|0x40);
//DEBUGMSG(ZONE_FUNCTION, (TEXT("Force resume\r\n")));
}
}
else
{
USB_PORTSC_T portsc;
DWORD *temp = (DWORD *)&portsc;
*temp = INREG32(&(pUSBRegs)->OTG.PORTSC);
portsc.PHCD = 1;
OUTREG32(&(pUSBRegs)->OTG.PORTSC, *temp);
}
}
//---------------------------------------------------------------------------------------------
// Function: RegisterCallback - function call by XVC to register the callback function during the
// XVC_Init.
//
// Parameters:
// Pointer to USB Callback function pointers
//
// Return:
// NULL
//------------------------------------------------------------------------------------------------
void RegisterCallback(BSP_USB_CALLBACK_FNS *pfn)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("+RegisterCallback\r\n")));
if (pfn)
{
pfn->pfnUSBPowerDown = NULL;
pfn->pfnUSBPowerUp = NULL;
//pfn->pfnUSBPowerUp = BSPUsbXvrPowerUp;
//pfn->pfnUSBPowerDown = BSPUsbXvrPowerDown;
pfn->pfnUSBSetPhyPowerMode = BSPUsbXvrSetPhyPowerMode;
DEBUGMSG(ZONE_FUNCTION, (TEXT("RegisterCallback for XVC\r\n")));
}
DEBUGMSG(ZONE_FUNCTION, (TEXT("-RegisterCallback\r\n")));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -