drivers/media/i2c/dw9807-vcm.c
Source file repositories/reference/linux-study-clean/drivers/media/i2c/dw9807-vcm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/i2c/dw9807-vcm.c- Extension
.c- Size
- 8307 bytes
- Lines
- 322
- 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/acpi.hlinux/delay.hlinux/i2c.hlinux/iopoll.hlinux/module.hlinux/pm_runtime.hmedia/v4l2-ctrls.hmedia/v4l2-device.h
Detected Declarations
struct dw9807_devicefunction dw9807_i2c_checkfunction dw9807_set_dacfunction dw9807_set_ctrlfunction dw9807_openfunction dw9807_closefunction dw9807_subdev_cleanupfunction dw9807_init_controlsfunction dw9807_probefunction dw9807_removefunction dw9807_vcm_suspendfunction dw9807_vcm_resume
Annotated Snippet
struct dw9807_device {
struct v4l2_ctrl_handler ctrls_vcm;
struct v4l2_subdev sd;
u16 current_val;
};
static inline struct dw9807_device *sd_to_dw9807_vcm(
struct v4l2_subdev *subdev)
{
return container_of(subdev, struct dw9807_device, sd);
}
static int dw9807_i2c_check(struct i2c_client *client)
{
const char status_addr = DW9807_STATUS_ADDR;
char status_result;
int ret;
ret = i2c_master_send(client, &status_addr, sizeof(status_addr));
if (ret < 0) {
dev_err(&client->dev, "I2C write STATUS address fail ret = %d\n",
ret);
return ret;
}
ret = i2c_master_recv(client, &status_result, sizeof(status_result));
if (ret < 0) {
dev_err(&client->dev, "I2C read STATUS value fail ret = %d\n",
ret);
return ret;
}
return status_result;
}
static int dw9807_set_dac(struct i2c_client *client, u16 data)
{
const char tx_data[3] = {
DW9807_MSB_ADDR, ((data >> 8) & 0x03), (data & 0xff)
};
int val, ret;
/*
* According to the datasheet, need to check the bus status before we
* write VCM position. This ensure that we really write the value
* into the register
*/
ret = readx_poll_timeout(dw9807_i2c_check, client, val, val <= 0,
DW9807_CTRL_DELAY_US, MAX_RETRY * DW9807_CTRL_DELAY_US);
if (ret || val < 0) {
if (ret) {
dev_warn(&client->dev,
"Cannot do the write operation because VCM is busy\n");
}
return ret ? -EBUSY : val;
}
/* Write VCM position to registers */
ret = i2c_master_send(client, tx_data, sizeof(tx_data));
if (ret < 0) {
dev_err(&client->dev,
"I2C write MSB fail ret=%d\n", ret);
return ret;
}
return 0;
}
static int dw9807_set_ctrl(struct v4l2_ctrl *ctrl)
{
struct dw9807_device *dev_vcm = container_of(ctrl->handler,
struct dw9807_device, ctrls_vcm);
if (ctrl->id == V4L2_CID_FOCUS_ABSOLUTE) {
struct i2c_client *client = v4l2_get_subdevdata(&dev_vcm->sd);
dev_vcm->current_val = ctrl->val;
return dw9807_set_dac(client, ctrl->val);
}
return -EINVAL;
}
static const struct v4l2_ctrl_ops dw9807_vcm_ctrl_ops = {
.s_ctrl = dw9807_set_ctrl,
};
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/delay.h`, `linux/i2c.h`, `linux/iopoll.h`, `linux/module.h`, `linux/pm_runtime.h`, `media/v4l2-ctrls.h`, `media/v4l2-device.h`.
- Detected declarations: `struct dw9807_device`, `function dw9807_i2c_check`, `function dw9807_set_dac`, `function dw9807_set_ctrl`, `function dw9807_open`, `function dw9807_close`, `function dw9807_subdev_cleanup`, `function dw9807_init_controls`, `function dw9807_probe`, `function dw9807_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.