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

📄 io_edgeport.c

📁 基于S3CEB2410平台LINUX操作系统下 USB驱动源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * Edgeport USB Serial Converter driver * * Copyright(c) 2000 Inside Out Networks, All rights reserved. * Copyright(c) 2001 Greg Kroah-Hartman <greg@kroah.com> * *	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. * * Supports the following devices: *	Edgeport/4 *	Edgeport/4t *	Edgeport/2 *	Edgeport/4i *	Edgeport/2i *	Edgeport/421 *	Edgeport/21 *	Rapidport/4 *	Edgeport/8 *	Edgeport/2D8 *	Edgeport/4D8 *	Edgeport/8i * * Version history: *  * 2.2 2001_11_14 greg kroah-hartman *	- fixed bug in edge_close that kept the port from being used more *	  than once. *	- fixed memory leak on device removal. *	- fixed potential double free of memory when command urb submitting *	  failed. *	- other small cleanups when the device is removed *	 * 2.1 2001_07_09 greg kroah-hartman *	- added support for TIOCMBIS and TIOCMBIC. * *     (04/08/2001) gb *	- Identify version on module load. * * 2.0 2001_03_05 greg kroah-hartman *	- reworked entire driver to fit properly in with the other usb-serial *	  drivers.  Occasional oopses still happen, but it's a good start. * * 1.2.3 (02/23/2001) greg kroah-hartman *	- changed device table to work properly for 2.4.x final format. *	- fixed problem with dropping data at high data rates. * * 1.2.2 (11/27/2000) greg kroah-hartman *	- cleaned up more NTisms. *	- Added device table for 2.4.0-test11 * * 1.2.1 (11/08/2000) greg kroah-hartman *	- Started to clean up NTisms. *	- Fixed problem with dev field of urb for kernels >= 2.4.0-test9 * * 1.2 (10/17/2000) David Iacovelli * 	Remove all EPIC code and GPL source *  Fix RELEVANT_IFLAG macro to include flow control  *  changes port configuration changes. *  Fix redefinition of SERIAL_MAGIC *  Change all timeout values to 5 seconds *  Tried to fix the UHCI multiple urb submission, but failed miserably. *  it seems to work fine with OHCI. *  ( Greg take a look at the #if 0 at end of WriteCmdUsb() we must  *    find a way to work arount this UHCI bug ) * * 1.1 (10/11/2000) David Iacovelli *  Fix XON/XOFF flow control to support both IXON and IXOFF * * 0.9.27 (06/30/2000) David Iacovelli *  Added transmit queue and now allocate urb for command writes. * * 0.9.26 (06/29/2000) David Iacovelli *  Add support for 80251 based edgeport * * 0.9.25 (06/27/2000) David Iacovelli *  Do not close the port if it has multiple opens. * * 0.9.24 (05/26/2000) David Iacovelli *  Add IOCTLs to support RXTX and JAVA POS  *  and first cut at running BlackBox Demo * * 0.9.23 (05/24/2000) David Iacovelli *  Add IOCTLs to support RXTX and JAVA POS * * 0.9.22 (05/23/2000) David Iacovelli *  fixed bug in enumeration.  If epconfig turns on mapping by *  path after a device is already plugged in, we now update *  the mapping correctly * * 0.9.21 (05/16/2000) David Iacovelli *  Added BlockUntilChaseResp() to also wait for txcredits *  Updated the way we allocate and handle write URBs  *	Add debug code to dump buffers * * 0.9.20 (05/01/2000) David Iacovelli *	change driver to use usb/tts/ * * 0.9.19 (05/01/2000) David Iacovelli *  Update code to compile if DEBUG is off * * 0.9.18 (04/28/2000) David Iacovelli *  cleanup and test tty_register with devfs * * 0.9.17 (04/27/2000) greg kroah-hartman * 	changed tty_register around to be like the way it * 	was before, but now it works properly with devfs. * * 0.9.16 (04/26/2000) david iacovelli *  Fixed bug in GetProductInfo() * * 0.9.15 (04/25/2000) david iacovelli *	Updated enumeration * * 0.9.14 (04/24/2000) david iacovelli *  Removed all config/status IOCTLS and  *  converted to using /proc/edgeport *  still playing with devfs * * 0.9.13 (04/24/2000) david iacovelli *  Removed configuration based on ttyUSB0 *  Added support for configuration using /prod/edgeport *  first attempt at using devfs (not working yet!) *  Added IOCTL to GetProductInfo() *  Added support for custom baud rates *	Add support for random port numbers * * 0.9.12 (04/18/2000) david iacovelli *	added additional configuration IOCTLs *  use ttyUSB0 for configuration * * 0.9.11 (04/17/2000) greg kroah-hartman *	fixed module initialization race conditions. *	made all urbs dynamically allocated. *	made driver devfs compatible. now it only registers the tty device *	when the device is actually plugged in. * * 0.9.10 (04/13/2000) greg kroah-hartman *	added proc interface framework. * * 0.9.9 (04/13/2000) david iacovelli *	added enumeration code and ioctls to configure the device * * 0.9.8 (04/12/2000) david iacovelli *  Change interrupt read start when device is plugged in *  and stop when device is removed *	process interrupt reads when all ports are closed  *  (keep value of rxBytesAvail consistent with the edgeport) *  set the USB_BULK_QUEUE flag so that we can shove a bunch  *  of urbs at once down the pipe  * * 0.9.7 (04/10/2000) david iacovelli * 	start to add enumeration code. *  generate serial number for epic devices *  add support for kdb * * 0.9.6 (03/30/2000) david iacovelli *  add IOCTL to get string, manufacture, and boot descriptors * * 0.9.5 (03/14/2000) greg kroah-hartman *	more error checking added to SerialOpen to try to fix UHCI open problem * * 0.9.4 (03/09/2000) greg kroah-hartman *	added more error checking to handle oops when data is hanging *	around and tty is abruptly closed. * * 0.9.3 (03/09/2000) david iacovelli *	Add epic support for xon/xoff chars *	play with performance * * 0.9.2 (03/08/2000) greg kroah-hartman *	changed most "info" calls to "dbg" *	implemented flow control properly in the termios call * * 0.9.1 (03/08/2000) david iacovelli *	added EPIC support *	enabled bootloader update * * 0.9 (03/08/2000) greg kroah-hartman *	Release to IO networks. *	Integrated changes that David made *  made getting urbs for writing SMP safe * * 0.8 (03/07/2000) greg kroah-hartman *	Release to IO networks. *	Fixed problems that were seen in code by David. *  Now both Edgeport/4 and Edgeport/2 works properly. *  Changed most of the functions to use port instead of serial. * * 0.7 (02/27/2000) greg kroah-hartman *	Milestone 3 release. *	Release to IO Networks *	ioctl for waiting on line change implemented. *	ioctl for getting statistics implemented. *	multiport support working. *	lsr and msr registers are now handled properly. *	change break now hooked up and working. *	support for all known Edgeport devices. * * 0.6 (02/22/2000) greg kroah-hartman *	Release to IO networks. *	CHASE is implemented correctly when port is closed. *	SerialOpen now blocks correctly until port is fully opened. * * 0.5 (02/20/2000) greg kroah-hartman *	Release to IO networks. *	Known problems: *		modem status register changes are not sent on to the user *		CHASE is not implemented when the port is closed. * * 0.4 (02/16/2000) greg kroah-hartman *	Second cut at the CeBit demo. *	Doesn't leak memory on every write to the port *	Still small leaks on startup. *	Added support for Edgeport/2 and Edgeport/8 * * 0.3 (02/15/2000) greg kroah-hartman *	CeBit demo release. *	Force the line settings to 4800, 8, 1, e for the demo. *	Warning! This version leaks memory like crazy! * * 0.2 (01/30/2000) greg kroah-hartman *	Milestone 1 release. *	Device is found by USB subsystem, enumerated, fimware is downloaded *	and the descriptors are printed to the debug log, config is set, and *	green light starts to blink. Open port works, and data can be sent *	and received at the default settings of the UART. Loopback connector *	and debug log confirms this. *  * 0.1 (01/23/2000) greg kroah-hartman *	Initial release to help IO Networks try to set up their test system.  *	Edgeport4 is recognized, firmware is downloaded, config is set so  *	device blinks green light every 3 sec. Port is bound, but opening, *	closing, and sending data do not work properly. *  */#include <linux/config.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/signal.h>#include <linux/errno.h>#include <linux/poll.h>#include <linux/init.h>#include <linux/slab.h>#include <linux/fcntl.h>#include <linux/tty.h>#include <linux/tty_driver.h>#include <linux/tty_flip.h>#include <linux/module.h>#include <linux/spinlock.h>#include <linux/serial.h>#include <linux/ioctl.h>#include <linux/proc_fs.h>#include <linux/usb.h>#ifdef CONFIG_USB_SERIAL_DEBUG	static int debug = 1;#else	static int debug;#endif#include "usb-serial.h"#include "io_edgeport.h"#include "io_ionsp.h"		/* info for the iosp messages */#include "io_16654.h"		/* 16654 UART defines *//* * Version Information */#define DRIVER_VERSION "v2.2"#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"#define DRIVER_DESC "Edgeport USB Serial Driver"/* First, the latest boot code - for first generation edgeports */#define IMAGE_ARRAY_NAME	BootCodeImage_GEN1#define IMAGE_VERSION_NAME	BootCodeImageVersion_GEN1#include "io_fw_boot.h"		/* the bootloader firmware to download to a device, if it needs it *//* for second generation edgeports */#define IMAGE_ARRAY_NAME	BootCodeImage_GEN2#define IMAGE_VERSION_NAME	BootCodeImageVersion_GEN2#include "io_fw_boot2.h"	/* the bootloader firmware to download to a device, if it needs it *//* Then finally the main run-time operational code - for first generation edgeports */#define IMAGE_ARRAY_NAME	OperationalCodeImage_GEN1#define IMAGE_VERSION_NAME	OperationalCodeImageVersion_GEN1#include "io_fw_down.h"		/* Define array OperationalCodeImage[] *//* for second generation edgeports */#define IMAGE_ARRAY_NAME	OperationalCodeImage_GEN2#define IMAGE_VERSION_NAME	OperationalCodeImageVersion_GEN2#include "io_fw_down2.h"	/* Define array OperationalCodeImage[] */#define MAX_NAME_LEN		64#define CHASE_TIMEOUT		(5*HZ)		/* 5 seconds */#define OPEN_TIMEOUT		(5*HZ)		/* 5 seconds */#define COMMAND_TIMEOUT		(5*HZ)		/* 5 seconds */#ifndef SERIAL_MAGIC	#define SERIAL_MAGIC	0x6702#endif#define PORT_MAGIC		0x7301/* receive port state */enum RXSTATE {	EXPECT_HDR1 = 0,	/* Expect header byte 1 */	EXPECT_HDR2 = 1,	/* Expect header byte 2 */	EXPECT_DATA = 2,	/* Expect 'RxBytesRemaining' data */	EXPECT_HDR3 = 3,	/* Expect header byte 3 (for status hdrs only) */};/* Transmit Fifo  * This Transmit queue is an extension of the edgeport Rx buffer.  * The maximum amount of data buffered in both the edgeport  * Rx buffer (maxTxCredits) and this buffer will never exceed maxTxCredits. */struct TxFifo {	unsigned int	head;	/* index to head pointer (write) */	unsigned int	tail;	/* index to tail pointer (read)  */	unsigned int	count;	/* Bytes in queue */	unsigned int	size;	/* Max size of queue (equal to Max number of TxCredits) */	unsigned char	*fifo;	/* allocated Buffer */};/* This structure holds all of the local port information */struct edgeport_port {	__u16			txCredits;		/* our current credits for this port */	__u16			maxTxCredits;		/* the max size of the port */	struct TxFifo		txfifo;			/* transmit fifo -- size will be maxTxCredits */	struct urb		*write_urb;		/* write URB for this port */	char			write_in_progress;	/* TRUE while a write URB is outstanding */	__u8			shadowLCR;		/* last LCR value received */	__u8			shadowMCR;		/* last MCR value received */	__u8			shadowMSR;		/* last MSR value received */	__u8			shadowLSR;		/* last LSR value received */	__u8			shadowXonChar;		/* last value set as XON char in Edgeport */	__u8			shadowXoffChar;		/* last value set as XOFF char in Edgeport */	__u8			validDataMask;	__u32			baudRate;	char			open;	char			openPending;	char			commandPending;	char			closePending;	char			chaseResponsePending;	wait_queue_head_t	wait_chase;		/* for handling sleeping while waiting for chase to finish */	wait_queue_head_t	wait_open;		/* for handling sleeping while waiting for open to finish */	wait_queue_head_t	wait_command;		/* for handling sleeping while waiting for command to finish */	wait_queue_head_t	delta_msr_wait;		/* for handling sleeping while waiting for msr change to happen */	struct async_icount	icount;	struct usb_serial_port	*port;			/* loop back to the owner of this object */};/* This structure holds all of the individual device information */struct edgeport_serial {	char			name[MAX_NAME_LEN+1];		/* string name of this device */	EDGE_MANUF_DESCRIPTOR		manuf_descriptor;	/* the manufacturer descriptor */	EDGE_BOOT_DESCRIPTOR		boot_descriptor;	/* the boot firmware descriptor */	struct edgeport_product_info	product_info;		/* Product Info */	__u8			interrupt_in_endpoint;		/* the interrupt endpoint handle */	unsigned char *		interrupt_in_buffer;		/* the buffer we use for the interrupt endpoint */	struct urb *		interrupt_read_urb;		/* our interrupt urb */	__u8			bulk_in_endpoint;		/* the bulk in endpoint handle */	unsigned char *		bulk_in_buffer;			/* the buffer we use for the bulk in endpoint */	struct urb *		read_urb;			/* our bulk read urb */	__u8			bulk_out_endpoint;		/* the bulk out endpoint handle */	__s16			rxBytesAvail;			/* the number of bytes that we need to read from this device */	enum RXSTATE		rxState;			/* the current state of the bulk receive processor */	__u8			rxHeader1;			/* receive header byte 1 */	__u8			rxHeader2;			/* receive header byte 2 */	__u8			rxHeader3;			/* receive header byte 3 */	__u8			rxPort;				/* the port that we are currently receiving data for */	__u8			rxStatusCode;			/* the receive status code */	__u8			rxStatusParam;			/* the receive status paramater */	__s16			rxBytesRemaining;		/* the number of port bytes left to read */	struct usb_serial	*serial;			/* loop back to the owner of this object */};/* baud rate information */typedef struct _DIVISOR_TABLE_ENTRY {	__u32   BaudRate;	__u16  Divisor;} DIVISOR_TABLE_ENTRY, *PDIVISOR_TABLE_ENTRY;//// Define table of divisors for Rev A EdgePort/4 hardware// These assume a 3.6864MHz crystal, the standard /16, and// MCR.7 = 0.

⌨️ 快捷键说明

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