⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bul_ohci.cpp

📁 pxa27x library for windows ce 5.0
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    m_pDCUSBOHCIReg->uhchr &= ~XLLP_USBOHCI_UHCHR_SSE;			// allow the values of SSEP1 and SSPE0 to control the power.

    DEBUGMSG(m_pDCUSBOHCIReg,(TEXT("OHCI_Reset: done.\r\n")));
    return TRUE;
}

// TurnOnUSBHostClocks:
//      This routine will make sure that the USB Host OHCI block in the
//      Bulverde core is getting clocks. If it is not getting clocks,
//      then some accesses to it may stall, especially if one needs to
//      wait for some OHCI register bits to change.
void
SOhcdPdd::TurnOnUSBHostClocks()
{
    // The clock enable bit for the USB Host OHCI block in Bulverde
    // is bit number 20.
    DEBUGMSG(ZONE_INIT,(TEXT("TurnOnUSBHostClocks: Initial Values: cccr: %08x cken: %08x oscc: %08x ccsr: %08x\n\r"), m_pDCCLKReg->cccr, m_pDCCLKReg->cken, m_pDCCLKReg->oscc, m_pDCCLKReg->ccsr));
    m_pDCCLKReg->cken |= XLLP_CLKEN_USBHOST;
    DEBUGMSG(ZONE_INIT,(TEXT("TurnOnUSBHostClocks: Final   Values: cccr: %08x cken: %08x oscc: %08x ccsr: %08x\n\r"), m_pDCCLKReg->cccr, m_pDCCLKReg->cken, m_pDCCLKReg->oscc, m_pDCCLKReg->ccsr));
}


// TurnOffUSBHostClocks:
//      This routine will make sure that the USB Host OHCI block in the
//      Bulverde core is not getting clocks. If it is not getting clocks,
//      then there will be power savings.
void
SOhcdPdd::TurnOffUSBHostClocks()
{
    // The clock enable bit for the USB Host OHCI block in Bulverde
    // is bit number 20.
    DEBUGMSG(ZONE_INIT,(TEXT("TurnOfUSBHostClocks: Initial Values: cccr: %08x cken: %08x oscc: %08x ccsr: %08x\n\r"), m_pDCCLKReg->cccr, m_pDCCLKReg->cken, m_pDCCLKReg->oscc, m_pDCCLKReg->ccsr));
    m_pDCCLKReg->cken &= ~XLLP_CLKEN_USBHOST;
    DEBUGMSG(ZONE_INIT,(TEXT("TurnOfUSBHostClocks: Final   Values: cccr: %08x cken: %08x oscc: %08x ccsr: %08x\n\r"), m_pDCCLKReg->cccr, m_pDCCLKReg->cken, m_pDCCLKReg->oscc, m_pDCCLKReg->ccsr));
}


void
SOhcdPdd::SelectUSBHOSTPowerManagementMode(
    int	Mode,
    int	NumPorts,
    int	*PortMode
    )
{
    switch(Mode) {
      case XLLP_USBOHCI_PPM_NPS:
        // set NO Power Switching mode
        m_pDCUSBOHCIReg->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
        m_pDCUSBOHCIReg->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
        m_pDCUSBOHCIReg->uhcrhda &= ~XLLP_USBOHCI_UHCRHDA_NPS;
        m_pDCUSBOHCIReg->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++ ) {
                m_pDCUSBOHCIReg->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
        m_pDCUSBOHCIReg->uhcrhda &= ~XLLP_USBOHCI_UHCRHDA_NPS;
        m_pDCUSBOHCIReg->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] ) {
                m_pDCUSBOHCIReg->uhcrhdb |= (unsigned int)( 1u << (p+17) );	// port 1 begins at bit 17
            }
            else   {
                m_pDCUSBOHCIReg->uhcrhdb &= ~(unsigned int)( 1u << (p+17) );	// port 1 begins at bit 17
            }

            }
        }

        break;
    }
}




// Manage WinCE suspend/resume events

DWORD SOhcdPdd::InitiatePowerUp()
{
    DEBUGMSG(ZONE_INIT,(TEXT("SOhcdPdd::InitiatePowerUp: m_pDCUSBOHCIReg: %08x.\r\n"), m_pDCUSBOHCIReg));


    TurnOnUSBHostClocks();	// make sure the ohci block is running (eg. getting clocked)
    SetupUSBHostPWR(0);		// this sets up Pwr 0 notification using gpio 88 as input in alternate function 1 mode
    SetupUSBHostPEN(0);		// this sets up Pwr 0 enable using gpio 89 as output in alternate function 2 mode
    //TurnOnUSBHostPorts();	// probably only do this after the rest of the ohci is set up.
    //TestUSBHostPEN(0);
    SelectUSBHOSTPowerManagementMode( XLLP_USBOHCI_PPM_NPS, 0, 0 );
    
    OHCI_Reset();
    return 0;
}
void SOhcdPdd::PowerUp()
{
    HcdMdd_PowerUp(m_pobOhcd);
}

void SOhcdPdd::PowerDown()
{

    // let the MDD do its processing (including putting the HC into reset)
    HcdMdd_PowerDown(m_pobOhcd);

    // disable the USB port as described in section 6.1.4.4 of the SA-1111 companion
    // chip documentation:
    // (1) Reset HC (done by MDD)
    // (2) wait 10 us
    // (3) clear global power enable bit
    // (4) set the standby enable bit
    // (5) stop the usb clock
    //usWait(10);                     // must not block or do operations illegal in interrupt context
    m_pDCUSBOHCIReg->uhcrhda &= ~ ((1 << 8) | (1 << 9));     // set global power switch mode
    m_pDCUSBOHCIReg->uhcrhs |= 0x0001;                   // clear global power
};


/* HcdPdd_DllMain
 * 
 *  DLL Entry point.
 *
 * Return Value:
 */
extern "C" BOOL HcdPdd_DllMain(HANDLE /*hinstDLL*/, DWORD /*dwReason*/, LPVOID /*lpvReserved*/)
{
    return TRUE;
}
// This gets called by the MDD's IST when it detects a power resume.
extern "C" void HcdPdd_InitiatePowerUp (DWORD hDeviceContext)
{
    SOhcdPdd * pPddObject = (SOhcdPdd *)hDeviceContext;
    if (pPddObject)
        pPddObject->InitiatePowerUp();
    
    return;
}


/* HcdPdd_Init
 *
 *   PDD Entry point - called at system init to detect and configure UHCI card.
 *
 * Return Value:
 *   Return pointer to PDD specific data structure, or NULL if error.
 */
extern "C" DWORD 
HcdPdd_Init(
    DWORD dwContext)  // IN - Pointer to context value. For device.exe, this is a string 
                      //      indicating our active registry key.
{
    SOhcdPdd *  pPddObject = CreateBulverdeOhci((LPCTSTR)dwContext);

    if (pPddObject && pPddObject->Init()) {
        DEBUGMSG(ZONE_INIT, (TEXT("HcdPdd_Init: Checking SW18 - controls OHCI loading.\r\n")));
        return (DWORD) pPddObject ;
    }
    if (pPddObject)
        delete pPddObject;
    return (DWORD)NULL;
}

/* HcdPdd_CheckConfigPower
 *
 *    Check power required by specific device configuration and return whether it
 *    can be supported on this platform.  For CEPC, this is trivial, just limit to
 *    the 500mA requirement of USB.  For battery powered devices, this could be 
 *    more sophisticated, taking into account current battery status or other info.
 *
 * Return Value:
 *    Return TRUE if configuration can be supported, FALSE if not.
 */
extern "C" BOOL HcdPdd_CheckConfigPower(
    UCHAR bPort,         // IN - Port number
    DWORD dwCfgPower,    // IN - Power required by configuration
    DWORD dwTotalPower)  // IN - Total power currently in use on port
{
    return ((dwCfgPower + dwTotalPower) > 500) ? FALSE : TRUE;
}

extern "C" void HcdPdd_PowerUp(DWORD hDeviceContext)
{
    SOhcdPdd * pPddObject = (SOhcdPdd *)hDeviceContext;
    DEBUGMSG(ZONE_INIT, (TEXT("HcdPdd_PowerUp: enter.\n\r")));
    if (pPddObject)
        pPddObject->PowerUp();
    DEBUGMSG(ZONE_INIT, (TEXT("HcdPdd_PowerUp: Need to add Bulverde support.\n\r")));
    return;
}

extern "C" void HcdPdd_PowerDown(DWORD hDeviceContext)
{
    SOhcdPdd * pPddObject = (SOhcdPdd *)hDeviceContext;
    DEBUGMSG(ZONE_INIT, (TEXT("HcdPdd_PowerDown: enter.\n\r")));
    if (pPddObject)
        pPddObject->PowerDown();

    DEBUGMSG(ZONE_INIT, (TEXT("HcdPdd_PowerDown: Need to add Bulverde support.\n\r")));
    return;
}


extern "C" BOOL HcdPdd_Deinit(DWORD hDeviceContext)
{
    SOhcdPdd * pPddObject = (SOhcdPdd *)hDeviceContext;
    if (pPddObject)
        delete pPddObject;
    return TRUE;
}


extern "C" DWORD HcdPdd_Open(DWORD /*hDeviceContext*/, DWORD /*AccessCode*/,
        DWORD /*ShareMode*/)
{

    return 1; // we can be opened, but only once!
}


extern "C" BOOL HcdPdd_Close(DWORD /*hOpenContext*/)
{
    return TRUE;
}


extern "C" DWORD HcdPdd_Read(DWORD /*hOpenContext*/, LPVOID /*pBuffer*/, DWORD /*Count*/)
{
    return (DWORD)-1; // an error occured
}


extern "C" DWORD HcdPdd_Write(DWORD /*hOpenContext*/, LPCVOID /*pSourceBytes*/,
        DWORD /*NumberOfBytes*/)
{
    return (DWORD)-1;
}


extern "C" DWORD HcdPdd_Seek(DWORD /*hOpenContext*/, LONG /*Amount*/, DWORD /*Type*/)
{
    return (DWORD)-1;
}


extern "C" BOOL HcdPdd_IOControl(DWORD /*hOpenContext*/, DWORD /*dwCode*/, PBYTE /*pBufIn*/,
        DWORD /*dwLenIn*/, PBYTE /*pBufOut*/, DWORD /*dwLenOut*/, PDWORD /*pdwActualOut*/)
{
    return FALSE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -