drivers/media/pci/mgb4/mgb4_i2c.c
Source file repositories/reference/linux-study-clean/drivers/media/pci/mgb4/mgb4_i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/pci/mgb4/mgb4_i2c.c- Extension
.c- Size
- 2782 bytes
- Lines
- 141
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
mgb4_i2c.h
Detected Declarations
function Copyrightfunction write_r16function mgb4_i2c_initfunction mgb4_i2c_freefunction mgb4_i2c_read_bytefunction mgb4_i2c_write_bytefunction mgb4_i2c_mask_bytefunction mgb4_i2c_configure
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2021-2023 Digiteq Automotive
* author: Martin Tuma <martin.tuma@digiteqautomotive.com>
*
* The i2c module unifies the I2C access to the serializes/deserializes. The I2C
* chips on the GMSL module use 16b addressing, the FPDL3 chips use standard
* 8b addressing.
*/
#include "mgb4_i2c.h"
static int read_r16(struct i2c_client *client, u16 reg, u8 *val, int len)
{
int ret;
u8 buf[2];
struct i2c_msg msg[2] = {
{
.addr = client->addr,
.flags = 0,
.len = 2,
.buf = buf,
}, {
.addr = client->addr,
.flags = I2C_M_RD,
.len = len,
.buf = val,
}
};
buf[0] = (reg >> 8) & 0xff;
buf[1] = (reg >> 0) & 0xff;
ret = i2c_transfer(client->adapter, msg, 2);
if (ret < 0)
return ret;
else if (ret != 2)
return -EREMOTEIO;
else
return 0;
}
static int write_r16(struct i2c_client *client, u16 reg, const u8 *val, int len)
{
int ret;
u8 buf[4];
struct i2c_msg msg[1] = {
{
.addr = client->addr,
.flags = 0,
.len = 2 + len,
.buf = buf,
}
};
if (2 + len > sizeof(buf))
return -EINVAL;
buf[0] = (reg >> 8) & 0xff;
buf[1] = (reg >> 0) & 0xff;
memcpy(&buf[2], val, len);
ret = i2c_transfer(client->adapter, msg, 1);
if (ret < 0)
return ret;
else if (ret != 1)
return -EREMOTEIO;
else
return 0;
}
int mgb4_i2c_init(struct mgb4_i2c_client *client, struct i2c_adapter *adap,
struct i2c_board_info const *info, int addr_size)
{
client->client = i2c_new_client_device(adap, info);
if (IS_ERR(client->client))
return PTR_ERR(client->client);
client->addr_size = addr_size;
return 0;
}
void mgb4_i2c_free(struct mgb4_i2c_client *client)
{
i2c_unregister_device(client->client);
}
s32 mgb4_i2c_read_byte(struct mgb4_i2c_client *client, u16 reg)
{
Annotation
- Immediate include surface: `mgb4_i2c.h`.
- Detected declarations: `function Copyright`, `function write_r16`, `function mgb4_i2c_init`, `function mgb4_i2c_free`, `function mgb4_i2c_read_byte`, `function mgb4_i2c_write_byte`, `function mgb4_i2c_mask_byte`, `function mgb4_i2c_configure`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
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.