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

📄 ftdi_sio.c

📁 linux-2.4.29操作系统的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
			break;		}		urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);		if (!urb->transfer_buffer) {			err("%s - out of memory for urb buffers.", 			    __FUNCTION__);			continue;		}	}	/* Need at least one write urb in the pool */	if (i == 0) {		kfree (priv);		return -ENOMEM;	}	port->private = priv;		return (0);}/* Startup for the SIO chip *//* Called from usbserial:serial_probe */static int ftdi_SIO_startup (struct usb_serial *serial){	struct ftdi_private *priv;	int err;	dbg("%s",__FUNCTION__);	err = ftdi_common_startup(serial);	if (err){		return (err);	}	priv = serial->port->private;	priv->chip_type = SIO;	priv->baud_base = 12000000 / 16;	priv->write_offset = 1;		return (0);}/* Startup for the 8U232AM chip *//* Called from usbserial:serial_probe */static int ftdi_8U232AM_startup (struct usb_serial *serial){ /* ftdi_8U232AM_startup */	struct ftdi_private *priv;	int err;	dbg("%s",__FUNCTION__);	err = ftdi_common_startup(serial);	if (err){		return (err);	}	priv = serial->port->private;	priv->chip_type = FT8U232AM;	priv->baud_base = 48000000 / 2; /* Would be / 16, but FTDI supports 0.125, 0.25 and 0.5 divisor fractions! */		return (0);} /* ftdi_8U232AM_startup *//* Startup for the FT232BM chip *//* Called from usbserial:serial_probe */static int ftdi_FT232BM_startup (struct usb_serial *serial){ /* ftdi_FT232BM_startup */	struct ftdi_private *priv;	int err;	dbg("%s",__FUNCTION__);	err = ftdi_common_startup(serial);	if (err){		return (err);	}	priv = serial->port->private;	priv->chip_type = FT232BM;	priv->baud_base = 48000000 / 2; /* Would be / 16, but FT232BM supports multiple of 0.125 divisor fractions! */		return (0);} /* ftdi_FT232BM_startup *//* Startup for the USB-UIRT device, which requires hardwired baudrate (38400 gets mapped to 312500) *//* Called from usbserial:serial_probe */static int ftdi_USB_UIRT_startup (struct usb_serial *serial){ /* ftdi_USB_UIRT_startup */	struct ftdi_private *priv;	int err;	dbg("%s",__FUNCTION__);	err = ftdi_8U232AM_startup(serial);	if (err){		return (err);	}	priv = serial->port->private;	priv->flags |= ASYNC_SPD_CUST;	priv->custom_divisor = 77;	priv->force_baud = B38400;		return (0);} /* ftdi_USB_UIRT_startup *//* Startup for the HE-TIRA1 device, which requires hardwired * baudrate (38400 gets mapped to 100000) */static int ftdi_HE_TIRA1_startup (struct usb_serial *serial){ /* ftdi_HE_TIRA1_startup */	struct ftdi_private *priv;	int err;	dbg("%s",__FUNCTION__);	err = ftdi_FT232BM_startup(serial);	if (err){		return (err);	}	priv = serial->port->private;	priv->flags |= ASYNC_SPD_CUST;	priv->custom_divisor = 240;	priv->force_baud = B38400;	priv->force_rtscts = 1;		return (0);} /* ftdi_HE_TIRA1_startup *//* ftdi_shutdown is called from usbserial:usb_serial_disconnect  *   it is called when the usb device is disconnected * *   usbserial:usb_serial_disconnect *      calls __serial_close for each open of the port *      shutdown is called then (ie ftdi_shutdown) *//* Startup for the 8U232AM chip */static int ftdi_userdev_startup (struct usb_serial *serial){	struct ftdi_private *priv;	priv = serial->port->private = kmalloc(sizeof(struct ftdi_private), GFP_KERNEL);	if (!priv){		err("%s- kmalloc(%Zd) failed.", __FUNCTION__, sizeof(struct ftdi_private));		return -ENOMEM;	}	priv->chip_type = FT8U232AM; /* XXX: Hmm. Keep this.... -- REW */	priv->baud_base = baud_base; 	priv->custom_divisor = 0;	priv->write_offset = 0;        init_waitqueue_head(&priv->delta_msr_wait);	/* This will push the characters through immediately rather	   than queue a task to deliver them */	priv->flags = ASYNC_LOW_LATENCY;		return (0);}static void ftdi_shutdown (struct usb_serial *serial){ /* ftdi_shutdown */		struct usb_serial_port *port = &serial->port[0];		struct ftdi_private *priv = serial->port->private; 	int i;	unsigned long flags; 	dbg("%s", __FUNCTION__);	/* all open ports are closed at this point          *    (by usbserial.c:__serial_close, which calls ftdi_close)  	 */		/* Only execute this if this is the final open port for this device */	if (port->open_count == 0){		spin_lock_irqsave (&priv->write_urb_pool_lock, flags);		for (i = 0; i < NUM_URBS && priv->write_urb_pool[i]; ++i) {			/* FIXME - uncomment the following usb_unlink_urb call when			 * the host controllers get fixed to set urb->dev = NULL after			 * the urb is finished.  Otherwise this call oopses. */			/* usb_unlink_urb(priv->write_urb_pool[i]); */			if (priv->write_urb_pool[i]->transfer_buffer) {				kfree(priv->write_urb_pool[i]->transfer_buffer);				priv->write_urb_pool[i]->transfer_buffer = NULL;			}			usb_free_urb (priv->write_urb_pool[i]);			priv->write_urb_pool[i] = NULL;		}		spin_unlock_irqrestore (&priv->write_urb_pool_lock, flags);		/* usb_disconnect shuts down the port->read_urb so don't do it here */		/* as was done previously */	}	if (serial->port->private){		kfree(serial->port->private);		serial->port->private = NULL;	}} /* ftdi_shutdown */static int  ftdi_open (struct usb_serial_port *port, struct file *filp){ /* ftdi_open */	struct termios tmp_termios;	struct usb_serial *serial = port->serial;	struct ftdi_private *priv = port->private;		int result = 0;	char buf[1]; /* Needed for the usb_control_msg I think */	dbg("%s", __FUNCTION__);	port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;	/* No error checking for this (will get errors later anyway) */	/* See ftdi_sio.h for description of what is reset */	usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),			FTDI_SIO_RESET_REQUEST, FTDI_SIO_RESET_REQUEST_TYPE, 			FTDI_SIO_RESET_SIO, 			0, buf, 0, WDR_TIMEOUT);	/* Termios defaults are set by usb_serial_init. We don't change	   port->tty->termios - this would loose speed settings, etc.	   This is same behaviour as serial.c/rs_open() - Kuba */	/* ftdi_set_termios  will send usb control messages */	ftdi_set_termios(port, &tmp_termios);	/* FIXME: Flow control might be enabled, so it should be checked -	   we have no control of defaults! */	/* Turn on RTS and DTR since we are not flow controlling by default */	if (set_dtr(port, HIGH) < 0) {		err("%s Error from DTR HIGH urb", __FUNCTION__);	}	if (set_rts(port, HIGH) < 0){		err("%s Error from RTS HIGH urb", __FUNCTION__);	}	/* Start reading from the device */	FILL_BULK_URB(port->read_urb, serial->dev, 		      usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),		      port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,		      ftdi_read_bulk_callback, port);	result = usb_submit_urb(port->read_urb);	if (result)		err("%s - failed submitting read urb, error %d", __FUNCTION__, result);	return result;} /* ftdi_open *//*  * usbserial:__serial_close  only calls ftdi_close if the point is open * *   This only gets called when it is the last close *    *    */static void ftdi_close (struct usb_serial_port *port, struct file *filp){ /* ftdi_close */	struct usb_serial *serial;	unsigned int c_cflag = port->tty->termios->c_cflag;	char buf[1];	dbg("%s", __FUNCTION__);	serial = get_usb_serial ( port, __FUNCTION__);	if (!serial)		return;	if (serial->dev) {		if (c_cflag & HUPCL){			/* Disable flow control */			if (usb_control_msg(serial->dev, 					    usb_sndctrlpipe(serial->dev, 0),					    FTDI_SIO_SET_FLOW_CTRL_REQUEST,					    FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,					    0, 0, buf, 0, WDR_TIMEOUT) < 0) {				err("error from flowcontrol urb");			}	    			/* drop DTR */			if (set_dtr(port, LOW) < 0){				err("Error from DTR LOW urb");			}			/* drop RTS */			if (set_rts(port, LOW) < 0) {				err("Error from RTS LOW urb");			}		} /* Note change no line is hupcl is off */		/* shutdown our bulk read */		if (port->read_urb) {			if(usb_unlink_urb (port->read_urb)<0)				err("Error unlinking urb");		}		/* unlink the running write urbs */	} /* if (serial->dev) */} /* ftdi_close */  /* The SIO requires the first byte to have: *  B0 1 *  B1 0 *  B2..7 length of message excluding byte 0 * * The new devices do not require this byte */static int ftdi_write (struct usb_serial_port *port, int from_user,			   const unsigned char *buf, int count){ /* ftdi_write */	struct usb_serial *serial = get_usb_serial ( port, __FUNCTION__);	struct ftdi_private *priv = (struct ftdi_private *)port->private;	unsigned char *first_byte;	int data_offset ;       /* will be 1 for the SIO and 0 otherwise */	int result;	int user_bytes_sent = 0 ;   /* amount of user data sent */	/* Variables for urb pool management */	unsigned char *current_position = (unsigned char *)buf;	int i; 	struct urb *urb; /* pointer to urb from urb pool */	unsigned long flags;	/* end of urb pool management */			dbg("%s port %d, %d bytes", __FUNCTION__, port->number, count);	if (count == 0) {		err("write request of 0 bytes");		goto exit;	}		data_offset = priv->write_offset;        dbg("data_offset set to %d",data_offset);	while (count > 0) {		/* urb_byte_count = user_byte_count + data_offset */		int urb_byte_count;  /* Number of bytes of URB data   */		int user_byte_count; /* Number of bytes of user data */		/* Find a free urb in the list */		urb = NULL;		spin_lock_irqsave (&(priv->write_urb_pool_lock), flags) ; 		for (i = 0 ; i < NUM_URBS && priv->write_urb_pool[i]; i++) {			if (priv->write_urb_pool[i] -> status != -EINPROGRESS) {				urb = priv->write_urb_pool[i];				/* Must make sure another write doesn't grab this */				urb->status = -EINPROGRESS;				break;			}		}		spin_unlock_irqrestore (&priv->write_urb_pool_lock, flags);		if (urb == NULL) {			dbg("%s - no more free urbs", __FUNCTION__);

⌨️ 快捷键说明

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