drivers/media/v4l2-core/v4l2-common.c
Source file repositories/reference/linux-study-clean/drivers/media/v4l2-core/v4l2-common.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/v4l2-core/v4l2-common.c- Extension
.c- Size
- 44137 bytes
- Lines
- 870
- 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.
- 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/clk.hlinux/clkdev.hlinux/clk-provider.hlinux/module.hlinux/types.hlinux/kernel.hlinux/mm.hlinux/string.hlinux/errno.hlinux/uaccess.hasm/io.hasm/div64.hmedia/v4l2-common.hmedia/v4l2-device.hmedia/v4l2-ctrls.hlinux/videodev2.h
Detected Declarations
function enhancementsfunction clamp_alignfunction clamp_roundupfunction v4l_bound_align_imagefunction __v4l2_find_nearest_size_conditionalfunction v4l2_g_parm_capfunction v4l2_s_parm_capfunction v4l2_format_block_widthfunction v4l2_format_block_heightfunction v4l2_format_plane_stridefunction v4l2_format_plane_heightfunction v4l2_format_plane_sizefunction v4l2_apply_frmsize_constraintsfunction v4l2_fill_pixfmt_mp_alignedfunction v4l2_fill_pixfmt_mpfunction v4l2_fill_pixfmtfunction v4l2_get_link_freq_ctrlfunction v4l2_get_link_freqfunction v4l2_get_active_data_lanesfunction v4l2_simplify_fractionfunction v4l2_fraction_to_intervalfunction v4l2_link_freq_to_bitmapexport v4l2_ctrl_query_fillexport v4l_bound_align_imageexport __v4l2_find_nearest_size_conditionalexport v4l2_g_parm_capexport v4l2_s_parm_capexport v4l2_format_infoexport v4l2_apply_frmsize_constraintsexport v4l2_fill_pixfmt_mp_alignedexport v4l2_fill_pixfmt_mpexport v4l2_fill_pixfmtexport v4l2_get_link_freqexport v4l2_get_active_data_lanesexport v4l2_simplify_fractionexport v4l2_fraction_to_intervalexport v4l2_link_freq_to_bitmapexport __devm_v4l2_sensor_clk_get
Annotated Snippet
if (an[n] >= threshold) {
if (n < 2)
n++;
break;
}
r = x - an[n] * y;
x = y;
y = r;
}
/* Expand the simple continued fraction back to an integer fraction. */
x = 0;
y = 1;
for (i = n; i > 0; --i) {
r = y;
y = an[i-1] * y + x;
x = r;
}
*numerator = y;
*denominator = x;
kfree(an);
}
EXPORT_SYMBOL_GPL(v4l2_simplify_fraction);
/*
* Convert a fraction to a frame interval in 100ns multiples. The idea here is
* to compute numerator / denominator * 10000000 using 32 bit fixed point
* arithmetic only.
*/
u32 v4l2_fraction_to_interval(u32 numerator, u32 denominator)
{
u32 multiplier;
/* Saturate the result if the operation would overflow. */
if (denominator == 0 ||
numerator/denominator >= ((u32)-1)/10000000)
return (u32)-1;
/*
* Divide both the denominator and the multiplier by two until
* numerator * multiplier doesn't overflow. If anyone knows a better
* algorithm please let me know.
*/
multiplier = 10000000;
while (numerator > ((u32)-1)/multiplier) {
multiplier /= 2;
denominator /= 2;
}
return denominator ? numerator * multiplier / denominator : 0;
}
EXPORT_SYMBOL_GPL(v4l2_fraction_to_interval);
int v4l2_link_freq_to_bitmap(struct device *dev, const u64 *fw_link_freqs,
unsigned int num_of_fw_link_freqs,
const s64 *driver_link_freqs,
unsigned int num_of_driver_link_freqs,
unsigned long *bitmap)
{
unsigned int i;
*bitmap = 0;
if (!num_of_fw_link_freqs) {
dev_err(dev, "no link frequencies in firmware\n");
return -ENODATA;
}
for (i = 0; i < num_of_fw_link_freqs; i++) {
unsigned int j;
for (j = 0; j < num_of_driver_link_freqs; j++) {
if (fw_link_freqs[i] != driver_link_freqs[j])
continue;
dev_dbg(dev, "enabling link frequency %lld Hz\n",
driver_link_freqs[j]);
*bitmap |= BIT(j);
break;
}
}
if (!*bitmap) {
dev_err(dev, "no matching link frequencies found\n");
dev_dbg(dev, "specified in firmware:\n");
for (i = 0; i < num_of_fw_link_freqs; i++)
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clkdev.h`, `linux/clk-provider.h`, `linux/module.h`, `linux/types.h`, `linux/kernel.h`, `linux/mm.h`, `linux/string.h`.
- Detected declarations: `function enhancements`, `function clamp_align`, `function clamp_roundup`, `function v4l_bound_align_image`, `function __v4l2_find_nearest_size_conditional`, `function v4l2_g_parm_cap`, `function v4l2_s_parm_cap`, `function v4l2_format_block_width`, `function v4l2_format_block_height`, `function v4l2_format_plane_stride`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: integration implementation candidate.
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.