📄 sc2443pdd.cpp
字号:
CEDEVICE_POWER_STATE cpsNew
)
{
SETFNAME();
PREFAST_DEBUGCHK(pContext);
DEBUGCHK(VALID_DX(cpsNew));
ValidateContext(pContext);
RETAILMSG(DBG, (_T("%s SetPowerState\r\n"),
pszFname));
// Adjust cpsNew.
if (cpsNew != pContext->cpsCurrent) {
if (cpsNew == D1 || cpsNew == D2) {
// D1 and D2 are not supported.
cpsNew = D0;
}
else if (pContext->cpsCurrent == D4) {
// D4 can only go to D0.
cpsNew = D0;
}
}
if (cpsNew != pContext->cpsCurrent) {
DEBUGMSG(ZONE_POWER, (_T("%s Going from D%u to D%u\r\n"),
pszFname, pContext->cpsCurrent, cpsNew));
if ( (cpsNew < pContext->cpsCurrent) && pContext->hBusAccess ) {
SetDevicePowerState(pContext->hBusAccess, cpsNew, NULL);
}
switch (cpsNew) {
case D0:
HW_USBClocks(D0);
KernelIoControl(IOCTL_HAL_DISABLE_WAKE, &pContext->dwSysIntr,
sizeof(pContext->dwSysIntr), NULL, 0, NULL);
if (pContext->fRunning) {
// Cause the IST to restart.
pContext->fRestartIST = TRUE;
SetInterruptEvent(pContext->dwSysIntr);
}
break;
case D3:
KernelIoControl(IOCTL_HAL_ENABLE_WAKE, &pContext->dwSysIntr,
sizeof(pContext->dwSysIntr), NULL, 0, NULL);
break;
case D4:
HW_USBClocks((CEDEVICE_POWER_STATE)D4);
KernelIoControl(IOCTL_HAL_DISABLE_WAKE, &pContext->dwSysIntr,
sizeof(pContext->dwSysIntr), NULL, 0, NULL);
break;
}
if ( (cpsNew > pContext->cpsCurrent) && pContext->hBusAccess ) {
SetDevicePowerState(pContext->hBusAccess, cpsNew, NULL);
}
pContext->cpsCurrent = cpsNew;
}
return pContext->cpsCurrent;
}
// EINT2 Test Code by woo
DWORD
HW_InitRegisters()
{
#if 1
pCLKPWR = (volatile S3C2443_CLKPWR_REG*)VirtualAlloc(0, sizeof(S3C2443_CLKPWR_REG), MEM_RESERVE, PAGE_NOACCESS);
if (!pCLKPWR)
{
DEBUGMSG(1, (TEXT("pCLKPWR: VirtualAlloc failed!\r\n")));
return(FALSE);
}
if (!VirtualCopy((PVOID)pCLKPWR, (PVOID)(S3C2443_BASE_REG_PA_CLOCK_POWER >> 8), sizeof(S3C2443_CLKPWR_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
{
DEBUGMSG(1, (TEXT("pCLKPWR: VirtualCopy failed!\r\n")));
return(FALSE);
}
pIOPregs = (volatile S3C2443_IOPORT_REG *)VirtualAlloc(0, sizeof(S3C2443_IOPORT_REG), MEM_RESERVE, PAGE_NOACCESS);
if(!pIOPregs) {
DEBUGMSG(1, (TEXT("pIOPregs: VirtualAlloc failed!\r\n")));
return(FALSE);
}
if(!VirtualCopy((PVOID)pIOPregs, (PVOID)(S3C2443_BASE_REG_PA_IOPORT >> 8), sizeof(S3C2443_IOPORT_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
{
DEBUGMSG(1, (TEXT("pIOPregs: VirtualCopy failed!\r\n")));
return(FALSE);
}
#endif
pIOPregs->EXTINT0 = (READEXTINT0(pIOPregs->EXTINT0) & ~(0xf<<8)) | (1<<11) | (7<<8);
pIOPregs->GPFCON &= ~(3<<4);
pIOPregs->GPFCON |= (2<<4);
// end woo
return 0;
}
// end woo
static
VOID
FreeCtrlrContext(
PCTRLR_PDD_CONTEXT pContext
)
{
PREFAST_DEBUGCHK(pContext);
DEBUGCHK(!pContext->hevInterrupt);
DEBUGCHK(!pContext->hIST);
DEBUGCHK(!pContext->fRunning);
pContext->dwSig = GARBAGE_DWORD;
UnmapRegisterSet(pContext);
if (pContext->hBusAccess) CloseBusAccessHandle(pContext->hBusAccess);
if (pContext->dwSysIntr) {
KernelIoControl(IOCTL_HAL_DISABLE_WAKE, &pContext->dwSysIntr,
sizeof(pContext->dwSysIntr), NULL, 0, NULL);
}
if (pContext->dwIrq != IRQ_UNSPECIFIED) {
KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &pContext->dwSysIntr,
sizeof(DWORD), NULL, 0, NULL);
}
DeleteCriticalSection(&pContext->csIndexedRegisterAccess);
LocalFree(pContext);
}
DWORD
WINAPI
UfnPdd_Deinit(
PVOID pvPddContext
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
RETAILMSG(DBG, (_T("%s UfnPdd_Deinit\r\n"),
pszFname));
PCTRLR_PDD_CONTEXT pContext = (PCTRLR_PDD_CONTEXT) pvPddContext;
ValidateContext(pContext);
FUNCTION_ENTER_MSG();
FreeCtrlrContext(pContext);
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
DWORD
WINAPI
UfnPdd_Start(
PVOID pvPddContext
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
DWORD dwRet;
PCTRLR_PDD_CONTEXT pContext = (PCTRLR_PDD_CONTEXT) pvPddContext;
ValidateContext(pContext);
FUNCTION_ENTER_MSG();
DEBUGCHK(!pContext->fRunning);
BOOL fIntInitialized = FALSE;
// Create the interrupt event
pContext->hevInterrupt = CreateEvent(0, FALSE, FALSE, NULL);
if (pContext->hevInterrupt == NULL) {
dwRet = GetLastError();
RETAILMSG(DBG, (_T("%s Error creating interrupt event. Error = %d\r\n"),
pszFname, dwRet));
goto EXIT;
}
fIntInitialized = InterruptInitialize(pContext->dwSysIntr,
pContext->hevInterrupt, NULL, 0);
if (fIntInitialized == FALSE) {
dwRet = ERROR_GEN_FAILURE;
RETAILMSG(DBG, (_T("%s interrupt initialization failed\r\n"),
pszFname));
goto EXIT;
}
InterruptDone(pContext->dwSysIntr);
pContext->fExitIST = FALSE;
pContext->hIST = CreateThread(NULL, 0, ISTMain, pContext, 0, NULL);
if (pContext->hIST == NULL) {
RETAILMSG(DBG, (_T("%s IST creation failed\r\n"), pszFname));
dwRet = GetLastError();
goto EXIT;
}
// EINT2 Test Code by woo
g_PlugEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &g_PlugIrq, sizeof(UINT32), &g_PlugSysIntr, sizeof(UINT32), NULL))
{
RETAILMSG(1, (TEXT("ERROR: Plug Failed to request sysintr value for Plug interrupt.\r\n")));
return(0);
}
RETAILMSG(1,(TEXT("INFO: Plug: Mapped Irq 0x%x to SysIntr 0x%x.\r\n"), g_PlugIrq, g_PlugSysIntr));
if (!(InterruptInitialize(g_PlugSysIntr, g_PlugEvent, 0, 0)))
{
RETAILMSG(1, (TEXT("ERROR: Plug: Interrupt initialize failed.\r\n")));
}
if ( (g_PlugThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) PLUG_IST, pContext, 0, NULL)) == NULL) {
dwRet = GetLastError();
RETAILMSG(1,(TEXT("PCF50606 ERROR: Unable to create IST: %u\r\n"), dwRet));
goto EXIT;
}
if ( !CeSetThreadPriority(g_PlugThread, POWER_THREAD_PRIORITY)) {
dwRet = GetLastError();
RETAILMSG(1, (TEXT("PCF50606 ERROR: CeSetThreadPriority ERROR:%d \r\n"), dwRet));
goto EXIT;
}
// end woo
// USB Power Control after Finishing Booting by woo
// After Booting with USB Cable Plug Out, USB Power should be Cut off.
if ( pIOPregs->GPFDAT & (1<<2) )
{
#if 0
// Set the Normal mode
pIOPregs->GPHCON = (pIOPregs->GPHCON & ~(0x3<<28)) | (0x1<<28);
pIOPregs->GPHUDP = (pIOPregs->GPHUDP & ~(0x3<<28));
pIOPregs->GPHDAT = (pIOPregs->GPHDAT & ~(0x1<<14)) | (0x1<<14);
// Enable the PHY Power
pCLKPWR->PWRCFG |= (1<<4);
// First USB PHY has to be reset, and after 10us, func and host has to be reset.
pCLKPWR->USB_RSTCON = (0<<2)|(0<<1)|(1<<0);
Sleep(1);
pCLKPWR->USB_RSTCON = (1<<2)|(0<<1)|(0<<0);
pCLKPWR->USB_RSTCON = (0<<2)|(0<<1)|(0<<0);
RETAILMSG(1,(TEXT("+USB Cable Plug in\r\n")));
#endif
}
else
{
// Set the Normal mode
pIOPregs->GPHCON = (pIOPregs->GPHCON & ~(0x3<<28)) | (0x1<<28);
pIOPregs->GPHUDP = (pIOPregs->GPHUDP & ~(0x3<<28)) | (0x2<<28);
pIOPregs->GPHDAT = (pIOPregs->GPHDAT & ~(0x1<<14));
//Disable the PHY Power
pCLKPWR->PWRCFG = (pCLKPWR->PWRCFG & ~(0x1<<4));
pContext->pfnNotify(pContext->pvMddContext, UFN_MSG_BUS_EVENTS, UFN_DETACH);
pContext->attachedState = UFN_DETACH;
RETAILMSG(1,(TEXT("-USB Cable Plug out\r\n")));
}
// end woo
pContext->fRunning = TRUE;
dwRet = ERROR_SUCCESS;
EXIT:
if (pContext->fRunning == FALSE) {
DEBUGCHK(dwRet != ERROR_SUCCESS);
if (fIntInitialized) InterruptDisable(pContext->dwSysIntr);
if (pContext->hevInterrupt) CloseHandle(pContext->hevInterrupt);
pContext->hevInterrupt = NULL;
}
FUNCTION_LEAVE_MSG();
return dwRet;
}
// Stop the device.
DWORD
WINAPI
UfnPdd_Stop(
PVOID pvPddContext
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
RETAILMSG(DBG, (_T("%s UfnPdd_Stop\r\n"),
pszFname));
PCTRLR_PDD_CONTEXT pContext = (PCTRLR_PDD_CONTEXT) pvPddContext;
ValidateContext(pContext);
DEBUGCHK(pContext->fRunning);
// Stop the IST
pContext->fExitIST = TRUE;
InterruptDisable(pContext->dwSysIntr);
SetEvent(pContext->hevInterrupt);
WaitForSingleObject(pContext->hIST, INFINITE);
CloseHandle(pContext->hevInterrupt);
CloseHandle(pContext->hIST);
pContext->hIST = NULL;
pContext->hevInterrupt = NULL;
// EINT2 Test Code by woo
InterruptDisable(g_PlugSysIntr);
SetEvent(g_PlugEvent);
WaitForSingleObject(g_PlugThread, INFINITE);
CloseHandle(g_PlugEvent);
CloseHandle(g_PlugThread);
g_PlugThread = NULL;
g_PlugEvent = NULL;
// end woo
ResetDevice(pContext);
pContext->fRunning = FALSE;
// EINT2 Test Code by woo
if (pIOPregs)
{
VirtualFree((PVOID)pIOPregs, 0, MEM_RELEASE);
pIOPregs = NULL;
}
if (pCLKPWR)
{
VirtualFree((PVOID)pCLKPWR, 0, MEM_RELEASE);
pCLKPWR = NULL;
}
// end woo
DEBUGMSG(ZONE_FUNCTION, (_T("%s Device has been stopped\r\n"),
pszFname));
FUNCTION_LEAVE_MSG();
return ERROR_SUCCESS;
}
DWORD
WINAPI
UfnPdd_IsConfigurationSupportable(
PVOID pvPddContext,
UFN_BUS_SPEED Speed,
PUFN_CONFIGURATION pConfiguration
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
RETAILMSG(DBG, (_T("%s UfnPdd_IsConfigurationSupportable\r\n"),
pszFname));
DEBUGCHK((Speed == BS_FULL_SPEED) | (Speed == BS_HIGH_SPEED));
PCTRLR_PDD_CONTEXT pContext = (PCTRLR_PDD_CONTEXT) pvPddContext;
ValidateContext(pContext);
// This PDD does not have any special requirements that cannot be
// handled through IsEndpointSupportable.
DWORD dwRet = ERROR_SUCCESS;
FUNCTION_LEAVE_MSG();
return dwRet;
}
//
// Is this endpoint supportable.
DWORD
WINAPI
UfnPdd_IsEndpointSupportable(
PVOID pvPddContext,
DWORD dwEndpoint,
UFN_BUS_SPEED Speed,
PUSB_ENDPOINT_DESCRIPTOR pEndpointDesc,
BYTE bConfigurationValue,
BYTE bInterfaceNumber,
BYTE bAlternateSetting
)
{
SETFNAME();
FUNCTION_ENTER_MSG();
RETAILMSG(DBG, (_T("%s UfnPdd_IsEndpointSupportable\r\n"),
pszFname));
//RETAILMSG(1, (_T("%s UfnPdd_IsEndpointSupportable\r\n"),
// pszFname));
DEBUGCHK(EP_VALID(dwEndpoint));
DEBUGCHK((Speed == BS_FULL_SPEED) | (Speed == BS_HIGH_SPEED));
DWORD dwRet = ERROR_SUCCESS;
PCTRLR_PDD_CONTEXT pContext = (PCTRLR_PDD_CONTEXT) pvPddContext;
ValidateContext(pContext);
PEP_STATUS peps = GetEpStatus(pContext, dwEndpoint);
// Special case for endpoint 0
if (dwEndpoint == 0) {
DEBUGCHK(pEndpointDesc->bmAttributes == USB_ENDPOINT_TYPE_CONTROL);
// Endpoint 0 only supports 8 or 16 byte packet size
if (pEndpointDesc->wMaxPacketSize < EP_0_PACKET_SIZE) {
RETAILMSG(DBG, (_T("%s Endpoint 0 only supports %u byte packets\r\n"),
pszFname, EP_0_PACKET_SIZE));
dwRet = ERROR_INVALID_PARAMETER;
}
else{
// Larger than EP 0 Max Packet Size - reduce to Max
pEndpointDesc->wMaxPacketSize = EP_0_PACKET_SIZE;
}
}
else if (dwEndpoint < ENDPOINT_COUNT) {
BYTE bTransferType = pEndpointDesc->bmAttributes & USB_ENDPOINT_TYPE_MASK;
DEBUGCHK(bTransferType != USB_ENDPOINT_TYPE_CONTROL);
// Validate and adjust packet size
WORD wPacketSize =
(pEndpointDesc->wMaxPacketSize & USB_ENDPOINT_MAX_PACKET_SIZE_MASK);
switch(bTransferType) {
// Isoch not currently supported by Samsung HW
case USB_ENDPOINT_TYPE_ISOCHRONOUS:
RETAILMSG(DBG, (_T("%s Isochronous endpoints are not supported\r\n"),
pszFname));
dwRet = ERROR_INVALID_PARAMETER;
break;
case USB_ENDPOINT_TYPE_BULK:
case USB_ENDPOINT_TYPE_INTERRUPT:
// HW Can only Support 8, 16, 32, 64 byte packets
if((wPacketSize >= 8) && (wPacketSize < 16)){
wPacketSize = 8;
}
else if ((wPacketSize >= 16) && (wPacketSize < 32)){
wPacketSize = 16;
}
else if((wPacketSize >= 32) && (wPacketSize < 64)){
wPacketSize = 32;
}
else if ((wPacketSize >= 64) && (w
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -