📄 xsusbhostdrv.c
字号:
Enabling / Disabling a specific Port's power
Enable: Write 1 to UHCRHPSx:PPS
Disable: Write 1 to UHCRHPSx:LDA
where x is 1 for Port1 or 2 for Port2
Inclusion / Exclusion from Global Set/Clear Port Power Commands
Inclusion: Write 0 to UHCRHDB:PPCM[x], the corresponding port
will only recognize Global Set/Clear Power commands.
It will not respond to specific SetPortPower or
ClearPortPower commands.
Exclusion: Write 1 to UHCRHDB:PPCM[x], the corresponding port
will not recognize Global Set/Clear Power commands.
It will only respond to specific SetPortPower or
ClearPortPower commands.
where x is 1 for Port1 or 2 for Prt2
note: x=0 or x>3 are reserved bits in the PPCM field.
Power Enable/Disable Configurations, in order of simplicity:
1. No Power Switching:
Setup:
A. Set UHCRHDA:NoPowerSwitching to 1. (Disallows power switching)
Comments:
The ports will be powered on as long as the USH Host block is on.
2. Global Power Switching Mode Only:
Setup:
A. Set UHCRHDA:NoPowerSwitching to 0. (Allows power switching)
B. Set UHCRHDA:PowerSwitchingMode to 0. (Selects PowerSwitchingMode = Global)
To Enable Global Power:
Set UHCRHDB:LPSC to 1. (Turn on power to all ports)
To Disable Global Power:
Set UHCRHDB:LPS to 1. (Turn off power to all ports)
Comments:
Power switching is enabled.
Global Power Mode is enabled.
Power to all ports is enabled or disabled at the same time.
3. Per Port Power Switching Mode Only:
Setup:
A. Set UHCRHDA:NoPowerSwitching to 0. (Allows power switching)
B. Set UHCRHDA:PowerSwitchingMode to 1. (Selects PowerSwitchingMode = Per-Port)
C. Set UHCRHDB:PPCM[1] to 1. (Makes UHCRHP1 respond only to per port power commands)
D. Set UHCRHDB:PPCM[2] to 1. (Makes UHCRHP2 respond only to per port power commands)
To Enable Port1 Power:
Set UHCRHPS1:PPS to 1 (Turn on power to port 1)
To Disable Port1 Power:
Set UHCRHPS1:LDA to 1 (Turn off power to port 1)
To Enable Port2 Power:
Set UHCRHPS2:PPS to 1 (Turn on power to port 2)
To Disable Port2 Power:
Set UHCRHPS2:LDA to 1 (Turn off power to port 2)
Comments:
Power switching is enabled.
Per Port Power switching mode is enabled.
Each port to participate in Per Port Power switching must set
its corresponding bit in the UHCRHDB:PPCM mask.
Power to individual ports is enabled or disabled without effecting other ports.
4. Combination Global Power Mode Switching and Per Port Power Switching Mode Only:
Setup:
A. Set UHCRHDA:NoPowerSwitching to 0. (Allows power switching)
B. Set UHCRHDA:PowerSwitchingMode to 1. (Selects PowerSwitchingMode = Per-Port)
C. Set UHCRHDB:PPCM[1] to 0. (Makes UHCRHP1 respond only to per port power commands)
D. Set UHCRHDB:PPCM[2] to 1. (Makes UHCRHP2 respond only to per port power commands)
To Enable Port1 Power:
Set UHCRHDB:LPSC to 1. (A Global Power Command: port1 responds by turning on)
(Port2 remains unaffected)
To Disable Port1 Power:
Set UHCRHDB:LPS to 1. (A Global Power Command: port1 responds by turning off)
(Port2 remains unaffected)
To Enable Port2 Power:
Set UHCRHPS2:PPS to 1 (Turn on power to port 2)
(Port1 remains unaffected)
To Disable Port2 Power:
Set UHCRHPS2:LDA to 1 (Turn off power to port 2)
(Port1 remains unaffected)
Comments:
This example shows port1 being controlled by Global Power Mode commands,
and port2 is controlled only by specific set or clear port power commands.
Power switching is enabled.
Per Port Power switching mode is enabled.
Each port to participate in Per Port Power switching must set
its corresponding bit in the UHCRHDB:PPCM mask.
In this case:
Port1 responds to Global Power Mode commands
Port2 response to Per Port Power Mode commands
All ports without their bits set in UHCRHDB:PPCM mask are effect by Global Power Mode commands.
Power to individual ports is enabled or disabled without effecting other ports.
*******************************************************************************************
*/
void XsUsbHostSelectPowerManagementMode(INT mode,
INT numPorts,
INT* portMode)
{
DM_CwDbgPrintf(DM_CW_USB_HOST_0, "XsUsbHostSelectPowerManagementMode>>");
switch(mode)
{
case XLLP_USBOHCI_PPM_NPS:
// set NO Power Switching mode
USBOHCIRegP->uhcrhda |= XLLP_USBOHCI_UHCRHDA_NPS;
break;
case XLLP_USBOHCI_PPM_GLOBAL:
// make sure the NO Power Switching mode bit is OFF so Power Switching can occur
// make sure the PSM bit is CLEAR, which allows all ports to be controlled with
// the GLOBAL set and clear power commands
USBOHCIRegP->uhcrhda &= ~(XLLP_USBOHCI_UHCRHDA_NPS|XLLP_USBOHCI_UHCRHDA_PSM_PERPORT);
break;
case XLLP_USBOHCI_PPM_PERPORT:
// make sure the NO Power Switching mode bit is OFF so Power Switching can occur
// make sure the PSM bit is SET, which allows all ports to be controlled with
// the PER PORT set and clear power commands
USBOHCIRegP->uhcrhda &= ~XLLP_USBOHCI_UHCRHDA_NPS;
USBOHCIRegP->uhcrhda |= XLLP_USBOHCI_UHCRHDA_PSM_PERPORT;
// set the power management mode for each individual port to Per Port.
{
int p;
for( p = 0; p < numPorts; p++ )
{
USBOHCIRegP->uhcrhdb |= (unsigned int)( 1u << (p+17) ); // port 1 begins at bit 17
}
}
break;
case XLLP_USBOHCI_PPM_MIXED:
// make sure the NO Power Switching mode bit is OFF so Power Switching can occur
// make sure the PSM bit is SET, which allows all ports to be controlled with
// the PER PORT set and clear power commands
USBOHCIRegP->uhcrhda &= ~XLLP_USBOHCI_UHCRHDA_NPS;
USBOHCIRegP->uhcrhda |= XLLP_USBOHCI_UHCRHDA_PSM_PERPORT;
// set the power management mode for each individual port to Per Port.
// if the value in the PortMode array is non-zero, set Per Port mode for the port.
// if the value in the PortMode array is zero, set Global mode for the port
{
int p;
for( p = 0; p < numPorts; p++ )
{
if( portMode[p] )
{
USBOHCIRegP->uhcrhdb |= (unsigned int)( 1u << (p+17) ); // port 1 begins at bit 17
}
else
{
USBOHCIRegP->uhcrhdb &= ~(unsigned int)( 1u << (p+17) ); // port 1 begins at bit 17
}
}
}
break;
}
DM_CwDbgPrintf(DM_CW_USB_HOST_0, "<<XsUsbHostSelectPowerManagementMode");
}
/*
******************************************************************************************
*
* FUNCTION: XsUsbHostHWSetup
*
* DESCRIPTION: This function is used for Bulverde specific hardware initialization
* of the USB Host.
*
* INPUT PARAMETERS: none
*
* RETURNS: 0 if successful
* UINT32 in case of error.
*
* GLOBAL EFFECTS: none
*
* ASSUMPTIONS: none
*
*******************************************************************************************
*/
UINT32 XsUsbHostHWSetup (void)
{
UINT32 error = FALSE;
// Setup USB Host GPIO 88 and GPIO 89
XsUsbHostSetupGPIOs(0);
// Enable the USB Host Controller clocks
XsUsbHostTurnOnClocks(1);
// Wait at least 10us
DM_WaitUs(10);
// Reset USB Host Controller
XsUsbHostReset();
// Set NO Power Switching mode for now
XsUsbHostSelectPowerManagementMode(XLLP_USBOHCI_PPM_NPS, 1, 0);
return error;
}
/*
******************************************************************************************
*
* FUNCTION: XsUsbHostShutdown
*
* DESCRIPTION: This function is used for Bulverde specific hardware shutdown
* of the USB Host.
*
* INPUT PARAMETERS: none
*
* RETURNS: none
*
* GLOBAL EFFECTS: none
*
* ASSUMPTIONS: none
*
*******************************************************************************************
*/
void XsUsbHostShutdown (void)
{
// Complete the hardware Reset sequence
XsUsbHostReset();
// Issue a software reset by writing a one to the HostControllerReset bit
// in the HcCommandStatus register
USBOHCIRegP->uhccoms |= XLLP_USBOHCI_UHCCOMS_HCR;
DM_WaitUs(10);
// Clear the global power enable bit to turn off power to all ports
USBOHCIRegP->uhcrhs |= XLLP_USBOHCI_UHCRHS_CGP;
// Clear the Sleep Standby Enable bit to enable power to the downstream ports
USBOHCIRegP->uhchr &= ~XLLP_USBOHCI_UHCHR_SSE;
// Stop the USB Clocks
XsUsbHostTurnOnClocks(0);
}
/*
*******************************************************************************
*
* FUNCTION: XsUsbHostSWInit
*
* DESCRIPTION: This function is used to initialize USB Host's context structure.
* No hardware setup is done at this point.
*
* INPUT PARAMETERS: none.
*
* RETURNS: none.
*
* GLOBAL EFFECTS: none.
*
* ASSUMPTIONS: none.
*
*******************************************************************************
*/
void XsUsbHostSWInit (void)
{
// the bulverde needs access to the clkmgr to enable the USBHOST clock
ClkMgrRegP = (volatile P_XLLP_CLKMGR_T)CLK_MGR_REGS_BASE;
// the bulverde needs access to the gpio regs to set up the gpios that
// are tied to the external MAX1693EUB USB Power Switch
GPIORegP = (P_XLLP_GPIO_T)GPIO_REGS_BASE;
// Map the usb ohci register block.
USBOHCIRegP = (volatile P_XLLP_USBOHCI_T)USBOHCI_REGS_BASE;
UsbHost.USBOHCIRegP = USBOHCIRegP;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -