コード例 #1
0
ファイル: usbtv-core.c プロジェクト: mkrufky/linux
static int usbtv_probe(struct usb_interface *intf,
	const struct usb_device_id *id)
{
	int ret;
	int size;
	struct device *dev = &intf->dev;
	struct usbtv *usbtv;
	struct usb_host_endpoint *ep;

	/* Checks that the device is what we think it is. */
	if (intf->num_altsetting != 2)
		return -ENODEV;
	if (intf->altsetting[1].desc.bNumEndpoints != 4)
		return -ENODEV;

	ep = &intf->altsetting[1].endpoint[0];

	/* Packet size is split into 11 bits of base size and count of
	 * extra multiplies of it.*/
	size = usb_endpoint_maxp(&ep->desc);
	size = (size & 0x07ff) * usb_endpoint_maxp_mult(&ep->desc);

	/* Device structure */
	usbtv = kzalloc(sizeof(struct usbtv), GFP_KERNEL);
	if (usbtv == NULL)
		return -ENOMEM;
	usbtv->dev = dev;
	usbtv->udev = usb_get_dev(interface_to_usbdev(intf));

	usbtv->iso_size = size;

	usb_set_intfdata(intf, usbtv);

	ret = usbtv_video_init(usbtv);
	if (ret < 0)
		goto usbtv_video_fail;

	ret = usbtv_audio_init(usbtv);
	if (ret < 0)
		goto usbtv_audio_fail;

	/* for simplicity we exploit the v4l2_device reference counting */
	v4l2_device_get(&usbtv->v4l2_dev);

	dev_info(dev, "Fushicai USBTV007 Audio-Video Grabber\n");
	return 0;

usbtv_audio_fail:
	usbtv_video_free(usbtv);

usbtv_video_fail:
	usb_set_intfdata(intf, NULL);
	usb_put_dev(usbtv->udev);
	kfree(usbtv);

	return ret;
}
コード例 #2
0
ファイル: main_usb.c プロジェクト: AICP/kernel_moto_shamu
static int
vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
	u8 fake_mac[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
	struct usb_device *udev = interface_to_usbdev(intf);
	int rc = 0;
	struct net_device *netdev = NULL;
	struct vnt_private *pDevice;

	printk(KERN_NOTICE "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
	printk(KERN_NOTICE "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");

	udev = usb_get_dev(udev);
	netdev = alloc_etherdev(sizeof(struct vnt_private));
	if (!netdev) {
		printk(KERN_ERR DEVICE_NAME ": allocate net device failed\n");
		rc = -ENOMEM;
		goto err_nomem;
	}

	pDevice = netdev_priv(netdev);
	memset(pDevice, 0, sizeof(struct vnt_private));

	pDevice->dev = netdev;
	pDevice->usb = udev;

	device_set_options(pDevice);
	spin_lock_init(&pDevice->lock);

	pDevice->tx_80211 = device_dma0_tx_80211;
	pDevice->vnt_mgmt.pAdapter = (void *) pDevice;

	netdev->netdev_ops = &device_netdev_ops;
	netdev->wireless_handlers =
		(struct iw_handler_def *) &iwctl_handler_def;

	usb_set_intfdata(intf, pDevice);
	SET_NETDEV_DEV(netdev, &intf->dev);
	memcpy(pDevice->dev->dev_addr, fake_mac, ETH_ALEN);
	rc = register_netdev(netdev);
	if (rc) {
		printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
		goto err_netdev;
	}

	usb_device_reset(pDevice);

	return 0;

err_netdev:
	free_netdev(netdev);
err_nomem:
	usb_put_dev(udev);

	return rc;
}
コード例 #3
0
static int gotemp_probe(struct usb_interface *interface,
			const struct usb_device_id *id)
{
	struct usb_device *udev = interface_to_usbdev(interface);
	struct gotemp *gdev;
	struct usb_endpoint_descriptor *endpoint;
	int retval = -ENOMEM;
	size_t buffer_size;

	gdev = kzalloc(sizeof(struct gotemp), GFP_KERNEL);
	if (gdev == NULL) {
		dev_err(&interface->dev, "Out of memory\n");
		return -ENOMEM;
	}

	gdev->udev = usb_get_dev(udev);

	/* find the one control endpoint of this device */
	endpoint = &interface->cur_altsetting->endpoint[0].desc;
	buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
	gdev->int_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
	if (!gdev->int_in_buffer) {
		dev_err(&interface->dev, "Could not allocate buffer");
		goto error;
	}

	gdev->int_in_urb = usb_alloc_urb(0, GFP_KERNEL);
	if (!gdev->int_in_urb) {
		dev_err(&interface->dev, "No free urbs available\n");
		goto error;
	}
	usb_fill_int_urb(gdev->int_in_urb, udev,
			 usb_rcvintpipe(udev,
					endpoint->bEndpointAddress),
			 gdev->int_in_buffer, buffer_size,
			 read_int_callback, gdev,
			 endpoint->bInterval);

	usb_set_intfdata(interface, gdev);

	init_dev(gdev);

	retval = device_create_file(&interface->dev, &dev_attr_temperature);
	if (retval)
		goto error;

	dev_info(&interface->dev, "USB GoTemp device now attached\n");
	return 0;

error:
	usb_free_urb(gdev->int_in_urb);
	kfree(gdev->int_in_buffer);
	kfree(gdev);
	return retval;
}
コード例 #4
0
static int robotic_arm_probe(struct usb_interface *interface,
			     const struct usb_device_id *id)
{
	struct usb_device *udev;
	struct usb_robotic_arm *dev;
	int retval = -ENOMEM;

	udev = interface_to_usbdev(interface);
	dev = kzalloc(sizeof(struct usb_robotic_arm), GFP_KERNEL);
	if (dev == NULL) {
		dev_err(&interface->dev, "out of memory\n");
		goto error_mem;
	}

	dev->udev = usb_get_dev(udev);

	usb_set_intfdata(interface, dev);

	retval = device_create_file(&interface->dev, &dev_attr_led);
	if (retval)
		goto error;
	retval = device_create_file(&interface->dev, &dev_attr_gripmotor);
	if (retval)
		goto error;
	retval = device_create_file(&interface->dev, &dev_attr_motor2);
	if (retval)
		goto error;
	retval = device_create_file(&interface->dev, &dev_attr_motor3);
	if (retval)
		goto error;
	retval = device_create_file(&interface->dev, &dev_attr_motor4);
	if (retval)
		goto error;
	retval = device_create_file(&interface->dev, &dev_attr_basemotor);
	if (retval)
		goto error;

	dev_info(&interface->dev, "USB ROBOTIC ARM now attached\n");
	return 0;

error:
	device_remove_file(&interface->dev, &dev_attr_led);
	device_remove_file(&interface->dev, &dev_attr_gripmotor);
	device_remove_file(&interface->dev, &dev_attr_motor2);
	device_remove_file(&interface->dev, &dev_attr_motor3);
	device_remove_file(&interface->dev, &dev_attr_motor4);
	device_remove_file(&interface->dev, &dev_attr_basemotor);

	usb_set_intfdata(interface, NULL);
	usb_put_dev(dev->udev);
	kfree(dev);

error_mem:
	return retval;
}
コード例 #5
0
pUsb_device SysUsbGetId(pUsb_interface pintf,
				unsigned short *vid, unsigned short *pid)
{
	struct usb_interface *intf = (struct usb_interface *) pintf;
	
	struct usb_device *pusb = usb_get_dev(interface_to_usbdev(intf));

	*vid = pusb->descriptor.idVendor;
	*pid = pusb->descriptor.idProduct;

	return (pUsb_device) pusb;
}
コード例 #6
0
ファイル: usb.c プロジェクト: Kirill2013/kasan
static int mt7601u_probe(struct usb_interface *usb_intf,
			 const struct usb_device_id *id)
{
	struct usb_device *usb_dev = interface_to_usbdev(usb_intf);
	struct mt7601u_dev *dev;
	u32 asic_rev, mac_rev;
	int ret;

	dev = mt7601u_alloc_device(&usb_intf->dev);
	if (!dev)
		return -ENOMEM;

	usb_dev = usb_get_dev(usb_dev);
	usb_reset_device(usb_dev);

	usb_set_intfdata(usb_intf, dev);

	ret = mt7601u_assign_pipes(usb_intf, dev);
	if (ret)
		goto err;
	ret = mt7601u_wait_asic_ready(dev);
	if (ret)
		goto err;

	asic_rev = mt7601u_rr(dev, MT_ASIC_VERSION);
	mac_rev = mt7601u_rr(dev, MT_MAC_CSR0);
	dev_info(dev->dev, "ASIC revision: %08x MAC revision: %08x\n",
		 asic_rev, mac_rev);

	/* Note: vendor driver skips this check for MT7601U */
	if (!(mt7601u_rr(dev, MT_EFUSE_CTRL) & MT_EFUSE_CTRL_SEL))
		dev_warn(dev->dev, "Warning: eFUSE not present\n");

	ret = mt7601u_init_hardware(dev);
	if (ret)
		goto err;
	ret = mt7601u_register_device(dev);
	if (ret)
		goto err_hw;

	set_bit(MT7601U_STATE_INITIALIZED, &dev->state);

	return 0;
err_hw:
	mt7601u_cleanup(dev);
err:
	usb_set_intfdata(usb_intf, NULL);
	usb_put_dev(interface_to_usbdev(usb_intf));

	destroy_workqueue(dev->stat_wq);
	ieee80211_free_hw(dev->hw);
	return ret;
}
static int find_linak(struct usb_device *udev, void *unused)
{
  if( udev->descriptor.idVendor  == 0x12d3
      &&
      udev->descriptor.idProduct == 0x0002 )
  {
    printk(KERN_INFO "found : '%s' '%s' %d %d",udev->manufacturer,udev->product,udev->descriptor.bDeviceClass,udev->descriptor.bDeviceSubClass);
    DATA.udev = udev;
    usb_get_dev(DATA.udev);//increments the reference count of the usb device structure
    return 1;
  }
  return 0;
}
コード例 #8
0
ファイル: lme2510.c プロジェクト: gentooo/s2-liplianin
static int lme2510_probe(struct usb_interface *intf,
		const struct usb_device_id *id)
{
	struct usb_device *udev = usb_get_dev(interface_to_usbdev(intf));

	if (usb_set_interface(udev,0,1) < 0)
		err("set interface to alts=1 failed");

	if (0 == dvb_usb_device_init(intf, &lme2510_properties,
				     THIS_MODULE, NULL, adapter_nr))
		return 0;
	return -ENODEV;
}
コード例 #9
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;
}
コード例 #10
0
static int asus_oled_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
	struct usb_device *udev = interface_to_usbdev(interface);
	struct asus_oled_dev *odev = NULL;
	int retval = -ENOMEM;

	odev = kzalloc(sizeof(struct asus_oled_dev), GFP_KERNEL);
	
	if (odev == NULL) {
		dev_err(&interface->dev, "Out of memory\n");
		goto error_mem;
	}

	odev->udev = usb_get_dev(udev);
	odev->pic_mode = ASUS_OLED_STATIC;
	odev->height = 0;
	odev->width = 0;
	odev->x_shift = 0;
	odev->y_shift = 0;
	odev->buf_offs = 0;
	odev->buf_size = 0;
	odev->last_val = 0;
	odev->buf = NULL;
	
	usb_set_intfdata (interface, odev);

	if ((retval = device_create_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(enabled)))) {
		device_remove_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(enabled));
		goto error;
	}

	if ((retval = device_create_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(picture)))) {
		device_remove_file(&interface->dev, &ASUS_OLED_DEVICE_ATTR(picture));
		goto error;
	}

	dev_info(&interface->dev, "Attached Asus OLED device\n");
	
	if (start_off)
		enable_oled(odev, 0);
	
	return 0;

error:
	usb_set_intfdata (interface, NULL);
	usb_put_dev(odev->udev);
	kfree(odev);
	
error_mem:
	return retval;
}
コード例 #11
0
ファイル: vstusb.c プロジェクト: mpalmer/linux-2.6
static int vstusb_probe(struct usb_interface *intf,
			const struct usb_device_id *id)
{
	struct usb_device *dev = interface_to_usbdev(intf);
	struct vstusb_device *vstdev;
	int i;
	int retval = 0;

	/* allocate memory for our device state and intialize it */

	vstdev = kzalloc(sizeof(*vstdev), GFP_KERNEL);
	if (vstdev == NULL)
		return -ENOMEM;

	/* must do usb_get_dev() prior to kref_init() since the kref_put()
	 * release function will do a usb_put_dev() */
	usb_get_dev(dev);
	kref_init(&vstdev->kref);
	mutex_init(&vstdev->lock);

	i = dev->descriptor.bcdDevice;

	dev_dbg(&intf->dev, "Version %1d%1d.%1d%1d found at address %d\n",
		(i & 0xF000) >> 12, (i & 0xF00) >> 8,
		(i & 0xF0) >> 4, (i & 0xF), dev->devnum);

	vstdev->present = 1;
	vstdev->isopen = 0;
	vstdev->usb_dev = dev;
	init_usb_anchor(&vstdev->submitted);

	usb_set_intfdata(intf, vstdev);
	retval = usb_register_dev(intf, &usb_vstusb_class);
	if (retval) {
		dev_err(&intf->dev,
			"%s: Not able to get a minor for this device.\n",
			__func__);
		usb_set_intfdata(intf, NULL);
		kref_put(&vstdev->kref, vstusb_delete);
		return retval;
	}

	/* let the user know what node this device is now attached to */
	dev_info(&intf->dev,
		 "VST USB Device #%d now attached to major %d minor %d\n",
		 (intf->minor - VSTUSB_MINOR_BASE), USB_MAJOR, intf->minor);

	dev_info(&intf->dev, "%s, %s\n", DRIVER_DESC, DRIVER_VERSION);

	return retval;
}
コード例 #12
0
ファイル: ledtrig-usbdev.c プロジェクト: CZ-NIC/turris-os
static int usbdev_trig_find_usb_dev(struct usb_device *usb_dev, void *data)
{
	struct usbdev_trig_match *match = data;

	if (WARN_ON(match->usb_dev))
		return 0;

	if (!strcmp(dev_name(&usb_dev->dev), match->device_name)) {
		dev_dbg(&usb_dev->dev, "matched this device!\n");
		match->usb_dev = usb_get_dev(usb_dev);
	}

	return 0;
}
コード例 #13
0
ファイル: bladeRF.c プロジェクト: adamgreig/bladeRF
static int bladerf_probe(struct usb_interface *interface,
        const struct usb_device_id *id)
{
    bladerf_device_t *dev;
    int retval;
    if (interface->cur_altsetting->desc.bInterfaceNumber != 0)
        return 0;

    dev = kzalloc(sizeof(bladerf_device_t), GFP_KERNEL);
    if (dev == NULL) {
        dev_err(&interface->dev, "Out of memory\n");
        goto error_oom;
    }


    spin_lock_init(&dev->data_in_lock);
    spin_lock_init(&dev->data_out_lock);
    dev->udev = usb_get_dev(interface_to_usbdev(interface));
    dev->interface = interface;
    dev->intnum = 0;
    dev->bytes = 0;
    dev->debug = 0;
    dev->disconnecting = 0;

    atomic_set(&dev->data_in_inflight, 0);
    atomic_set(&dev->data_out_inflight, 0);

    init_usb_anchor(&dev->data_in_anchor);
    init_waitqueue_head(&dev->data_in_wait);

    init_usb_anchor(&dev->data_out_anchor);
    init_waitqueue_head(&dev->data_out_wait);

    bladerf_start(dev);

    usb_set_intfdata(interface, dev);

    retval = usb_register_dev(interface, &bladerf_class);
    if (retval) {
        dev_err(&interface->dev, "Unable to get a minor device number for bladeRF device\n");
        usb_set_intfdata(interface, NULL);
        return retval;
    }

    dev_info(&interface->dev, "Nuand bladeRF device is now attached\n");
    return 0;

error_oom:
    return -ENOMEM;
}
コード例 #14
0
ファイル: usb2impl.c プロジェクト: chinjianji/it9507
Dword Usb2_readControlBus (
    IN  Modulator*    modulator,
    IN  Dword           bufferLength,
    OUT Byte*           buffer
) {
	Dword     ret;
	int       nBytesRead;
	Byte *pTmpBuffer = kzalloc(sizeof(buffer)*bufferLength, GFP_KERNEL);
	ret = 0;

//deb_data(" ---------Usb2_readControlBus----------\n", ret);			
   ret = usb_bulk_msg(usb_get_dev(modulator->userData),
				usb_rcvbulkpipe(usb_get_dev(modulator->userData),129),
				pTmpBuffer,
				bufferLength,
				&nBytesRead,
				1000000);
	if (pTmpBuffer)
		memcpy(buffer, pTmpBuffer, bufferLength);   
	 
	if (ret) 	deb_data(" Usb2_readControlBus fail : 0x%08lx\n", ret);

	return (Error_NO_ERROR);
}
コード例 #15
0
ファイル: usb2impl.c プロジェクト: chinjianji/it9507
Dword Usb2_writeControlBus (
    IN  Modulator*    modulator,
    IN  Dword           bufferLength,
    IN  Byte*           buffer
) {
    Dword     ret;
    int		  act_len;
	Byte *pTmpBuffer = kzalloc(sizeof(buffer)*bufferLength, GFP_KERNEL);
	ret = 0;

	if (pTmpBuffer) 
		memcpy(pTmpBuffer, buffer, bufferLength);
//deb_data(" ---------Usb2_writeControlBus----------\n", ret);	
	ret = usb_bulk_msg(usb_get_dev( modulator->userData),
			usb_sndbulkpipe(usb_get_dev(modulator->userData), 0x02),
			pTmpBuffer,
			bufferLength,
			&act_len,
			1000000);
   
	if (ret) deb_data(" Usb2_writeControlBus fail : 0x%08lx\n", ret);

	return (Error_NO_ERROR);
}
コード例 #16
0
static int rtusb_probe (struct usb_interface *intf,
                        const USB_DEVICE_ID *id)
{
    RTMP_ADAPTER *pAd;
    struct usb_device *dev;
    int rv;

    dev = interface_to_usbdev(intf);
    dev = usb_get_dev(dev);

    rv = rt2870_probe(intf, dev, id, &pAd);
    if (rv != 0)
        usb_put_dev(dev);

    return rv;
}
コード例 #17
0
ファイル: usb_main_dev.c プロジェクト: AshishPrasad/BTP
static int __devinit rtusb_probe(struct usb_interface *intf,
		       const struct usb_device_id *id)
{
	struct rt_rtmp_adapter *pAd;
	struct usb_device *dev;
	int rv;

	dev = interface_to_usbdev(intf);
	dev = usb_get_dev(dev);

	rv = rt2870_probe(intf, dev, id, &pAd);
	if (rv != 0)
		usb_put_dev(dev);

	return rv;
}
コード例 #18
0
ファイル: ikalcd.c プロジェクト: hogeki/ikalcd
static int ikalcd_probe(struct usb_interface *interface,
		      const struct usb_device_id *id)
{
	struct usb_ikalcd *dev;
	int retval = -ENOMEM;

	/* allocate memory for our device state and initialize it */
	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
	if (!dev) {
		dev_err(&interface->dev, "Out of memory\n");
		goto error;
	}
	kref_init(&dev->kref);
	sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
	mutex_init(&dev->io_mutex);
	spin_lock_init(&dev->err_lock);
	init_usb_anchor(&dev->submitted);

	dev->udev = usb_get_dev(interface_to_usbdev(interface));
	dev->interface = interface;

	/* save our data pointer in this interface device */
	usb_set_intfdata(interface, dev);

	/* we can register the device now, as it is ready */
	retval = usb_register_dev(interface, &ikalcd_class);
	if (retval) {
		/* something prevented us from registering this driver */
		dev_err(&interface->dev,
			"Not able to get a minor for this device.\n");
		usb_set_intfdata(interface, NULL);
		goto error;
	}

	/* let the user know what node this device is now attached to */
	dev_info(&interface->dev,
		 "USB Skeleton device now attached to USBSkel-%d",
		 interface->minor);

	return 0;

error:
	if (dev)
		/* this frees allocated memory */
		kref_put(&dev->kref, ikalcd_delete);
	return retval;
}
コード例 #19
0
ファイル: avrBridge.c プロジェクト: ka010/avrBridge
static int avrBridge_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
	struct usb_device *udev = interface_to_usbdev(interface);
	struct avrBridge *dev = NULL;
	struct usb_host_interface *iface_desc;
	struct usb_endpoint_descriptor *endpoint;
	size_t buffer_size;
	int i;
	int retval = -ENOMEM;

	dev = kzalloc(sizeof(struct avrBridge), GFP_KERNEL);
	if (dev == NULL) {
		dev_err(&interface->dev, "Out of memory\n");
		goto error_mem;
	}
	
	kref_init(&dev->kref);
	sema_init(&dev->limit_sem, 8);
	mutex_init(&dev->io_mutex);
	spin_lock_init(&dev->err_lock);
	init_usb_anchor(&dev->submitted);
	dev->udev = usb_get_dev(udev);
	dev->interface = interface;
	dev->bulk_in_buffer = kmalloc(le16_to_cpu(512), GFP_KERNEL);

	usb_set_intfdata (interface, dev);
	retval = usb_register_dev(interface,&avrBridge_class);
		if (retval) {
		/* something prevented us from registering this device */
		err("Unble to allocate minor number.");
		usb_set_intfdata(interface, NULL);
		//idmouse_delete(dev);
		return retval;
	}

	dev_info(&interface->dev, "avrBridge device now attached\n");
	return 0;

error:
	usb_deregister_dev(interface,&avrBridge_class);
	usb_set_intfdata (interface, NULL);
	usb_put_dev(dev->udev);
	kfree(dev);
error_mem:
	return retval;
}
コード例 #20
0
ファイル: sierra.c プロジェクト: PennPanda/linux-repo
static int sierra_probe(struct usb_interface *iface,
			const struct usb_device_id *id)
{
	int result;
	struct usb_device *udev;

	udev = usb_get_dev(interface_to_usbdev(iface));

	/* Check if in installer mode */
	if (id->driver_info == DEVICE_INSTALLER) {
		dev_dbg(&udev->dev, "%s", "FOUND DEVICE(SW)\n");
		result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem);
		/*We do not want to bind to the device when in installer mode*/
		return -EIO;
	}

	return usb_serial_probe(iface, id);
}
コード例 #21
0
//Function that usb core calls when detects a usb device device
static int de2_probe(struct usb_interface* interface, const struct usb_device_id* id){
	//Create the usb device in memory 
	struct usb_device* udev = interface_to_usbdev(interface);
	struct de2 *usbDe2;

	usbDe2 = kzalloc(sizeof(*usbDe2), GFP_KERNEL);
	if (usbDe2 == NULL) {
		dev_err(&interface->dev, "Out of memory\n");
		retuusbDe2rn -ENOMEM;
	}
	
	usbDe2->udev = usb_get_dev(udev);
	usb_set_intfdata(interface, usbDe2);
	
	//Send a init command
	send_cmd(usbDe2, INIT);
	dev_info(&interface->dev, "DE2 board is now attached\n");
	return 0;
}
コード例 #22
0
ファイル: usb-file-op.c プロジェクト: amitesh-singh/ldd
//called when a usb device is connected to PC
static int
my_usb_probe(struct usb_interface *interface,
             const struct usb_device_id *id)
{
   int retval;
   struct my_usb *sd;
   struct usb_device *udev = interface_to_usbdev(interface);

   printk(KERN_INFO "usb device is connected");

   sd = kzalloc(sizeof(struct my_usb), GFP_KERNEL);
   if (sd == NULL)
     {
        // handler error
     }

   g_udev = udev;

   sd->udev = usb_get_dev(udev);

   sd->fops.open = _device_open;
   sd->fops.release = _device_close;
   sd->fops.read = _device_read;
   sd->fops.write = _device_write;

   sd->udc.name = "led%d";
   sd->udc.fops = &sd->fops;

   usb_set_intfdata(interface, sd);

   g_sd = sd;

   retval = usb_register_dev(interface, &sd->udc);
   if (retval < 0)
     {
        printk(KERN_ALERT "unable to register dev");
     }
   else
     printk(KERN_INFO "minor: %d", interface->minor);

   //dev_set_drvdata(interface->usb_dev, sd); ?
   return 0;
}
コード例 #23
0
static void rmnet_usb_disable_hsic_autosuspend(struct usbnet *usbnet,
						int enable_autosuspend)
{
	struct usb_device *usb_dev = usbnet->udev;
	struct rmnet_ctrl_udev *rmnet_udev =
		(struct rmnet_ctrl_udev *)usbnet->data[1];

	usb_get_dev(usb_dev);
	if (!enable_autosuspend) {
		usb_disable_autosuspend(usb_dev);
		rmnet_udev->autosuspend_disabled = 1;
		rmnet_udev->autosuspend_dis_cnt++;
	} else {
		usb_enable_autosuspend(usb_dev);
		rmnet_udev->autosuspend_disabled = 0;
		rmnet_udev->autosuspend_en_cnt++;
	}
	usb_put_dev(usb_dev);
}
コード例 #24
0
ファイル: dragon_usb.c プロジェクト: derekqian/KNJN
static int dragon_usb_probe (struct usb_interface *interface, const struct usb_device_id *id)
{
  struct usb_device *udev = interface_to_usbdev (interface);
  struct usb_dragon_usb *dragon_usb_dev;
  int ret;

  ret = usb_register_dev(interface, &dragon_usb_class_driver);
  if (ret < 0) {
    printk (KERN_WARNING "dragon_usb_probe: usb_register_dev() error\n");
    return ret;
  }

  dragon_usb_dev = kmalloc (sizeof(struct usb_dragon_usb), GFP_KERNEL);
  if (dragon_usb_dev == NULL) {
    dev_err (&interface->dev, "Out of memory\n");
    return -ENOMEM;
  }

  // Fill private structure and save it
  memset (dragon_usb_dev, 0, sizeof (*dragon_usb_dev));
  dragon_usb_dev->udev = usb_get_dev(udev);
  dragon_usb_dev->ledmask = 0;
  usb_set_intfdata (interface, dragon_usb_dev);

  // Create /sys entry
  ret = device_create_file (&interface->dev, &dev_attr_ledmask);
  if (ret < 0) {
    printk (KERN_WARNING "dragon_usb_probe: device_create_file() error\n");
    return ret;
  }

  // Set interface to alternate 1
  ret = usb_set_interface  (udev, 0, 1);
  if (ret < 0) {
    printk (KERN_WARNING "dragon_usb_probe: usb_set_interface() error\n");
    return ret;
  }

  dev_info(&interface->dev, "KNJN Dragon now attached\n");

  return 0;
}
コード例 #25
0
ファイル: simpleusb.c プロジェクト: abhishekpawar/temptest
static int simpleusb_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
	struct usb_host_interface *iface_desc;
	struct usb_endpoint_descriptor *endpoint;
	simpleusb_t *simpleusb_device;
	int retval = -ENOMEM;
	int i = 0;

	printk(KERN_INFO "simpleusb: %s\n", __func__);
	simpleusb_device = kzalloc(sizeof(simpleusb_t), GFP_KERNEL);
	simpleusb_device->usbdev = usb_get_dev(interface_to_usbdev(interface));
	iface_desc = interface->cur_altsetting;
	for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
		endpoint = &iface_desc->endpoint[i].desc;
		if (!simpleusb_device->bulk_in_addr && usb_endpoint_is_bulk_in(endpoint)) {
			/* Bulk IN endpoint */
			simpleusb_device->bulk_in_len = le16_to_cpu(endpoint->wMaxPacketSize);
			simpleusb_device->bulk_in_addr = endpoint->bEndpointAddress;
			simpleusb_device->bulk_in_buf = kmalloc(simpleusb_device->bulk_in_len, GFP_KERNEL);
		}
		if (!simpleusb_device->bulk_out_addr && usb_endpoint_is_bulk_out(endpoint)) {
			/* Bulk OUT endpoint */
			simpleusb_device->bulk_out_addr = endpoint->bEndpointAddress;
		}

	}
	if (!(simpleusb_device->bulk_in_addr && simpleusb_device->bulk_out_addr)) {
		return retval;
	}

	/* attach device specific structure to this interface */
	usb_set_intfdata(interface, simpleusb_device);

	/* register the device */
	retval = usb_register_dev(interface, &simpleusb_class);
	if (retval) {
		usb_set_intfdata(interface, NULL);
		return retval;
	}
	printk(KERN_INFO "simpleusb: device now attached to /dev/simpleusb\n");
	return 0;
}
コード例 #26
0
ファイル: usb.c プロジェクト: A2109devs/lenovo_a2109a_kernel
static
int i1480_usb_create(struct i1480_usb *i1480_usb, struct usb_interface *iface)
{
	struct usb_device *usb_dev = interface_to_usbdev(iface);
	int result = -ENOMEM;

	i1480_usb->usb_dev = usb_get_dev(usb_dev);	/* bind the USB device */
	i1480_usb->usb_iface = usb_get_intf(iface);
	usb_set_intfdata(iface, i1480_usb);		/* Bind the driver to iface0 */
	i1480_usb->neep_urb = usb_alloc_urb(0, GFP_KERNEL);
	if (i1480_usb->neep_urb == NULL)
		goto error;
	return 0;

error:
	usb_set_intfdata(iface, NULL);
	usb_put_intf(iface);
	usb_put_dev(usb_dev);
	return result;
}
コード例 #27
0
ファイル: timingLED.c プロジェクト: udit-gupta/ldd_basic
static int led_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
        struct usb_device *udev = interface_to_usbdev(interface);
        struct usb_led *dev = NULL;
        int retval = -ENOMEM;

				printk(">>>>>>> Step #1. probe starting! <<<<<");
        dev = kzalloc(sizeof(struct usb_led), GFP_KERNEL);
        if (dev == NULL) {
                dev_err(&interface->dev, "Out of memory\n");
                goto error_mem;
        }

        dev->udev = usb_get_dev(udev);

        usb_set_intfdata (interface, dev);

        retval = device_create_file(&interface->dev, &dev_attr_yellow);
        if (retval)
                goto error;
        retval = device_create_file(&interface->dev, &dev_attr_red);
        if (retval)
                goto error;
        retval = device_create_file(&interface->dev, &dev_attr_green);
        if (retval)
                goto error;

        dev_info(&interface->dev, "USB LED device now attached\n");
        return 0;

error:
				printk(">>>>>>> USB LED device not attached! <<<<<");
        device_remove_file(&interface->dev, &dev_attr_yellow);
        device_remove_file(&interface->dev, &dev_attr_red);
        device_remove_file(&interface->dev, &dev_attr_green);
        usb_set_intfdata (interface, NULL);
        usb_put_dev(dev->udev);
        kfree(dev);
error_mem:
        return retval;
}
コード例 #28
0
ファイル: cbaf.c プロジェクト: AshishNamdev/linux
static int cbaf_probe(struct usb_interface *iface,
		      const struct usb_device_id *id)
{
	struct cbaf *cbaf;
	struct device *dev = &iface->dev;
	int result = -ENOMEM;

	cbaf = kzalloc(sizeof(*cbaf), GFP_KERNEL);
	if (cbaf == NULL)
		goto error_kzalloc;
	cbaf->buffer = kmalloc(512, GFP_KERNEL);
	if (cbaf->buffer == NULL)
		goto error_kmalloc_buffer;

	cbaf->buffer_size = 512;
	cbaf->usb_dev = usb_get_dev(interface_to_usbdev(iface));
	cbaf->usb_iface = usb_get_intf(iface);
	result = cbaf_check(cbaf);
	if (result < 0) {
		dev_err(dev, "This device is not WUSB-CBAF compliant and is not supported yet.\n");
		goto error_check;
	}

	result = sysfs_create_group(&dev->kobj, &cbaf_dev_attr_group);
	if (result < 0) {
		dev_err(dev, "Can't register sysfs attr group: %d\n", result);
		goto error_create_group;
	}
	usb_set_intfdata(iface, cbaf);
	return 0;

error_create_group:
error_check:
	usb_put_intf(iface);
	usb_put_dev(cbaf->usb_dev);
	kfree(cbaf->buffer);
error_kmalloc_buffer:
	kfree(cbaf);
error_kzalloc:
	return result;
}
コード例 #29
0
static int cypress_probe(struct usb_interface *interface,
			 const struct usb_device_id *id)
{
	struct cypress *dev = NULL;
	int retval = -ENOMEM;

	/* allocate memory for our device state and initialize it */
	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
	if (dev == NULL) {
		dev_err(&interface->dev, "Out of memory!\n");
		goto error_mem;
	}

	dev->udev = usb_get_dev(interface_to_usbdev(interface));

	/* save our data pointer in this interface device */
	usb_set_intfdata(interface, dev);

	/* create device attribute files */
	retval = device_create_file(&interface->dev, &dev_attr_port0);
	if (retval)
		goto error;
	retval = device_create_file(&interface->dev, &dev_attr_port1);
	if (retval)
		goto error;

	/* let the user know that the device is now attached */
	dev_info(&interface->dev,
		 "Cypress CY7C63xxx device now attached\n");
	return 0;

error:
	device_remove_file(&interface->dev, &dev_attr_port0);
	device_remove_file(&interface->dev, &dev_attr_port1);
	usb_set_intfdata(interface, NULL);
	usb_put_dev(dev->udev);
	kfree(dev);

error_mem:
	return retval;
}
コード例 #30
0
static int usbrh_probe(struct usb_interface *interface,
                       const struct usb_device_id *id)
{
    struct usbrh *dev = NULL;
    int result = -ENOMEM;

    dev = kmalloc(sizeof(struct usbrh), GFP_KERNEL);
    if (dev == NULL) {
        pr_err("Out of memory");
        goto error;
    }

    memset(dev, 0, sizeof(*dev));
    mutex_init(&dev->io_mutex);
    kref_init(&dev->kref);

    usb_set_intfdata(interface, dev);

    result = usb_register_dev(interface, &usbrh_class);
    if (result) {
        pr_err("Unable to get a minor for this device.");
        usb_set_intfdata(interface, NULL);
        goto error;
    }

    dev->udev = usb_get_dev(interface_to_usbdev(interface));
    dev->interface = interface;
    dev->index = interface->minor - USBRH_MINOR_BASE;

    usbrh_create_proc(dev);

    dev_info(&dev->udev->dev, "USBRH device now attached to /dev/usbrh%d", dev->index);
    return 0;

 error:
    if (dev != NULL) {
        kref_put(&dev->kref, usbrh_delete);
    }
    return result;
}