예제 #1
0
int Egis_BulkXfer(
		usb_ss801u *dev,
		trans_dir 	dir,
		void* 		Data,
		int			DataSize,
		int*		pActualSize,
		int			Timeout
)
{
	int retval = -1;
	int iActualRWSize;
	bool bRestore=false;

//Wayne for test
//  dev->bPrintDbgMsg = true;

//  pr_debug("%s:%d bulk In endpoint = %d Out endpoint = %d\n",  __FUNCTION__, __LINE__, dev->bulk_in_endpointAddr, dev->bulk_out_endpointAddr);
	if (!dev->udev)
	{
		pr_debug("dev->udev = NULL\n");
	}
	else
	{
		pr_debug("dev->udev->state = %d dev->udev->speed = %d\n", dev->udev->state, dev->udev->speed);
	}
	
//  for (i = 0; i < DataSize; i++)
//  {
//  	pr_debug("%2x ", (u8)Data[i]);
//  }
//  pr_debug("\n");

	mutex_lock(&dev->Bulk_Mutex);
	//----- if EPROTO happens, we will call clear feature and re-send again
	do{
		
		EgisMsg(dev->bPrintDbgMsg, KERN_ERR,"Do usb_bulk_msg\n");
		retval = usb_bulk_msg(
					dev->udev,
		  			(dir_in == dir) ? 
						usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr) :
						usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),
		   			Data,
		   			DataSize,
		   			&iActualRWSize, 
					Timeout
				 );
		// show data
//  	EgisMsg(dev->bPrintDbgMsg, KERN_ERR,"following are data block of bulk transfer:\r\n");
//  	int iLoopIndex = 0;
//  	unsigned char *pData = Data;
//  	for(iLoopIndex = 0; iLoopIndex<DataSize; iLoopIndex++)
//  	{
//  		EgisMsg(dev->bPrintDbgMsg, KERN_ERR,"%2x", pData[iLoopIndex]);
//  	}
//  	EgisMsg(dev->bPrintDbgMsg, KERN_ERR,"\r\ndata block finish\r\n");
		
		if(EGIS_FAIL(retval)){
			//----- if error == EPROTO && not be restored --> clear halt
			if(EOVERFLOW == retval)
			{
				EgisMsg(dev->bPrintDbgMsg, KERN_ERR,"=Egis_BulkXfer= bulk transfer error, EOVERFLOW, data size = %d"
					, DataSize);
			}
			if(EPROTO == retval && !bRestore){
				EgisMsg(dev->bPrintDbgMsg, KERN_ERR, "=Egis_BulkXfer= bulk xfer fail clear feature\r\n");
				retval = usb_clear_halt(dev->udev, (dir_in == dir) ? 
								usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr) :
								usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr)
						 );
				bRestore = true;
			}
			//----- this if include "else" above and check clear halt fail
			if(EGIS_FAIL(retval)){
				EgisMsg(dev->bPrintDbgMsg, KERN_ERR, "=Egis_BulkXfer= bulk xfer fail %d\r\n", retval);
				break;
			}
		}
		else{
			//----- if xfer is success, set bRestore=false to leave while loop
			bRestore = false;
		}
		
	}while(EGIS_SUCCESS(retval) && bRestore);

	memcpy(pActualSize, &iActualRWSize, sizeof(int));
	EgisMsg(dev->bPrintDbgMsg, KERN_ERR, "=Egis_BulkXfer= bulk xfer actual data size: %d\r\n", iActualRWSize);

	mutex_unlock(&dev->Bulk_Mutex);

	//----- If xfer fails, reset device.
	if(EGIS_FAIL(retval)){
		Egis_Reset_device(dev);
	}
	//Wayne for test
	dev->bPrintDbgMsg = false;
	return retval;
}
예제 #2
0
int AlphaTec_SwitchIOPwrOff(usb_ss801u *dev)
{
	int retval = 0;
	int buf_size = 512;
	unsigned char *buffer = kzalloc(buf_size, GFP_KERNEL);


	/* _____	0x300 */
	retval = Read_Write_Register(dev, 0xD2, 0x13, 0x03, 0x00, 0x00, 0x01, buffer, buf_size);
	buffer[0] &= 0xBF;
	if (EGIS_SUCCESS(retval))
		retval = Read_Write_Register(dev, 0xDA, 0x23, 0x03, 0x00, 0x00, 0x01, buffer, buf_size);

	/* ____	0x301 */
	if (EGIS_SUCCESS(retval)) {
		retval = Read_Write_Register(dev, 0xD2, 0x13, 0x03, 0x01, 0x00, 0x01, buffer, buf_size);
		buffer[0] &= 0xFB;
		if (EGIS_SUCCESS(retval))
			retval = Read_Write_Register(dev, 0xDA, 0x23, 0x03, 0x01, 0x00, 0x01, buffer, buf_size);
	}

	/* ____	0x0302 Off Bit5 to 0 */
	if (EGIS_SUCCESS(retval)) {
		retval = Read_Write_Register(dev, 0xD2, 0x13, 0x03, 0x02, 0x00, 0x01, buffer, buf_size);
		buffer[0] &= 0xDF;
		if (EGIS_SUCCESS(retval))
			retval = Read_Write_Register(dev, 0xDA, 0x23, 0x03, 0x02, 0x00, 0x01, buffer, buf_size);
	}

	/* ____	0x30c ~0x30f */
	if (EGIS_SUCCESS(retval)) {
		buffer[0] = 0x0;
		buffer[1] = 0x0;
		buffer[2] = 0x0;
		buffer[3] = 0x0;
		retval = Read_Write_Register(dev, 0xDA, 0x23, 0x03, 0x0C, 0x00, 0x04, buffer, buf_size);
	}

	/* ____	0x310 ~ 0x313 */
	if (EGIS_SUCCESS(retval)) {
		buffer[0] = 0xFF;
		buffer[1] = 0xFF;
		buffer[2] = 0xFF;
		buffer[3] = 0xFF;
		retval = Read_Write_Register(dev, 0xDA, 0x23, 0x03, 0x10, 0x00, 0x04, buffer, buf_size);
	}

	/* ____	0x80 */
	if (EGIS_SUCCESS(retval)) {
		buffer[0] = 0xFF;
		retval = Read_Write_Register(dev, 0xDA, 0x2A, 0x00, 0x80, 0x00, 0x01, buffer, buf_size);
	}

	/* ____	0x90 */
	if (EGIS_SUCCESS(retval)) {
		buffer[0] = 0xFF;
		retval = Read_Write_Register(dev, 0xDA, 0x2A, 0x00, 0x90, 0x00, 0x01, buffer, buf_size);
	}

	/* ____	0xA0 */
	if (EGIS_SUCCESS(retval)) {
		buffer[0] = 0xFF;
		retval = Read_Write_Register(dev, 0xDA, 0x2A, 0x00, 0xA0, 0x00, 0x01, buffer, buf_size);
	}

	/* ____	0xB0 */
	if (EGIS_SUCCESS(retval)) {
		buffer[0] = 0xFF;
		retval = Read_Write_Register(dev, 0xDA, 0x2A, 0x00, 0xB0, 0x00, 0x01, buffer, buf_size);
	}


	kfree(buffer);

	return retval;
}