drivers/media/test-drivers/vimc/vimc-scaler.c

Source file repositories/reference/linux-study-clean/drivers/media/test-drivers/vimc/vimc-scaler.c

File Facts

System
Linux kernel
Corpus path
drivers/media/test-drivers/vimc/vimc-scaler.c
Extension
.c
Size
11197 bytes
Lines
423
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct vimc_scaler_device {
	struct vimc_ent_device ved;
	struct v4l2_subdev sd;
	struct media_pad pads[2];

	u8 *src_frame;

	/*
	 * Virtual "hardware" configuration, filled when the stream starts or
	 * when controls are set.
	 */
	struct {
		struct v4l2_mbus_framefmt sink_fmt;
		struct v4l2_mbus_framefmt src_fmt;
		struct v4l2_rect sink_crop;
		unsigned int bpp;
	} hw;
};

static const struct v4l2_mbus_framefmt fmt_default = {
	.width = VIMC_SCALER_FMT_WIDTH_DEFAULT,
	.height = VIMC_SCALER_FMT_HEIGHT_DEFAULT,
	.code = MEDIA_BUS_FMT_RGB888_1X24,
	.field = V4L2_FIELD_NONE,
	.colorspace = V4L2_COLORSPACE_SRGB,
};

static const struct v4l2_rect crop_rect_default = {
	.width = VIMC_SCALER_FMT_WIDTH_DEFAULT,
	.height = VIMC_SCALER_FMT_HEIGHT_DEFAULT,
	.top = 0,
	.left = 0,
};

static const struct v4l2_rect crop_rect_min = {
	.width = VIMC_FRAME_MIN_WIDTH,
	.height = VIMC_FRAME_MIN_HEIGHT,
	.top = 0,
	.left = 0,
};

static struct v4l2_rect
vimc_scaler_get_crop_bound_sink(const struct v4l2_mbus_framefmt *sink_fmt)
{
	/* Get the crop bounds to clamp the crop rectangle correctly */
	struct v4l2_rect r = {
		.left = 0,
		.top = 0,
		.width = sink_fmt->width,
		.height = sink_fmt->height,
	};
	return r;
}

static int vimc_scaler_init_state(struct v4l2_subdev *sd,
				  struct v4l2_subdev_state *sd_state)
{
	struct v4l2_mbus_framefmt *mf;
	struct v4l2_rect *r;
	unsigned int i;

	for (i = 0; i < sd->entity.num_pads; i++) {
		mf = v4l2_subdev_state_get_format(sd_state, i);
		*mf = fmt_default;
	}

	r = v4l2_subdev_state_get_crop(sd_state, VIMC_SCALER_SINK);
	*r = crop_rect_default;

	return 0;
}

static int vimc_scaler_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);
	const struct vimc_pix_map *vpix;

	if (!mbus_code)
		return -EINVAL;

	vpix = vimc_pix_map_by_code(mbus_code);

	/* We don't support bayer format */
	if (!vpix || vpix->bayer)
		return -EINVAL;

	code->code = mbus_code;

Annotation

Implementation Notes