drivers/media/i2c/mt9m001.c
Source file repositories/reference/linux-study-clean/drivers/media/i2c/mt9m001.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/i2c/mt9m001.c- Extension
.c- Size
- 23487 bytes
- Lines
- 889
- 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/gpio/consumer.hlinux/i2c.hlinux/log2.hlinux/module.hlinux/pm_runtime.hlinux/slab.hlinux/videodev2.hmedia/v4l2-ctrls.hmedia/v4l2-device.hmedia/v4l2-event.hmedia/v4l2-subdev.h
Detected Declarations
struct mt9m001_datafmtstruct mt9m001struct mt9m001_regfunction reg_readfunction reg_writefunction reg_setfunction reg_clearfunction multi_reg_writefunction mt9m001_initfunction mt9m001_apply_selectionfunction mt9m001_s_streamfunction mt9m001_set_selectionfunction mt9m001_get_selectionfunction mt9m001_get_fmtfunction mt9m001_s_fmtfunction mt9m001_set_fmtfunction mt9m001_g_registerfunction mt9m001_s_registerfunction mt9m001_power_onfunction mt9m001_power_offfunction mt9m001_g_volatile_ctrlfunction mt9m001_s_ctrlfunction mt9m001_video_probefunction mt9m001_g_skip_top_linesfunction mt9m001_init_statefunction mt9m001_enum_mbus_codefunction mt9m001_get_mbus_configfunction mt9m001_probefunction mt9m001_remove
Annotated Snippet
struct mt9m001_datafmt {
u32 code;
enum v4l2_colorspace colorspace;
};
/* Find a data format by a pixel code in an array */
static const struct mt9m001_datafmt *mt9m001_find_datafmt(
u32 code, const struct mt9m001_datafmt *fmt,
int n)
{
int i;
for (i = 0; i < n; i++)
if (fmt[i].code == code)
return fmt + i;
return NULL;
}
static const struct mt9m001_datafmt mt9m001_colour_fmts[] = {
/*
* Order important: first natively supported,
* second supported with a GPIO extender
*/
{MEDIA_BUS_FMT_SBGGR10_1X10, V4L2_COLORSPACE_SRGB},
{MEDIA_BUS_FMT_SBGGR8_1X8, V4L2_COLORSPACE_SRGB},
};
static const struct mt9m001_datafmt mt9m001_monochrome_fmts[] = {
/* Order important - see above */
{MEDIA_BUS_FMT_Y10_1X10, V4L2_COLORSPACE_JPEG},
{MEDIA_BUS_FMT_Y8_1X8, V4L2_COLORSPACE_JPEG},
};
struct mt9m001 {
struct v4l2_subdev subdev;
struct v4l2_ctrl_handler hdl;
struct {
/* exposure/auto-exposure cluster */
struct v4l2_ctrl *autoexposure;
struct v4l2_ctrl *exposure;
};
struct mutex mutex;
struct v4l2_rect rect; /* Sensor window */
struct clk *clk;
struct gpio_desc *standby_gpio;
struct gpio_desc *reset_gpio;
const struct mt9m001_datafmt *fmt;
const struct mt9m001_datafmt *fmts;
int num_fmts;
unsigned int total_h;
unsigned short y_skip_top; /* Lines to skip at the top */
struct media_pad pad;
};
static struct mt9m001 *to_mt9m001(const struct i2c_client *client)
{
return container_of(i2c_get_clientdata(client), struct mt9m001, subdev);
}
static int reg_read(struct i2c_client *client, const u8 reg)
{
return i2c_smbus_read_word_swapped(client, reg);
}
static int reg_write(struct i2c_client *client, const u8 reg,
const u16 data)
{
return i2c_smbus_write_word_swapped(client, reg, data);
}
static int reg_set(struct i2c_client *client, const u8 reg,
const u16 data)
{
int ret;
ret = reg_read(client, reg);
if (ret < 0)
return ret;
return reg_write(client, reg, ret | data);
}
static int reg_clear(struct i2c_client *client, const u8 reg,
const u16 data)
{
int ret;
ret = reg_read(client, reg);
if (ret < 0)
return ret;
return reg_write(client, reg, ret & ~data);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/log2.h`, `linux/module.h`, `linux/pm_runtime.h`, `linux/slab.h`.
- Detected declarations: `struct mt9m001_datafmt`, `struct mt9m001`, `struct mt9m001_reg`, `function reg_read`, `function reg_write`, `function reg_set`, `function reg_clear`, `function multi_reg_write`, `function mt9m001_init`, `function mt9m001_apply_selection`.
- 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.