drivers/media/i2c/ov7670.c
Source file repositories/reference/linux-study-clean/drivers/media/i2c/ov7670.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/i2c/ov7670.c- Extension
.c- Size
- 54201 bytes
- Lines
- 2023
- 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/clk.hlinux/init.hlinux/mod_devicetable.hlinux/module.hlinux/slab.hlinux/i2c.hlinux/delay.hlinux/videodev2.hlinux/gpio/consumer.hmedia/v4l2-device.hmedia/v4l2-event.hmedia/v4l2-ctrls.hmedia/v4l2-fwnode.hmedia/v4l2-mediabus.hmedia/v4l2-image-sizes.hmedia/i2c/ov7670.h
Detected Declarations
struct ov7670_win_sizestruct ov7670_devtypestruct ov7670_format_structstruct ov7670_infostruct regval_listfunction ov7670_read_smbusfunction ov7670_write_smbusfunction ov7670_read_i2cfunction ov7670_write_i2cfunction ov7670_readfunction ov7670_writefunction ov7670_update_bitsfunction ov7670_write_arrayfunction ov7670_resetfunction ov7670_initfunction ov7670_detectfunction ov7675_get_frameratefunction ov7675_apply_frameratefunction ov7675_set_frameratefunction ov7670_get_framerate_legacyfunction ov7670_set_framerate_legacyfunction ov7670_set_hwfunction ov7670_enum_mbus_codefunction ov7670_try_fmt_internalfunction ov7670_apply_fmtfunction ov7670_set_fmtfunction ov7670_get_fmtfunction ov7670_get_frame_intervalfunction ov7670_set_frame_intervalfunction ov7670_enum_frame_intervalfunction ov7670_enum_frame_sizefunction ov7670_store_cmatrixfunction ov7670_sinefunction ov7670_cosinefunction ov7670_calc_cmatrixfunction ov7670_s_sat_huefunction ov7670_abs_to_smfunction ov7670_s_brightnessfunction ov7670_s_contrastfunction ov7670_s_hflipfunction ov7670_s_vflipfunction ov7670_g_gainfunction ov7670_s_gainfunction ov7670_s_autogainfunction ov7670_s_expfunction ov7670_s_autoexpfunction ov7670_s_test_patternfunction ov7670_g_volatile_ctrl
Annotated Snippet
struct ov7670_win_size {
int width;
int height;
unsigned char com7_bit;
int hstart; /* Start/stop values for the camera. Note */
int hstop; /* that they do not always make complete */
int vstart; /* sense to humans, but evidently the sensor */
int vstop; /* will do the right thing... */
struct regval_list *regs; /* Regs to tweak */
};
struct ov7670_devtype {
/* formats supported for each model */
struct ov7670_win_size *win_sizes;
unsigned int n_win_sizes;
/* callbacks for frame rate control */
int (*set_framerate)(struct v4l2_subdev *, struct v4l2_fract *);
void (*get_framerate)(struct v4l2_subdev *, struct v4l2_fract *);
};
/*
* Information we maintain about a known sensor.
*/
struct ov7670_format_struct; /* coming later */
struct ov7670_info {
struct v4l2_subdev sd;
struct media_pad pad;
struct v4l2_ctrl_handler hdl;
struct {
/* gain cluster */
struct v4l2_ctrl *auto_gain;
struct v4l2_ctrl *gain;
};
struct {
/* exposure cluster */
struct v4l2_ctrl *auto_exposure;
struct v4l2_ctrl *exposure;
};
struct {
/* saturation/hue cluster */
struct v4l2_ctrl *saturation;
struct v4l2_ctrl *hue;
};
struct v4l2_mbus_framefmt format;
struct ov7670_format_struct *fmt; /* Current format */
struct ov7670_win_size *wsize;
struct clk *clk;
int on;
struct gpio_desc *resetb_gpio;
struct gpio_desc *pwdn_gpio;
unsigned int mbus_config; /* Media bus configuration flags */
int min_width; /* Filter out smaller sizes */
int min_height; /* Filter out smaller sizes */
int clock_speed; /* External clock speed (MHz) */
u8 clkrc; /* Clock divider value */
bool use_smbus; /* Use smbus I/O instead of I2C */
bool pll_bypass;
bool pclk_hb_disable;
const struct ov7670_devtype *devtype; /* Device specifics */
};
static inline struct ov7670_info *to_state(struct v4l2_subdev *sd)
{
return container_of(sd, struct ov7670_info, sd);
}
static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
{
return &container_of(ctrl->handler, struct ov7670_info, hdl)->sd;
}
/*
* The default register settings, as obtained from OmniVision. There
* is really no making sense of most of these - lots of "reserved" values
* and such.
*
* These settings give VGA YUYV.
*/
struct regval_list {
unsigned char reg_num;
unsigned char value;
};
static struct regval_list ov7670_default_regs[] = {
{ REG_COM7, COM7_RESET },
/*
* Clock scale: 3 = 15fps
Annotation
- Immediate include surface: `linux/clk.h`, `linux/init.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/slab.h`, `linux/i2c.h`, `linux/delay.h`, `linux/videodev2.h`.
- Detected declarations: `struct ov7670_win_size`, `struct ov7670_devtype`, `struct ov7670_format_struct`, `struct ov7670_info`, `struct regval_list`, `function ov7670_read_smbus`, `function ov7670_write_smbus`, `function ov7670_read_i2c`, `function ov7670_write_i2c`, `function ov7670_read`.
- 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.