ov2640: select sensor register bank before applying h/v-flip settings
PATCH 1/3 ov2640: select sensor register bank before applying h/v-flip settings
We currently don't select the register bank in ov2640_s_ctrl, so we can end up writing to DSP register 0x04 instead of sensor register 0x04. This happens for example when calling ov2640_s_ctrl after ov2640_s_fmt.
--- drivers/media/i2c/soc_camera/ov2640.c | 8 ++++++++
1 Datei geändert, 8 Zeilen hinzugefügt(+)
drivers/media/i2c/soc_camera/ov2640.c +8 -0
@@ -683,8 +683,16 @@ static int ov2640_s_ctrl(struct v4l2_ctrl *ctrl)struct v4l2_subdev *sd = &container_of(ctrl->handler, struct ov2640_priv, hdl)->subdev;struct i2c_client *client =v4l2_get_subdevdata (sd); +struct regval_list regval; +int ret;u8 val; + regval.reg_num =BANK_SEL ; + regval.value =BANK_SEL_SENS ; + ret =ov2640_write_array (client, ®val); +if (ret <0 ) +return ret; +switch (ctrl->id) {case V4L2_CID_VFLIP : val = ctrl->val ?REG04_VFLIP_IMG :0x00 ;
Signature · 1 line
1.7.10.4
PATCH 2/3 ov2640: add support for V4L2_MBUS_FMT_YUYV8_2X8, V4L2_MBUS_FMT_RGB565_2X8_BE
This is the result of experimenting with the SpeedLink VAD Laplace webcam. The register sequence for V4L2_MBUS_FMT_YUYV8_2X8 has been identified by analyzing USB-logs of this device running on MS Windows.
--- drivers/media/i2c/soc_camera/ov2640.c | 49 ++++++++++++++++++++++++++++-----
1 Datei geändert, 42 Zeilen hinzugefügt(+), 7 Zeilen entfernt(-)
drivers/media/i2c/soc_camera/ov2640.c +42 -7
@@ -586,9 +586,20 @@ static const struct regval_list ov2640_format_change_preamble_regs[] = { ENDMARKER, }; -static const struct regval_list ov2640_yuv422_regs[] = { +static const struct regval_list ov2640_yuyv_regs[] = { + {IMAGE_MODE ,IMAGE_MODE_YUV422 }, + {0xd7 ,0x03 }, + {0x33 ,0xa0 }, + {0xe5 ,0x1f }, + {0xe1 ,0x67 }, + {RESET ,0x00 }, + {R_BYPASS ,R_BYPASS_USE_DSP }, +ENDMARKER , +}; + +static const struct regval_list ov2640_uyvy_regs[] = { {IMAGE_MODE ,IMAGE_MODE_LBYTE_FIRST |IMAGE_MODE_YUV422 }, - {0xD7 ,0x01 }, + {0xd7 ,0x01 }, {0x33 ,0xa0 }, {0xe1 ,0x67 }, {RESET ,0x00 },
@@ -596,7 +607,15 @@ static const struct regval_list ov2640_yuv422_regs[] = { ENDMARKER, }; -static const struct regval_list ov2640_rgb565_regs[] = { +static const struct regval_list ov2640_rgb565_be_regs[] = { + {IMAGE_MODE ,IMAGE_MODE_RGB565 }, + {0xd7 ,0x03 }, + {RESET ,0x00 }, + {R_BYPASS ,R_BYPASS_USE_DSP }, +ENDMARKER , +}; + +static const struct regval_list ov2640_rgb565_le_regs[] = { {IMAGE_MODE ,IMAGE_MODE_LBYTE_FIRST |IMAGE_MODE_RGB565 }, {0xd7 ,0x03 }, {RESET ,0x00 },
@@ -605,7 +624,9 @@ static const struct regval_list ov2640_rgb565_regs[] = { };static enum v4l2_mbus_pixelcode ov2640_codes[] = { +V4L2_MBUS_FMT_YUYV8_2X8 ,V4L2_MBUS_FMT_UYVY8_2X8 , +V4L2_MBUS_FMT_RGB565_2X8_BE ,V4L2_MBUS_FMT_RGB565_2X8_LE , };
@@ -790,14 +811,22 @@ static int ov2640_set_params(struct i2c_client *client, u32 *width, u32 *height,/* select format */ priv->cfmt_code =0 ;switch (code) { +case V4L2_MBUS_FMT_RGB565_2X8_BE : +dev_dbg (&client->dev,"%s: Selected cfmt RGB565 BE" , __func__); + selected_cfmt_regs = ov2640_rgb565_be_regs; +break ;case V4L2_MBUS_FMT_RGB565_2X8_LE : -dev_dbg (&client->dev,"%s: Selected cfmt RGB565" , __func__); - selected_cfmt_regs = ov2640_rgb565_regs; +dev_dbg (&client->dev,"%s: Selected cfmt RGB565 LE" , __func__); + selected_cfmt_regs = ov2640_rgb565_le_regs; +break ; +case V4L2_MBUS_FMT_YUYV8_2X8 : +dev_dbg (&client->dev,"%s: Selected cfmt YUYV (YUV422)" , __func__); + selected_cfmt_regs = ov2640_yuyv_regs;break ;default :case V4L2_MBUS_FMT_UYVY8_2X8 : -dev_dbg (&client->dev,"%s: Selected cfmt YUV422" , __func__); - selected_cfmt_regs = ov2640_yuv422_regs; +dev_dbg (&client->dev,"%s: Selected cfmt UYVY" , __func__); + selected_cfmt_regs = ov2640_uyvy_regs; }/* reset hardware */
@@ -862,10 +891,12 @@ static int ov2640_g_fmt(struct v4l2_subdev *sd, mf->code = priv->cfmt_code;switch (mf->code) { +case V4L2_MBUS_FMT_RGB565_2X8_BE :case V4L2_MBUS_FMT_RGB565_2X8_LE : mf->colorspace =V4L2_COLORSPACE_SRGB ;break ;default : +case V4L2_MBUS_FMT_YUYV8_2X8 :case V4L2_MBUS_FMT_UYVY8_2X8 : mf->colorspace =V4L2_COLORSPACE_JPEG ; }
@@ -882,11 +913,13 @@ static int ov2640_s_fmt(struct v4l2_subdev *sd,switch (mf->code) { +case V4L2_MBUS_FMT_RGB565_2X8_BE :case V4L2_MBUS_FMT_RGB565_2X8_LE : mf->colorspace =V4L2_COLORSPACE_SRGB ;break ;default : mf->code =V4L2_MBUS_FMT_UYVY8_2X8 ; +case V4L2_MBUS_FMT_YUYV8_2X8 :case V4L2_MBUS_FMT_UYVY8_2X8 : mf->colorspace =V4L2_COLORSPACE_JPEG ; }
@@ -909,11 +942,13 @@ static int ov2640_try_fmt(struct v4l2_subdev *sd, mf->field =V4L2_FIELD_NONE ;switch (mf->code) { +case V4L2_MBUS_FMT_RGB565_2X8_BE :case V4L2_MBUS_FMT_RGB565_2X8_LE : mf->colorspace =V4L2_COLORSPACE_SRGB ;break ;default : mf->code =V4L2_MBUS_FMT_UYVY8_2X8 ; +case V4L2_MBUS_FMT_YUYV8_2X8 :case V4L2_MBUS_FMT_UYVY8_2X8 : mf->colorspace =V4L2_COLORSPACE_JPEG ; }
Signature · 1 line
1.7.10.4
PATCH 3/3 ov2640: simplify single register writes
In reply to Frank Schäfer--- drivers/media/i2c/soc_camera/ov2640.c | 21 ++++++++++++---------
1 Datei geändert, 12 Zeilen hinzugefügt(+), 9 Zeilen entfernt(-)
drivers/media/i2c/soc_camera/ov2640.c +12 -9
@@ -639,17 +639,23 @@ static struct ov2640_priv *to_ov2640(const struct i2c_client *client) subdev); } +static int ov2640_write_single (struct i2c_client *client,u8 reg,u8 val) +{ +int ret; + + ret =i2c_smbus_write_byte_data (client, reg, val); +dev_vdbg (&client->dev,"write: 0x%02x, 0x%02x" , reg, val); + +return ret; +} +static int ov2640_write_array (struct i2c_client *client,const struct regval_list *vals) {int ret;while ((vals->reg_num !=0xff ) || (vals->value !=0xff )) { - ret =i2c_smbus_write_byte_data (client, - vals->reg_num, vals->value); -dev_vdbg (&client->dev,"array: 0x%02x, 0x%02x" , - vals->reg_num, vals->value); - + ret =ov2640_write_single (client, vals->reg_num, vals->value);if (ret <0 )return ret; vals++;
@@ -704,13 +710,10 @@ static int ov2640_s_ctrl(struct v4l2_ctrl *ctrl)struct v4l2_subdev *sd = &container_of(ctrl->handler, struct ov2640_priv, hdl)->subdev;struct i2c_client *client =v4l2_get_subdevdata (sd); -struct regval_list regval;int ret;u8 val; - regval.reg_num =BANK_SEL ; - regval.value =BANK_SEL_SENS ; - ret =ov2640_write_array (client, ®val); + ret =ov2640_write_single (client,BANK_SEL ,BANK_SEL_SENS );if (ret <0 )return ret;
Signature · 1 line
1.7.10.4
Re: [PATCH 3/3] ov2640: simplify single register writes
Am 23.09.2012 15:07, schrieb Frank Schäfer:
Quoted 11 lines
Signed-off-by Frank Schäfer <[email protected]>--- drivers/media/i2c/soc_camera/ov2640.c | 21 ++++++++++++---------1 Datei geändert, 12 Zeilen hinzugefügt(+), 9 Zeilen entfernt(-)
drivers/media/i2c/soc_camera/ov2640.c +0
-0@@ -639,17 +639,23 @@ static struct ov2640_priv *to_ov2640(const struct i2c_client *client) subdev);
drivers/media/i2c/soc_camera/ov2640.c static struct ov2640_priv *to_ov2640(const struct i2c_client *client) · line 649
Quoted 10 lines
drivers/media/i2c/soc_camera/ov2640.c +8
-0} +static int ov2640_write_single (struct i2c_client *client,u8 reg,u8 val) +{ +int ret; + + ret =i2c_smbus_write_byte_data (client, reg, val); +dev_vdbg (&client->dev,"write: 0x%02x, 0x%02x" , reg, val); + +return ret;
Uhm... wait ! Of course we can get rid of int ret. Will resend in a minute...
Regards,
Frank
Quoted 32 lines
drivers/media/i2c/soc_camera/ov2640.c +4
-9+} +static int ov2640_write_array (struct i2c_client *client,const struct regval_list *vals) {int ret;while ((vals->reg_num !=0xff ) || (vals->value !=0xff )) { - ret =i2c_smbus_write_byte_data (client, - vals->reg_num, vals->value); -dev_vdbg (&client->dev,"array: 0x%02x, 0x%02x" , - vals->reg_num, vals->value); - + ret =ov2640_write_single (client, vals->reg_num, vals->value);if (ret <0 )return ret; vals++;@@ -704,13 +710,10 @@ static int ov2640_s_ctrl(struct v4l2_ctrl *ctrl)struct v4l2_subdev *sd = &container_of(ctrl->handler, struct ov2640_priv, hdl)->subdev;struct i2c_client *client =v4l2_get_subdevdata (sd); -struct regval_list regval;int ret;u8 val; - regval.reg_num =BANK_SEL ; - regval.value =BANK_SEL_SENS ; - ret =ov2640_write_array (client, ®val); + ret =ov2640_write_single (client,BANK_SEL ,BANK_SEL_SENS );if (ret <0 )return ret;