📄 hc_sl811.c
字号:
/*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------* * SL811HS USB HCD for Linux Version 0.1 (10/28/2001) 0.3 (11/23/2003) * * requires (includes) hc_simple.[hc] simple generic HCD frontend * * COPYRIGHT(C) 2001 by CYPRESS SEMICONDUCTOR INC. * * ! This driver have end of live! Please use hcd/sl811.c instand ! * * 05.06.2003 HNE * Support x86 architecture now. * Set "bus->bus_name" at init. * hc_reset,regTest: Don't load driver, if pattern-Test failed (better error returns) * * 06.06.2003 HNE * Moved regTest from hc_reset to hc_found_hci. So we check registers * only at start, and not at unload. Only all Register show, if full Debug. * * 22.09.2003 HNE * Do not write SL11H_INTSTATREG in loop, use delay instand. * If device disconnected, wait only for next insert interrupt (no Idle-Interrpts). * * 29.09.2003 HNE * Moving hc_sl811-arm.h and hc_sl811-x86.h to include/asm-.../hc_sl811-hw.h * * 03.10.2003 HNE * Low level only for port io into hardware-include. * GPRD as parameter (ARM only). * ToDo: * Separate IO-Base for second controller (see sl811.c) * Only as module tested! Compiled in Version not tested! * *-------------------------------------------------------------------------* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *-------------------------------------------------------------------------*/#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/delay.h>#include <linux/sched.h>#include <linux/slab.h>#include <linux/errno.h>#include <linux/init.h>#include <linux/smp_lock.h>#include <linux/list.h>#include <linux/ioport.h>#include <asm/io.h>#include <asm/irq.h>#include <linux/usb.h>#define MODNAME "HC_SL811"#undef HC_URB_TIMEOUT#undef HC_SWITCH_INT#undef HC_ENABLE_ISOC// #define SL811_DEBUG#define SL811_DEBUG_ERR// #define SL811_DEBUG_IRQ// #define SL811_DEBUG_VERBOSE#ifdef SL811_DEBUG_ERR#define DBGERR(fmt, args...) printk(fmt,## args)#else#define DBGERR(fmt, args...)#endif#ifdef SL811_DEBUG#define DBG(fmt, args...) printk(fmt,## args)#else#define DBG(fmt, args...)#endif#ifdef SL811_DEBUG_FUNC#define DBGFUNC(fmt, args...) printk(fmt,## args)#else#define DBGFUNC(fmt, args...)#endif#ifdef SL811_DEBUG_DATA#define DBGDATAR(fmt, args...) printk(fmt,## args)#define DBGDATAW(fmt, args...) printk(fmt,## args)#else#define DBGDATAR(fmt, args...)#define DBGDATAW(fmt, args...)#endif#ifdef SL811_DEBUG_VERBOSE#define DBGVERBOSE(fmt, args...) printk(fmt,## args)#else#define DBGVERBOSE(fmt, args...)#endif#define TRUE 1#define FALSE 0#define HC_SWITCH_INT#include "hc_sl811.h"#include "hc_simple.h"static int urb_debug = 0;#include "hc_simple.c"#include "hc_sl811_rh.c"/* Include hardware and board depens */#include "hc_sl811-hw.h"/* forware declaration */int SL11StartXaction (hci_t * hci, __u8 addr, __u8 epaddr, int pid, int len, int toggle, int slow, int urb_state);static int sofWaitCnt = 0;MODULE_PARM (urb_debug, "i");MODULE_PARM_DESC (urb_debug, "debug urb messages, default is 0 (no)");static int hc_reset (hci_t * hci);/*************************************************************************** * Function Name : SL811Read * * Read a byte of data from the SL811H/SL11H * * Input: hci = data structure for the host controller * offset = address of SL811/SL11H register or memory * * Return: data **************************************************************************/static __u8 inline SL811Read (hci_t *hci, __u8 offset){ hcipriv_t *hp = &hci->hp;#ifdef SL811_DEBUG_ERR if (!hp->hcport) DBGERR ("SL811Read: Error port not set!\n");#endif sl811_write_index (hp, offset); return (sl811_read_data (hp));}/*************************************************************************** * Function Name : SL811Write * * Write a byte of data to the SL811H/SL11H * * Input: hci = data structure for the host controller * offset = address of SL811/SL11H register or memory * data = the data going to write to SL811H * * Return: none **************************************************************************/static void inline SL811Write (hci_t *hci, __u8 offset, __u8 data){ hcipriv_t *hp = &hci->hp;#ifdef SL811_DEBUG_ERR if (!hp->hcport) DBGERR ("SL811Write: Error port not set!\n");#endif sl811_write_index_data (hp, offset, data);}/*************************************************************************** * Function Name : SL811BufRead * * Read consecutive bytes of data from the SL811H/SL11H buffer * * Input: hci = data structure for the host controller * offset = SL811/SL11H register offset * buf = the buffer where the data will store * size = number of bytes to read * * Return: none **************************************************************************/static void SL811BufRead (hci_t *hci, __u8 offset, __u8 *buf, __u8 size){ hcipriv_t *hp = &hci->hp; if( size <= 0) return;#ifdef SL811_DEBUG_ERR if (!hp->hcport) DBGERR ("SL811BufRead: Error port not set!\n");#endif sl811_write_index (hp, offset); DBGDATAR ("SL811BufRead: io=%X offset = %02x, data = ", hp->hcport, offset); while (size--) { *buf++ = sl811_read_data(hp); DBGDATAR ("%02x ", *(buf-1)); } DBGDATAR ("\n");}/*************************************************************************** * Function Name : SL811BufWrite * * Write consecutive bytes of data to the SL811H/SL11H buffer * * Input: hci = data structure for the host controller * offset = SL811/SL11H register offset * buf = the data buffer * size = number of bytes to write * * Return: none **************************************************************************/static void SL811BufWrite(hci_t *hci, __u8 offset, __u8 *buf, __u8 size){ hcipriv_t *hp = &hci->hp; if(size<=0) return;#ifdef SL811_DEBUG_ERR if (!hp->hcport) DBGERR ("SL811BufWrite: Error port not set!\n");#endif sl811_write_index (hp, offset); DBGDATAW ("SL811BufWrite: io=%X offset = %02x, data = ", hp->hcport, offset); while (size--) { DBGDATAW ("%02x ", *buf); sl811_write_data (hp, *buf); buf++; } DBGDATAW ("\n");}/*************************************************************************** * Function Name : regTest * * This routine test the Read/Write functionality of SL811HS registers * * 1) Store original register value into a buffer * 2) Write to registers with a RAMP pattern. (10, 11, 12, ..., 255) * 3) Read from register * 4) Compare the written value with the read value and make sure they are * equivalent * 5) Restore the original register value * * Input: hci = data structure for the host controller * * * Return: TRUE = passed; FALSE = failed **************************************************************************/int regTest (hci_t * hci){ int i, result = TRUE; __u8 buf[256], data; DBGFUNC ("Enter regTest\n"); for (i = 0x10; i < 256; i++) { /* save the original buffer */ buf[i] = SL811Read (hci, i); /* Write the new data to the buffer */ SL811Write (hci, i, i); } /* compare the written data */ for (i = 0x10; i < 256; i++) { data = SL811Read (hci, i); if (data != i) { DBGERR ("Pattern test failed!! value = 0x%x, s/b 0x%x\n", data, i); result = FALSE; /* If no Debug, show only first failed Address */ if (!urb_debug) break; } } /* restore the data */ for (i = 0x10; i < 256; i++) { SL811Write (hci, i, buf[i]); } return (result);}#if 0 /* unused (hne) *//*************************************************************************** * Function Name : regShow * * Display all SL811HS register values * * Input: hci = data structure for the host controller * * Return: none **************************************************************************/static void regShow (hci_t * hci){ int i; for (i = 0; i < 256; i++) { printk ("offset %d: 0x%x\n", i, SL811Read (hci, i)); }}#endif // if0/************************************************************************ * Function Name : USBReset * * This function resets SL811HS controller and detects the speed of * the connecting device * * Input: hci = data structure for the host controller * * Return: 0 = no device attached; 1 = USB device attached * ***********************************************************************//* [2.4.22] sl811_hc_reset */static int USBReset (hci_t * hci){ int status; hcipriv_t *hp = &hci->hp; DBGFUNC ("enter USBReset\n"); SL811Write (hci, SL11H_CTLREG2, 0xae); // setup master and full speed SL811Write (hci, SL11H_CTLREG1, 0x08); // reset USB mdelay (20); // 20ms SL811Write (hci, SL11H_CTLREG1, 0); // remove SE0 /* disable all interrupts (18.09.2003) */ SL811Write (hci, SL11H_INTENBLREG, 0); /* 19.09.2003 [2.4.22] */ mdelay(2); SL811Write (hci, SL11H_INTSTATREG, 0xff); // clear all interrupt bits status = SL811Read (hci, SL11H_INTSTATREG); if (status & SL11H_INTMASK_USBRESET) // Check if device is removed (0x40) { DBG ("USBReset: Device removed %03X\n", hci->hp.hcport); /* 19.09.2003 [2.4.22] only IRQ for insert... SL811Write (hci, SL11H_INTENBLREG, SL11H_INTMASK_XFERDONE | SL11H_INTMASK_SOFINTR | SL11H_INTMASK_INSRMV); */ SL811Write (hci, SL11H_INTENBLREG, SL11H_INTMASK_INSRMV); hp->RHportStatus->portStatus &= ~(PORT_CONNECT_STAT | PORT_ENABLE_STAT); return 0; } // Send SOF to address 0, endpoint 0. SL811Write (hci, SL11H_BUFLNTHREG_B, 0); //zero lenth SL811Write (hci, SL11H_PIDEPREG_B, 0x50); //send SOF to EP0 SL811Write (hci, SL11H_DEVADDRREG_B, 0x01); //address0 SL811Write (hci, SL11H_SOFLOWREG, 0xe0); if (!(status & SL11H_INTMASK_DSTATE)) { /* 0x80 */ /* slow speed device connect directly to root-hub */ DBG ("USBReset: low speed Device attached %03X\n", hci->hp.hcport); SL811Write (hci, SL11H_CTLREG1, 0x8); mdelay (20); // SL811Write (hci, SL11H_SOFTMRREG, 0xee); /* the same, but better reading (hne) */ SL811Write (hci, SL11H_CTLREG2, 0xee); SL811Write (hci, SL11H_CTLREG1, 0x21); hp->RHportStatus->portStatus |= (PORT_CONNECT_STAT | PORT_LOW_SPEED_DEV_ATTACH_STAT); } else { /* full speed device connect directly to root hub */ DBG ("USBReset: full speed Device attached %03X \n", hci->hp.hcport); SL811Write (hci, SL11H_CTLREG1, 0x8); mdelay (20); // SL811Write (hci, SL11H_SOFTMRREG, 0xae); /* the same, but better reading (hne) */ SL811Write (hci, SL11H_CTLREG2, 0xae); SL811Write (hci, SL11H_CTLREG1, 0x01); hp->RHportStatus->portStatus |= (PORT_CONNECT_STAT); hp->RHportStatus->portStatus &= ~PORT_LOW_SPEED_DEV_ATTACH_STAT; } /* start the SOF or EOP */ SL811Write (hci, SL11H_HOSTCTLREG_B, 0x01); /* clear all interrupt bits */ /* 19.09.2003 [2.4.22] */ mdelay(2); SL811Write (hci, SL11H_INTSTATREG, 0xff); /* enable all interrupts */ SL811Write (hci, SL11H_INTENBLREG, SL11H_INTMASK_XFERDONE | SL11H_INTMASK_SOFINTR | SL11H_INTMASK_INSRMV); return 1;}/*-------------------------------------------------------------------------*//* tl functions */static inline void hc_mark_last_trans (hci_t * hci){ hcipriv_t *hp = &hci->hp; __u8 *ptd = hp->tl; dbg ("enter hc_mark_last_trans\n"); if (ptd == NULL) { printk ("hc_mark_last_trans: ptd = null\n"); return; } if (hp->xferPktLen > 0) *(ptd + hp->tl_last) |= (1 << 3);}static inline void hc_flush_data_cache (hci_t * hci, void *data, int len){}/************************************************************************ * Function Name : hc_add_trans * * This function sets up the SL811HS register and transmit the USB packets. * * 1) Determine if enough time within the current frame to send the packet * 2) Load the data into the SL811HS register * 3) Set the appropriate command to the register and trigger the transmit * * Input: hci = data structure for the host controller * len = data length * data = transmitting data * toggle = USB toggle bit, either 0 or 1 * maxps = maximum packet size for this endpoint * slow = speed of the device * endpoint = endpoint number * address = USB address of the device * pid = packet ID * format = * urb_state = the current stage of USB transaction * * Return: 0 = no time left to schedule the transfer * 1 = success * ***********************************************************************/static inline int hc_add_trans (hci_t * hci, int len, void *data, int toggle, int maxps, int slow, int endpoint, int address, int pid, int format, int urb_state){ hcipriv_t *hp = &hci->hp; __u16 speed; int ii, jj, kk; DBGFUNC ("enter hc_add_trans: len=0x%x, toggle:0x%x, endpoing:0x%x," " addr:0x%x, pid:0x%x,format:0x%x\n", len, toggle, endpoint, address, pid, format); if (len > maxps) { len = maxps; } speed = hp->RHportStatus->portStatus; if (speed & PORT_LOW_SPEED_DEV_ATTACH_STAT) {// ii = (8*7*8 + 6*3) * len + 800; ii = 8 * 8 * len + 1024; } else { if (slow) {// ii = (8*7*8 + 6*3) * len + 800; ii = 8 * 8 * len + 2048; } else// ii = (8*7 + 6*3)*len + 110; ii = 8 * len + 256; } ii += 2 * 10 * len; jj = SL811Read (hci, SL11H_SOFTMRREG); /* Read back SOF counter HIGH (bit0-bit5 only) 26.11.2002 (hne) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -