📄 sl11h.c
字号:
/* ********************************************************************* * Broadcom Common Firmware Environment (CFE) * * BCM1250CPCI USB Driver File: sl11h.c * * USB Include definitions * * Author: Paul Burrell * Parts of code extracted from Scanlogic USB demo driver * ********************************************************************* * * Copyright 2000,2001,2002,2003 * Broadcom Corporation. All rights reserved. * * This software is furnished under license and may be used and * copied only in accordance with the following terms and * conditions. Subject to these conditions, you may download, * copy, install, use, modify and distribute modified or unmodified * copies of this software in source and/or binary form. No title * or ownership is transferred hereby. * * 1) Any source code used, modified or distributed must reproduce * and retain this copyright notice and list of conditions * as they appear in the source file. * * 2) No right is granted to use any trade name, trademark, or * logo of Broadcom Corporation. The "Broadcom Corporation" * name may not be used to endorse or promote products derived * from this software without the prior written permission of * Broadcom Corporation. * * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************* *///#include <stdio.h>//#include <string.h>//#include <stdlib.h>//#include <stdarg.h>#include "lib_types.h"#include "lib_printf.h"#include "lib_string.h"#include "cfe_timer.h"#include "sbmips.h"#include "sb1250_regs.h"#include "sb1250_smbus.h"#include "bcm91125pcix.h"#include "sl11h.h"#define SBWRITEUSB(csr,val) *((volatile unsigned char *) PHYS_TO_K1(csr)) = (val)#define SBREADUSB(csr) (*((volatile unsigned char *) PHYS_TO_K1(csr)))unsigned short crc5(unsigned short f);unsigned int usbXfer(unsigned char pid, unsigned short crc, unsigned int len, unsigned char *buf);short ep0Xfer(PSetupPKG setup, unsigned char *pData);short VendorCmd(unsigned char bReq,unsigned char bCmd,unsigned short wValue,unsigned short wIndex,unsigned short wLen,unsigned char* pData);short GetDesc(unsigned short wValue, unsigned int cDesc, void * desc);short SetAddress(unsigned short addr);short uDataRead(unsigned int cData,void * pData);short uDataWrite(unsigned int cData,void * pData);short uCloseUsbDev(void);int speed_detect(void);/*-------------------------------------------------------------------------- * Byte Read from SL11 * Input: address = address of SL11 register or memory * Input: port = usb port * Output: return data *-------------------------------------------------------------------------- */unsigned char SL11Read(unsigned int address){ if (address > 0xff) { printf("Invalid register access, register %x\n"); return (0x0); }// printf("Address = %08X\n",PHYS_TO_K1(USBCTL_PHYS)); SBWRITEUSB(USBCTL_PHYS,address);// printf("Address = %08X\n",PHYS_TO_K1(USBCTL_PHYS + A0_OFFSET)); return(SBREADUSB(USBCTL_PHYS + A0_OFFSET));}/*-------------------------------------------------------------------------- * Byte Write to SL11 * Input: address = address of SL11 register or memory, d = data * Input: port = usb port * Input: data = data to output *-------------------------------------------------------------------------- */void SL11Write(unsigned int address, unsigned char data){ if (address > 0xff) { printf("Invalid register access, register %x\n"); } SBWRITEUSB(USBCTL_PHYS,address); SBWRITEUSB(USBCTL_PHYS + A0_OFFSET,data);}/*-------------------------------------------------------------------------- * Buffer Read from SL11 * Input: address = address of SL11 register or memory * byte_count = byte count * buffer = char buffer * Output: None *-------------------------------------------------------------------------- */void SL11BufRead(short address,unsigned char *buffer, short byte_count){ if (byte_count <= 0) return; SBWRITEUSB(USBCTL_PHYS,address); while (byte_count--) *buffer++ = SBREADUSB(USBCTL_PHYS + A0_OFFSET);}/*-------------------------------------------------------------------------- * Buffer Write to SL11 * Input: address = address of SL11 register or memory * byte_count = byte count * buffer = char buffer *-------------------------------------------------------------------------- */void SL11BufWrite(short address, unsigned char *buffer, short byte_count){ if(byte_count <= 0) return; SBWRITEUSB(USBCTL_PHYS,address); while (byte_count--) SBWRITEUSB(USBCTL_PHYS + A0_OFFSET,*buffer++);}//--------------------------------------------------------------------------// Delayms mili second//--------------------------------------------------------------------------//void Delayms(unsigned int tt)//{ // unsigned int time;// time=GetTickCount();// while(GetTickCount() < time+tt);//}/**************************************************************************** * Full-speed and slow-speed detect ****************************************************************************/int speed_detect(void){ int i=0; int full_speed; full_speed = 0xffff; SL11Write(IntEna, 0x63); // USBA/B, Insert/Remove,USBRest/Resume. SL11Write(cSOFcnt, 0xae); // Set SOF high counter, no change D+/D-// SL11Write(CtrlReg, 0x48); // Setup Normal Operation SL11Write(CtrlReg, 0x08); // Setup Normal Operation SL11Write(CtrlReg, (unsigned char)i); // Disable USB transfer operation and SOF SL11Write(cSOFcnt, 0xae); // Set SOF high counter, no change D+/D-// SL11Write(CtrlReg, 0x48); // Clear SL811H mode and setup normal operation SL11Write(CtrlReg, 0x08); // Clear SL811H mode and setup normal operation cfe_sleep(1); // Sleep 10 ms SL11Write(CtrlReg, 0); // Disable USB transfer operation and SOF cfe_sleep(1); // Sleep 10 ms (original file 1ms) SL11Write(IntStatus,0xff); i = SL11Read(IntStatus); // Read Interrupt Status if(i & 0x40) { printf("Device is Removed\n"); return 0; } if ((i & 0x80) == 0) { // Checking full or slow speed printf("Slow Speed is detected %x\n", i); SL11Write(cSOFcnt,0xee); // Set up Master and Slow Speed direct and SOF cnt high=0x2e SL11Write(cDATASet,0xe0); // SOF Counter Low = 0xe0; 1ms interval SL11Write(CtrlReg,0x21); // Setup 6MHz and EOP enable full_speed = 0; } else { printf("Full Speed is detected %x\n", i); SL11Write(cSOFcnt,0xae); // Set up Master and Slow Speed direct and SOF cnt high=0x2e SL11Write(cDATASet,0xe0); // SOF Counter Low = 0xe0; 1ms interval SL11Write(CtrlReg,0x05); // Setup 48MHz and SOF enable } SL11Write(EP0Status, 0x50); SL11Write(EP0Counter, 0); SL11Write(EP0Control, 0x01); // start generate SOF or EOP cfe_sleep(3); // Sleep 30 ms// Delayms(25); // Hub required approx. 24.1mS return 0; }/*------------------------------------------------------------------------- * SL11 Memory test * Input: None * Output: return 0 = no error *------------------------------------------------------------------------- */int SL11HMemTest(void){ int errors = 0; int i; /* Write Data to buffer */ for (i=EP0Buf; i<sMemSize; i++) SL11Write((unsigned char)i,(unsigned char)i); /* Verify Data in buffer using byte checks */ for (i=EP0Buf; i<sMemSize; i++) { if ((unsigned char)i != SL11Read((unsigned char)i)) errors++; SL11Write ((unsigned char)i,(unsigned char)~i); if ((unsigned char)~i != SL11Read((unsigned char)i)) errors++; } /* Write data to buffer using auto increment mode */ SBWRITEUSB(USBCTL_PHYS,EP0Buf); for (i=EP0Buf; i<sMemSize; i++) SBWRITEUSB(USBCTL_PHYS + A0_OFFSET,i); /* Verify data in buffer using auto increment mode */ SBWRITEUSB(USBCTL_PHYS,EP0Buf); for (i=EP0Buf; i<sMemSize; i++) { if ((unsigned char)i != SBREADUSB(USBCTL_PHYS + A0_OFFSET)) //(unsigned char)*(unsigned char *)(PHYS_TO_K1(USBCTL_PHYS + A0_OFFSET))) errors++; } /* Clear memory in buffer using auto increment mode */ SBWRITEUSB(USBCTL_PHYS,EP0Buf); for (i=EP0Buf; i<sMemSize; i++) SBWRITEUSB(USBCTL_PHYS + A0_OFFSET,0); return errors;}/*------------------------------------------------------------------------- * SL11 Reset * Input: None * Output: None *------------------------------------------------------------------------- */void USBReset(void){ unsigned char tmp; tmp = SL11Read(CtrlReg); SL11Write(CtrlReg, tmp | 0x08); cfe_sleep(CFE_HZ / 4); // Delay 250 ms SL11Write(CtrlReg, tmp | 0x18); cfe_sleep(CFE_HZ / 6); // Delay 166 ms SL11Write(CtrlReg, tmp | 0x08); cfe_sleep(CFE_HZ / 10); // Delay 100ms speed_detect();// SL11Write(CtrlReg, tmp & 0xBF);// SL11Write(CtrlReg, 8); /* Setup USB Reset */// cfe_sleep(CFE_HZ / 10); /* Delay 100ms */// SL11Write(CtrlReg, 0); /* Enable USB */// cfe_sleep(CFE_HZ / 10); /* Delay 100ms */// SL11Write(0x0d, 0xff);}/* From original */// BYTE tmp;// tmp = SL11Read(CtrlReg); // SL11Write(CtrlReg, (BYTE)(tmp | 8)); // Setup USB Reset// Delayms(20);// SL11Write(CtrlReg, tmp); // enable USB// Delayms(250);// return 0;/**************************************************************************** * SL811H mode Hardware SOF/EOP generation ****************************************************************************/#if 0int hw_sof(){ SL11Write(CtrlReg,8); // Reset cfe_sleep(CFE_HZ / 10); // Delay 100ms original code was 10ms */ SL11Write(CtrlReg,0); // Disable USB transfer operation and SOF cfe_sleep(CFE_HZ / 10); // Delay 100ms original code was 10ms */ SL11Write(cDATASet,0xe0); // Reg: cDATASet= 0x0e : Set up SOF for 1ms interval SL11Write(cSOFcnt,0xae); // Reg: cSOFcnt =0x0f : SL11Write(CtrlReg,1); // Enable SOF/EOP SL11Write(EP0Control, 0x01); // Start SOF/EOP return 0;}#endif//--------------------------------------------------------------------------// Sending EOP packet// -- (Not used in SL811H)//--------------------------------------------------------------------------#if 0int sEOP(){ BYTE tmp; tmp = SL11Read(CtrlReg); SL11Write(CtrlReg,(BYTE)(8|tmp)); // Send SL11Write(CtrlReg,tmp); // enable USB return 0;}#endif/*-------------------------------------------------------------------------- * CRC5 *-------------------------------------------------------------------------- */unsigned short crc5(unsigned short f){ unsigned short i,seed=0x1f,t=f,flag; for(i=0;i<11;i++) { flag=(t^seed)&1; seed>>=1; t>>=1; if(flag) seed^=0x14; } seed^=0x1f;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -