summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorYuxi Sun <b36102@freescale.com>2011-07-21 14:07:41 +0800
committerYuxi Sun <b36102@freescale.com>2011-07-22 10:46:30 +0800
commitb0d90bdee1c596e5b33a748af2fa11590119481c (patch)
tree5399f133bdeb9d1bc6c207bfe10c162d38aed3b9 /drivers
parent477c3fcd2b151a36720d6efec3808a642f8bebf5 (diff)
ENGR00151170 ov3640: green color displays when take picture
This patch fix green color of ov3640 when take picture under QXGA mode by update setting form OV and using “Read preview mode exposure & Gain -> Make calculation -> Write back for capture mode” method. Signed-off-by: Yuxi Sun <b36102@freescale.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/mxc/capture/ov3640.c196
1 files changed, 124 insertions, 72 deletions
diff --git a/drivers/media/video/mxc/capture/ov3640.c b/drivers/media/video/mxc/capture/ov3640.c
index 54a59ddda637..5d3bd29dd26e 100644
--- a/drivers/media/video/mxc/capture/ov3640.c
+++ b/drivers/media/video/mxc/capture/ov3640.c
@@ -109,72 +109,20 @@ static struct reg_value ov3640_rotate_180[] = {
};
static struct reg_value ov3640_setting_15fps_QXGA_2048_1536[] = {
-#if 0
- /* The true 15fps QXGA setting. */
- {0x3012, 0x80, 0, 0}, {0x304d, 0x41, 0, 0}, {0x3087, 0x16, 0, 0},
- {0x30aa, 0x45, 0, 0}, {0x30b0, 0xff, 0, 0}, {0x30b1, 0xff, 0, 0},
- {0x30b2, 0x13, 0, 0}, {0x30d7, 0x10, 0, 0}, {0x309e, 0x00, 0, 0},
- {0x3602, 0x26, 0, 0}, {0x3603, 0x4D, 0, 0}, {0x364c, 0x04, 0, 0},
- {0x360c, 0x12, 0, 0}, {0x361e, 0x00, 0, 0}, {0x361f, 0x11, 0, 0},
- {0x3633, 0x03, 0, 0}, {0x3629, 0x3c, 0, 0}, {0x300e, 0x33, 0, 0},
- {0x300f, 0x21, 0, 0}, {0x3010, 0x20, 0, 0}, {0x3011, 0x00, 0, 0},
- {0x304c, 0x81, 0, 0}, {0x3029, 0x47, 0, 0}, {0x3070, 0x00, 0, 0},
- {0x3071, 0xEC, 0, 0}, {0x301C, 0x06, 0, 0}, {0x3072, 0x00, 0, 0},
- {0x3073, 0xC5, 0, 0}, {0x301D, 0x07, 0, 0}, {0x3018, 0x38, 0, 0},
- {0x3019, 0x30, 0, 0}, {0x301a, 0x61, 0, 0}, {0x307d, 0x00, 0, 0},
- {0x3087, 0x02, 0, 0}, {0x3082, 0x20, 0, 0}, {0x303c, 0x08, 0, 0},
- {0x303d, 0x18, 0, 0}, {0x303e, 0x06, 0, 0}, {0x303F, 0x0c, 0, 0},
- {0x3030, 0x62, 0, 0}, {0x3031, 0x26, 0, 0}, {0x3032, 0xe6, 0, 0},
- {0x3033, 0x6e, 0, 0}, {0x3034, 0xea, 0, 0}, {0x3035, 0xae, 0, 0},
- {0x3036, 0xa6, 0, 0}, {0x3037, 0x6a, 0, 0}, {0x3015, 0x12, 0, 0},
- {0x3014, 0x04, 0, 0}, {0x3013, 0xf7, 0, 0}, {0x3104, 0x02, 0, 0},
- {0x3105, 0xfd, 0, 0}, {0x3106, 0x00, 0, 0}, {0x3107, 0xff, 0, 0},
- {0x3308, 0xa5, 0, 0}, {0x3316, 0xff, 0, 0}, {0x3317, 0x00, 0, 0},
- {0x3087, 0x02, 0, 0}, {0x3082, 0x20, 0, 0}, {0x3300, 0x13, 0, 0},
- {0x3301, 0xd6, 0, 0}, {0x3302, 0xef, 0, 0}, {0x30b8, 0x20, 0, 0},
- {0x30b9, 0x17, 0, 0}, {0x30ba, 0x04, 0, 0}, {0x30bb, 0x08, 0, 0},
- {0x3100, 0x02, 0, 0}, {0x3304, 0x00, 0, 0}, {0x3400, 0x00, 0, 0},
- {0x3404, 0x02, 0, 0}, {0x3020, 0x01, 0, 0}, {0x3021, 0x1d, 0, 0},
- {0x3022, 0x00, 0, 0}, {0x3023, 0x0a, 0, 0}, {0x3024, 0x08, 0, 0},
- {0x3025, 0x18, 0, 0}, {0x3026, 0x06, 0, 0}, {0x3027, 0x0c, 0, 0},
- {0x335f, 0x68, 0, 0}, {0x3360, 0x18, 0, 0}, {0x3361, 0x0c, 0, 0},
- {0x3362, 0x68, 0, 0}, {0x3363, 0x08, 0, 0}, {0x3364, 0x04, 0, 0},
- {0x3403, 0x42, 0, 0}, {0x3088, 0x08, 0, 0}, {0x3089, 0x00, 0, 0},
- {0x308a, 0x06, 0, 0}, {0x308b, 0x00, 0, 0}, {0x3507, 0x06, 0, 0},
- {0x350a, 0x4f, 0, 0}, {0x3600, 0xc4, 0, 0},
-#endif
- /*
- * Only support 7.5fps for QXGA to workaround screen tearing issue
- * for 15fps when capturing still image.
- */
- {0x3012, 0x80, 0, 0}, {0x304d, 0x45, 0, 0}, {0x30a7, 0x5e, 0, 0},
- {0x3087, 0x16, 0, 0}, {0x309c, 0x1a, 0, 0}, {0x30a2, 0xe4, 0, 0},
- {0x30aa, 0x42, 0, 0}, {0x30b0, 0xff, 0, 0}, {0x30b1, 0xff, 0, 0},
- {0x30b2, 0x10, 0, 0}, {0x300e, 0x32, 0, 0}, {0x300f, 0x21, 0, 0},
- {0x3010, 0x20, 0, 0}, {0x3011, 0x00, 0, 0}, {0x304c, 0x81, 0, 0},
- {0x30d7, 0x10, 0, 0}, {0x30d9, 0x0d, 0, 0}, {0x30db, 0x08, 0, 0},
- {0x3016, 0x82, 0, 0}, {0x3018, 0x38, 0, 0}, {0x3019, 0x30, 0, 0},
- {0x301a, 0x61, 0, 0}, {0x307d, 0x00, 0, 0}, {0x3087, 0x02, 0, 0},
- {0x3082, 0x20, 0, 0}, {0x3015, 0x12, 0, 0}, {0x3014, 0x04, 0, 0},
- {0x3013, 0xf7, 0, 0}, {0x303c, 0x08, 0, 0}, {0x303d, 0x18, 0, 0},
- {0x303e, 0x06, 0, 0}, {0x303f, 0x0c, 0, 0}, {0x3030, 0x62, 0, 0},
- {0x3031, 0x26, 0, 0}, {0x3032, 0xe6, 0, 0}, {0x3033, 0x6e, 0, 0},
- {0x3034, 0xea, 0, 0}, {0x3035, 0xae, 0, 0}, {0x3036, 0xa6, 0, 0},
- {0x3037, 0x6a, 0, 0}, {0x3104, 0x02, 0, 0}, {0x3105, 0xfd, 0, 0},
- {0x3106, 0x00, 0, 0}, {0x3107, 0xff, 0, 0}, {0x3300, 0x12, 0, 0},
- {0x3301, 0xde, 0, 0}, {0x3302, 0xcf, 0, 0}, {0x3312, 0x26, 0, 0},
- {0x3314, 0x42, 0, 0}, {0x3313, 0x2b, 0, 0}, {0x3315, 0x42, 0, 0},
- {0x3310, 0xd0, 0, 0}, {0x3311, 0xbd, 0, 0}, {0x330c, 0x18, 0, 0},
- {0x330d, 0x18, 0, 0}, {0x330e, 0x56, 0, 0}, {0x330f, 0x5c, 0, 0},
- {0x330b, 0x1c, 0, 0}, {0x3306, 0x5c, 0, 0}, {0x3307, 0x11, 0, 0},
- {0x336a, 0x52, 0, 0}, {0x3370, 0x46, 0, 0}, {0x3376, 0x38, 0, 0},
- {0x30b8, 0x20, 0, 0}, {0x30b9, 0x17, 0, 0}, {0x30ba, 0x04, 0, 0},
- {0x30bb, 0x08, 0, 0}, {0x3507, 0x06, 0, 0}, {0x350a, 0x4f, 0, 0},
- {0x3100, 0x02, 0, 0}, {0x3301, 0xde, 0, 0}, {0x3304, 0x00, 0, 0},
- {0x3400, 0x00, 0, 0}, {0x3404, 0x02, 0, 0}, {0x3600, 0xc4, 0, 0},
+ {0x300e, 0x36, 0, 0}, {0x300f, 0x21, 0, 0}, {0x3010, 0x20, 0, 0},
+ {0x3011, 0x03, 0, 0}, {0x3012, 0x00, 0, 0}, {0x3020, 0x01, 0, 0},
+ {0x3021, 0x1b, 0, 0}, {0x3022, 0x00, 0, 0}, {0x3023, 0x0c, 0, 0},
+ {0x3024, 0x08, 0, 0}, {0x3025, 0x18, 0, 0}, {0x3026, 0x06, 0, 0},
+ {0x3027, 0x0c, 0, 0}, {0x302a, 0x06, 0, 0}, {0x302b, 0x20, 0, 0},
+ {0x3075, 0x44, 0, 0}, {0x300d, 0x00, 0, 0}, {0x30d7, 0x10, 0, 0},
+ {0x3069, 0x40, 0, 0}, {0x303e, 0x01, 0, 0}, {0x303f, 0x80, 0, 0},
+ {0x3366, 0x10, 0, 0}, {0x3302, 0xcf, 0, 0}, {0x335f, 0x68, 0, 0},
+ {0x3360, 0x18, 0, 0}, {0x3361, 0x0c, 0, 0}, {0x3362, 0x68, 0, 0},
+ {0x3363, 0x08, 0, 0}, {0x3364, 0x04, 0, 0}, {0x3403, 0x42, 0, 0},
{0x3088, 0x08, 0, 0}, {0x3089, 0x00, 0, 0}, {0x308a, 0x06, 0, 0},
- {0x308b, 0x00, 0, 0}, {0x308d, 0x04, 0, 0}, {0x3086, 0x03, 0, 0},
- {0x3086, 0x00, 0, 0}, {0x3011, 0x01, 0, 0},
+ {0x308b, 0x00, 0, 0}, {0x304c, 0x81, 0, 0}, {0x300e, 0x35, 0, 0},
+ {0x300f, 0x21, 0, 0}, {0x3010, 0x20, 0, 0}, {0x3011, 0x01, 0, 0},
+ {0x3085, 0x20, 0, 0},
};
static struct reg_value ov3640_setting_15fps_XGA_1024_768[] = {
@@ -258,7 +206,7 @@ static struct reg_value ov3640_setting_30fps_VGA_640_480[] = {
{0x3012, 0x80, 0, 0}, {0x304d, 0x45, 0, 0}, {0x30a7, 0x5e, 0, 0},
{0x3087, 0x16, 0, 0}, {0x309c, 0x1a, 0, 0}, {0x30a2, 0xe4, 0, 0},
{0x30aa, 0x42, 0, 0}, {0x30b0, 0xff, 0, 0}, {0x30b1, 0xff, 0, 0},
- {0x30b2, 0x10, 0, 0}, {0x300e, 0x32, 0, 0}, {0x300f, 0x21, 0, 0},
+ {0x30b2, 0x13, 0, 0}, {0x300e, 0x32, 0, 0}, {0x300f, 0x21, 0, 0},
{0x3010, 0x20, 0, 0}, {0x3011, 0x01, 0, 0}, {0x304c, 0x82, 0, 0},
{0x30d7, 0x10, 0, 0}, {0x30d9, 0x0d, 0, 0}, {0x30db, 0x08, 0, 0},
{0x3016, 0x82, 0, 0}, {0x3018, 0x38, 0, 0}, {0x3019, 0x30, 0, 0},
@@ -278,13 +226,13 @@ static struct reg_value ov3640_setting_30fps_VGA_640_480[] = {
{0x336a, 0x52, 0, 0}, {0x3370, 0x46, 0, 0}, {0x3376, 0x38, 0, 0},
{0x3300, 0x13, 0, 0}, {0x30b8, 0x20, 0, 0}, {0x30b9, 0x17, 0, 0},
{0x30ba, 0x04, 0, 0}, {0x30bb, 0x08, 0, 0}, {0x3100, 0x02, 0, 0},
- {0x3301, 0x10, 0x30, 0}, {0x3304, 0x00, 0x03, 0}, {0x3400, 0x00, 0, 0},
+ {0x3301, 0xde, 0, 0}, {0x3304, 0x00, 0, 0}, {0x3400, 0x00, 0, 0},
{0x3404, 0x02, 0, 0}, {0x3600, 0xc0, 0, 0}, {0x308d, 0x04, 0, 0},
{0x3086, 0x03, 0, 0}, {0x3086, 0x00, 0, 0}, {0x3012, 0x10, 0, 0},
{0x3023, 0x06, 0, 0}, {0x3026, 0x03, 0, 0}, {0x3027, 0x04, 0, 0},
- {0x302a, 0x03, 0, 0}, {0x302b, 0x10, 0, 0}, {0x3075, 0x24, 0, 0},
- {0x300d, 0x01, 0, 0}, {0x30d7, 0x80, 0x80, 0}, {0x3069, 0x00, 0x40, 0},
- {0x303e, 0x00, 0, 0}, {0x303f, 0xc0, 0, 0}, {0x3302, 0x20, 0x20, 0},
+ {0x302a, 0x03, 0, 0}, {0x302b, 0xf0, 0, 0}, {0x3075, 0x24, 0, 0},
+ {0x300d, 0x01, 0, 0}, {0x30d7, 0x90, 0, 0}, {0x3069, 0x44, 0, 0},
+ {0x303e, 0x00, 0, 0}, {0x303f, 0xc0, 0, 0}, {0x3302, 0xef, 0, 0},
{0x335f, 0x34, 0, 0}, {0x3360, 0x0c, 0, 0}, {0x3361, 0x04, 0, 0},
{0x3362, 0x12, 0, 0}, {0x3363, 0x88, 0, 0}, {0x3364, 0xe4, 0, 0},
{0x3403, 0x42, 0, 0}, {0x3088, 0x02, 0, 0}, {0x3089, 0x80, 0, 0},
@@ -293,8 +241,11 @@ static struct reg_value ov3640_setting_30fps_VGA_640_480[] = {
{0x3088, 0x02, 0, 0}, {0x3089, 0x80, 0, 0}, {0x308a, 0x01, 0, 0},
{0x308b, 0xe0, 0, 0}, {0x300e, 0x37, 0, 0}, {0x300f, 0xe1, 0, 0},
{0x3010, 0x22, 0, 0}, {0x3011, 0x01, 0, 0}, {0x304c, 0x84, 0, 0},
- {0x3014, 0x04, 0, 0}, {0x3015, 0x02, 0, 0}, {0x302e, 0x00, 0, 0},
- {0x302d, 0x00, 0, 0},
+ {0x3014, 0x84, 0, 0}, {0x3015, 0x02, 0, 0}, {0x302e, 0x00, 0, 0},
+ {0x302d, 0x00, 0, 0}, {0x300e, 0x36, 0, 0}, {0x300f, 0x21, 0, 0},
+ {0x3010, 0x20, 0, 0}, {0x3011, 0x00, 0, 0}, {0x3070, 0x00, 0, 0},
+ {0x3071, 0xa8, 0, 0}, {0x301c, 0x06, 0, 0}, {0x3085, 0x20, 0, 0},
+
};
static struct reg_value ov3640_setting_15fps_QVGA_320_240[] = {
@@ -833,10 +784,35 @@ static int ov3640_init_mode(enum ov3640_frame_rate frame_rate,
u8 RegVal = 0;
int retval = 0;
+ u8 temp_reg1, temp_reg2, gain;
+ u16 preview_shutter, preview_extra_lines, preview_gain, capture_exposure;
+ u16 capture_line_width, capture_banding_filter, capture_gain, capture_maximum_shutter;
+ u16 capture_gain16, capture_pclk_frequency, capture_max_gain16;
+ u32 gain_exposure;
+
if (mode > ov3640_mode_MAX || mode < ov3640_mode_MIN) {
pr_err("Wrong ov3640 mode detected!\n");
return -1;
}
+ if (mode == ov3640_mode_QXGA_2048_1536 && frame_rate == ov3640_15_fps) {
+ /*stop AEC/AGC */
+ ov3640_read_reg(0x3013, &temp_reg1);
+ temp_reg1 = temp_reg1 & 0xfa;
+ ov3640_write_reg(0x3013, temp_reg1);
+
+ /*read out preview_shutter*/
+ ov3640_read_reg(0x3003, &temp_reg1);
+ ov3640_read_reg(0x3002, &temp_reg2);
+ preview_shutter = (temp_reg1) | (temp_reg2 << 8);
+ /*read out preview_extra_lines*/
+ ov3640_read_reg(0x302E, &temp_reg1);
+ ov3640_read_reg(0x302D, &temp_reg2);
+ preview_extra_lines = (temp_reg1) | (temp_reg2 << 8);
+
+ /*read out preview_gain*/
+ ov3640_read_reg(0x3001, &temp_reg1);
+ preview_gain = (((temp_reg1 & 0xF0) >> 4) + 1) * (16 + (temp_reg1 & 0x0F));
+ }
pModeSetting = ov3640_mode_info_data[frame_rate][mode].init_data_ptr;
iModeSettingArySize =
@@ -872,6 +848,82 @@ static int ov3640_init_mode(enum ov3640_frame_rate frame_rate,
if (Delay_ms)
msleep(Delay_ms);
}
+ if (mode == ov3640_mode_QXGA_2048_1536 && frame_rate == ov3640_15_fps) {
+ capture_max_gain16 = 64;
+ /*Set Capture_Maximum_Shutter*/
+ capture_maximum_shutter = 1640;
+
+ capture_line_width = 2376;
+
+ capture_pclk_frequency = 28;
+
+ /* 50Hz banding filter calculate*/
+ capture_banding_filter = capture_pclk_frequency * 1000000 / 100 / (2 * capture_line_width);
+
+ /*capture exposure calculate*/
+ capture_exposure = (preview_shutter + preview_extra_lines) / 2;
+ /*redistribute gain and exposure*/
+ gain_exposure = preview_gain * capture_exposure;
+
+ if (gain_exposure < capture_banding_filter * 16) {
+ capture_exposure = gain_exposure / 16;
+ if (0 == capture_exposure) {
+ capture_exposure = 1;
+ }
+ capture_gain = (gain_exposure*2 + 1) / capture_exposure / 2;
+ } else {
+ if (gain_exposure > capture_maximum_shutter * 16) {
+ capture_exposure = capture_maximum_shutter;
+ capture_gain = (gain_exposure*2 + 1)/capture_maximum_shutter/2;
+ if (capture_gain > capture_max_gain16) {
+ capture_exposure = gain_exposure*11/10/capture_max_gain16;
+ if (0 == capture_exposure) {
+ capture_exposure = 1;
+ }
+ capture_exposure = capture_exposure / capture_banding_filter;
+ capture_exposure = capture_exposure * capture_banding_filter;
+ capture_gain = (gain_exposure*2 + 1) / capture_exposure/2;
+ }
+ } else {
+ capture_exposure = gain_exposure / 16 / capture_banding_filter;
+ capture_exposure = capture_exposure * capture_banding_filter;
+ if (0 == capture_exposure) {
+ capture_exposure = 1;
+ }
+ capture_gain = (gain_exposure*2 + 1) / capture_exposure/2;
+ }
+ }
+ capture_gain = capture_gain * 500/2048;
+ capture_gain16 = capture_gain * 16;
+
+ /*write back Capture_Exposure*/
+ ov3640_write_reg(0x3003, capture_exposure & 0xFF);
+ ov3640_write_reg(0x3002, (capture_exposure & 0xFF00) >> 8);
+
+ if (capture_gain16 > 31) {
+ capture_gain16 = capture_gain16/2;
+ gain = 0x10;
+ }
+ if (capture_gain16 > 31) {
+ capture_gain16 = capture_gain16/2;
+ gain = gain | 0x20;
+ }
+ if (capture_gain16 > 31) {
+ capture_gain16 = capture_gain16/2;
+ gain = gain | 0x40;
+ }
+ if (capture_gain16 > 31) {
+ capture_gain16 = capture_gain16/2;
+ gain = gain | 0x80;
+ }
+ if (capture_gain16 > 16) {
+ gain = gain | (capture_gain16 - 16);
+ }
+ ov3640_write_reg(0x3001, gain);
+ ov3640_read_reg(0x3021, &gain);
+ ov3640_read_reg(0x3023, &gain);
+ }
+
err:
return retval;
}