drivers/media/platform/ti/cal/cal-video.c
Source file repositories/reference/linux-study-clean/drivers/media/platform/ti/cal/cal-video.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/platform/ti/cal/cal-video.c- Extension
.c- Size
- 28529 bytes
- Lines
- 1113
- Domain
- Driver Families
- Bucket
- drivers/media
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/ioctl.hlinux/pm_runtime.hlinux/videodev2.hmedia/media-device.hmedia/v4l2-common.hmedia/v4l2-ctrls.hmedia/v4l2-device.hmedia/v4l2-event.hmedia/v4l2-fh.hmedia/v4l2-ioctl.hmedia/videobuf2-core.hmedia/videobuf2-dma-contig.hcal.h
Detected Declarations
function Layerfunction cal_g_fmt_vid_capfunction cal_legacy_enum_fmt_vid_capfunction __subdev_get_formatfunction __subdev_set_formatfunction cal_calc_format_sizefunction cal_legacy_try_fmt_vid_capfunction cal_legacy_s_fmt_vid_capfunction cal_legacy_enum_framesizesfunction cal_legacy_enum_inputfunction cal_legacy_g_inputfunction cal_legacy_s_inputfunction cal_legacy_enum_frameintervalsfunction cal_legacy_g_parmfunction cal_legacy_s_parmfunction cal_mc_enum_fmt_vid_capfunction cal_mc_try_fmtfunction cal_mc_try_fmt_vid_capfunction cal_mc_s_fmt_vid_capfunction cal_mc_enum_framesizesfunction cal_queue_setupfunction cal_buffer_preparefunction cal_buffer_queuefunction cal_release_buffersfunction list_for_each_entry_safefunction cal_video_check_formatfunction cal_start_streamingfunction cal_stop_streamingfunction cal_ctx_v4l2_init_formatsfunction cal_ctx_v4l2_init_mc_formatfunction cal_ctx_v4l2_registerfunction cal_ctx_v4l2_unregisterfunction cal_ctx_v4l2_initfunction cal_ctx_v4l2_cleanup
Annotated Snippet
if (idx == f->index) {
f->pixelformat = cal_formats[i].fourcc;
f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
return 0;
}
idx++;
}
return -EINVAL;
}
static void cal_mc_try_fmt(struct cal_ctx *ctx, struct v4l2_format *f,
const struct cal_format_info **info)
{
struct v4l2_pix_format *format = &f->fmt.pix;
const struct cal_format_info *fmtinfo;
unsigned int bpp;
/*
* Default to the first format if the requested pixel format code isn't
* supported.
*/
fmtinfo = cal_format_by_fourcc(f->fmt.pix.pixelformat);
if (!fmtinfo || fmtinfo->meta)
fmtinfo = &cal_formats[0];
/*
* Clamp the size, update the pixel format. The field and colorspace are
* accepted as-is, except for V4L2_FIELD_ANY that is turned into
* V4L2_FIELD_NONE.
*/
bpp = ALIGN(fmtinfo->bpp, 8);
format->width = clamp_t(unsigned int, format->width,
CAL_MIN_WIDTH_BYTES * 8 / bpp,
CAL_MAX_WIDTH_BYTES * 8 / bpp);
format->height = clamp_t(unsigned int, format->height,
CAL_MIN_HEIGHT_LINES, CAL_MAX_HEIGHT_LINES);
format->pixelformat = fmtinfo->fourcc;
if (format->field == V4L2_FIELD_ANY)
format->field = V4L2_FIELD_NONE;
/*
* Calculate the number of bytes per line and the image size. The
* hardware stores the stride as a number of 16 bytes words, in a
* signed 15-bit value. Only 14 bits are thus usable.
*/
format->bytesperline = ALIGN(clamp(format->bytesperline,
format->width * bpp / 8,
((1U << 14) - 1) * 16), 16);
format->sizeimage = format->height * format->bytesperline;
format->colorspace = ctx->v_fmt.fmt.pix.colorspace;
if (info)
*info = fmtinfo;
ctx_dbg(3, ctx, "%s: %p4cc %ux%u (bytesperline %u sizeimage %u)\n",
__func__, &format->pixelformat,
format->width, format->height,
format->bytesperline, format->sizeimage);
}
static int cal_mc_try_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f)
{
struct cal_ctx *ctx = video_drvdata(file);
cal_mc_try_fmt(ctx, f, NULL);
return 0;
}
static int cal_mc_s_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_format *f)
{
struct cal_ctx *ctx = video_drvdata(file);
const struct cal_format_info *fmtinfo;
if (vb2_is_busy(&ctx->vb_vidq)) {
ctx_dbg(3, ctx, "%s device busy\n", __func__);
return -EBUSY;
}
cal_mc_try_fmt(ctx, f, &fmtinfo);
ctx->v_fmt = *f;
ctx->fmtinfo = fmtinfo;
Annotation
- Immediate include surface: `linux/ioctl.h`, `linux/pm_runtime.h`, `linux/videodev2.h`, `media/media-device.h`, `media/v4l2-common.h`, `media/v4l2-ctrls.h`, `media/v4l2-device.h`, `media/v4l2-event.h`.
- Detected declarations: `function Layer`, `function cal_g_fmt_vid_cap`, `function cal_legacy_enum_fmt_vid_cap`, `function __subdev_get_format`, `function __subdev_set_format`, `function cal_calc_format_size`, `function cal_legacy_try_fmt_vid_cap`, `function cal_legacy_s_fmt_vid_cap`, `function cal_legacy_enum_framesizes`, `function cal_legacy_enum_input`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source 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.