drivers/media/pci/mgb4/mgb4_sysfs_out.c

Source file repositories/reference/linux-study-clean/drivers/media/pci/mgb4/mgb4_sysfs_out.c

File Facts

System
Linux kernel
Corpus path
drivers/media/pci/mgb4/mgb4_sysfs_out.c
Extension
.c
Size
21594 bytes
Lines
826
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) 2021-2023 Digiteq Automotive
 *     author: Martin Tuma <martin.tuma@digiteqautomotive.com>
 *
 * This module handles all the sysfs info/configuration that is related to the
 * v4l2 output devices.
 */

#include <linux/device.h>
#include <linux/nospec.h>
#include "mgb4_core.h"
#include "mgb4_i2c.h"
#include "mgb4_vout.h"
#include "mgb4_vin.h"
#include "mgb4_cmt.h"
#include "mgb4_sysfs.h"

static int loopin_cnt(struct mgb4_vin_dev *vindev)
{
	struct mgb4_vout_dev *voutdev;
	u32 config;
	int i, cnt = 0;

	for (i = 0; i < MGB4_VOUT_DEVICES; i++) {
		voutdev = vindev->mgbdev->vout[i];
		if (!voutdev)
			continue;

		config = mgb4_read_reg(&voutdev->mgbdev->video,
				       voutdev->config->regs.config);
		if ((config & 0xc) >> 2 == vindev->config->id)
			cnt++;
	}

	return cnt;
}

static bool is_busy(struct video_device *dev)
{
	bool ret;

	mutex_lock(dev->lock);
	ret = vb2_is_busy(dev->queue);
	mutex_unlock(dev->lock);

	return ret;
}

/* Common for both FPDL3 and GMSL */

static ssize_t output_id_show(struct device *dev,
			      struct device_attribute *attr, char *buf)
{
	struct video_device *vdev = to_video_device(dev);
	struct mgb4_vout_dev *voutdev = video_get_drvdata(vdev);

	return sprintf(buf, "%d\n", voutdev->config->id);
}

static ssize_t video_source_show(struct device *dev,
				 struct device_attribute *attr, char *buf)
{
	struct video_device *vdev = to_video_device(dev);
	struct mgb4_vout_dev *voutdev = video_get_drvdata(vdev);
	u32 config = mgb4_read_reg(&voutdev->mgbdev->video,
	  voutdev->config->regs.config);

	return sprintf(buf, "%u\n", (config & 0xc) >> 2);
}

/*
 * Video source change may affect the buffer queue of ANY video input/output on
 * the card thus if any of the inputs/outputs is in use, we do not allow
 * the change.
 *
 * As we do not want to lock all the video devices at the same time, a two-stage
 * locking strategy is used. In addition to the video device locking there is
 * a global (PCI device) variable "io_reconfig" atomically checked/set when
 * the reconfiguration is running. All the video devices check the variable in
 * their queue_setup() functions and do not allow to start the queue when
 * the reconfiguration has started.
 */
static ssize_t video_source_store(struct device *dev,
				  struct device_attribute *attr,
				  const char *buf, size_t count)
{
	struct video_device *vdev = to_video_device(dev);
	struct mgb4_vout_dev *voutdev = video_get_drvdata(vdev);
	struct mgb4_dev *mgbdev = voutdev->mgbdev;

Annotation

Implementation Notes