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.

Dependency Surface

Detected Declarations

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

Implementation Notes