这篇教程C++ usb_string函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中usb_string函数的典型用法代码示例。如果您正苦于以下问题:C++ usb_string函数的具体用法?C++ usb_string怎么用?C++ usb_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了usb_string函数的22个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: usbnet_get_ethernet_addrint usbnet_get_ethernet_addr(struct usbnet *dev, int iMACAddress){ int tmp, i; unsigned char buf [13]; tmp = usb_string(dev->udev, iMACAddress, buf, sizeof buf); if (tmp != 12) { dev_dbg(&dev->udev->dev, "bad MAC string %d fetch, %d/n", iMACAddress, tmp); if (tmp >= 0) tmp = -EINVAL; return tmp; } for (i = tmp = 0; i < 6; i++, tmp += 2) dev->net->dev_addr [i] = (hex_to_bin(buf[tmp]) << 4) + hex_to_bin(buf[tmp + 1]); return 0;}
开发者ID:1yankeedt,项目名称:D710BST_FL24_Kernel,代码行数:18,
示例2: get_ethernet_addrstatic inline intget_ethernet_addr(struct usbnet *dev, struct usb_cdc_ether_desc *e){ int tmp, i; unsigned char buf [13]; tmp = usb_string(dev->udev, e->iMACAddress, buf, sizeof buf); if (tmp != 12) { dev_dbg(&dev->udev->dev, "bad MAC string %d fetch, %d/n", e->iMACAddress, tmp); if (tmp >= 0) tmp = -EINVAL; return tmp; } for (i = tmp = 0; i < 6; i++, tmp += 2) dev->net->dev_addr [i] = (nibble(buf [tmp]) << 4) + nibble(buf [tmp + 1]); return 0;}
开发者ID:IgnasD,项目名称:Tomato-RAF,代码行数:19,
示例3: getSerialNum/** * getSerialNum - function to read the serial number from a USB board * * result - int - serial number of the board * Returns (negative) error code on failure. */int getSerialNum(struct usb_cypress *dev){ int i, result, len; char buffer[MAX_SERIAL_LENGTH] = {0}; if( dev == NULL ) { printk("getSerialNum error: Passed in NULL pointer/n"); return -1; } //Read in USB iSerialNumber descriptor string len = usb_string(dev->udev, dev->udev->descriptor.iSerialNumber, buffer, MAX_SERIAL_LENGTH); result = 0; //Return error code if( len <= 0 ) { printk("Error reading USB serial number:%d/n",len); return len; // return failure. } //Loop through and convert it to an integer for (i = 0; i < len; i++) { if( (buffer[i] < '0') || (buffer[i] > '9') ) { printk("Error in serial Number - Non Numeral Digit '%c' found!!!/n",buffer[i]); return -1; } result = result*10 + buffer[i] - '0'; } //Return serial number return result;}
开发者ID:iitbombay,项目名称:usb-board-driver,代码行数:43,
示例4: af9015_probestatic int af9015_probe(struct usb_interface *intf, const struct usb_device_id *id){ struct usb_device *udev = interface_to_usbdev(intf); char manufacturer[sizeof("ITE Technologies, Inc.")]; memset(manufacturer, 0, sizeof(manufacturer)); usb_string(udev, udev->descriptor.iManufacturer, manufacturer, sizeof(manufacturer)); /* * There is two devices having same ID but different chipset. One uses * AF9015 and the other IT9135 chipset. Only difference seen on lsusb * is iManufacturer string. * * idVendor 0x0ccd TerraTec Electronic GmbH * idProduct 0x0099 * bcdDevice 2.00 * iManufacturer 1 Afatech * iProduct 2 DVB-T 2 * * idVendor 0x0ccd TerraTec Electronic GmbH * idProduct 0x0099 * bcdDevice 2.00 * iManufacturer 1 ITE Technologies, Inc. * iProduct 2 DVB-T TV Stick */ if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VID_TERRATEC) && (le16_to_cpu(udev->descriptor.idProduct) == 0x0099)) { if (!strcmp("ITE Technologies, Inc.", manufacturer)) { dev_dbg(&udev->dev, "%s: rejecting device/n", __func__); return -ENODEV; } } return dvb_usbv2_probe(intf, id);}
开发者ID:ChineseDr,项目名称:linux,代码行数:36,
示例5: usb_pwc_probe//.........这里部分代码省略......... name = "AME Co. Afina Eye"; type_id = 750; break; default: return -ENODEV; break; } } else if (vendor_id == 0x0d81) { switch(product_id) { case 0x1900: PWC_INFO("Visionite VCS-UC300 USB webcam detected./n"); name = "Visionite VCS-UC300"; type_id = 740; /* CCD sensor */ break; case 0x1910: PWC_INFO("Visionite VCS-UM100 USB webcam detected./n"); name = "Visionite VCS-UM100"; type_id = 730; /* CMOS sensor */ break; default: return -ENODEV; break; } } else return -ENODEV; /* Not any of the know types; but the list keeps growing. */ if (my_power_save == -1) my_power_save = 0; memset(serial_number, 0, 30); usb_string(udev, udev->descriptor.iSerialNumber, serial_number, 29); PWC_DEBUG_PROBE("Device serial number is %s/n", serial_number); if (udev->descriptor.bNumConfigurations > 1) PWC_WARNING("Warning: more than 1 configuration available./n"); /* Allocate structure, initialize pointers, mutexes, etc. and link it to the usb_device */ pdev = kzalloc(sizeof(struct pwc_device), GFP_KERNEL); if (pdev == NULL) { PWC_ERROR("Oops, could not allocate memory for pwc_device./n"); return -ENOMEM; } pdev->type = type_id; pdev->features = features; pwc_construct(pdev); /* set min/max sizes correct */ mutex_init(&pdev->v4l2_lock); mutex_init(&pdev->vb_queue_lock); spin_lock_init(&pdev->queued_bufs_lock); INIT_LIST_HEAD(&pdev->queued_bufs); pdev->udev = udev; pdev->power_save = my_power_save; /* Init videobuf2 queue structure */ pdev->vb_queue.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; pdev->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; pdev->vb_queue.drv_priv = pdev; pdev->vb_queue.buf_struct_size = sizeof(struct pwc_frame_buf); pdev->vb_queue.ops = &pwc_vb_queue_ops; pdev->vb_queue.mem_ops = &vb2_vmalloc_memops; pdev->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; rc = vb2_queue_init(&pdev->vb_queue);
开发者ID:AK101111,项目名称:linux,代码行数:67,
示例6: iowarrior_probe/** * iowarrior_probe * * Called by the usb core when a new device is connected that it thinks * this driver might be interested in. */static int iowarrior_probe(struct usb_interface *interface, const struct usb_device_id *id){ struct usb_device *udev = interface_to_usbdev(interface); struct iowarrior *dev = NULL; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *endpoint; int i; int retval = -ENOMEM; /* allocate memory for our device state and initialize it */ dev = kzalloc(sizeof(struct iowarrior), GFP_KERNEL); if (dev == NULL) { dev_err(&interface->dev, "Out of memory/n"); return retval; } mutex_init(&dev->mutex); atomic_set(&dev->intr_idx, 0); atomic_set(&dev->read_idx, 0); spin_lock_init(&dev->intr_idx_lock); atomic_set(&dev->overflow_flag, 0); init_waitqueue_head(&dev->read_wait); atomic_set(&dev->write_busy, 0); init_waitqueue_head(&dev->write_wait); dev->udev = udev; dev->interface = interface; iface_desc = interface->cur_altsetting; dev->product_id = le16_to_cpu(udev->descriptor.idProduct); /* set up the endpoint information */ 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_endpoint = endpoint; if (usb_endpoint_is_int_out(endpoint)) /* this one will match for the IOWarrior56 only */ dev->int_out_endpoint = endpoint; } /* we have to check the report_size often, so remember it in the endianess suitable for our machine */ dev->report_size = usb_endpoint_maxp(dev->int_in_endpoint); if ((dev->interface->cur_altsetting->desc.bInterfaceNumber == 0) && (dev->product_id == USB_DEVICE_ID_CODEMERCS_IOW56)) /* IOWarrior56 has wMaxPacketSize different from report size */ dev->report_size = 7; /* create the urb and buffer for reading */ dev->int_in_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->int_in_urb) { dev_err(&interface->dev, "Couldn't allocate interrupt_in_urb/n"); goto error; } dev->int_in_buffer = kmalloc(dev->report_size, GFP_KERNEL); if (!dev->int_in_buffer) { dev_err(&interface->dev, "Couldn't allocate int_in_buffer/n"); goto error; } usb_fill_int_urb(dev->int_in_urb, dev->udev, usb_rcvintpipe(dev->udev, dev->int_in_endpoint->bEndpointAddress), dev->int_in_buffer, dev->report_size, iowarrior_callback, dev, dev->int_in_endpoint->bInterval); /* create an internal buffer for interrupt data from the device */ dev->read_queue = kmalloc(((dev->report_size + 1) * MAX_INTERRUPT_BUFFER), GFP_KERNEL); if (!dev->read_queue) { dev_err(&interface->dev, "Couldn't allocate read_queue/n"); goto error; } /* Get the serial-number of the chip */ memset(dev->chip_serial, 0x00, sizeof(dev->chip_serial)); usb_string(udev, udev->descriptor.iSerialNumber, dev->chip_serial, sizeof(dev->chip_serial)); if (strlen(dev->chip_serial) != 8) memset(dev->chip_serial, 0x00, sizeof(dev->chip_serial)); /* Set the idle timeout to 0, if this is interface 0 */ if (dev->interface->cur_altsetting->desc.bInterfaceNumber == 0) { usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x0A, USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); } /* allow device read and ioctl */ dev->present = 1; /* we can register the device now, as it is ready */ usb_set_intfdata(interface, dev);//.........这里部分代码省略.........
开发者ID:96boards,项目名称:wilink8-wlan_wl18xx,代码行数:101,
示例7: adu_probe//.........这里部分代码省略......... if (usb_endpoint_is_int_out(endpoint)) dev->interrupt_out_endpoint = endpoint; } if (dev->interrupt_in_endpoint == NULL) { dev_err(&interface->dev, "interrupt in endpoint not found/n"); goto error; } if (dev->interrupt_out_endpoint == NULL) { dev_err(&interface->dev, "interrupt out endpoint not found/n"); goto error; } in_end_size = usb_endpoint_maxp(dev->interrupt_in_endpoint); out_end_size = usb_endpoint_maxp(dev->interrupt_out_endpoint); dev->read_buffer_primary = kmalloc((4 * in_end_size), GFP_KERNEL); if (!dev->read_buffer_primary) { dev_err(&interface->dev, "Couldn't allocate read_buffer_primary/n"); retval = -ENOMEM; goto error; } /* debug code prime the buffer */ memset(dev->read_buffer_primary, 'a', in_end_size); memset(dev->read_buffer_primary + in_end_size, 'b', in_end_size); memset(dev->read_buffer_primary + (2 * in_end_size), 'c', in_end_size); memset(dev->read_buffer_primary + (3 * in_end_size), 'd', in_end_size); dev->read_buffer_secondary = kmalloc((4 * in_end_size), GFP_KERNEL); if (!dev->read_buffer_secondary) { dev_err(&interface->dev, "Couldn't allocate read_buffer_secondary/n"); retval = -ENOMEM; goto error; } /* debug code prime the buffer */ memset(dev->read_buffer_secondary, 'e', in_end_size); memset(dev->read_buffer_secondary + in_end_size, 'f', in_end_size); memset(dev->read_buffer_secondary + (2 * in_end_size), 'g', in_end_size); memset(dev->read_buffer_secondary + (3 * in_end_size), 'h', in_end_size); dev->interrupt_in_buffer = kmalloc(in_end_size, GFP_KERNEL); if (!dev->interrupt_in_buffer) { dev_err(&interface->dev, "Couldn't allocate interrupt_in_buffer/n"); goto error; } /* debug code prime the buffer */ memset(dev->interrupt_in_buffer, 'i', in_end_size); dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->interrupt_in_urb) { dev_err(&interface->dev, "Couldn't allocate interrupt_in_urb/n"); goto error; } dev->interrupt_out_buffer = kmalloc(out_end_size, GFP_KERNEL); if (!dev->interrupt_out_buffer) { dev_err(&interface->dev, "Couldn't allocate interrupt_out_buffer/n"); goto error; } dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->interrupt_out_urb) { dev_err(&interface->dev, "Couldn't allocate interrupt_out_urb/n"); goto error; } if (!usb_string(udev, udev->descriptor.iSerialNumber, dev->serial_number, sizeof(dev->serial_number))) { dev_err(&interface->dev, "Could not retrieve serial number/n"); goto error; } dbg(2," %s : serial_number=%s", __func__, dev->serial_number); /* we can register the device now, as it is ready */ usb_set_intfdata(interface, dev); retval = usb_register_dev(interface, &adu_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; } dev->minor = interface->minor; /* let the user know what node this device is now attached to */ dev_info(&interface->dev, "ADU%d %s now attached to /dev/usb/adutux%d/n", le16_to_cpu(udev->descriptor.idProduct), dev->serial_number, (dev->minor - ADU_MINOR_BASE));exit: dbg(2," %s : leave, return value %p (dev)", __func__, dev); return retval;error: adu_delete(dev); return retval;}
开发者ID:AbdulrahmanAmir,项目名称:Dorimanx-LG-G2-D802-Kernel,代码行数:101,
示例8: cpcusb_probe/* * probe function for new CPC-USB devices */static int cpcusb_probe(struct usb_interface *interface, const struct usb_device_id *id){ CPC_USB_T *card = NULL; CPC_CHAN_T *chan = NULL; struct usb_device *udev = interface_to_usbdev(interface); struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *endpoint; int i, j, retval = -ENOMEM, slot; slot = cpcusb_get_free_slot(); if (slot < 0) { info("No more devices supported"); return -ENOMEM; } /* allocate memory for our device state and initialize it */ card = kzalloc(sizeof(CPC_USB_T), GFP_KERNEL); if (!card) { err("Out of memory"); return -ENOMEM; } CPCUSB_Table[slot] = card; /* allocate and initialize the channel struct */ card->chan = kmalloc(sizeof(CPC_CHAN_T), GFP_KERNEL); if (!card->chan) { kfree(card); err("Out of memory"); return -ENOMEM; } chan = card->chan; memset(chan, 0, sizeof(CPC_CHAN_T)); ResetBuffer(chan); semaphore_init(&card->sem); spin_lock_init(&card->slock); card->udev = udev; card->interface = interface; if (udev->descriptor.iSerialNumber) { usb_string(udev, udev->descriptor.iSerialNumber, card->serialNumber, 128); info("Serial %s", card->serialNumber); } card->productId = udev->descriptor.idProduct; info("Product %s", card->productId == USB_CPCUSB_LPC2119_PRODUCT_ID ? "CPC-USB/ARM7" : "CPC-USB/M16C"); /* set up the endpoint information */ /* check out the endpoints */ /* use only the first bulk-in and bulk-out endpoints */ iface_desc = &interface->altsetting[0]; for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { endpoint = &iface_desc->endpoint[i].desc; if (!card->num_intr_in && (endpoint->bEndpointAddress & USB_DIR_IN) && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) { card->intr_in_urb = usb_alloc_urb(0, GFP_KERNEL); card->num_intr_in = 1; if (!card->intr_in_urb) { err("No free urbs available"); goto error; } dbg("intr_in urb %d", card->num_intr_in); } if (!card->num_bulk_in && (endpoint->bEndpointAddress & USB_DIR_IN) && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK)) { card->num_bulk_in = 2; for (j = 0; j < CPC_USB_URB_CNT; j++) { card->urbs[j].size = endpoint->wMaxPacketSize; card->urbs[j].urb = usb_alloc_urb(0, GFP_KERNEL); if (!card->urbs[j].urb) { err("No free urbs available"); goto error; } card->urbs[j].buffer = usb_buffer_alloc(udev, card->urbs[j].size, GFP_KERNEL, &card->urbs[j].urb->transfer_dma); if (!card->urbs[j].buffer) { err("Couldn't allocate bulk_in_buffer"); goto error; }//.........这里部分代码省略.........
开发者ID:fread-ink,项目名称:fread-kernel-k4,代码行数:101,
示例9: igorplugusb_remote_probestatic int igorplugusb_remote_probe(struct usb_interface *intf, const struct usb_device_id *id){ struct usb_device *dev; struct usb_host_interface *idesc = NULL; struct usb_endpoint_descriptor *ep; struct igorplug *ir = NULL; struct lirc_driver *driver = NULL; int devnum, pipe, maxp; char buf[63], name[128] = ""; int ret; dprintk(DRIVER_NAME ": usb probe called./n"); dev = interface_to_usbdev(intf); idesc = intf->cur_altsetting; if (idesc->desc.bNumEndpoints != 1) return -ENODEV; ep = &idesc->endpoint->desc; if (((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) != USB_DIR_IN) || (ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_CONTROL) return -ENODEV; pipe = usb_rcvctrlpipe(dev, ep->bEndpointAddress); devnum = dev->devnum; maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); dprintk(DRIVER_NAME "[%d]: bytes_in_key=%zu maxp=%d/n", devnum, CODE_LENGTH, maxp); ir = devm_kzalloc(&intf->dev, sizeof(*ir), GFP_KERNEL); if (!ir) return -ENOMEM; driver = devm_kzalloc(&intf->dev, sizeof(*driver), GFP_KERNEL); if (!driver) return -ENOMEM; ir->buf_in = usb_alloc_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN, GFP_ATOMIC, &ir->dma_in); if (!ir->buf_in) return -ENOMEM; strcpy(driver->name, DRIVER_NAME " "); driver->minor = -1; driver->code_length = CODE_LENGTH * 8; /* in bits */ driver->features = LIRC_CAN_REC_MODE2; driver->data = ir; driver->chunk_size = CODE_LENGTH; driver->buffer_size = DEVICE_BUFLEN + ADDITIONAL_LIRC_BYTES; driver->set_use_inc = &set_use_inc; driver->set_use_dec = &set_use_dec; driver->sample_rate = sample_rate; /* per second */ driver->add_to_buf = &igorplugusb_remote_poll; driver->dev = &intf->dev; driver->owner = THIS_MODULE; ret = lirc_register_driver(driver); if (ret < 0) { usb_free_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN, ir->buf_in, ir->dma_in); return ret; } driver->minor = ret; ir->d = driver; ir->devnum = devnum; ir->usbdev = dev; ir->len_in = DEVICE_BUFLEN + DEVICE_HEADERLEN; ir->in_space = 1; /* First mode2 event is a space. */ do_gettimeofday(&ir->last_time); if (dev->descriptor.iManufacturer && usb_string(dev, dev->descriptor.iManufacturer, buf, sizeof(buf)) > 0) strlcpy(name, buf, sizeof(name)); if (dev->descriptor.iProduct && usb_string(dev, dev->descriptor.iProduct, buf, sizeof(buf)) > 0) snprintf(name + strlen(name), sizeof(name) - strlen(name), " %s", buf); printk(DRIVER_NAME "[%d]: %s on usb%d:%d/n", devnum, name, dev->bus->busnum, devnum); /* clear device buffer */ ret = usb_control_msg(ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0), SET_INFRABUFFER_EMPTY, USB_TYPE_VENDOR|USB_DIR_IN, /*unused*/0, /*unused*/0, /*dummy*/ir->buf_in, /*dummy*/ir->len_in, /*timeout*/HZ * USB_CTRL_GET_TIMEOUT); if (ret < 0) printk(DRIVER_NAME "[%d]: SET_INFRABUFFER_EMPTY: error %d/n", devnum, ret); usb_set_intfdata(intf, ir); return 0;//.........这里部分代码省略.........
开发者ID:AeroGirl,项目名称:VAR-SOM-AM33-SDK7-Kernel,代码行数:101,
示例10: iowarrior_probestatic int iowarrior_probe(struct usb_interface *interface, const struct usb_device_id *id){ struct usb_device *udev = interface_to_usbdev(interface); struct iowarrior *dev = NULL; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *endpoint; int i; int retval = -ENOMEM; /* */ dev = kzalloc(sizeof(struct iowarrior), GFP_KERNEL); if (dev == NULL) { dev_err(&interface->dev, "Out of memory/n"); return retval; } mutex_init(&dev->mutex); atomic_set(&dev->intr_idx, 0); atomic_set(&dev->read_idx, 0); spin_lock_init(&dev->intr_idx_lock); atomic_set(&dev->overflow_flag, 0); init_waitqueue_head(&dev->read_wait); atomic_set(&dev->write_busy, 0); init_waitqueue_head(&dev->write_wait); dev->udev = udev; dev->interface = interface; iface_desc = interface->cur_altsetting; dev->product_id = le16_to_cpu(udev->descriptor.idProduct); /* */ 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_endpoint = endpoint; if (usb_endpoint_is_int_out(endpoint)) /* */ dev->int_out_endpoint = endpoint; } /* */ dev->report_size = usb_endpoint_maxp(dev->int_in_endpoint); if ((dev->interface->cur_altsetting->desc.bInterfaceNumber == 0) && (dev->product_id == USB_DEVICE_ID_CODEMERCS_IOW56)) /* */ dev->report_size = 7; /* */ dev->int_in_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->int_in_urb) { dev_err(&interface->dev, "Couldn't allocate interrupt_in_urb/n"); goto error; } dev->int_in_buffer = kmalloc(dev->report_size, GFP_KERNEL); if (!dev->int_in_buffer) { dev_err(&interface->dev, "Couldn't allocate int_in_buffer/n"); goto error; } usb_fill_int_urb(dev->int_in_urb, dev->udev, usb_rcvintpipe(dev->udev, dev->int_in_endpoint->bEndpointAddress), dev->int_in_buffer, dev->report_size, iowarrior_callback, dev, dev->int_in_endpoint->bInterval); /* */ dev->read_queue = kmalloc(((dev->report_size + 1) * MAX_INTERRUPT_BUFFER), GFP_KERNEL); if (!dev->read_queue) { dev_err(&interface->dev, "Couldn't allocate read_queue/n"); goto error; } /* */ memset(dev->chip_serial, 0x00, sizeof(dev->chip_serial)); usb_string(udev, udev->descriptor.iSerialNumber, dev->chip_serial, sizeof(dev->chip_serial)); if (strlen(dev->chip_serial) != 8) memset(dev->chip_serial, 0x00, sizeof(dev->chip_serial)); /* */ if (dev->interface->cur_altsetting->desc.bInterfaceNumber == 0) { usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x0A, USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); } /* */ dev->present = 1; /* */ usb_set_intfdata(interface, dev); retval = usb_register_dev(interface, &iowarrior_class); if (retval) { /* */ dev_err(&interface->dev, "Not able to get a minor for this device./n"); usb_set_intfdata(interface, NULL);//.........这里部分代码省略.........
开发者ID:romanbb,项目名称:android_kernel_lge_d851,代码行数:101,
示例11: usb_set_configuration//.........这里部分代码省略......... /* if it's already configured, clear out old state first. * getting rid of old interfaces means unbinding their drivers. */ if (dev->state != USB_STATE_ADDRESS) usb_disable_device (dev, 1); // Skip ep0 if ((ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION, 0, configuration, 0, NULL, 0, USB_CTRL_SET_TIMEOUT)) < 0) goto free_interfaces; dev->actconfig = cp; if (!cp) usb_set_device_state(dev, USB_STATE_ADDRESS); else { usb_set_device_state(dev, USB_STATE_CONFIGURED); /* Initialize the new interface structures and the * hc/hcd/usbcore interface/endpoint state. */ for (i = 0; i < nintf; ++i) { struct usb_interface_cache *intfc; struct usb_interface *intf; struct usb_host_interface *alt; cp->interface[i] = intf = new_interfaces[i]; memset(intf, 0, sizeof(*intf)); intfc = cp->intf_cache[i]; intf->altsetting = intfc->altsetting; intf->num_altsetting = intfc->num_altsetting; kref_get(&intfc->ref); alt = usb_altnum_to_altsetting(intf, 0); /* No altsetting 0? We'll assume the first altsetting. * We could use a GetInterface call, but if a device is * so non-compliant that it doesn't have altsetting 0 * then I wouldn't trust its reply anyway. */ if (!alt) alt = &intf->altsetting[0]; intf->cur_altsetting = alt; usb_enable_interface(dev, intf); intf->dev.parent = &dev->dev; intf->dev.driver = NULL; intf->dev.bus = &usb_bus_type; intf->dev.dma_mask = dev->dev.dma_mask; intf->dev.release = release_interface; device_initialize (&intf->dev); sprintf (&intf->dev.bus_id[0], "%d-%s:%d.%d", dev->bus->busnum, dev->devpath, configuration, alt->desc.bInterfaceNumber); } kfree(new_interfaces); if ((cp->desc.iConfiguration) && (cp->string == NULL)) { cp->string = kmalloc(256, GFP_KERNEL); if (cp->string) usb_string(dev, cp->desc.iConfiguration, cp->string, 256); } /* Now that all the interfaces are set up, register them * to trigger binding of drivers to interfaces. probe() * routines may install different altsettings and may * claim() any interfaces not yet bound. Many class drivers * need that: CDC, audio, video, etc. */ for (i = 0; i < nintf; ++i) { struct usb_interface *intf = cp->interface[i]; struct usb_interface_descriptor *desc; desc = &intf->altsetting [0].desc; dev_dbg (&dev->dev, "adding %s (config #%d, interface %d)/n", intf->dev.bus_id, configuration, desc->bInterfaceNumber); ret = device_add (&intf->dev); if (ret != 0) { dev_err(&dev->dev, "device_add(%s) --> %d/n", intf->dev.bus_id, ret); continue; } if ((intf->cur_altsetting->desc.iInterface) && (intf->cur_altsetting->string == NULL)) { intf->cur_altsetting->string = kmalloc(256, GFP_KERNEL); if (intf->cur_altsetting->string) usb_string(dev, intf->cur_altsetting->desc.iInterface, intf->cur_altsetting->string, 256); } usb_create_sysfs_intf_files (intf); } } return 0;}
开发者ID:kzlin129,项目名称:tt-gpl,代码行数:101,
示例12: ld_usb_probestatic int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *id){ struct usb_device *udev = interface_to_usbdev(intf); struct ld_usb *dev = NULL; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *endpoint; char *buffer; int i; int retval = -ENOMEM; dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (dev == NULL) { dev_err(&intf->dev, "Out of memory/n"); goto exit; } mutex_init(&dev->mutex); spin_lock_init(&dev->rbsl); dev->intf = intf; init_waitqueue_head(&dev->read_wait); init_waitqueue_head(&dev->write_wait); if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VENDOR_ID_LD) && ((le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_LD_CASSY) || (le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_LD_COM3LAB)) && (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x103)) { buffer = kmalloc(256, GFP_KERNEL); if (buffer == NULL) { dev_err(&intf->dev, "Couldn't allocate string buffer/n"); goto error; } usb_string(udev, 255, buffer, 256); kfree(buffer); } iface_desc = intf->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->interrupt_in_endpoint = endpoint; if (usb_endpoint_is_int_out(endpoint)) dev->interrupt_out_endpoint = endpoint; } if (dev->interrupt_in_endpoint == NULL) { dev_err(&intf->dev, "Interrupt in endpoint not found/n"); goto error; } if (dev->interrupt_out_endpoint == NULL) dev_warn(&intf->dev, "Interrupt out endpoint not found (using control endpoint instead)/n"); dev->interrupt_in_endpoint_size = usb_endpoint_maxp(dev->interrupt_in_endpoint); dev->ring_buffer = kmalloc(ring_buffer_size*(sizeof(size_t)+dev->interrupt_in_endpoint_size), GFP_KERNEL); if (!dev->ring_buffer) { dev_err(&intf->dev, "Couldn't allocate ring_buffer/n"); goto error; } dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL); if (!dev->interrupt_in_buffer) { dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer/n"); goto error; } dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->interrupt_in_urb) { dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb/n"); goto error; } dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? usb_endpoint_maxp(dev->interrupt_out_endpoint) : udev->descriptor.bMaxPacketSize0; dev->interrupt_out_buffer = kmalloc(write_buffer_size*dev->interrupt_out_endpoint_size, GFP_KERNEL); if (!dev->interrupt_out_buffer) { dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer/n"); goto error; } dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->interrupt_out_urb) { dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb/n"); goto error; } dev->interrupt_in_interval = min_interrupt_in_interval > dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval : dev->interrupt_in_endpoint->bInterval; if (dev->interrupt_out_endpoint) dev->interrupt_out_interval = min_interrupt_out_interval > dev->interrupt_out_endpoint->bInterval ? min_interrupt_out_interval : dev->interrupt_out_endpoint->bInterval; usb_set_intfdata(intf, dev); retval = usb_register_dev(intf, &ld_usb_class); if (retval) { dev_err(&intf->dev, "Not able to get a minor for this device./n"); usb_set_intfdata(intf, NULL); goto error; }//.........这里部分代码省略.........
开发者ID:MiniBlu,项目名称:cm11_kernel_htc_msm8974a3ul,代码行数:101,
示例13: advdrv_init_onestatic INT32S __devinit advdrv_init_one(struct usb_interface *interface, const struct usb_device_id *id){ private_data *privdata = NULL; adv_device *device = NULL; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *endpoint; struct semaphore *urb_sema = NULL; INT8U strbuf[50]; INT32U tmp; INT32S ret = 0; INT16U i; /* allocate urb sema */ urb_sema = kmalloc(sizeof(struct semaphore), GFP_KERNEL); if (urb_sema == NULL) { return -ENOMEM; } init_MUTEX(urb_sema); /* allocate device structure */ device = (adv_device *) kmalloc(sizeof(adv_device), GFP_KERNEL); if (device == NULL) { kfree(urb_sema); return -ENOMEM; } memset(device, 0, sizeof(adv_device)); /* allocate private data structure */ privdata = kmalloc(sizeof(private_data), GFP_KERNEL); if (privdata == NULL) { kfree(urb_sema); kfree(device); return -ENOMEM; } memset(privdata, 0, sizeof(private_data)); /* initialize the private data in the device */ privdata->udev = usb_get_dev(interface_to_usbdev(interface)); privdata->interface = interface; privdata->usb_urb_sema = urb_sema; privdata->device_type = (id->idProduct << 16) | privdata->udev->descriptor.bcdDevice; /* get board id */ ret = adv_usb_ctrl_msg(privdata->udev, usb_rcvctrlpipe(privdata->udev, 0), MAJOR_SYSTEM, 0x40|0x80, MINOR_READ_SWITCHID, 0, (INT8U *) &privdata->board_id, sizeof(INT16U)); if (ret < 0) { kfree(urb_sema); kfree(device); kfree(privdata); return ret; } /* get USB speed (low, full or high) */ ret = usb_string(privdata->udev, privdata->udev->descriptor.iProduct, strbuf, sizeof(strbuf)); if (ret < 0) { kfree(urb_sema); kfree(device); kfree(privdata); return ret; } if (strstr(strbuf, "(LS)") != NULL) { privdata->usb_speed = USB_SPEED_LOW; } else if (strstr(strbuf, "(FS)") != NULL) { privdata->usb_speed = USB_SPEED_FULL; } else if (strstr(strbuf, "(HS)") != NULL) { privdata->usb_speed = USB_SPEED_HIGH; } /* select pipe */ tmp = 2; ret = adv_usb_ctrl_msg(privdata->udev, usb_sndctrlpipe(privdata->udev, 0), MAJOR_DIRECT_IO, 0x40, MINOR_DIRECT_WRITE, 0x501, &tmp, sizeof(INT32U)); if (ret < 0) { kfree(urb_sema); kfree(device); kfree(privdata); return ret; } /* init queue, spinlock and process info list */ adv_process_info_header_init(&privdata->ptr_process_info); spin_lock_init(&privdata->spinlock); init_waitqueue_head(&privdata->event_wait); tasklet_init(&privdata->urb_tasklet, urb_tasklet_fn, (PTR_T) device); INIT_WORK(&privdata->fai_stop_work, adv_fai_stop_work, (VOID *) device); /* probe endpoint */ iface_desc = interface->cur_altsetting; for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { endpoint = &iface_desc->endpoint[i].desc;//.........这里部分代码省略.........
开发者ID:rct225,项目名称:scanside,代码行数:101,
示例14: usb_lmpcm_probestatic 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,
示例15: ld_usb_probe/** * ld_usb_probe * * Called by the usb core when a new device is connected that it thinks * this driver might be interested in. */static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *id){ struct usb_device *udev = interface_to_usbdev(intf); struct ld_usb *dev = NULL; struct usb_host_interface *iface_desc; char *buffer; int retval = -ENOMEM; int res; /* allocate memory for our device state and initialize it */ dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) goto exit; mutex_init(&dev->mutex); spin_lock_init(&dev->rbsl); dev->intf = intf; init_waitqueue_head(&dev->read_wait); init_waitqueue_head(&dev->write_wait); /* workaround for early firmware versions on fast computers */ if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VENDOR_ID_LD) && ((le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_LD_CASSY) || (le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_LD_COM3LAB)) && (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x103)) { buffer = kmalloc(256, GFP_KERNEL); if (!buffer) goto error; /* usb_string makes SETUP+STALL to leave always ControlReadLoop */ usb_string(udev, 255, buffer, 256); kfree(buffer); } iface_desc = intf->cur_altsetting; res = usb_find_last_int_in_endpoint(iface_desc, &dev->interrupt_in_endpoint); if (res) { dev_err(&intf->dev, "Interrupt in endpoint not found/n"); retval = res; goto error; } res = usb_find_last_int_out_endpoint(iface_desc, &dev->interrupt_out_endpoint); if (res) dev_warn(&intf->dev, "Interrupt out endpoint not found (using control endpoint instead)/n"); dev->interrupt_in_endpoint_size = usb_endpoint_maxp(dev->interrupt_in_endpoint); dev->ring_buffer = kmalloc_array(ring_buffer_size, sizeof(size_t) + dev->interrupt_in_endpoint_size, GFP_KERNEL); if (!dev->ring_buffer) goto error; dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL); if (!dev->interrupt_in_buffer) goto error; dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->interrupt_in_urb) goto error; dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? usb_endpoint_maxp(dev->interrupt_out_endpoint) : udev->descriptor.bMaxPacketSize0; dev->interrupt_out_buffer = kmalloc_array(write_buffer_size, dev->interrupt_out_endpoint_size, GFP_KERNEL); if (!dev->interrupt_out_buffer) goto error; dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->interrupt_out_urb) goto error; dev->interrupt_in_interval = min_interrupt_in_interval > dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval : dev->interrupt_in_endpoint->bInterval; if (dev->interrupt_out_endpoint) dev->interrupt_out_interval = min_interrupt_out_interval > dev->interrupt_out_endpoint->bInterval ? min_interrupt_out_interval : dev->interrupt_out_endpoint->bInterval; /* we can register the device now, as it is ready */ usb_set_intfdata(intf, dev); retval = usb_register_dev(intf, &ld_usb_class); if (retval) { /* something prevented us from registering this driver */ dev_err(&intf->dev, "Not able to get a minor for this device./n"); usb_set_intfdata(intf, NULL); goto error; } /* let the user know what node this device is now attached to */ dev_info(&intf->dev, "LD USB Device #%d now attached to major %d minor %d/n", (intf->minor - USB_LD_MINOR_BASE), USB_MAJOR, intf->minor);exit: return retval;error://.........这里部分代码省略.........
开发者ID:krzk,项目名称:linux,代码行数:101,
示例16: DECLARE_WAIT_QUEUE_HEAD/* Probe if this driver wants to serve an USB device This entry point is called whenever a new device is attached to the bus. Then the device driver has to create a new instance of its internal data structures for the new device. The dev argument specifies the device context, which contains pointers to all USB descriptors. The interface argument specifies the interface number. If a USB driver wants to bind itself to a particular device and interface it has to return a pointer. This pointer normally references the device driver's context structure. Probing normally is done by checking the vendor and product identifications or the class and subclass definitions. If they match the interface number is compared with the ones supported by the driver. When probing is done class based it might be necessary to parse some more USB descriptors because the device properties can differ in a wide range.*/static void *auerswald_probe(struct usb_device *usbdev, unsigned int ifnum, const struct usb_device_id *id){ struct auerswald *cp = NULL; DECLARE_WAIT_QUEUE_HEAD(wqh); unsigned int dtindex; unsigned int u = 0; char *pbuf; int ret; dbg("probe: vendor id 0x%x, device id 0x%x ifnum:%d", usbdev->descriptor.idVendor, usbdev->descriptor.idProduct, ifnum); /* See if the device offered us matches that we can accept */ if (usbdev->descriptor.idVendor != ID_AUERSWALD) return NULL; /* we use only the first -and only- interface */ if (ifnum != 0) return NULL; /* prevent module unloading while sleeping */ MOD_INC_USE_COUNT; /* allocate memory for our device and intialize it */ cp = kmalloc(sizeof(struct auerswald), GFP_KERNEL); if (cp == NULL) { err("out of memory"); goto pfail; } /* Initialize device descriptor */ memset(cp, 0, sizeof(struct auerswald)); init_MUTEX(&cp->mutex); cp->usbdev = usbdev; auerchain_init(&cp->controlchain); auerbuf_init(&cp->bufctl); init_waitqueue_head(&cp->bufferwait); auerisdn_init_dev(cp); /* find a free slot in the device table */ down(&auerdev_table_mutex); for (dtindex = 0; dtindex < AUER_MAX_DEVICES; ++dtindex) { if (auerdev_table[dtindex] == NULL) break; } if (dtindex >= AUER_MAX_DEVICES) { err("more than %d devices plugged in, can not handle this device", AUER_MAX_DEVICES); up(&auerdev_table_mutex); goto pfail; } /* Give the device a name */ sprintf(cp->name, AU_PREFIX "%d", dtindex); /* Store the index */ cp->dtindex = dtindex; auerdev_table[dtindex] = cp; up(&auerdev_table_mutex); /* initialize the devfs node for this device and register it */ cp->devfs = devfs_register(usb_devfs_handle, cp->name, DEVFS_FL_DEFAULT, USB_MAJOR, AUER_MINOR_BASE + dtindex, S_IFCHR | S_IRUGO | S_IWUGO, &auerswald_fops, NULL); /* Get the usb version of the device */ cp->version = cp->usbdev->descriptor.bcdDevice; dbg("Version is %X", cp->version); /* allow some time to settle the device */ sleep_on_timeout(&wqh, HZ / 3); /* Try to get a suitable textual description of the device */ /* Device name: */ ret = usb_string(cp->usbdev, AUSI_DEVICE, cp->dev_desc, AUSI_DLEN - 1); if (ret >= 0) { u += ret;//.........这里部分代码省略.........
开发者ID:GunioRobot,项目名称:MI424WR_GEN2_Rev_E-F,代码行数:101,
示例17: hiddev_ioctl/* * "ioctl" file op */static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ struct hiddev_list *list = file->private_data; struct hiddev *hiddev = list->hiddev; struct hid_device *hid = hiddev->hid; struct usb_device *dev = hid->dev; struct hiddev_collection_info cinfo; struct hiddev_report_info rinfo; struct hiddev_field_info finfo; struct hiddev_usage_ref_multi uref_multi; struct hiddev_usage_ref *uref = &uref_multi.uref; struct hiddev_devinfo dinfo; struct hid_report *report; struct hid_field *field; int i; if (!hiddev->exist) return -EIO; switch (cmd) { case HIDIOCGVERSION: return put_user(HID_VERSION, (int *) arg); case HIDIOCAPPLICATION: if (arg < 0 || arg >= hid->maxapplication) return -EINVAL; for (i = 0; i < hid->maxcollection; i++) if (hid->collection[i].type == HID_COLLECTION_APPLICATION && arg-- == 0) break; if (i == hid->maxcollection) return -EINVAL; return hid->collection[i].usage; case HIDIOCGDEVINFO: dinfo.bustype = BUS_USB; dinfo.busnum = dev->bus->busnum; dinfo.devnum = dev->devnum; dinfo.ifnum = hid->ifnum; dinfo.vendor = dev->descriptor.idVendor; dinfo.product = dev->descriptor.idProduct; dinfo.version = dev->descriptor.bcdDevice; dinfo.num_applications = hid->maxapplication; if (copy_to_user((void *) arg, &dinfo, sizeof(dinfo))) return -EFAULT; return 0; case HIDIOCGFLAG: return put_user(list->flags, (int *) arg); case HIDIOCSFLAG: { int newflags; if (get_user(newflags, (int *) arg)) return -EFAULT; if ((newflags & ~HIDDEV_FLAGS) != 0 || ((newflags & HIDDEV_FLAG_REPORT) != 0 && (newflags & HIDDEV_FLAG_UREF) == 0)) return -EINVAL; list->flags = newflags; return 0; } case HIDIOCGSTRING: { int idx, len; char *buf; if (get_user(idx, (int *) arg)) return -EFAULT; if ((buf = kmalloc(HID_STRING_SIZE, GFP_KERNEL)) == NULL) return -ENOMEM; if ((len = usb_string(dev, idx, buf, HID_STRING_SIZE-1)) < 0) { kfree(buf); return -EINVAL; } if (copy_to_user((void *) (arg+sizeof(int)), buf, len+1)) { kfree(buf); return -EFAULT; } kfree(buf); return len; } case HIDIOCINITREPORT://.........这里部分代码省略.........
开发者ID:SimonKagstrom,项目名称:mci500h-linux-2.4.27,代码行数:101,
示例18: usb_remote_probe//.........这里部分代码省略.........mem_failure_switch: switch (mem_failure) { case 9:#if defined(KERNEL_2_5) usb_buffer_free(dev, DEVICE_BUFLEN+DEVICE_HEADERLEN, ir->buf_in, ir->dma_in);#else kfree(ir->buf_in);#endif case 3: kfree(driver); case 2: kfree(ir); case 1: printk(KERN_ERR DRIVER_NAME "[%d]: out of memory (code=%d)/n", devnum, mem_failure);#if defined(KERNEL_2_5) return -ENOMEM;#else return NULL;#endif } driver->minor = minor; ir->d = driver; ir->devnum = devnum; ir->usbdev = dev; ir->len_in = DEVICE_BUFLEN+DEVICE_HEADERLEN; ir->in_space = 1; /* First mode2 event is a space. */ do_gettimeofday(&ir->last_time); if (dev->descriptor.iManufacturer && usb_string(dev, dev->descriptor.iManufacturer, buf, sizeof(buf)) > 0) strlcpy(name, buf, sizeof(name)); if (dev->descriptor.iProduct && usb_string(dev, dev->descriptor.iProduct, buf, sizeof(buf)) > 0) snprintf(name + strlen(name), sizeof(name) - strlen(name), " %s", buf); printk(KERN_INFO DRIVER_NAME "[%d]: %s on usb%d:%d/n", devnum, name, dev->bus->busnum, devnum); /* clear device buffer */ ret = usb_control_msg(ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0), SET_INFRABUFFER_EMPTY, USB_TYPE_VENDOR|USB_DIR_IN, /*unused*/0, /*unused*/0, /*dummy*/ir->buf_in, /*dummy*/ir->len_in, /*timeout*/HZ * USB_CTRL_GET_TIMEOUT); if (ret < 0) printk(KERN_WARNING DRIVER_NAME "[%d]: SET_INFRABUFFER_EMPTY: error %d/n", devnum, ret);#if defined(KERNEL_2_5) usb_set_intfdata(intf, ir); return 0;#else return ir;#endif}#if defined(KERNEL_2_5)static void usb_remote_disconnect(struct usb_interface *intf){
开发者ID:ArthySundaram,项目名称:firstrepo,代码行数:67,
示例19: ld_usb_probe/** * ld_usb_probe * * Called by the usb core when a new device is connected that it thinks * this driver might be interested in. */static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *id){ struct usb_device *udev = interface_to_usbdev(intf); struct ld_usb *dev = NULL; struct usb_host_interface *iface_desc; struct usb_endpoint_descriptor *endpoint; char *buffer; int i; int retval = -ENOMEM; /* allocate memory for our device state and intialize it */ dev = kmalloc(sizeof(*dev), GFP_KERNEL); if (dev == NULL) { dev_err(&intf->dev, "Out of memory/n"); goto exit; } memset(dev, 0x00, sizeof(*dev)); init_MUTEX(&dev->sem); dev->intf = intf; init_waitqueue_head(&dev->read_wait); init_waitqueue_head(&dev->write_wait); /* workaround for early firmware versions on fast computers */ if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VENDOR_ID_LD) && ((le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_CASSY) || (le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_COM3LAB)) && (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x103)) { buffer = kmalloc(256, GFP_KERNEL); if (buffer == NULL) { dev_err(&intf->dev, "Couldn't allocate string buffer/n"); goto error; } /* usb_string makes SETUP+STALL to leave always ControlReadLoop */ usb_string(udev, 255, buffer, 256); kfree(buffer); } iface_desc = intf->cur_altsetting; /* set up the endpoint information */ for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { endpoint = &iface_desc->endpoint[i].desc; if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) { dev->interrupt_in_endpoint = endpoint; } if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) { dev->interrupt_out_endpoint = endpoint; } } if (dev->interrupt_in_endpoint == NULL) { dev_err(&intf->dev, "Interrupt in endpoint not found/n"); goto error; } if (dev->interrupt_out_endpoint == NULL) dev_warn(&intf->dev, "Interrupt out endpoint not found (using control endpoint instead)/n"); dev->interrupt_in_endpoint_size = le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize); dev->ring_buffer = kmalloc(ring_buffer_size*(sizeof(size_t)+dev->interrupt_in_endpoint_size), GFP_KERNEL); if (!dev->ring_buffer) { dev_err(&intf->dev, "Couldn't allocate ring_buffer/n"); goto error; } dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL); if (!dev->interrupt_in_buffer) { dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer/n"); goto error; } dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->interrupt_in_urb) { dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb/n"); goto error; } dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize) : udev->descriptor.bMaxPacketSize0; dev->interrupt_out_buffer = kmalloc(write_buffer_size*dev->interrupt_out_endpoint_size, GFP_KERNEL); if (!dev->interrupt_out_buffer) { dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer/n"); goto error; } dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); if (!dev->interrupt_out_urb) { dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb/n"); goto error; } dev->interrupt_in_interval = min_interrupt_in_interval > dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval : dev->interrupt_in_endpoint->bInterval; if (dev->interrupt_out_endpoint) dev->interrupt_out_interval = min_interrupt_out_interval > dev->interrupt_out_endpoint->bInterval ? min_interrupt_out_interval : dev->interrupt_out_endpoint->bInterval; /* we can register the device now, as it is ready *///.........这里部分代码省略.........
开发者ID:kzlin129,项目名称:tt-gpl,代码行数:101,
示例20: init_cardstatic int init_card(struct snd_usb_caiaqdev *dev){ char *c, usbpath[32]; struct usb_device *usb_dev = dev->chip.dev; struct snd_card *card = dev->chip.card; int err, len; if (usb_set_interface(usb_dev, 0, 1) != 0) { log("can't set alt interface./n"); return -EIO; } usb_init_urb(&dev->ep1_in_urb); usb_init_urb(&dev->midi_out_urb); usb_fill_bulk_urb(&dev->ep1_in_urb, usb_dev, usb_rcvbulkpipe(usb_dev, 0x1), dev->ep1_in_buf, EP1_BUFSIZE, usb_ep1_command_reply_dispatch, dev); usb_fill_bulk_urb(&dev->midi_out_urb, usb_dev, usb_sndbulkpipe(usb_dev, 0x1), dev->midi_out_buf, EP1_BUFSIZE, snd_usb_caiaq_midi_output_done, dev); init_waitqueue_head(&dev->ep1_wait_queue); init_waitqueue_head(&dev->prepare_wait_queue); if (usb_submit_urb(&dev->ep1_in_urb, GFP_KERNEL) != 0) return -EIO; err = snd_usb_caiaq_send_command(dev, EP1_CMD_GET_DEVICE_INFO, NULL, 0); if (err) return err; if (!wait_event_timeout(dev->ep1_wait_queue, dev->spec_received, HZ)) return -ENODEV; usb_string(usb_dev, usb_dev->descriptor.iManufacturer, dev->vendor_name, CAIAQ_USB_STR_LEN); usb_string(usb_dev, usb_dev->descriptor.iProduct, dev->product_name, CAIAQ_USB_STR_LEN); strlcpy(card->driver, MODNAME, sizeof(card->driver)); strlcpy(card->shortname, dev->product_name, sizeof(card->shortname)); strlcpy(card->mixername, dev->product_name, sizeof(card->mixername)); /* if the id was not passed as module option, fill it with a shortened * version of the product string which does not contain any * whitespaces */ if (*card->id == '/0') { char id[sizeof(card->id)]; memset(id, 0, sizeof(id)); for (c = card->shortname, len = 0; *c && len < sizeof(card->id); c++) if (*c != ' ') id[len++] = *c; snd_card_set_id(card, id); } usb_make_path(usb_dev, usbpath, sizeof(usbpath)); snprintf(card->longname, sizeof(card->longname), "%s %s (%s)", dev->vendor_name, dev->product_name, usbpath); setup_card(dev); return 0;}
开发者ID:AiWinters,项目名称:linux,代码行数:73,
示例21: usb_8dev_cmd_close//.........这里部分代码省略......... .ndo_start_xmit = usb_8dev_start_xmit, .ndo_change_mtu = can_change_mtu,};static const struct can_bittiming_const usb_8dev_bittiming_const = { .name = "usb_8dev", .tseg1_min = 1, .tseg1_max = 16, .tseg2_min = 1, .tseg2_max = 8, .sjw_max = 4, .brp_min = 1, .brp_max = 1024, .brp_inc = 1,};/* Probe USB device * * Check device and firmware. * Set supported modes and bittiming constants. * Allocate some memory. */static int usb_8dev_probe(struct usb_interface *intf, const struct usb_device_id *id){ struct net_device *netdev; struct usb_8dev_priv *priv; int i, err = -ENOMEM; u32 version; char buf[18]; struct usb_device *usbdev = interface_to_usbdev(intf); /* product id looks strange, better we also check iProduct string */ if (usb_string(usbdev, usbdev->descriptor.iProduct, buf, sizeof(buf)) > 0 && strcmp(buf, "USB2CAN converter")) { dev_info(&usbdev->dev, "ignoring: not an USB2CAN converter/n"); return -ENODEV; } netdev = alloc_candev(sizeof(struct usb_8dev_priv), MAX_TX_URBS); if (!netdev) { dev_err(&intf->dev, "Couldn't alloc candev/n"); return -ENOMEM; } priv = netdev_priv(netdev); priv->udev = usbdev; priv->netdev = netdev; priv->can.state = CAN_STATE_STOPPED; priv->can.clock.freq = USB_8DEV_ABP_CLOCK; priv->can.bittiming_const = &usb_8dev_bittiming_const; priv->can.do_set_mode = usb_8dev_set_mode; priv->can.do_get_berr_counter = usb_8dev_get_berr_counter; priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY | CAN_CTRLMODE_ONE_SHOT; netdev->netdev_ops = &usb_8dev_netdev_ops; netdev->flags |= IFF_ECHO; /* we support local echo */ init_usb_anchor(&priv->rx_submitted); init_usb_anchor(&priv->tx_submitted);
开发者ID:mikuhatsune001,项目名称:linux2.6.32,代码行数:67,
示例22: hiddev_ioctl/* * "ioctl" file op */static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ struct hiddev_list *list = file->private_data; struct hiddev *hiddev = list->hiddev; struct hid_device *hid = hiddev->hid; struct usb_device *dev = hid->dev; struct hiddev_report_info rinfo; struct hiddev_usage_ref uref; struct hid_report *report; struct hid_field *field; if (!hiddev->exist) return -EIO; switch (cmd) { case HIDIOCGVERSION: return put_user(HID_VERSION, (int *) arg); case HIDIOCAPPLICATION: if (arg < 0 || arg >= hid->maxapplication) return -EINVAL; return hid->application[arg]; case HIDIOCGDEVINFO: { struct hiddev_devinfo dinfo; dinfo.bustype = BUS_USB; dinfo.busnum = dev->bus->busnum; dinfo.devnum = dev->devnum; dinfo.ifnum = hid->ifnum; dinfo.vendor = dev->descriptor.idVendor; dinfo.product = dev->descriptor.idProduct; dinfo.version = dev->descriptor.bcdDevice; dinfo.num_applications = hid->maxapplication; return copy_to_user((void *) arg, &dinfo, sizeof(dinfo)); } case HIDIOCGSTRING: { int idx, len; char *buf; if (get_user(idx, (int *) arg)) return -EFAULT; if ((buf = kmalloc(HID_STRING_SIZE, GFP_KERNEL)) == NULL) return -ENOMEM; if ((len = usb_string(dev, idx, buf, HID_STRING_SIZE-1)) < 0) { kfree(buf); return -EINVAL; } if (copy_to_user((void *) (arg+sizeof(int)), buf, len+1)) { kfree(buf); return -EFAULT; } kfree(buf); return len; } case HIDIOCINITREPORT: hid_init_reports(hid); return 0; case HIDIOCGREPORT: if (copy_from_user(&rinfo, (void *) arg, sizeof(rinfo))) return -EFAULT; if (rinfo.report_type == HID_REPORT_TYPE_OUTPUT) return -EINVAL; if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) return -EINVAL; hid_read_report(hid, report); return 0; case HIDIOCSREPORT: if (copy_from_user(&rinfo, (void *) arg, sizeof(rinfo))) return -EFAULT; if (rinfo.report_type == HID_REPORT_TYPE_INPUT) return -EINVAL; if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) return -EINVAL; hid_write_report(hid, report); return 0;//.........这里部分代码省略.........
开发者ID:liexusong,项目名称:Linux-2.4.16,代码行数:101,
注:本文中的usb_string函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ usb_submit_urb函数代码示例 C++ usb_stor_msg_common函数代码示例 |