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

📄 isp1504_ulpi.c

📁 LP1071 无线局域网卡WinCE驱动程序
💻 C
字号:
//------------------------------------------------------------------------------
//
//  Copyright (C) 2005-2006, Freescale Semiconductor, Inc. All Rights Reserved.
//  THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
//  AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT 
//
//------------------------------------------------------------------------------

//--------------------------------------------------------------------------
//  File:     ISP1504_ULPI.c
//  Purpose:  Common routines for manipulating ISP1504 controller
//  Functions: WakeUpULPI   - initiate wakeup on suspended 1504 transceiver
//           The following 3 functions access transceiver directly via ULPI and
//           must be coordinated with host/device controller access to ULPI.
//           Controller should be stopped to avoid ULPI bus clash.
//             ISP1504_ReadReg()     read a transceiver register via viewport
//             ISP1504_WriteReg()    write a transceiver register via viewport
//             DumpULPIRegs  - diagnostic dump of transceiver registers
//--------------------------------------------------------------------------
#include <windows.h>
#include <Winbase.h>
#include <ceddk.h>
#include "bsp.h"
#include "mx27_usbcommon.h"

#ifdef DEBUG

#define ZONE_FUNCTION         DEBUGZONE(3)
#define ZONE_ERROR            DEBUGZONE(0)

extern DBGPARAM dpCurSettings;
#endif

//-----------------------------------------------------------------------------
//
//  Function: WakeUpULPI
//
//  This function is to wakeup the ULPI if it is suspend through viewport
//
//  Parameters:
//     reg - Pointer to the corresponding ULPI viewport registers
//     
//  Returns:
//     TRUE - success, FALSE - failure
//
//-----------------------------------------------------------------------------
static BOOL WakeUpULPI(volatile DWORD *reg)
{
    USB_ULPI_VIEWPORT_T ulpi;
    int i;
    DWORD * temp = (DWORD *)&ulpi;
    
    *temp = INREG32(reg);    
    if (ulpi.ULPISS == 0)
    {
        *temp = 0;
        ulpi.ULPIWU = 1;
        ulpi.ULPIRUN = 0;
        OUTREG32(reg, *temp);
        for (i = 0; i < 2000; i++) {
            *temp = INREG32(reg);
            if (ulpi.ULPIWU == 0)
                return TRUE;
            Sleep(0);
        }
        *temp = INREG32(reg);
        if (ulpi.ULPIWU == 1)
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("WakeUpULPI return FALSE\r\n")));
            return FALSE;
        }
    }
    return TRUE;
}

//-----------------------------------------------------------------------------
//
//  Function: ISP1504_ReadReg
//
//  This function is to read the value of ULPI transceiver via viewport
//
//  Parameters:
//     reg - Pointer to the ULPI viewport register
//     idx - Offset of the ULPI viewport register want to access.
//     Refer to mx31_usbcommon.h in csp\arm\freescale\mx31\inc for full list
//     
//  Returns:
//     value in the register in unsigned character format.
//     0 - indicate failure
//
//-----------------------------------------------------------------------------
UCHAR ISP1504_ReadReg(volatile DWORD * reg, UCHAR idx)
{
	USB_ULPI_VIEWPORT_T ulpi;
	DWORD * temp=(DWORD *)&ulpi;
    int iAttempts;
	
    WakeUpULPI(reg);
	*temp=0;
	ulpi.ULPIRUN=1;
	ulpi.ULPIADDR=idx;
 	OUTREG32(reg, *temp);	

    iAttempts = 0;
    do {
        Sleep(0);
        *temp = INREG32(reg);
        
        if ( !ulpi.ULPIRUN )
		{
			DEBUGMSG(ZONE_FUNCTION,(TEXT("ISP1504_ReadReg: ############ read ULPI ulpi.ULPIDATRD %x\r\n"), ulpi.ULPIDATRD));
            return ulpi.ULPIDATRD;
		}

    } while ( iAttempts++ < 1000 );

	DEBUGMSG(ZONE_ERROR,(TEXT("ISP1504_ReadReg: ############ Error -- failed to read ULPI reg %d\r\n"), idx));

	return 0;
}

//-----------------------------------------------------------------------------
//
//  Function: ISP1504_WriteReg
//
//  This function is to write the data to register of ULPI transceiver via viewport
//
//  Parameters:
//     reg - Pointer to the ULPI viewport register
//     idx - Offset of the ULPI viewport register want to access.
//     Refer to mx31_usbcommon.h in csp\arm\freescale\mx31\inc for full list
//     data - Data to be written
//     
//  Returns:
//     TRUE - success, FALSE - failure
//
//-----------------------------------------------------------------------------
BOOL ISP1504_WriteReg(volatile DWORD * reg, UCHAR idx, UCHAR data)
{
	USB_ULPI_VIEWPORT_T ulpi;
	DWORD * temp=(DWORD *)&ulpi;
    int iAttempts;

    WakeUpULPI(reg);
	*temp=0;
	ulpi.ULPIRUN=1;
	ulpi.ULPIADDR=idx;
	ulpi.ULPIRW=1;
	ulpi.ULPIDATWR=data;
 	OUTREG32(reg, *temp);	

    iAttempts = 0;
    do {
        Sleep(0);
        *temp = INREG32(reg);

        if ( !ulpi.ULPIRUN )
		{
			DEBUGMSG(ZONE_FUNCTION,(TEXT("ISP1504_WriteReg: ############ wrote ULPI reg %d\r\n"), ulpi.ULPIRUN));
            return TRUE;
		}

    } while ( iAttempts++ < 1000 );

	DEBUGMSG(ZONE_ERROR,(TEXT("ISP1504_WriteReg: ############ Error -- failed to write ULPI reg %d\r\n"), idx));
    return FALSE;
}

//-----------------------------------------------------------------------------
//
//  Function: DumpULPIRegs
//
//  This function is to dump the ULPI register for debug purpose
//
//  Parameters:
//     regs - Pointer to the 3 USB Core Registers
//     
//  Returns:
//     NULL
//
//-----------------------------------------------------------------------------
void DumpULPIRegs(CSP_USB_REGS * regs)
{
    volatile CSP_USB_REG *pReg;
    // Read the ID
  /*  WORD sel = BSPGetUSBControllerType();
    
    if (sel == USB_SEL_OTG)
        pReg = &regs->OTG;
    else if (sel == USB_SEL_H2)
        pReg = &regs->H2;
    else
        return;
*/

	 pReg = &regs->H2;
    DEBUGMSG(ZONE_FUNCTION, (L"Dump PORTSC (0x%x)\r\n", INREG32(&pReg->PORTSC[0])));
    DEBUGMSG(ZONE_FUNCTION, (L"Dump ULPI registers(%x)\r\n", INREG32(&pReg->ULPI_VIEWPORT)));    
    DEBUGMSG(ZONE_FUNCTION, (L"\tULPI_VID=(%x,%x)\r\n", 
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_VENDERID_LOW_R),
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_VENDERID_HIGH_R)));
    DEBUGMSG(ZONE_FUNCTION, (L"\tULPI_PID=(%x,%x)\r\n", 
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_PRODUCT_LOW_R),
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_PRODUCT_HIGH_R)));

    // XCVR Select[1:0]=00, Term Select[2]=0, OP Mode[4:3]=00
//      ISP1504_WriteReg(&pReg->ULPI_VIEWPORT, ISP1504_FUNCTION_CTRL_C, 0x1f);
    DEBUGMSG(ZONE_FUNCTION, (L"\tFunction Control(%x)=%x\r\n", 
            ISP1504_FUNCTION_CTRL_RW,
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_FUNCTION_CTRL_RW)));
    DEBUGMSG(ZONE_FUNCTION, (L"\tInterface Control(%x)=%x\r\n", 
            ISP1504_INTERFACE_CTRL_RW,
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_INTERFACE_CTRL_RW)));
    // DP_PullDown[1]=0, DM_PullDown[2]=0
//      ISP1504_WriteReg(&pReg->ULPI_VIEWPORT, ISP1504_OTG_CTRL_C, 0x6);
    DEBUGMSG(ZONE_FUNCTION, (L"\tOTG Control(%x)=%x\r\n", 
            ISP1504_OTG_CTRL_RW,
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_OTG_CTRL_RW)));
    DEBUGMSG(ZONE_FUNCTION, (L"\tInterrupt Enable rising(%x)=%x\r\n", 
            ISP1504_INTR_RISING_RW,
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_INTR_RISING_RW)));
    DEBUGMSG(ZONE_FUNCTION, (L"\tInterrupt Enable Falling(%x)=%x\r\n", 
            ISP1504_INTR_FALLING_RW,
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_INTR_FALLING_RW)));
    DEBUGMSG(ZONE_FUNCTION, (L"\tInterrupt Status(%x)=%x\r\n", 
            ISP1504_INTR_STATUS_R,
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_INTR_STATUS_R)));
    DEBUGMSG(ZONE_FUNCTION, (L"\tInterrupt Latch(%x)=%x\r\n", 
            ISP1504_INTR_LATCH_RC,
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_INTR_LATCH_RC)));
    DEBUGMSG(ZONE_FUNCTION, (L"\tDebug(%x)=%x\r\n", 
            ISP1504_DEBUG_R,
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_DEBUG_R)));
    DEBUGMSG(ZONE_FUNCTION, (L"\tScratch(%x)=%x\r\n", 
            ISP1504_SCRATCH_RW,
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_SCRATCH_RW)));
    DEBUGMSG(ZONE_FUNCTION, (L"\tPower(%x)=%x\r\n", 
            ISP1504_POWER_CTRL_RW,
            ISP1504_ReadReg(&pReg->ULPI_VIEWPORT, ISP1504_POWER_CTRL_RW)));
}

⌨️ 快捷键说明

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