drivers/media/i2c/ar0521.c
Source file repositories/reference/linux-study-clean/drivers/media/i2c/ar0521.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/i2c/ar0521.c- Extension
.c- Size
- 34895 bytes
- Lines
- 1193
- 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/clk.hlinux/delay.hlinux/pm_runtime.hmedia/v4l2-ctrls.hmedia/v4l2-fwnode.hmedia/v4l2-subdev.h
Detected Declarations
struct ar0521_ctrlsstruct ar0521_devfunction div64_roundfunction div64_round_upfunction ar0521_code_to_bppfunction ar0521_write_regsfunction ar0521_write_regfunction ar0521_set_geometryfunction ar0521_set_gainsfunction calc_pllfunction ar0521_calc_pllfunction ar0521_pll_configfunction ar0521_set_streamfunction ar0521_adj_fmtfunction ar0521_get_fmtfunction ar0521_set_fmtfunction ar0521_s_ctrlfunction ar0521_init_controlsfunction __ar0521_power_offfunction ar0521_power_offfunction ar0521_power_onfunction ar0521_enum_mbus_codefunction ar0521_enum_frame_sizefunction ar0521_pre_streamonfunction ar0521_post_streamofffunction ar0521_s_streamfunction ar0521_probefunction ar0521_remove
Annotated Snippet
struct ar0521_ctrls {
struct v4l2_ctrl_handler handler;
struct {
struct v4l2_ctrl *gain;
struct v4l2_ctrl *red_balance;
struct v4l2_ctrl *blue_balance;
};
struct {
struct v4l2_ctrl *hblank;
struct v4l2_ctrl *vblank;
};
struct v4l2_ctrl *pixrate;
struct v4l2_ctrl *exposure;
struct v4l2_ctrl *test_pattern;
};
struct ar0521_dev {
struct i2c_client *i2c_client;
struct v4l2_subdev sd;
struct media_pad pad;
struct clk *extclk;
u32 extclk_freq;
struct regulator *supplies[ARRAY_SIZE(ar0521_supply_names)];
struct gpio_desc *reset_gpio;
/* lock to protect all members below */
struct mutex lock;
struct v4l2_mbus_framefmt fmt;
struct ar0521_ctrls ctrls;
unsigned int lane_count;
struct {
u16 pre;
u16 mult;
u16 pre2;
u16 mult2;
u16 vt_pix;
} pll;
};
static inline struct ar0521_dev *to_ar0521_dev(struct v4l2_subdev *sd)
{
return container_of(sd, struct ar0521_dev, sd);
}
static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl)
{
return &container_of(ctrl->handler, struct ar0521_dev,
ctrls.handler)->sd;
}
static u32 div64_round(u64 v, u32 d)
{
return div_u64(v + (d >> 1), d);
}
static u32 div64_round_up(u64 v, u32 d)
{
return div_u64(v + d - 1, d);
}
static int ar0521_code_to_bpp(struct ar0521_dev *sensor)
{
switch (sensor->fmt.code) {
case MEDIA_BUS_FMT_SGRBG8_1X8:
return 8;
}
return -EINVAL;
}
/* Data must be BE16, the first value is the register address */
static int ar0521_write_regs(struct ar0521_dev *sensor, const __be16 *data,
unsigned int count)
{
struct i2c_client *client = sensor->i2c_client;
struct i2c_msg msg;
int ret;
msg.addr = client->addr;
msg.flags = client->flags;
msg.buf = (u8 *)data;
msg.len = count * sizeof(*data);
ret = i2c_transfer(client->adapter, &msg, 1);
if (ret < 0) {
v4l2_err(&sensor->sd, "%s: I2C write error\n", __func__);
return ret;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/pm_runtime.h`, `media/v4l2-ctrls.h`, `media/v4l2-fwnode.h`, `media/v4l2-subdev.h`.
- Detected declarations: `struct ar0521_ctrls`, `struct ar0521_dev`, `function div64_round`, `function div64_round_up`, `function ar0521_code_to_bpp`, `function ar0521_write_regs`, `function ar0521_write_reg`, `function ar0521_set_geometry`, `function ar0521_set_gains`, `function calc_pll`.
- 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.