From 9625dc1c42b6e6171d3e8260f85d6445b48fc49d Mon Sep 17 00:00:00 2001 From: "nengwen.chen" Date: Thu, 10 May 2018 19:32:49 +0800 Subject: [PATCH] atv_demod: Add atv color and sound system setting separately [7/8] PD#165560: Add atv color and sound system setting separately. Change-Id: I8279143706ddfd705bce95c3f40f701ae9af7829 Signed-off-by: nengwen.chen --- drivers/amlogic/atv_demod/atv_demod_driver.h | 1 + drivers/amlogic/atv_demod/atv_demod_ops.c | 11 +- drivers/amlogic/atv_demod/atv_demod_v4l2.c | 172 ++++++++---- drivers/amlogic/atv_demod/atvdemod_func.c | 275 +++++++++++++++++-- include/linux/amlogic/aml_atvdemod.h | 2 + 5 files changed, 378 insertions(+), 83 deletions(-) diff --git a/drivers/amlogic/atv_demod/atv_demod_driver.h b/drivers/amlogic/atv_demod/atv_demod_driver.h index 270e72b627da..3aed46cb0401 100644 --- a/drivers/amlogic/atv_demod/atv_demod_driver.h +++ b/drivers/amlogic/atv_demod/atv_demod_driver.h @@ -48,6 +48,7 @@ struct aml_atvdemod_device { unsigned int if_freq; unsigned int if_inv; u64 std; + unsigned int audmode; int fre_offset; struct pinctrl *pin; diff --git a/drivers/amlogic/atv_demod/atv_demod_ops.c b/drivers/amlogic/atv_demod/atv_demod_ops.c index 894753509f29..78d3447c2a52 100644 --- a/drivers/amlogic/atv_demod/atv_demod_ops.c +++ b/drivers/amlogic/atv_demod/atv_demod_ops.c @@ -272,7 +272,8 @@ static void atv_demod_set_params(struct dvb_frontend *fe, if ((atvdemod_param->param.std != amlatvdemod_devp->std) || (atvdemod_param->tuner_id == AM_TUNER_R840) || (atvdemod_param->tuner_id == AM_TUNER_SI2151) || - (atvdemod_param->tuner_id == AM_TUNER_MXL661)) { + (atvdemod_param->tuner_id == AM_TUNER_MXL661) || + (atvdemod_param->tuner_id == AM_TUNER_SI2159)) { /* open AGC if needed */ if (amlatvdemod_devp->pin != NULL) devm_pinctrl_put(amlatvdemod_devp->pin); @@ -285,8 +286,14 @@ static void atv_demod_set_params(struct dvb_frontend *fe, last_frq = atvdemod_param->param.frequency; last_std = atvdemod_param->param.std; #endif - if (1/*atvdemod_param->param.std != amlatvdemod_devp->std*/) { + if (1) { + /* + * atvdemod_param->param.std != amlatvdemod_devp->std || + * atvdemod_param->param.audmode != amlatvdemod_devp->audmode + */ amlatvdemod_devp->std = atvdemod_param->param.std; + amlatvdemod_devp->audmode = + atvdemod_param->param.audmode; amlatvdemod_devp->if_freq = atvdemod_param->if_freq; amlatvdemod_devp->if_inv = atvdemod_param->if_inv; amlatvdemod_devp->tuner_id = atvdemod_param->tuner_id; diff --git a/drivers/amlogic/atv_demod/atv_demod_v4l2.c b/drivers/amlogic/atv_demod/atv_demod_v4l2.c index fe8db19d38e1..324167656a8f 100644 --- a/drivers/amlogic/atv_demod/atv_demod_v4l2.c +++ b/drivers/amlogic/atv_demod/atv_demod_v4l2.c @@ -114,62 +114,42 @@ static v4l2_std_id demod_fmt_2_v4l2_std(int fmt) static v4l2_std_id trans_tvin_fmt_to_v4l2_std(int fmt) { v4l2_std_id std = 0; -#if 0 /* Want to remove ours define V4L2_COLOR_STD_NTSC/PAL/SECAM.*/ + switch (fmt) { case TVIN_SIG_FMT_CVBS_NTSC_M: - std = V4L2_STD_NTSC; + std = V4L2_COLOR_STD_NTSC | V4L2_STD_NTSC_M; break; case TVIN_SIG_FMT_CVBS_NTSC_443: - std = V4L2_STD_NTSC_443; + std = V4L2_COLOR_STD_NTSC | V4L2_STD_NTSC_443; + break; + case TVIN_SIG_FMT_CVBS_NTSC_50: + std = V4L2_COLOR_STD_NTSC | V4L2_STD_NTSC_M; break; case TVIN_SIG_FMT_CVBS_PAL_I: - std = V4L2_STD_PAL_I; + std = V4L2_COLOR_STD_PAL | V4L2_STD_PAL_I; break; case TVIN_SIG_FMT_CVBS_PAL_M: - std = V4L2_STD_PAL_M; + std = V4L2_COLOR_STD_PAL | V4L2_STD_PAL_M; break; case TVIN_SIG_FMT_CVBS_PAL_60: - std = V4L2_STD_PAL_60; + std = V4L2_COLOR_STD_PAL | V4L2_STD_PAL_60; break; case TVIN_SIG_FMT_CVBS_PAL_CN: - std = V4L2_STD_PAL_Nc; + std = V4L2_COLOR_STD_PAL | V4L2_STD_PAL_Nc; break; case TVIN_SIG_FMT_CVBS_SECAM: - std = V4L2_STD_SECAM; + std = V4L2_COLOR_STD_SECAM | V4L2_STD_SECAM_L; break; default: pr_err("%s: Unsupport fmt: 0x%x\n", __func__, fmt); break; } -#else - switch (fmt) { - case TVIN_SIG_FMT_CVBS_NTSC_M: - case TVIN_SIG_FMT_CVBS_NTSC_443: - case TVIN_SIG_FMT_CVBS_NTSC_50: - std = V4L2_COLOR_STD_NTSC; - break; - - case TVIN_SIG_FMT_CVBS_PAL_I: - case TVIN_SIG_FMT_CVBS_PAL_M: - case TVIN_SIG_FMT_CVBS_PAL_60: - case TVIN_SIG_FMT_CVBS_PAL_CN: - std = V4L2_COLOR_STD_PAL; - break; - - case TVIN_SIG_FMT_CVBS_SECAM: - std = V4L2_COLOR_STD_SECAM; - break; - default: - pr_err("%s Unsupport fmt: 0x%x\n", __func__, fmt); - break; - } -#endif return std; } static void v4l2_fe_try_analog_format(struct v4l2_frontend *v4l2_fe, - bool auto_search_std, v4l2_std_id *video_fmt, + int auto_search_std, v4l2_std_id *video_fmt, unsigned int *audio_fmt) { struct dvb_frontend *fe = &v4l2_fe->fe; @@ -181,7 +161,7 @@ static void v4l2_fe_try_analog_format(struct v4l2_frontend *v4l2_fe, v4l2_std_id std_bk = 0; unsigned int audio = 0; - if (auto_search_std == true) { + if (auto_search_std & 0x01) { for (i = 0; i < try_vfmt_cnt; i++) { if (aml_fe_hook_get_fmt == NULL) { pr_err("%s: aml_fe_hook_get_fmt == NULL.\n", @@ -209,16 +189,18 @@ static void v4l2_fe_try_analog_format(struct v4l2_frontend *v4l2_fe, if (p->std & V4L2_COLOR_STD_PAL) p->std = V4L2_COLOR_STD_NTSC | V4L2_STD_NTSC_M; +/* else if (p->std & V4L2_COLOR_STD_NTSC) p->std = V4L2_COLOR_STD_SECAM | V4L2_STD_SECAM; - else if (p->std & V4L2_COLOR_STD_SECAM) +*/ + else if (p->std & V4L2_COLOR_STD_NTSC) p->std = V4L2_COLOR_STD_PAL | V4L2_STD_PAL_DK; p->frequency += 1; params.frequency = p->frequency; - params.mode = p->flag; + params.mode = p->afc_range; params.audmode = p->audmode; params.std = p->std; @@ -239,7 +221,7 @@ static void v4l2_fe_try_analog_format(struct v4l2_frontend *v4l2_fe, p->audmode = V4L2_STD_PAL_DK; params.frequency = p->frequency; - params.mode = p->flag; + params.mode = p->afc_range; params.audmode = p->audmode; params.std = p->std; @@ -258,7 +240,12 @@ static void v4l2_fe_try_analog_format(struct v4l2_frontend *v4l2_fe, *video_fmt = std_bk; - if (std_bk == V4L2_COLOR_STD_NTSC) { + if (!(auto_search_std & 0x02)) { + *audio_fmt = p->audmode; + return; + } + + if (std_bk & V4L2_COLOR_STD_NTSC) { #if 1 /* For TV Signal Generator(TG39) test, NTSC need support other audio.*/ amlatvdemod_set_std(AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK); audio = aml_audiomode_autodet(fe); @@ -275,8 +262,16 @@ static void v4l2_fe_try_analog_format(struct v4l2_frontend *v4l2_fe, audio = V4L2_STD_NTSC_M; *video_fmt |= V4L2_STD_NTSC_M; #endif - } else if (std_bk == V4L2_COLOR_STD_SECAM) { + } else if (std_bk & V4L2_COLOR_STD_SECAM) { +#if 1 /* For support SECAM-DK/BG/I/L */ + amlatvdemod_set_std(AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_L); + audio = aml_audiomode_autodet(fe); + pr_info("autodet audmode 0x%x\n", audio); + audio = demod_fmt_2_v4l2_std(audio); + pr_info("v4l2_std audmode 0x%x\n", audio); +#else audio = V4L2_STD_SECAM_L; +#endif } else { /*V4L2_COLOR_STD_PAL*/ amlatvdemod_set_std(AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK); @@ -292,7 +287,6 @@ static void v4l2_fe_try_analog_format(struct v4l2_frontend *v4l2_fe, #endif } - *video_fmt |= audio; *audio_fmt = audio; } @@ -412,7 +406,7 @@ static int v4l2_fe_afc_closer(struct v4l2_frontend *v4l2_fe, int minafcfreq, p->frequency++; if (fe->ops.tuner_ops.set_analog_params) { params.frequency = p->frequency; - params.mode = p->flag; + params.mode = p->afc_range; params.audmode = p->audmode; params.std = p->std; fe->ops.tuner_ops.set_analog_params(fe, @@ -445,8 +439,9 @@ static enum v4l2_search v4l2_frontend_search(struct v4l2_frontend *v4l2_fe) v4l2_std_id std_bk = 0; unsigned int audio = 0; int double_check_cnt = 1; - bool auto_search_std = false; + int auto_search_std = 0; int search_count = 0; + bool try_secam = false; int ret = -1; unsigned int tuner_id = v4l2_fe->tuner_id; @@ -458,7 +453,8 @@ static enum v4l2_search v4l2_frontend_search(struct v4l2_frontend *v4l2_fe) if (unlikely(!fe || !p || !fe->ops.tuner_ops.get_status || - !fe->ops.analog_ops.has_signal)) { + !fe->ops.analog_ops.has_signal || + !fe->ops.analog_ops.set_params)) { pr_err("[%s] error: NULL function or pointer.\n", __func__); return V4L2_SEARCH_INVALID; } @@ -481,11 +477,29 @@ static enum v4l2_search v4l2_frontend_search(struct v4l2_frontend *v4l2_fe) */ if (p->std == 0) { p->std = V4L2_COLOR_STD_NTSC | V4L2_STD_NTSC_M; - auto_search_std = true; - pr_dbg("[%s] user analog.std is 0, so set it to PAL | DK.\n", + auto_search_std = 0x01; + pr_dbg("[%s] user std is 0, so set it to NTSC | M.\n", __func__); } + if (p->audmode == 0) { + if (auto_search_std) + p->audmode = p->std & 0x00FFFFFF; + else { + if (p->std & V4L2_COLOR_STD_PAL) + p->audmode = V4L2_STD_PAL_DK; + else if (p->std & V4L2_COLOR_STD_NTSC) + p->audmode = V4L2_STD_NTSC_M; + else if (p->std & V4L2_COLOR_STD_SECAM) + p->audmode = V4L2_STD_PAL_DK; + + p->std = (p->std & 0xFF000000) | p->audmode; + } + auto_search_std |= 0x02; + pr_dbg("[%s] user audmode is 0, so set it to %s.\n", + __func__, v4l2_std_to_str(p->audmode)); + } + /*afc tune disable*/ //TODO: afc_timer_disable(); //analog_search_flag = 1; @@ -508,8 +522,8 @@ static enum v4l2_search v4l2_frontend_search(struct v4l2_frontend *v4l2_fe) } /**enter auto search mode**/ - pr_dbg("[%s] Auto search std: 0x%08x\n", - __func__, (unsigned int) p->std); + pr_dbg("[%s] Auto search std: 0x%08x, audmode: 0x%08x\n", + __func__, (unsigned int) p->std, p->audmode); #ifdef DEBUG_TIME_CUS time_end = jiffies_to_msecs(jiffies); @@ -521,13 +535,11 @@ static enum v4l2_search v4l2_frontend_search(struct v4l2_frontend *v4l2_fe) while (minafcfreq <= p->frequency && p->frequency <= maxafcfreq) { - if (fe->ops.analog_ops.set_params) { - params.frequency = p->frequency; - params.mode = p->flag; - params.audmode = p->audmode; - params.std = p->std; - fe->ops.analog_ops.set_params(fe, ¶ms); - } + params.frequency = p->frequency; + params.mode = p->afc_range; + params.audmode = p->audmode; + params.std = p->std; + fe->ops.analog_ops.set_params(fe, ¶ms); pr_dbg("[%s] [%d] is processing, [min=%d, max=%d].\n", __func__, p->frequency, minafcfreq, maxafcfreq); @@ -558,10 +570,54 @@ static enum v4l2_search v4l2_frontend_search(struct v4l2_frontend *v4l2_fe) break; } - if (tuner_status_cnt_local == 0) + if (tuner_status_cnt_local == 0) { + if (auto_search_std && + !(p->std & V4L2_COLOR_STD_SECAM) && + !(p->std & V4L2_STD_SECAM_L)) { + /* backup the std and audio mode */ + std_bk = p->std; + audio = p->audmode; + + p->std = (V4L2_COLOR_STD_SECAM + | V4L2_STD_SECAM_L); + p->audmode = V4L2_STD_SECAM_L; + + params.frequency = p->frequency; + params.mode = p->afc_range; + params.audmode = p->audmode; + params.std = p->std; + fe->ops.analog_ops.set_params(fe, + ¶ms); + + try_secam = true; + + tuner_status_cnt_local = + tuner_status_cnt / 2; + + continue; + } + + if (try_secam) { + p->std = std_bk; + p->audmode = audio; + + params.frequency = p->frequency; + params.mode = p->afc_range; + params.audmode = p->audmode; + params.std = p->std; + fe->ops.analog_ops.set_params(fe, + ¶ms); + + try_secam = false; + } + break; + } } while (1); + std_bk = 0; + audio = 0; + if (pll_lock) { pr_dbg("[%s] freq: [%d] pll lock success\n", @@ -592,6 +648,7 @@ static enum v4l2_search v4l2_frontend_search(struct v4l2_frontend *v4l2_fe) /*avoid std unenable */ p->frequency -= 1; std_bk = 0; + audio = 0; } #ifdef DEBUG_TIME_CUS time_end = jiffies_to_msecs(jiffies); @@ -609,16 +666,18 @@ static enum v4l2_search v4l2_frontend_search(struct v4l2_frontend *v4l2_fe) } /*avoid sound format is not match after search over */ - if (std_bk != 0) { + if (std_bk != 0 && audio != 0) { p->std = std_bk; + p->audmode = audio; params.frequency = p->frequency; - params.mode = p->flag; + params.mode = p->afc_range; params.audmode = p->audmode; params.std = p->std; fe->ops.analog_ops.set_params(fe, ¶ms); std_bk = 0; + audio = 0; } pr_dbg("[%s] freq[analog.std:0x%08x] is[%d] unlock\n", @@ -987,6 +1046,7 @@ static int v4l2_set_frontend(struct v4l2_frontend *v4l2_fe, } else if (fe->ops.analog_ops.set_params) { /* TODO:*/ p.frequency = params->frequency; + p.mode = params->afc_range; p.std = params->std; p.audmode = params->audmode; fe->ops.analog_ops.set_params(fe, &p); diff --git a/drivers/amlogic/atv_demod/atvdemod_func.c b/drivers/amlogic/atv_demod/atvdemod_func.c index 629f18e2092f..97db31187608 100644 --- a/drivers/amlogic/atv_demod/atvdemod_func.c +++ b/drivers/amlogic/atv_demod/atvdemod_func.c @@ -63,6 +63,46 @@ static int non_std_en; module_param(non_std_en, int, 0644); MODULE_PARM_DESC(non_std_en, "\n non_std_en\n"); +static int non_std_onoff; +module_param(non_std_onoff, int, 0644); +MODULE_PARM_DESC(non_std_onoff, "\n non_std_onoff\n"); + +static int non_std_times = 50; +module_param(non_std_times, int, 0644); +MODULE_PARM_DESC(non_std_times, "\n non_std_times\n"); + +static int non_std_thld_4c_h = 100; +module_param(non_std_thld_4c_h, int, 0644); +MODULE_PARM_DESC(non_std_thld_4c_h, "\n non_std_thld_4c_h\n"); + +static int non_std_thld_4c_l = 30; +module_param(non_std_thld_4c_l, int, 0644); +MODULE_PARM_DESC(non_std_thld_4c_l, "\n non_std_thld_4c_l\n"); + +static int non_std_thld_54_h = 500; +module_param(non_std_thld_54_h, int, 0644); +MODULE_PARM_DESC(non_std_thld_54_h, "\n non_std_thld_54_h\n"); + +static int non_std_thld_54_l = 300; +module_param(non_std_thld_54_l, int, 0644); +MODULE_PARM_DESC(non_std_thld_54_l, "\n non_std_thld_54_l\n"); + +static int sum1_thd_h; +module_param(sum1_thd_h, int, 0644); +MODULE_PARM_DESC(sum1_thd_h, "\n sum1_thd_h\n"); + +static int sum1_thd_l = 0x7fffffff; +module_param(sum1_thd_l, int, 0644); +MODULE_PARM_DESC(sum1_thd_l, "\n sum1_thd_l\n"); + +static int sum2_thd_h; +module_param(sum2_thd_h, int, 0644); +MODULE_PARM_DESC(sum2_thd_h, "\n sum2_thd_h\n"); + +static int sum2_thd_l = 0x7fffffff; +module_param(sum2_thd_l, int, 0644); +MODULE_PARM_DESC(sum2_thd_l, "\n sum2_thd_l\n"); + static int atv_video_gain; module_param(atv_video_gain, int, 0644); MODULE_PARM_DESC(atv_video_gain, "\n atv_video_gain reg:0x0f44\n"); @@ -419,6 +459,11 @@ void power_on_receiver(void) void atv_dmd_misc(void) { + if (broad_std == AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_L) { + pr_info("broad_std is SECAM_L, no need config misc\n"); + return; + } + atv_dmd_wr_byte(APB_BLOCK_ADDR_AGC_PWM, 0x08, 0x38); /*zhuangwei*/ /*cpu.write_byte(8'h1A,8'h0E,8'h06);//zhuangwei*/ /*cpu.write_byte(8'h19,8'h01,8'h7f);//zhuangwei*/ @@ -439,8 +484,10 @@ void atv_dmd_misc(void) atv_dmd_wr_long(APB_BLOCK_ADDR_AGC_PWM, 0x1C, 0x03010855); } else { + /* bit[0] = 0 for auto agc */ + /* bit[0] = 1 for foce agc */ atv_dmd_wr_long(APB_BLOCK_ADDR_AGC_PWM, - 0x08, 0x601b0201); + 0x08, 0x601b0200); } /*dezhi@20150610a 0x1a maybe better?!*/ /* atv_dmd_wr_byte(APB_BLOCK_ADDR_AGC_PWM, 0x09, 0x19); */ @@ -492,6 +539,147 @@ void atv_dmd_misc(void) } +void atv_dmd_non_std_set(bool enable) +{ + unsigned long temp = 0; + int temp1 = 0; + int temp2 = 0; + int vdagc1_diff = 0; + unsigned int vdagc2_diff = 0; + static int times; + static int vdagc1_max; + static int vdagc1_min = 0xffff; + static int vdagc2_max = -0x7fff; + static int vdagc2_min = 0x7fff; + + static int vdagc1_d1; + static int vdagc2_d1; + static int sum1; + static int sum2; + static unsigned char delay_times; + static bool has_entry; + + int vpll_lock = 0; + int line_lock = 0; + + if (!enable || broad_std == AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_L) { + times = 0; + vdagc1_max = 0; + vdagc1_min = 0xffff; + vdagc2_max = -0x7fff; + vdagc2_min = 0x7fff; + vdagc1_d1 = 0; + vdagc2_d1 = 0; + sum1 = 0; + sum2 = 0; + delay_times = 0; + has_entry = false; + + return; + } + + /* pll lock */ + vpll_lock = atv_dmd_rd_byte(APB_BLOCK_ADDR_CARR_RCVY, 0x43) & 0x01; + /* line lock */ + line_lock = atv_dmd_rd_byte(APB_BLOCK_ADDR_VDAGC, 0x4f) & 0x10; + + if (vpll_lock != 0 || line_lock != 0) { + has_entry = false; + delay_times = 0; + + /* reset non std params */ + vdagc1_d1 = 0; + vdagc2_d1 = 0; + + vdagc1_max = 0; + vdagc1_min = 0xffff; + vdagc2_max = -0x7fff; + vdagc2_min = 0x7fff; + times = 0; + sum1 = 0; + sum2 = 0; + + return; + } + + /* delay 5s entry checking */ + if (delay_times++ <= 50 && !has_entry) + return; + + delay_times = 0; + has_entry = true; + + temp = atv_dmd_rd_long(APB_BLOCK_ADDR_VDAGC, 0x4c); + temp1 = temp >> 16 & 0xffff; + if (temp1 < vdagc1_min) + vdagc1_min = temp1; + + if (temp1 > vdagc1_max) + vdagc1_max = temp1; + + temp = atv_dmd_rd_long(APB_BLOCK_ADDR_VDAGC, 0x54); + temp = temp >> 16 & 0xffff; + if ((temp >> 15) & 1) + temp2 = temp - 0x10000; + else + temp2 = temp; + + if (temp2 < vdagc2_min) + vdagc2_min = temp2; + + if (temp2 > vdagc2_max) + vdagc2_max = temp2; + + /*Count the value in total = 100ms (timer) * non_std_times (times). */ + if (times == non_std_times) { + vdagc1_diff = vdagc1_max - vdagc1_min; + vdagc2_diff = vdagc2_max - vdagc2_min; + + if ((vdagc1_diff > non_std_thld_4c_h && + vdagc2_diff > non_std_thld_54_h && + sum1 > sum1_thd_h && + sum2 > sum2_thd_h)) { + atv_dmd_wr_long(0x09, 0x00, 0x2030503); + atv_dmd_wr_long(0x0f, 0x44, 0x4d0808c1); + atv_dmd_wr_long(APB_BLOCK_ADDR_CARR_RCVY, + 0x24, 0x0c010801); + } else if (vdagc1_diff < non_std_thld_4c_l && + vdagc2_diff < non_std_thld_54_l && + sum1 < sum1_thd_l && + sum2 < sum2_thd_l) { + atv_dmd_wr_long(0x09, 0x00, extra_input_fil_val); + if (atv_video_gain) + atv_dmd_wr_long(0x0f, 0x44, atv_video_gain); + else + atv_dmd_wr_long(0x0f, 0x44, 0xfc0808c1); + atv_dmd_wr_long(APB_BLOCK_ADDR_CARR_RCVY, 0x24, + carrier_amplif_val); + } + + times = 0; + + pr_info("===> vdagc1_diff[0x0f4c]: %d\n", vdagc1_diff); + pr_info("===> vdagc2_diff[0x0f54]: %d\n", vdagc2_diff); + pr_info("===> vdagc1_sum1[0x0f4c]: 0x%x\n", sum1); + pr_info("===> vdagc2_sum2[0x0f4c]: 0x%x\n", sum2); + + vdagc1_max = 0; + vdagc1_min = 0xffff; + vdagc2_max = -0x7fff; + vdagc2_min = 0x7fff; + + sum1 = 0; + sum2 = 0; + } else { + times++; + sum1 += abs(vdagc1_d1 - temp1); + sum2 += abs(vdagc2_d1 - temp2); + } + + vdagc1_d1 = temp1; + vdagc2_d1 = temp2; +} + /*Broadcast_Standard*/ /* 0: NTSC*/ /* 1: NTSC-J*/ @@ -710,7 +898,8 @@ void configure_receiver(int Broadcast_Standard, unsigned int Tuner_IF_Frequency, gp_cv_g2 = 0x3f6c2e; } else if ((Broadcast_Standard == AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK) || - (Broadcast_Standard == AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_DK3)) { + (Broadcast_Standard == AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_DK3) || + (Broadcast_Standard == AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_L)) { gp_coeff_1[0] = 0x47777; gp_coeff_1[1] = 0x77777; gp_coeff_1[2] = 0x5d777; @@ -1605,6 +1794,9 @@ void atvdemod_timer_handler(unsigned long arg) if (aml_atvdemod_get_btsc_sap_mode() == 1 && aud_std == AUDIO_STANDARD_BTSC) audio_mode_det(aud_mode); + + if (non_std_onoff) + atv_dmd_non_std_set(true); } int atvdemod_clk_init(void) @@ -1760,6 +1952,7 @@ int atvdemod_init(void) if (timer_init_flag == 1) { del_timer_sync(&atvdemod_timer); timer_init_flag = 0; + atv_dmd_non_std_set(false); } } @@ -1813,6 +2006,7 @@ void atvdemod_uninit(void) if (timer_init_flag == 1) { del_timer_sync(&atvdemod_timer); timer_init_flag = 0; + atv_dmd_non_std_set(false); } } } @@ -1822,27 +2016,42 @@ void atv_dmd_set_std(void) v4l2_std_id ptstd = amlatvdemod_devp->std; /* set broad standard of tuner*/ - if ((ptstd & V4L2_COLOR_STD_PAL) && ((ptstd & V4L2_STD_B) || - (ptstd & V4L2_STD_G))) { + if (((ptstd & V4L2_COLOR_STD_PAL) + || (ptstd & V4L2_COLOR_STD_SECAM) + || (ptstd & V4L2_COLOR_STD_NTSC)) + && ((ptstd & V4L2_STD_B) || (ptstd & V4L2_STD_G))) { amlatvdemod_devp->fre_offset = 2250000; freq_hz_cvrt = AML_ATV_DEMOD_FREQ_50HZ_VERT; broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_BG; if_freq = 3250000; gde_curve = 2; - } else if ((ptstd & V4L2_COLOR_STD_PAL) && (ptstd & V4L2_STD_DK)) { + } else if (((ptstd & V4L2_COLOR_STD_PAL) + || (ptstd & V4L2_COLOR_STD_SECAM) + || (ptstd & V4L2_COLOR_STD_NTSC)) + && (ptstd & V4L2_STD_DK)) { amlatvdemod_devp->fre_offset = 2250000; freq_hz_cvrt = AML_ATV_DEMOD_FREQ_50HZ_VERT; if_freq = 3250000; broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK; gde_curve = 3; - } else if ((ptstd & V4L2_COLOR_STD_PAL) && (ptstd & V4L2_STD_PAL_M)) { + } else if (((ptstd & V4L2_COLOR_STD_PAL) + || (ptstd & V4L2_COLOR_STD_SECAM)) + && (ptstd & V4L2_STD_PAL_M)) { amlatvdemod_devp->fre_offset = 2250000; freq_hz_cvrt = AML_ATV_DEMOD_FREQ_60HZ_VERT; broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M; if_freq = 4250000; gde_curve = 0; - } else if ((ptstd & V4L2_COLOR_STD_NTSC) && - ((ptstd & V4L2_STD_NTSC_M) || (ptstd & V4L2_STD_PAL_M))) { + } else if (((ptstd & V4L2_COLOR_STD_PAL) || + (ptstd & V4L2_COLOR_STD_NTSC)) + && (ptstd & V4L2_STD_PAL_I)) { + amlatvdemod_devp->fre_offset = 2750000; + freq_hz_cvrt = AML_ATV_DEMOD_FREQ_50HZ_VERT; + broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_I; + if_freq = 3250000; + gde_curve = 4; + } else if ((ptstd & V4L2_COLOR_STD_NTSC) && ((ptstd & V4L2_STD_NTSC_M) + || (ptstd & V4L2_STD_PAL_M))) { amlatvdemod_devp->fre_offset = 1750000; freq_hz_cvrt = AML_ATV_DEMOD_FREQ_60HZ_VERT; if_freq = 4250000; @@ -1860,12 +2069,6 @@ void atv_dmd_set_std(void) if_freq = 4250000; broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_BG; gde_curve = 0; - } else if ((ptstd & V4L2_COLOR_STD_NTSC) && (ptstd & V4L2_STD_PAL_I)) { - amlatvdemod_devp->fre_offset = 1750000; - freq_hz_cvrt = AML_ATV_DEMOD_FREQ_60HZ_VERT; - if_freq = 4250000; - broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_I; - gde_curve = 0; } else if ((ptstd & V4L2_COLOR_STD_NTSC) && (ptstd & V4L2_STD_NTSC_M_JP)) { amlatvdemod_devp->fre_offset = 1750000; @@ -1900,9 +2103,11 @@ void atv_dmd_set_std(void) if_inv = amlatvdemod_devp->if_inv; } - pr_info("[%s] broad_std:%d, freq_hz_cvrt:0x%x, fre_offset:%d.\n", - __func__, broad_std, freq_hz_cvrt, - amlatvdemod_devp->fre_offset); + pr_info + ("[atvdemod..]%s: broad_std %d,hz_cvrt:0x%x, offset:%d,std:0x%x.\n", + __func__, broad_std, freq_hz_cvrt, amlatvdemod_devp->fre_offset, + (unsigned int) ptstd); + if (atvdemod_init()) pr_info("[%s]: atv restart error.\n", __func__); } @@ -1923,6 +2128,7 @@ int aml_audiomode_autodet(struct dvb_frontend *fe) int num = 0, i = 0, final_id = 0; int delay_ms = 10, delay_ms_default = 10; int cur_std = ID_PAL_DK; + bool secam_signal = false; #if 0 temp_data = atv_dmd_rd_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x02); @@ -1954,15 +2160,27 @@ int aml_audiomode_autodet(struct dvb_frontend *fe) case AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_L: case AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_DK2: case AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_DK3: - broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_L; - atvdemod_init(); - temp_data = atv_dmd_rd_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x02); + if (!(param->param.std & V4L2_COLOR_STD_SECAM) || + !(param->param.std & V4L2_STD_SECAM_L)) { + secam_signal = true; + broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M; + } else { + broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_L; + atvdemod_init(); + temp_data = atv_dmd_rd_reg(APB_BLOCK_ADDR_SIF_STG_2, + 0x02); - temp_data = temp_data & (~0x80); /* 0xbf; */ + temp_data = temp_data & (~0x80); /* 0xbf; */ + + atv_dmd_wr_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x02, + temp_data); + /* pr_err("%s, SECAM ,audio set SECAM_L\n", + * __func__); + */ + return broad_std; + } + break; - atv_dmd_wr_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x02, temp_data); - /* pr_err("%s, SECAM ,audio set SECAM_L\n", __func__); */ - return broad_std; default: pr_err("unsupport broadcast_standard!!!\n"); temp_data = atv_dmd_rd_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x02); @@ -2010,8 +2228,15 @@ int aml_audiomode_autodet(struct dvb_frontend *fe) broad_std = broad_std_final; pr_err("%s:broad_std:%d,carrier_power_average_max:%lu\n", __func__, broad_std, carrier_power_average_max); - if (carrier_power_average_max < 150) + if (carrier_power_average_max < 150) { pr_err("%s,carrier too low error\n", __func__); + if (secam_signal) { + broad_std = + AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_L; + pr_err("%s,set broad_std to SECAM_L\n", + __func__); + } + } if (broad_std == AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M) { /*the max except palm*/ carrier_power_average[final_id] = 0; diff --git a/include/linux/amlogic/aml_atvdemod.h b/include/linux/amlogic/aml_atvdemod.h index 790dbb33f482..b63f3ee61ae7 100644 --- a/include/linux/amlogic/aml_atvdemod.h +++ b/include/linux/amlogic/aml_atvdemod.h @@ -102,6 +102,8 @@ static inline const char *v4l2_std_to_str(v4l2_std_id std) return "V4L2_STD_NTSC"; case V4L2_STD_SECAM_DK: return "V4L2_STD_SECAM_DK"; + case (V4L2_STD_SECAM_B | V4L2_STD_SECAM_G): + return "V4L2_STD_SECAM_BG"; case V4L2_STD_SECAM: return "V4L2_STD_SECAM"; case V4L2_STD_525_60: