drivers/usb/gadget/function/f_uvc.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/function/f_uvc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/function/f_uvc.c- Extension
.c- Size
- 33778 bytes
- Lines
- 1177
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/errno.hlinux/fs.hlinux/kernel.hlinux/list.hlinux/module.hlinux/mutex.hlinux/string.hlinux/usb/ch9.hlinux/usb/gadget.hlinux/usb/g_uvc.hlinux/usb/video.hlinux/vmalloc.hlinux/wait.hmedia/v4l2-dev.hmedia/v4l2-event.huvc.huvc_configfs.huvc_v4l2.huvc_video.h
Detected Declarations
function uvc_function_ep0_completefunction uvc_function_setupfunction uvc_function_setup_continuefunction uvc_function_get_altfunction uvc_function_set_altfunction uvc_function_disablefunction uvc_function_connectfunction uvc_function_disconnectfunction function_name_showfunction uvc_vdev_releasefunction uvc_register_videofunction uvc_copy_descriptorsfunction list_for_each_entryfunction uvc_function_bindfunction uvc_free_instfunction uvc_freefunction uvc_function_unbind
Annotated Snippet
if (uvc->enable_interrupt_ep) {
uvcg_info(f, "reset UVC interrupt endpoint\n");
usb_ep_disable(uvc->interrupt_ep);
if (!uvc->interrupt_ep->desc)
if (config_ep_by_speed(cdev->gadget, f,
uvc->interrupt_ep))
return -EINVAL;
usb_ep_enable(uvc->interrupt_ep);
}
if (uvc->state == UVC_STATE_DISCONNECTED) {
memset(&v4l2_event, 0, sizeof(v4l2_event));
v4l2_event.type = UVC_EVENT_CONNECT;
uvc_event->speed = cdev->gadget->speed;
v4l2_event_queue(&uvc->vdev, &v4l2_event);
uvc->state = UVC_STATE_CONNECTED;
}
return 0;
}
if (interface != uvc->streaming_intf)
return -EINVAL;
/* TODO
if (usb_endpoint_xfer_bulk(&uvc->desc.vs_ep))
return alt ? -EINVAL : 0;
*/
switch (alt) {
case 0:
if (uvc->state != UVC_STATE_STREAMING)
return 0;
memset(&v4l2_event, 0, sizeof(v4l2_event));
v4l2_event.type = UVC_EVENT_STREAMOFF;
v4l2_event_queue(&uvc->vdev, &v4l2_event);
return USB_GADGET_DELAYED_STATUS;
case 1:
if (uvc->state != UVC_STATE_CONNECTED)
return 0;
if (!uvc->video.ep)
return -EINVAL;
uvcg_info(f, "reset UVC\n");
usb_ep_disable(uvc->video.ep);
ret = config_ep_by_speed(f->config->cdev->gadget,
&(uvc->func), uvc->video.ep);
if (ret)
return ret;
usb_ep_enable(uvc->video.ep);
uvc->video.max_req_size = uvc->video.ep->maxpacket
* max_t(unsigned int, uvc->video.ep->maxburst, 1)
* (uvc->video.ep->mult);
memset(&v4l2_event, 0, sizeof(v4l2_event));
v4l2_event.type = UVC_EVENT_STREAMON;
v4l2_event_queue(&uvc->vdev, &v4l2_event);
return USB_GADGET_DELAYED_STATUS;
default:
return -EINVAL;
}
}
static void
uvc_function_disable(struct usb_function *f)
{
struct uvc_device *uvc = to_uvc(f);
struct v4l2_event v4l2_event;
uvcg_info(f, "%s()\n", __func__);
memset(&v4l2_event, 0, sizeof(v4l2_event));
v4l2_event.type = UVC_EVENT_DISCONNECT;
v4l2_event_queue(&uvc->vdev, &v4l2_event);
uvc->state = UVC_STATE_DISCONNECTED;
usb_ep_disable(uvc->video.ep);
if (uvc->enable_interrupt_ep)
usb_ep_disable(uvc->interrupt_ep);
Annotation
- Immediate include surface: `linux/device.h`, `linux/errno.h`, `linux/fs.h`, `linux/kernel.h`, `linux/list.h`, `linux/module.h`, `linux/mutex.h`, `linux/string.h`.
- Detected declarations: `function uvc_function_ep0_complete`, `function uvc_function_setup`, `function uvc_function_setup_continue`, `function uvc_function_get_alt`, `function uvc_function_set_alt`, `function uvc_function_disable`, `function uvc_function_connect`, `function uvc_function_disconnect`, `function function_name_show`, `function uvc_vdev_release`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.