From ad2d48082180cfadbd9542e959c2a6bf39b3647d Mon Sep 17 00:00:00 2001 From: "nengwen.chen" Date: Thu, 12 Jul 2018 16:00:37 +0800 Subject: [PATCH] atv_demod: fix nicam. [1/1] PD#169523: fix nicam. Change-Id: Ied4b6867b7993164cd156f120099767b12ab131a Signed-off-by: nengwen.chen --- drivers/amlogic/atv_demod/atv_demod_debug.c | 1 + drivers/amlogic/atv_demod/atv_demod_driver.c | 2 +- drivers/amlogic/atv_demod/atv_demod_ops.c | 16 +++--- drivers/amlogic/atv_demod/atv_demod_ops.h | 2 + drivers/amlogic/atv_demod/atvauddemod_func.c | 26 ++++++++- drivers/amlogic/atv_demod/atvdemod_func.c | 55 +++++++++++++++----- 6 files changed, 80 insertions(+), 22 deletions(-) diff --git a/drivers/amlogic/atv_demod/atv_demod_debug.c b/drivers/amlogic/atv_demod/atv_demod_debug.c index 83cd9ddfedce..1eb4b80ec3f3 100644 --- a/drivers/amlogic/atv_demod/atv_demod_debug.c +++ b/drivers/amlogic/atv_demod/atv_demod_debug.c @@ -69,6 +69,7 @@ DEBUGFS_CREATE_NODE(ademod_debug_en, 0640, dentry, u32)\ DEBUGFS_CREATE_NODE(btsc_detect_delay, 0640, dentry, u32)\ DEBUGFS_CREATE_NODE(nicam_detect_delay, 0640, dentry, u32)\ + DEBUGFS_CREATE_NODE(a2_detect_delay, 0640, dentry, u32)\ DEBUGFS_CREATE_NODE(signal_audmode, 0640, dentry, u32)\ DEBUGFS_CREATE_NODE(audio_thd_threshold1, 0640, dentry, u32)\ DEBUGFS_CREATE_NODE(gde_curve, 0640, dentry, u32)\ diff --git a/drivers/amlogic/atv_demod/atv_demod_driver.c b/drivers/amlogic/atv_demod/atv_demod_driver.c index e81d8397d773..c5ae058451fd 100644 --- a/drivers/amlogic/atv_demod/atv_demod_driver.c +++ b/drivers/amlogic/atv_demod/atv_demod_driver.c @@ -39,7 +39,7 @@ #include "atvauddemod_func.h" -#define AMLATVDEMOD_VER "V2.00" +#define AMLATVDEMOD_VER "V2.01" struct aml_atvdemod_device *amlatvdemod_devp; diff --git a/drivers/amlogic/atv_demod/atv_demod_ops.c b/drivers/amlogic/atv_demod/atv_demod_ops.c index 32b9d282671e..bc7cf11cf9b4 100644 --- a/drivers/amlogic/atv_demod/atv_demod_ops.c +++ b/drivers/amlogic/atv_demod/atv_demod_ops.c @@ -431,12 +431,12 @@ int is_atvdemod_work(void) return ret; } -static int atv_demod_get_scan_mode(void) +int atv_demod_get_scan_mode(void) { return atvdemod_scan_mode; } -static void atv_demod_set_scan_mode(int val) +void atv_demod_set_scan_mode(int val) { atvdemod_scan_mode = val; } @@ -465,14 +465,14 @@ int atv_demod_enter_mode(void) amlatvdemod_devp->pin_name); adc_set_pll_cntl(1, 0x1, NULL); - /* vdac_enable(1, 1); */ + vdac_enable(1, 1); usleep_range(2000, 2100); atvdemod_clk_init(); - err_code = atvdemod_init(); + /* err_code = atvdemod_init(); */ if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) { aud_demod_clk_gate(1); - atvauddemod_init(); + /* atvauddemod_init(); */ } if (err_code) { pr_dbg("[amlatvdemod..]%s init atvdemod error.\n", __func__); @@ -506,7 +506,7 @@ int atv_demod_leave_mode(void) amlatvdemod_devp->pin = NULL; } - /* vdac_enable(0, 1); */ + vdac_enable(0, 1); adc_set_pll_cntl(0, 0x1, NULL); if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) aud_demod_clk_gate(0); @@ -1111,6 +1111,10 @@ static int atvdemod_fe_set_property(struct v4l2_frontend *v4l2_fe, case V4L2_SOUND_SYS: aud_mode = tvp->data & 0xFF; priv->sound_sys.output_mode = tvp->data & 0xFF; + if (atv_demod_get_state() == ATVDEMOD_STATE_WORK) { + if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) + atvauddemod_set_outputmode(); + } break; case V4L2_SLOW_SEARCH_MODE: diff --git a/drivers/amlogic/atv_demod/atv_demod_ops.h b/drivers/amlogic/atv_demod/atv_demod_ops.h index 216fe1a389bb..dbffc1c9df77 100644 --- a/drivers/amlogic/atv_demod/atv_demod_ops.h +++ b/drivers/amlogic/atv_demod/atv_demod_ops.h @@ -48,6 +48,8 @@ struct atv_demod_priv { struct work_struct demod_wq; }; +extern int atv_demod_get_scan_mode(void); +extern void atv_demod_set_scan_mode(int val); extern int atv_demod_enter_mode(void); struct dvb_frontend *aml_atvdemod_attach(struct dvb_frontend *fe, diff --git a/drivers/amlogic/atv_demod/atvauddemod_func.c b/drivers/amlogic/atv_demod/atvauddemod_func.c index 8a5d250e806a..520c452bd374 100644 --- a/drivers/amlogic/atv_demod/atvauddemod_func.c +++ b/drivers/amlogic/atv_demod/atvauddemod_func.c @@ -22,6 +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; /* signal_audmode for btsc signal audio mode */ unsigned int signal_audmode; unsigned int audio_thd_threshold1 = 0x1000; @@ -649,6 +650,9 @@ void set_nicam_dk(void) { int aa; + adec_wr_reg(0x103, 0x1000000); + adec_wr_reg(0x115, 0x1503d); + adec_wr_reg(ADDR_ADEC_CTRL, AUDIO_STANDARD_NICAM_DK); set_filter(filter_100k, ADDR_DDC_FIR0_COEF, 65); @@ -671,6 +675,10 @@ void set_nicam_i(void) { int aa; + adec_wr_reg(0x103, 0x1000000); + adec_wr_reg(0x110, 0xcb9581); + adec_wr_reg(0x115, 0x1503d); + adec_wr_reg(ADDR_ADEC_CTRL, AUDIO_STANDARD_NICAM_I); set_filter(filter_100k, ADDR_DDC_FIR0_COEF, 65); @@ -691,6 +699,9 @@ void set_nicam_bg(void) { int aa; + adec_wr_reg(0x103, 0x1000000); + adec_wr_reg(0x115, 0x1503d); + adec_wr_reg(ADDR_ADEC_CTRL, AUDIO_STANDARD_NICAM_BG); set_filter(filter_100k, ADDR_DDC_FIR0_COEF, 65); @@ -794,6 +805,8 @@ 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); + if (auto_en) { reg_value = adec_rd_reg(CARRIER_MAG_REPORT); if (((reg_value >> 16) & 0xffff) < 0x400) { @@ -1022,6 +1035,9 @@ void set_a2_eiaj_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_dual_flag == dual_flag && last_mode == outmode) @@ -1113,8 +1129,14 @@ void set_nicam_outputmode(uint32_t outmode) */ reg_value = adec_rd_reg(ADDR_ADEC_CTRL); - pr_info("%s nicam_lock:%d, regval:0x%x\n", - __func__, nicam_lock, reg_value); + pr_info("# pll lock: 0x%lx.\n", + atv_dmd_rd_byte(APB_BLOCK_ADDR_CARR_RCVY, 0x43)&0x01); + pr_info("# line lock: 0x%lx.\n", + atv_dmd_rd_byte(APB_BLOCK_ADDR_VDAGC, 0x4f)&0x10); + + pr_info("%s nicam_lock:%d, regval:0x%x, signal_mode:%d, outmode:%d\n", + __func__, nicam_lock, reg_value, + signal_audmode, outmode); if (last_nicam_lock == nicam_lock && last_mono_flag == nicam_mono_flag diff --git a/drivers/amlogic/atv_demod/atvdemod_func.c b/drivers/amlogic/atv_demod/atvdemod_func.c index 1ceb80ba8727..7596ffe2bf62 100644 --- a/drivers/amlogic/atv_demod/atvdemod_func.c +++ b/drivers/amlogic/atv_demod/atvdemod_func.c @@ -947,7 +947,7 @@ void configure_receiver(int Broadcast_Standard, unsigned int Tuner_IF_Frequency, || (Broadcast_Standard == AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_BG)) { sif_co_mx = 0xa6; sif_fi_mx = 0x10; - sif_ic_bw = 0x2; + sif_ic_bw = 0x0; sif_bb_bw = 0x0; sif_deemp = 0x2; sif_cfg_demod = (sound_format == 0) ? 0x0:0x2; @@ -1764,13 +1764,20 @@ int amlfmt_aud_standard(int broad_std) /* maybe need wait */ reg_value = adec_rd_reg(CARRIER_MAG_REPORT); pr_info("\n%s 0x%x\n", __func__, (reg_value>>16)&0xffff); - if (((reg_value>>16)&0xffff) > audio_a2_threshold) + if (((reg_value>>16)&0xffff) > audio_a2_threshold) { std = AUDIO_STANDARD_A2_K; - else + aud_mode = AUDIO_OUTMODE_A2_STEREO; + } else { std = AUDIO_STANDARD_BTSC; + aud_mode = AUDIO_OUTMODE_STEREO; + configure_adec(std); + adec_soft_reset(); + } break; case AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_J: std = AUDIO_STANDARD_EIAJ; + configure_adec(std); + adec_soft_reset(); break; case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_BG: std = AUDIO_STANDARD_NICAM_BG; @@ -1778,13 +1785,22 @@ int amlfmt_aud_standard(int broad_std) adec_soft_reset(); mdelay(audio_nicam_delay); /* need wait */ + pr_info("pll lock: 0x%lx.\n", + atv_dmd_rd_byte(0x06, 0x43) & 0x01); + pr_info("line lock: 0x%lx.\n", + atv_dmd_rd_byte(0x0f, 0x4f) & 0x10); reg_value = adec_rd_reg(NICAM_LEVEL_REPORT); nicam_lock = (reg_value>>28)&1; pr_info("\n%s 0x%x\n", __func__, reg_value); - if (nicam_lock) + if (nicam_lock) { std = AUDIO_STANDARD_NICAM_BG; - else + aud_mode = AUDIO_OUTMODE_NICAM_STEREO; + } else { std = AUDIO_STANDARD_A2_BG; + aud_mode = AUDIO_OUTMODE_A2_STEREO; + configure_adec(std); + adec_soft_reset(); + } break; case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK: std = AUDIO_STANDARD_NICAM_DK; @@ -1792,19 +1808,32 @@ int amlfmt_aud_standard(int broad_std) adec_soft_reset(); mdelay(audio_nicam_delay); /* need wait */ + pr_info("pll lock: 0x%lx.\n", + atv_dmd_rd_byte(0x06, 0x43) & 0x01); + pr_info("line lock: 0x%lx.\n", + atv_dmd_rd_byte(0x0f, 0x4f) & 0x10); reg_value = adec_rd_reg(NICAM_LEVEL_REPORT); nicam_lock = (reg_value>>28)&1; pr_info("\n%s 0x%x\n", __func__, reg_value); - if (nicam_lock) + if (nicam_lock) { std = AUDIO_STANDARD_NICAM_DK; - else + aud_mode = AUDIO_OUTMODE_NICAM_STEREO; + } else { std = AUDIO_STANDARD_A2_DK2; + aud_mode = AUDIO_OUTMODE_A2_STEREO; + configure_adec(std); + adec_soft_reset(); + } break; case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_I: std = AUDIO_STANDARD_NICAM_I; + configure_adec(std); + adec_soft_reset(); break; case AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_L: std = AUDIO_STANDARD_NICAM_L; + configure_adec(std); + adec_soft_reset(); break; } pr_err("%s detect aud std:%d\n", __func__, std); @@ -1816,8 +1845,8 @@ int atvauddemod_init(void) if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) { if (aud_auto) aud_std = amlfmt_aud_standard(broad_std); - configure_adec(aud_std); - adec_soft_reset(); + /* configure_adec(aud_std); */ + /* adec_soft_reset(); */ set_outputmode(aud_std, aud_mode); } return 0; @@ -1831,7 +1860,7 @@ void atvauddemod_set_outputmode(void) int atvdemod_init(void) { /* unsigned long data32; */ - if (atvdemod_timer_en == 1) { + if (atvdemod_timer_en == 1 && !atv_demod_get_scan_mode()) { if (timer_init_flag == 1) { del_timer_sync(&atvdemod_timer); timer_init_flag = 0; @@ -1865,15 +1894,15 @@ int atvdemod_init(void) * } */ #if 1/* temp mark */ - if (atvdemod_timer_en == 1) { + if (atvdemod_timer_en == 1 && !atv_demod_get_scan_mode()) { if (audio_thd_en) audio_thd_init(); /*atvdemod timer handler*/ init_timer(&atvdemod_timer); /* atvdemod_timer.data = (ulong) devp; */ atvdemod_timer.function = atvdemod_timer_handler; - /* after 3s enable demod auto detect */ - atvdemod_timer.expires = jiffies + ATVDEMOD_INTERVAL*300; + /* after 1s enable demod auto detect */ + atvdemod_timer.expires = jiffies + ATVDEMOD_INTERVAL*100; add_timer(&atvdemod_timer); mix1_freq = atv_dmd_rd_byte(APB_BLOCK_ADDR_MIXER_1, 0x0); timer_init_flag = 1;