Example #1
0
static int chaoskey_open(struct inode *inode, struct file *file)
{
	struct chaoskey *dev;
	struct usb_interface *interface;

	/* get the interface from minor number and driver information */
	interface = usb_find_interface(&chaoskey_driver, iminor(inode));
	if (!interface)
		return -ENODEV;

	usb_dbg(interface, "open");

	dev = usb_get_intfdata(interface);
	if (!dev) {
		usb_dbg(interface, "open (dev)");
		return -ENODEV;
	}

	file->private_data = dev;
	mutex_lock(&dev->lock);
	++dev->open;
	mutex_unlock(&dev->lock);

	usb_dbg(interface, "open success");
	return 0;
}
Example #2
0
struct usb_dev_handle* Bench_Open(WORD vid, WORD pid, INT interfaceNumber, INT altInterfaceNumber, struct usb_device** deviceForHandle)
{
    struct usb_bus* bus;
    struct usb_device* dev;
    struct usb_dev_handle* udev;

    for (bus = usb_get_busses(); bus; bus = bus->next)
    {
        for (dev = bus->devices; dev; dev = dev->next)
        {
            if (dev->descriptor.idVendor == vid && dev->descriptor.idProduct == pid)
            {
				if ((udev = usb_open(dev)))
				{
					if (dev->descriptor.bNumConfigurations)
					{
						if (usb_find_interface(&dev->config[0], interfaceNumber, altInterfaceNumber, NULL) != NULL)
						{
							if (deviceForHandle) *deviceForHandle = dev;
							return udev;
						}
					}

					usb_close(udev);
				}
            }
        }
    }
    return NULL;
}
static int skel_open(struct inode *inode, struct file *file)
{
	struct usb_skel *dev;
	struct usb_interface *interface;
	int subminor;
	int retval = 0;

	subminor = iminor(inode);

	interface = usb_find_interface(&skel_driver, subminor);
	if (!interface) {
		err ("%s - error, can't find device for minor %d",
		     __FUNCTION__, subminor);
		retval = -ENODEV;
		goto exit;
	}

	dev = usb_get_intfdata(interface);
	if (!dev) {
		retval = -ENODEV;
		goto exit;
	}
	
	/* increment our usage count for the device */
	kref_get(&dev->kref);

	/* save our object in the file's private structure */
	file->private_data = dev;

exit:
	return retval;
}
Example #4
0
int wagusb_open(struct inode *inode, struct file *filep)
{
  struct usb_wagusb *dev;
  struct usb_interface *interface;
  int subminor;

  subminor = iminor(inode);
  interface = usb_find_interface(&wagusb_driver, subminor);
  if (!interface)
  {
    printk(KERN_ALERT "wagusb: wagusb_open() ERROR: cant find interface\n");
    return -ENODEV;
  }

  dev = usb_get_intfdata(interface);
  if (!dev)
  {
    printk(KERN_ALERT "wagusb: wagusb_open() ERROR: cant find usb_wagusb\n");
    return -ENODEV;
  }

  mutex_lock(&dev->lock);
  dev->read_pos = 0;
  dev->bytes_read = 0;
  filep->private_data = dev;
  mutex_unlock(&dev->lock);
  return 0;
}
Example #5
0
static int as102_open(struct inode *inode, struct file *file)
{
	int ret = 0, minor = 0;
	struct usb_interface *intf = NULL;
	struct as102_dev_t *dev = NULL;

	/* read minor from inode */
	minor = iminor(inode);

	/* fetch device from usb interface */
	intf = usb_find_interface(&as102_usb_driver, minor);
	if (intf == NULL) {
		pr_err("%s: can't find device for minor %d\n",
		       __func__, minor);
		ret = -ENODEV;
		goto exit;
	}

	/* get our device */
	dev = usb_get_intfdata(intf);
	if (dev == NULL) {
		ret = -EFAULT;
		goto exit;
	}

	/* save our device object in the file's private structure */
	file->private_data = dev;

	/* increment our usage count for the device */
	kref_get(&dev->kref);

exit:
	return ret;
}
Example #6
0
static int yurex_open(struct inode *inode, struct file *file)
{
	struct usb_yurex *dev;
	struct usb_interface *interface;
	int subminor;
	int retval = 0;

	subminor = iminor(inode);

	interface = usb_find_interface(&yurex_driver, subminor);
	if (!interface) {
		printk(KERN_ERR "%s - error, can't find device for minor %d",
		       __func__, subminor);
		retval = -ENODEV;
		goto exit;
	}

	dev = usb_get_intfdata(interface);
	if (!dev) {
		retval = -ENODEV;
		goto exit;
	}

	/* increment our usage count for the device */
	kref_get(&dev->kref);

	/* save our object in the file's private structure */
	mutex_lock(&dev->io_mutex);
	file->private_data = dev;
	mutex_unlock(&dev->io_mutex);

exit:
	return retval;
}
/* Char device operations */
static int temper_open(struct inode *inode, struct file *file)
{
	struct usb_interface *intf;
	struct usb_temper *temper_dev;
	int minor;

	minor = iminor(inode);

	/* Get interface with minor */
	intf = usb_find_interface(&temper_driver, minor);
	if (!intf) {
		printk(KERN_WARNING "temper: cannot find USB interface\n");
		return -ENODEV;
	}

	/* Get private data from interface */
	temper_dev = usb_get_intfdata (intf);
	if (!temper_dev) {
		printk (KERN_WARNING "temper: cannot find device for minor %d\n", minor);
		return -ENODEV;
	}

	/* Save the pointer for further use */
	file->private_data = (void *)temper_dev;

	return 0;
}
Example #8
0
//
// char device functions
//
static int dragon_usb_open (struct inode *inode, struct file *file)
{
  struct usb_dragon_usb *dev;
  struct usb_interface *interface;
  int minor;
  
  minor = iminor(inode);

  // Get interface for device
  interface = usb_find_interface (&dragon_usb_driver, minor);
  if (!interface)
    return -ENODEV;

  // Get private data from interface
  dev = usb_get_intfdata (interface);
  if (dev == NULL) {
      printk (KERN_WARNING "dragon_usb_open(): can't find device for minor %d\n", minor);
      return -ENODEV;
  }

  // Set to file structure
  file->private_data = (void *)dev;

  return 0;
}
Example #9
0
static int usbrh_open(struct inode *inode, struct file *file)
{
    struct usbrh *dev;
    struct usbrh_fh *dev_fh;
    struct usb_interface *interface;
    int subminor;

    subminor = iminor(inode);

    interface = usb_find_interface(&usbrh_driver, subminor);
    if (interface == NULL) {
        pr_err("Can't find device for minor %d", subminor);
        return -ENODEV;
    }

    dev = usb_get_intfdata(interface);
    if (dev == NULL) {
        return -ENODEV;
    }

    dev_fh = kmalloc(sizeof(struct usbrh_fh), GFP_KERNEL);
    if (dev_fh == NULL) {
        pr_err("Out of memory");
        return -ENOMEM;
    }

    dev_fh->dev = dev;
    dev_fh->done = 0;

    kref_get(&dev->kref);
    file->private_data = dev_fh;

    return 0;
}
Example #10
0
int lighty_open(struct inode *inode, struct file *filp)
{
    struct usb_lighty *dev;
    struct usb_interface *interface;
    int subminor;

    //get the minor number from the inode
    subminor = iminor(inode);

    //use the minor number to get the assocaited interface
    interface = usb_find_interface(&lighty_driver, subminor);
    //make sure interface was found
    if (!interface) {
        printk (KERN_NOTICE "%s - error, can't find device for minor %d",  __FUNCTION__,
                                                                    subminor);
        return -ENODEV;
    }

    //get our data structure that was saved in the device interface in probe()
    dev = usb_get_intfdata(interface);
    if (!dev) {
	printk (KERN_NOTICE "Could not get interface data\n");
        return -ENODEV;
	}
	
    //increment our device reference counter
    kref_get(&dev->refcount);

    //save our device struct (pointer) in the file's private data structure
    filp->private_data = dev;

    //return success
    return 0;
}
Example #11
0
static int usblp_open(struct inode *inode, struct file *file)
{
	int minor = iminor(inode);
	struct usblp *usblp;
	struct usb_interface *intf;
	int retval;
        unsigned long arg = NULL; // Added by PaN. Modified by Jiahao
        long ioctl_retval;        // Added by Jiahao

	if (minor < 0)
		return -ENODEV;

	mutex_lock(&usblp_mutex);

	retval = -ENODEV;
	intf = usb_find_interface(&usblp_driver, minor);
	if (!intf)
		goto out;
	usblp = usb_get_intfdata(intf);
	if (!usblp || !usblp->dev || !usblp->present)
		goto out;

	retval = -EBUSY;
	if (usblp->used)
		goto out;

	/*
	 * We do not implement LP_ABORTOPEN/LPABORTOPEN for two reasons:
	 *  - We do not want persistent state which close(2) does not clear
	 *  - It is not used anyway, according to CUPS people
	 */

	retval = usb_autopm_get_interface(intf);
	if (retval < 0)
		goto out;
	usblp->used = 1;
	file->private_data = usblp;

	usblp->wcomplete = 1; /* we begin writeable */
	usblp->wstatus = 0;
	usblp->rcomplete = 0;

	if (handle_bidir(usblp) < 0) {
		usb_autopm_put_interface(intf);
		usblp->used = 0;
		file->private_data = NULL;
		retval = -EIO;
	}

        /* Added by PaN */
        if ((ioctl_retval=usblp_ioctl(file, LPGETID, arg)) <0)  // modified by Jiahao
        {
                // Update device id failed
        }
out:
	mutex_unlock(&usblp_mutex);
	return retval;
}
Example #12
0
static int skel_open(struct inode *inode, struct file *file)
{
	struct usb_skel *dev;
	struct usb_interface *interface;
	int subminor;
	int retval = 0;

	printk(KERN_INFO "eric_open\n");

	subminor = iminor(inode);

	interface = usb_find_interface(&skel_driver, subminor);
	if (!interface) {
		err("%s - error, can't find device for minor %d",
		     __func__, subminor);
		retval = -ENODEV;
		goto exit;
	}

	dev = usb_get_intfdata(interface);
	if (!dev) {
		retval = -ENODEV;
		goto exit;
	}

	/* increment our usage count for the device */
	kref_get(&dev->kref);

	/* lock the device to allow correctly handling errors
	 * in resumption */
	mutex_lock(&dev->io_mutex);

	if (!dev->open_count++) {
		retval = usb_autopm_get_interface(interface);
			if (retval) {
				dev->open_count--;
				mutex_unlock(&dev->io_mutex);
				kref_put(&dev->kref, skel_delete);
				goto exit;
			}
	} /* else { //uncomment this block if you want exclusive open
		retval = -EBUSY;
		dev->open_count--;
		mutex_unlock(&dev->io_mutex);
		kref_put(&dev->kref, skel_delete);
		goto exit;
	} */
	/* prevent the device from being autosuspended */

	/* save our object in the file's private structure */
	file->private_data = dev;
	mutex_unlock(&dev->io_mutex);

exit:
	return retval;
}
Example #13
0
static int ss801u_open(struct inode *inode, struct file *file)
{
	usb_ss801u *dev;
	struct usb_interface *interface;
	int subminor;
	int retval = 0;

	printk(KERN_INFO "Patrick-> ss801u_open  start\n");
	pr_debug("%s:%s:%d\n", __FILE__, __func__, __LINE__);
	subminor = iminor(inode);

	/* ----- use minor code to find the interface which we store data in. */
	interface = usb_find_interface(&ss801u_driver, subminor);
	if (!interface) {
		err("%s - error, can't find device for minor %d",
			__func__, subminor);
		retval = -ENODEV;
		goto exit;
	}

	/* ----- get data we saved in the interface */
	dev = usb_get_intfdata(interface);
	if (!dev) {
		retval = -ENODEV;
		goto exit;
	}

	/* increment our usage count for the device */
	kref_get(&dev->kref);

	mutex_lock(&dev->io_mutex);

	/*NOTE: open_count initializes in probe. */
	/* ----- only happen when open_count is zero */
	/* ==> means if someone is opening, another can't enter this if-case at same time */
	if (!dev->open_count++) {
		retval = 0;/* usb_autopm_get_interface(interface); //usb_autopm_enable(interface); */
		if (retval) {
			dev->open_count--;
			mutex_unlock(&dev->io_mutex);
			kref_put(&dev->kref, ss801u_delete);
			goto exit;
		}
	}

	/* usb_autopm_get_interface(dev->interface); */

	file->private_data = dev;
	mutex_unlock(&dev->io_mutex);

exit:
	printk(KERN_INFO "Patrick->  ss801u_open finish\n");
	return retval;
}
Example #14
0
/**
 *	iowarrior_open
 */
static int iowarrior_open(struct inode *inode, struct file *file)
{
	struct iowarrior *dev = NULL;
	struct usb_interface *interface;
	int subminor;
	int retval = 0;

	dbg("%s", __func__);

	mutex_lock(&iowarrior_mutex);
	subminor = iminor(inode);

	interface = usb_find_interface(&iowarrior_driver, subminor);
	if (!interface) {
		mutex_unlock(&iowarrior_mutex);
		err("%s - error, can't find device for minor %d", __func__,
		    subminor);
		return -ENODEV;
	}

	mutex_lock(&iowarrior_open_disc_lock);
	dev = usb_get_intfdata(interface);
	if (!dev) {
		mutex_unlock(&iowarrior_open_disc_lock);
		mutex_unlock(&iowarrior_mutex);
		return -ENODEV;
	}

	mutex_lock(&dev->mutex);
	mutex_unlock(&iowarrior_open_disc_lock);

	/* Only one process can open each device, no sharing. */
	if (dev->opened) {
		retval = -EBUSY;
		goto out;
	}

	/* setup interrupt handler for receiving values */
	if ((retval = usb_submit_urb(dev->int_in_urb, GFP_KERNEL)) < 0) {
		dev_err(&interface->dev, "Error %d while submitting URB\n", retval);
		retval = -EFAULT;
		goto out;
	}
	/* increment our usage count for the driver */
	++dev->opened;
	/* save our object in the file's private structure */
	file->private_data = dev;
	retval = 0;

out:
	mutex_unlock(&dev->mutex);
	mutex_unlock(&iowarrior_mutex);
	return retval;
}
static int iowarrior_open(struct inode *inode, struct file *file)
{
	struct iowarrior *dev = NULL;
	struct usb_interface *interface;
	int subminor;
	int retval = 0;

	dbg("%s", __func__);

	mutex_lock(&iowarrior_mutex);
	subminor = iminor(inode);

	interface = usb_find_interface(&iowarrior_driver, subminor);
	if (!interface) {
		mutex_unlock(&iowarrior_mutex);
		err("%s - error, can't find device for minor %d", __func__,
		    subminor);
		return -ENODEV;
	}

	mutex_lock(&iowarrior_open_disc_lock);
	dev = usb_get_intfdata(interface);
	if (!dev) {
		mutex_unlock(&iowarrior_open_disc_lock);
		mutex_unlock(&iowarrior_mutex);
		return -ENODEV;
	}

	mutex_lock(&dev->mutex);
	mutex_unlock(&iowarrior_open_disc_lock);

	/*                                                    */
	if (dev->opened) {
		retval = -EBUSY;
		goto out;
	}

	/*                                              */
	if ((retval = usb_submit_urb(dev->int_in_urb, GFP_KERNEL)) < 0) {
		dev_err(&interface->dev, "Error %d while submitting URB\n", retval);
		retval = -EFAULT;
		goto out;
	}
	/*                                          */
	++dev->opened;
	/*                                                 */
	file->private_data = dev;
	retval = 0;

out:
	mutex_unlock(&dev->mutex);
	mutex_unlock(&iowarrior_mutex);
	return retval;
}
Example #16
0
static int usblp_open(struct inode *inode, struct file *file)
{
	int minor = iminor(inode);
	struct usblp *usblp;
	struct usb_interface *intf;
	int retval;

	if (minor < 0)
		return -ENODEV;

	mutex_lock (&usblp_mutex);

	retval = -ENODEV;
	intf = usb_find_interface(&usblp_driver, minor);
	if (!intf) {
		goto out;
	}
	usblp = usb_get_intfdata (intf);
	if (!usblp || !usblp->dev || !usblp->present)
		goto out;

	retval = -EBUSY;
	if (usblp->used)
		goto out;

	/*
	 * We do not implement LP_ABORTOPEN/LPABORTOPEN for two reasons:
	 *  - We do not want persistent state which close(2) does not clear
	 *  - It is not used anyway, according to CUPS people
	 */

	retval = usb_autopm_get_interface(intf);
	if (retval < 0)
		goto out;
	usblp->used = 1;
	file->private_data = usblp;

	usblp->wcomplete = 1; /* we begin writeable */
	usblp->wstatus = 0;
	usblp->rcomplete = 0;

	if (handle_bidir(usblp) < 0) {
		usb_autopm_put_interface(intf);
		usblp->used = 0;
		file->private_data = NULL;
		retval = -EIO;
	}
out:
	mutex_unlock (&usblp_mutex);
	return retval;
}
Example #17
0
static int pixcir_open (struct inode *inode, struct file *file)
{
	struct pixcir_mt_usb *dev;
	struct usb_interface *interface;
	int subminor;
	char *buf,*getbuf;
	int retval;
	
	buf = NULL;
	getbuf = NULL;
	retval=0;	

	subminor = iminor(inode);
	
	//printk("enter pixcir_open function\n");	

	interface = usb_find_interface(&pixcir_driver, subminor);
	if (!interface) {
		err("%s - error, can't find device for minor %d",
		     __func__, subminor);
		retval = -ENODEV;
		return retval;	
	}
	
	dev = usb_get_intfdata(interface);
	if (!dev) {
		retval = -ENODEV;
		return retval;
	}
	
	dev->udev = usb_get_dev(interface_to_usbdev(interface));
	dev->interface = interface;

	kref_get(&dev->kref);
	mutex_lock(&dev->io_mutex);

	if (!dev->open_count++) {
		retval = usb_autopm_get_interface(interface);
			if (retval) {
				dev->open_count--;
				mutex_unlock(&dev->io_mutex);
				kref_put(&dev->kref, pixcir_delete);
				return retval;
			}
	}
	/* save our object in the file's private structure */
	file->private_data = dev;
	mutex_unlock(&dev->io_mutex);
	
	return 0;
}
Example #18
0
static int piusb_open(struct inode *inode, struct file *file)
{
	struct device_extension *pdx = NULL;
	struct usb_interface *interface;
	int subminor;
	int retval = 0;

	dbg("Piusb_Open()");
	subminor = iminor(inode);
	interface = usb_find_interface(&piusb_driver, subminor);
	if (!interface) {
		printk(KERN_ERR "%s - error, can't find device for minor %d\n",
		       __func__, subminor);
		retval = -ENODEV;
		goto exit_no_device;
	}

	pdx = usb_get_intfdata(interface);
	if (!pdx) {
		retval = -ENODEV;
		goto exit_no_device;
	}
	dbg("Alternate Setting = %d", interface->num_altsetting);

	pdx->bulk_in_size_returned = 0;
	pdx->bulk_in_byte_trk = 0;
	pdx->PixelUrb = NULL;
	pdx->frameIdx = 0;
	pdx->urbIdx = 0;
	pdx->maplist_numPagesMapped = NULL;
	pdx->userBufMapped = 0;
	pdx->sgl = NULL;
	pdx->sgEntries = NULL;
	pdx->gotPixelData = 0;
	pdx->pendingWrite = 0;
	pdx->pendedPixelUrbs = NULL;
	pdx->num_frames = 0;
	pdx->active_frame = 0;
	pdx->frameSize = 0;

	/* increment our usage count for the device */
	kref_get(&pdx->kref);

	/* save our object in the file's private structure */
	file->private_data = pdx;

exit_no_device:
	return retval;
}
Example #19
0
/**
 * fx2_bulk_open - Does nothing in this case
 *
 * @node: not used
 * @fp: Used to store private structure
 *
 * Returns 0 on success
 */
static int fx2_bulk_open(struct inode *node, struct file *fp)

{
	int subminor;
	struct usb_interface *intf;
	struct osr_usb_fx2_dev *dev_priv = NULL;


	subminor = iminor(node);

	intf = usb_find_interface(&osr_usb_fx2_driver, subminor);
	if (!intf) {
		printk("fx2_bulk_open: Cannot find USB Interface\n");
		return -ENODEV;
	}

	dev_priv = usb_get_intfdata(intf);
	if (!dev_priv) {
		printk("fx2_bulk_open: Cannot find device private structure\n");
		return -ENODEV;
	}

	fp->private_data = dev_priv;

	switch (dev_priv->udev->speed) {
	case USB_SPEED_HIGH:
		dev_priv->bulk_buffer_size = BULK_HIGH_SPEED_SIZE;
		break;
	case USB_SPEED_FULL:
		dev_priv->bulk_buffer_size = BULK_FULL_SPEED_SIZE;
		break;
	default:
		printk("fx2_bulk_open: Unsupported speed\n");
		return -EINVAL;
	}

	/* Allocate bulk buffer */
	if (!dev_priv->bulk_buffer) {
		printk("fx2_bulk_open: Allocate %ld bytes\n",
			dev_priv->bulk_buffer_size);

		dev_priv->bulk_buffer = kmalloc(dev_priv->bulk_buffer_size,
						GFP_KERNEL);
	}

	return 0;
}
Example #20
0
static int wdm_open(struct inode *inode, struct file *file)
{
	int minor = iminor(inode);
	int rv = -ENODEV;
	struct usb_interface *intf;
	struct wdm_device *desc;

	mutex_lock(&wdm_mutex);
	intf = usb_find_interface(&wdm_driver, minor);
	if (!intf)
		goto out;

	desc = usb_get_intfdata(intf);
	if (test_bit(WDM_DISCONNECTING, &desc->flags))
		goto out;
	file->private_data = desc;

	rv = usb_autopm_get_interface(desc->intf);
	if (rv < 0) {
		dev_err(&desc->intf->dev, "Error autopm - %d\n", rv);
		goto out;
	}
	intf->needs_remote_wakeup = 1;

	/* using write lock to protect desc->count */
	mutex_lock(&desc->wlock);
	if (!desc->count++) {
		desc->werr = 0;
		desc->rerr = 0;
		rv = usb_submit_urb(desc->validity, GFP_KERNEL);
		if (rv < 0) {
			desc->count--;
			dev_err(&desc->intf->dev,
				"Error submitting int urb - %d\n", rv);
		}
	} else {
		rv = 0;
	}
	mutex_unlock(&desc->wlock);
	usb_autopm_put_interface(desc->intf);
out:
	mutex_unlock(&wdm_mutex);
	return rv;
}
Example #21
0
static int lcd_open(struct inode *inode, struct file *file)
{
	struct usb_lcd *dev;
	struct usb_interface *interface;
	int subminor, r;

	mutex_lock(&lcd_mutex);
	subminor = iminor(inode);

	interface = usb_find_interface(&lcd_driver, subminor);
	if (!interface) {
		mutex_unlock(&lcd_mutex);
		printk(KERN_ERR "USBLCD: %s - error, can't find device for minor %d\n",
		       __func__, subminor);
		return -ENODEV;
	}

	mutex_lock(&open_disc_mutex);
	dev = usb_get_intfdata(interface);
	if (!dev) {
		mutex_unlock(&open_disc_mutex);
		mutex_unlock(&lcd_mutex);
		return -ENODEV;
	}

	/* increment our usage count for the device */
	kref_get(&dev->kref);
	mutex_unlock(&open_disc_mutex);

	/* grab a power reference */
	r = usb_autopm_get_interface(interface);
	if (r < 0) {
		kref_put(&dev->kref, lcd_delete);
		mutex_unlock(&lcd_mutex);
		return r;
	}

	/* save our object in the file's private structure */
	file->private_data = dev;
	mutex_unlock(&lcd_mutex);

	return 0;
}
Example #22
0
static int vstusb_open(struct inode *inode, struct file *file)
{
	struct vstusb_device *vstdev;
	struct usb_interface *interface;

	interface = usb_find_interface(&vstusb_driver, iminor(inode));

	if (!interface) {
		printk(KERN_ERR KBUILD_MODNAME
		       ": %s - error, can't find device for minor %d\n",
		       __func__, iminor(inode));
		return -ENODEV;
	}

	vstdev = usb_get_intfdata(interface);

	if (!vstdev)
		return -ENODEV;

	/* lock this device */
	mutex_lock(&vstdev->lock);

	/* can only open one time */
	if ((!vstdev->present) || (vstdev->isopen)) {
		mutex_unlock(&vstdev->lock);
		return -EBUSY;
	}

	/* increment our usage count */
	kref_get(&vstdev->kref);

	vstdev->isopen = 1;

	/* save device in the file's private structure */
	file->private_data = vstdev;

	dev_dbg(&vstdev->usb_dev->dev, "%s: opened\n", __func__);

	mutex_unlock(&vstdev->lock);

	return 0;
}
Example #23
0
static int usbtmc_open(struct inode *inode, struct file *filp)
{
	struct usb_interface *intf;
	struct usbtmc_device_data *data;
	int retval = 0;

	intf = usb_find_interface(&usbtmc_driver, iminor(inode));
	if (!intf) {
		pr_err("can not find device for minor %d", iminor(inode));
		return -ENODEV;
	}

	data = usb_get_intfdata(intf);
	kref_get(&data->kref);

	/* Store pointer in file structure's private data field */
	filp->private_data = data;

	return retval;
}
Example #24
0
static int skel_open(struct inode *inode, struct file *file)
{
	struct usb_skel *dev;
	struct usb_interface *interface;
	int subminor;
	int retval = 0;

	subminor = iminor(inode);

	interface = usb_find_interface(&skel_driver, subminor);
	if (!interface) {
		err("%s - error, can't find device for minor %d",
		     __func__, subminor);
		retval = -ENODEV;
		goto exit;
	}

	dev = usb_get_intfdata(interface);
	if (!dev) {
		retval = -ENODEV;
		goto exit;
	}

	/* increment our usage count for the device */
	kref_get(&dev->kref);

	/* lock the device to allow correctly handling errors
	 * in resumption */
	mutex_lock(&dev->io_mutex);

	retval = usb_autopm_get_interface(interface);
	if (retval)
		goto out_err;

	/* save our object in the file's private structure */
	file->private_data = dev;
	mutex_unlock(&dev->io_mutex);

exit:
	return retval;
}
Example #25
0
static int synccom_open(struct inode *inode, struct file *file)
{
        
	struct synccom_port *port;
	struct usb_interface *interface;
	int subminor;
	int retval = 0;

	subminor = iminor(inode);

	interface = usb_find_interface(&synccom_driver, subminor);
	if (!interface) {
		pr_err("%s - error, can't find device for minor %d\n",
			__func__, subminor);
		retval = -ENODEV;
		goto exit;
	}

	port = usb_get_intfdata(interface);
	if (!port) {
		retval = -ENODEV;
		goto exit;
	}

	retval = usb_autopm_get_interface(interface);
	if (retval)
		goto exit;
   
        

	/* increment our usage count for the device */
	kref_get(&port->kref);
	/* save our object in the file's private structure */
	file->private_data = port;
	
        
exit:
   
	return retval;
}
Example #26
0
static int diodev_open(struct inode *inode, struct file *file) {
  struct usb_dio_dev *dev;
  struct usb_interface *interface;
  int subminor;
  int p;
  FUNC_HI();
  
  subminor = iminor(inode);
  
  interface = usb_find_interface(&usb_dio_driver, subminor);
  if (!interface) {
    printk(KERN_ALERT "%s: Can't find device for minor %d\n", usb_dio_driver.name, subminor);
    FUNC_ERR();
    return -ENODEV;
  }
  
  dev = usb_get_intfdata(interface);
  if (!dev) {
    printk(KERN_ALERT "%s: Can't find interface data for minor %d\n", usb_dio_driver.name, subminor);
    FUNC_ERR();
    return -ENODEV;
  }
  
  kref_get(&dev->kref);
  
  file->private_data = dev;
  
  if (down_interruptible(&dev->buffer_sem)) {
    FUNC_ERR();
    return -EINTR;
  }
  dev->buffer_head = 0;
  dev->buffer_tail = 0;
  p = down_trylock(&dev->buffer_empty_sem);
  up(&dev->buffer_sem);
  
  FUNC_BYE();
  return 0;
}
static int skel_open(struct inode *inode, struct file *file)
{
	struct usb_skel *dev;
	struct usb_interface *interface;
	int subminor;
	int retval = 0;

	subminor = iminor(inode);

	interface = usb_find_interface(&skel_driver, subminor);
	if (!interface) {
		err("%s - error, can't find device for minor %d",
		     __func__, subminor);
		retval = -ENODEV;
		goto exit;
	}

	dev = usb_get_intfdata(interface);
	if (!dev) {
		retval = -ENODEV;
		goto exit;
	}

	
	kref_get(&dev->kref);

	mutex_lock(&dev->io_mutex);

	retval = usb_autopm_get_interface(interface);
	if (retval)
		goto out_err;

	
	file->private_data = dev;
	mutex_unlock(&dev->io_mutex);

exit:
	return retval;
}
Example #28
0
static int bladerf_open(struct inode *inode, struct file *file)
{
    bladerf_device_t *dev;
    struct usb_interface *interface;
    int subminor;

    subminor = iminor(inode);

    interface = usb_find_interface(&bladerf_driver, subminor);
    if (interface == NULL) {
        pr_err("%s - error, cannot find device for minor %d\n", __func__, subminor);
        return -ENODEV;
    }

    dev = usb_get_intfdata(interface);
    if (dev == NULL) {
        return -ENODEV;
    }

    file->private_data = dev;

    return 0;
}
Example #29
0
static int urbtc_open(struct inode *inode, struct file *file)
{
	struct usb_urbtc *dev;
	struct usb_interface *interface;
	int subminor;
	int retval = 0;

	subminor = iminor(inode);

	interface = usb_find_interface(&urbtc_driver, subminor);
	if (!interface) {
		/* err ("%s - error, can't find device for minor %d", */
		/*      __FUNCTION__, subminor); */
		retval = -ENODEV;
		goto exit;
	}

	dev = usb_get_intfdata(interface);
	if (!dev) {
		retval = -ENODEV;
		goto exit;
	}

	dev->read_status = URBTC_STATUS_READ_REQUEST;
	dev->readbuf_enabled = 0;
	dev->write_status = URBTC_STATUS_WRITE_DESIRE;

	/* increment our usage count for the device */
	kref_get(&dev->kref);

	/* save our object in the file's private structure */
	file->private_data = dev;

exit:
	return retval;
}
Example #30
0
/**
 *	usb_tranzport_open
 */
static int usb_tranzport_open(struct inode *inode, struct file *file)
{
	struct usb_tranzport *dev;
	int subminor;
	int retval = 0;
	struct usb_interface *interface;

	nonseekable_open(inode, file);
	subminor = iminor(inode);

	mutex_lock(&disconnect_mutex);

	interface = usb_find_interface(&usb_tranzport_driver, subminor);

	if (!interface) {
		err("%s - error, can't find device for minor %d\n",
		     __func__, subminor);
		retval = -ENODEV;
		goto unlock_disconnect_exit;
	}

	dev = usb_get_intfdata(interface);

	if (!dev) {
		retval = -ENODEV;
		goto unlock_disconnect_exit;
	}

	/* lock this device */
	if (down_interruptible(&dev->sem)) {
		retval = -ERESTARTSYS;
		goto unlock_disconnect_exit;
	}

	/* 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;
	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,
			 usb_tranzport_interrupt_in_callback,
			 dev,
			 dev->interrupt_in_interval);

	dev->interrupt_in_running = 1;
	dev->interrupt_in_done = 0;
	dev->enable = 1;
	dev->offline = 0;
	dev->compress_wheel = 1;

	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:
	up(&dev->sem);

unlock_disconnect_exit:
	mutex_unlock(&disconnect_mutex);

	return retval;
}