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

📄 visor.c

📁 usb driver for 2.6.17
💻 C
📖 第 1 页 / 共 3 页
字号:
static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_id *id){	struct device *dev = &serial->dev->dev;	struct palm_ext_connection_info *connection_info;	unsigned char *transfer_buffer;	int retval;	dbg("%s", __FUNCTION__);	transfer_buffer =  kmalloc (sizeof (*connection_info), GFP_KERNEL);	if (!transfer_buffer) {		dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __FUNCTION__,			sizeof(*connection_info));		return -ENOMEM;	}	retval = usb_control_msg (serial->dev,				  usb_rcvctrlpipe(serial->dev, 0), 				  PALM_GET_EXT_CONNECTION_INFORMATION,				  0xc2, 0x0000, 0x0000, transfer_buffer,				  sizeof (*connection_info), 300);	if (retval < 0)		dev_err(dev, "%s - error %d getting connection info\n",			__FUNCTION__, retval);	else		usb_serial_debug_data(debug, &serial->dev->dev, __FUNCTION__,				      retval, transfer_buffer);	kfree (transfer_buffer);	return 0;}static int visor_probe (struct usb_serial *serial, const struct usb_device_id *id){	int retval = 0;	int (*startup) (struct usb_serial *serial, const struct usb_device_id *id);	dbg("%s", __FUNCTION__);	if (serial->dev->actconfig->desc.bConfigurationValue != 1) {		err("active config #%d != 1 ??",			serial->dev->actconfig->desc.bConfigurationValue);		return -ENODEV;	}	if (id->driver_info) {		startup = (void *)id->driver_info;		retval = startup(serial, id);	}	return retval;}static int visor_calc_num_ports (struct usb_serial *serial){	int num_ports = (int)(long)(usb_get_serial_data(serial));	if (num_ports)		usb_set_serial_data(serial, NULL);	return num_ports;}static int generic_startup(struct usb_serial *serial){	struct visor_private *priv;	int i;	for (i = 0; i < serial->num_ports; ++i) {		priv = kzalloc (sizeof(*priv), GFP_KERNEL);		if (!priv)			return -ENOMEM;		spin_lock_init(&priv->lock);		usb_set_serial_port_data(serial->port[i], priv);	}	return 0;}static int clie_3_5_startup (struct usb_serial *serial){	struct device *dev = &serial->dev->dev;	int result;	u8 data;	dbg("%s", __FUNCTION__);	/*	 * Note that PEG-300 series devices expect the following two calls.	 */	/* get the config number */	result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0),				  USB_REQ_GET_CONFIGURATION, USB_DIR_IN,				  0, 0, &data, 1, 3000);	if (result < 0) {		dev_err(dev, "%s: get config number failed: %d\n", __FUNCTION__, result);		return result;	}	if (result != 1) {		dev_err(dev, "%s: get config number bad return length: %d\n", __FUNCTION__, result);		return -EIO;	}	/* get the interface number */	result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0),				  USB_REQ_GET_INTERFACE, 				  USB_DIR_IN | USB_RECIP_INTERFACE,				  0, 0, &data, 1, 3000);	if (result < 0) {		dev_err(dev, "%s: get interface number failed: %d\n", __FUNCTION__, result);		return result;	}	if (result != 1) {		dev_err(dev, "%s: get interface number bad return length: %d\n", __FUNCTION__, result);		return -EIO;	}	return generic_startup(serial);} static int treo_attach (struct usb_serial *serial){	struct usb_serial_port *swap_port;	/* Only do this endpoint hack for the Handspring devices with	 * interrupt in endpoints, which for now are the Treo devices. */	if (!((le16_to_cpu(serial->dev->descriptor.idVendor) == HANDSPRING_VENDOR_ID) ||	      (le16_to_cpu(serial->dev->descriptor.idVendor) == KYOCERA_VENDOR_ID)) ||	    (serial->num_interrupt_in == 0))		goto generic_startup;	dbg("%s", __FUNCTION__);	/*	* It appears that Treos and Kyoceras want to use the 	* 1st bulk in endpoint to communicate with the 2nd bulk out endpoint, 	* so let's swap the 1st and 2nd bulk in and interrupt endpoints.  	* Note that swapping the bulk out endpoints would break lots of 	* apps that want to communicate on the second port.	*/#define COPY_PORT(dest, src)						\	dest->read_urb = src->read_urb;					\	dest->bulk_in_endpointAddress = src->bulk_in_endpointAddress;	\	dest->bulk_in_buffer = src->bulk_in_buffer;			\	dest->interrupt_in_urb = src->interrupt_in_urb;			\	dest->interrupt_in_endpointAddress = src->interrupt_in_endpointAddress;	\	dest->interrupt_in_buffer = src->interrupt_in_buffer;	swap_port = kmalloc(sizeof(*swap_port), GFP_KERNEL);	if (!swap_port)		return -ENOMEM;	COPY_PORT(swap_port, serial->port[0]);	COPY_PORT(serial->port[0], serial->port[1]);	COPY_PORT(serial->port[1], swap_port);	kfree(swap_port);generic_startup:	return generic_startup(serial);}static int clie_5_attach (struct usb_serial *serial){	dbg("%s", __FUNCTION__);	/* TH55 registers 2 ports. 	   Communication in from the UX50/TH55 uses bulk_in_endpointAddress from port 0 	   Communication out to the UX50/TH55 uses bulk_out_endpointAddress from port 1 	   	   Lets do a quick and dirty mapping	 */		/* some sanity check */	if (serial->num_ports < 2)		return -1;			/* port 0 now uses the modified endpoint Address */	serial->port[0]->bulk_out_endpointAddress = serial->port[1]->bulk_out_endpointAddress;	return generic_startup(serial);}static void visor_shutdown (struct usb_serial *serial){	dbg("%s", __FUNCTION__);}static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg){	dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);	return -ENOIOCTLCMD;}/* This function is all nice and good, but we don't change anything based on it :) */static void visor_set_termios (struct usb_serial_port *port, struct termios *old_termios){	unsigned int cflag;	dbg("%s - port %d", __FUNCTION__, port->number);	if ((!port->tty) || (!port->tty->termios)) {		dbg("%s - no tty structures", __FUNCTION__);		return;	}	cflag = port->tty->termios->c_cflag;	/* check that they really want us to change something */	if (old_termios) {		if ((cflag == old_termios->c_cflag) &&		    (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {			dbg("%s - nothing to change...", __FUNCTION__);			return;		}	}	/* get the byte size */	switch (cflag & CSIZE) {		case CS5:	dbg("%s - data bits = 5", __FUNCTION__);   break;		case CS6:	dbg("%s - data bits = 6", __FUNCTION__);   break;		case CS7:	dbg("%s - data bits = 7", __FUNCTION__);   break;		default:		case CS8:	dbg("%s - data bits = 8", __FUNCTION__);   break;	}		/* determine the parity */	if (cflag & PARENB)		if (cflag & PARODD)			dbg("%s - parity = odd", __FUNCTION__);		else			dbg("%s - parity = even", __FUNCTION__);	else		dbg("%s - parity = none", __FUNCTION__);	/* figure out the stop bits requested */	if (cflag & CSTOPB)		dbg("%s - stop bits = 2", __FUNCTION__);	else		dbg("%s - stop bits = 1", __FUNCTION__);		/* figure out the flow control settings */	if (cflag & CRTSCTS)		dbg("%s - RTS/CTS is enabled", __FUNCTION__);	else		dbg("%s - RTS/CTS is disabled", __FUNCTION__);		/* determine software flow control */	if (I_IXOFF(port->tty))		dbg("%s - XON/XOFF is enabled, XON = %2x, XOFF = %2x",		    __FUNCTION__, START_CHAR(port->tty), STOP_CHAR(port->tty));	else		dbg("%s - XON/XOFF is disabled", __FUNCTION__);	/* get the baud rate wanted */	dbg("%s - baud rate = %d", __FUNCTION__, tty_get_baud_rate(port->tty));	return;}static int __init visor_init (void){	int i, retval;	/* Only if parameters were passed to us */	if ((vendor>0) && (product>0)) {		struct usb_device_id usb_dev_temp[]=			{{USB_DEVICE(vendor, product),			.driver_info = (kernel_ulong_t)&palm_os_4_probe }};		/* Find the last entry in id_table */		for (i=0; ; i++) {			if (id_table[i].idVendor==0) {				id_table[i] = usb_dev_temp[0];				break;			}		}		/* Find the last entry in id_table_combined */		for (i=0; ; i++) {			if (id_table_combined[i].idVendor==0) {				id_table_combined[i] = usb_dev_temp[0];				break;			}		}		info("Untested USB device specified at time of module insertion");		info("Warning: This is not guaranteed to work");		info("Using a newer kernel is preferred to this method");		info("Adding Palm OS protocol 4.x support for unknown device: 0x%x/0x%x",			vendor, product);	}	retval = usb_serial_register(&handspring_device);	if (retval)		goto failed_handspring_register;	retval = usb_serial_register(&clie_3_5_device);	if (retval)		goto failed_clie_3_5_register;	retval = usb_serial_register(&clie_5_device);	if (retval)		goto failed_clie_5_register;	retval = usb_register(&visor_driver);	if (retval) 		goto failed_usb_register;	info(DRIVER_DESC);	return 0;failed_usb_register:	usb_serial_deregister(&clie_5_device);failed_clie_5_register:	usb_serial_deregister(&clie_3_5_device);failed_clie_3_5_register:	usb_serial_deregister(&handspring_device);failed_handspring_register:	return retval;}static void __exit visor_exit (void){	usb_deregister (&visor_driver);	usb_serial_deregister (&handspring_device);	usb_serial_deregister (&clie_3_5_device);	usb_serial_deregister (&clie_5_device);}module_init(visor_init);module_exit(visor_exit);MODULE_AUTHOR( DRIVER_AUTHOR );MODULE_DESCRIPTION( DRIVER_DESC );MODULE_LICENSE("GPL");module_param(debug, bool, S_IRUGO | S_IWUSR);MODULE_PARM_DESC(debug, "Debug enabled or not");module_param(stats, bool, S_IRUGO | S_IWUSR);MODULE_PARM_DESC(stats, "Enables statistics or not");module_param(vendor, ushort, 0);MODULE_PARM_DESC(vendor, "User specified vendor ID");module_param(product, ushort, 0);MODULE_PARM_DESC(product, "User specified product ID");

⌨️ 快捷键说明

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