📄 usbohci.c
字号:
* c) Reset the OHCI Host Controller * d) Initialize the OHCI Host Controller */ for (uIndex = 0; uIndex < maxOhciCount; uIndex++) { /* To hold the pointer to the default pipe */ PUSB_OHCI_ENDPOINT_DESCRIPTOR pDefaultEndpointDescriptor = NULL; /* Call the function to initialize the OHCI Controller */ bStatus = usbOhciInitializeHostController(uIndex); /* Check whether the host controller was initialized successfully */ if (!bStatus) { /* * Call the function to clean up the resources allocated for * the host controller. */ usbOhciExit(); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_OHCI_WV_INIT_EXIT, "usbOhciInit() exits - Controller initialisation failed", USB_OHCD_WV_FILTER); /* Return without proceeding */ return FALSE; } /* Obtain the pointer to the default pipe */ pDefaultEndpointDescriptor = usbOhciControllerInfo[uIndex].pDefaultEndpointDescriptor; /* Call the function to register the bus with USBD */ uUsbStatus = usbHstBusRegister(hHostControllerDriver, USBHST_FULL_SPEED, (UINT32)pDefaultEndpointDescriptor); /* Check whether the bus was registered successfully */ if (uUsbStatus != USBHST_SUCCESS) { /* * Call the function to clean up the resources allocated for * the host controller. */ usbOhciExit(); /* Debug message */ OS_LOG_MESSAGE_HIGH( OHCD, "Failed to register the bus for OHCI host controller.\n", 0, 0, 0, 0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_OHCI_WV_INIT_EXIT, "usbOhciInit() exits - Bus registration failed", USB_OHCD_WV_FILTER); /* Return without proceeding */ return FALSE; } } /* Set the flag to specify that the OHCI Controllers are initialized */ bInitialized = TRUE; /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_OHCI_WV_INIT_EXIT, "usbOhciInit() exits successfully", USB_OHCD_WV_FILTER); /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Exiting the function: usbOhciInit().\n", 0, 0, 0, 0); return TRUE; } /* End of function usbOhciInit() *//***************************************************************************** usbOhciExit - uninitialise the USB OHCI Host Controller Driver.** This function uninitialises the OHCI Host Controller Driver.** RETURNS: FALSE, TRUE if all the OHCI Host Controllers are reset and the* cleanup is successful.** ERRNO:* None.*/BOOLEAN usbOhciExit (void) { /* * To hold the index into the OHCI_INFORMATION array corresponding to the * number of OHCI Controllers found on the system. */ UINT32 uOhciControllerIndex = 0; /* To hold the status of deregistering the OHCI host controller driver */ USBHST_STATUS uUsbStatus = USBHST_SUCCESS; /* Flag to indicate whether there are any active host controllers */ BOOLEAN bActiveHostControllers = FALSE; /* To hold the pointer to the host controller information */ PUSB_OHCI_INFORMATION pOhciControllerInfo = NULL; /* To hold the status of the host controller */ UINT32 uOhciControllerState = 0; OS_LOG_MESSAGE_LOW( OHCD, "Entering the function: usbOhciExit().\n", 0, 0, 0, 0); /* * Stop all the host controllers and release the resources allocated * for them. */ for (uOhciControllerIndex = 0; uOhciControllerIndex < maxOhciCount; uOhciControllerIndex++) { /* Obtain the pointer to the host controller information */ pOhciControllerInfo = &usbOhciControllerInfo[uOhciControllerIndex]; /* Check whether the host controller is initialized */ if (TRUE == pOhciControllerInfo->bHostControllerInitialized) { /* Call the function to deregister the bus */ uUsbStatus = usbHstBusDeregister ( hHostControllerDriver, uOhciControllerIndex, (UINT32)pOhciControllerInfo->pDefaultEndpointDescriptor); /* Check whether the bus was deregistered successfully */ if (uUsbStatus != USBHST_SUCCESS) { /* Debug message */ OS_LOG_MESSAGE_HIGH ( OHCD, "Failed to deregister the bus for OHCI host controller.\n", 0, 0, 0, 0); /* * NOTE: If the deregisteration of the bus fails, it is likely * that there are active devices on the bus. Hence, stop * the cleanup operations for the bus. */ /* Set the flag to indicate there are active host controllers */ bActiveHostControllers = TRUE; /* * Do not cleanup the current host controller and move to the * next host controllers. */ continue; } } else { /* * Since this OHCI host controller is not registered, move to the * host controller in the list. */ continue; } /* * Check whether the default pipe is valid. * * NOTE: The default pipe should be deleted before the ISR is * unregistered (OR) the polling mode ISR task is destroyed. * * This is bacause the OHCI_DeletePipe() function synchronizes * with the host controller before deleting the pipe. In order * to synchronize the OHCI_DeletePipe() function depends on SOF * interrupt. * * Hence, the default pipe should be deleted when the host * controller is in operational state. */ if (pOhciControllerInfo->pDefaultEndpointDescriptor != NULL) { /* Call the function to delete the default pipe */ usbOhciDeletePipe ( uOhciControllerIndex, (UINT32) pOhciControllerInfo->pDefaultEndpointDescriptor); /* Reset the pointer to the default pipe */ pOhciControllerInfo->pDefaultEndpointDescriptor = NULL; } #ifndef USB_OHCI_POLLING_MODE /* Disable the interrupts */ USB_OHCI_REG_WRITE (uOhciControllerIndex, (pOhciControllerInfo->uBaseAddress + USB_OHCI_INTERRUPT_DISABLE_REGISTER_OFFSET), USB_OHCI_INTERRUPT_MASK);#endif /* USB_OHCI_POLLING_MODE */ /* Reset the OHCI Controller */ USB_OHCI_REG_WRITE (uOhciControllerIndex, (pOhciControllerInfo->uBaseAddress + USB_OHCI_COMMAND_STATUS_REGISTER_OFFSET), USB_OHCI_COMMAND_STATUS_HCR); /* * Wait for the reset operation to complete. The reset operation should * be completed in 1 micro second. However, a delay of 1 milli second * is provided. * * NOTE: This extra delay will not create any performance issues. * Since the host controller is being disabled, this delay is * acceptable. */ OS_DELAY_MS (USB_OHCI_WAIT_FOR_HOST_CONTROLLER_RESET_COMPLETION); /* Check the status of the OHCI Controller */ uOhciControllerState = USB_OHCI_REG_READ (uOhciControllerIndex, (pOhciControllerInfo->uBaseAddress + USB_OHCI_CONTROL_REGISTER_OFFSET)); /* Check whether the OHCI Controller is in SUSPEND state */ if ((uOhciControllerState & USB_OHCI_CONTROL_HCFS_USB_SUSPEND) != USB_OHCI_CONTROL_HCFS_USB_SUSPEND) { /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_OHCI_WV_INIT_EXIT, "usbOhciExit() exits - Controller reset failed", USB_OHCD_WV_FILTER); /* * NOTE: There is no error recovery mechanism. Hence the error * is ignored. */ }#ifndef USB_OHCI_POLLING_MODE /* * Unregister the interrupt handler for the OHCI Controller. * * NOTE: Check whether ISR is valid. If valid,deregister the ISR. */ if (pOhciBusInfo[uOhciControllerIndex]->pFuncIntDisconnect != NULL) pOhciBusInfo[uOhciControllerIndex]->pFuncIntDisconnect (usbOhciIsr, uOhciControllerIndex, pOhciControllerInfo->uIrqNumber);#endif /* End of #ifndef USB_OHCI_POLLING_MODE */ /* Check whether the OHCI interrupt handler thread is valid */ if (pOhciControllerInfo->isrThreadId != OS_THREAD_FAILURE) { /* Delete the OHCI interrupt handler thread */ OS_DESTROY_THREAD (pOhciControllerInfo->isrThreadId); /* Reset the OHCI interrupt handler thread ID */ pOhciControllerInfo->isrThreadId = OS_THREAD_FAILURE; }#ifndef USB_OHCI_POLLING_MODE /* Check whether the ISR event was created successfully */ if (OS_INVALID_EVENT_ID != pOhciControllerInfo->isrEvent) { /* Call the function to delete the ISR event */ OS_DESTROY_EVENT (pOhciControllerInfo->isrEvent); /* Reset the ISR event pointer */ pOhciControllerInfo->isrEvent = OS_INVALID_EVENT_ID; }#endif /* End of #ifndef USB_OHCI_POLLING_MODE */ /* Check whether the endpoint list access event is valid */ if (pOhciControllerInfo->endpointListAccessEvent != OS_INVALID_EVENT_ID) { /* Call the function to delete the endpoint list access event */ OS_DESTROY_EVENT (pOhciControllerInfo->endpointListAccessEvent); /* Reset the endpoint list access event pointer */ pOhciControllerInfo->endpointListAccessEvent = OS_INVALID_EVENT_ID; } /* * Check whether the pointer to the host controller communication * area is valid. */ if (pOhciControllerInfo->pHcca != NULL) { /* * Release the memory allocated for the host controller * communication area */ OHCI_FREE (pOhciControllerInfo->pHcca); /* Reset the HCCA pointer */ pOhciControllerInfo->pHcca = NULL; } /* Reset the flag to indicate the host controller is not initialized */ pOhciControllerInfo->bHostControllerInitialized = FALSE; } /* End of for (uOhciControllerIndex = 0; ... ) */ /* * Check whether there are any active host controllers. If true, do not * deregister the HCD and return from the function. */ if (bActiveHostControllers) { /* Return from the function without deregistering the HCD */ return FALSE; } /* free the usbOhciControllerInfo */ OS_FREE (usbOhciControllerInfo) ; usbOhciControllerInfo = NULL; /* Call the function to deregister the OHCI host controller driver */ uUsbStatus = usbHstHCDDeregister (hHostControllerDriver); /* * Check whether the OHCI host controller driver was deregistered * successfully */ if (uUsbStatus != USBHST_SUCCESS) { /* Debug message */ OS_LOG_MESSAGE_HIGH ( OHCD, "Failed to deregister OHCI host controller driver.\n", 0, 0, 0, 0); /* * NOTE: There is no error recovery mechanism. Hence the error is * ignored. */ } /* Set the flag to specify that the OHCI Controllers are not initialized */ bInitialized = FALSE; /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_OHCI_WV_INIT_EXIT, "usbOhciExit() exits successfully", USB_OHCD_WV_FILTER); OS_LOG_MESSAGE_LOW( OHCD, "Exiting the function: usbOhciExit().\n", 0, 0, 0, 0); return TRUE; } /* End of function usbOhciExit () *//******************* MODULE SPECIFIC FUNCTIONS DEFINITION *********************//***************************************************************************** usbOhciInitializeHostController - initialise the USB OHCI Host Controller** This function initialises the OHCI Host Controller. It* a) Identifies the PCI IRQ Number* b) Identifies the Base Address of USB Registers* c) Reset the OHCI Host Controller* d) Initialize the OHCI Host Controller** RETURNS: FALSE,TRUE if the USB OHCI Host Controller is initialized successfully,** ERRNO:* None.* * \NOMANUAL*/LOCAL BOOLEAN usbOhciInitializeHostController ( UINT8 uHostControllerIndex )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -