您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ usb_fill_int_urb函数代码示例

51自学网 2021-06-03 09:19:43
  C++
这篇教程C++ usb_fill_int_urb函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中usb_fill_int_urb函数的典型用法代码示例。如果您正苦于以下问题:C++ usb_fill_int_urb函数的具体用法?C++ usb_fill_int_urb怎么用?C++ usb_fill_int_urb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了usb_fill_int_urb函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: adu_write

static ssize_t adu_write(struct file *file, const __user char *buffer,			 size_t count, loff_t *ppos){	DECLARE_WAITQUEUE(waita, current);	struct adu_device *dev;	size_t bytes_written = 0;	size_t bytes_to_write;	size_t buffer_size;	unsigned long flags;	int retval;	dbg(2," %s : enter, count = %Zd", __func__, count);	dev = file->private_data;	retval = mutex_lock_interruptible(&dev->mtx);	if (retval)		goto exit_nolock;	/* verify that the device wasn't unplugged */	if (dev->udev == NULL) {		retval = -ENODEV;		printk(KERN_ERR "adutux: No device or device unplugged %d/n",		       retval);		goto exit;	}	/* verify that we actually have some data to write */	if (count == 0) {		dbg(1," %s : write request of 0 bytes", __func__);		goto exit;	}	while (count > 0) {		add_wait_queue(&dev->write_wait, &waita);		set_current_state(TASK_INTERRUPTIBLE);		spin_lock_irqsave(&dev->buflock, flags);		if (!dev->out_urb_finished) {			spin_unlock_irqrestore(&dev->buflock, flags);			mutex_unlock(&dev->mtx);			if (signal_pending(current)) {				dbg(1," %s : interrupted", __func__);				set_current_state(TASK_RUNNING);				retval = -EINTR;				goto exit_onqueue;			}			if (schedule_timeout(COMMAND_TIMEOUT) == 0) {				dbg(1, "%s - command timed out.", __func__);				retval = -ETIMEDOUT;				goto exit_onqueue;			}			remove_wait_queue(&dev->write_wait, &waita);			retval = mutex_lock_interruptible(&dev->mtx);			if (retval) {				retval = bytes_written ? bytes_written : retval;				goto exit_nolock;			}			dbg(4," %s : in progress, count = %Zd", __func__, count);		} else {			spin_unlock_irqrestore(&dev->buflock, flags);			set_current_state(TASK_RUNNING);			remove_wait_queue(&dev->write_wait, &waita);			dbg(4," %s : sending, count = %Zd", __func__, count);			/* write the data into interrupt_out_buffer from userspace */			buffer_size = le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize);			bytes_to_write = count > buffer_size ? buffer_size : count;			dbg(4," %s : buffer_size = %Zd, count = %Zd, bytes_to_write = %Zd",			    __func__, buffer_size, count, bytes_to_write);			if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write) != 0) {				retval = -EFAULT;				goto exit;			}			/* send off the urb */			usb_fill_int_urb(				dev->interrupt_out_urb,				dev->udev,				usb_sndintpipe(dev->udev, dev->interrupt_out_endpoint->bEndpointAddress),				dev->interrupt_out_buffer,				bytes_to_write,				adu_interrupt_out_callback,				dev,				dev->interrupt_out_endpoint->bInterval);			dev->interrupt_out_urb->actual_length = bytes_to_write;			dev->out_urb_finished = 0;			retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL);			if (retval < 0) {				dev->out_urb_finished = 1;				dev_err(&dev->udev->dev, "Couldn't submit "					"interrupt_out_urb %d/n", retval);				goto exit;			}			buffer += bytes_to_write;			count -= bytes_to_write;//.........这里部分代码省略.........
开发者ID:Adjustxx,项目名称:Savaged-Zen,代码行数:101,


示例2: wdm_probe

//.........这里部分代码省略.........	desc = kzalloc(sizeof(struct wdm_device), GFP_KERNEL);	if (!desc)		goto out;	mutex_init(&desc->lock);	spin_lock_init(&desc->iuspin);	init_waitqueue_head(&desc->wait);	desc->wMaxCommand = maxcom;	/* this will be expanded and needed in hardware endianness */	desc->inum = cpu_to_le16((u16)intf->cur_altsetting->desc.bInterfaceNumber);	desc->intf = intf;	INIT_WORK(&desc->rxwork, wdm_rxwork);	rv = -EINVAL;	iface = intf->cur_altsetting;	if (iface->desc.bNumEndpoints != 1)		goto err;	ep = &iface->endpoint[0].desc;	if (!ep || !usb_endpoint_is_int_in(ep))		goto err;	desc->wMaxPacketSize = le16_to_cpu(ep->wMaxPacketSize);	desc->bMaxPacketSize0 = udev->descriptor.bMaxPacketSize0;	desc->orq = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);	if (!desc->orq)		goto err;	desc->irq = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);	if (!desc->irq)		goto err;	desc->validity = usb_alloc_urb(0, GFP_KERNEL);	if (!desc->validity)		goto err;	desc->response = usb_alloc_urb(0, GFP_KERNEL);	if (!desc->response)		goto err;	desc->command = usb_alloc_urb(0, GFP_KERNEL);	if (!desc->command)		goto err;	desc->ubuf = kmalloc(desc->wMaxCommand, GFP_KERNEL);	if (!desc->ubuf)		goto err;	desc->sbuf = usb_alloc_coherent(interface_to_usbdev(intf),					desc->wMaxPacketSize,					GFP_KERNEL,					&desc->validity->transfer_dma);	if (!desc->sbuf)		goto err;	desc->inbuf = usb_alloc_coherent(interface_to_usbdev(intf),					 desc->bMaxPacketSize0,					 GFP_KERNEL,					 &desc->response->transfer_dma);	if (!desc->inbuf)		goto err2;	usb_fill_int_urb(		desc->validity,		interface_to_usbdev(intf),		usb_rcvintpipe(interface_to_usbdev(intf), ep->bEndpointAddress),		desc->sbuf,		desc->wMaxPacketSize,		wdm_int_callback,		desc,		ep->bInterval	);	desc->validity->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;	usb_set_intfdata(intf, desc);	rv = usb_register_dev(intf, &wdm_class);	if (rv < 0)		goto err3;	else		dev_info(&intf->dev, "cdc-wdm%d: USB WDM device/n",			intf->minor - WDM_MINOR_BASE);out:	return rv;err3:	usb_set_intfdata(intf, NULL);	usb_free_coherent(interface_to_usbdev(desc->intf),			  desc->bMaxPacketSize0,			desc->inbuf,			desc->response->transfer_dma);err2:	usb_free_coherent(interface_to_usbdev(desc->intf),			  desc->wMaxPacketSize,			  desc->sbuf,			  desc->validity->transfer_dma);err:	free_urbs(desc);	kfree(desc->ubuf);	kfree(desc->orq);	kfree(desc->irq);	kfree(desc);	return rv;}
开发者ID:jbaldus,项目名称:android_kernel_a100,代码行数:101,


示例3: btusb_send_frame

static int btusb_send_frame(struct sk_buff *skb){    struct hci_dev *hdev = (struct hci_dev *) skb->dev;    struct btusb_data *data = hdev->driver_data;    struct usb_ctrlrequest *dr;    struct urb *urb;    unsigned int pipe;    int err;    BT_DBG("%s", hdev->name);    if (!test_bit(HCI_RUNNING, &hdev->flags))        return -EBUSY;    switch (bt_cb(skb)->pkt_type) {    case HCI_COMMAND_PKT:        urb = usb_alloc_urb(0, GFP_ATOMIC);        if (!urb)            return -ENOMEM;        dr = kmalloc(sizeof(*dr), GFP_ATOMIC);        if (!dr) {            usb_free_urb(urb);            return -ENOMEM;        }        dr->bRequestType = data->cmdreq_type;        dr->bRequest     = 0;        dr->wIndex       = 0;        dr->wValue       = 0;        dr->wLength      = __cpu_to_le16(skb->len);        pipe = usb_sndctrlpipe(data->udev, 0x00);        usb_fill_control_urb(urb, data->udev, pipe, (void *) dr,                             skb->data, skb->len, btusb_tx_complete, skb);        hdev->stat.cmd_tx++;        break;    case HCI_ACLDATA_PKT:        if (!data->bulk_tx_ep || (hdev->conn_hash.acl_num < 1 &&                                  hdev->conn_hash.le_num < 1))            return -ENODEV;        urb = usb_alloc_urb(0, GFP_ATOMIC);        if (!urb)            return -ENOMEM;        pipe = usb_sndbulkpipe(data->udev,                               data->bulk_tx_ep->bEndpointAddress);        usb_fill_bulk_urb(urb, data->udev, pipe,                          skb->data, skb->len, btusb_tx_complete, skb);        hdev->stat.acl_tx++;        break;    case HCI_SCODATA_PKT:        if (!data->isoc_tx_ep || hdev->conn_hash.sco_num < 1)            return -ENODEV;        urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_ATOMIC);        if (!urb)            return -ENOMEM;        pipe = usb_sndisocpipe(data->udev,                               data->isoc_tx_ep->bEndpointAddress);        usb_fill_int_urb(urb, data->udev, pipe,                         skb->data, skb->len, btusb_isoc_tx_complete,                         skb, data->isoc_tx_ep->bInterval);        urb->transfer_flags  = URB_ISO_ASAP;        __fill_isoc_descriptor(urb, skb->len,                               le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));        hdev->stat.sco_tx++;        goto skip_waking;    default:        return -EILSEQ;    }    err = inc_tx(data);    if (err) {        usb_anchor_urb(urb, &data->deferred);        schedule_work(&data->waker);        err = 0;        goto done;    }skip_waking:    usb_anchor_urb(urb, &data->tx_anchor);    err = usb_submit_urb(urb, GFP_ATOMIC);    if (err < 0) {        BT_ERR("%s urb %p submission failed", hdev->name, urb);        kfree(urb->setup_packet);//.........这里部分代码省略.........
开发者ID:magnostik,项目名称:Project-X5pro-Kernel-u8860-u8800pro,代码行数:101,


示例4: adu_open

static int adu_open(struct inode *inode, struct file *file){	struct adu_device *dev = NULL;	struct usb_interface *interface;	int subminor;	int retval = 0;	dbg(2,"%s : enter", __FUNCTION__);	subminor = iminor(inode);	interface = usb_find_interface(&adu_driver, subminor);	if (!interface) {		err("%s - error, can't find device for minor %d",		    __FUNCTION__, subminor);		retval = -ENODEV;		goto exit_no_device;	}	dev = usb_get_intfdata(interface);	if (!dev) {		retval = -ENODEV;		goto exit_no_device;	}	/* lock this device */	if ((retval = mutex_lock_interruptible(&dev->mtx))) {		dbg(2, "%s : mutex lock failed", __FUNCTION__);		goto exit_no_device;	}	/* increment our usage count for the device */	++dev->open_count;	dbg(2,"%s : open count %d", __FUNCTION__, dev->open_count);	/* save device in the file's private structure */	file->private_data = dev;	if (dev->open_count == 1) {		/* initialize in direction */		dev->read_buffer_length = 0;		/* fixup first read by having urb waiting for it */		usb_fill_int_urb(dev->interrupt_in_urb,dev->udev,				 usb_rcvintpipe(dev->udev,				 		dev->interrupt_in_endpoint->bEndpointAddress),				 dev->interrupt_in_buffer,				 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize),				 adu_interrupt_in_callback, dev,				 dev->interrupt_in_endpoint->bInterval);		/* dev->interrupt_in_urb->transfer_flags |= URB_ASYNC_UNLINK; */		dev->read_urb_finished = 0;		retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);		if (retval)			--dev->open_count;	}	mutex_unlock(&dev->mtx);exit_no_device:	dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval);	return retval;}
开发者ID:3sOx,项目名称:asuswrt-merlin,代码行数:63,


示例5: adu_write

static ssize_t adu_write(struct file *file, const __user char *buffer,			 size_t count, loff_t *ppos){	struct adu_device *dev;	size_t bytes_written = 0;	size_t bytes_to_write;	size_t buffer_size;	int retval;	int timeout = 0;	dbg(2," %s : enter, count = %Zd", __FUNCTION__, count);	dev = file->private_data;	/* lock this object */	retval = mutex_lock_interruptible(&dev->mtx);	if (retval)		goto exit_nolock;	/* verify that the device wasn't unplugged */	if (dev->udev == NULL || dev->minor == 0) {		retval = -ENODEV;		err("No device or device unplugged %d", retval);		goto exit;	}	/* verify that we actually have some data to write */	if (count == 0) {		dbg(1," %s : write request of 0 bytes", __FUNCTION__);		goto exit;	}	while (count > 0) {		if (dev->interrupt_out_urb->status == -EINPROGRESS) {			timeout = COMMAND_TIMEOUT;			while (timeout > 0) {				if (signal_pending(current)) {				dbg(1," %s : interrupted", __FUNCTION__);				retval = -EINTR;				goto exit;			}			mutex_unlock(&dev->mtx);			timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout);			retval = mutex_lock_interruptible(&dev->mtx);			if (retval) {				retval = bytes_written ? bytes_written : retval;				goto exit_nolock;			}			if (timeout > 0) {				break;			}			dbg(1," %s : interrupted timeout: %d", __FUNCTION__, timeout);		}		dbg(1," %s : final timeout: %d", __FUNCTION__, timeout);		if (timeout == 0) {			dbg(1, "%s - command timed out.", __FUNCTION__);			retval = -ETIMEDOUT;			goto exit;		}		dbg(4," %s : in progress, count = %Zd", __FUNCTION__, count);		} else {			dbg(4," %s : sending, count = %Zd", __FUNCTION__, count);			/* write the data into interrupt_out_buffer from userspace */			buffer_size = le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize);			bytes_to_write = count > buffer_size ? buffer_size : count;			dbg(4," %s : buffer_size = %Zd, count = %Zd, bytes_to_write = %Zd",			    __FUNCTION__, buffer_size, count, bytes_to_write);			if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write) != 0) {				retval = -EFAULT;				goto exit;			}			/* send off the urb */			usb_fill_int_urb(				dev->interrupt_out_urb,				dev->udev,				usb_sndintpipe(dev->udev, dev->interrupt_out_endpoint->bEndpointAddress),				dev->interrupt_out_buffer,				bytes_to_write,				adu_interrupt_out_callback,				dev,				dev->interrupt_in_endpoint->bInterval);			/* dev->interrupt_in_urb->transfer_flags |= URB_ASYNC_UNLINK; */			dev->interrupt_out_urb->actual_length = bytes_to_write;			retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL);			if (retval < 0) {				err("Couldn't submit interrupt_out_urb %d", retval);				goto exit;			}			buffer += bytes_to_write;//.........这里部分代码省略.........
开发者ID:3sOx,项目名称:asuswrt-merlin,代码行数:101,


示例6: gigaset_probe

static int gigaset_probe(struct usb_interface *interface,			 const struct usb_device_id *id){	int retval;	struct usb_device *udev = interface_to_usbdev(interface);	struct usb_host_interface *hostif = interface->cur_altsetting;	struct cardstate *cs = NULL;	struct usb_cardstate *ucs = NULL;	struct usb_endpoint_descriptor *endpoint;	int buffer_size;	gig_dbg(DEBUG_ANY, "%s: Check if device matches ...", __func__);	/* See if the device offered us matches what we can accept */	if ((le16_to_cpu(udev->descriptor.idVendor)  != USB_M105_VENDOR_ID) ||	    (le16_to_cpu(udev->descriptor.idProduct) != USB_M105_PRODUCT_ID)) {		gig_dbg(DEBUG_ANY, "device ID (0x%x, 0x%x) not for me - skip",			le16_to_cpu(udev->descriptor.idVendor),			le16_to_cpu(udev->descriptor.idProduct));		return -ENODEV;	}	if (hostif->desc.bInterfaceNumber != 0) {		gig_dbg(DEBUG_ANY, "interface %d not for me - skip",			hostif->desc.bInterfaceNumber);		return -ENODEV;	}	if (hostif->desc.bAlternateSetting != 0) {		dev_notice(&udev->dev, "unsupported altsetting %d - skip",			   hostif->desc.bAlternateSetting);		return -ENODEV;	}	if (hostif->desc.bInterfaceClass != 255) {		dev_notice(&udev->dev, "unsupported interface class %d - skip",			   hostif->desc.bInterfaceClass);		return -ENODEV;	}	dev_info(&udev->dev, "%s: Device matched ... !/n", __func__);	/* allocate memory for our device state and intialize it */	cs = gigaset_initcs(driver, 1, 1, 0, cidmode, GIGASET_MODULENAME);	if (!cs)		return -ENODEV;	ucs = cs->hw.usb;	/* save off device structure ptrs for later use */	usb_get_dev(udev);	ucs->udev = udev;	ucs->interface = interface;	cs->dev = &interface->dev;	/* save address of controller structure */	usb_set_intfdata(interface, cs);	endpoint = &hostif->endpoint[0].desc;	buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);	ucs->bulk_out_size = buffer_size;	ucs->bulk_out_endpointAddr = endpoint->bEndpointAddress;	ucs->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);	if (!ucs->bulk_out_buffer) {		dev_err(cs->dev, "Couldn't allocate bulk_out_buffer/n");		retval = -ENOMEM;		goto error;	}	ucs->bulk_out_urb = usb_alloc_urb(0, GFP_KERNEL);	if (!ucs->bulk_out_urb) {		dev_err(cs->dev, "Couldn't allocate bulk_out_urb/n");		retval = -ENOMEM;		goto error;	}	endpoint = &hostif->endpoint[1].desc;	ucs->busy = 0;	ucs->read_urb = usb_alloc_urb(0, GFP_KERNEL);	if (!ucs->read_urb) {		dev_err(cs->dev, "No free urbs available/n");		retval = -ENOMEM;		goto error;	}	buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);	ucs->rcvbuf_size = buffer_size;	ucs->int_in_endpointAddr = endpoint->bEndpointAddress;	ucs->rcvbuf = kmalloc(buffer_size, GFP_KERNEL);	if (!ucs->rcvbuf) {		dev_err(cs->dev, "Couldn't allocate rcvbuf/n");		retval = -ENOMEM;		goto error;	}	/* Fill the interrupt urb and send it to the core */	usb_fill_int_urb(ucs->read_urb, udev,			 usb_rcvintpipe(udev,					endpoint->bEndpointAddress & 0x0f),			 ucs->rcvbuf, buffer_size,			 gigaset_read_int_callback,			 cs, endpoint->bInterval);//.........这里部分代码省略.........
开发者ID:AdrianHuang,项目名称:uclinux-robutest,代码行数:101,


示例7: ems_usb_start

/* * Start interface */static int ems_usb_start(struct ems_usb *dev){	struct net_device *netdev = dev->netdev;	int err, i;	dev->intr_in_buffer[0] = 0;	dev->free_slots = 15; /* initial size */	for (i = 0; i < MAX_RX_URBS; i++) {		struct urb *urb = NULL;		u8 *buf = NULL;		/* create a URB, and a buffer for it */		urb = usb_alloc_urb(0, GFP_KERNEL);		if (!urb) {			netdev_err(netdev, "No memory left for URBs/n");			err = -ENOMEM;			break;		}		buf = usb_alloc_coherent(dev->udev, RX_BUFFER_SIZE, GFP_KERNEL,					 &urb->transfer_dma);		if (!buf) {			netdev_err(netdev, "No memory left for USB buffer/n");			usb_free_urb(urb);			err = -ENOMEM;			break;		}		usb_fill_bulk_urb(urb, dev->udev, usb_rcvbulkpipe(dev->udev, 2),				  buf, RX_BUFFER_SIZE,				  ems_usb_read_bulk_callback, dev);		urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;		usb_anchor_urb(urb, &dev->rx_submitted);		err = usb_submit_urb(urb, GFP_KERNEL);		if (err) {			usb_unanchor_urb(urb);			usb_free_coherent(dev->udev, RX_BUFFER_SIZE, buf,					  urb->transfer_dma);			usb_free_urb(urb);			break;		}		/* Drop reference, USB core will take care of freeing it */		usb_free_urb(urb);	}	/* Did we submit any URBs */	if (i == 0) {		netdev_warn(netdev, "couldn't setup read URBs/n");		return err;	}	/* Warn if we've couldn't transmit all the URBs */	if (i < MAX_RX_URBS)		netdev_warn(netdev, "rx performance may be slow/n");	/* Setup and start interrupt URB */	usb_fill_int_urb(dev->intr_urb, dev->udev,			 usb_rcvintpipe(dev->udev, 1),			 dev->intr_in_buffer,			 INTR_IN_BUFFER_SIZE,			 ems_usb_read_interrupt_callback, dev, 1);	err = usb_submit_urb(dev->intr_urb, GFP_KERNEL);	if (err) {		netdev_warn(netdev, "intr URB submit failed: %d/n", err);		return err;	}	/* CPC-USB will transfer received message to host */	err = ems_usb_control_cmd(dev, CONTR_CAN_MESSAGE | CONTR_CONT_ON);	if (err)		goto failed;	/* CPC-USB will transfer CAN state changes to host */	err = ems_usb_control_cmd(dev, CONTR_CAN_STATE | CONTR_CONT_ON);	if (err)		goto failed;	/* CPC-USB will transfer bus errors to host */	err = ems_usb_control_cmd(dev, CONTR_BUS_ERROR | CONTR_CONT_ON);	if (err)		goto failed;	err = ems_usb_write_mode(dev, SJA1000_MOD_NORMAL);	if (err)		goto failed;	dev->can.state = CAN_STATE_ERROR_ACTIVE;	return 0;failed:	netdev_warn(netdev, "couldn't submit control: %d/n", err);//.........这里部分代码省略.........
开发者ID:3null,项目名称:linux,代码行数:101,


示例8: yurex_probe

static int yurex_probe(struct usb_interface *interface, const struct usb_device_id *id){	struct usb_yurex *dev;	struct usb_host_interface *iface_desc;	struct usb_endpoint_descriptor *endpoint;	int retval = -ENOMEM;	int i;	DEFINE_WAIT(wait);	/* allocate memory for our device state and initialize it */	dev = kzalloc(sizeof(*dev), GFP_KERNEL);	if (!dev)		goto error;	kref_init(&dev->kref);	mutex_init(&dev->io_mutex);	spin_lock_init(&dev->lock);	init_waitqueue_head(&dev->waitq);	dev->udev = usb_get_dev(interface_to_usbdev(interface));	dev->interface = interface;	/* set up the endpoint information */	iface_desc = interface->cur_altsetting;	for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {		endpoint = &iface_desc->endpoint[i].desc;		if (usb_endpoint_is_int_in(endpoint)) {			dev->int_in_endpointAddr = endpoint->bEndpointAddress;			break;		}	}	if (!dev->int_in_endpointAddr) {		retval = -ENODEV;		dev_err(&interface->dev, "Could not find endpoints/n");		goto error;	}	/* allocate control URB */	dev->cntl_urb = usb_alloc_urb(0, GFP_KERNEL);	if (!dev->cntl_urb)		goto error;	/* allocate buffer for control req */	dev->cntl_req = kmalloc(YUREX_BUF_SIZE, GFP_KERNEL);	if (!dev->cntl_req)		goto error;	/* allocate buffer for control msg */	dev->cntl_buffer = usb_alloc_coherent(dev->udev, YUREX_BUF_SIZE,					      GFP_KERNEL,					      &dev->cntl_urb->transfer_dma);	if (!dev->cntl_buffer) {		dev_err(&interface->dev, "Could not allocate cntl_buffer/n");		goto error;	}	/* configure control URB */	dev->cntl_req->bRequestType = USB_DIR_OUT | USB_TYPE_CLASS |				      USB_RECIP_INTERFACE;	dev->cntl_req->bRequest	= HID_REQ_SET_REPORT;	dev->cntl_req->wValue	= cpu_to_le16((HID_OUTPUT_REPORT + 1) << 8);	dev->cntl_req->wIndex	= cpu_to_le16(iface_desc->desc.bInterfaceNumber);	dev->cntl_req->wLength	= cpu_to_le16(YUREX_BUF_SIZE);	usb_fill_control_urb(dev->cntl_urb, dev->udev,			     usb_sndctrlpipe(dev->udev, 0),			     (void *)dev->cntl_req, dev->cntl_buffer,			     YUREX_BUF_SIZE, yurex_control_callback, dev);	dev->cntl_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;	/* allocate interrupt URB */	dev->urb = usb_alloc_urb(0, GFP_KERNEL);	if (!dev->urb)		goto error;	/* allocate buffer for interrupt in */	dev->int_buffer = usb_alloc_coherent(dev->udev, YUREX_BUF_SIZE,					GFP_KERNEL, &dev->urb->transfer_dma);	if (!dev->int_buffer) {		dev_err(&interface->dev, "Could not allocate int_buffer/n");		goto error;	}	/* configure interrupt URB */	usb_fill_int_urb(dev->urb, dev->udev,			 usb_rcvintpipe(dev->udev, dev->int_in_endpointAddr),			 dev->int_buffer, YUREX_BUF_SIZE, yurex_interrupt,			 dev, 1);	dev->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;	if (usb_submit_urb(dev->urb, GFP_KERNEL)) {		retval = -EIO;		dev_err(&interface->dev, "Could not submitting URB/n");		goto error;	}	/* save our data pointer in this interface device */	usb_set_intfdata(interface, dev);	dev->bbu = -1;//.........这里部分代码省略.........
开发者ID:AshishNamdev,项目名称:linux,代码行数:101,


示例9: symbol_int_callback

static void symbol_int_callback(struct urb *urb){	struct symbol_private *priv = urb->context;	unsigned char *data = urb->transfer_buffer;	struct usb_serial_port *port = priv->port;	int status = urb->status;	struct tty_struct *tty;	int result;	int data_length;	dbg("%s - port %d", __func__, port->number);	switch (status) {	case 0:		/* success */		break;	case -ECONNRESET:	case -ENOENT:	case -ESHUTDOWN:		/* this urb is terminated, clean up */		dbg("%s - urb shutting down with status: %d",		    __func__, status);		return;	default:		dbg("%s - nonzero urb status received: %d",		    __func__, status);		goto exit;	}	usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length,			      data);	if (urb->actual_length > 1) {		data_length = urb->actual_length - 1;		/*		 * Data from the device comes with a 1 byte header:		 *		 * <size of data>data...		 * 	This is real data to be sent to the tty layer		 * we pretty much just ignore the size and send everything		 * else to the tty layer.		 */		tty = tty_port_tty_get(&port->port);		if (tty) {			tty_insert_flip_string(tty, &data[1], data_length);			tty_flip_buffer_push(tty);			tty_kref_put(tty);		}	} else {		dev_dbg(&priv->udev->dev,			"Improper amount of data received from the device, "			"%d bytes", urb->actual_length);	}exit:	spin_lock(&priv->lock);	/* Continue trying to always read if we should */	if (!priv->throttled) {		usb_fill_int_urb(priv->int_urb, priv->udev,				 usb_rcvintpipe(priv->udev,				 		priv->int_address),				 priv->int_buffer, priv->buffer_size,				 symbol_int_callback, priv, priv->bInterval);		result = usb_submit_urb(priv->int_urb, GFP_ATOMIC);		if (result)			dev_err(&port->dev,			    "%s - failed resubmitting read urb, error %d/n",							__func__, result);	} else		priv->actually_throttled = true;	spin_unlock(&priv->lock);}
开发者ID:nos1609,项目名称:Chrono_Kernel-1,代码行数:74,


示例10: ar9170_usb_exec_cmd

static int ar9170_usb_exec_cmd(struct ar9170 *ar, enum ar9170_cmd cmd,			       unsigned int plen, void *payload,			       unsigned int outlen, void *out){	struct ar9170_usb *aru = (void *) ar;	struct urb *urb = NULL;	unsigned long flags;	int err = -ENOMEM;	if (unlikely(!IS_ACCEPTING_CMD(ar)))		return -EPERM;	if (WARN_ON(plen > AR9170_MAX_CMD_LEN - 4))		return -EINVAL;	urb = usb_alloc_urb(0, GFP_ATOMIC);	if (unlikely(!urb))		goto err_free;	ar->cmdbuf[0] = cpu_to_le32(plen);	ar->cmdbuf[0] |= cpu_to_le32(cmd << 8);	/* writing multiple regs fills this buffer already */	if (plen && payload != (u8 *)(&ar->cmdbuf[1]))		memcpy(&ar->cmdbuf[1], payload, plen);	spin_lock_irqsave(&aru->common.cmdlock, flags);	aru->readbuf = (u8 *)out;	aru->readlen = outlen;	spin_unlock_irqrestore(&aru->common.cmdlock, flags);	usb_fill_int_urb(urb, aru->udev,			 usb_sndbulkpipe(aru->udev, AR9170_EP_CMD),			 aru->common.cmdbuf, plen + 4,			 ar9170_usb_tx_urb_complete, NULL, 1);	usb_anchor_urb(urb, &aru->tx_submitted);	err = usb_submit_urb(urb, GFP_ATOMIC);	if (unlikely(err)) {		usb_unanchor_urb(urb);		usb_free_urb(urb);		goto err_unbuf;	}	usb_free_urb(urb);	err = wait_for_completion_timeout(&aru->cmd_wait, HZ);	if (err == 0) {		err = -ETIMEDOUT;		goto err_unbuf;	}	if (aru->readlen != outlen) {		err = -EMSGSIZE;		goto err_unbuf;	}	return 0;err_unbuf:	/* Maybe the device was removed in the second we were waiting? */	if (IS_STARTED(ar)) {		dev_err(&aru->udev->dev, "no command feedback "					 "received (%d)./n", err);		/* provide some maybe useful debug information */		print_hex_dump_bytes("ar9170 cmd: ", DUMP_PREFIX_NONE,				     aru->common.cmdbuf, plen + 4);		dump_stack();	}	/* invalidate to avoid completing the next prematurely */	spin_lock_irqsave(&aru->common.cmdlock, flags);	aru->readbuf = NULL;	aru->readlen = 0;	spin_unlock_irqrestore(&aru->common.cmdlock, flags);err_free:	return err;}
开发者ID:325116067,项目名称:semc-qsd8x50,代码行数:79,


示例11: symbol_startup

static int symbol_startup(struct usb_serial *serial){	struct symbol_private *priv;	struct usb_host_interface *intf;	int i;	int retval = -ENOMEM;	bool int_in_found = false;	/* create our private serial structure */	priv = kzalloc(sizeof(*priv), GFP_KERNEL);	if (priv == NULL) {		dev_err(&serial->dev->dev, "%s - Out of memory/n", __func__);		return -ENOMEM;	}	spin_lock_init(&priv->lock);	priv->serial = serial;	priv->port = serial->port[0];	priv->udev = serial->dev;	/* find our interrupt endpoint */	intf = serial->interface->altsetting;	for (i = 0; i < intf->desc.bNumEndpoints; ++i) {		struct usb_endpoint_descriptor *endpoint;		endpoint = &intf->endpoint[i].desc;		if (!usb_endpoint_is_int_in(endpoint))			continue;		priv->int_urb = usb_alloc_urb(0, GFP_KERNEL);		if (!priv->int_urb) {			dev_err(&priv->udev->dev, "out of memory/n");			goto error;		}		priv->buffer_size = le16_to_cpu(endpoint->wMaxPacketSize) * 2;		priv->int_buffer = kmalloc(priv->buffer_size, GFP_KERNEL);		if (!priv->int_buffer) {			dev_err(&priv->udev->dev, "out of memory/n");			goto error;		}		priv->int_address = endpoint->bEndpointAddress;		priv->bInterval = endpoint->bInterval;		/* set up our int urb */		usb_fill_int_urb(priv->int_urb, priv->udev,				 usb_rcvintpipe(priv->udev,				 		endpoint->bEndpointAddress),				 priv->int_buffer, priv->buffer_size,				 symbol_int_callback, priv, priv->bInterval);		int_in_found = true;		break;		}	if (!int_in_found) {		dev_err(&priv->udev->dev,			"Error - the proper endpoints were not found!/n");		goto error;	}	usb_set_serial_data(serial, priv);	return 0;error:	usb_free_urb(priv->int_urb);	kfree(priv->int_buffer);	kfree(priv);	return retval;}
开发者ID:nos1609,项目名称:Chrono_Kernel-1,代码行数:70,


示例12: appledisplay_probe

static int appledisplay_probe(struct usb_interface *iface,	const struct usb_device_id *id){	struct backlight_properties props;	struct appledisplay *pdata;	struct usb_device *udev = interface_to_usbdev(iface);	struct usb_host_interface *iface_desc;	struct usb_endpoint_descriptor *endpoint;	int int_in_endpointAddr = 0;	int i, retval = -ENOMEM, brightness;	char bl_name[20];	/* set up the endpoint information */	/* use only the first interrupt-in endpoint */	iface_desc = iface->cur_altsetting;	for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {		endpoint = &iface_desc->endpoint[i].desc;		if (!int_in_endpointAddr && usb_endpoint_is_int_in(endpoint)) {			/* we found an interrupt in endpoint */			int_in_endpointAddr = endpoint->bEndpointAddress;			break;		}	}	if (!int_in_endpointAddr) {		dev_err(&iface->dev, "Could not find int-in endpoint/n");		return -EIO;	}	/* allocate memory for our device state and initialize it */	pdata = kzalloc(sizeof(struct appledisplay), GFP_KERNEL);	if (!pdata) {		retval = -ENOMEM;		dev_err(&iface->dev, "Out of memory/n");		goto error;	}	pdata->udev = udev;	spin_lock_init(&pdata->lock);	INIT_DELAYED_WORK(&pdata->work, appledisplay_work);	/* Allocate buffer for control messages */	pdata->msgdata = kmalloc(ACD_MSG_BUFFER_LEN, GFP_KERNEL);	if (!pdata->msgdata) {		retval = -ENOMEM;		dev_err(&iface->dev,			"Allocating buffer for control messages failed/n");		goto error;	}	/* Allocate interrupt URB */	pdata->urb = usb_alloc_urb(0, GFP_KERNEL);	if (!pdata->urb) {		retval = -ENOMEM;		dev_err(&iface->dev, "Allocating URB failed/n");		goto error;	}	/* Allocate buffer for interrupt data */	pdata->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,		GFP_KERNEL, &pdata->urb->transfer_dma);	if (!pdata->urbdata) {		retval = -ENOMEM;		dev_err(&iface->dev, "Allocating URB buffer failed/n");		goto error;	}	/* Configure interrupt URB */	usb_fill_int_urb(pdata->urb, udev,		usb_rcvintpipe(udev, int_in_endpointAddr),		pdata->urbdata, ACD_URB_BUFFER_LEN, appledisplay_complete,		pdata, 1);	if (usb_submit_urb(pdata->urb, GFP_KERNEL)) {		retval = -EIO;		dev_err(&iface->dev, "Submitting URB failed/n");		goto error;	}	/* Register backlight device */	snprintf(bl_name, sizeof(bl_name), "appledisplay%d",		atomic_inc_return(&count_displays) - 1);	memset(&props, 0, sizeof(struct backlight_properties));	props.type = BACKLIGHT_RAW;	props.max_brightness = 0xff;	pdata->bd = backlight_device_register(bl_name, NULL, pdata,					      &appledisplay_bl_data, &props);	if (IS_ERR(pdata->bd)) {		dev_err(&iface->dev, "Backlight registration failed/n");		retval = PTR_ERR(pdata->bd);		goto error;	}	/* Try to get brightness */	brightness = appledisplay_bl_get_brightness(pdata->bd);	if (brightness < 0) {		retval = brightness;		dev_err(&iface->dev,			"Error while getting initial brightness: %d/n", retval);		goto error;//.........这里部分代码省略.........
开发者ID:303750856,项目名称:linux-3.1,代码行数:101,


示例13: usb_mouse_probe

//.........这里部分代码省略.........	usb_make_path(dev, mouse->phys, 64/*sizeof(mouse->phys)*/);	strlcat(mouse->phys, "/input0", 64/*sizeof(mouse->phys)*/);		//@ open input_dev_unregistered(input_dev, _, _, _, _, _, _);		input_dev->name = mouse->name;	input_dev->phys = mouse->phys;	//@ close usb_device(dev, _);	usb_to_input_id(dev, &input_dev->id);	//@ open usb_device(dev, _);	//TODO: input_dev->dev.parent = &intf->dev;	//TODO:	/*input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);	input_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |		BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE);	input_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);	input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_SIDE) |		BIT_MASK(BTN_EXTRA);	input_dev->relbit[0] |= BIT_MASK(REL_WHEEL);*/		//@ close input_dev_unregistered(input_dev, _, _, _, _, _, _);	input_set_drvdata(input_dev, mouse);		//@ open input_dev_unregistered(input_dev, _, _, _, _, _, _);	input_dev->open = usb_mouse_open;	input_dev->close = usb_mouse_close;	input_dev->event = usb_mouse_event_dummy; // not original code, HACK		//@ close usb_device(dev, _);	//@ close complete_t_ghost_param(usb_mouse_irq, usb_mouse_irq);	usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data,			 (maxp > 8 ? 8 : maxp),			 usb_mouse_irq, mouse, endpoint->bInterval);	mouse->irq->transfer_dma = mouse->data_dma;	mouse->irq->transfer_flags = mouse->irq->transfer_flags | URB_NO_TRANSFER_DMA_MAP;		/*@ urb_transfer_flags_add_no_transfer_dma_map(		mouse->irq, data_tmp, mouse->data_dma, 8, mouse->irq->transfer_flags); @*/	//@ assert mouse->irq |-> ?irq;	//@ close urb_struct(true, irq, _, data_tmp, mouse->data_dma, 8, true, usb_mouse_irq, mouse, 0);		//@ close input_open_t_ghost_param(usb_mouse_open, usb_mouse_open);	//@ close input_close_t_ghost_param(usb_mouse_close, usb_mouse_close);	//@ assume(is_input_event_t_no_pointer(usb_mouse_event_dummy) == true); // HACK HACK HACK, there are no events for this driver	//@ close input_event_t_ghost_param(usb_mouse_event_dummy, usb_mouse_event_dummy);		//@ close input_dev_unregistered(input_dev, _, _, _, _, _, _);		//@ input_ghost_register_device(input_dev, fracsize);	//@ close input_open_callback_link(usb_mouse_open)(usb_mouse_close, usb_mouse_event_dummy);	//@ close input_close_callback_link(usb_mouse_close)(usb_mouse_open, usb_mouse_event_dummy);	//@ close input_event_callback_link(usb_mouse_event_dummy)(usb_mouse_open, usb_mouse_close);	//@ assert input_dev_ghost_registered(_, _, _, _, _, _, _, _, ?input_register_result);	/*@	if (input_register_result == 0){		close userdef_input_drvdata(usb_mouse_open, usb_mouse_close, usb_mouse_event_dummy)(input_dev, false, mouse, fracsize);	}	@*/	//@ assume( true && (void*) 0 != ((void*) mouse->phys));	//@ assert chars(mouse->phys, 64, ?phys_text);	//@ close maybe_chars(1, mouse->phys, 64, phys_text);	error = input_register_device(mouse->dev);	if (error != 0) {		//@ open maybe_chars(1, _, _, _);		//@ open input_open_callback_link(usb_mouse_open)(usb_mouse_close, usb_mouse_event_dummy);		//@ open input_close_callback_link(usb_mouse_close)(usb_mouse_open, usb_mouse_event_dummy);		//@ open input_event_callback_link(usb_mouse_event_dummy)(usb_mouse_open, usb_mouse_close);		//@ open input_open_t_ghost_param(usb_mouse_open, usb_mouse_open);		//@ open input_close_t_ghost_param(usb_mouse_close, usb_mouse_close);		//@ open input_event_t_ghost_param(usb_mouse_event_dummy, usb_mouse_event_dummy);		goto fail3;	}	//@ close usb_interface_descriptor(&interface->desc, 1, _);	//@ close usb_host_endpoint(interface->endpoint);	//@ close [f2]usb_host_interface(interface);	//@ close usb_interface(usb_mouse_probe, usb_mouse_disconnect, intf, dev, originalData, false, fracsize);	//@ close userdef_usb_interface_data(usb_mouse_probe, usb_mouse_disconnect)(intf, dev, mouse, fracsize);	usb_set_intfdata(intf, mouse);	return 0;fail3:	   	//@ close urb_struct_maybe(true, irq, _, _, _, _, _, _, _, _);	usb_free_urb(mouse->irq);fail2:		usb_free_coherent(dev, 8, mouse->data, mouse->data_dma);	//@ open_struct(mouse);	//@ chars_to_uchars(mouse);fail1:		input_free_device(input_dev);	kfree(mouse);	//@ close [f3]usb_interface_descriptor(&interface->desc, bNumEndpoints, bInterfaceNumber);	//@ close usb_host_endpoint(interface->endpoint);	//@ close [f2]usb_host_interface(interface);	//@ close usb_interface(usb_mouse_probe, disconnect_cb, intf, _, originalData, false, fracsize);	return error;}
开发者ID:amintimany,项目名称:verifast,代码行数:101,


示例14: g13_probe

/* FIXME VP 27.12.2010: Really long method */static int g13_probe(struct usb_interface *intf, const struct usb_device_id *id) {    struct usb_device* device = interface_to_usbdev(intf);    struct usb_host_interface* cur_altsetting = intf->cur_altsetting;    struct usb_interface_descriptor desc = cur_altsetting->desc;    int usb_register_dev_result;     int i;    struct usb_host_endpoint endpoint;    struct usb_endpoint_descriptor endpoint_descriptor;    __u8 bEndpointAddress;    __u8 bmAttributes;    __u8 bInterval;    struct urb* urb;    unsigned int in_pipe;    __le16 wMaxPacketSize;    unsigned char* in_transfer_buffer;    unsigned int in_transfer_buffer_length;    int input_register_device_result;    g13_input_device = input_allocate_device();    if (g13_input_device == NULL) {        printk("G13: input_allocate_device failed./n");        return -1;    }    g13_input_device->name = "G13";    g13_input_device->evbit[0] = BIT_MASK(EV_KEY);    REGISTER_BUTTON(1);    REGISTER_BUTTON(2);    REGISTER_BUTTON(3);    REGISTER_BUTTON(4);    REGISTER_BUTTON(5);    REGISTER_BUTTON(6);    REGISTER_BUTTON(7);    REGISTER_BUTTON(8);    REGISTER_BUTTON(9);    REGISTER_BUTTON(10);    REGISTER_BUTTON(11);    REGISTER_BUTTON(12);    REGISTER_BUTTON(13);    REGISTER_BUTTON(14);    REGISTER_BUTTON(15);    REGISTER_BUTTON(16);    REGISTER_BUTTON(17);    REGISTER_BUTTON(18);    REGISTER_BUTTON(19);    REGISTER_BUTTON(20);    REGISTER_BUTTON(21);    REGISTER_BUTTON(22);    input_register_device_result = input_register_device(g13_input_device);    if (input_register_device_result) {        printk("G13: input_register_device failed: %d/n", input_register_device_result);        return input_register_device_result;    }    for (i = 0; i < desc.bNumEndpoints; i++) {        endpoint = cur_altsetting->endpoint[i];        endpoint_descriptor = endpoint.desc;        bEndpointAddress = endpoint_descriptor.bEndpointAddress;        bmAttributes = endpoint_descriptor.bmAttributes;        if (usb_endpoint_dir_in(&endpoint_descriptor)) {            /* We know that bmAttributes == USB_ENDPOINT_XFER_INT */            if (usb_endpoint_xfer_int(&endpoint_descriptor)) {                bInterval = endpoint_descriptor.bInterval;                wMaxPacketSize = endpoint_descriptor.wMaxPacketSize;                in_pipe = usb_rcvintpipe(device, bEndpointAddress);                in_transfer_buffer = kzalloc((sizeof (unsigned char)) * wMaxPacketSize, GFP_ATOMIC);                in_transfer_buffer_length = wMaxPacketSize;                 urb = usb_alloc_urb(0, GFP_ATOMIC);                usb_fill_int_urb(urb, device, in_pipe, in_transfer_buffer, in_transfer_buffer_length, &g13_urb_complete, NULL, bInterval);                usb_submit_urb(urb, GFP_ATOMIC);            }        } else if (usb_endpoint_dir_out(&endpoint_descriptor)) {            /* We know that bmAttributes == USB_ENDPOINT_XFER_INT */            if (usb_endpoint_xfer_int(&endpoint_descriptor)) {                bInterval = endpoint_descriptor.bInterval;                /* TODO VP 27.12.2010: Implement output */            }        } else {            printk("G13: Bug found! Endpoint not IN nor OUT./n");        }     }    usb_register_dev_result = usb_register_dev(intf, &g13_class);    if (usb_register_dev_result ) {        printk("G13: usb_register_dev failed: %d/n", usb_register_dev_result);        return usb_register_dev_result;    }    printk("G13: Device registration successful./n");    return 0;}
开发者ID:vpeurala,项目名称:g13driver,代码行数:87,


示例15: mdc800_usb_probe

/* * Callback to search the Mustek MDC800 on the USB Bus */static int mdc800_usb_probe (struct usb_interface *intf,			       const struct usb_device_id *id){	int i,j;	struct usb_host_interface *intf_desc;	struct usb_device *dev = interface_to_usbdev (intf);	int irq_interval=0;	int retval;	dbg ("(mdc800_usb_probe) called.");	if (mdc800->dev != 0)	{		warn ("only one Mustek MDC800 is supported.");		return -ENODEV;	}	if (dev->descriptor.bNumConfigurations != 1)	{		err ("probe fails -> wrong Number of Configuration");		return -ENODEV;	}	intf_desc = intf->cur_altsetting;	if (			( intf_desc->desc.bInterfaceClass != 0xff )		||	( intf_desc->desc.bInterfaceSubClass != 0 )		|| ( intf_desc->desc.bInterfaceProtocol != 0 )		|| ( intf_desc->desc.bNumEndpoints != 4)	)	{		err ("probe fails -> wrong Interface");		return -ENODEV;	}	/* Check the Endpoints */	for (i=0; i<4; i++)	{		mdc800->endpoint[i]=-1;		for (j=0; j<4; j++)		{			if (mdc800_endpoint_equals (&intf_desc->endpoint [j].desc,&mdc800_ed [i]))			{				mdc800->endpoint[i]=intf_desc->endpoint [j].desc.bEndpointAddress ;				if (i==1)				{					irq_interval=intf_desc->endpoint [j].desc.bInterval;				}				continue;			}		}		if (mdc800->endpoint[i] == -1)		{			err ("probe fails -> Wrong Endpoints.");			return -ENODEV;		}	}	info ("Found Mustek MDC800 on USB.");	down (&mdc800->io_lock);	retval = usb_register_dev(intf, &mdc800_class);	if (retval) {		err ("Not able to get a minor for this device.");		return -ENODEV;	}	mdc800->dev=dev;	mdc800->open=0;	/* Setup URB Structs */	usb_fill_int_urb (		mdc800->irq_urb,		mdc800->dev,		usb_rcvintpipe (mdc800->dev,mdc800->endpoint [1]),		mdc800->irq_urb_buffer,		8,		mdc800_usb_irq,		mdc800,		irq_interval	);	usb_fill_bulk_urb (		mdc800->write_urb,		mdc800->dev,		usb_sndbulkpipe (mdc800->dev, mdc800->endpoint[0]),		mdc800->write_urb_buffer,		8,		mdc800_usb_write_notify,		mdc800	);	usb_fill_bulk_urb (//.........这里部分代码省略.........
开发者ID:iPodLinux,项目名称:linux-2.6.7-ipod,代码行数:101,


示例16: acm_probe

//.........这里部分代码省略.........	acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL);	if (!acm->ctrlurb) {		dev_dbg(&intf->dev, "out of memory (ctrlurb kmalloc)/n");		goto alloc_fail5;	}	for (i = 0; i < num_rx_buf; i++) {		struct acm_ru *rcv = &(acm->ru[i]);		if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) {			dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)/n");			goto alloc_fail7;		}		rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;		rcv->instance = acm;	}	for (i = 0; i < num_rx_buf; i++) {		struct acm_rb *buf = &(acm->rb[i]);		if (!(buf->base = usb_buffer_alloc(acm->dev, readsize, GFP_KERNEL, &buf->dma))) {			dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)/n");			goto alloc_fail7;		}	}	acm->writeurb = usb_alloc_urb(0, GFP_KERNEL);	if (!acm->writeurb) {		dev_dbg(&intf->dev, "out of memory (writeurb kmalloc)/n");		goto alloc_fail7;	}	usb_set_intfdata (intf, acm);	i = device_create_file(&intf->dev, &dev_attr_bmCapabilities);	if (i < 0)		goto alloc_fail8;	if (cfd) { /* export the country data */		acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL);		if (!acm->country_codes)			goto skip_countries;		acm->country_code_size = cfd->bLength - 4;		memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, cfd->bLength - 4);		acm->country_rel_date = cfd->iCountryCodeRelDate;		i = device_create_file(&intf->dev, &dev_attr_wCountryCodes);		if (i < 0) {			kfree(acm->country_codes);			goto skip_countries;		}		i = device_create_file(&intf->dev, &dev_attr_iCountryCodeRelDate);		if (i < 0) {			kfree(acm->country_codes);			goto skip_countries;		}	}skip_countries:	usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress),			 acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval);	acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;	acm->ctrlurb->transfer_dma = acm->ctrl_dma;	usb_fill_bulk_urb(acm->writeurb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),			  NULL, acm->writesize, acm_write_bulk, acm);	acm->writeurb->transfer_flags |= URB_NO_FSBR | URB_NO_TRANSFER_DMA_MAP;	dev_info(&intf->dev, "ttyACM%d: USB ACM device/n", minor);	acm_set_control(acm, acm->ctrlout);	acm->line.dwDTERate = cpu_to_le32(9600);	acm->line.bDataBits = 8;	acm_set_line(acm, &acm->line);	usb_driver_claim_interface(&acm_driver, data_interface, acm);	usb_get_intf(control_interface);	tty_register_device(acm_tty_driver, minor, &control_interface->dev);	acm_table[minor] = acm;	return 0;alloc_fail8:	usb_free_urb(acm->writeurb);alloc_fail7:	for (i = 0; i < num_rx_buf; i++)		usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma);	for (i = 0; i < num_rx_buf; i++)		usb_free_urb(acm->ru[i].urb);	usb_free_urb(acm->ctrlurb);alloc_fail5:	acm_write_buffers_free(acm);alloc_fail4:	usb_buffer_free(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);alloc_fail2:	kfree(acm);alloc_fail:	return -ENOMEM;}
开发者ID:Tigrouzen,项目名称:k1099,代码行数:101,


示例17: usb_lmpcm_probe

static int usb_lmpcm_probe(struct usb_interface *intf, const struct usb_device_id *id) {	struct usb_device *dev = interface_to_usbdev(intf);	struct usb_host_interface *interface;	struct usb_endpoint_descriptor *endpoint;	lmpcm_t *mouse;	int pipe, maxp;	char *buf;	// Get mouse endpoint	interface = intf->cur_altsetting;	if ( interface->desc.bNumEndpoints != 1 ) return -ENODEV;	endpoint = &interface->endpoint[0].desc;	// Check endpoint	if (!(endpoint->bEndpointAddress & USB_DIR_IN))		return -ENODEV;	if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT)		return -ENODEV;	// Create endpoint pipe	pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);	maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));	// Create lmpcm object	if (!(mouse = lmpcm_new(dev)))		return -ENOMEM;	// Initialize input device	input_device_init(mouse->inputdev,intf,dev);	// Set device name	if (!(buf = kmalloc(63, GFP_KERNEL))) {		lmpcm_free(mouse);		return -ENOMEM;	}	if (dev->descriptor.iManufacturer &&		usb_string(dev, dev->descriptor.iManufacturer, buf, 63) > 0)			strcat(mouse->name, buf);	if (dev->descriptor.iProduct &&		usb_string(dev, dev->descriptor.iProduct, buf, 63) > 0)			sprintf(mouse->name, "%s %s", mouse->name, buf);	if (!strlen(mouse->name))		sprintf(mouse->name, "lmpcm_usb.c: Logitech MediaPlay Mouse on usb%04x:%04x",			mouse->inputdev->id.vendor, mouse->inputdev->id.product);	kfree(buf);	// Initialize interrupt transfer	usb_fill_int_urb(mouse->urb,dev,pipe,mouse->data,((maxp > 8)?8:maxp),usb_lmpcm_handle,mouse,endpoint->bInterval);	mouse->urb->transfer_dma = mouse->data_dma;	mouse->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;	// Register input device	input_register_device(mouse->inputdev);	printk(KERN_INFO "lmpcm_usb.c: Detected device: %s/n", mouse->name);	// Set usb handler interface data	usb_set_intfdata(intf,mouse);	return 0;}
开发者ID:aheadley,项目名称:lmpcm_usb,代码行数:90,


示例18: wacom_probe

static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id){	struct usb_device *dev = interface_to_usbdev(intf);	struct usb_endpoint_descriptor *endpoint;	struct wacom *wacom;	struct wacom_wac *wacom_wac;	struct wacom_features *features;	struct input_dev *input_dev;	int error;	if (!id->driver_info)		return -EINVAL;	wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);	wacom_wac = kzalloc(sizeof(struct wacom_wac), GFP_KERNEL);	input_dev = input_allocate_device();	if (!wacom || !input_dev || !wacom_wac) {		error = -ENOMEM;		goto fail1;	}	wacom_wac->features = *((struct wacom_features *)id->driver_info);	features = &wacom_wac->features;	if (features->pktlen > WACOM_PKGLEN_MAX) {		error = -EINVAL;		goto fail1;	}	wacom_wac->data = usb_buffer_alloc(dev, WACOM_PKGLEN_MAX,					   GFP_KERNEL, &wacom->data_dma);	if (!wacom_wac->data) {		error = -ENOMEM;		goto fail1;	}	wacom->irq = usb_alloc_urb(0, GFP_KERNEL);	if (!wacom->irq) {		error = -ENOMEM;		goto fail2;	}	wacom->usbdev = dev;	wacom->dev = input_dev;	wacom->intf = intf;	mutex_init(&wacom->lock);	usb_make_path(dev, wacom->phys, sizeof(wacom->phys));	strlcat(wacom->phys, "/input0", sizeof(wacom->phys));	usb_to_input_id(dev, &input_dev->id);	input_dev->dev.parent = &intf->dev;	input_set_drvdata(input_dev, wacom);	input_dev->open = wacom_open;	input_dev->close = wacom_close;	endpoint = &intf->cur_altsetting->endpoint[0].desc;	/* Retrieve the physical and logical size for OEM devices */	error = wacom_retrieve_hid_descriptor(intf, features);	if (error)		goto fail2;	strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));	if (features->type == TABLETPC || features->type == TABLETPC2FG) {		/* Append the device type to the name */		strlcat(wacom_wac->name,			features->device_type == BTN_TOOL_PEN ?				" Pen" : " Finger",			sizeof(wacom_wac->name));	}	input_dev->name = wacom_wac->name;	wacom->wacom_wac = wacom_wac;	input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);	input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOUCH);	input_set_abs_params(input_dev, ABS_X, 0, features->x_max, 4, 0);	input_set_abs_params(input_dev, ABS_Y, 0, features->y_max, 4, 0);	input_set_abs_params(input_dev, ABS_PRESSURE, 0, features->pressure_max, 0, 0);	input_dev->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC);	wacom_init_input_dev(input_dev, wacom_wac);	usb_fill_int_urb(wacom->irq, dev,			 usb_rcvintpipe(dev, endpoint->bEndpointAddress),			 wacom_wac->data, features->pktlen,			 wacom_sys_irq, wacom, endpoint->bInterval);	wacom->irq->transfer_dma = wacom->data_dma;	wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;	error = input_register_device(wacom->dev);	if (error)		goto fail3;	/* Note that if query fails it is not a hard failure */	wacom_query_tablet_data(intf, features);//.........这里部分代码省略.........
开发者ID:A2109devs,项目名称:lenovo_a2109a_kernel,代码行数:101,


示例19: xpad_probe

//.........这里部分代码省略.........		for (i = 0; xpad_btn[i] >= 0; i++)			__set_bit(xpad_btn[i], input_dev->keybit);	}	if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {		for (i = 0; xpad_btn_pad[i] >= 0; i++)			__set_bit(xpad_btn_pad[i], input_dev->keybit);	} else {		for (i = 0; xpad_abs_pad[i] >= 0; i++)		    xpad_set_up_abs(input_dev, xpad_abs_pad[i]);	}	if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {		for (i = 0; xpad_btn_triggers[i] >= 0; i++)			__set_bit(xpad_btn_triggers[i], input_dev->keybit);	} else {		for (i = 0; xpad_abs_triggers[i] >= 0; i++)			xpad_set_up_abs(input_dev, xpad_abs_triggers[i]);	}	error = xpad_init_output(intf, xpad);	if (error)		goto fail3;	error = xpad_init_ff(xpad);	if (error)		goto fail4;	error = xpad_led_probe(xpad);	if (error)		goto fail5;	ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;	usb_fill_int_urb(xpad->irq_in, udev,			 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),			 xpad->idata, XPAD_PKT_LEN, xpad_irq_in,			 xpad, ep_irq_in->bInterval);	xpad->irq_in->transfer_dma = xpad->idata_dma;	xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;	error = input_register_device(xpad->dev);	if (error)		goto fail6;	usb_set_intfdata(intf, xpad);	if (xpad->xtype == XTYPE_XBOX360W) {		/*                                                                                */		xpad->bulk_out = usb_alloc_urb(0, GFP_KERNEL);		if (!xpad->bulk_out) {			error = -ENOMEM;			goto fail7;		}		xpad->bdata = kzalloc(XPAD_PKT_LEN, GFP_KERNEL);		if (!xpad->bdata) {			error = -ENOMEM;			goto fail8;		}		xpad->bdata[2] = 0x08;		switch (intf->cur_altsetting->desc.bInterfaceNumber) {		case 0:
开发者ID:romanbb,项目名称:android_kernel_lge_d851,代码行数:67,


示例20: acm_rx_tasklet

static void acm_rx_tasklet(unsigned long _acm){	struct acm *acm = (void *)_acm;	struct acm_rb *buf;	struct tty_struct *tty;	struct acm_ru *rcv;	unsigned long flags;	unsigned char throttled;	dbg("Entering acm_rx_tasklet");	if (!ACM_READY(acm)) {		dbg("acm_rx_tasklet: ACM not ready");		return;	}	spin_lock_irqsave(&acm->throttle_lock, flags);	throttled = acm->throttle;	spin_unlock_irqrestore(&acm->throttle_lock, flags);	if (throttled) {		dbg("acm_rx_tasklet: throttled");		return;	}	tty = tty_port_tty_get(&acm->port);next_buffer:	spin_lock_irqsave(&acm->read_lock, flags);	if (list_empty(&acm->filled_read_bufs)) {		spin_unlock_irqrestore(&acm->read_lock, flags);		goto urbs;	}	buf = list_entry(acm->filled_read_bufs.next,			 struct acm_rb, list);	list_del(&buf->list);	spin_unlock_irqrestore(&acm->read_lock, flags);	dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size);	if (tty) {		spin_lock_irqsave(&acm->throttle_lock, flags);		throttled = acm->throttle;		spin_unlock_irqrestore(&acm->throttle_lock, flags);		if (!throttled) {			tty_buffer_request_room(tty, buf->size);			tty_insert_flip_string(tty, buf->base, buf->size);			tty_flip_buffer_push(tty);		} else {			tty_kref_put(tty);			dbg("Throttling noticed");			spin_lock_irqsave(&acm->read_lock, flags);			list_add(&buf->list, &acm->filled_read_bufs);			spin_unlock_irqrestore(&acm->read_lock, flags);			return;		}	}	spin_lock_irqsave(&acm->read_lock, flags);	list_add(&buf->list, &acm->spare_read_bufs);	spin_unlock_irqrestore(&acm->read_lock, flags);	goto next_buffer;urbs:	tty_kref_put(tty);	while (!list_empty(&acm->spare_read_bufs)) {		spin_lock_irqsave(&acm->read_lock, flags);		if (list_empty(&acm->spare_read_urbs)) {			acm->processing = 0;			spin_unlock_irqrestore(&acm->read_lock, flags);			return;		}		rcv = list_entry(acm->spare_read_urbs.next,				 struct acm_ru, list);		list_del(&rcv->list);		spin_unlock_irqrestore(&acm->read_lock, flags);		buf = list_entry(acm->spare_read_bufs.next,				 struct acm_rb, list);		list_del(&buf->list);		rcv->buffer = buf;		if (acm->is_int_ep)			usb_fill_int_urb(rcv->urb, acm->dev,					 acm->rx_endpoint,					 buf->base,					 acm->readsize,					 acm_read_bulk, rcv, acm->bInterval);		else			usb_fill_bulk_urb(rcv->urb, acm->dev,					  acm->rx_endpoint,					  buf->base,					  acm->readsize,					  acm_read_bulk, rcv);		rcv->urb->transfer_dma = buf->dma;		rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;		/* This shouldn't kill the driver as unsuccessful URBs are		   returned to the free-urbs-pool and resubmited ASAP *///.........这里部分代码省略.........
开发者ID:mikeberkelaar,项目名称:grhardened,代码行数:101,


示例21: ld_usb_open

/** *	ld_usb_open */static int ld_usb_open(struct inode *inode, struct file *file){	struct ld_usb *dev;	int subminor;	int retval;	struct usb_interface *interface;	nonseekable_open(inode, file);	subminor = iminor(inode);	interface = usb_find_interface(&ld_usb_driver, subminor);	if (!interface) {		printk(KERN_ERR "%s - error, can't find device for minor %d/n",		       __func__, subminor);		return -ENODEV;	}	dev = usb_get_intfdata(interface);	if (!dev)		return -ENODEV;	/* lock this device */	if (mutex_lock_interruptible(&dev->mutex))		return -ERESTARTSYS;	/* allow opening only once */	if (dev->open_count) {		retval = -EBUSY;		goto unlock_exit;	}	dev->open_count = 1;	/* initialize in direction */	dev->ring_head = 0;	dev->ring_tail = 0;	dev->buffer_overflow = 0;	usb_fill_int_urb(dev->interrupt_in_urb,			 interface_to_usbdev(interface),			 usb_rcvintpipe(interface_to_usbdev(interface),					dev->interrupt_in_endpoint->bEndpointAddress),			 dev->interrupt_in_buffer,			 dev->interrupt_in_endpoint_size,			 ld_usb_interrupt_in_callback,			 dev,			 dev->interrupt_in_interval);	dev->interrupt_in_running = 1;	dev->interrupt_in_done = 0;	retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);	if (retval) {		dev_err(&interface->dev, "Couldn't submit interrupt_in_urb %d/n", retval);		dev->interrupt_in_running = 0;		dev->open_count = 0;		goto unlock_exit;	}	/* save device in the file's private structure */	file->private_data = dev;unlock_exit:	mutex_unlock(&dev->mutex);	return retval;}
开发者ID:krzk,项目名称:linux,代码行数:70,


示例22: adu_read

static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,			loff_t *ppos){	struct adu_device *dev;	size_t bytes_read = 0;	size_t bytes_to_read = count;	int i;	int retval = 0;	int timeout = 0;	int should_submit = 0;	unsigned long flags;	DECLARE_WAITQUEUE(wait, current);	dbg(2," %s : enter, count = %Zd, file=%p", __FUNCTION__, count, file);	dev = file->private_data;	dbg(2," %s : dev=%p", __FUNCTION__, dev);	/* lock this object */	if (mutex_lock_interruptible(&dev->mtx))		return -ERESTARTSYS;	/* verify that the device wasn't unplugged */	if (dev->udev == NULL || dev->minor == 0) {		retval = -ENODEV;		err("No device or device unplugged %d", retval);		goto exit;	}	/* verify that some data was requested */	if (count == 0) {		dbg(1," %s : read request of 0 bytes", __FUNCTION__);		goto exit;	}	timeout = COMMAND_TIMEOUT;	dbg(2," %s : about to start looping", __FUNCTION__);	while (bytes_to_read) {		int data_in_secondary = dev->secondary_tail - dev->secondary_head;		dbg(2," %s : while, data_in_secondary=%d, status=%d",		    __FUNCTION__, data_in_secondary,		    dev->interrupt_in_urb->status);		if (data_in_secondary) {			/* drain secondary buffer */			int amount = bytes_to_read < data_in_secondary ? bytes_to_read : data_in_secondary;			i = copy_to_user(buffer, dev->read_buffer_secondary+dev->secondary_head, amount);			if (i < 0) {				retval = -EFAULT;				goto exit;			}			dev->secondary_head += (amount - i);			bytes_read += (amount - i);			bytes_to_read -= (amount - i);			if (i) {				retval = bytes_read ? bytes_read : -EFAULT;				goto exit;			}		} else {			/* we check the primary buffer */			spin_lock_irqsave (&dev->buflock, flags);			if (dev->read_buffer_length) {				/* we secure access to the primary */				char *tmp;				dbg(2," %s : swap, read_buffer_length = %d",				    __FUNCTION__, dev->read_buffer_length);				tmp = dev->read_buffer_secondary;				dev->read_buffer_secondary = dev->read_buffer_primary;				dev->read_buffer_primary = tmp;				dev->secondary_head = 0;				dev->secondary_tail = dev->read_buffer_length;				dev->read_buffer_length = 0;				spin_unlock_irqrestore(&dev->buflock, flags);				/* we have a free buffer so use it */				should_submit = 1;			} else {				/* even the primary was empty - we may need to do IO */				if (dev->interrupt_in_urb->status == -EINPROGRESS) {					/* somebody is doing IO */					spin_unlock_irqrestore(&dev->buflock, flags);					dbg(2," %s : submitted already", __FUNCTION__);				} else {					/* we must initiate input */					dbg(2," %s : initiate input", __FUNCTION__);					dev->read_urb_finished = 0;					usb_fill_int_urb(dev->interrupt_in_urb,dev->udev,							 usb_rcvintpipe(dev->udev,							 		dev->interrupt_in_endpoint->bEndpointAddress),							 dev->interrupt_in_buffer,							 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize),							 adu_interrupt_in_callback,							 dev,							 dev->interrupt_in_endpoint->bInterval);					retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC);					if (!retval) {						spin_unlock_irqrestore(&dev->buflock, flags);						dbg(2," %s : submitted OK", __FUNCTION__);					} else {						if (retval == -ENOMEM) {							retval = bytes_read ? bytes_read : -ENOMEM;//.........这里部分代码省略.........
开发者ID:3sOx,项目名称:asuswrt-merlin,代码行数:101,


示例23: ld_usb_write

/** *	ld_usb_write */static ssize_t ld_usb_write(struct file *file, const char __user *buffer,			    size_t count, loff_t *ppos){	struct ld_usb *dev;	size_t bytes_to_write;	int retval = 0;	dev = file->private_data;	/* verify that we actually have some data to write */	if (count == 0)		goto exit;	/* lock this object */	if (mutex_lock_interruptible(&dev->mutex)) {		retval = -ERESTARTSYS;		goto exit;	}	/* verify that the device wasn't unplugged */	if (dev->intf == NULL) {		retval = -ENODEV;		printk(KERN_ERR "ldusb: No device or device unplugged %d/n", retval);		goto unlock_exit;	}	/* wait until previous transfer is finished */	if (dev->interrupt_out_busy) {		if (file->f_flags & O_NONBLOCK) {			retval = -EAGAIN;			goto unlock_exit;		}		retval = wait_event_interruptible(dev->write_wait, !dev->interrupt_out_busy);		if (retval < 0) {			goto unlock_exit;		}	}	/* write the data into interrupt_out_buffer from userspace */	bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size);	if (bytes_to_write < count)		dev_warn(&dev->intf->dev, "Write buffer overflow, %zd bytes dropped/n", count-bytes_to_write);	dev_dbg(&dev->intf->dev, "%s: count = %zd, bytes_to_write = %zd/n",		__func__, count, bytes_to_write);	if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {		retval = -EFAULT;		goto unlock_exit;	}	if (dev->interrupt_out_endpoint == NULL) {		/* try HID_REQ_SET_REPORT=9 on control_endpoint instead of interrupt_out_endpoint */		retval = usb_control_msg(interface_to_usbdev(dev->intf),					 usb_sndctrlpipe(interface_to_usbdev(dev->intf), 0),					 9,					 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,					 1 << 8, 0,					 dev->interrupt_out_buffer,					 bytes_to_write,					 USB_CTRL_SET_TIMEOUT * HZ);		if (retval < 0)			dev_err(&dev->intf->dev,				"Couldn't submit HID_REQ_SET_REPORT %d/n",				retval);		goto unlock_exit;	}	/* send off the urb */	usb_fill_int_urb(dev->interrupt_out_urb,			 interface_to_usbdev(dev->intf),			 usb_sndintpipe(interface_to_usbdev(dev->intf),					dev->interrupt_out_endpoint->bEndpointAddress),			 dev->interrupt_out_buffer,			 bytes_to_write,			 ld_usb_interrupt_out_callback,			 dev,			 dev->interrupt_out_interval);	dev->interrupt_out_busy = 1;	wmb();	retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL);	if (retval) {		dev->interrupt_out_busy = 0;		dev_err(&dev->intf->dev,			"Couldn't submit interrupt_out_urb %d/n", retval);		goto unlock_exit;	}	retval = bytes_to_write;unlock_exit:	/* unlock the device */	mutex_unlock(&dev->mutex);exit:	return retval;}
开发者ID:krzk,项目名称:linux,代码行数:100,


示例24: st5481_setup_usb

int st5481_setup_usb(struct st5481_adapter *adapter){	struct usb_device *dev = adapter->usb_dev;	struct st5481_ctrl *ctrl = &adapter->ctrl;	struct st5481_intr *intr = &adapter->intr;	struct usb_interface *intf;	struct usb_host_interface *altsetting = NULL;	struct usb_host_endpoint *endpoint;	int status;	struct urb *urb;	u8 *buf;	DBG(2, "");	if ((status = usb_reset_configuration(dev)) < 0) {		WARNING("reset_configuration failed,status=%d", status);		return status;	}	intf = usb_ifnum_to_if(dev, 0);	if (intf)		altsetting = usb_altnum_to_altsetting(intf, 3);	if (!altsetting)		return -ENXIO;	// Check if the config is sane	if (altsetting->desc.bNumEndpoints != 7) {		WARNING("expecting 7 got %d endpoints!", altsetting->desc.bNumEndpoints);		return -EINVAL;	}	// The descriptor is wrong for some early samples of the ST5481 chip	altsetting->endpoint[3].desc.wMaxPacketSize = cpu_to_le16(32);	altsetting->endpoint[4].desc.wMaxPacketSize = cpu_to_le16(32);	// Use alternative setting 3 on interface 0 to have 2B+D	if ((status = usb_set_interface(dev, 0, 3)) < 0) {		WARNING("usb_set_interface failed,status=%d", status);		return status;	}	// Allocate URB for control endpoint	urb = usb_alloc_urb(0, GFP_KERNEL);	if (!urb) {		return -ENOMEM;	}	ctrl->urb = urb;	// Fill the control URB	usb_fill_control_urb(urb, dev,			     usb_sndctrlpipe(dev, 0),			     NULL, NULL, 0, usb_ctrl_complete, adapter);	fifo_init(&ctrl->msg_fifo.f, ARRAY_SIZE(ctrl->msg_fifo.data));	// Allocate URBs and buffers for interrupt endpoint	urb = usb_alloc_urb(0, GFP_KERNEL);	if (!urb) {		goto err1;	}	intr->urb = urb;	buf = kmalloc(INT_PKT_SIZE, GFP_KERNEL);	if (!buf) {		goto err2;	}	endpoint = &altsetting->endpoint[EP_INT-1];	// Fill the interrupt URB	usb_fill_int_urb(urb, dev,			 usb_rcvintpipe(dev, endpoint->desc.bEndpointAddress),			 buf, INT_PKT_SIZE,			 usb_int_complete, adapter,			 endpoint->desc.bInterval);	return 0;err2:	usb_free_urb(intr->urb);	intr->urb = NULL;err1:	usb_free_urb(ctrl->urb);	ctrl->urb = NULL;	return -ENOMEM;}
开发者ID:AlexShiLucky,项目名称:linux,代码行数:87,


示例25: metrousb_read_int_callback

static void metrousb_read_int_callback(struct urb *urb){	struct usb_serial_port *port = urb->context;	struct metrousb_private *metro_priv = usb_get_serial_port_data(port);	struct tty_struct *tty;	unsigned char *data = urb->transfer_buffer;	int throttled = 0;	int result = 0;	unsigned long flags = 0;	dev_dbg(&port->dev, "%s/n", __func__);	switch (urb->status) {	case 0:		/* Success status, read from the port. */		break;	case -ECONNRESET:	case -ENOENT:	case -ESHUTDOWN:		/* urb has been terminated. */		dev_dbg(&port->dev,			"%s - urb shutting down, error code=%d/n",			__func__, urb->status);		return;	default:		dev_dbg(&port->dev,			"%s - non-zero urb received, error code=%d/n",			__func__, urb->status);		goto exit;	}	/* Set the data read from the usb port into the serial port buffer. */	tty = tty_port_tty_get(&port->port);	if (!tty) {		dev_err(&port->dev, "%s - bad tty pointer - exiting/n",			__func__);		return;	}	if (tty && urb->actual_length) {		/* Loop through the data copying each byte to the tty layer. */		tty_insert_flip_string(tty, data, urb->actual_length);		/* Force the data to the tty layer. */		tty_flip_buffer_push(tty);	}	tty_kref_put(tty);	/* Set any port variables. */	spin_lock_irqsave(&metro_priv->lock, flags);	throttled = metro_priv->throttled;	spin_unlock_irqrestore(&metro_priv->lock, flags);	/* Continue trying to read if set. */	if (!throttled) {		usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,				 usb_rcvintpipe(port->serial->dev, port->interrupt_in_endpointAddress),				 port->interrupt_in_urb->transfer_buffer,				 port->interrupt_in_urb->transfer_buffer_length,				 metrousb_read_int_callback, port, 1);		result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);		if (result)			dev_err(&port->dev,				"%s - failed submitting interrupt in urb, error code=%d/n",				__func__, result);	}	return;exit:	/* Try to resubmit the urb. */	result = usb_submit_urb(urb, GFP_ATOMIC);	if (result)		dev_err(&port->dev,			"%s - failed submitting interrupt in urb, error code=%d/n",			__func__, result);}
开发者ID:aywq2008,项目名称:omniplay,代码行数:79,


示例26: kobil_write

static int kobil_write (struct usb_serial_port *port, 			const unsigned char *buf, int count){	int length = 0;	int result = 0;	int todo = 0;	struct kobil_private * priv;	if (count == 0) {		dbg("%s - port %d write request of 0 bytes", __FUNCTION__, port->number);		return 0;	}	priv = usb_get_serial_port_data(port);	if (count > (KOBIL_BUF_LENGTH - priv->filled)) {		dbg("%s - port %d Error: write request bigger than buffer size", __FUNCTION__, port->number);		return -ENOMEM;	}	// Copy data to buffer	memcpy (priv->buf + priv->filled, buf, count);	usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, priv->buf + priv->filled);	priv->filled = priv->filled + count;	// only send complete block. TWIN, KAAN SIM and adapter K use the same protocol.	if ( ((priv->device_type != KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 2) && (priv->filled >= (priv->buf[1] + 3))) || 	     ((priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) && (priv->filled > 3) && (priv->filled >= (priv->buf[2] + 4))) ) {				// stop reading (except TWIN and KAAN SIM)		if ( (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) || (priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) )			usb_kill_urb(port->interrupt_in_urb);		todo = priv->filled - priv->cur_pos;		while(todo > 0) {			// max 8 byte in one urb (endpoint size)			length = (todo < 8) ? todo : 8;			// copy data to transfer buffer			memcpy(port->write_urb->transfer_buffer, priv->buf + priv->cur_pos, length );			usb_fill_int_urb( port->write_urb,					  port->serial->dev,					  usb_sndintpipe(port->serial->dev, priv->write_int_endpoint_address),					  port->write_urb->transfer_buffer,					  length,					  kobil_write_callback,					  port,					  8				);			priv->cur_pos = priv->cur_pos + length;			result = usb_submit_urb( port->write_urb, GFP_NOIO );			dbg("%s - port %d Send write URB returns: %i", __FUNCTION__, port->number, result);			todo = priv->filled - priv->cur_pos;			if (todo > 0) {				msleep(24);			}		} // end while				priv->filled = 0;		priv->cur_pos = 0;		// someone sets the dev to 0 if the close method has been called		port->interrupt_in_urb->dev = port->serial->dev;				// start reading (except TWIN and KAAN SIM)		if ( (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID) || (priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) ) {			// someone sets the dev to 0 if the close method has been called			port->interrupt_in_urb->dev = port->serial->dev;						result = usb_submit_urb( port->interrupt_in_urb, GFP_NOIO ); 			dbg("%s - port %d Send read URB returns: %i", __FUNCTION__, port->number, result);		}	}	return count;}
开发者ID:3sOx,项目名称:asuswrt-merlin,代码行数:81,


示例27: xpad_probe

static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id){	struct usb_device *udev = interface_to_usbdev(intf);	struct usb_xpad *xpad;	struct input_dev *input_dev;	struct usb_endpoint_descriptor *ep_irq_in;	int i;	int error = -ENOMEM;	for (i = 0; xpad_device[i].idVendor; i++) {		if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) &&		    (le16_to_cpu(udev->descriptor.idProduct) == xpad_device[i].idProduct))			break;	}	xpad = kzalloc(sizeof(struct usb_xpad), GFP_KERNEL);	input_dev = input_allocate_device();	if (!xpad || !input_dev)		goto fail1;	xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN,				       GFP_KERNEL, &xpad->idata_dma);	if (!xpad->idata)		goto fail1;	xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL);	if (!xpad->irq_in)		goto fail2;	xpad->udev = udev;	xpad->dpad_mapping = xpad_device[i].dpad_mapping;	xpad->xtype = xpad_device[i].xtype;	if (xpad->dpad_mapping == MAP_DPAD_UNKNOWN)		xpad->dpad_mapping = !dpad_to_buttons;	if (xpad->xtype == XTYPE_UNKNOWN) {		if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) {			if (intf->cur_altsetting->desc.bInterfaceProtocol == 129)				xpad->xtype = XTYPE_XBOX360W;			else				xpad->xtype = XTYPE_XBOX360;		} else			xpad->xtype = XTYPE_XBOX;	}	xpad->dev = input_dev;	usb_make_path(udev, xpad->phys, sizeof(xpad->phys));	strlcat(xpad->phys, "/input0", sizeof(xpad->phys));	input_dev->name = xpad_device[i].name;	input_dev->phys = xpad->phys;	usb_to_input_id(udev, &input_dev->id);	input_dev->dev.parent = &intf->dev;	input_set_drvdata(input_dev, xpad);	input_dev->open = xpad_open;	input_dev->close = xpad_close;	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);	/* set up buttons */	for (i = 0; xpad_common_btn[i] >= 0; i++)		set_bit(xpad_common_btn[i], input_dev->keybit);	if ((xpad->xtype == XTYPE_XBOX360) || (xpad->xtype == XTYPE_XBOX360W))		for (i = 0; xpad360_btn[i] >= 0; i++)			set_bit(xpad360_btn[i], input_dev->keybit);	else		for (i = 0; xpad_btn[i] >= 0; i++)			set_bit(xpad_btn[i], input_dev->keybit);	if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS)		for (i = 0; xpad_btn_pad[i] >= 0; i++)			set_bit(xpad_btn_pad[i], input_dev->keybit);	/* set up axes */	for (i = 0; xpad_abs[i] >= 0; i++)		xpad_set_up_abs(input_dev, xpad_abs[i]);	if (xpad->dpad_mapping == MAP_DPAD_TO_AXES)		for (i = 0; xpad_abs_pad[i] >= 0; i++)		    xpad_set_up_abs(input_dev, xpad_abs_pad[i]);	error = xpad_init_output(intf, xpad);	if (error)		goto fail2;	error = xpad_init_ff(xpad);	if (error)		goto fail3;	error = xpad_led_probe(xpad);	if (error)		goto fail3;	ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;	usb_fill_int_urb(xpad->irq_in, udev,			 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),			 xpad->idata, XPAD_PKT_LEN, xpad_irq_in,			 xpad, ep_irq_in->bInterval);	xpad->irq_in->transfer_dma = xpad->idata_dma;	xpad->irq_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;	error = input_register_device(xpad->dev);//.........这里部分代码省略.........
开发者ID:maraz,项目名称:linux-2.6,代码行数:101,


示例28: acm_probe

//.........这里部分代码省略.........	if (acm_write_buffers_alloc(acm) < 0) {		dev_err(&intf->dev, "out of memory (write buffer alloc)/n");		goto alloc_fail4;	}	acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL);	if (!acm->ctrlurb) {		dev_err(&intf->dev, "out of memory (ctrlurb kmalloc)/n");		goto alloc_fail5;	}	for (i = 0; i < num_rx_buf; i++) {		struct acm_rb *rb = &(acm->read_buffers[i]);		struct urb *urb;		rb->base = usb_alloc_coherent(acm->dev, readsize, GFP_KERNEL,								&rb->dma);		if (!rb->base) {			dev_err(&intf->dev, "out of memory "					"(read bufs usb_alloc_coherent)/n");			goto alloc_fail6;		}		rb->index = i;		rb->instance = acm;		urb = usb_alloc_urb(0, GFP_KERNEL);		if (!urb) {			dev_err(&intf->dev,				"out of memory (read urbs usb_alloc_urb)/n");			goto alloc_fail6;		}		urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;		urb->transfer_dma = rb->dma;		if (acm->is_int_ep) {			usb_fill_int_urb(urb, acm->dev,					 acm->rx_endpoint,					 rb->base,					 acm->readsize,					 acm_read_bulk_callback, rb,					 acm->bInterval);		} else {			usb_fill_bulk_urb(urb, acm->dev,					  acm->rx_endpoint,					  rb->base,					  acm->readsize,					  acm_read_bulk_callback, rb);		}		acm->read_urbs[i] = urb;		__set_bit(i, &acm->read_urbs_free);	}	for (i = 0; i < ACM_NW; i++) {		struct acm_wb *snd = &(acm->wb[i]);		snd->urb = usb_alloc_urb(0, GFP_KERNEL);		if (snd->urb == NULL) {			dev_err(&intf->dev,				"out of memory (write urbs usb_alloc_urb)/n");			goto alloc_fail7;		}		if (usb_endpoint_xfer_int(epwrite))			usb_fill_int_urb(snd->urb, usb_dev,				usb_sndintpipe(usb_dev, epwrite->bEndpointAddress),				NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval);		else			usb_fill_bulk_urb(snd->urb, usb_dev,
开发者ID:Emineminero,项目名称:DORIMANX_LG_STOCK_LP_KERNEL,代码行数:67,


示例29: adu_open

static int adu_open(struct inode *inode, struct file *file){	struct adu_device *dev = NULL;	struct usb_interface *interface;	int subminor;	int retval;	dbg(2,"%s : enter", __func__);	subminor = iminor(inode);	if ((retval = mutex_lock_interruptible(&adutux_mutex))) {		dbg(2, "%s : mutex lock failed", __func__);		goto exit_no_lock;	}	interface = usb_find_interface(&adu_driver, subminor);	if (!interface) {		printk(KERN_ERR "adutux: %s - error, can't find device for "		       "minor %d/n", __func__, subminor);		retval = -ENODEV;		goto exit_no_device;	}	dev = usb_get_intfdata(interface);	if (!dev || !dev->udev) {		retval = -ENODEV;		goto exit_no_device;	}	/* check that nobody else is using the device */	if (dev->open_count) {		retval = -EBUSY;		goto exit_no_device;	}	++dev->open_count;	dbg(2,"%s : open count %d", __func__, dev->open_count);	/* save device in the file's private structure */	file->private_data = dev;	/* initialize in direction */	dev->read_buffer_length = 0;	/* fixup first read by having urb waiting for it */	usb_fill_int_urb(dev->interrupt_in_urb,dev->udev,			 usb_rcvintpipe(dev->udev,					dev->interrupt_in_endpoint->bEndpointAddress),			 dev->interrupt_in_buffer,			 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize),			 adu_interrupt_in_callback, dev,			 dev->interrupt_in_endpoint->bInterval);	dev->read_urb_finished = 0;	if (usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL))		dev->read_urb_finished = 1;	/* we ignore failure */	/* end of fixup for first read */	/* initialize out direction */	dev->out_urb_finished = 1;	retval = 0;exit_no_device:	mutex_unlock(&adutux_mutex);exit_no_lock:	dbg(2,"%s : leave, return value %d ", __func__, retval);	return retval;}
开发者ID:Adjustxx,项目名称:Savaged-Zen,代码行数:70,



注:本文中的usb_fill_int_urb函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ usb_find_busses函数代码示例
C++ usb_fill_control_urb函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。