drivers/media/i2c/cvs/v4l2.c

Source file repositories/reference/linux-study-clean/drivers/media/i2c/cvs/v4l2.c

File Facts

System
Linux kernel
Corpus path
drivers/media/i2c/cvs/v4l2.c
Extension
.c
Size
16374 bytes
Lines
619
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

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (C) 2026 Intel Corporation
 * CVS driver - CSI/V4L2 subdev support
 */

#include <linux/cleanup.h>
#include <linux/device.h>
#include <linux/module.h>
#include <linux/pm_runtime.h>
#include <linux/property.h>

#include <media/v4l2-async.h>
#include <media/v4l2-common.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-event.h>
#include <media/v4l2-fwnode.h>
#include <media/v4l2-mc.h>
#include <media/v4l2-subdev.h>

#include "icvs.h"

/*
 * Helpers
 */
static inline struct icvs *notifier_to_csi(struct v4l2_async_notifier *n)
{
	return container_of(n, struct icvs, notifier);
}

static inline struct icvs *sd_to_csi(struct v4l2_subdev *sd)
{
	return container_of(sd, struct icvs, subdev);
}

/*
 * Default formats
 */
static const struct v4l2_mbus_framefmt cvs_csi_format_mbus_default = {
	.width = 1,
	.height = 1,
	.code = MEDIA_BUS_FMT_Y8_1X8,
	.field = V4L2_FIELD_NONE,
};

/**
 * csi_set_link_cfg - Program default CSI-2 link parameters
 * @ctx: CVS device context
 *
 * Populates a HOST_SET_MIPI_CONFIG command using current lane count and
 * link frequency, then submits it to the device.
 * Rest of the link parameters are left at firmware defaults.
 *
 * Return: 0 on success or negative errno.
 */
static int csi_set_link_cfg(struct icvs *ctx)
{
	struct icvs_cmd cmd = {
		.cmd_id = cpu_to_be16(ICVS_HOST_SET_MIPI_CONFIG),
		.param.conf.nr_of_lanes = ctx->nr_of_lanes,
		.param.conf.link_freq = ctx->link_freq,
	};
	size_t cmd_size = sizeof(cmd.cmd_id) + sizeof(cmd.param.conf);

	guard(mutex)(&ctx->lock);
	return cvs_send(ctx, &cmd, cmd_size);
}

/*
 * Streaming
 */

/**
 * cvs_csi_enable_streams - Start streaming through the bridge
 * @sd: Sub-device pointer
 * @state: Active state
 * @pad: Pad identifier (must be ICVS_CSI_PAD_SOURCE)
 * @streams_mask: Streams to enable (bit 0 supported)
 *
 * Runtime-resumes the bridge (triggering cvs_runtime_resume() to claim CSI-2
 * link ownership), fetches the link frequency, programs the MIPI configuration,
 * and forwards the enable request downstream.
 *
 * Return: 0 on success or negative errno.
 */
static int cvs_csi_enable_streams(struct v4l2_subdev *sd,
				  struct v4l2_subdev_state *state,
				  u32 pad, u64 streams_mask)
{
	struct icvs *ctx = sd_to_csi(sd);

Annotation

Implementation Notes