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.
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hmgb4_core.hmgb4_i2c.hmgb4_vin.hmgb4_cmt.hmgb4_sysfs.h
Detected Declarations
function Copyrightfunction oldi_lane_width_showfunction oldi_lane_width_storefunction color_mapping_showfunction color_mapping_storefunction link_status_showfunction stream_status_showfunction video_width_showfunction video_height_showfunction hsync_status_showfunction vsync_status_showfunction hsync_gap_length_showfunction hsync_gap_length_storefunction vsync_gap_length_showfunction vsync_gap_length_storefunction pclk_frequency_showfunction hsync_width_showfunction vsync_width_showfunction hback_porch_showfunction hfront_porch_showfunction vback_porch_showfunction vfront_porch_showfunction frequency_range_showfunction frequency_range_storefunction fpdl3_input_width_showfunction fpdl3_input_width_storefunction gmsl_mode_showfunction gmsl_mode_storefunction gmsl_stream_id_showfunction gmsl_stream_id_storefunction gmsl_fec_showfunction gmsl_fec_store
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
- Immediate include surface: `linux/device.h`, `mgb4_core.h`, `mgb4_i2c.h`, `mgb4_vin.h`, `mgb4_cmt.h`, `mgb4_sysfs.h`.
- Detected declarations: `function Copyright`, `function oldi_lane_width_show`, `function oldi_lane_width_store`, `function color_mapping_show`, `function color_mapping_store`, `function link_status_show`, `function stream_status_show`, `function video_width_show`, `function video_height_show`, `function hsync_status_show`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.