📄 usbehcdinitexit.c
字号:
/* Power off all the root hub ports */ /* * The EHC_PPC field indicates whether the EHCI Host Controller supports * per port power switching. * Check whether the port supports per port power switching. */ if (1 == USB_EHCD_GET_FIELD(pHCDData, HCSPARAMS, PPC)) { /* This loop will power off all the ports */ for (uTempCount = 0; uTempCount < pHCDData->RHData.uNumDownstreamPorts; uTempCount++) { /* Set the PP field to power on the port */ USB_EHCD_CLR_BIT_PORT(pHCDData, uTempCount, PORT_POWER); /* Wait for 50 ms for the power to settle down */ OS_DELAY_MS(50); }/* End of for() */ } /* If the EHCI does not support * port power switching and if a device is connected * while the target boots up, there is no connect status change * and no root hub status change interrupt which is generated */ else { for (uTempCount = 0; uTempCount < pHCDData->RHData.uNumDownstreamPorts; uTempCount++) { if (USB_EHCD_GET_FIELD_PORT(pHCDData, uTempCount, CURRENT_CONNECT_STATUS) != 0) { /* To hold the status of the port */ UINT32 uPortStatus = 0; /* Copy the value in the port status register */ OS_MEMCPY(&uPortStatus, (pHCDData->RHData.pPortStatus + uTempCount), USB_EHCD_RH_PORT_STATUS_SIZE); /* Swap the data from LE format */ uPortStatus = USB_EHCD_SWAP_DATA(g_EHCDControllerCount, uPortStatus); /* Update the connect status change */ uPortStatus |= USB_EHCD_RH_PORT_CONNECT_CHANGE; /* Swap the data to LE format data */ uPortStatus = USB_EHCD_SWAP_DATA(g_EHCDControllerCount, uPortStatus); /* Copy the status back to the port status */ OS_MEMCPY((pHCDData->RHData.pPortStatus + uTempCount), &uPortStatus, USB_EHCD_RH_PORT_STATUS_SIZE); /* * Call the function to populate the interrupt * status data */ usbEhcdCopyRHInterruptData( pHCDData, (USB_EHCD_RH_MASK_VALUE << uTempCount)); } } }#ifdef EHCD_MODULE_TEST /* * The EHC_PPC field indicates whether the EHCI Host Controller supports * per port power switching. * Check whether the port supports per port power switching. */ if (1 == USB_EHCD_GET_FIELD(pHCDData, HCSPARAMS, PPC)) { /* This loop will power on all the ports */ for (uTempCount = 0; uTempCount < pHCDData->RHData.uNumDownstreamPorts; uTempCount++) { /* Set the PP field to power on the port */ USB_EHCD_SET_BIT_PORT(pHCDData, uTempCount, PORT_POWER); /* Wait for 50 ms for the power to settle down */ OS_DELAY_MS(50); }/* End of for() */ }#endif /* * Enable the interrupts which are necessary for the EHCI * Host Controller. Other interrupts can be enabled only after * Root hub configuration. */ USB_EHCD_WRITE_REG(pHCDData, USB_EHCD_USBINTR, USB_EHCD_INTERRUPT_MASK); /* Increment the host controller count. This is incremented here as * the USBD calls the interface functions to enumerate the root hub. * This results in all the function calls return a failure if we don't * increment the controller index here. */ g_EHCDControllerCount++; /* Register the bus with the USBD */ Status = usbHstBusRegister(g_EHCDHandle, USBHST_HIGH_SPEED, (UINT32)pHCDData->pDefaultPipe); /* Check if the bus is registered successfully */ if (USBHST_SUCCESS != Status ) { OS_LOG_MESSAGE_HIGH(EHCD,"usbEhcdInit - Error in registering the \ bus \n",0,0,0,0); /* Stop the Host Controller */ USB_EHCD_CLR_BIT(pHCDData, USBCMD, RS); /* Call the uninitialization function of the HC bus */ usbEhcdHostBusUninitialize(pHCDData); /* Call the uninitialization function of the HCD data */ usbEhcdDataUninitialize(pHCDData); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_EHCI_WV_INIT_EXIT, "usbEhcdInit() exits - Bus registration failed", USB_EHCD_WV_FILTER); /* Decrement the controller index */ g_EHCDControllerCount--; return FALSE; } }/* End of for () */ OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdInit - Exit\n",0,0,0,0); return TRUE; } /* End of function usbEhcdInit() *//***************************************************************************** usbEhcdExit - uninitializes the EHCI Host Controller** This routine uninitializes the EHCI Host Controller Driver and detaches * it from the usbd interface layer.** RETURNS: TRUE, or FALSE if there is an error during HCD uninitialization.** ERRNO:* None.*/BOOLEAN usbEhcdExit(VOID) { /* To hold the pointer to the HCD maintained data structure */ pUSB_EHCD_DATA pHCDData = NULL; /* To hold the local host controller count */ UINT32 EHCDControllerCount; /* To hold the status of the function call */ USBHST_STATUS Status = USBHST_FAILURE; OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdExit - Entry",0,0,0,0); /* Check if the globals are valid */ if ((NULL == g_pEHCDriverInfo) || (maxEhciCount < g_EHCDControllerCount) || (0 == g_EHCDControllerCount) || (NULL == g_ListAccessEvent) || (g_pEHCDData == NULL)) { OS_LOG_MESSAGE_HIGH(EHCD,"Invalid globals\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_EHCI_WV_INIT_EXIT, "usbEhcdExit() exits - invalid global variables", USB_EHCD_WV_FILTER); return FALSE; } /* This loop releases the resources for all the host controllers present */ for (EHCDControllerCount = g_EHCDControllerCount - 1; (maxEhciCount > EHCDControllerCount); g_EHCDControllerCount--,EHCDControllerCount--) { /* Extract the pointer from the global array */ pHCDData = g_pEHCDData[EHCDControllerCount]; /* Check if the pointer is valid */ OS_ASSERT(NULL != pHCDData); /* Assert if the base address is not valid */ OS_ASSERT(NULL != pHCDData->pEHCBaseAddress); /* Call the USBD function to deregister the bus */ Status = usbHstBusDeregister(g_EHCDHandle, EHCDControllerCount, (UINT32)pHCDData->pDefaultPipe); /* Check if the bus is deregistered successfully */ if (USBHST_SUCCESS != Status) { OS_LOG_MESSAGE_HIGH(EHCD,"Failure in deregistering the bus\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_EHCI_WV_INIT_EXIT, "usbEhcdExit() exits - bus deregistration failed", USB_EHCD_WV_FILTER); return FALSE; } /* * Reset the CONFIGURE_FLAG bit to default route all the ports * to the companion Host Controllers. */ USB_EHCD_CLR_BIT(pHCDData, CONFIGFLAG, CF); /* Clear the Run/Stop bit to stop the Host Controller */ USB_EHCD_CLR_BIT(pHCDData, USBCMD, RS); /* Disable the asynchronous list */ USB_EHCD_CLR_BIT(pHCDData, USBCMD, ASYNCH_SCHEDULE_ENABLE); /* * Periodic list is disabled during EHCD * data structure uninitialization. */ /* Disable all the interrupts */ USB_EHCD_WRITE_REG(pHCDData, USB_EHCD_USBINTR, 0); /* Call the function to uninitialize the EHCD data structure */ usbEhcdDataUninitialize(pHCDData); /* Call the function to perform the host bus specific uninitialization*/ usbEhcdHostBusUninitialize(pHCDData); /* Release the memory allocated for the HCD data structure */ OS_FREE(pHCDData); g_pEHCDData[EHCDControllerCount] = NULL; } /* End of for () */ /* Deregister the HCD from USBD */ Status = usbHstHCDDeregister(g_EHCDHandle); /* Check if HCD is deregistered successfully */ if (USBHST_SUCCESS != Status) { OS_LOG_MESSAGE_HIGH(EHCD,"Failure in deregistering the HCD\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_EHCI_WV_INIT_EXIT, "usbEhcdExit() exits - EHCD deregistration failed", USB_EHCD_WV_FILTER); return FALSE; } g_EHCDHandle = 0; /* Free memory allocated for the driver data structure */ OS_FREE(g_pEHCDriverInfo); g_pEHCDriverInfo = NULL; /* Call the function to release all the memory in the free lists */ usbEhcdFreeAllLists(); /* Destroy the event used for synchronisation of the free list */ OS_DESTROY_EVENT(g_ListAccessEvent); g_ListAccessEvent = NULL; /* Free the memory allocated for the global data structure */ OS_FREE(g_pEHCDData); g_pEHCDData = NULL; OS_LOG_MESSAGE_LOW(EHCD,"usbEhcdExit - Exit\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_EHCI_WV_INIT_EXIT, "usbEhcdExit() exits successfully", USB_EHCD_WV_FILTER); return TRUE; } /* End of function usbEhcdExit() *//***************************************************************************** usbEhcdDisableHC - called on a reboot to disable the host controller** This routine is called on a warm reboot to disable the host controller by* the BSP.*** RETURNS: None.** ERRNO:* None.** \NOMANUAL*/VOID usbEhcdDisableHC ( int startType ) { /* Pointer to the HCD data structure */ pUSB_EHCD_DATA pHCDData = NULL; if ((NULL == g_pEHCDriverInfo) || (maxEhciCount < g_EHCDControllerCount) || (0 == g_EHCDControllerCount) || (NULL == g_ListAccessEvent) || (g_pEHCDData == NULL)) { return; } /* This loop releases the resources for all the host controllers present */ for (g_EHCDControllerCount = g_EHCDControllerCount - 1; (maxEhciCount > g_EHCDControllerCount); g_EHCDControllerCount--) { /* Extract the pointer from the global array */ pHCDData = g_pEHCDData[g_EHCDControllerCount]; /* Check if the pointer is valid */ OS_ASSERT(NULL != pHCDData); /* Assert if the base address is not valid */ OS_ASSERT(NULL != pHCDData->pEHCBaseAddress); /* Reset the Host Controller */ USB_EHCD_SET_BIT(pHCDData, USBCMD, HCRESET); /* Unregister the interrupt handler for the IRQ */ if ((pEhciBusInfo[pHCDData->uBusIndex] != NULL) && (pEhciBusInfo[pHCDData->uBusIndex]->pFuncIntDisconnect != NULL)) pEhciBusInfo[pHCDData->uBusIndex]->pFuncIntDisconnect(usbEhcdISR, pHCDData,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -