drivers/media/i2c/adv7170.c

Source file repositories/reference/linux-study-clean/drivers/media/i2c/adv7170.c

File Facts

System
Linux kernel
Corpus path
drivers/media/i2c/adv7170.c
Extension
.c
Size
10225 bytes
Lines
396
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 adv7170 {
	struct v4l2_subdev sd;
	unsigned char reg[128];

	v4l2_std_id norm;
	int input;
};

static inline struct adv7170 *to_adv7170(struct v4l2_subdev *sd)
{
	return container_of(sd, struct adv7170, sd);
}

static char *inputs[] = { "pass_through", "play_back" };

static u32 adv7170_codes[] = {
	MEDIA_BUS_FMT_UYVY8_2X8,
	MEDIA_BUS_FMT_UYVY8_1X16,
};

/* ----------------------------------------------------------------------- */

static inline int adv7170_write(struct v4l2_subdev *sd, u8 reg, u8 value)
{
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	struct adv7170 *encoder = to_adv7170(sd);

	encoder->reg[reg] = value;
	return i2c_smbus_write_byte_data(client, reg, value);
}

static inline int adv7170_read(struct v4l2_subdev *sd, u8 reg)
{
	struct i2c_client *client = v4l2_get_subdevdata(sd);

	return i2c_smbus_read_byte_data(client, reg);
}

static int adv7170_write_block(struct v4l2_subdev *sd,
		     const u8 *data, unsigned int len)
{
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	struct adv7170 *encoder = to_adv7170(sd);
	int ret = -1;
	u8 reg;

	/* the adv7170 has an autoincrement function, use it if
	 * the adapter understands raw I2C */
	if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
		/* do raw I2C, not smbus compatible */
		u8 block_data[32];
		int block_len;

		while (len >= 2) {
			block_len = 0;
			block_data[block_len++] = reg = data[0];
			do {
				block_data[block_len++] =
				    encoder->reg[reg++] = data[1];
				len -= 2;
				data += 2;
			} while (len >= 2 && data[0] == reg && block_len < 32);
			ret = i2c_master_send(client, block_data, block_len);
			if (ret < 0)
				break;
		}
	} else {
		/* do some slow I2C emulation kind of thing */
		while (len >= 2) {
			reg = *data++;
			ret = adv7170_write(sd, reg, *data++);
			if (ret < 0)
				break;
			len -= 2;
		}
	}
	return ret;
}

/* ----------------------------------------------------------------------- */

#define TR0MODE     0x4c
#define TR0RST	    0x80

#define TR1CAPT	    0x00
#define TR1PLAY	    0x00

static const unsigned char init_NTSC[] = {
	0x00, 0x10,		/* MR0 */
	0x01, 0x20,		/* MR1 */

Annotation

Implementation Notes