drivers/media/i2c/mt9p031.c
Source file repositories/reference/linux-study-clean/drivers/media/i2c/mt9p031.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/i2c/mt9p031.c- Extension
.c- Size
- 34041 bytes
- Lines
- 1249
- 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/device.hlinux/gpio/consumer.hlinux/i2c.hlinux/log2.hlinux/mod_devicetable.hlinux/module.hlinux/pm.hlinux/property.hlinux/regulator/consumer.hlinux/slab.hlinux/videodev2.hmedia/v4l2-async.hmedia/v4l2-ctrls.hmedia/v4l2-device.hmedia/v4l2-fwnode.hmedia/v4l2-subdev.haptina-pll.h
Detected Declarations
struct mt9p031_model_infostruct mt9p031function mt9p031_readfunction mt9p031_writefunction mt9p031_set_output_controlfunction mt9p031_set_mode2function mt9p031_resetfunction mt9p031_clk_setupfunction mt9p031_pll_enablefunction mt9p031_pll_disablefunction mt9p031_power_onfunction mt9p031_power_offfunction __mt9p031_set_powerfunction mt9p031_set_paramsfunction mt9p031_s_streamfunction mt9p031_enum_mbus_codefunction mt9p031_enum_frame_sizefunction __mt9p031_get_pad_formatfunction __mt9p031_get_pad_cropfunction mt9p031_get_formatfunction mt9p031_set_formatfunction mt9p031_get_selectionfunction mt9p031_set_selectionfunction mt9p031_init_statefunction mt9p031_restore_blcfunction mt9p031_s_ctrlfunction mt9p031_set_powerfunction mt9p031_registeredfunction mt9p031_openfunction mt9p031_closefunction mt9p031_parse_propertiesfunction mt9p031_probefunction mt9p031_remove
Annotated Snippet
struct mt9p031_model_info {
u32 code;
};
struct mt9p031 {
struct v4l2_subdev subdev;
struct media_pad pad;
struct v4l2_rect crop; /* Sensor window */
struct v4l2_mbus_framefmt format;
struct mutex power_lock; /* lock to protect power_count */
int power_count;
struct clk *clk;
struct regulator_bulk_data regulators[3];
unsigned int pixclk_pol:1;
int ext_freq;
int target_freq;
u32 code;
struct aptina_pll pll;
unsigned int clk_div;
bool use_pll;
struct gpio_desc *reset;
struct v4l2_ctrl_handler ctrls;
struct v4l2_ctrl *blc_auto;
struct v4l2_ctrl *blc_offset;
/* Registers cache */
u16 output_control;
u16 mode2;
};
static struct mt9p031 *to_mt9p031(struct v4l2_subdev *sd)
{
return container_of(sd, struct mt9p031, subdev);
}
static int mt9p031_read(struct i2c_client *client, u8 reg)
{
return i2c_smbus_read_word_swapped(client, reg);
}
static int mt9p031_write(struct i2c_client *client, u8 reg, u16 data)
{
return i2c_smbus_write_word_swapped(client, reg, data);
}
static int mt9p031_set_output_control(struct mt9p031 *mt9p031, u16 clear,
u16 set)
{
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
u16 value = (mt9p031->output_control & ~clear) | set;
int ret;
ret = mt9p031_write(client, MT9P031_OUTPUT_CONTROL, value);
if (ret < 0)
return ret;
mt9p031->output_control = value;
return 0;
}
static int mt9p031_set_mode2(struct mt9p031 *mt9p031, u16 clear, u16 set)
{
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
u16 value = (mt9p031->mode2 & ~clear) | set;
int ret;
ret = mt9p031_write(client, MT9P031_READ_MODE_2, value);
if (ret < 0)
return ret;
mt9p031->mode2 = value;
return 0;
}
static int mt9p031_reset(struct mt9p031 *mt9p031)
{
struct i2c_client *client = v4l2_get_subdevdata(&mt9p031->subdev);
int ret;
/* Disable chip output, synchronous option update */
ret = mt9p031_write(client, MT9P031_RST, MT9P031_RST_ENABLE);
if (ret < 0)
return ret;
ret = mt9p031_write(client, MT9P031_RST, 0);
if (ret < 0)
return ret;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/device.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/log2.h`, `linux/mod_devicetable.h`, `linux/module.h`.
- Detected declarations: `struct mt9p031_model_info`, `struct mt9p031`, `function mt9p031_read`, `function mt9p031_write`, `function mt9p031_set_output_control`, `function mt9p031_set_mode2`, `function mt9p031_reset`, `function mt9p031_clk_setup`, `function mt9p031_pll_enable`, `function mt9p031_pll_disable`.
- 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.