drivers/media/i2c/ov2732.c

Source file repositories/reference/linux-study-clean/drivers/media/i2c/ov2732.c

File Facts

System
Linux kernel
Corpus path
drivers/media/i2c/ov2732.c
Extension
.c
Size
21086 bytes
Lines
791
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ov2732_mode {
	u32 width;
	u32 height;
	u32 vts;
};

static const struct ov2732_mode supported_modes[] = {
	{
		.width = 1920,
		.height = 1080,
		.vts = 1184,
	},
};

struct ov2732 {
	struct device *dev;
	struct regmap *regmap;

	struct media_pad pad;
	struct v4l2_subdev sd;
	struct v4l2_ctrl_handler ctrl_handler;
	struct v4l2_ctrl *hblank;
	struct v4l2_ctrl *vblank;
	struct v4l2_ctrl *exposure;

	struct clk *xvclk;
	u32 xvclk_freq;
	struct gpio_desc *powerdown_gpio;
	struct gpio_desc *reset_gpio;
	struct regulator_bulk_data supplies[ARRAY_SIZE(ov2732_supply_names)];
};

#define to_ov2732(_sd) container_of(_sd, struct ov2732, sd)

static const s64 link_freq_menu_items[] = {
	OV2732_LINK_FREQ_DEFAULT,
};

static const char * const ov2732_test_pattern_menu[] = {
	"Disabled",
	"Vertical Color Bar Type 1",
	"Vertical Color Bar Type 2",
	"Vertical Color Bar Type 3",
	"Vertical Color Bar Type 4",
	"Vertical Color Bar Type 5",
	"Random",
	"Color Squares",
	"Black and White Squares",
};

static const int ov2732_test_pattern_val[] = {
	OV2732_TEST_PATTERN_DISABLE,
	OV2732_TEST_PATTERN_BAR1,
	OV2732_TEST_PATTERN_BAR2,
	OV2732_TEST_PATTERN_BAR3,
	OV2732_TEST_PATTERN_BAR4,
	OV2732_TEST_PATTERN_BAR5,
	OV2732_TEST_PATTERN_RANDOM,
	OV2732_TEST_PATTERN_SQUARES_C,
	OV2732_TEST_PATTERN_SQUARES_BW,
};

static int ov2732_power_on(struct device *dev)
{
	struct v4l2_subdev *sd = dev_get_drvdata(dev);
	struct ov2732 *ov2732 = to_ov2732(sd);
	int ret;

	ret = regulator_bulk_enable(ARRAY_SIZE(ov2732_supply_names),
				    ov2732->supplies);
	if (ret) {
		dev_err(dev, "failed to enable regulators\n");
		return ret;
	}

	ret = clk_prepare_enable(ov2732->xvclk);
	if (ret) {
		dev_err(dev, "failed to enable clock\n");
		goto reg_off;
	}

	/* Wait 10ms before power up, as per datasheet. */
	fsleep(10 * USEC_PER_MSEC);

	gpiod_set_value_cansleep(ov2732->reset_gpio, 0);
	gpiod_set_value_cansleep(ov2732->powerdown_gpio, 0);

	/* Datasheet requires an 8192 cycles wait, but that isn't enough. */
	fsleep(OV2732_DELAY_US(OV2732_POWER_UP_DELAY_CYCLES * 2));

Annotation

Implementation Notes