drivers/staging/media/tegra-video/vip.c

Source file repositories/reference/linux-study-clean/drivers/staging/media/tegra-video/vip.c

File Facts

System
Linux kernel
Corpus path
drivers/staging/media/tegra-video/vip.c
Extension
.c
Size
6932 bytes
Lines
282
Domain
Driver Families
Bucket
drivers/staging
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
/*
 * Parallel video capture module (VIP) for the Tegra VI.
 *
 * This file implements the VIP-specific infrastructure.
 *
 * Copyright (C) 2023 SKIDATA GmbH
 * Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
 */

#include <linux/device.h>
#include <linux/host1x.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_graph.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>

#include <media/v4l2-fwnode.h>

#include "vip.h"
#include "video.h"

static inline struct tegra_vip *host1x_client_to_vip(struct host1x_client *client)
{
	return container_of(client, struct tegra_vip, client);
}

static inline struct tegra_vip_channel *subdev_to_vip_channel(struct v4l2_subdev *subdev)
{
	return container_of(subdev, struct tegra_vip_channel, subdev);
}

static inline struct tegra_vip *vip_channel_to_vip(struct tegra_vip_channel *chan)
{
	return container_of(chan, struct tegra_vip, chan);
}

/* Find the previous subdev in the pipeline (i.e. the one connected to our sink pad) */
static struct v4l2_subdev *tegra_vip_channel_get_prev_subdev(struct tegra_vip_channel *chan)
{
	struct media_pad *remote_pad;

	remote_pad = media_pad_remote_pad_first(&chan->pads[TEGRA_VIP_PAD_SINK]);
	if (!remote_pad)
		return NULL;

	return media_entity_to_v4l2_subdev(remote_pad->entity);
}

static int tegra_vip_enable_stream(struct v4l2_subdev *subdev)
{
	struct tegra_vip_channel *vip_chan = subdev_to_vip_channel(subdev);
	struct tegra_vip *vip = vip_channel_to_vip(vip_chan);
	struct v4l2_subdev *prev_subdev = tegra_vip_channel_get_prev_subdev(vip_chan);
	int err;

	err = pm_runtime_resume_and_get(vip->dev);
	if (err)
		return dev_err_probe(vip->dev, err, "failed to get runtime PM\n");

	err = vip->soc->ops->vip_start_streaming(vip_chan);
	if (err < 0)
		goto err_start_streaming;

	err = v4l2_subdev_call(prev_subdev, video, s_stream, true);
	if (err < 0 && err != -ENOIOCTLCMD)
		goto err_prev_subdev_start_stream;

	return 0;

err_prev_subdev_start_stream:
err_start_streaming:
	pm_runtime_put(vip->dev);
	return err;
}

static int tegra_vip_disable_stream(struct v4l2_subdev *subdev)
{
	struct tegra_vip_channel *vip_chan = subdev_to_vip_channel(subdev);
	struct tegra_vip *vip = vip_channel_to_vip(vip_chan);
	struct v4l2_subdev *prev_subdev = tegra_vip_channel_get_prev_subdev(vip_chan);

	v4l2_subdev_call(prev_subdev, video, s_stream, false);

	pm_runtime_put(vip->dev);

	return 0;
}

Annotation

Implementation Notes