/* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */ #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
/* * Scan usb interface and populate max_pkt_size array * with information on each alternate setting. * The array should be allocated by the caller.
*/ staticint stk1160_scan_usb(struct usb_interface *intf, struct usb_device *udev, unsignedint *max_pkt_size)
{ int i, e, sizedescr, size, ifnum; conststruct usb_endpoint_descriptor *desc;
/* Get endpoints */ for (i = 0; i < intf->num_altsetting; i++) {
for (e = 0; e < intf->altsetting[i].desc.bNumEndpoints; e++) {
/* This isn't clear enough, at least to me */
desc = &intf->altsetting[i].endpoint[e].desc;
sizedescr = le16_to_cpu(desc->wMaxPacketSize);
size = sizedescr & 0x7ff;
if (udev->speed == USB_SPEED_HIGH)
size = size * hb_mult(sizedescr);
if (usb_endpoint_xfer_isoc(desc) &&
usb_endpoint_dir_in(desc)) { switch (desc->bEndpointAddress) { case STK1160_EP_AUDIO:
has_audio = true; break; case STK1160_EP_VIDEO:
has_video = true;
max_pkt_size[i] = size; break;
}
}
}
}
/* Is this even possible? */ if (!(has_audio || has_video)) {
dev_err(&udev->dev, "no audio or video endpoints found\n"); return -ENODEV;
}
switch (udev->speed) { case USB_SPEED_LOW:
speed = "1.5"; break; case USB_SPEED_FULL:
speed = "12"; break; case USB_SPEED_HIGH:
speed = "480"; break; default:
speed = "unknown";
}
/* This should never happen, since we rejected audio interfaces */ if (has_audio)
dev_warn(&udev->dev, "audio interface %d found.\n\ This is not implemented by this driver,\
you should use snd-usb-audio instead\n", ifnum);
if (has_video)
dev_info(&udev->dev, "video interface %d found\n",
ifnum);
/* * Make sure we have 480 Mbps of bandwidth, otherwise things like * video stream wouldn't likely work, since 12 Mbps is generally * not enough even for most streams.
*/ if (udev->speed != USB_SPEED_HIGH)
dev_warn(&udev->dev, "must be connected to a high-speed USB 2.0 port\n\
You may not be able to stream video smoothly\n");
/* * Since usb audio class is supported by snd-usb-audio, * we reject audio interface.
*/ if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) return -ENODEV;
/* Alloc an array for all possible max_pkt_size */
alt_max_pkt_size = kmalloc_array(interface->num_altsetting, sizeof(alt_max_pkt_size[0]),
GFP_KERNEL); if (alt_max_pkt_size == NULL) return -ENOMEM;
/* * Scan usb possibilities and populate alt_max_pkt_size array. * Also, check if device speed is fast enough.
*/
rc = stk1160_scan_usb(interface, udev, alt_max_pkt_size); if (rc < 0) {
kfree(alt_max_pkt_size); return rc;
}
dev = kzalloc(sizeof(struct stk1160), GFP_KERNEL); if (dev == NULL) {
kfree(alt_max_pkt_size); return -ENOMEM;
}
/* * There is no need to take any locks here in probe * because we register the device node as the *last* thing.
*/
spin_lock_init(&dev->buf_lock);
mutex_init(&dev->v4l_lock);
mutex_init(&dev->vb_queue_lock);
/* * We obtain a v4l2_dev but defer * registration of video device node as the last thing. * There is no need to set the name if we give a device struct
*/
dev->v4l2_dev.release = stk1160_release;
dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
rc = v4l2_device_register(dev->dev, &dev->v4l2_dev); if (rc) {
stk1160_err("v4l2_device_register failed (%d)\n", rc); goto free_ctrl;
}
rc = stk1160_i2c_register(dev); if (rc < 0) goto unreg_v4l2;
/* * To the best of my knowledge stk1160 boards only have * saa7113, but it doesn't hurt to support them all.
*/
dev->sd_saa7115 = v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap, "saa7115_auto", 0, saa7113_addrs);
/* * This calls stk1160_release if it's the last reference. * Otherwise, release is postponed until there are no users left.
*/
v4l2_device_put(&dev->v4l2_dev);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.