Example #1
0
/***************************************************************************
 * 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;
		}
	}

	/* restore the data */
	for (i = 0x10; i < 256; i++) {
		SL811Write (hci, i, buf[i]);
	}

	return (result);
}
Example #2
0
void USBReset(void)
{
	u_int8 temp;
  temp=SL811Read(CtrlReg);   
 	SL811Write(CtrlReg,temp|0x08);
	//task_time_sleep(25);		
	SL811Write(CtrlReg,temp);    
}
Example #3
0
/************************************************************************
 * Function Name : hc_stop_int
 *  
 * This function disables SL811HS interrupts
 *
 * Input:  hci = data structure for the host controller
 *       
 * Return: none 
 ***********************************************************************/
static void hc_stop_int (hci_t * hci)
{
#ifdef HC_SWITCH_INT
	SL811Write (hci, SL11H_INTSTATREG, 0xff);
//  SL811Write(hci, SL11H_INTENBLREG, SL11H_INTMASK_INSRMV);

#endif
}
Example #4
0
/************************************************************************
 * Function Name : hc_start_int
 *  
 * This function enables SL811HS interrupts
 *
 * Input:  hci = data structure for the host controller
 *       
 * Return: none 
 ***********************************************************************/
static void hc_start_int (hci_t * hci)
{
#ifdef HC_SWITCH_INT
	int mask =
	    SL11H_INTMASK_XFERDONE | SL11H_INTMASK_SOFINTR |
	    SL11H_INTMASK_INSRMV | SL11H_INTMASK_USBRESET;
	SL811Write (hci, IntEna, mask);
#endif
}
Example #5
0
void check_key_LED(void)
{
	  u_int8 intr;
	intr=SL811Read(IntStatus);
	if(intr & USB_DETECT)
		   {
		    if(bXXGFlags.SLAVE_ONLINE ==TRUE)
		   	{bXXGFlags.SLAVE_REMOVED=TRUE;
		   	 bXXGFlags.SLAVE_ONLINE =FALSE;
		   	}
		   }
	else	{
		   if(bXXGFlags.SLAVE_ONLINE == FALSE)
		   	{bXXGFlags.SLAVE_DETECT=TRUE;
		   	 bXXGFlags.SLAVE_ONLINE =TRUE;
		   	}
		   }
	SL811Write(IntStatus,INT_CLEAR);
	SL811Write(IntStatus,INSERT_REMOVE);
}
Example #6
0
void SL811_Init(void)
{	
	bXXGFlags.SLAVE_ONLINE = FALSE;
	bXXGFlags.SLAVE_DETECT = FALSE;
	bXXGFlags.SLAVE_REMOVED=FALSE;
	
	bXXGFlags.SLAVE_ENUMERATED = FALSE;
	bXXGFlags.SLAVE_IS_ATTACHED = FALSE;
	
	SL811Write(cDATASet,0xe0);    //for 1ms interval
	SL811Write(cSOFcnt,0xae);
	SL811Write(CtrlReg,0x5);
			
	SL811Write(EP0Status,0x50);
	SL811Write(EP0Counter,0);
	SL811Write(EP0Control,0x01);
			
	
	SL811Write(IntEna,0x20);      		// USB-A, Insert/Remove, USB_Resume.
	SL811Write(IntStatus,INT_CLEAR);	// Clear Interrupt enable status
}
Example #7
0
/*****************************************************************
 *
 * Function Name: hc_interrupt
 *
 * Interrupt service routine. 
 *
 * 1) determine the causes of interrupt
 * 2) clears all interrupts
 * 3) calls appropriate function to service the interrupt
 *
 * Input:  irq = interrupt line associated with the controller 
 *         hci = data structure for the host controller
 *         r = holds the snapshot of the processor's context before 
 *             the processor entered interrupt code. (not used here) 
 *
 * Return value  : None.
 *                
 *****************************************************************/
static void hc_interrupt (int irq, void *__hci, struct pt_regs *r)
{
	char ii;
	hci_t *hci = __hci;
	int isExcessNak = 0;
	int urb_state = 0;
	char tmpIrq = 0;

	/* Get value from interrupt status register */

	ii = SL811Read (hci, SL11H_INTSTATREG);

	if (ii & SL11H_INTMASK_INSRMV) {
		/* Device insertion or removal detected for the USB port */

		SL811Write (hci, SL11H_INTENBLREG, 0);
		SL811Write (hci, SL11H_CTLREG1, 0);
		mdelay (100);	// wait for device stable 
		handleInsRmvIntr (hci);
		return;
	}

	/* Clear all interrupts */

	SL811Write (hci, SL11H_INTSTATREG, 0xff);

	if (ii & SL11H_INTMASK_XFERDONE) {
		/* USB Done interrupt occurred */

		urb_state = sh_done_list (hci, &isExcessNak);
#ifdef WARNING
		if (hci->td_array->len > 0)
			printk ("WARNING: IRQ, td_array->len = 0x%x, s/b:0\n",
				hci->td_array->len);
#endif
		if (hci->td_array->len == 0 && !isExcessNak
		    && !(ii & SL11H_INTMASK_SOFINTR) && (urb_state == 0)) {
			if (urb_state == 0) {
				/* All urb_state has not been finished yet! 
				 * continue with the current urb transaction 
				 */

				if (hci->last_packet_nak == 0) {
					if (!usb_pipecontrol
					    (hci->td_array->td[0].urb->pipe))
						sh_add_packet (hci, hci->td_array-> td[0].urb);
				}
			} else {
				/* The last transaction has completed:
				 * schedule the next transaction 
				 */

				sh_schedule_trans (hci, 0);
			}
		}
		SL811Write (hci, SL11H_INTSTATREG, 0xff);
		return;
	}

	if (ii & SL11H_INTMASK_SOFINTR) {
		hci->frame_number = (hci->frame_number + 1) % 2048;
		if (hci->td_array->len == 0)
			sh_schedule_trans (hci, 1);
		else {
			if (sofWaitCnt++ > 100) {
				/* The last transaction has not completed.
				 * Need to retire the current td, and let
				 * it transmit again later on.
				 * (THIS NEEDS TO BE WORK ON MORE, IT SHOULD NEVER 
				 *  GET TO THIS POINT)
				 */

				DBGERR ("SOF interrupt: td_array->len = 0x%x, s/b: 0\n",
					hci->td_array->len);
				urb_print (hci->td_array->td[hci->td_array->len - 1].urb,
					   "INTERRUPT", 0);
				sh_done_list (hci, &isExcessNak);
				SL811Write (hci, SL11H_INTSTATREG, 0xff);
				hci->td_array->len = 0;
				sofWaitCnt = 0;
			}
		}
		tmpIrq = SL811Read (hci, SL11H_INTSTATREG) & SL811Read (hci, SL11H_INTENBLREG);
		if (tmpIrq) {
			DBG ("IRQ occurred while service SOF: irq = 0x%x\n",
			     tmpIrq);

			/* If we receive a DONE IRQ after schedule, need to 
			 * handle DONE IRQ again 
			 */

			if (tmpIrq & SL11H_INTMASK_XFERDONE) {
				DBGERR ("IRQ occurred while service SOF: irq = 0x%x\n",
					tmpIrq);
				urb_state = sh_done_list (hci, &isExcessNak);
			}
			SL811Write (hci, SL11H_INTSTATREG, 0xff);
		}
	} else {
		DBG ("SL811 ISR: unknown, int = 0x%x \n", ii);
	}

	SL811Write (hci, SL11H_INTSTATREG, 0xff);
	return;
}
Example #8
0
/*****************************************************************
 *
 * Function Name: SL11StartXaction
 *  
 * This functions load the registers with appropriate value and 
 * transmit the packet.				  
 *
 * Input:  hci = data structure for the host controller
 *         addr = USB address of the device
 *         epaddr = endpoint number
 *         pid = packet ID
 *         len = data length
 *         toggle = USB toggle bit, either 0 or 1
 *         slow = speed of the device
 *         urb_state = the current stage of USB transaction
 *
 * Return: 0 = error; 1 = successful
 *                
 *****************************************************************/
int SL11StartXaction (hci_t * hci, __u8 addr, __u8 epaddr, int pid, int len,
		      int toggle, int slow, int urb_state)
{

	hcipriv_t *hp = &hci->hp;
	__u8 cmd = 0;
	__u8 setup_data[4];
	__u16 speed;

	speed = hp->RHportStatus->portStatus;
	if (!(speed & PORT_LOW_SPEED_DEV_ATTACH_STAT) && slow) {
		cmd |= SL11H_HCTLMASK_PREAMBLE;
	}
	switch (pid) {
	case PID_SETUP:
		cmd &= SL11H_HCTLMASK_PREAMBLE;
		cmd |=
		    (SL11H_HCTLMASK_ARM | SL11H_HCTLMASK_ENBLEP |
		     SL11H_HCTLMASK_WRITE);
		break;

	case PID_OUT:
		cmd &= (SL11H_HCTLMASK_SEQ | SL11H_HCTLMASK_PREAMBLE);
		cmd |=
		    (SL11H_HCTLMASK_ARM | SL11H_HCTLMASK_ENBLEP |
		     SL11H_HCTLMASK_WRITE);
		if (toggle) {
			cmd |= SL11H_HCTLMASK_SEQ;
		}
		break;

	case PID_IN:
		cmd &= (SL11H_HCTLMASK_SEQ | SL11H_HCTLMASK_PREAMBLE);
		cmd |= (SL11H_HCTLMASK_ARM | SL11H_HCTLMASK_ENBLEP);
		break;

	default:
		DBGERR ("ERR: SL11StartXaction: unknow pid = 0x%x\n", pid);
		return 0;
	}
	setup_data[0] = SL11H_DATA_START;
	setup_data[1] = len;
	setup_data[2] = (((pid & 0x0F) << 4) | (epaddr & 0xF));
	setup_data[3] = addr & 0x7F;

	SL811BufWrite (hci, SL11H_BUFADDRREG, (__u8 *) & setup_data[0], 4);

	SL811Write (hci, SL11H_HOSTCTLREG, cmd);

#if 0
	/* The SL811 has a hardware flaw when hub devices sends out
	 * SE0 between packets. It has been found in a TI chipset and
	 * cypress hub chipset. It causes the SL811 to hang
	 * The workaround is to re-issue the preample again.
	 */

	if ((cmd & SL11H_HCTLMASK_PREAMBLE)) {
		SL811Write (hci, SL11H_PIDEPREG_B, 0xc0);
		SL811Write (hci, SL11H_HOSTCTLREG_B, 0x1);	// send the premable
	}
#endif
	return 1;
}
Example #9
0
/************************************************************************
 * 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;
}
Example #10
0
//*****************************************************************************************
// usbXfer:
// successful transfer = return TRUE
// fail transfer = return FALSE
//*****************************************************************************************
  u_int8 usbXfer(void)
{  
	
	  u_int8	xferLen, data0, data1,cmd;
	  u_int8 intr,result,remainder,dataX,bufLen,addr,timeout;
	
	//------------------------------------------------
	// Default setting for usb trasnfer
	//------------------------------------------------
	dataX=timeout=0;
	//result 	  = SL811Read(EP0Status);	
	data0 = EP0_Buf;					// DATA0 buffer address
	data1 = data0 + (  u_int8)usbstack.wPayload;	// DATA1 buffer address
	bXXGFlags.DATA_STOP=FALSE;
	bXXGFlags.TIMEOUT_ERR=FALSE;
	//------------------------------------------------
	// Define data transfer payload
	//------------------------------------------------
	if (usbstack.wLen >= usbstack.wPayload)  		// select proper data payload
		xferLen = usbstack.wPayload;			// limit to wPayload size 
	else							// else take < payload len
		xferLen = usbstack.wLen;			//	
	
	// For IN token
	if (usbstack.pid==PID_IN)				// for current IN tokens
	{												//
		cmd = sDATA0_RD;			// FS/FS on Hub, sync to sof
	}
	// For OUT token
	else if(usbstack.pid==PID_OUT)				// for OUT tokens
	{  	
		if(xferLen)									// only when there are	
			{
			//intr=usbstack.setup.wLength;
			//usbstack.setup.wLength=WordSwap(usbstack.setup.wLength);
			SL811BufWrite(data0,usbstack.buffer,xferLen); 	// data to transfer on USB
			//usbstack.setup.wLength=intr;
			}
		cmd = sDATA0_WR;						// FS/FS on Hub, sync to sof
	// implement data toggle
		bXXGFlags.bData1 = uDev.bData1[usbstack.endpoint];
        	uDev.bData1[usbstack.endpoint] = (uDev.bData1[usbstack.endpoint] ? 0 : 1); // DataToggle
		
		if(bXXGFlags.bData1)
          		cmd |= 0x40;                              // Set Data1 bit in command
	}
	// For SETUP/OUT token
	else											// for current SETUP/OUT tokens
	{  	
		if(xferLen)									// only when there are	
			{
			intr=usbstack.setup.wLength;
			usbstack.setup.wValue=usbstack.setup.wValue;
			usbstack.setup.wIndex=usbstack.setup.wIndex;
			usbstack.setup.wLength=usbstack.setup.wLength;
			SL811BufWrite(data0,(  u_int8 *)&usbstack.setup,xferLen); 	// data to transfer on USB
			usbstack.setup.wLength=intr;
			}
		cmd = sDATA0_WR;						// FS/FS on Hub, sync to sof
	}
	//------------------------------------------------
	// For EP0's IN/OUT token data, start with DATA1
	// Control Endpoint0's status stage.
	// For data endpoint, IN/OUT data, start ????
	//------------------------------------------------
	if (usbstack.endpoint == 0 && usbstack.pid != PID_SETUP) 	// for Ep0's IN/OUT token
		cmd |= 0x40; 					// always set DATA1
	//------------------------------------------------
	// Arming of USB data transfer for the first pkt
	//------------------------------------------------
	SL811Write(EP0Status,((usbstack.endpoint&0x0F)|usbstack.pid));	// PID + EP address
	SL811Write(EP0Counter,usbstack.usbaddr);					// USB address
	SL811Write(EP0Address,data0);					// buffer address, start with "data0"
	SL811Write(EP0XferLen,xferLen);					// data transfer length
	SL811Write(IntStatus,INT_CLEAR); 				// clear interrupt status
	SL811Write(EP0Control,cmd);						// Enable ARM and USB transfer start here
	
	//------------------------------------------------
	// Main loop for completing a wLen data trasnfer
	//------------------------------------------------
	while(TRUE)
	{   
		//---------------Wait for done interrupt------------------
		while(TRUE)												// always ensure requested device is
		{														// inserted at all time, then you will
			//intr=SL811Read(cSOFcnt);
			//intr=SL811Read(IntEna);
			intr = SL811Read(IntStatus);	
								// wait for interrupt to be done, and 
			if((intr & USB_DETECT) || (intr & INSERT_REMOVE))	// proceed to parse result from slave 
			{													// device.
				bXXGFlags.DATA_STOP = TRUE;								// if device is removed, set DATA_STOP
				return FALSE;									// flag true, so that main loop will 
			}													// know this condition and exit gracefully
			if(intr & USB_A_DONE)								
				break;											// interrupt done !!!
		}

		SL811Write(IntStatus,INT_CLEAR); 						// clear interrupt status
		result 	  = SL811Read(EP0Status);						// read EP0status register
		remainder = SL811Read(EP0Counter);						// remainder value in last pkt xfer

		//-------------------------ACK----------------------------
		if (result & EP0_ACK)									// Transmission ACK
		{	

			// SETUP TOKEN
			if(usbstack.pid == PID_SETUP)								// do nothing for SETUP/OUT token 
				break;											// exit while(1) immediately

			// OUT TOKEN				
			else if(usbstack.pid == PID_OUT)
				break;

			// IN TOKEN
			else if(usbstack.pid == PID_IN)
			{													// for IN token only
				usbstack.wLen  -= (WORD)xferLen;	// update remainding wLen value
				cmd   ^= 0x40;    			// toggle DATA0/DATA1
				dataX++;				// point to next dataX

				//------------------------------------------------	
				// If host requested for more data than the slave 
				// have, and if the slave's data len is a multiple
				// of its endpoint payload size/last xferLen. Do 
				// not overwrite data in previous buffer.
				//------------------------------------------------	
				if(remainder==xferLen)			// empty data detected
					bufLen = 0;			// do not overwriten previous data
				else					// reset bufLen to zero
					bufLen = xferLen;		// update previous buffer length
				
				//------------------------------------------------	
				// Arm for next data transfer when requested data 
				// length have not reach zero, i.e. wLen!=0, and
				// last xferlen of data was completed, i.e.
				// remainder is equal to zero, not a short pkt
				//------------------------------------------------	
				if(!remainder && usbstack.wLen)							// remainder==0 when last xferLen
				{												// was all completed or wLen!=0
					addr    = (dataX & 1) ? data1:data0; 		// select next address for data
					xferLen = (u_int8)(usbstack.wLen>=usbstack.wPayload) ? usbstack.wPayload:usbstack.wLen;	// get data length required
					//if (FULL_SPEED)								// sync with SOF transfer
					cmd |= 0x20;							// always sync SOF when FS, regardless 
					SL811Write(EP0XferLen, xferLen); 			// select next xfer length
					SL811Write(EP0Address, addr);           	// data buffer addr 
					SL811Write(IntStatus,INT_CLEAR);			// is a LS is on Hub.
					SL811Write(EP0Control,cmd);					// Enable USB transfer and re-arm
				}				

				//------------------------------------------------
				// Copy last IN token data pkt from prev transfer
				// Check if there was data available during the
				// last data transfer
				//------------------------------------------------
				if(bufLen)										
				{	
					SL811BufRead(((dataX&1)?data0:data1), usbstack.buffer, bufLen);
					usbstack.buffer += bufLen;								
				}

				//------------------------------------------------
				// Terminate on short packets, i.e. remainder!=0
				// a short packet or empty data packet OR when 
				// requested data len have completed, i.e.wLen=0
				// For a LOWSPEED device, the 1st device descp,
				// wPayload is default to 64-u_int8, LS device will
				// only send back a max of 8-u_int8 device descp,
				// and host detect this as a short packet, and 
				// terminate with OUT status stage
				//------------------------------------------------
				if(remainder || !usbstack.wLen)
					break;
			}// PID IN							
		}
			
		//-------------------------NAK----------------------------
		if (result & EP0_NAK)									// NAK Detected
		{														
			if(usbstack.endpoint==0)										// on ep0 during enumeration of LS device
			{													// happen when slave is not fast enough,
				SL811Write(IntStatus,INT_CLEAR);				// clear interrupt status, need to
				SL811Write(EP0Control,cmd);						// re-arm and request for last cmd, IN token
                		result = 0;                                     // respond to NAK status only
			}
			else												// normal data endpoint, exit now !!! , non-zero ep
				break;											// main loop control the interval polling
		}
	
		//-----------------------TIMEOUT--------------------------
		if (result & EP0_TIMEOUT)								// TIMEOUT Detected
		{														
			if(usbstack.endpoint==0)										// happens when hub enumeration
			{
				if(++timeout >= TIMEOUT_RETRY)
				{	
				    timeout--;
					break;										// exit on the timeout detected	
				}
				SL811Write(IntStatus,INT_CLEAR);				// clear interrupt status, need to
				SL811Write(EP0Control,cmd);						// re-arm and request for last cmd again
			}
			else												
			{													// all other data endpoint, data transfer 
				bXXGFlags.TIMEOUT_ERR = TRUE;								// failed, set flag to terminate transfer
				break;											// happens when data transfer on a device
			}													// through the hub
		}

		//-----------------------STALL----------------------------
		if (result & EP0_STALL)  								// STALL detected
			return TRUE;										// for unsupported request.
																		
		//----------------------OVEFLOW---------------------------
		if (result & EP0_OVERFLOW)  							// OVERFLOW detected
			//result=result;
			break;
		//-----------------------ERROR----------------------------
		if (result & EP0_ERROR)  								// ERROR detected
			//result=result;
			break;
	}	// end of While(1)
   
	if (result & EP0_ACK) 	// on ACK transmission
		return TRUE;		// return OK

	return FALSE;			// fail transmission

}