media: mt9v032: Improvements from PHYTEC
cover media: mt9v032: Improvements from PHYTEC
Add PHYTEC improvements for the Aptina mt9v032 sensor used on their VM010 phyCAM modules.
Christian Hemp (1):
media: mt9v032: Support color format selection
Jan Luebbe (1):
media: mt9v032: Add control for row noise correction
Stefan Riedmüller (1):
media: mt9v032: Add get_mbus_config subdev_pad_ops callback
drivers/media/i2c/mt9v032.c | 95 +++++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 15 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 media: mt9v032: Support color format selection
From: Christian Hemp <[email protected]>
The driver only ever exposed one fixed mbus code per sensor variant (MEDIA_BUS_FMT_SGRBG10_1X10 for color, MEDIA_BUS_FMT_Y10_1X10 for monochrome): enum_mbus_code() rejected any index > 0, and set_format() ignored the requested code entirely.
Add per-variant format tables (8-bit and 10-bit Bayer/greyscale) and a mt9v032_find_datafmt() helper, so userspace can actually select the pixel format via the standard subdev pad ops instead of being limited to the single hardcoded 10-bit default.
--- drivers/media/i2c/mt9v032.c | 47 +++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 10 deletions(-)
drivers/media/i2c/mt9v032.c +37 -10
@@ -187,6 +187,16 @@ struct mt9v032_platform_data {s64 link_def_freq; }; +static const u32 mt9v032_color_fmts[] = { +MEDIA_BUS_FMT_SGRBG8_1X8 , +MEDIA_BUS_FMT_SGRBG10_1X10 , +}; + +static const u32 mt9v032_monochrome_fmts[] = { +MEDIA_BUS_FMT_Y8_1X8 , +MEDIA_BUS_FMT_Y10_1X10 , +}; +struct mt9v032 {struct device *dev;
@@ -215,6 +225,8 @@ struct mt9v032 {struct mt9v032_platform_data pdata;const struct mt9v032_model_info *model;const struct mt9v032_model_version *version; +const u32 *fmts; +int num_fmts;u32 sysclk;u16 aec_agc;
@@ -434,16 +446,28 @@ static int mt9v032_s_stream(struct v4l2_subdev *subdev, int enable)return regmap_update_bits (map,MT9V032_CHIP_CONTROL , mode, mode); } +static u32 mt9v032_find_datafmt (struct mt9v032 *mt9v032,u32 code) +{ +const u32 *fmt = mt9v032->fmts; +int i; + +for (i =0 ; i < mt9v032->num_fmts; i++) +if (fmt[i] == code) +return fmt[i]; + +return fmt[mt9v032->num_fmts -1 ]; +} +static int mt9v032_enum_mbus_code (struct v4l2_subdev *subdev,struct v4l2_subdev_state *sd_state,struct v4l2_subdev_mbus_code_enum *code) {struct mt9v032 *mt9v032 =to_mt9v032 (subdev); -if (code->index >0 ) +if (code->index >= mt9v032->num_fmts)return -EINVAL ; - code->code = mt9v032->format.code; + code->code = mt9v032->fmts[code->index];return 0 ; }
@@ -535,6 +559,8 @@ static int mt9v032_set_format(struct v4l2_subdev *subdev, __format->width = __crop->width / hratio; __format->height = __crop->height / vratio; + __format->code =mt9v032_find_datafmt (mt9v032, format->format.code); +if (format->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) { mt9v032->hratio = hratio; mt9v032->vratio = vratio;
@@ -946,10 +972,7 @@ static int mt9v032_open(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh) format =v4l2_subdev_state_get_format (fh->state,0 ); -if (mt9v032->model->color) - format->code =MEDIA_BUS_FMT_SGRBG10_1X10 ; -else - format->code =MEDIA_BUS_FMT_Y10_1X10 ; + format->code =mt9v032_find_datafmt (mt9v032,0 ); format->width =MT9V032_WINDOW_WIDTH_DEF ; format->height =MT9V032_WINDOW_HEIGHT_DEF ;
@@ -1157,10 +1180,14 @@ static int mt9v032_probe(struct i2c_client *client) mt9v032->crop.width =MT9V032_WINDOW_WIDTH_DEF ; mt9v032->crop.height =MT9V032_WINDOW_HEIGHT_DEF ; -if (mt9v032->model->color) - mt9v032->format.code =MEDIA_BUS_FMT_SGRBG10_1X10 ; -else - mt9v032->format.code =MEDIA_BUS_FMT_Y10_1X10 ; +if (mt9v032->model->color) { + mt9v032->fmts = mt9v032_color_fmts; + mt9v032->num_fmts =ARRAY_SIZE (mt9v032_color_fmts); + }else { + mt9v032->fmts = mt9v032_monochrome_fmts; + mt9v032->num_fmts =ARRAY_SIZE (mt9v032_monochrome_fmts); + } + mt9v032->format.code =mt9v032_find_datafmt (mt9v032,0 ); mt9v032->format.width =MT9V032_WINDOW_WIDTH_DEF ; mt9v032->format.height =MT9V032_WINDOW_HEIGHT_DEF ;
Signature · 1 line
2.34.1
PATCH 2/3 media: mt9v032: Add control for row noise correction
In reply to Primoz FiserFrom: Jan Luebbe <[email protected]>
The sensor's row noise correction algorithm was previously always disabled by unconditionally writing 0 to MT9V032_ROW_NOISE_CORR_CONTROL, with no way for userspace to enable it.
Add a V4L2_CID_ROW_NOISE_CORRECTION boolean control so userspace can toggle the model-specific enable value (MT9V032_ROW_NOISE_CORR_ENABLE / MT9V034_ROW_NOISE_CORR_ENABLE) at runtime. Default to disabled to preserve existing behaviour.
--- drivers/media/i2c/mt9v032.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-)
drivers/media/i2c/mt9v032.c +23 -5
@@ -167,6 +167,7 @@ struct mt9v032_model_data {unsigned int pclk_reg;unsigned int aec_max_shutter_reg;const struct v4l2_ctrl_config *const aec_max_shutter_v4l2_ctrl; +unsigned int row_noise_enable; };struct mt9v032_model_info {
@@ -231,6 +232,7 @@ struct mt9v032 {u32 sysclk;u16 aec_agc;u16 hblank; +bool row_noise_corr;struct {struct v4l2_ctrl *test_pattern;struct v4l2_ctrl *test_pattern_color;
@@ -356,11 +358,6 @@ static int __mt9v032_set_power(struct mt9v032 *mt9v032, bool on)return ret; } -/* Disable the noise correction algorithm and restore the controls. */ - ret =regmap_write (map,MT9V032_ROW_NOISE_CORR_CONTROL ,0 ); -if (ret <0 ) -return ret; -return v4l2_ctrl_handler_setup (&mt9v032->ctrls); }
@@ -679,6 +676,10 @@ static int mt9v032_set_selection(struct v4l2_subdev *subdev,* Maximum shutter width used for AEC. */ #define V4L2_CID_AEC_MAX_SHUTTER_WIDTH (V4L2_CID_USER_BASE | 0x1007) +/* +* Row Noise Correction enable. +*/ +#define V4L2_CID_ROW_NOISE_CORRECTION (V4L2_CID_USER_BASE | 0x1008)static int mt9v032_s_ctrl (struct v4l2_ctrl *ctrl) {
@@ -770,6 +771,11 @@ static int mt9v032_s_ctrl(struct v4l2_ctrl *ctrl)return regmap_write (map, mt9v032->model->data->aec_max_shutter_reg, ctrl->val); +case V4L2_CID_ROW_NOISE_CORRECTION : + mt9v032->row_noise_corr = ctrl->val; +return regmap_write (map,MT9V032_ROW_NOISE_CORR_CONTROL , + mt9v032->row_noise_corr ? + mt9v032->model->data->row_noise_enable :0 ); }return 0 ;
@@ -850,6 +856,16 @@ static const struct v4l2_ctrl_config mt9v032_aegc_controls[] = { .step = 1, .def = 2, .flags = 0, + }, { + .ops = &mt9v032_ctrl_ops, + .id = V4L2_CID_ROW_NOISE_CORRECTION, + .type = V4L2_CTRL_TYPE_BOOLEAN, + .name = "Row Noise Correction", + .min = 0, + .max = 1, + .step = 1, + .def = 0, + .flags = 0, } };
@@ -1246,6 +1262,7 @@ static const struct mt9v032_model_data mt9v032_model_data[] = { .pclk_reg = MT9V032_PIXEL_CLOCK, .aec_max_shutter_reg = MT9V032_AEC_MAX_SHUTTER_WIDTH, .aec_max_shutter_v4l2_ctrl = &mt9v032_aec_max_shutter_width, + .row_noise_enable = MT9V032_ROW_NOISE_CORR_ENABLE, }, {/* MT9V024, MT9V034 */ .min_row_time = 690,
@@ -1257,6 +1274,7 @@ static const struct mt9v032_model_data mt9v032_model_data[] = { .pclk_reg = MT9V034_PIXEL_CLOCK, .aec_max_shutter_reg = MT9V034_AEC_MAX_SHUTTER_WIDTH, .aec_max_shutter_v4l2_ctrl = &mt9v034_aec_max_shutter_width, + .row_noise_enable = MT9V034_ROW_NOISE_CORR_ENABLE, }, };
Signature · 1 line
2.34.1
PATCH 3/3 media: mt9v032: Add get_mbus_config subdev_pad_ops callback
In reply to Primoz FiserFrom: Stefan Riedmüller <[email protected]>
Some drivers like the i.MX6 IPU driver require the get_mbus_config callback to be implemented, thus implement it.
--- drivers/media/i2c/mt9v032.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/media/i2c/mt9v032.c +20 -0
@@ -1003,6 +1003,25 @@ static int mt9v032_close(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)return mt9v032_set_power (subdev,0 ); } +static int mt9v032_get_mbus_config (struct v4l2_subdev *sd,unsigned int pad, +struct v4l2_mbus_config *cfg) +{ +struct mt9v032 *mt9v032 =to_mt9v032 (sd); + + cfg->type =V4L2_MBUS_PARALLEL ; + + cfg->bus.parallel.flags =V4L2_MBUS_MASTER | +V4L2_MBUS_HSYNC_ACTIVE_HIGH | +V4L2_MBUS_VSYNC_ACTIVE_HIGH | +V4L2_MBUS_DATA_ACTIVE_HIGH ; + + cfg->bus.parallel.flags |= mt9v032->pdata.clk_pol ? +V4L2_MBUS_PCLK_SAMPLE_RISING : +V4L2_MBUS_PCLK_SAMPLE_FALLING ; + +return 0 ; +} +static const struct v4l2_subdev_core_ops mt9v032_subdev_core_ops = { .s_power = mt9v032_set_power, };
@@ -1018,6 +1037,7 @@ static const struct v4l2_subdev_pad_ops mt9v032_subdev_pad_ops = { .set_fmt = mt9v032_set_format, .get_selection = mt9v032_get_selection, .set_selection = mt9v032_set_selection, + .get_mbus_config = mt9v032_get_mbus_config, };static const struct v4l2_subdev_ops mt9v032_subdev_ops = {
Signature · 1 line
2.34.1