📄 hc_sl811.c
字号:
/*-------------------------------------------------------------------------*//*-------------------------------------------------------------------------* * SL811HS USB HCD for Linux Version 0.1 (10/28/2001) * * requires (includes) hc_simple.[hc] simple generic HCD frontend x * * COPYRIGHT(C) 2001 by CYPRESS SEMICONDUCTOR INC. * *-------------------------------------------------------------------------* * 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>#undef HC_URB_TIMEOUT#undef HC_SWITCH_INT#define HC_ENABLE_ISOC#define SL811_DEBUG_ERR// #define SL811_DEBUG /* (hne) */// #define SL811_DEBUG_VERBOSE /* (hne) */// #define SL811_DEBUG_FUNC /* (hne) */// #define SL811_DEBUG_DATA /* (hne) */#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"/* hardware and board dependend */#ifdef CONFIG_ARCH_RAMSES#define SIZEOF_IO_REGION 8 /* Size for request/release region */static void *ramses_sl811hs; /* dynamically assign virtual address */#define WRITE_INDEX(i) outb ((i), (unsigned long)ramses_sl811hs)#define WRITE_DATA(d) outb ((d), (unsigned long)ramses_sl811hs+4)#define READ_DATA() ((__u8) inb ((unsigned long)ramses_sl811hs+4))/*************************************************************************** * Function Name : SL811Read [arm] * * 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 SL811Read (hci_t * hci, __u8 offset){ WRITE_INDEX (offset); return (READ_DATA ());}/*************************************************************************** * Function Name : SL811Write [arm] * * 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 SL811Write (hci_t * hci, __u8 offset, __u8 data){ WRITE_INDEX (offset); WRITE_DATA (data);}/*************************************************************************** * Function Name : SL811BufRead [arm] * * 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){ WRITE_INDEX (offset); DBGDATAR ("SL811BufRead: offset = %02x, data = ", offset); while (size--) { *buf++ = READ_DATA(); DBGDATAR ("%02x ", *(buf-1)); } DBGDATAR ("\n");}/*************************************************************************** * Function Name : SL811BufWrite [arm] * * 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){ if(size<=0) return; WRITE_INDEX (offset); DBGDATAW ("SL811BufWrite: offset = %02x, data = ", offset); while (size--) { DBGDATAW ("%02x ", *buf); WRITE_DATA (*buf); buf++; } DBGDATAW ("\n");}/***************************************************************** * * Function Name: init_irq [arm] * * This function is board specific. It sets up the interrupt to * be an edge trigger and trigger on the rising edge * * Input: none * * Return value : none * *****************************************************************/static void inline init_irq (void){ int irq_gpio_pin = IRQ_TO_GPIO_2_80(SL811HS_IRQ); GPDR(irq_gpio_pin) &= ~GPIO_bit(irq_gpio_pin); set_GPIO_IRQ_edge(irq_gpio_pin, SL811HS_IRQ_EDGE);}/***************************************************************** * * Function Name: release_regions [arm] * * This function is board specific. It frees all io address. * * Input: hcipriv_t * * * Return value : none * *****************************************************************/static void inline release_regions (hcipriv_t *hp){ if (ramses_sl811hs) { iounmap(ramses_sl811hs); release_mem_region(SL811HS_PHYS, SIZEOF_IO_REGION); } hp->hcport = 0; hp->hcport2 = 0;}/***************************************************************** * * Function Name: request_regions [arm] * * This function is board specific. It request all io address and * maps into memory (if can). * * Input: hcipriv_t * * * Return value : 0 = OK * *****************************************************************/static int inline request_regions (hcipriv_t *hp){ if (!request_mem_region(SL811HS_PHYS, SIZEOF_IO_REGION, "SL111 USB HOST")) { printk(KERN_ERR "unable to reserve region\n"); return -EBUSY; } else { ramses_sl811hs = ioremap_nocache(SL811HS_PHYS, SIZEOF_IO_REGION); if (!ramses_sl811hs) { printk(KERN_ERR "unable to map region\n"); release_mem_region(SL811HS_PHYS, SIZEOF_IO_REGION); return -EBUSY; } } hp->hcport = (unsigned long) ramses_sl811hs; hp->hcport2 = (unsigned long) ramses_sl811hs+4; return 0;}#endif/* forware declaration */int SL11StartXaction (hci_t * hci, __u8 addr, __u8 epaddr, int pid, int len, int toggle, int slow, int iso, 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 : 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 data; DBGFUNC ("Enter regTest\n"); for (i = 0x10; i < 256; 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; } } /* initialize the data */ for (i = 0x10; i < 256; i++) { SL811Write (hci, i, 0); } return (result);}/************************************************************************ * 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 * ***********************************************************************/static int USBReset (hci_t * hci){ int status; hcipriv_t *hp = &hci->hp; DBGFUNC ("enter USBReset\n"); SL811Write (hci, SL11H_CTLREG2, 0xae); // master, full speed for (status = 0; status < 100; status++) SL811Write (hci, SL11H_INTSTATREG, 0xff); // clear all interrupt bits status = SL811Read (hci, SL11H_INTSTATREG); if (status & 0x80) { // full speed SL811Write (hci, SL11H_CTLREG2, 0xae); // master, full speed } else { // low speed SL811Write (hci, SL11H_CTLREG2, 0xee); // master, low speed } if (status & 0x40) // Check if device is removed { DBG ("USBReset: Device removed\n"); SL811Write (hci, SL11H_INTENBLREG, SL11H_INTMASK_XFERDONE | SL11H_INTMASK_SOFINTR | SL11H_INTMASK_INSRMV); hp->RHportStatus->portStatus &= ~(PORT_CONNECT_STAT | PORT_ENABLE_STAT); return 0; } if (!(status & 0x80)) { /* slow speed device connect directly to root-hub */ DBG ("USBReset: low speed Device attached\n"); SL811Write (hci, SL11H_CTLREG1, 0x8); mdelay (18); // SL811Write (hci, SL11H_SOFTMRREG, 0xee); /* the same, but better reading (hne) */ SL811Write (hci, SL11H_CTLREG2, 0xee); SL811Write (hci, SL11H_CTLREG1, 0x21); /* start the SOF or EOP */ SL811Write (hci, SL11H_HOSTCTLREG_B, 0x01); hp->RHportStatus->portStatus |= (PORT_CONNECT_STAT | PORT_LOW_SPEED_DEV_ATTACH_STAT); /* clear all interrupt bits */ for (status = 0; status < 20; status++) SL811Write (hci, SL11H_INTSTATREG, 0xff); } else { /* full speed device connect directly to root hub */ DBG ("USBReset: full speed device attached\n"); SL811Write (hci, SL11H_CTLREG1, 0x8); mdelay (12); SL811Write (hci, SL11H_CTLREG1, 0x10); // SE0 -> J to avoid floating SL811Write (hci, SL11H_CTLREG1, 0x00); // reset end SL811Write (hci, SL11H_CTLREG2, 0xae); SL811Write (hci, SL11H_CTLREG1, 0x01); // start SOF /* start the SOF or EOP */ SL811Write (hci, SL11H_HOSTCTLREG_B, 0x01); hp->RHportStatus->portStatus |= (PORT_CONNECT_STAT); hp->RHportStatus->portStatus &= ~PORT_LOW_SPEED_DEV_ATTACH_STAT; /* clear all interrupt bits */ 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 * iso = is transaction iso * 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 iso, int urb_state){ hcipriv_t *hp = &hci->hp; __u16 speed; int ii, jj, kk; int omaxps = maxps; DBGFUNC ("enter hc_add_trans: len=0x%x, toggle:0x%x, endpoing:0x%x," " addr:0x%x, pid:0x%x,iso:0x%x\n", len, toggle, endpoint, address, pid, iso); if (len > maxps) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -