drivers/media/usb/gspca/gspca.c
Source file repositories/reference/linux-study-clean/drivers/media/usb/gspca/gspca.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/usb/gspca/gspca.c- Extension
.c- Size
- 44058 bytes
- Lines
- 1702
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/init.hlinux/fs.hlinux/vmalloc.hlinux/sched.hlinux/slab.hlinux/mm.hlinux/string.hlinux/pagemap.hlinux/io.hasm/page.hlinux/uaccess.hlinux/ktime.hmedia/v4l2-ioctl.hmedia/v4l2-ctrls.hmedia/v4l2-fh.hmedia/v4l2-event.hgspca.hlinux/input.hlinux/usb/input.h
Detected Declarations
struct ep_tb_sfunction PDEBUG_MODEfunction int_irqfunction gspca_input_connectfunction alloc_and_submit_int_urbfunction gspca_input_create_urbfunction gspca_input_destroy_urbfunction gspca_input_destroy_urbfunction fill_framefunction isoc_irqfunction bulk_irqfunction gspca_frame_addfunction destroy_urbsfunction gspca_set_alt0function which_bandwidthfunction build_isoc_ep_tbfunction create_urbsfunction gspca_stream_offfunction gspca_init_transferfunction gspca_set_default_modefunction wxh_to_modefunction wxh_to_nearest_modefunction gspca_get_modefunction vidioc_g_chip_infofunction vidioc_g_registerfunction vidioc_s_registerfunction vidioc_enum_fmt_vid_capfunction vidioc_g_fmt_vid_capfunction try_fmt_vid_capfunction vidioc_try_fmt_vid_capfunction vidioc_s_fmt_vid_capfunction vidioc_enum_framesizesfunction vidioc_enum_frameintervalsfunction gspca_releasefunction vidioc_querycapfunction vidioc_enum_inputfunction vidioc_g_inputfunction vidioc_s_inputfunction vidioc_g_jpegcompfunction vidioc_s_jpegcompfunction vidioc_g_parmfunction vidioc_s_parmfunction gspca_queue_setupfunction gspca_buffer_preparefunction gspca_buffer_finishfunction gspca_buffer_queuefunction gspca_return_all_buffersfunction gspca_start_streaming
Annotated Snippet
struct ep_tb_s {
u32 alt;
u32 bandwidth;
};
/*
* build the table of the endpoints
* and compute the minimum bandwidth for the image transfer
*/
static int build_isoc_ep_tb(struct gspca_dev *gspca_dev,
struct usb_interface *intf,
struct ep_tb_s *ep_tb)
{
struct usb_host_endpoint *ep;
int i, j, nbalt, psize, found;
u32 bandwidth, last_bw;
nbalt = intf->num_altsetting;
if (nbalt > MAX_ALT)
nbalt = MAX_ALT; /* fixme: should warn */
/* build the endpoint table */
i = 0;
last_bw = 0;
for (;;) {
ep_tb->bandwidth = 2000 * 2000 * 120;
found = 0;
for (j = 0; j < nbalt; j++) {
ep = alt_xfer(&intf->altsetting[j],
USB_ENDPOINT_XFER_ISOC,
gspca_dev->xfer_ep);
if (ep == NULL)
continue;
if (ep->desc.bInterval == 0) {
pr_err("alt %d iso endp with 0 interval\n", j);
continue;
}
psize = le16_to_cpu(ep->desc.wMaxPacketSize);
psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
bandwidth = psize * 1000;
if (gspca_dev->dev->speed == USB_SPEED_HIGH
|| gspca_dev->dev->speed >= USB_SPEED_SUPER)
bandwidth *= 8;
bandwidth /= 1 << (ep->desc.bInterval - 1);
if (bandwidth <= last_bw)
continue;
if (bandwidth < ep_tb->bandwidth) {
ep_tb->bandwidth = bandwidth;
ep_tb->alt = j;
found = 1;
}
}
if (!found)
break;
gspca_dbg(gspca_dev, D_STREAM, "alt %d bandwidth %d\n",
ep_tb->alt, ep_tb->bandwidth);
last_bw = ep_tb->bandwidth;
i++;
ep_tb++;
}
/*
* If the camera:
* has a usb audio class interface (a built in usb mic); and
* is a usb 1 full speed device; and
* uses the max full speed iso bandwidth; and
* and has more than 1 alt setting
* then skip the highest alt setting to spare bandwidth for the mic
*/
if (gspca_dev->audio &&
gspca_dev->dev->speed == USB_SPEED_FULL &&
last_bw >= 1000000 &&
i > 1) {
gspca_dbg(gspca_dev, D_STREAM, "dev has usb audio, skipping highest alt\n");
i--;
ep_tb--;
}
/* get the requested bandwidth and start at the highest atlsetting */
bandwidth = which_bandwidth(gspca_dev);
ep_tb--;
while (i > 1) {
ep_tb--;
if (ep_tb->bandwidth < bandwidth)
break;
i--;
}
return i;
}
Annotation
- Immediate include surface: `linux/init.h`, `linux/fs.h`, `linux/vmalloc.h`, `linux/sched.h`, `linux/slab.h`, `linux/mm.h`, `linux/string.h`, `linux/pagemap.h`.
- Detected declarations: `struct ep_tb_s`, `function PDEBUG_MODE`, `function int_irq`, `function gspca_input_connect`, `function alloc_and_submit_int_urb`, `function gspca_input_create_urb`, `function gspca_input_destroy_urb`, `function gspca_input_destroy_urb`, `function fill_frame`, `function isoc_irq`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.