drivers/media/v4l2-core/v4l2-cci.c
Source file repositories/reference/linux-study-clean/drivers/media/v4l2-core/v4l2-cci.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/v4l2-core/v4l2-cci.c- Extension
.c- Size
- 4098 bytes
- Lines
- 204
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/delay.hlinux/dev_printk.hlinux/module.hlinux/regmap.hlinux/types.hlinux/unaligned.hmedia/v4l2-cci.h
Detected Declarations
function Interfacefunction cci_writefunction cci_update_bitsfunction cci_multi_reg_writeexport cci_readexport cci_writeexport cci_update_bitsexport cci_multi_reg_writeexport devm_cci_regmap_init_i2c
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* MIPI Camera Control Interface (CCI) register access helpers.
*
* Copyright (C) 2023 Hans de Goede <hansg@kernel.org>
*/
#include <linux/bitfield.h>
#include <linux/delay.h>
#include <linux/dev_printk.h>
#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/types.h>
#include <linux/unaligned.h>
#include <media/v4l2-cci.h>
int cci_read(struct regmap *map, u32 reg, u64 *val, int *err)
{
bool little_endian;
unsigned int len;
u8 buf[8];
int ret;
/*
* TODO: Fix smatch. Assign *val to 0 here in order to avoid
* failing a smatch check on caller when the caller proceeds to
* read *val without initialising it on caller's side. *val is set
* to a valid value whenever this function returns 0 but smatch
* can't figure that out currently.
*/
*val = 0;
if (err && *err)
return *err;
little_endian = reg & CCI_REG_LE;
len = CCI_REG_WIDTH_BYTES(reg);
reg = CCI_REG_ADDR(reg);
ret = regmap_bulk_read(map, reg, buf, len);
if (ret) {
dev_err(regmap_get_device(map), "Error reading reg 0x%04x: %d\n",
reg, ret);
goto out;
}
switch (len) {
case 1:
*val = buf[0];
break;
case 2:
if (little_endian)
*val = get_unaligned_le16(buf);
else
*val = get_unaligned_be16(buf);
break;
case 3:
if (little_endian)
*val = get_unaligned_le24(buf);
else
*val = get_unaligned_be24(buf);
break;
case 4:
if (little_endian)
*val = get_unaligned_le32(buf);
else
*val = get_unaligned_be32(buf);
break;
case 8:
if (little_endian)
*val = get_unaligned_le64(buf);
else
*val = get_unaligned_be64(buf);
break;
default:
dev_err(regmap_get_device(map), "Error invalid reg-width %u for reg 0x%04x\n",
len, reg);
ret = -EINVAL;
break;
}
out:
if (ret && err)
*err = ret;
return ret;
}
EXPORT_SYMBOL_GPL(cci_read);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/delay.h`, `linux/dev_printk.h`, `linux/module.h`, `linux/regmap.h`, `linux/types.h`, `linux/unaligned.h`, `media/v4l2-cci.h`.
- Detected declarations: `function Interface`, `function cci_write`, `function cci_update_bits`, `function cci_multi_reg_write`, `export cci_read`, `export cci_write`, `export cci_update_bits`, `export cci_multi_reg_write`, `export devm_cci_regmap_init_i2c`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: integration 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.