drivers/media/i2c/tw9903.c
Source file repositories/reference/linux-study-clean/drivers/media/i2c/tw9903.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/i2c/tw9903.c- Extension
.c- Size
- 6185 bytes
- Lines
- 263
- 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.hmedia/v4l2-device.hmedia/v4l2-ctrls.hlinux/slab.h
Detected Declarations
struct tw9903function write_regfunction write_regsfunction tw9903_s_video_routingfunction tw9903_s_stdfunction tw9903_s_ctrlfunction tw9903_log_statusfunction tw9903_probefunction tw9903_remove
Annotated Snippet
struct tw9903 {
struct v4l2_subdev sd;
struct v4l2_ctrl_handler hdl;
v4l2_std_id norm;
};
static inline struct tw9903 *to_state(struct v4l2_subdev *sd)
{
return container_of(sd, struct tw9903, sd);
}
static const u8 initial_registers[] = {
0x02, 0x44, /* input 1, composite */
0x03, 0x92, /* correct digital format */
0x04, 0x00,
0x05, 0x80, /* or 0x00 for PAL */
0x06, 0x40, /* second internal current reference */
0x07, 0x02, /* window */
0x08, 0x14, /* window */
0x09, 0xf0, /* window */
0x0a, 0x81, /* window */
0x0b, 0xd0, /* window */
0x0c, 0x8c,
0x0d, 0x00, /* scaling */
0x0e, 0x11, /* scaling */
0x0f, 0x00, /* scaling */
0x10, 0x00, /* brightness */
0x11, 0x60, /* contrast */
0x12, 0x01, /* sharpness */
0x13, 0x7f, /* U gain */
0x14, 0x5a, /* V gain */
0x15, 0x00, /* hue */
0x16, 0xc3, /* sharpness */
0x18, 0x00,
0x19, 0x58, /* vbi */
0x1a, 0x80,
0x1c, 0x0f, /* video norm */
0x1d, 0x7f, /* video norm */
0x20, 0xa0, /* clamping gain (working 0x50) */
0x21, 0x22,
0x22, 0xf0,
0x23, 0xfe,
0x24, 0x3c,
0x25, 0x38,
0x26, 0x44,
0x27, 0x20,
0x28, 0x00,
0x29, 0x15,
0x2a, 0xa0,
0x2b, 0x44,
0x2c, 0x37,
0x2d, 0x00,
0x2e, 0xa5, /* burst PLL control (working: a9) */
0x2f, 0xe0, /* 0xea is blue test frame -- 0xe0 for normal */
0x31, 0x00,
0x33, 0x22,
0x34, 0x11,
0x35, 0x35,
0x3b, 0x05,
0x06, 0xc0, /* reset device */
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 tw9903_s_video_routing(struct v4l2_subdev *sd, u32 input,
u32 output, u32 config)
{
write_reg(sd, 0x02, 0x40 | (input << 1));
return 0;
}
static int tw9903_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
{
struct tw9903 *dec = to_state(sd);
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/i2c.h`, `linux/videodev2.h`, `linux/ioctl.h`, `media/v4l2-device.h`, `media/v4l2-ctrls.h`, `linux/slab.h`.
- Detected declarations: `struct tw9903`, `function write_reg`, `function write_regs`, `function tw9903_s_video_routing`, `function tw9903_s_std`, `function tw9903_s_ctrl`, `function tw9903_log_status`, `function tw9903_probe`, `function tw9903_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.