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

📄 uclinuxsl811hstdrivers.txt

📁 linux下的sl811hs驱动
💻 TXT
字号:
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/sched.h>
#include <linux/malloc.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>
#include "hcd.h"

#undef HC_URB_TIMEOUT
#undef HC_SWITCH_INT
#undef HC_ENABLE_ISOC

#define SL811_DEBUG_ERR

#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"

/* 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;

#ifndef CONFIG_USB_SL811HC_AUTO
/* The base_addr, data_reg_addr, and irq number are board specific.
 * The current values are design to run on the Accelent SA1110 IDP
 * NOTE: values need to modify for different development boards 
 */

static int base_addr = 0x1200000;
static int data_reg_addr = 0x1200400;
static int irq = 0;

MODULE_PARM (urb_debug, "i");
MODULE_PARM_DESC (urb_debug, "debug urb messages, default is 0 (no)");

MODULE_PARM (base_addr, "i");
MODULE_PARM_DESC (base_addr, "sl811 base address 0xd3800000");
MODULE_PARM (data_reg_addr, "i");
MODULE_PARM_DESC (data_reg_addr, "sl811 data register address 0xd3810000");
MODULE_PARM (irq, "i");
MODULE_PARM_DESC (irq, "IRQ 34 (default)");

#else
/*
 * Brave soul,
 * ask for heaven's protection!
 */
/* 
 * Our board has this controller attached to CS2 with address 0xc0000000
 */


#define SL811HC_IOPORT0 0x1200000
#define SL811HC_IODATAPORT0 0x1200400
#define SL811HC_IOPORT1 0x1200000
#define SL811HC_IODATAPORT1 0x1200400
#define SL811HC_IOPORT2 0x1200000
#define SL811HC_IODATAPORT2 0x1200400
#define SL811HC_IOPORT3 0x1200000
#define SL811HC_IODATAPORT3 0x1200400

#define SL811HC_IRQ0 0
#define SL811HC_IRQ1 0
#define SL811HC_IRQ2 0
#define SL811HC_IRQ3 0

int sl811hc_portlist[] = { SL811HC_IOPORT0, SL811HC_IOPORT1, SL811HC_IOPORT2, SL811HC_IOPORT3, 0 };
int sl811hc_datalist[] = { SL811HC_IODATAPORT0, SL811HC_IODATAPORT1, SL811HC_IODATAPORT2, SL811HC_IODATAPORT3, 0 };
int sl811hc_irqlist[] = { SL811HC_IRQ0, SL811HC_IRQ1, SL811HC_IRQ2, SL811HC_IRQ3, 0 };

MODULE_PARM(sl811hc_portlist,"i");
MODULE_PARM_DESC(base_addr,"sl811hc base address (0xc0000000 default)");
MODULE_PARM(data_reg_addr,"i");
MODULE_PARM_DESC(data_reg_addr,"sl811hc data register address (0xc0010000 default)");
MODULE_PARM(irq,"i");
MODULE_PARM_DESC(irq,"IRQ 27 (default)");

#endif /* CONFIG_USB_SL811HC_AUTO */

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 
 **************************************************************************/
char SL811Read (hci_t * hci, char offset)
{
hcipriv_t *hp = &hci->hp;
char data;
writeb (offset, hp->hcport);
wmb ();
data = readb (hp->hcport2);
rmb ();
return (data);
}

/***************************************************************************
 * 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 
 **************************************************************************/
void SL811Write (hci_t * hci, char offset, char data)
{
hcipriv_t *hp = &hci->hp;
writeb (offset, hp->hcport);
writeb (data, hp->hcport2);
wmb ();
}

/***************************************************************************
 * 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 
 **************************************************************************/
void SL811BufRead (hci_t * hci, short offset, char *buf, short size)
{
hcipriv_t *hp = &hci->hp;
if (size <= 0)
return;
writeb ((char) offset, hp->hcport);
wmb ();
DBGDATAR ("SL811BufRead: offset = 0x%x, data = ", offset);
while (size--) {
*buf++ = (char) readb (hp->hcport2);
DBGDATAR ("0x%x ", *(buf - 1));
rmb ();
}
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 
 **************************************************************************/
void SL811BufWrite (hci_t * hci, short offset, char *buf, short size)
{
hcipriv_t *hp = &hci->hp;
if (size <= 0)
return;
writeb ((char) offset, hp->hcport);
wmb ();
DBGDATAW ("SL811BufWrite: offset = 0x%x, data = ", offset);
while (size--) {
DBGDATAW ("0x%x ", *buf);
writeb (*buf, hp->hcport2);
wmb ();
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, data, result = TRUE;
char buf[256];

DBGFUNC ("Enter regTest\n");
for (i = 0x10; i < 256; i++) {
/* save the original buffer */
buf[i] = (char) 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(result!=FALSE)
DBGERR ("GOOD LUCK,Pattern test PASSED!! ");
/* restore the data */
for (i = 0x10; i < 256; i++) {
SL811Write (hci, i, buf[i]);
}

return (result);
}

/***************************************************************************
 * Function Name : regShow
 *
 * Display all SL811HS register values
 *
 * Input:  hci = data structure for the host controller
 *
 * Return: none 
 **************************************************************************/
void regShow (hci_t * hci)
{
int i;
for (i = 0; i < 256; i++) {
printk ("offset %d: 0x%x\n", i, SL811Read (hci, i));
}
}

/************************************************************************
 * 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);

// setup master and full speed

SL811Write (hci, SL11H_CTLREG1, 0x08); // reset USB
mdelay (20); // 20ms                             
SL811Write (hci, SL11H_CTLREG1, 0); // remove SE0        

for (status = 0; status < 100; status++)
SL811Write (hci, SL11H_INTSTATREG, 0xff); // clear all interrupt bits

status = SL811Read (hci, SL11H_INTSTATREG);

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;
}

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 & 0x80)) {
/* slow speed device connect directly to root-hub */

DBG ("USBReset: low speed Device attached\n");
SL811Write (hci, SL11H_CTLREG1, 0x8);
mdelay (20);
SL811Write (hci, SL11H_SOFTMRREG, 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 (20);
SL811Write (hci, SL11H_SOFTMRREG, 0xae);
SL811Write (hci, SL11H_CTLREG1, 0x01);

/* 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;
}

⌨️ 快捷键说明

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