atv_demod: atv demod code optimization for audio [1/1]

PD#TV-1448

Problem:
1.atv demod code optimization for audio
2.amlogic-4.9-dev

Solution:
atv demod code optimization for audio

Verify:
verified by einstein

Change-Id: Ic1c6a26ef97fbaf288ae37f2761c0df83ec7cf1e
Signed-off-by: nengwen.chen <nengwen.chen@amlogic.com>
This commit is contained in:
nengwen.chen
2018-12-07 21:41:43 +08:00
committed by Luke Go
parent 9ba7c8f814
commit a8fcbb728d
8 changed files with 95 additions and 36 deletions

View File

@@ -134,7 +134,7 @@ int atvaudiodem_reg_write(unsigned int reg, unsigned int val)
return 0;
}
int atvaudio_reg_read(unsigned int *val)
int atvaudio_ctrl_read(unsigned int *val)
{
/* only 0xffd0d340 read */
/* bit0: I2s select in_src, 0 = atv_demod, 1 = adec */
@@ -146,7 +146,7 @@ int atvaudio_reg_read(unsigned int *val)
return 0;
}
int atvaudio_reg_write(unsigned int val)
int atvaudio_ctrl_write(unsigned int val)
{
/* only 0xffd0d340 write */
/* bit0: I2s select in_src, 0 = atv_demod, 1 = adec */

View File

@@ -25,8 +25,8 @@ extern int amlatvdemod_reg_read(unsigned int reg, unsigned int *val);
extern int amlatvdemod_reg_write(unsigned int reg, unsigned int val);
extern int atvaudiodem_reg_read(unsigned int reg, unsigned int *val);
extern int atvaudiodem_reg_write(unsigned int reg, unsigned int val);
extern int atvaudio_reg_read(unsigned int *val);
extern int atvaudio_reg_write(unsigned int val);
extern int atvaudio_ctrl_read(unsigned int *val);
extern int atvaudio_ctrl_write(unsigned int val);
extern int amlatvdemod_hiu_reg_read(unsigned int reg, unsigned int *val);
extern int amlatvdemod_hiu_reg_write(unsigned int reg, unsigned int val);
extern int amlatvdemod_periphs_reg_read(unsigned int reg, unsigned int *val);

View File

@@ -158,7 +158,8 @@ void atv_demod_afc_do_work(struct work_struct *work)
return;
}
if (!afc->lock || (afc->lock && !field_lock)) {
/* add "(lock && !field_lock)", horizontal synchronization test NG */
if (!afc->lock/* || (afc->lock && !field_lock)*/) {
afc->status = AFC_LOCK_STATUS_POST_UNLOCK;
afc->pre_lock_cnt = 0;
param->frequency -= afc->offset * 1000;

View File

@@ -45,7 +45,7 @@
#include "atvauddemod_func.h"
#define AMLATVDEMOD_VER "V2.04"
#define AMLATVDEMOD_VER "V2.05"
struct aml_atvdemod_device *amlatvdemod_devp;

View File

@@ -43,12 +43,18 @@ bool atvdemod_timer_en = true;
static void atv_demod_monitor_do_work(struct work_struct *work)
{
int vpll_lock = 0, line_lock = 0;
struct atv_demod_monitor *monitor =
container_of(work, struct atv_demod_monitor, work);
if (!monitor->state)
return;
retrieve_vpll_carrier_lock(&vpll_lock);
retrieve_vpll_carrier_line_lock(&line_lock);
if ((vpll_lock != 0) || (line_lock != 0))
return;
if (atvdemod_mixer_tune_en)
atvdemod_mixer_tune();
@@ -61,10 +67,7 @@ static void atv_demod_monitor_do_work(struct work_struct *work)
if (audio_thd_en)
audio_thd_det();
if (atvaudio_det_outputmode_en &&
(is_meson_txlx_cpu()
|| is_meson_txhd_cpu()
|| is_meson_tl1_cpu()))
if (atvaudio_det_outputmode_en)
atvauddemod_set_outputmode();
if (atvdemod_det_nonstd_en)

View File

@@ -49,6 +49,13 @@ unsigned int audio_thd_threshold2 = 0xf00;
unsigned int audio_a2_auto = 1;
unsigned int audio_a2_power_threshold = 0x1800;
static int last_nicam_lock = -1;
static int last_nicam_mono_flag = -1;
static int last_stereo_flag = -1;
static int last_dual_flag = -1;
static int last_sap_flag = -1;
static int last_mode = -1;
#undef pr_info
#define pr_info(args...)\
do {\
@@ -885,7 +892,7 @@ void set_btsc_outputmode(uint32_t outmode)
uint32_t reg_value = 0;
uint32_t tmp_value = 0, tmp_value1 = 0;
int stereo_flag = 0, sap_flag = 0;
static int last_stereo_flag = -1, last_sap_flag = -1, last_mode = -1;
/*static int last_stereo_flag = -1,last_sap_flag = -1,last_mode = -1;*/
update_btsc_mode(1, &stereo_flag, &sap_flag);
@@ -996,7 +1003,7 @@ void set_a2_eiaj_outputmode(uint32_t outmode)
uint32_t reg_value = 0;
uint32_t tmp_value = 0;
int stereo_flag = 0, dual_flag = 0;
static int last_stereo_flag = -1, last_dual_flag = -1, last_mode = -1;
/*static int last_stereo_flag = -1,last_dual_flag = -1, last_mode=-1;*/
update_a2_eiaj_mode(audio_a2_auto, &stereo_flag, &dual_flag);
@@ -1089,8 +1096,8 @@ 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_nicam_mono_flag = -1;
static int last_stereo_flag = -1, last_dual_flag = -1, last_mode = -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,
&nicam_stereo_flag, &nicam_dual_flag);
@@ -1106,11 +1113,6 @@ void set_nicam_outputmode(uint32_t outmode)
*/
reg_value = adec_rd_reg(ADDR_ADEC_CTRL);
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);
@@ -1351,14 +1353,24 @@ void audio_thd_det(void)
}
}
void set_outputmode_status_init(void)
{
last_nicam_lock = -1;
last_nicam_mono_flag = -1;
last_stereo_flag = -1;
last_dual_flag = -1;
last_sap_flag = -1;
last_mode = -1;
}
void set_output_left_right_exchange(unsigned int ch)
{
unsigned int read = 0;
atvaudio_reg_read(&read);
atvaudio_ctrl_read(&read);
if ((read & (1 << 2)) != ((ch & 0x01) << 2))
atvaudio_reg_write((read & ~(1 << 2)) | ((ch & 0x01) << 2));
atvaudio_ctrl_write((read & ~(1 << 2)) | ((ch & 0x01) << 2));
}
#endif /* __ATVAUDDEMOD_FUN_H */

View File

@@ -39,6 +39,7 @@ void update_nicam_mode(int *nicam_flag, int *nicam_mono_flag,
int *nicam_stereo_flag, int *nicam_dual_flag);
void update_btsc_mode(int auto_en, int *stereo_flag, int *sap_flag);
void update_a2_eiaj_mode(int auto_en, int *stereo_flag, int *dual_flag);
void set_outputmode_status_init(void);
void set_output_left_right_exchange(unsigned int ch);

View File

@@ -40,6 +40,7 @@ unsigned int broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC;
unsigned int aud_std = AUDIO_STANDARD_NICAM_DK;
unsigned int aud_mode = AUDIO_OUTMODE_STEREO;
bool aud_auto = true;
bool aud_reinit;
unsigned long over_threshold = 0xffff;
unsigned long input_amplitude = 0xffff;
@@ -185,6 +186,8 @@ void power_on_receiver(void)
void atv_dmd_misc(void)
{
unsigned int reg = 0;
if (broad_std == AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_L) {
pr_info("broad_std is SECAM_L, no need config misc\n");
return;
@@ -271,7 +274,8 @@ void atv_dmd_misc(void)
0x18, 0x7ffff);
atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
0x1c, 0x0f000);
atvaudio_reg_write(0x0);
atvaudio_ctrl_read(&reg);
atvaudio_ctrl_write(reg & (~0x3));
audio_atv_ov_flag = 1;
} else {
atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
@@ -280,7 +284,8 @@ void atv_dmd_misc(void)
0x18, 0xc000);
atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
0x1c, 0x1f000);
atvaudio_reg_write(0x7);
atvaudio_ctrl_read(&reg);
atvaudio_ctrl_write(reg | 0x3);
audio_atv_ov_flag = 0;
}
}
@@ -1651,6 +1656,7 @@ int amlfmt_aud_standard(int broad_std)
int std = 0;
int nicam_lock = 0;
uint32_t reg_value = 0;
int vpll_lock = 0, line_lock = 0;
switch (broad_std) {
case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M:
@@ -1660,6 +1666,9 @@ int amlfmt_aud_standard(int broad_std)
adec_soft_reset();
msleep(audio_a2_delay);
retrieve_vpll_carrier_lock(&vpll_lock);
retrieve_vpll_carrier_line_lock(&line_lock);
/* maybe need wait */
reg_value = adec_rd_reg(CARRIER_MAG_REPORT);
pr_info("\n%s 0x%x\n", __func__, (reg_value>>16)&0xffff);
@@ -1690,10 +1699,10 @@ int amlfmt_aud_standard(int broad_std)
adec_soft_reset();
msleep(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);
retrieve_vpll_carrier_lock(&vpll_lock);
retrieve_vpll_carrier_line_lock(&line_lock);
reg_value = adec_rd_reg(NICAM_LEVEL_REPORT);
nicam_lock = (reg_value>>28)&1;
pr_info("\n%s 0x%x\n", __func__, reg_value);
@@ -1719,10 +1728,10 @@ 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);
retrieve_vpll_carrier_lock(&vpll_lock);
retrieve_vpll_carrier_line_lock(&line_lock);
reg_value = adec_rd_reg(NICAM_LEVEL_REPORT);
nicam_lock = (reg_value>>28)&1;
pr_info("\n%s 0x%x\n", __func__, reg_value);
@@ -1753,7 +1762,17 @@ int amlfmt_aud_standard(int broad_std)
adec_soft_reset();
break;
}
pr_err("%s detect aud std:%d\n", __func__, std);
if ((vpll_lock == 0) && (line_lock == 0)) {
aud_reinit = false;
} else {
aud_reinit = true;
pr_err("pll lock: 0x%x, line lock: 0x%x.\n",
vpll_lock, line_lock);
}
pr_err("%s detect aud std:%d, aud_reinit:%d.\n", __func__,
std, aud_reinit);
return std;
}
@@ -1769,6 +1788,7 @@ int atvauddemod_init(void)
configure_adec(aud_std);
adec_soft_reset();
}
set_outputmode_status_init();
set_outputmode(aud_std, aud_mode);
} else {
/* for non support adec */
@@ -1781,7 +1801,13 @@ int atvauddemod_init(void)
void atvauddemod_set_outputmode(void)
{
set_outputmode(aud_std, aud_mode);
if (is_meson_txlx_cpu() || is_meson_txhd_cpu() || is_meson_tl1_cpu()) {
if (aud_reinit) {
/* before maybe need check afc status */
atvauddemod_init();
} else
set_outputmode(aud_std, aud_mode);
}
}
int atvdemod_init(void)
@@ -1954,6 +1980,7 @@ int aml_audiomode_autodet(struct v4l2_frontend *v4l2_fe)
int cur_std = ID_PAL_DK;
bool secam_signal = false;
bool ntsc_signal = false;
bool pal_signal = false;
bool has_audio = false;
#if 0
temp_data = atv_dmd_rd_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x02);
@@ -1967,6 +1994,7 @@ int aml_audiomode_autodet(struct v4l2_frontend *v4l2_fe)
case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_BG:
case AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M:
broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M;
pal_signal = true;
break;
case AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_DK:
case AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_I:
@@ -2069,7 +2097,8 @@ int aml_audiomode_autodet(struct v4l2_frontend *v4l2_fe)
}
}
if (broad_std == AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M) {
if (broad_std == AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M
&& pal_signal) {
/*the max except palm*/
carrier_power_average[final_id] = 0;
final_id = 0;
@@ -2097,6 +2126,12 @@ int aml_audiomode_autodet(struct v4l2_frontend *v4l2_fe)
AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK;
break;
}
/* pal signal and pal-m power max,
* so set to second max std.
*/
broad_std = broad_std_except_pal_m;
pr_err("%s:pal signal and pal-m power max, set broad_std:%d\n",
__func__, broad_std);
}
p->std = V4L2_COLOR_STD_PAL;
@@ -2284,6 +2319,7 @@ void aml_audio_overmodulation(int enable)
{
unsigned long tmp_v = 0;
unsigned long tmp_v1 = 0;
unsigned int reg = 0;
u32 Broadcast_Standard = broad_std;
if (enable && Broadcast_Standard ==
@@ -2301,8 +2337,11 @@ void aml_audio_overmodulation(int enable)
0x18, 0x7ffff);
atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
0x1c, 0x0f000);
atvaudio_reg_write(0x0);
atvaudio_ctrl_read(&reg);
atvaudio_ctrl_write(reg & (~0x3));
audio_atv_ov_flag = 1;
pr_info("tmp_v[0x%lx] > 0x10 && audio_atv_ov_flag == 0.\n",
tmp_v);
} else if (tmp_v <= 0x10 && audio_atv_ov_flag == 1) {
tmp_v1 = atv_dmd_rd_long(APB_BLOCK_ADDR_SIF_STG_2, 0);
tmp_v1 = (tmp_v1&0xffffff)|(0<<24);
@@ -2313,8 +2352,11 @@ void aml_audio_overmodulation(int enable)
0x18, 0xc000);
atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
0x1c, 0x1f000);
atvaudio_reg_write(0x7);
atvaudio_ctrl_read(&reg);
atvaudio_ctrl_write(reg | 0x3);
audio_atv_ov_flag = 0;
pr_info("tmp_v[0x%lx] <= 0x10 && audio_atv_ov_flag == 1.\n",
tmp_v);
}
}
}