📄 hwinit.c
字号:
// Function: ConfigOTGClient
//
// This function is to configure client functionality on the USB OTG Core.
//
// Parameters:
// pRegs - Pointer to 3 USB Core Registers
//
// Returns:
// NULL
//
//-----------------------------------------------------------------------------
static void ConfigOTGClient(CSP_USB_REGS *pRegs)
{
USB_PORTSC_T Port;
USB_USBCMD_T Cmd;
USB_HCSPARAMS_T Hcs;
DWORD *temp;
DEBUGMSG(1, (TEXT("ConfigOTGClient: Stop controller\r\n")));
// Stop the controller first
Stop(pRegs);
DEBUGMSG(1, (TEXT("ConfigOTGClient: Reset\r\n")));
// Do a reset first no matter what
Reset(pRegs);
// Enable power for OTG on port 1
temp=(DWORD *)&Hcs;
*temp=INREG32(&pRegs->OTG.HCSPARAMS);
if (Hcs.PPC) {
WORD USB_OTG_PORTSC1_Write_MASK = (0x1<<1)+(0x1<<3)+(0x1<<5);
*temp=INREG32(&pRegs->OTG.PORTSC[0]);
*temp&=~USB_OTG_PORTSC1_Write_MASK;
*temp|=1<<12;
SETREG32(&pRegs->OTG.PORTSC[0], *temp);
}
// reset the usb otg
Reset(pRegs);
// Set USB Mode
SetMode(pRegs,CM_DEVICE_CONTROLLER);
// otg_itc_setup(0);
temp=(DWORD *)&Cmd;
*temp=INREG32(&pRegs->OTG.USBCMD);
Cmd.ITC=0;
OUTREG32(&pRegs->OTG.USBCMD, *temp);
// otg_frindex_setup(1);
OUTREG32(&pRegs->OTG.FRINDEX, 1);
// otg_set_configflag_on();
OUTREG32(&pRegs->OTG.CONFIGFLAG, 1);
// for debug, just check the Port Reset bit
temp=(DWORD *)&Port;
*temp=INREG32(&pRegs->OTG.PORTSC[0]);
DEBUGMSG(1,(TEXT("ConfigOTGClient: PORTSC 0x%x PR=%d\r\n"), *temp, Port.PR));
//RETAILMSG(1, (TEXT("Initialize1504 OTG HighSpeed Client\r\n")));
Initialize1504Client(pRegs);
}
//-----------------------------------------------------------------------------
//
// 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* pRegs, BOOL IsHost)
{
// Clear USB Interrupt enable registers
OUTREG32(&(*pRegs)->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(&(*pRegs)->OTG.USBCMD);
Cmd.RS = 0;
OUTREG32(&(*pRegs)->OTG.USBCMD, *temp);
*pTmpMode = INREG32(&(*pRegs)->OTG.USBMODE);
if ( Mode.CM == 0x3 )
{
*temp2 = INREG32(&(*pRegs)->OTG.USBSTS);
while ( (Sts.HCH == 0) && (nAttempts++ < 50) )
{
Sleep(10);
*temp2 = INREG32(&(*pRegs)->OTG.USBSTS);
}
}
}
// Do a reset first no matter what
Reset(*pRegs);
// actually set the mode to HOST now
SetMode(*pRegs,CM_HOST_CONTROLLER);
ConfigOTGHost(*pRegs);
{ //usb_bypass_inactive()
USB_CTRL_T Ctrl;
DWORD * temp=(DWORD *)&Ctrl;
*temp=0;
Ctrl.BPE = BPE_BYPASS_ACTIVE; // Bypass Enable bit, clear it
CLRREG32(&(*pRegs)->USB_CTRL, *temp);
}
SetMode(*pRegs,CM_HOST_CONTROLLER);
//RETAILMSG(1, (TEXT("PowerOnPort\r\n")));
// power on port
{
DWORD *temp;
USB_HCSPARAMS_T Hcs;
temp=(DWORD *)&Hcs;
*temp=INREG32(&(*pRegs)->OTG.HCSPARAMS);
if (Hcs.PPC)
{
USB_PORTSC_T Portsc;
DWORD * temp2= (DWORD *)&Portsc;
*temp2 = INREG32(&(*pRegs)->OTG.PORTSC);
Portsc.PP = PP_READ_WRITE;
SETREG32(&(*pRegs)->OTG.PORTSC, *temp2);
}
}
//RETAILMSG(1, (TEXT("Initialize1504 Host\r\n")));
Initialize1504Host(*pRegs);
}
else
{
ConfigOTGClient(*pRegs);
// 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(&(*pRegs)->OTG.USBSTS, *t);
}
}
// Last to do: Enable the ID Pin Interrupt in OTGSC
{
USB_OTGSC_T temp;
DWORD *t = (DWORD *)&temp;
*t = INREG32(&(*pRegs)->OTG.OTGSC);
temp.IDIE = 1;
OUTREG32(&(*pRegs)->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;
}
#if 0
/*
* These are example callback routines which would be called on USB power-up or power-down
*/
//----------------------------------------------------------------------------------------------
// Function : BSPUsbXvrPowerDown - Call during XVC_PowerDown
//
// Parameters:
// 1) regs - USB registers
// 2) pUSBCoreClk - pointer to boolean to indicate the status of USB Core Clk
// if it is on or off. Platform is responsible to update this value if they change
// the status of USBCoreClk. [TRUE - USBCoreClk ON, FALSE - USBCoreClk OFF]
// 3) pPanicMode - pointer to boolean to indicate the status of panic mode
// if it is on or off. Platform is responsible to update this value if they change
// the status of panic mode. [TRUE - PanicMode ON, FALSE - USBCoreClk OFF]
// Returns:
// NULL
//----------------------------------------------------------------------------------------------
static void BSPUsbXvrPowerDown(CSP_USB_REGS *regs, BOOL *pUSBCoreClk, BOOL *pPanicMode)
{
// For Toshiba: Please move their XVC_PowerDown to here, no need to set the Critical section as XVC would handle that.
DEBUGMSG(1, (TEXT("BSPUsbXvrPowerDown reg=0x%x, USBCoreClk=%d, PanicMode=%d\r\n"), regs, *pUSBCoreClk, *pPanicMode));
return;
}
//-----------------------------------------------------------------------------------------------
// Function: BSPUsbXvrPowerUp - Call during XVC_PowerUp
//
// Parameters:
// 1) regs - USB registers
// 2) pUSBCoreClk - pointer to boolean to indicate the status of USB Core Clk
// if it is on or off. Platform is responsible to update this value if they change
// the status of USBCoreClk. [TRUE - USBCoreClk ON, FALSE - USBCoreClk OFF]
// 3) pPanicMode - pointer to boolean to indicate the status of panic mode
// if it is on or off. Platform is responsible to update this value if they change
// the status of panic mode. [TRUE - PanicMode ON, FALSE - USBCoreClk OFF]
// Returns:
// NULL
//-----------------------------------------------------------------------------------------------
static void BSPUsbXvrPowerUp(CSP_USB_REGS *regs, BOOL *pUSBCoreClk, BOOL *pPanicMode)
{
// For Toshiba, basically, nothing need to be done.
DEBUGMSG(1, (TEXT("BSPUsbXvrPowerUp reg=0x%x, USBCoreClk=%d, PanicMode=%d\r\n"), regs, *pUSBCoreClk, *pPanicMode));
return;
}
#endif
//-------------------------------------------------------------------------------------------------------
// Function: BSPUsbXvrSetPhyPowerMode
// function for platform to call when they want to suspend/resume the PHY
//
// Parameters:
// 1) pUSBRegs - USB registers
// 2) bResume - TRUE - request to resume, FALSE - request suspend
//
// Return:
// NULL
//-----------------------------------------------------------------------------------------------------------
static void BSPUsbXvrSetPhyPowerMode(CSP_USB_REGS *pUSBRegs, BOOL bResume)
{
// For Toshiba: Please move their xvc_SetPhyPowerMode to here
DEBUGMSG(1, (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);
Sleep(1);
// Force Resume bit
OUTREG32(&pUSBRegs->OTG.PORTSC[0], INREG32(&pUSBRegs->OTG.PORTSC[0])|0x40);
//RETAILMSG(1, (TEXT("Force resume\r\n")));
}
}
else
{
USB_PORTSC_T portsc;
DWORD *temp = (DWORD *)&portsc;
*temp = INREG32(&(pUSBRegs)->OTG.PORTSC);
portsc.PHCD = 1;
Sleep(1);
OUTREG32(&(pUSBRegs)->OTG.PORTSC, *temp);
}
}
//---------------------------------------------------------------------------------------------
// Function: RegisterCallback
// - function call by XVC to register the callback function during the XVC_Init.
//
// Parameters:
// pfn - Pointer to USB Callback function pointers
//
// Return:
// NULL
//------------------------------------------------------------------------------------------------
void RegisterCallback(BSP_USB_CALLBACK_FNS *pfn)
{
DEBUGMSG(1, (TEXT("+RegisterCallback\r\n")));
if (pfn)
{
pfn->pfnUSBPowerDown = NULL;
pfn->pfnUSBPowerUp = NULL;
//pfn->pfnUSBPowerUp = BSPUsbXvrPowerUp;
//pfn->pfnUSBPowerDown = BSPUsbXvrPowerDown;
pfn->pfnUSBSetPhyPowerMode = BSPUsbXvrSetPhyPowerMode;
DEBUGMSG(1, (TEXT("RegisterCallback for XVC\r\n")));
}
DEBUGMSG(1, (TEXT("-RegisterCallback\r\n")));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -