linux/drivers/media/i2c/mt9v032.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Driver for MT9V022, MT9V024, MT9V032, and MT9V034 CMOS Image Sensors
 *
 * Copyright (C) 2010, Laurent Pinchart <[email protected]>
 *
 * Based on the MT9M001 driver,
 *
 * Copyright (C) 2008, Guennadi Liakhovetski <[email protected]>
 */

#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/log2.h>
#include <linux/mod_devicetable.h>
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/of_graph.h>
#include <linux/regmap.h>
#include <linux/slab.h>
#include <linux/videodev2.h>
#include <linux/v4l2-mediabus.h>
#include <linux/module.h>

#include <media/i2c/mt9v032.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/v4l2-fwnode.h>
#include <media/v4l2-subdev.h>

/* The first four rows are black rows. The active area spans 753x481 pixels. */
#define MT9V032_PIXEL_ARRAY_HEIGHT
#define MT9V032_PIXEL_ARRAY_WIDTH

#define MT9V032_SYSCLK_FREQ_DEF

#define MT9V032_CHIP_VERSION
#define MT9V032_CHIP_ID_REV1
#define MT9V032_CHIP_ID_REV3
#define MT9V034_CHIP_ID_REV1
#define MT9V032_COLUMN_START
#define MT9V032_COLUMN_START_MIN
#define MT9V032_COLUMN_START_DEF
#define MT9V032_COLUMN_START_MAX
#define MT9V032_ROW_START
#define MT9V032_ROW_START_MIN
#define MT9V032_ROW_START_DEF
#define MT9V032_ROW_START_MAX
#define MT9V032_WINDOW_HEIGHT
#define MT9V032_WINDOW_HEIGHT_MIN
#define MT9V032_WINDOW_HEIGHT_DEF
#define MT9V032_WINDOW_HEIGHT_MAX
#define MT9V032_WINDOW_WIDTH
#define MT9V032_WINDOW_WIDTH_MIN
#define MT9V032_WINDOW_WIDTH_DEF
#define MT9V032_WINDOW_WIDTH_MAX
#define MT9V032_HORIZONTAL_BLANKING
#define MT9V032_HORIZONTAL_BLANKING_MIN
#define MT9V034_HORIZONTAL_BLANKING_MIN
#define MT9V032_HORIZONTAL_BLANKING_DEF
#define MT9V032_HORIZONTAL_BLANKING_MAX
#define MT9V032_VERTICAL_BLANKING
#define MT9V032_VERTICAL_BLANKING_MIN
#define MT9V034_VERTICAL_BLANKING_MIN
#define MT9V032_VERTICAL_BLANKING_DEF
#define MT9V032_VERTICAL_BLANKING_MAX
#define MT9V034_VERTICAL_BLANKING_MAX
#define MT9V032_CHIP_CONTROL
#define MT9V032_CHIP_CONTROL_MASTER_MODE
#define MT9V032_CHIP_CONTROL_DOUT_ENABLE
#define MT9V032_CHIP_CONTROL_SEQUENTIAL
#define MT9V032_SHUTTER_WIDTH1
#define MT9V032_SHUTTER_WIDTH2
#define MT9V032_SHUTTER_WIDTH_CONTROL
#define MT9V032_TOTAL_SHUTTER_WIDTH
#define MT9V032_TOTAL_SHUTTER_WIDTH_MIN
#define MT9V034_TOTAL_SHUTTER_WIDTH_MIN
#define MT9V032_TOTAL_SHUTTER_WIDTH_DEF
#define MT9V032_TOTAL_SHUTTER_WIDTH_MAX
#define MT9V034_TOTAL_SHUTTER_WIDTH_MAX
#define MT9V032_RESET
#define MT9V032_READ_MODE
#define MT9V032_READ_MODE_ROW_BIN_MASK
#define MT9V032_READ_MODE_ROW_BIN_SHIFT
#define MT9V032_READ_MODE_COLUMN_BIN_MASK
#define MT9V032_READ_MODE_COLUMN_BIN_SHIFT
#define MT9V032_READ_MODE_ROW_FLIP
#define MT9V032_READ_MODE_COLUMN_FLIP
#define MT9V032_READ_MODE_DARK_COLUMNS
#define MT9V032_READ_MODE_DARK_ROWS
#define MT9V032_READ_MODE_RESERVED
#define MT9V032_PIXEL_OPERATION_MODE
#define MT9V034_PIXEL_OPERATION_MODE_HDR
#define MT9V034_PIXEL_OPERATION_MODE_COLOR
#define MT9V032_PIXEL_OPERATION_MODE_COLOR
#define MT9V032_PIXEL_OPERATION_MODE_HDR
#define MT9V032_ANALOG_GAIN
#define MT9V032_ANALOG_GAIN_MIN
#define MT9V032_ANALOG_GAIN_DEF
#define MT9V032_ANALOG_GAIN_MAX
#define MT9V032_MAX_ANALOG_GAIN
#define MT9V032_MAX_ANALOG_GAIN_MAX
#define MT9V032_FRAME_DARK_AVERAGE
#define MT9V032_DARK_AVG_THRESH
#define MT9V032_DARK_AVG_LOW_THRESH_MASK
#define MT9V032_DARK_AVG_LOW_THRESH_SHIFT
#define MT9V032_DARK_AVG_HIGH_THRESH_MASK
#define MT9V032_DARK_AVG_HIGH_THRESH_SHIFT
#define MT9V032_ROW_NOISE_CORR_CONTROL
#define MT9V034_ROW_NOISE_CORR_ENABLE
#define MT9V034_ROW_NOISE_CORR_USE_BLK_AVG
#define MT9V032_ROW_NOISE_CORR_ENABLE
#define MT9V032_ROW_NOISE_CORR_USE_BLK_AVG
#define MT9V032_PIXEL_CLOCK
#define MT9V034_PIXEL_CLOCK
#define MT9V032_PIXEL_CLOCK_INV_LINE
#define MT9V032_PIXEL_CLOCK_INV_FRAME
#define MT9V032_PIXEL_CLOCK_XOR_LINE
#define MT9V032_PIXEL_CLOCK_CONT_LINE
#define MT9V032_PIXEL_CLOCK_INV_PXL_CLK
#define MT9V032_TEST_PATTERN
#define MT9V032_TEST_PATTERN_DATA_MASK
#define MT9V032_TEST_PATTERN_DATA_SHIFT
#define MT9V032_TEST_PATTERN_USE_DATA
#define MT9V032_TEST_PATTERN_GRAY_MASK
#define MT9V032_TEST_PATTERN_GRAY_NONE
#define MT9V032_TEST_PATTERN_GRAY_VERTICAL
#define MT9V032_TEST_PATTERN_GRAY_HORIZONTAL
#define MT9V032_TEST_PATTERN_GRAY_DIAGONAL
#define MT9V032_TEST_PATTERN_ENABLE
#define MT9V032_TEST_PATTERN_FLIP
#define MT9V032_AEGC_DESIRED_BIN
#define MT9V032_AEC_UPDATE_FREQUENCY
#define MT9V032_AEC_LPF
#define MT9V032_AGC_UPDATE_FREQUENCY
#define MT9V032_AGC_LPF
#define MT9V032_AEC_AGC_ENABLE
#define MT9V032_AEC_ENABLE
#define MT9V032_AGC_ENABLE
#define MT9V034_AEC_MAX_SHUTTER_WIDTH
#define MT9V032_AEC_MAX_SHUTTER_WIDTH
#define MT9V032_THERMAL_INFO

enum mt9v032_model {};

struct mt9v032_model_version {};

struct mt9v032_model_data {};

struct mt9v032_model_info {};

static const struct mt9v032_model_version mt9v032_versions[] =;

struct mt9v032 {};

static struct mt9v032 *to_mt9v032(struct v4l2_subdev *sd)
{}

static int
mt9v032_update_aec_agc(struct mt9v032 *mt9v032, u16 which, int enable)
{}

static int
mt9v032_update_hblank(struct mt9v032 *mt9v032)
{}

static int mt9v032_power_on(struct mt9v032 *mt9v032)
{}

static void mt9v032_power_off(struct mt9v032 *mt9v032)
{}

static int __mt9v032_set_power(struct mt9v032 *mt9v032, bool on)
{}

/* -----------------------------------------------------------------------------
 * V4L2 subdev video operations
 */

static struct v4l2_mbus_framefmt *
__mt9v032_get_pad_format(struct mt9v032 *mt9v032,
			 struct v4l2_subdev_state *sd_state,
			 unsigned int pad, enum v4l2_subdev_format_whence which)
{}

static struct v4l2_rect *
__mt9v032_get_pad_crop(struct mt9v032 *mt9v032,
		       struct v4l2_subdev_state *sd_state,
		       unsigned int pad, enum v4l2_subdev_format_whence which)
{}

static int mt9v032_s_stream(struct v4l2_subdev *subdev, int enable)
{}

static int mt9v032_enum_mbus_code(struct v4l2_subdev *subdev,
				  struct v4l2_subdev_state *sd_state,
				  struct v4l2_subdev_mbus_code_enum *code)
{}

static int mt9v032_enum_frame_size(struct v4l2_subdev *subdev,
				   struct v4l2_subdev_state *sd_state,
				   struct v4l2_subdev_frame_size_enum *fse)
{}

static int mt9v032_get_format(struct v4l2_subdev *subdev,
			      struct v4l2_subdev_state *sd_state,
			      struct v4l2_subdev_format *format)
{}

static void mt9v032_configure_pixel_rate(struct mt9v032 *mt9v032)
{}

static unsigned int mt9v032_calc_ratio(unsigned int input, unsigned int output)
{}

static int mt9v032_set_format(struct v4l2_subdev *subdev,
			      struct v4l2_subdev_state *sd_state,
			      struct v4l2_subdev_format *format)
{}

static int mt9v032_get_selection(struct v4l2_subdev *subdev,
				 struct v4l2_subdev_state *sd_state,
				 struct v4l2_subdev_selection *sel)
{}

static int mt9v032_set_selection(struct v4l2_subdev *subdev,
				 struct v4l2_subdev_state *sd_state,
				 struct v4l2_subdev_selection *sel)
{}

/* -----------------------------------------------------------------------------
 * V4L2 subdev control operations
 */

#define V4L2_CID_TEST_PATTERN_COLOR
/*
 * Value between 1 and 64 to set the desired bin. This is effectively a measure
 * of how bright the image is supposed to be. Both AGC and AEC try to reach
 * this.
 */
#define V4L2_CID_AEGC_DESIRED_BIN
/*
 * LPF is the low pass filter capability of the chip. Both AEC and AGC have
 * this setting. This limits the speed in which AGC/AEC adjust their settings.
 * Possible values are 0-2. 0 means no LPF. For 1 and 2 this equation is used:
 *
 * if |(calculated new exp - current exp)| > (current exp / 4)
 *	next exp = calculated new exp
 * else
 *	next exp = current exp + ((calculated new exp - current exp) / 2^LPF)
 */
#define V4L2_CID_AEC_LPF
#define V4L2_CID_AGC_LPF
/*
 * Value between 0 and 15. This is the number of frames being skipped before
 * updating the auto exposure/gain.
 */
#define V4L2_CID_AEC_UPDATE_INTERVAL
#define V4L2_CID_AGC_UPDATE_INTERVAL
/*
 * Maximum shutter width used for AEC.
 */
#define V4L2_CID_AEC_MAX_SHUTTER_WIDTH

static int mt9v032_s_ctrl(struct v4l2_ctrl *ctrl)
{}

static const struct v4l2_ctrl_ops mt9v032_ctrl_ops =;

static const char * const mt9v032_test_pattern_menu[] =;

static const struct v4l2_ctrl_config mt9v032_test_pattern_color =;

static const struct v4l2_ctrl_config mt9v032_aegc_controls[] =;

static const struct v4l2_ctrl_config mt9v032_aec_max_shutter_width =;

static const struct v4l2_ctrl_config mt9v034_aec_max_shutter_width =;

/* -----------------------------------------------------------------------------
 * V4L2 subdev core operations
 */

static int mt9v032_set_power(struct v4l2_subdev *subdev, int on)
{}

/* -----------------------------------------------------------------------------
 * V4L2 subdev internal operations
 */

static int mt9v032_registered(struct v4l2_subdev *subdev)
{}

static int mt9v032_open(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)
{}

static int mt9v032_close(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)
{}

static const struct v4l2_subdev_core_ops mt9v032_subdev_core_ops =;

static const struct v4l2_subdev_video_ops mt9v032_subdev_video_ops =;

static const struct v4l2_subdev_pad_ops mt9v032_subdev_pad_ops =;

static const struct v4l2_subdev_ops mt9v032_subdev_ops =;

static const struct v4l2_subdev_internal_ops mt9v032_subdev_internal_ops =;

static const struct regmap_config mt9v032_regmap_config =;

/* -----------------------------------------------------------------------------
 * Driver initialization and probing
 */

static struct mt9v032_platform_data *
mt9v032_get_pdata(struct i2c_client *client)
{}

static int mt9v032_probe(struct i2c_client *client)
{}

static void mt9v032_remove(struct i2c_client *client)
{}

static const struct mt9v032_model_data mt9v032_model_data[] =;

static const struct mt9v032_model_info mt9v032_models[] =;

static const struct i2c_device_id mt9v032_id[] =;
MODULE_DEVICE_TABLE(i2c, mt9v032_id);

static const struct of_device_id mt9v032_of_match[] =;
MODULE_DEVICE_TABLE(of, mt9v032_of_match);

static struct i2c_driver mt9v032_driver =;

module_i2c_driver();

MODULE_DESCRIPTION();
MODULE_AUTHOR();
MODULE_LICENSE();