atv_demod: improve the nicam and a2 [1/6]
authornengwen.chen <nengwen.chen@amlogic.com>
Thu, 26 Jul 2018 08:10:38 +0000 (16:10 +0800)
committerYixun Lan <yixun.lan@amlogic.com>
Mon, 30 Jul 2018 04:16:23 +0000 (21:16 -0700)
PD#169518: improve the nicam and a2

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

index 19c5b2555af00130ed54150da318915e1bb10cf1..6d2372bff9fab51c1526e173395a95aa13878a38 100644 (file)
@@ -50,6 +50,7 @@ struct aml_atvdemod_device {
        unsigned int if_inv;
        u64 std;
        unsigned int audmode;
+       unsigned int soundsys;
        int fre_offset;
 
        struct pinctrl *agc_pin;
index 4eb44e5f507a3bdfd5a2713ba2839d01f589c9e4..86cf695951d29c419218b42c55efef5e810f48f4 100644 (file)
@@ -493,11 +493,12 @@ int atv_demod_enter_mode(struct dvb_frontend *fe)
                return err_code;
        }
 
-       aml_afc_timer_enable(fe);
-       aml_demod_timer_enable(fe);
+       /* aml_afc_timer_enable(fe); */
+       /* aml_demod_timer_enable(fe); */
 
        amlatvdemod_devp->std = 0;
        amlatvdemod_devp->audmode = 0;
+       amlatvdemod_devp->soundsys = 0xFF;
 
        atv_demod_set_state(ATVDEMOD_STATE_WORK);
 
@@ -527,6 +528,7 @@ int atv_demod_leave_mode(struct dvb_frontend *fe)
 
        amlatvdemod_devp->std = 0;
        amlatvdemod_devp->audmode = 0;
+       amlatvdemod_devp->soundsys = 0xFF;
        atv_demod_set_state(ATVDEMOD_STATE_IDEL);
 
        pr_info("%s: OK.\n", __func__);
@@ -1113,12 +1115,17 @@ static int atvdemod_fe_set_property(struct v4l2_frontend *v4l2_fe,
 
        switch (tvp->cmd) {
        case V4L2_SOUND_SYS:
-               aud_mode = tvp->data & 0xFF;
+               /* aud_mode = tvp->data & 0xFF; */
+               amlatvdemod_devp->soundsys = tvp->data & 0xFF;
+               if (amlatvdemod_devp->soundsys != 0xFF)
+                       aud_mode = amlatvdemod_devp->soundsys;
                priv->sound_sys.output_mode = tvp->data & 0xFF;
+#if 0
                if (atv_demod_get_state() == ATVDEMOD_STATE_WORK) {
                        if (is_meson_txlx_cpu() || is_meson_txhd_cpu())
                                atvauddemod_set_outputmode();
                }
+#endif
                break;
 
        case V4L2_SLOW_SEARCH_MODE:
index 716a6873a0918072b57cd07dadd076f8efca0548..7274ab71b32685bda24d555869168834d4ad1514 100644 (file)
@@ -332,9 +332,10 @@ static int v4l2_set_frontend(struct v4l2_frontend *v4l2_fe,
 {
        u32 freq_min = 0;
        u32 freq_max = 0;
-       struct analog_parameters p;
+       struct analog_parameters p = { 0 };
        struct v4l2_frontend_private *fepriv = v4l2_fe->frontend_priv;
        struct dvb_frontend *fe = &v4l2_fe->fe;
+       struct v4l2_property tvp = { 0 };
 
        pr_dbg("%s.\n", __func__);
 
@@ -376,6 +377,12 @@ static int v4l2_set_frontend(struct v4l2_frontend *v4l2_fe,
                p.mode = params->afc_range;
                p.std = params->std;
                p.audmode = params->audmode;
+
+               tvp.cmd = V4L2_SOUND_SYS;
+               tvp.data = params->soundsys;
+               if (v4l2_fe->ops.set_property)
+                       v4l2_fe->ops.set_property(v4l2_fe, &tvp);
+
                fe->ops.analog_ops.set_params(fe, &p);
        }
 
index 520c452bd374f151ab50514ff5e7bb74104d0c98..5840ab4675564d8e73b131e08ad26ab91fe8630d 100644 (file)
@@ -22,7 +22,7 @@ unsigned int ademod_debug_en;
 /* btsc_detect_delay for btsc detect delay */
 unsigned int btsc_detect_delay = 10;
 unsigned int nicam_detect_delay = 10;
-unsigned int a2_detect_delay = 10;
+unsigned int a2_detect_delay = 300;
 /* signal_audmode for btsc signal audio mode */
 unsigned int signal_audmode;
 unsigned int audio_thd_threshold1 = 0x1000;
@@ -805,7 +805,7 @@ void update_a2_eiaj_mode(int auto_en, int *stereo_flag, int *dual_flag)
        uint32_t reg_value;
        uint32_t stereo_power, dual_power;
 
-       mdelay(a2_detect_delay);
+       msleep(a2_detect_delay);
 
        if (auto_en) {
                reg_value = adec_rd_reg(CARRIER_MAG_REPORT);
@@ -927,6 +927,9 @@ void set_btsc_outputmode(uint32_t outmode)
         */
        reg_value = adec_rd_reg(ADDR_ADEC_CTRL);
 
+       pr_info("%s regval:0x%x, signal_audmode:%d, outmode:%d\n",
+                               __func__, reg_value, signal_audmode, outmode);
+
        if (last_stereo_flag == stereo_flag
                        && last_sap_flag == sap_flag
                        && last_mode == outmode)
@@ -1055,17 +1058,18 @@ void set_a2_eiaj_outputmode(uint32_t outmode)
                }
                break;
        case 1: /* Stereo */
-               if (outmode != AUDIO_OUTMODE_A2_MONO &&
-                       outmode != AUDIO_OUTMODE_A2_STEREO) {
+               if ((outmode != AUDIO_OUTMODE_A2_MONO &&
+                       outmode != AUDIO_OUTMODE_A2_STEREO)
+                       || (last_stereo_flag != stereo_flag)) {
                        outmode = AUDIO_OUTMODE_A2_STEREO;
                        aud_mode = AUDIO_OUTMODE_A2_STEREO;
                }
                break;
        case 2: /* Dual */
-               if (outmode != AUDIO_OUTMODE_A2_MONO &&
-                       outmode != AUDIO_OUTMODE_A2_DUAL_A &&
+               if ((outmode != AUDIO_OUTMODE_A2_DUAL_A &&
                        outmode != AUDIO_OUTMODE_A2_DUAL_B &&
-                       outmode != AUDIO_OUTMODE_A2_DUAL_AB) {
+                       outmode != AUDIO_OUTMODE_A2_DUAL_AB)
+                       || (last_dual_flag != dual_flag)) {
                        outmode = AUDIO_OUTMODE_A2_DUAL_A;
                        aud_mode = AUDIO_OUTMODE_A2_DUAL_A;
                }
@@ -1112,7 +1116,7 @@ void set_nicam_outputmode(uint32_t outmode)
        uint32_t tmp_value = 0;
        int nicam_mono_flag = 0, nicam_stereo_flag = 0, nicam_dual_flag = 0;
        int nicam_lock = 0;
-       static int last_nicam_lock = -1, last_mono_flag = -1;
+       static int last_nicam_lock = -1, last_nicam_mono_flag = -1;
        static int last_stereo_flag = -1, last_dual_flag = -1, last_mode = -1;
 
        update_nicam_mode(&nicam_lock, &nicam_mono_flag,
@@ -1139,7 +1143,7 @@ void set_nicam_outputmode(uint32_t outmode)
                        signal_audmode, outmode);
 
        if (last_nicam_lock == nicam_lock
-                       && last_mono_flag == nicam_mono_flag
+                       && last_nicam_mono_flag == nicam_mono_flag
                        && last_stereo_flag == nicam_stereo_flag
                        && last_dual_flag == nicam_dual_flag
                        && last_mode == outmode)
@@ -1157,24 +1161,27 @@ void set_nicam_outputmode(uint32_t outmode)
                }
                break;
        case 1: /* Stereo */
-               if (outmode != AUDIO_OUTMODE_NICAM_MONO &&
-                       outmode != AUDIO_OUTMODE_NICAM_STEREO) {
+               if ((outmode != AUDIO_OUTMODE_NICAM_MONO &&
+                       outmode != AUDIO_OUTMODE_NICAM_STEREO)
+                       || (last_stereo_flag != nicam_stereo_flag)) {
                        outmode = AUDIO_OUTMODE_NICAM_STEREO;
                        aud_mode = AUDIO_OUTMODE_NICAM_STEREO;
                }
                break;
        case 2: /* Dual */
-               if (outmode != AUDIO_OUTMODE_NICAM_MONO &&
+               if ((outmode != AUDIO_OUTMODE_NICAM_MONO &&
                        outmode != AUDIO_OUTMODE_NICAM_DUAL_A &&
                        outmode != AUDIO_OUTMODE_NICAM_DUAL_B &&
-                       outmode != AUDIO_OUTMODE_NICAM_DUAL_AB) {
+                       outmode != AUDIO_OUTMODE_NICAM_DUAL_AB)
+                       || (last_dual_flag != nicam_dual_flag)) {
                        outmode = AUDIO_OUTMODE_NICAM_DUAL_A;
                        aud_mode = AUDIO_OUTMODE_NICAM_DUAL_A;
                }
                break;
        case 3: /* NICAM MONO */
-               if (outmode != AUDIO_OUTMODE_NICAM_MONO &&
-                       outmode != AUDIO_OUTMODE_NICAM_MONO1) {
+               if ((outmode != AUDIO_OUTMODE_NICAM_MONO &&
+                       outmode != AUDIO_OUTMODE_NICAM_MONO1)
+                       || (last_nicam_mono_flag != nicam_mono_flag)) {
                        outmode = AUDIO_OUTMODE_NICAM_MONO1;
                        aud_mode = AUDIO_OUTMODE_NICAM_MONO1;
                }
@@ -1240,7 +1247,7 @@ void set_nicam_outputmode(uint32_t outmode)
        pr_info("[%s] tmp_value: 0x%x.\n", __func__, reg_value);
 
        last_nicam_lock = nicam_lock;
-       last_mono_flag = nicam_mono_flag;
+       last_nicam_mono_flag = nicam_mono_flag;
        last_stereo_flag = nicam_stereo_flag;
        last_dual_flag = nicam_dual_flag;
        last_mode = outmode;
index 941417bf3cbbac80e32e1af33d2ec6a99f60506b..3a542f6a833933e5a45192c48ec5b1b311221a28 100644 (file)
@@ -1789,10 +1789,16 @@ int amlfmt_aud_standard(int broad_std)
                pr_info("\n%s 0x%x\n", __func__, (reg_value>>16)&0xffff);
                if (((reg_value>>16)&0xffff) > audio_a2_threshold) {
                        std = AUDIO_STANDARD_A2_K;
-                       aud_mode = AUDIO_OUTMODE_A2_STEREO;
+                       if (amlatvdemod_devp->soundsys == 0xFF)
+                               aud_mode = AUDIO_OUTMODE_A2_STEREO;
+                       else
+                               aud_mode = amlatvdemod_devp->soundsys;
                } else {
                        std = AUDIO_STANDARD_BTSC;
-                       aud_mode = AUDIO_OUTMODE_STEREO;
+                       if (amlatvdemod_devp->soundsys == 0xFF)
+                               aud_mode = AUDIO_OUTMODE_STEREO;
+                       else
+                               aud_mode = amlatvdemod_devp->soundsys;
                        configure_adec(std);
                        adec_soft_reset();
                }
@@ -1806,7 +1812,7 @@ int amlfmt_aud_standard(int broad_std)
                std = AUDIO_STANDARD_NICAM_BG;
                configure_adec(std);
                adec_soft_reset();
-               mdelay(audio_nicam_delay);
+               msleep(audio_nicam_delay);
                /* need wait */
                pr_info("pll lock: 0x%lx.\n",
                                atv_dmd_rd_byte(0x06, 0x43) & 0x01);
@@ -1817,10 +1823,16 @@ int amlfmt_aud_standard(int broad_std)
                pr_info("\n%s 0x%x\n", __func__, reg_value);
                if (nicam_lock) {
                        std = AUDIO_STANDARD_NICAM_BG;
-                       aud_mode = AUDIO_OUTMODE_NICAM_STEREO;
+                       if (amlatvdemod_devp->soundsys == 0xFF)
+                               aud_mode = AUDIO_OUTMODE_NICAM_STEREO;
+                       else
+                               aud_mode = amlatvdemod_devp->soundsys;
                } else {
                        std = AUDIO_STANDARD_A2_BG;
-                       aud_mode = AUDIO_OUTMODE_A2_STEREO;
+                       if (amlatvdemod_devp->soundsys == 0xFF)
+                               aud_mode = AUDIO_OUTMODE_A2_STEREO;
+                       else
+                               aud_mode = amlatvdemod_devp->soundsys;
                        configure_adec(std);
                        adec_soft_reset();
                }
@@ -1840,10 +1852,16 @@ int amlfmt_aud_standard(int broad_std)
                pr_info("\n%s 0x%x\n", __func__, reg_value);
                if (nicam_lock) {
                        std = AUDIO_STANDARD_NICAM_DK;
-                       aud_mode = AUDIO_OUTMODE_NICAM_STEREO;
+                       if (amlatvdemod_devp->soundsys == 0xFF)
+                               aud_mode = AUDIO_OUTMODE_NICAM_STEREO;
+                       else
+                               aud_mode = amlatvdemod_devp->soundsys;
                } else {
-                       std = AUDIO_STANDARD_A2_DK2;
-                       aud_mode = AUDIO_OUTMODE_A2_STEREO;
+                       std = AUDIO_STANDARD_A2_DK1;
+                       if (amlatvdemod_devp->soundsys == 0xFF)
+                               aud_mode = AUDIO_OUTMODE_A2_STEREO;
+                       else
+                               aud_mode = amlatvdemod_devp->soundsys;
                        configure_adec(std);
                        adec_soft_reset();
                }
@@ -1874,6 +1892,9 @@ int atvauddemod_init(void)
                /* configure_adec(aud_std); */
                /* adec_soft_reset(); */
                set_outputmode(aud_std, aud_mode);
+       } else {
+               /* for non support adec */
+               aud_std = 0;
        }
 
        return 0;