drivers/media/platform/nxp/mx2_emmaprp.c

Source file repositories/reference/linux-study-clean/drivers/media/platform/nxp/mx2_emmaprp.c

File Facts

System
Linux kernel
Corpus path
drivers/media/platform/nxp/mx2_emmaprp.c
Extension
.c
Size
23939 bytes
Lines
906
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 emmaprp_fmt {
	u32	fourcc;
	/* Types the format can be used for */
	u32	types;
};

static struct emmaprp_fmt formats[] = {
	{
		.fourcc	= V4L2_PIX_FMT_YUV420,
		.types	= MEM2MEM_CAPTURE,
	},
	{
		.fourcc	= V4L2_PIX_FMT_YUYV,
		.types	= MEM2MEM_OUTPUT,
	},
};

/* Per-queue, driver-specific private data */
struct emmaprp_q_data {
	unsigned int		width;
	unsigned int		height;
	unsigned int		sizeimage;
	struct emmaprp_fmt	*fmt;
};

enum {
	V4L2_M2M_SRC = 0,
	V4L2_M2M_DST = 1,
};

#define NUM_FORMATS ARRAY_SIZE(formats)

static struct emmaprp_fmt *find_format(struct v4l2_format *f)
{
	struct emmaprp_fmt *fmt;
	unsigned int k;

	for (k = 0; k < NUM_FORMATS; k++) {
		fmt = &formats[k];
		if (fmt->fourcc == f->fmt.pix.pixelformat)
			break;
	}

	if (k == NUM_FORMATS)
		return NULL;

	return &formats[k];
}

struct emmaprp_dev {
	struct v4l2_device	v4l2_dev;
	struct video_device	*vfd;

	struct mutex		dev_mutex;
	spinlock_t		irqlock;

	void __iomem		*base_emma;
	struct clk		*clk_emma_ahb, *clk_emma_ipg;

	struct v4l2_m2m_dev	*m2m_dev;
};

struct emmaprp_ctx {
	struct v4l2_fh		fh;
	struct emmaprp_dev	*dev;
	/* Abort requested by m2m */
	int			aborting;
	struct emmaprp_q_data	q_data[2];
};

static inline struct emmaprp_ctx *file_to_emmaprp_ctx(struct file *filp)
{
	return container_of(file_to_v4l2_fh(filp), struct emmaprp_ctx, fh);
}

static struct emmaprp_q_data *get_q_data(struct emmaprp_ctx *ctx,
					 enum v4l2_buf_type type)
{
	switch (type) {
	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
		return &(ctx->q_data[V4L2_M2M_SRC]);
	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
		return &(ctx->q_data[V4L2_M2M_DST]);
	default:
		BUG();
	}
	return NULL;
}

/*

Annotation

Implementation Notes