drivers/media/test-drivers/vimc/vimc-sensor.c
Source file repositories/reference/linux-study-clean/drivers/media/test-drivers/vimc/vimc-sensor.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/test-drivers/vimc/vimc-sensor.c- Extension
.c- Size
- 14458 bytes
- Lines
- 508
- 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.
- 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/v4l2-mediabus.hlinux/vmalloc.hmedia/v4l2-ctrls.hmedia/v4l2-event.hmedia/v4l2-subdev.hmedia/tpg/v4l2-tpg.hvimc-common.h
Detected Declarations
function vimc_sensor_init_statefunction vimc_sensor_enum_mbus_codefunction vimc_sensor_enum_frame_sizefunction vimc_sensor_tpg_s_formatfunction vimc_sensor_update_frame_timingfunction vimc_sensor_adjust_fmtfunction vimc_calc_vblankfunction vimc_sensor_set_fmtfunction vimc_sensor_s_streamfunction vimc_sensor_s_ctrlfunction vimc_sensor_release
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* vimc-sensor.c Virtual Media Controller Driver
*
* Copyright (C) 2015-2017 Helen Koike <helen.fornazier@gmail.com>
*/
#include <linux/v4l2-mediabus.h>
#include <linux/vmalloc.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-event.h>
#include <media/v4l2-subdev.h>
#include <media/tpg/v4l2-tpg.h>
#include "vimc-common.h"
static const struct v4l2_mbus_framefmt fmt_default = {
.width = 640,
.height = 480,
.code = MEDIA_BUS_FMT_RGB888_1X24,
.field = V4L2_FIELD_NONE,
.colorspace = V4L2_COLORSPACE_SRGB,
};
static int vimc_sensor_init_state(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state)
{
struct vimc_sensor_device *vsensor =
container_of(sd, struct vimc_sensor_device, sd);
struct v4l2_mbus_framefmt *mf;
mf = v4l2_subdev_state_get_format(sd_state, 0);
*mf = fmt_default;
vsensor->hw.size.width = fmt_default.width;
vsensor->hw.size.height = fmt_default.height;
return 0;
}
static int vimc_sensor_enum_mbus_code(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_mbus_code_enum *code)
{
u32 mbus_code = vimc_mbus_code_by_index(code->index);
if (!mbus_code)
return -EINVAL;
code->code = mbus_code;
return 0;
}
static int vimc_sensor_enum_frame_size(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_frame_size_enum *fse)
{
const struct vimc_pix_map *vpix;
if (fse->index)
return -EINVAL;
/* Only accept code in the pix map table */
vpix = vimc_pix_map_by_code(fse->code);
if (!vpix)
return -EINVAL;
fse->min_width = VIMC_FRAME_MIN_WIDTH;
fse->max_width = VIMC_FRAME_MAX_WIDTH;
fse->min_height = VIMC_FRAME_MIN_HEIGHT;
fse->max_height = VIMC_FRAME_MAX_HEIGHT;
return 0;
}
static void vimc_sensor_tpg_s_format(struct vimc_sensor_device *vsensor,
const struct v4l2_mbus_framefmt *format)
{
const struct vimc_pix_map *vpix = vimc_pix_map_by_code(format->code);
tpg_reset_source(&vsensor->tpg, format->width, format->height,
format->field);
tpg_s_bytesperline(&vsensor->tpg, 0, format->width * vpix->bpp);
tpg_s_buf_height(&vsensor->tpg, format->height);
tpg_s_fourcc(&vsensor->tpg, vpix->pixelformat);
/* TODO: add support for V4L2_FIELD_ALTERNATE */
tpg_s_field(&vsensor->tpg, format->field, false);
tpg_s_colorspace(&vsensor->tpg, format->colorspace);
tpg_s_ycbcr_enc(&vsensor->tpg, format->ycbcr_enc);
Annotation
- Immediate include surface: `linux/v4l2-mediabus.h`, `linux/vmalloc.h`, `media/v4l2-ctrls.h`, `media/v4l2-event.h`, `media/v4l2-subdev.h`, `media/tpg/v4l2-tpg.h`, `vimc-common.h`.
- Detected declarations: `function vimc_sensor_init_state`, `function vimc_sensor_enum_mbus_code`, `function vimc_sensor_enum_frame_size`, `function vimc_sensor_tpg_s_format`, `function vimc_sensor_update_frame_timing`, `function vimc_sensor_adjust_fmt`, `function vimc_calc_vblank`, `function vimc_sensor_set_fmt`, `function vimc_sensor_s_stream`, `function vimc_sensor_s_ctrl`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source 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.