drivers/media/i2c/tw9906.c
Source file repositories/reference/linux-study-clean/drivers/media/i2c/tw9906.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/i2c/tw9906.c- Extension
.c- Size
- 5213 bytes
- Lines
- 231
- 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/init.hlinux/i2c.hlinux/videodev2.hlinux/ioctl.hlinux/slab.hmedia/v4l2-device.hmedia/v4l2-ctrls.h
Detected Declarations
struct tw9906function write_regfunction write_regsfunction tw9906_s_video_routingfunction tw9906_s_stdfunction tw9906_s_ctrlfunction tw9906_log_statusfunction tw9906_probefunction tw9906_remove
Annotated Snippet
struct tw9906 {
struct v4l2_subdev sd;
struct v4l2_ctrl_handler hdl;
v4l2_std_id norm;
};
static inline struct tw9906 *to_state(struct v4l2_subdev *sd)
{
return container_of(sd, struct tw9906, sd);
}
static const u8 initial_registers[] = {
0x02, 0x40, /* input 0, composite */
0x03, 0xa2, /* correct digital format */
0x05, 0x81, /* or 0x01 for PAL */
0x07, 0x02, /* window */
0x08, 0x14, /* window */
0x09, 0xf0, /* window */
0x0a, 0x10, /* window */
0x0b, 0xd0, /* window */
0x0d, 0x00, /* scaling */
0x0e, 0x11, /* scaling */
0x0f, 0x00, /* scaling */
0x10, 0x00, /* brightness */
0x11, 0x60, /* contrast */
0x12, 0x11, /* sharpness */
0x13, 0x7e, /* U gain */
0x14, 0x7e, /* V gain */
0x15, 0x00, /* hue */
0x19, 0x57, /* vbi */
0x1a, 0x0f,
0x1b, 0x40,
0x29, 0x03,
0x55, 0x00,
0x6b, 0x26,
0x6c, 0x36,
0x6d, 0xf0,
0x6e, 0x41,
0x6f, 0x13,
0xad, 0x70,
0x00, 0x00, /* Terminator (reg 0x00 is read-only) */
};
static int write_reg(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 int write_regs(struct v4l2_subdev *sd, const u8 *regs)
{
int i;
for (i = 0; regs[i] != 0x00; i += 2)
if (write_reg(sd, regs[i], regs[i + 1]) < 0)
return -1;
return 0;
}
static int tw9906_s_video_routing(struct v4l2_subdev *sd, u32 input,
u32 output, u32 config)
{
write_reg(sd, 0x02, 0x40 | (input << 1));
return 0;
}
static int tw9906_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
{
struct tw9906 *dec = to_state(sd);
bool is_60hz = norm & V4L2_STD_525_60;
static const u8 config_60hz[] = {
0x05, 0x81,
0x07, 0x02,
0x08, 0x14,
0x09, 0xf0,
0, 0,
};
static const u8 config_50hz[] = {
0x05, 0x01,
0x07, 0x12,
0x08, 0x18,
0x09, 0x20,
0, 0,
};
write_regs(sd, is_60hz ? config_60hz : config_50hz);
dec->norm = norm;
return 0;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/i2c.h`, `linux/videodev2.h`, `linux/ioctl.h`, `linux/slab.h`, `media/v4l2-device.h`, `media/v4l2-ctrls.h`.
- Detected declarations: `struct tw9906`, `function write_reg`, `function write_regs`, `function tw9906_s_video_routing`, `function tw9906_s_std`, `function tw9906_s_ctrl`, `function tw9906_log_status`, `function tw9906_probe`, `function tw9906_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.