atv_demod: ATV sound system cannot be auto detected [1/2]
authornengwen.chen <nengwen.chen@amlogic.com>
Wed, 17 Oct 2018 09:44:38 +0000 (17:44 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Thu, 18 Oct 2018 07:09:00 +0000 (00:09 -0700)
PD#TV-44

Problem:
ATV sound system cannot be auto detected.

Solution:
Update demod and tuner config after adjust freqency, so that audio can detect.

Verify:
verified by einstein and p321

Change-Id: I8ce70a8f1fd2261c098b7b7f02c93ee061dd52c9
Signed-off-by: nengwen.chen <nengwen.chen@amlogic.com>
drivers/amlogic/atv_demod/atv_demod_driver.c
drivers/amlogic/atv_demod/atv_demod_ops.c
drivers/amlogic/atv_demod/atvdemod_func.c
drivers/amlogic/atv_demod/atvdemod_func.h

index f7284da..ceb4f29 100644 (file)
@@ -166,7 +166,7 @@ static ssize_t aml_atvdemod_store(struct class *class,
                pr_dbg("aml_atvdemod_ver %s.\n",
                                AMLATVDEMOD_VER);
        } else if (!strncmp(parm[0], "audio_autodet", 13)) {
-               aml_audiomode_autodet(&dev->v4l2_fe.fe);
+               aml_audiomode_autodet(&dev->v4l2_fe);
        } else if (!strncmp(parm[0], "audio_gain_set", 14)) {
                if (kstrtoul(buf + strlen("audio_gain_set") + 1, 16, &tmp) == 0)
                        val = tmp;
index e10b85a..12ead9f 100644 (file)
@@ -504,6 +504,7 @@ static void atvdemod_fe_try_analog_format(struct v4l2_frontend *v4l2_fe,
        int try_vfmt_cnt = 300;
        int varify_cnt = 0;
        v4l2_std_id std_bk = 0;
+       unsigned int broad_std = 0;
        unsigned int audio = 0;
 
        if (auto_search_std & 0x01) {
@@ -594,10 +595,8 @@ static void atvdemod_fe_try_analog_format(struct v4l2_frontend *v4l2_fe,
        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);
-               pr_info("autodet audmode 0x%x\n", audio);
-               audio = atvdemod_fmt_2_v4l2_std(audio);
-               pr_info("v4l2_std audmode 0x%x\n", audio);
+               broad_std = aml_audiomode_autodet(v4l2_fe);
+               audio = atvdemod_fmt_2_v4l2_std(broad_std);
 #if 0 /* I don't know what's going on here */
                if (audio == V4L2_STD_PAL_M)
                        audio = V4L2_STD_NTSC_M;
@@ -606,25 +605,20 @@ static void atvdemod_fe_try_analog_format(struct v4l2_frontend *v4l2_fe,
 #endif
 #else /* Now, force to NTSC_M, Ours demod only support M for NTSC.*/
                audio = V4L2_STD_NTSC_M;
-               *video_fmt |= V4L2_STD_NTSC_M;
 #endif
        } 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 = atvdemod_fmt_2_v4l2_std(audio);
-               pr_info("v4l2_std audmode 0x%x\n", audio);
-#else
+               broad_std = aml_audiomode_autodet(v4l2_fe);
+               audio = atvdemod_fmt_2_v4l2_std(broad_std);
+#else /* For force L */
                audio = V4L2_STD_SECAM_L;
 #endif
        } else {
-               /*V4L2_COLOR_STD_PAL*/
+               /* V4L2_COLOR_STD_PAL */
                amlatvdemod_set_std(AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK);
-               audio = aml_audiomode_autodet(fe);
-               pr_info("autodet audmode 0x%x\n", audio);
-               audio = atvdemod_fmt_2_v4l2_std(audio);
-               pr_info("v4l2_std audmode 0x%x\n", audio);
+               broad_std = aml_audiomode_autodet(v4l2_fe);
+               audio = atvdemod_fmt_2_v4l2_std(broad_std);
 #if 0 /* Why do this to me? We need support PAL_M.*/
                if (audio == V4L2_STD_PAL_M) {
                        audio = atvdemod_fmt_2_v4l2_std(broad_std_except_pal_m);
@@ -633,6 +627,9 @@ static void atvdemod_fe_try_analog_format(struct v4l2_frontend *v4l2_fe,
 #endif
        }
 
+       pr_info("autodet audio mode %d, [%s][0x%x]\n",
+                       broad_std, v4l2_std_to_str(audio), audio);
+
        *audio_fmt = audio;
 }
 
index e939d44..854f132 100644 (file)
@@ -1877,16 +1877,17 @@ void atv_dmd_set_std(void)
                pr_info("[%s]: atv restart error.\n", __func__);
 }
 
-int aml_audiomode_autodet(struct dvb_frontend *fe)
+int aml_audiomode_autodet(struct v4l2_frontend *v4l2_fe)
 {
-       struct atv_demod_priv *priv = fe->analog_demod_priv;
-       struct aml_atvdemod_parameters *param = &priv->atvdemod_param;
+       struct dvb_frontend *fe = &v4l2_fe->fe;
+       struct v4l2_analog_parameters *p = &v4l2_fe->params;
+       struct analog_parameters params;
 
        unsigned long carrier_power = 0;
        unsigned long carrier_power_max = 0;
        unsigned long carrier_power_average_max = 0;
        unsigned long carrier_power_average[4] = {0};
-       unsigned long reg_addr = 0x03, temp_data;
+       unsigned long temp_data = 0;
        int carrier_lock_count = 0;
        int lock = 0;
        int broad_std_final = 0;
@@ -1925,8 +1926,8 @@ 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:
-               if (!(param->param.std & V4L2_COLOR_STD_SECAM) ||
-                               !(param->param.std & V4L2_STD_SECAM_L)) {
+               if (!(p->std & V4L2_COLOR_STD_SECAM) ||
+                               !(p->std & V4L2_STD_SECAM_L)) {
                        secam_signal = true;
                        broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M;
                } else {
@@ -1971,6 +1972,7 @@ int aml_audiomode_autodet(struct dvb_frontend *fe)
                                        final_id = i;
                                }
                        }
+
                        switch (final_id) {
                        case ID_PAL_I:
                                broad_std_final =
@@ -1989,10 +1991,12 @@ int aml_audiomode_autodet(struct dvb_frontend *fe)
                                        AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK;
                                break;
                        }
+
                        carrier_power_average_max = carrier_power_max;
                        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) {
                                pr_err("%s,carrier too low error\n", __func__);
                                if (secam_signal) {
@@ -2002,6 +2006,7 @@ int aml_audiomode_autodet(struct dvb_frontend *fe)
                                                        __func__);
                                }
                        }
+
                        if (broad_std == AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M) {
                                /*the max except palm*/
                                carrier_power_average[final_id] = 0;
@@ -2015,93 +2020,96 @@ int aml_audiomode_autodet(struct dvb_frontend *fe)
                                                final_id = i;
                                        }
                                }
-                       switch (final_id) {
-                       case ID_PAL_I:
-                               broad_std_except_pal_m =
+
+                               switch (final_id) {
+                               case ID_PAL_I:
+                                       broad_std_except_pal_m =
                                        AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_I;
-                               break;
-                       case ID_PAL_BG:
-                               broad_std_except_pal_m =
+                                       break;
+                               case ID_PAL_BG:
+                                       broad_std_except_pal_m =
                                        AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_BG;
-                               break;
-                       case ID_PAL_DK:
-                               broad_std_except_pal_m =
+                                       break;
+                               case ID_PAL_DK:
+                                       broad_std_except_pal_m =
                                        AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK;
-                               break;
-                       }
+                                       break;
+                               }
                        }
-                       if (priv != NULL) {
-                               param->param.std = V4L2_COLOR_STD_PAL;
-                               switch (broad_std) {
-                               case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK:
-                                       param->param.std |= V4L2_STD_PAL_DK;
-                                       param->param.audmode = V4L2_STD_PAL_DK;
+
+                       p->std = V4L2_COLOR_STD_PAL;
+                       switch (broad_std) {
+                       case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK:
+                               p->std |= V4L2_STD_PAL_DK;
+                               p->audmode = V4L2_STD_PAL_DK;
                                break;
-                               case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_I:
-                                       param->param.std |= V4L2_STD_PAL_I;
-                                       param->param.audmode = V4L2_STD_PAL_I;
+                       case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_I:
+                               p->std |= V4L2_STD_PAL_I;
+                               p->audmode = V4L2_STD_PAL_I;
                                break;
-                               case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_BG:
-                                       param->param.std |= V4L2_STD_PAL_BG;
-                                       param->param.audmode = V4L2_STD_PAL_BG;
+                       case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_BG:
+                               p->std |= V4L2_STD_PAL_BG;
+                               p->audmode = V4L2_STD_PAL_BG;
                                break;
-                               case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M:
-                                       param->param.std |= V4L2_STD_PAL_M;
-                                       param->param.audmode = V4L2_STD_PAL_M;
+                       case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M:
+                               p->std |= V4L2_STD_PAL_M;
+                               p->audmode = V4L2_STD_PAL_M;
                                break;
-                               default:
-                                       param->param.std |= V4L2_STD_PAL_DK;
-                                       param->param.audmode = V4L2_STD_PAL_DK;
-                               }
-                               param->param.frequency += 1;
-                               fe->ops.analog_ops.set_params(fe,
-                                               &param->param);
+                       default:
+                               p->std |= V4L2_STD_PAL_DK;
+                               p->audmode = V4L2_STD_PAL_DK;
                        }
+
+                       p->frequency += 1;
+                       params.frequency = p->frequency;
+                       params.mode = p->afc_range;
+                       params.audmode = p->audmode;
+                       params.std = p->std;
+
+                       fe->ops.analog_ops.set_params(fe, &params);
+
                        return broad_std;
                }
+
                switch (broad_std) {
                case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK:
                        broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_I;
                        cur_std = ID_PAL_I;
-                       if (priv != NULL) {
-                               param->param.std = V4L2_COLOR_STD_PAL
-                                               | V4L2_STD_PAL_I;
-                               param->param.frequency += 1;
-                               param->param.audmode = V4L2_STD_PAL_I;
-                       }
+
+                       p->std = V4L2_COLOR_STD_PAL | V4L2_STD_PAL_I;
+                       p->frequency += 1;
+                       p->audmode = V4L2_STD_PAL_I;
+
                        delay_ms = delay_ms_default;
                        break;
                case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_I:
                        broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_BG;
                        cur_std = ID_PAL_BG;
-                       if (priv != NULL) {
-                               param->param.std = V4L2_COLOR_STD_PAL
-                                               | V4L2_STD_PAL_BG;
-                               param->param.frequency += 1;
-                               param->param.audmode = V4L2_STD_PAL_BG;
-                       }
+
+                       p->std = V4L2_COLOR_STD_PAL | V4L2_STD_PAL_BG;
+                       p->frequency += 1;
+                       p->audmode = V4L2_STD_PAL_BG;
+
                        delay_ms = delay_ms_default;
                        break;
                case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_BG:
                        broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M;
                        cur_std = ID_PAL_M;
-                       if (priv != NULL) {
-                               param->param.std = V4L2_COLOR_STD_PAL
-                                               | V4L2_STD_PAL_M;
-                               param->param.frequency += 1;
-                               param->param.audmode = V4L2_STD_PAL_M;
-                       }
+
+                       p->std = V4L2_COLOR_STD_PAL | V4L2_STD_PAL_M;
+                       p->frequency += 1;
+                       p->audmode = V4L2_STD_PAL_M;
+
                        delay_ms = delay_ms_default;
                        break;
                case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M:
                        broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK;
                        cur_std = ID_PAL_DK;
-                       if (priv != NULL) {
-                               param->param.std = V4L2_COLOR_STD_PAL
-                                               | V4L2_STD_PAL_DK;
-                               param->param.frequency += 1;
-                               param->param.audmode = V4L2_STD_PAL_DK;
-                       }
+
+                       p->std = V4L2_COLOR_STD_PAL | V4L2_STD_PAL_DK;
+                       p->frequency += 1;
+                       p->audmode = V4L2_STD_PAL_DK;
+
                        delay_ms = delay_ms_default;
                        break;
 
@@ -2109,16 +2117,19 @@ int aml_audiomode_autodet(struct dvb_frontend *fe)
                        pr_err("unsupport broadcast_standard!!!\n");
                        break;
                }
-               if (priv != NULL)
-                       fe->ops.analog_ops.set_params(fe, &param->param);
-               /* atvdemod_init(); //set_frontend has already been called it */
+
+               params.frequency = p->frequency;
+               params.mode = p->afc_range;
+               params.audmode = p->audmode;
+               params.std = p->std;
+               fe->ops.analog_ops.set_params(fe, &params);
 
                /* enable audio detect function */
                temp_data = atv_dmd_rd_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x02);
                temp_data = temp_data | 0x80;/* 0x40 */
                atv_dmd_wr_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x02, temp_data);
 
-               usleep_range(delay_ms*1000, delay_ms*1000+100);
+               usleep_range(delay_ms * 1000, delay_ms * 1000 + 100);
 
                carrier_lock_count = 0;
                i = 4;
@@ -2137,8 +2148,7 @@ int aml_audiomode_autodet(struct dvb_frontend *fe)
                /* ----------------read carrier_power--------------------- */
                for (i = 0; i < 100; i++) {
                        carrier_power =
-                               atv_dmd_rd_reg(APB_BLOCK_ADDR_SIF_STG_2,
-                                       reg_addr);
+                               atv_dmd_rd_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x03);
                        carrier_power_max += carrier_power;
                }
                carrier_power = carrier_power_max/i;
index a2e3ac2..530982c 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef __ATV_DEMOD_FUNC_H__
 #define __ATV_DEMOD_FUNC_H__
 
-struct dvb_frontend;
+struct v4l2_frontend;
 
 #define HHI_ATV_DMD_SYS_CLK_CNTL               0x10f3
 
@@ -198,7 +198,7 @@ extern void amlatvdemod_set_std(int val);
 extern void aml_fix_PWM_adjust(int enable);
 extern void aml_audio_valume_gain_set(unsigned int audio_gain);
 extern unsigned int aml_audio_valume_gain_get(void);
-extern int aml_audiomode_autodet(struct dvb_frontend *fe);
+extern int aml_audiomode_autodet(struct v4l2_frontend *v4l2_fe);
 extern void retrieve_frequency_offset(int *freq_offset);
 extern void retrieve_field_lock(int *lock);
 extern void set_atvdemod_scan_mode(int val);