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

📄 keyspan.c

📁 优龙2410linux2.6.8内核源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	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;	serial = (struct usb_serial *) urb->context;	if (urb->status) {		dbg("%s - nonzero status: %x", __FUNCTION__, urb->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 pt_regs *regs){	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);	}}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]) != 0) {		if (this_urb->status != -EINPROGRESS)			return (data_len);		flip = (flip + 1) & d_details->outdat_endp_flip;        		if ((this_urb = p_priv->out_urbs[flip]) != 0) 			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) {		urb->transfer_flags &= ~URB_ASYNC_UNLINK;		usb_unlink_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",	    serial->dev->descriptor.bcdDevice,	    serial->dev->descriptor.idProduct); 		if ((serial->dev->descriptor.bcdDevice & 0x8000) != 0x8000) {		dbg("Firmware already loaded.  Quitting.");		return(1);	}		/* Select firmware image on the basis of idProduct */	switch (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 urb *keyspan_setup_urb (struct usb_serial *serial, int endpoint,				      int dir, void *ctx, char *buf, int len,				      void (*callback)(struct urb *, struct pt_regs *regs)){	struct urb *urb;	if (endpoint == -1)		return NULL;		/* endpoint not needed */	dbg ("%s - alloc for endpoint %d.", __FUNCTION__, endpoint);	urb = usb_alloc_urb(0, GFP_KERNEL);		/* No ISO */	if (urb == NULL) {		dbg ("%s - alloc for endpoint %d failed.", __FUNCTION__, endpoint);		return NULL;	}		/* Fill URB using supplied data. */	usb_fill_bulk_urb(urb, serial->dev,		      usb_sndbulkpipe(serial->dev, endpoint) | dir,		      buf, len, callback, ctx);	return urb;}static struct callbacks {	void	(*instat_callback)(struct urb *, struct pt_regs *regs);	void	(*glocont_callback)(struct urb *, struct pt_regs *regs);	void	(*indat_callback)(struct urb *, struct pt_regs *regs);	void	(*outdat_callback)(struct urb *, struct pt_regs *regs);	void	(*inack_callback)(struct urb *, struct pt_regs *regs);	void	(*outcont_callback)(struct urb *, struct pt_regs *regs);} keyspan_callbacks[] = {	{		/* msg_usa26 callbacks */		.instat_callback =	usa26_instat_callback,		.glocont_callback =	usa26_glocont_callback,		.indat_callback =	usa26_indat_callback,		.outdat_callback =	usa2x_outdat_callback,		.inack_callback =	usa26_inack_callback,		.outcont_callback =	usa26_outcont_callback,	}, {		/* msg_usa28 callbacks */		.instat_callback =	usa28_instat_callback,		.glocont_callback =	usa28_glocont_callback,		.indat_callback =	usa28_indat_callback,		.outdat_callback =	usa2x_outdat_callback,		.inack_callback =	usa28_inack_callback,		.outcont_callback =	usa28_outcont_callback,	}, {		/* msg_usa49 callbacks */		.instat_callback =	usa49_instat_callback,		.glocont_callback =	usa49_glocont_callback,		.indat_callback =	usa49_indat_callback,		.outdat_callback =	usa2x_outdat_callback,		.inack_callback =	usa49_inack_callback,		.outcont_callback =	usa49_outcont_callback,	}, {		/* msg_usa90 callbacks */		.instat_callback =	usa90_instat_callback,		.glocont_callback =	usa28_glocont_callback,				.indat_callback =	usa90_indat_callback,		.outdat_callback =	usa2x_outdat_callback,		.inack_callback =	usa28_inack_callback,		.outcont_callback =	usa90_outcont_callback,	}};	/* Generic setup urbs function that uses	   data in device_details */static void keyspan_setup_urbs(struct usb_serial *serial){	int				i, j;	struct keyspan_serial_private 	*s_priv;	const struct keyspan_device_details	*d_details;	struct usb_serial_port		*port;	struct keyspan_port_private	*p_priv;	struct callbacks		*cback;	int				endp;	dbg ("%s", __FUNCTION__);	s_priv = usb_get_serial_data(serial);	d_details = s_priv->device_details;		/* Setup values for the various callback routines */	cback = &keyspan_callbacks[d_details->msg_format];		/* Allocate and set up urbs for each one that is in use, 		   starting with instat endpoints */	s_priv->instat_urb = keyspan_setup_urb		(serial, d_details->instat_endpoint, USB_DIR_IN,		 serial, s_priv->instat_buf, INSTAT_BUFLEN,		 cback->instat_callback);	s_priv->glocont_urb = keyspan_setup_urb		(serial, d_details->glocont_endpoint, USB_DIR_OUT,		 serial, s_priv->glocont_buf, GLOCONT_BUFLEN,		 cback->glocont_callback);		/* Setup endpoints for each port specific thing */	for (i = 0; i < d_details->num_ports; i ++) {		port = serial->port[i];		p_priv = usb_get_serial_port_data(port);		/* Do indat endpoints first, once for each flip */		endp = d_details->indat_endpoints[i];		for (j = 0; j <= d_details->indat_endp_flip; ++j, ++endp) {			p_priv->in_urbs[j] = keyspan_setup_urb				(serial, endp, USB_DIR_IN, port,				 p_priv->in_buffer[j], 64,				 cback->indat_callback);		}		for (; j < 2; ++j)			p_priv->in_urbs[j] = NULL;		/* outdat endpoints also have flip */		endp = d_details->outdat_endpoints[i];		for (j = 0; j <= d_details->outdat_endp_flip; ++j, ++endp) {			p_priv->out_urbs[j] = keyspan_setup_urb				(serial, endp, USB_DIR_OUT, port,				 p_priv->out_buffer[j], 64,				 cback->outdat_callback);		}		for (; j < 2; ++j)			p_priv->out_urbs[j] = NULL;		/* inack endpoint */

⌨️ 快捷键说明

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