📄 isp1504.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.c
// Purpose: Contains configuration routines specific to the ISP 1504 transceiver,
// when used as OTG (host+client).
//
// Functions:
// // these routines manipulate the ISP1504 transceiver via ULPI bus
// void SetULPIToClientMode(CSP_USB_REGS //regs) - switch from host to client
// BOOL Initialize1504Host(CSP_USB_REGS * regs) - setup for host mode
// BOOL Initialize1504Client(CSP_USB_REGS * regs) - setup for client mode, including
// configuring the IOMUX
//------------------------------------------------------------------------------
#include <windows.h>
#include <Winbase.h>
#include <ceddk.h>
#include "bsp.h"
#include "mx31_usbcommon.h"
#ifdef FORCE_FULLSPEED
#undef FORCE_FULLSPEED
//#define FORCE_FULLSPEED 1
#endif
#ifdef DEBUG
#define ZONE_FUNCTION DEBUGZONE(3)
#define ZONE_ERROR DEBUGZONE(0)
extern DBGPARAM dpCurSettings;
#endif
//-----------------------------------------------------------------------------
//
// Function: SetULPIToClientMode
//
// This function is called by CSP public module to configure the ULPI to client
// mode before putting the ULPI to suspend mode.
//
// Parameters:
// regs - Pointer to the 3 USB Core registers.
//
// Returns:
// NONE
//
//-----------------------------------------------------------------------------
void SetULPIToClientMode(CSP_USB_REGS *regs)
{
DWORD temp;
DEBUGMSG(ZONE_FUNCTION, (TEXT("+SetULPIToClientMode\r\n")));
// resetting the PHY doesn't reset the ULPI. It does seem to reset the state though.
//
// Transceiver reset
// DEBUGMSG(ZONE_FUNCTION, (TEXT("RESET the PHY\r\n")));
// ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_FUNCTION_CTRL_S, 0x20);
temp = ISP1504_ReadReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_RW);
// enable ID pull up
if ((temp & 0x1) == 0)
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_S, 0x1); // ID_PULLUP
// disable external vbus supply
// onboard power supply MC13783 feeds through MAX4787 current limit switch
if (temp & 0x40)
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_C, 0x40); // DRV_VBUS_EXT
// disable vbus (internal)
// use external VBus power supply from MC17383 DC-DC converter
if (temp & 0x20)
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_C, 0x20); // DRV_VBUS
// disable external vbus (fault) indicator
// use MAX4787 fault flag to indicate over current condition
if ((temp & 0x80) == 0)
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_S, 0x80); // USE_EXT_VBUS_IND
// Discharge VBus
if ((temp & 0x08) == 0)
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_S, 0x08); // USE_EXT_VBUS_IND
if ((temp & 0x4) == 0) // DM_PULL DOWN up
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_S, 0x4);
if (temp & 0x2)// DP_PULL DOWN off
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_C, 0x2);
temp = ISP1504_ReadReg(®s->OTG.ULPI_VIEWPORT, ISP1504_FUNCTION_CTRL_RW);
// Term select
if ((temp & 0x4) == 0)
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_FUNCTION_CTRL_S, 0x4);
// disable the ULPI interrupt
temp = ISP1504_ReadReg(®s->OTG.ULPI_VIEWPORT, ISP1504_INTR_RISING_RW);
if (temp & 0xF)
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_INTR_RISING_C, 0xF);
temp = ISP1504_ReadReg(®s->OTG.ULPI_VIEWPORT, ISP1504_INTR_FALLING_RW);
if (temp & 0xF)
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_INTR_FALLING_C, 0xF);
}
//-----------------------------------------------------------------------------
//
// Function: Initialize1504Host
//
// This function is to configure the ISP1504 transceiver and corresponding
// USB OTG Core with USB Host functionality
//
// Parameters:
// regs - Pointer to the 3 USB Core registers.
//
// Returns:
// TRUE - success, FALSE - failure
//
//-----------------------------------------------------------------------------
BOOL Initialize1504Host(CSP_USB_REGS * regs)
{
//
DWORD * temp;
USB_HCSPARAMS_T hcs;
temp=(DWORD *)&hcs;
*temp=INREG32(®s->OTG.HCSPARAMS);
if (hcs.PPC) {
USB_PORTSC_T portsc;
temp=(DWORD *)&portsc;
*temp=0;
//
// read current value of PORTSC
*temp=INREG32(®s->OTG.PORTSC);
// clear all bits (by writing 1) with the exception of:
portsc.CSC=0; portsc.PEC=0; portsc.OCC=0;
OUTREG32(®s->OTG.PORTSC, *temp);
}
// Transceiver reset
DEBUGMSG(ZONE_FUNCTION, (TEXT("Access PHY set to host mode - USBXVR\r\n")));
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_FUNCTION_CTRL_S, 0x20);
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_S, 0x1); // ID_PULLUP
// enable external vbus supply
// onboard power supply MC13783 feeds through MAX4787 current limit switch
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_S, 0x40); // DRV_VBUS_EXT
// disable vbus (internal)
// use external VBus power supply from MC17383 DC-DC converter
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_S, 0x20); // DRV_VBUS
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_S, 0x10); // VBus Charge
// enable external vbus (fault) indicator
// use MAX4787 fault flag to indicate over current condition
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_S, 0x80); // USE_EXT_VBUS_IND
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: Initialize1504Client
//
// This function is to configure the ISP1504 transceiver and corresponding
// USB OTG Core with USB Client functionality
//
// Parameters:
// regs - Pointer to the 3 USB Core registers.
//
// Returns:
// TRUE - success, FALSE - failure
//
//-----------------------------------------------------------------------------
BOOL Initialize1504Client(CSP_USB_REGS * regs)
{
//
DWORD * temp;
int i = 0;
//RETAILMSG(1, (TEXT("Initialize1504Client here\r\n")));
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_USBOTG_DATA0, DDK_IOMUX_PAD_SLEW_FAST,DDK_IOMUX_PAD_DRIVE_MAX,
DDK_IOMUX_PAD_MODE_CMOS, DDK_IOMUX_PAD_TRIG_CMOS, DDK_IOMUX_PAD_PULL_UP_100K);
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_USBOTG_DATA1, DDK_IOMUX_PAD_SLEW_FAST,DDK_IOMUX_PAD_DRIVE_MAX,
DDK_IOMUX_PAD_MODE_CMOS, DDK_IOMUX_PAD_TRIG_CMOS, DDK_IOMUX_PAD_PULL_UP_100K);
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_USBOTG_DATA2, DDK_IOMUX_PAD_SLEW_FAST,DDK_IOMUX_PAD_DRIVE_MAX,
DDK_IOMUX_PAD_MODE_CMOS, DDK_IOMUX_PAD_TRIG_CMOS, DDK_IOMUX_PAD_PULL_UP_100K);
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_USBOTG_DATA3, DDK_IOMUX_PAD_SLEW_FAST,DDK_IOMUX_PAD_DRIVE_MAX,
DDK_IOMUX_PAD_MODE_CMOS, DDK_IOMUX_PAD_TRIG_CMOS, DDK_IOMUX_PAD_PULL_UP_100K);
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_USBOTG_DATA4, DDK_IOMUX_PAD_SLEW_FAST,DDK_IOMUX_PAD_DRIVE_MAX,
DDK_IOMUX_PAD_MODE_CMOS, DDK_IOMUX_PAD_TRIG_CMOS, DDK_IOMUX_PAD_PULL_UP_100K);
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_USBOTG_DATA5, DDK_IOMUX_PAD_SLEW_FAST,DDK_IOMUX_PAD_DRIVE_MAX,
DDK_IOMUX_PAD_MODE_CMOS, DDK_IOMUX_PAD_TRIG_CMOS, DDK_IOMUX_PAD_PULL_UP_100K);
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_USBOTG_DATA6, DDK_IOMUX_PAD_SLEW_FAST,DDK_IOMUX_PAD_DRIVE_MAX,
DDK_IOMUX_PAD_MODE_CMOS, DDK_IOMUX_PAD_TRIG_CMOS, DDK_IOMUX_PAD_PULL_UP_100K);
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_USBOTG_DATA7, DDK_IOMUX_PAD_SLEW_FAST,DDK_IOMUX_PAD_DRIVE_MAX,
DDK_IOMUX_PAD_MODE_CMOS, DDK_IOMUX_PAD_TRIG_CMOS, DDK_IOMUX_PAD_PULL_UP_100K);
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_USBOTG_STP, DDK_IOMUX_PAD_SLEW_FAST,DDK_IOMUX_PAD_DRIVE_MAX,
DDK_IOMUX_PAD_MODE_CMOS, DDK_IOMUX_PAD_TRIG_CMOS, DDK_IOMUX_PAD_PULL_UP_100K);
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_USBOTG_NXT, DDK_IOMUX_PAD_SLEW_FAST,DDK_IOMUX_PAD_DRIVE_MAX,
DDK_IOMUX_PAD_MODE_CMOS, DDK_IOMUX_PAD_TRIG_CMOS, DDK_IOMUX_PAD_PULL_UP_100K);
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_USBOTG_DIR, DDK_IOMUX_PAD_SLEW_FAST,DDK_IOMUX_PAD_DRIVE_MAX,
DDK_IOMUX_PAD_MODE_CMOS, DDK_IOMUX_PAD_TRIG_CMOS, DDK_IOMUX_PAD_PULL_UP_100K);
DDKIomuxSetPadConfig(DDK_IOMUX_PAD_USBOTG_CLK, DDK_IOMUX_PAD_SLEW_FAST,DDK_IOMUX_PAD_DRIVE_MAX,
DDK_IOMUX_PAD_MODE_CMOS, DDK_IOMUX_PAD_TRIG_CMOS, DDK_IOMUX_PAD_PULL_UP_100K);
// usb_otg_ulpi_interface_config()
{
USB_PORTSC_T portsc;
temp=(DWORD *)&portsc;
*temp=INREG32(®s->OTG.PORTSC);
// Set PORTSC
//RETAILMSG(1, (TEXT("Set the transceiver driver to suspend mode\r\n")));
portsc.PTS=2; //Parallel Transeiver to ULPI
portsc.WKDC = 1;
portsc.WKCN = 1;
// portsc.PHCD = 1; // the suspend should be set only after it is ready
*temp|=(2<<10); // IS THIS REALLY MEANT TO BE HERE?
// first mask out the PTS field, then set all the above bits
INSREG32(®s->OTG.PORTSC,(3<<30),*temp);
}
//usb_otg_ulpi_interrupt_enable() && usb_otg_power_mask_enable()
{
USB_CTRL_T ctrl;
temp=(DWORD *)&ctrl;
*temp = INREG32(®s->USB_CTRL);
ctrl.OUIE=1; // OUIE -- OTG ULPI interrupt enable
ctrl.OPM=1; // OTG Power Mask
ctrl.OWIE = 1;
SETREG32(®s->USB_CTRL, *temp);
}
// otg_power_on_port1()
{
USB_HCSPARAMS_T hcs;
temp=(DWORD *)&hcs;
*temp=INREG32(®s->OTG.HCSPARAMS);
if (hcs.PPC) {
USB_PORTSC_T portsc;
temp=(DWORD *)&portsc;
*temp = INREG32(®s->OTG.PORTSC);
// (write 1 to) clear any set bits, with the exception of:
portsc.CSC=0; portsc.PEC=0; portsc.OCC=0;
// and write a 1 to PP as well
portsc.PP=1;
OUTREG32(®s->OTG.PORTSC,*temp);
}
}
// usb cmd
{
USB_USBCMD_T cmd;
temp=(DWORD *)&cmd;
*temp=INREG32(®s->OTG.USBCMD);
cmd.ITC=0x08;
OUTREG32(®s->OTG.USBCMD, *temp);
}
// Enable interrupts - transceiver should disable all other interrupts
// as this would affect the running of the system.
OUTREG32(®s->OTG.USBINTR, 0x07f);
// OUTREG32(®s->OTG.USBINTR, 0x5ff);
// initial endpoints
for (i=0;i<15;i++)
OUTREG32(®s->OTG.ENDPTCTRL[i], 0x400040);
OUTREG32(®s->OTG.T_154H.USBADR, 0);
//RETAILMSG(1, (TEXT("Acccess PHY\r\n")));
// Transceiver reset
DEBUGMSG(ZONE_FUNCTION, (TEXT("Access PHY set to client mode - USBXVR\r\n")));
// Execute Reset
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_FUNCTION_CTRL_S, 0x20);
// enable ID pull up
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_S, 0x1); // ID_PULLUP
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_FUNCTION_CTRL_S, 0x4); // Term select
// DM_PULL DOWN up
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_S, 0x4);
// DP_PULL DOWN off
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_C, 0x2);
// disable external vbus supply
// onboard power supply MC13783 feeds through MAX4787 current limit switch
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_C, 0x40); // DRV_VBUS_EXT
// disable vbus (internal)
// use external VBus power supply from MC17383 DC-DC converter
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_C, 0x20); // DRV_VBUS
// disable external vbus (fault) indicator
// use MAX4787 fault flag to indicate over current condition
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_S, 0x80); // USE_EXT_VBUS_IND
// Discharge VBus
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_OTG_CTRL_S, 0x08); // USE_EXT_VBUS_IND
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_INTR_RISING_C, 0xF);
ISP1504_WriteReg(®s->OTG.ULPI_VIEWPORT, ISP1504_INTR_FALLING_C, 0xF);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -