drivers/media/pci/mgb4/mgb4_sysfs_in.c

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

File Facts

System
Linux kernel
Corpus path
drivers/media/pci/mgb4/mgb4_sysfs_in.c
Extension
.c
Size
22042 bytes
Lines
814
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 input devices.
 */

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

/* Common for both FPDL3 and GMSL */

static ssize_t input_id_show(struct device *dev,
			     struct device_attribute *attr, char *buf)
{
	struct video_device *vdev = to_video_device(dev);
	struct mgb4_vin_dev *vindev = video_get_drvdata(vdev);

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

static ssize_t oldi_lane_width_show(struct device *dev,
				    struct device_attribute *attr, char *buf)
{
	struct video_device *vdev = to_video_device(dev);
	struct mgb4_vin_dev *vindev = video_get_drvdata(vdev);
	struct mgb4_dev *mgbdev = vindev->mgbdev;
	u16 i2c_reg;
	u8 i2c_mask, i2c_single_val, i2c_dual_val;
	u32 config;
	int ret;

	if (MGB4_IS_GMSL1(mgbdev))
		return sprintf(buf, "0\n");

	i2c_reg = MGB4_IS_GMSL3(mgbdev) ? 0x1CE : 0x49;
	i2c_mask = MGB4_IS_GMSL3(mgbdev) ? 0x0E : 0x03;
	i2c_single_val = MGB4_IS_GMSL3(mgbdev) ? 0x00 : 0x02;
	i2c_dual_val = MGB4_IS_GMSL3(mgbdev) ? 0x0E : 0x00;

	mutex_lock(&mgbdev->i2c_lock);
	ret = mgb4_i2c_read_byte(&vindev->deser, i2c_reg);
	mutex_unlock(&mgbdev->i2c_lock);
	if (ret < 0)
		return -EIO;

	config = mgb4_read_reg(&mgbdev->video, vindev->config->regs.config);

	if (((config & (1U << 9)) && ((ret & i2c_mask) != i2c_dual_val)) ||
	    (!(config & (1U << 9)) && ((ret & i2c_mask) != i2c_single_val))) {
		dev_err(dev, "I2C/FPGA register value mismatch\n");
		return -EINVAL;
	}

	return sprintf(buf, "%s\n", config & (1U << 9) ? "1" : "0");
}

/*
 * OLDI lane width change is expected to be called on live streams. Video device
 * locking/queue check is not needed.
 */
static ssize_t oldi_lane_width_store(struct device *dev,
				     struct device_attribute *attr,
				     const char *buf, size_t count)
{
	struct video_device *vdev = to_video_device(dev);
	struct mgb4_vin_dev *vindev = video_get_drvdata(vdev);
	struct mgb4_dev *mgbdev = vindev->mgbdev;
	u32 fpga_data;
	u16 i2c_reg;
	u8 i2c_mask, i2c_data;
	unsigned long val;
	int ret;

	ret = kstrtoul(buf, 10, &val);
	if (ret)
		return ret;

	if (MGB4_IS_GMSL1(mgbdev))
		return val ? -EINVAL : count;

	switch (val) {
	case 0: /* single */
		fpga_data = 0;

Annotation

Implementation Notes