drivers/media/i2c/tw9900.c
Source file repositories/reference/linux-study-clean/drivers/media/i2c/tw9900.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/i2c/tw9900.c- Extension
.c- Size
- 17362 bytes
- Lines
- 782
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/bitfield.hlinux/clk.hlinux/delay.hlinux/device.hlinux/gpio/consumer.hlinux/i2c.hlinux/module.hlinux/pm_runtime.hlinux/regulator/consumer.hmedia/media-entity.hmedia/v4l2-async.hmedia/v4l2-ctrls.hmedia/v4l2-event.hmedia/v4l2-subdev.h
Detected Declarations
struct regvalstruct tw9900_modestruct tw9900function tw9900_write_regfunction tw9900_write_arrayfunction tw9900_read_regfunction tw9900_fill_fmtfunction tw9900_get_fmtfunction tw9900_set_fmtfunction tw9900_enum_mbus_codefunction tw9900_s_ctrlfunction tw9900_s_streamfunction tw9900_subscribe_eventfunction tw9900_s_stdfunction tw9900_get_stream_stdfunction tw9900_g_stdfunction tw9900_start_autodetectfunction tw9900_detect_donefunction tw9900_querystdfunction tw9900_g_tvnormsfunction tw9900_g_input_statusfunction tw9900_check_idfunction tw9900_runtime_resumefunction tw9900_runtime_suspendfunction tw9900_probefunction tw9900_remove
Annotated Snippet
struct regval {
u8 addr;
u8 val;
};
struct tw9900_mode {
u32 width;
u32 height;
u32 std;
const struct regval *reg_list;
int n_regs;
};
struct tw9900 {
struct i2c_client *client;
struct gpio_desc *reset_gpio;
struct regulator *regulator;
struct v4l2_subdev subdev;
struct v4l2_ctrl_handler hdl;
struct media_pad pad;
/* Serialize access to hardware and global state. */
struct mutex mutex;
bool streaming;
const struct tw9900_mode *cur_mode;
};
#define to_tw9900(sd) container_of(sd, struct tw9900, subdev)
static const struct regval tw9900_init_regs[] = {
{ TW9900_REG_MISC_CTL_II, 0xE6 },
{ TW9900_REG_MISSCNT, 0x24 },
{ TW9900_REG_OUT_FMT_CTL, 0xA7 },
{ TW9900_REG_ANAL_CTL_II, 0x0A },
{ TW9900_REG_VDELAY_LO, 0x19 },
{ TW9900_REG_STD, 0x00 },
{ TW9900_REG_VACTIVE_LO, 0xF0 },
{ TW9900_REG_STD, 0x07 },
{ TW9900_REG_CKHY_HSDLY, 0x00 },
{ TW9900_REG_ANALOG_CTL, 0x80 },
{ TW9900_REG_CNTRL1, 0xDC },
{ TW9900_REG_OUT_CTRL_I, 0x98 },
};
static const struct regval tw9900_pal_regs[] = {
{ TW9900_REG_STD, 0x01 },
};
static const struct regval tw9900_ntsc_regs[] = {
{ TW9900_REG_OUT_FMT_CTL, 0xA4 },
{ TW9900_REG_VDELAY_LO, 0x12 },
{ TW9900_REG_VACTIVE_LO, 0xF0 },
{ TW9900_REG_CROP_HI, 0x02 },
{ TW9900_REG_HACTIVE_LO, 0xD0 },
{ TW9900_REG_VBI_CNTL, 0x01 },
{ TW9900_REG_STD, 0x00 },
};
static const struct tw9900_mode supported_modes[] = {
{
.width = 720,
.height = 480,
.std = V4L2_STD_NTSC,
.reg_list = tw9900_ntsc_regs,
.n_regs = ARRAY_SIZE(tw9900_ntsc_regs),
},
{
.width = 720,
.height = 576,
.std = V4L2_STD_PAL,
.reg_list = tw9900_pal_regs,
.n_regs = ARRAY_SIZE(tw9900_pal_regs),
},
};
static int tw9900_write_reg(struct i2c_client *client, u8 reg, u8 val)
{
int ret;
ret = i2c_smbus_write_byte_data(client, reg, val);
if (ret < 0)
dev_err(&client->dev, "write reg error: %d\n", ret);
return ret;
}
static int tw9900_write_array(struct i2c_client *client,
const struct regval *regs, int n_regs)
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk.h`, `linux/delay.h`, `linux/device.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/module.h`, `linux/pm_runtime.h`.
- Detected declarations: `struct regval`, `struct tw9900_mode`, `struct tw9900`, `function tw9900_write_reg`, `function tw9900_write_array`, `function tw9900_read_reg`, `function tw9900_fill_fmt`, `function tw9900_get_fmt`, `function tw9900_set_fmt`, `function tw9900_enum_mbus_code`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.