drivers/media/i2c/cs3308.c
Source file repositories/reference/linux-study-clean/drivers/media/i2c/cs3308.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/i2c/cs3308.c- Extension
.c- Size
- 3281 bytes
- Lines
- 127
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/kernel.hlinux/i2c.hlinux/slab.hlinux/videodev2.hmedia/v4l2-device.h
Detected Declarations
function cs3308_writefunction cs3308_readfunction cs3308_g_registerfunction cs3308_s_registerfunction cs3308_probefunction cs3308_remove
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Cirrus Logic cs3308 8-Channel Analog Volume Control
*
* Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
* Copyright (C) 2012 Steven Toth <stoth@kernellabs.com>
*
* Derived from cs5345.c Copyright (C) 2007 Hans Verkuil
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/videodev2.h>
#include <media/v4l2-device.h>
MODULE_DESCRIPTION("i2c device driver for cs3308 8-channel volume control");
MODULE_AUTHOR("Devin Heitmueller");
MODULE_LICENSE("GPL");
static inline int cs3308_write(struct v4l2_subdev *sd, u8 reg, u8 value)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
return i2c_smbus_write_byte_data(client, reg, value);
}
static inline int cs3308_read(struct v4l2_subdev *sd, u8 reg)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
return i2c_smbus_read_byte_data(client, reg);
}
#ifdef CONFIG_VIDEO_ADV_DEBUG
static int cs3308_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
{
reg->val = cs3308_read(sd, reg->reg & 0xffff);
reg->size = 1;
return 0;
}
static int cs3308_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
{
cs3308_write(sd, reg->reg & 0xffff, reg->val & 0xff);
return 0;
}
#endif
/* ----------------------------------------------------------------------- */
static const struct v4l2_subdev_core_ops cs3308_core_ops = {
#ifdef CONFIG_VIDEO_ADV_DEBUG
.g_register = cs3308_g_register,
.s_register = cs3308_s_register,
#endif
};
static const struct v4l2_subdev_ops cs3308_ops = {
.core = &cs3308_core_ops,
};
/* ----------------------------------------------------------------------- */
static int cs3308_probe(struct i2c_client *client)
{
struct v4l2_subdev *sd;
unsigned i;
/* Check if the adapter supports the needed features */
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -EIO;
if ((i2c_smbus_read_byte_data(client, 0x1c) & 0xf0) != 0xe0)
return -ENODEV;
v4l_info(client, "chip found @ 0x%x (%s)\n",
client->addr << 1, client->adapter->name);
sd = kzalloc_obj(struct v4l2_subdev);
if (sd == NULL)
return -ENOMEM;
v4l2_i2c_subdev_init(sd, client, &cs3308_ops);
/* Set some reasonable defaults */
cs3308_write(sd, 0x0d, 0x00); /* Power up all channels */
cs3308_write(sd, 0x0e, 0x00); /* Master Power */
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/i2c.h`, `linux/slab.h`, `linux/videodev2.h`, `media/v4l2-device.h`.
- Detected declarations: `function cs3308_write`, `function cs3308_read`, `function cs3308_g_register`, `function cs3308_s_register`, `function cs3308_probe`, `function cs3308_remove`.
- 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.