drivers/media/i2c/ak7375.c

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

File Facts

System
Linux kernel
Corpus path
drivers/media/i2c/ak7375.c
Extension
.c
Size
9272 bytes
Lines
358
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 ak73xx_chipdef {
	u8 reg_position;
	u8 reg_cont;
	u8 shift_pos;
	u8 mode_active;
	u8 mode_standby;
	bool has_standby;	/* Some chips may not have standby mode */
	u16 focus_pos_max;
	/*
	 * This sets the minimum granularity for the focus positions.
	 * A value of 1 gives maximum accuracy for a desired focus position
	 */
	u16 focus_steps;
	/*
	 * This acts as the minimum granularity of lens movement.
	 * Keep this value power of 2, so the control steps can be
	 * uniformly adjusted for gradual lens movement, with desired
	 * number of control steps.
	 */
	u16 ctrl_steps;
	u16 ctrl_delay_us;
	/*
	 * The vcm may take time (tDELAY) to power on and start taking
	 * I2C messages.
	 */
	u16 power_delay_us;
};

static const struct ak73xx_chipdef ak7345_cdef = {
	.reg_position	= 0x0,
	.reg_cont	= 0x2,
	.shift_pos	= 7,	/* 9 bits position values, need to << 7 */
	.mode_active	= 0x0,
	.has_standby	= false,
	.focus_pos_max	= 511,
	.focus_steps	= 1,
	.ctrl_steps	= 16,
	.ctrl_delay_us	= 1000,
	.power_delay_us	= 20000,
};

static const struct ak73xx_chipdef ak7375_cdef = {
	.reg_position	= 0x0,
	.reg_cont	= 0x2,
	.shift_pos	= 4,	/* 12 bits position values, need to << 4 */
	.mode_active	= 0x0,
	.mode_standby	= 0x40,
	.has_standby	= true,
	.focus_pos_max	= 4095,
	.focus_steps	= 1,
	.ctrl_steps	= 64,
	.ctrl_delay_us	= 1000,
	.power_delay_us	= 10000,
};

static const char * const ak7375_supply_names[] = {
	"vdd",
	"vio",
};

/* ak7375 device structure */
struct ak7375_device {
	const struct ak73xx_chipdef *cdef;
	struct v4l2_ctrl_handler ctrls_vcm;
	struct v4l2_subdev sd;
	struct v4l2_ctrl *focus;
	struct regulator_bulk_data supplies[ARRAY_SIZE(ak7375_supply_names)];

	/* active or standby mode */
	bool active;
};

static inline struct ak7375_device *to_ak7375_vcm(struct v4l2_ctrl *ctrl)
{
	return container_of(ctrl->handler, struct ak7375_device, ctrls_vcm);
}

static inline struct ak7375_device *sd_to_ak7375_vcm(struct v4l2_subdev *subdev)
{
	return container_of(subdev, struct ak7375_device, sd);
}

static int ak7375_i2c_write(struct ak7375_device *ak7375,
	u8 addr, u16 data, u8 size)
{
	struct i2c_client *client = v4l2_get_subdevdata(&ak7375->sd);
	u8 buf[3];
	int ret;

	if (size != 1 && size != 2)

Annotation

Implementation Notes