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

📄 keyspan.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	   		otherwise looks like usa26 data format */		if (p_priv->baud > 57600) {			for (i = 0; i < urb->actual_length ; ++i) 				tty_insert_flip_char(tty, data[i], 0);		}		else {						/* 0x80 bit is error flag */			if ((data[0] & 0x80) == 0) {				/* no errors on individual bytes, only possible overrun err*/				if (data[0] & RXERROR_OVERRUN)						err = TTY_OVERRUN;				else err = 0;				for (i = 1; i < urb->actual_length ; ++i) 					tty_insert_flip_char(tty, data[i], err);						} 			else {			/* some bytes had errors, every byte has status */				dbg("%s - RX error!!!!", __FUNCTION__);				for (i = 0; i + 1 < urb->actual_length; i += 2) {					int stat = data[i], flag = 0;					if (stat & RXERROR_OVERRUN)						flag |= TTY_OVERRUN;					if (stat & RXERROR_FRAMING)						flag |= TTY_FRAME;					if (stat & RXERROR_PARITY)						flag |= TTY_PARITY;					/* XXX should handle break (0x10) */					tty_insert_flip_char(tty, data[i+1], flag);				}			}		}		tty_flip_buffer_push(tty);	}					/* Resubmit urb so we continue receiving */	urb->dev = port->serial->dev;	if (port->open_count)		if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {			dbg("%s - resubmit read urb failed. (%d)", __FUNCTION__, err);		}	return;}static void	usa90_instat_callback(struct urb *urb){	unsigned char 				*data = urb->transfer_buffer;	struct keyspan_usa90_portStatusMessage	*msg;	struct usb_serial			*serial;	struct usb_serial_port			*port;	struct keyspan_port_private	 	*p_priv;	int old_dcd_state, err;	int status = urb->status;	serial = (struct usb_serial *) urb->context;	if (status) {		dbg("%s - nonzero status: %x", __FUNCTION__, status);		return;	}	if (urb->actual_length < 14) {		dbg("%s - %d byte report??", __FUNCTION__, urb->actual_length);		goto exit;	}	msg = (struct keyspan_usa90_portStatusMessage *)data;	/* Now do something useful with the data */	port = serial->port[0];	p_priv = usb_get_serial_port_data(port);		/* Update handshaking pin state information */	old_dcd_state = p_priv->dcd_state;	p_priv->cts_state = ((msg->cts) ? 1 : 0);	p_priv->dsr_state = ((msg->dsr) ? 1 : 0);	p_priv->dcd_state = ((msg->dcd) ? 1 : 0);	p_priv->ri_state = ((msg->ri) ? 1 : 0);	if (port->tty && !C_CLOCAL(port->tty)	    && old_dcd_state != p_priv->dcd_state) {		if (old_dcd_state)			tty_hangup(port->tty);		/*  else */		/*	wake_up_interruptible(&p_priv->open_wait); */	}		/* Resubmit urb so we continue receiving */	urb->dev = serial->dev;	if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {		dbg("%s - resubmit read urb failed. (%d)", __FUNCTION__, err);	}exit:	;}static void	usa90_outcont_callback(struct urb *urb){	struct usb_serial_port *port;	struct keyspan_port_private *p_priv;	port = (struct usb_serial_port *) urb->context;	p_priv = usb_get_serial_port_data(port);	if (p_priv->resend_cont) {		dbg ("%s - sending setup", __FUNCTION__); 		keyspan_usa90_send_setup(port->serial, port, p_priv->resend_cont - 1);	}}/* Status messages from the 28xg */static void	usa67_instat_callback(struct urb *urb){	int					err;	unsigned char 				*data = urb->transfer_buffer;	struct keyspan_usa67_portStatusMessage	*msg;	struct usb_serial			*serial;	struct usb_serial_port			*port;	struct keyspan_port_private	 	*p_priv;	int old_dcd_state;	int status = urb->status;	dbg ("%s", __FUNCTION__);	serial = urb->context;	if (status) {		dbg("%s - nonzero status: %x", __FUNCTION__, status);		return;	}	if (urb->actual_length != sizeof(struct keyspan_usa67_portStatusMessage)) {		dbg("%s - bad length %d", __FUNCTION__, urb->actual_length);		return;	}	/* Now do something useful with the data */	msg = (struct keyspan_usa67_portStatusMessage *)data;	/* Check port number from message and retrieve private data */	if (msg->port >= serial->num_ports) {		dbg ("%s - Unexpected port number %d", __FUNCTION__, msg->port);		return;	}	port = serial->port[msg->port];	p_priv = usb_get_serial_port_data(port);	/* Update handshaking pin state information */	old_dcd_state = p_priv->dcd_state;	p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);	p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);	if (port->tty && !C_CLOCAL(port->tty)	    && old_dcd_state != p_priv->dcd_state) {		if (old_dcd_state)			tty_hangup(port->tty);		/*  else */		/*	wake_up_interruptible(&p_priv->open_wait); */	}	/* Resubmit urb so we continue receiving */	urb->dev = serial->dev;	err = usb_submit_urb(urb, GFP_ATOMIC);	if (err != 0)		dbg("%s - resubmit read urb failed. (%d)", __FUNCTION__, err);}static void usa67_glocont_callback(struct urb *urb){	struct usb_serial *serial;	struct usb_serial_port *port;	struct keyspan_port_private *p_priv;	int i;	dbg ("%s", __FUNCTION__);	serial = urb->context;	for (i = 0; i < serial->num_ports; ++i) {		port = serial->port[i];		p_priv = usb_get_serial_port_data(port);		if (p_priv->resend_cont) {			dbg ("%s - sending setup", __FUNCTION__);			keyspan_usa67_send_setup(serial, port,						p_priv->resend_cont - 1);			break;		}	}}static int keyspan_write_room (struct usb_serial_port *port){	struct keyspan_port_private	*p_priv;	const struct keyspan_device_details	*d_details;	int				flip;	int				data_len;	struct urb			*this_urb;	dbg("%s", __FUNCTION__);	p_priv = usb_get_serial_port_data(port);	d_details = p_priv->device_details;	if (d_details->msg_format == msg_usa90)   		data_len = 64;	else		data_len = 63;	flip = p_priv->out_flip;	/* Check both endpoints to see if any are available. */	if ((this_urb = p_priv->out_urbs[flip]) != NULL) {		if (this_urb->status != -EINPROGRESS)			return (data_len);		flip = (flip + 1) & d_details->outdat_endp_flip;        		if ((this_urb = p_priv->out_urbs[flip]) != NULL) 			if (this_urb->status != -EINPROGRESS)				return (data_len);	}	return (0);}static int keyspan_chars_in_buffer (struct usb_serial_port *port){	return (0);}static int keyspan_open (struct usb_serial_port *port, struct file *filp){	struct keyspan_port_private 	*p_priv;	struct keyspan_serial_private 	*s_priv;	struct usb_serial 		*serial = port->serial;	const struct keyspan_device_details	*d_details;	int				i, err;	int				baud_rate, device_port;	struct urb			*urb;	unsigned int			cflag;	s_priv = usb_get_serial_data(serial);	p_priv = usb_get_serial_port_data(port);	d_details = p_priv->device_details;	dbg("%s - port%d.", __FUNCTION__, port->number);	/* Set some sane defaults */	p_priv->rts_state = 1;	p_priv->dtr_state = 1;	p_priv->baud = 9600;	/* force baud and lcr to be set on open */	p_priv->old_baud = 0;	p_priv->old_cflag = 0;	p_priv->out_flip = 0;	p_priv->in_flip = 0;	/* Reset low level data toggle and start reading from endpoints */	for (i = 0; i < 2; i++) {		if ((urb = p_priv->in_urbs[i]) == NULL)			continue;		urb->dev = serial->dev;		/* make sure endpoint data toggle is synchronized with the device */		usb_clear_halt(urb->dev, urb->pipe);		if ((err = usb_submit_urb(urb, GFP_KERNEL)) != 0) {			dbg("%s - submit urb %d failed (%d)", __FUNCTION__, i, err);		}	}	/* Reset low level data toggle on out endpoints */	for (i = 0; i < 2; i++) {		if ((urb = p_priv->out_urbs[i]) == NULL)			continue;		urb->dev = serial->dev;		/* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), 0); */	}	/* get the terminal config for the setup message now so we don't	 * need to send 2 of them */	cflag = port->tty->termios->c_cflag;	device_port = port->number - port->serial->minor;	/* Baud rate calculation takes baud rate as an integer	   so other rates can be generated if desired. */	baud_rate = tty_get_baud_rate(port->tty);	/* If no match or invalid, leave as default */	if (baud_rate >= 0	    && d_details->calculate_baud_rate(baud_rate, d_details->baudclk,				NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {		p_priv->baud = baud_rate;	}	/* set CTS/RTS handshake etc. */	p_priv->cflag = cflag;	p_priv->flow_control = (cflag & CRTSCTS)? flow_cts: flow_none;	keyspan_send_setup(port, 1);	//mdelay(100);	//keyspan_set_termios(port, NULL);	return (0);}static inline void stop_urb(struct urb *urb){	if (urb && urb->status == -EINPROGRESS)		usb_kill_urb(urb);}static void keyspan_close(struct usb_serial_port *port, struct file *filp){	int			i;	struct usb_serial	*serial = port->serial;	struct keyspan_serial_private 	*s_priv;	struct keyspan_port_private 	*p_priv;	dbg("%s", __FUNCTION__);	s_priv = usb_get_serial_data(serial);	p_priv = usb_get_serial_port_data(port);		p_priv->rts_state = 0;	p_priv->dtr_state = 0;		if (serial->dev) {		keyspan_send_setup(port, 2);		/* pilot-xfer seems to work best with this delay */		mdelay(100);		// keyspan_set_termios(port, NULL);	}	/*while (p_priv->outcont_urb->status == -EINPROGRESS) {		dbg("%s - urb in progress", __FUNCTION__);	}*/	p_priv->out_flip = 0;	p_priv->in_flip = 0;	if (serial->dev) {		/* Stop reading/writing urbs */		stop_urb(p_priv->inack_urb);		/* stop_urb(p_priv->outcont_urb); */		for (i = 0; i < 2; i++) {			stop_urb(p_priv->in_urbs[i]);			stop_urb(p_priv->out_urbs[i]);		}	}	port->tty = NULL;}	/* download the firmware to a pre-renumeration device */static int keyspan_fake_startup (struct usb_serial *serial){	int 				response;	const struct ezusb_hex_record 	*record;	char				*fw_name;	dbg("Keyspan startup version %04x product %04x",	    le16_to_cpu(serial->dev->descriptor.bcdDevice),	    le16_to_cpu(serial->dev->descriptor.idProduct));		if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000) != 0x8000) {		dbg("Firmware already loaded.  Quitting.");		return(1);	}		/* Select firmware image on the basis of idProduct */	switch (le16_to_cpu(serial->dev->descriptor.idProduct)) {	case keyspan_usa28_pre_product_id:		record = &keyspan_usa28_firmware[0];		fw_name = "USA28";		break;	case keyspan_usa28x_pre_product_id:		record = &keyspan_usa28x_firmware[0];		fw_name = "USA28X";		break;	case keyspan_usa28xa_pre_product_id:		record = &keyspan_usa28xa_firmware[0];		fw_name = "USA28XA";		break;	case keyspan_usa28xb_pre_product_id:		record = &keyspan_usa28xb_firmware[0];		fw_name = "USA28XB";		break;	case keyspan_usa19_pre_product_id:		record = &keyspan_usa19_firmware[0];		fw_name = "USA19";		break;			     	case keyspan_usa19qi_pre_product_id:		record = &keyspan_usa19qi_firmware[0];		fw_name = "USA19QI";		break;			     	case keyspan_mpr_pre_product_id:		record = &keyspan_mpr_firmware[0];		fw_name = "MPR";		break;	case keyspan_usa19qw_pre_product_id:		record = &keyspan_usa19qw_firmware[0];		fw_name = "USA19QI";		break;			     	case keyspan_usa18x_pre_product_id:		record = &keyspan_usa18x_firmware[0];		fw_name = "USA18X";		break;			     	case keyspan_usa19w_pre_product_id:		record = &keyspan_usa19w_firmware[0];		fw_name = "USA19W";		break;			case keyspan_usa49w_pre_product_id:		record = &keyspan_usa49w_firmware[0];		fw_name = "USA49W";		break;	case keyspan_usa49wlc_pre_product_id:		record = &keyspan_usa49wlc_firmware[0];		fw_name = "USA49WLC";		break;	default:		record = NULL;		fw_name = "Unknown";		break;	}	if (record == NULL) {		dev_err(&serial->dev->dev, "Required keyspan firmware image (%s) unavailable.\n", fw_name);		return(1);	}	dbg("Uploading Keyspan %s firmware.", fw_name);		/* download the firmware image */	response = ezusb_set_reset(serial, 1);	while(record->address != 0xffff) {		response = ezusb_writememory(serial, record->address,					     (unsigned char *)record->data,					     record->data_size, 0xa0);		if (response < 0) {			dev_err(&serial->dev->dev, "ezusb_writememory failed for Keyspan"				"firmware (%d %04X %p %d)\n",				response, 				record->address, record->data, record->data_size);			break;		}		record++;	}		/* bring device out of reset. Renumeration will occur in a		   moment and the new device will bind to the real driver */	response = ezusb_set_reset(serial, 0);	/* we don't want this device to have a driver assigned to it. */	return (1);}/* Helper functions used by keyspan_setup_urbs */static struct usb_endpoint_descriptor const *find_ep(struct usb_serial const *serial,						     int endpoint){	struct usb_host_interface *iface_desc;	struct usb_endpoint_descriptor *ep;	int i;	iface_desc = serial->interface->cur_altsetting;	for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {		ep = &iface_desc->endpoint[i].desc;		if (ep->bEndpointAddress == endpoint)			return ep;	}	dev_warn(&serial->interface->dev, "found no endpoint descriptor for "		 "endpoint %x\n", endpoint);	return NULL;

⌨️ 快捷键说明

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