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

📄 ftdi_sio.c

📁 基于S3CEB2410平台LINUX操作系统下 USB驱动源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
		case B19200: urb_value = ftdi_sio_b19200; dbg("Set to 19200") ; break;		case B38400: urb_value = ftdi_sio_b38400; dbg("Set to 38400") ; break;		case B57600: urb_value = ftdi_sio_b57600; dbg("Set to 57600") ; break;		case B115200: urb_value = ftdi_sio_b115200; dbg("Set to 115200") ; break;		default: dbg(__FUNCTION__ " FTDI_SIO does not support the baudrate (%d) requested",			     (cflag & CBAUD)); 		   break;		}	} else { /* it is 8U232AM */		switch(cflag & CBAUD){		case B0: break; /* ignored by this */		case B300: urb_value = ftdi_8U232AM_48MHz_b300; dbg("Set to 300"); break;		case B600: urb_value = ftdi_8U232AM_48MHz_b600; dbg("Set to 600") ; break;		case B1200: urb_value = ftdi_8U232AM_48MHz_b1200; dbg("Set to 1200") ; break;		case B2400: urb_value = ftdi_8U232AM_48MHz_b2400; dbg("Set to 2400") ; break;		case B4800: urb_value = ftdi_8U232AM_48MHz_b4800; dbg("Set to 4800") ; break;		case B9600: urb_value = ftdi_8U232AM_48MHz_b9600; dbg("Set to 9600") ; break;		case B19200: urb_value = ftdi_8U232AM_48MHz_b19200; dbg("Set to 19200") ; break;		case B38400: urb_value = ftdi_8U232AM_48MHz_b38400; dbg("Set to 38400") ; break;		case B57600: urb_value = ftdi_8U232AM_48MHz_b57600; dbg("Set to 57600") ; break;		case B115200: urb_value = ftdi_8U232AM_48MHz_b115200; dbg("Set to 115200") ; break;		case B230400: urb_value = ftdi_8U232AM_48MHz_b230400; dbg("Set to 230400") ; break;		case B460800: urb_value = ftdi_8U232AM_48MHz_b460800; dbg("Set to 460800") ; break;		case B921600: urb_value = ftdi_8U232AM_48MHz_b921600; dbg("Set to 921600") ; break;		default: dbg(__FUNCTION__ " The baudrate (%d) requested is not implemented",			     (cflag & CBAUD)); 		   break;		}	}	return(urb_value);}static void ftdi_sio_break_ctl( struct usb_serial_port *port, int break_state ){	struct usb_serial *serial = port->serial;	struct ftdi_private *priv = (struct ftdi_private *)port->private;	__u16 urb_value = 0; 	char buf[1];		/* break_state = -1 to turn on break, and 0 to turn off break */	/* see drivers/char/tty_io.c to see it used */	/* last_set_data_urb_value NEVER has the break bit set in it */	if (break_state) {		urb_value = priv->last_set_data_urb_value | FTDI_SIO_SET_BREAK;	} else {		urb_value = priv->last_set_data_urb_value; 	}		if (usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),			    FTDI_SIO_SET_DATA_REQUEST, 			    FTDI_SIO_SET_DATA_REQUEST_TYPE,			    urb_value , 0,			    buf, 0, WDR_TIMEOUT) < 0) {		err(__FUNCTION__ " FAILED to enable/disable break state (state was %d)",break_state);	}	   	dbg(__FUNCTION__ " break state is %d - urb is %d",break_state, urb_value);	}/* As I understand this - old_termios contains the original termios settings *//*  and tty->termios contains the new setting to be used *//* *//*   WARNING: set_termios calls this with old_termios in kernel space */static void ftdi_sio_set_termios (struct usb_serial_port *port, struct termios *old_termios){ /* ftdi_sio_set_termios */	struct usb_serial *serial = port->serial;	unsigned int cflag = port->tty->termios->c_cflag;	struct ftdi_private *priv = (struct ftdi_private *)port->private;		__u16 urb_value; /* will hold the new flags */	char buf[1]; /* Perhaps I should dynamically alloc this? */			dbg(__FUNCTION__);	/* FIXME -For this cut I don't care if the line is really changing or 	   not  - so just do the change regardless  - should be able to 	   compare old_termios and tty->termios */	/* NOTE These routines can get interrupted by 	   ftdi_sio_read_bulk_callback  - need to examine what this            means - don't see any problems yet */		/* Set number of data bits, parity, stop bits */		urb_value = 0;	urb_value |= (cflag & CSTOPB ? FTDI_SIO_SET_DATA_STOP_BITS_2 :		      FTDI_SIO_SET_DATA_STOP_BITS_1);	urb_value |= (cflag & PARENB ? 		      (cflag & PARODD ? FTDI_SIO_SET_DATA_PARITY_ODD : 		       FTDI_SIO_SET_DATA_PARITY_EVEN) :		      FTDI_SIO_SET_DATA_PARITY_NONE);	if (cflag & CSIZE) {		switch (cflag & CSIZE) {		case CS5: urb_value |= 5; dbg("Setting CS5"); break;		case CS6: urb_value |= 6; dbg("Setting CS6"); break;		case CS7: urb_value |= 7; dbg("Setting CS7"); break;		case CS8: urb_value |= 8; dbg("Setting CS8"); break;		default:			err("CSIZE was set but not CS5-CS8");		}	}	/* This is needed by the break command since it uses the same command - but is	 *  or'ed with this value  */	priv->last_set_data_urb_value = urb_value;		if (usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),			    FTDI_SIO_SET_DATA_REQUEST, 			    FTDI_SIO_SET_DATA_REQUEST_TYPE,			    urb_value , 0,			    buf, 0, 100) < 0) {		err(__FUNCTION__ " FAILED to set databits/stopbits/parity");	}	   	/* Now do the baudrate */	urb_value = translate_baudrate_to_ftdi((cflag & CBAUD), priv->ftdi_type);		if ((cflag & CBAUD) == B0 ) {		/* 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(__FUNCTION__ " error from disable flowcontrol urb");		}	    		/* Drop RTS and DTR */		if (set_dtr(serial->dev, usb_sndctrlpipe(serial->dev, 0),LOW) < 0){			err(__FUNCTION__ " Error from DTR LOW urb");		}		if (set_rts(serial->dev, usb_sndctrlpipe(serial->dev, 0),LOW) < 0){			err(__FUNCTION__ " Error from RTS LOW urb");		}				} else {		/* set the baudrate determined before */		if (usb_control_msg(serial->dev, 				    usb_sndctrlpipe(serial->dev, 0),				    FTDI_SIO_SET_BAUDRATE_REQUEST, 				    FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE,				    urb_value, 0, 				    buf, 0, 100) < 0) {			err(__FUNCTION__ " urb failed to set baurdrate");		}	}	/* Set flow control */	/* Note device also supports DTR/CD (ugh) and Xon/Xoff in hardware */	if (cflag & CRTSCTS) {		dbg(__FUNCTION__ " Setting to CRTSCTS 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 , FTDI_SIO_RTS_CTS_HS,				    buf, 0, WDR_TIMEOUT) < 0) {			err("urb failed to set to rts/cts flow control");		}					} else { 		/* CHECKME Assuming XON/XOFF handled by tty stack - not by device */		dbg(__FUNCTION__ " Turning off hardware 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("urb failed to clear flow control");		}							}	return;} /* ftdi_sio_set_termios */static int ftdi_sio_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg){	struct usb_serial *serial = port->serial;	struct ftdi_private *priv = (struct ftdi_private *)port->private;	__u16 urb_value=0; /* Will hold the new flags */	char buf[2];	int  ret, mask;		dbg(__FUNCTION__ " cmd 0x%04x", cmd);	/* Based on code from acm.c and others */	switch (cmd) {	case TIOCMGET:		dbg(__FUNCTION__ " TIOCMGET");		if (priv->ftdi_type == sio){			/* Request the status from the device */			if ((ret = usb_control_msg(serial->dev, 						   usb_rcvctrlpipe(serial->dev, 0),						   FTDI_SIO_GET_MODEM_STATUS_REQUEST, 						   FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,						   0, 0, 						   buf, 1, WDR_TIMEOUT)) < 0 ) {				err(__FUNCTION__ " Could not get modem status of device - err: %d",				    ret);				return(ret);			}		} else {			/* the 8U232AM returns a two byte value (the sio is a 1 byte value) - in the same 			   format as the data returned from the in point */			if ((ret = usb_control_msg(serial->dev, 						   usb_rcvctrlpipe(serial->dev, 0),						   FTDI_SIO_GET_MODEM_STATUS_REQUEST, 						   FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,						   0, 0, 						   buf, 2, WDR_TIMEOUT)) < 0 ) {				err(__FUNCTION__ " Could not get modem status of device - err: %d",				    ret);				return(ret);			}		}		return put_user((buf[0] & FTDI_SIO_DSR_MASK ? TIOCM_DSR : 0) |				(buf[0] & FTDI_SIO_CTS_MASK ? TIOCM_CTS : 0) |				(buf[0]  & FTDI_SIO_RI_MASK  ? TIOCM_RI  : 0) |				(buf[0]  & FTDI_SIO_RLSD_MASK ? TIOCM_CD  : 0),				(unsigned long *) arg);		break;	case TIOCMSET: /* Turns on and off the lines as specified by the mask */		dbg(__FUNCTION__ " TIOCMSET");		if (get_user(mask, (unsigned long *) arg))			return -EFAULT;		urb_value = ((mask & TIOCM_DTR) ? HIGH : LOW);		if (set_dtr(serial->dev, usb_sndctrlpipe(serial->dev, 0),urb_value) < 0){			err("Error from DTR set urb (TIOCMSET)");		}		urb_value = ((mask & TIOCM_RTS) ? HIGH : LOW);		if (set_rts(serial->dev, usb_sndctrlpipe(serial->dev, 0),urb_value) < 0){			err("Error from RTS set urb (TIOCMSET)");		}			break;						case TIOCMBIS: /* turns on (Sets) the lines as specified by the mask */		dbg(__FUNCTION__ " TIOCMBIS"); 	        if (get_user(mask, (unsigned long *) arg))			return -EFAULT;  	        if (mask & TIOCM_DTR){			if ((ret = set_dtr(serial->dev, 					   usb_sndctrlpipe(serial->dev, 0),					   HIGH)) < 0) {				err("Urb to set DTR failed");				return(ret);			}		}		if (mask & TIOCM_RTS) {			if ((ret = set_rts(serial->dev, 					   usb_sndctrlpipe(serial->dev, 0),					   HIGH)) < 0){				err("Urb to set RTS failed");				return(ret);			}		}					break;	case TIOCMBIC: /* turns off (Clears) the lines as specified by the mask */		dbg(__FUNCTION__ " TIOCMBIC"); 	        if (get_user(mask, (unsigned long *) arg))			return -EFAULT;  	        if (mask & TIOCM_DTR){			if ((ret = set_dtr(serial->dev, 					   usb_sndctrlpipe(serial->dev, 0),					   LOW)) < 0){				err("Urb to unset DTR failed");				return(ret);			}		}			if (mask & TIOCM_RTS) {			if ((ret = set_rts(serial->dev, 					   usb_sndctrlpipe(serial->dev, 0),					   LOW)) < 0){				err("Urb to unset RTS failed");				return(ret);			}		}		break;		/*		 * I had originally implemented TCSET{A,S}{,F,W} and		 * TCGET{A,S} here separately, however when testing I		 * found that the higher layers actually do the termios		 * conversions themselves and pass the call onto		 * ftdi_sio_set_termios. 		 *		 */	default:	  /* This is not an error - turns out the higher layers will do 	   *  some ioctls itself (see comment above) 	   */		dbg(__FUNCTION__ " arg not supported - it was 0x%04x",cmd);		return(-ENOIOCTLCMD);		break;	}	return 0;} /* ftdi_sio_ioctl */static int __init ftdi_sio_init (void){	dbg(__FUNCTION__);	usb_serial_register (&ftdi_sio_device);	usb_serial_register (&ftdi_8U232AM_device);	info(DRIVER_VERSION ":" DRIVER_DESC);	return 0;}static void __exit ftdi_sio_exit (void){	dbg(__FUNCTION__);	usb_serial_deregister (&ftdi_sio_device);	usb_serial_deregister (&ftdi_8U232AM_device);}module_init(ftdi_sio_init);module_exit(ftdi_sio_exit);MODULE_AUTHOR( DRIVER_AUTHOR );MODULE_DESCRIPTION( DRIVER_DESC );MODULE_LICENSE("GPL");MODULE_PARM(debug, "i");MODULE_PARM_DESC(debug, "Debug enabled or not");

⌨️ 快捷键说明

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