From b3690fb7a586f157736a4526f21a19a28663db04 Mon Sep 17 00:00:00 2001 From: "zhiwei.yuan" Date: Tue, 19 Mar 2019 11:07:42 +0800 Subject: [PATCH] dtv_demod: add AGC control for board t309 [1/1] PD#SWPL-5175 Problem: r842 agc control need be controlled by demod Solution: add agc control function Verify: verified by t962x2_x301 t962x2_t309 Change-Id: If712e22276b97c457e2e2ed1c79bdf3673813dff Signed-off-by: zhiwei.yuan --- drivers/amlogic/media/dtv_demod/amlfrontend.c | 103 +++++++++++++++++++-- drivers/amlogic/media/dtv_demod/dvbc_v3.c | 34 +++++-- .../amlogic/media/dtv_demod/include/demod_func.h | 5 +- drivers/amlogic/media/dtv_demod/tuner_func.c | 68 ++++++++++++++ 4 files changed, 189 insertions(+), 21 deletions(-) diff --git a/drivers/amlogic/media/dtv_demod/amlfrontend.c b/drivers/amlogic/media/dtv_demod/amlfrontend.c index 463ca08..3d43b53 100644 --- a/drivers/amlogic/media/dtv_demod/amlfrontend.c +++ b/drivers/amlogic/media/dtv_demod/amlfrontend.c @@ -935,6 +935,18 @@ static int gxtv_demod_dvbc_read_status_timer /*check tuner*/ if (!timer_tuner_not_enough()) { strenth = tuner_get_ch_power2(); + + /*agc control,fine tune strength*/ + if (is_ic_ver(IC_VER_TL1) && (dtvdd_devp->pin_name != NULL) && + (strncmp(fe->ops.tuner_ops.info.name, "r842", 4) + == 0)) { + strenth += 22; + + if (strenth <= -80) + strenth = dvbc_get_power_strength( + qam_read_reg(0x27) & 0x7ff, strenth); + } + if (strenth < -87) { *status = FE_TIMEDOUT; return 0; @@ -1040,6 +1052,7 @@ static int gxtv_demod_dvbc_read_ber(struct dvb_frontend *fe, u32 *ber) static int gxtv_demod_dvbc_read_signal_strength (struct dvb_frontend *fe, u16 *strength) { + int tuner_sr; #if 0 @@ -1047,7 +1060,22 @@ static int gxtv_demod_dvbc_read_signal_strength tn_strength = fe->ops.tuner_ops.get_strength(fe); *strength = 256 - tn_strength; #else - *strength = tuner_get_ch_power3(); + if (is_ic_ver(IC_VER_TL1) && + (dtvdd_devp->pin_name != NULL) && + (strncmp(fe->ops.tuner_ops.info.name, "r842", 4) == 0)) { + tuner_sr = tuner_get_ch_power2(); + tuner_sr += 22; + + if (tuner_sr <= -80) + tuner_sr = dvbc_get_power_strength( + qam_read_reg(0x27) & 0x7ff, tuner_sr); + + if (tuner_sr < -100) + *strength = 0; + else + *strength = tuner_sr + 100; + } else + *strength = tuner_get_ch_power3(); #endif return 0; @@ -1548,17 +1576,31 @@ static int gxtv_demod_atsc_read_ber(struct dvb_frontend *fe, u32 *ber) static int gxtv_demod_atsc_read_signal_strength (struct dvb_frontend *fe, u16 *strength) { + int strenth; + + strenth = tuner_get_ch_power(fe); /* struct aml_fe *afe = fe->demodulator_priv;*/ /*struct aml_fe_dev *dev = afe->dtv_demod; */ + if (is_ic_ver(IC_VER_TL1) && (dtvdd_devp->pin_name != NULL) && + (strncmp(fe->ops.tuner_ops.info.name, "r842", 4) == 0)) { + if ((fe->dtv_property_cache.modulation <= QAM_AUTO) && + (fe->dtv_property_cache.modulation != QPSK)) + strenth += 18; + else { + strenth += 15; + if (strenth <= -80) + strenth = atsc_get_power_strength( + atsc_read_reg_v4(0x44) & 0xfff, + strenth); + } + if (strenth < -100) + *strength = 0; + else + *strength = strenth + 100; + } else + *strength = tuner_get_ch_power3(); - *strength = tuner_get_ch_power3(); - #if 0 - if (*strength < 0) - *strength = 0; - else if (*strength > 100) - *strength = 100; - #endif if (*strength > 100) *strength = 100; @@ -1605,6 +1647,8 @@ static int gxtv_demod_atsc_set_frontend(struct dvb_frontend *fe) union ATSC_DEMOD_REG_0X6A_BITS Val_0x6a; union ATSC_CNTR_REG_0X20_BITS Val_0x20; int nco_rate; + /*[0]: specturm inverse(1),normal(0); [1]:if_frequency*/ + unsigned int tuner_freq[2] = {0}; memset(¶m_atsc, 0, sizeof(param_atsc)); memset(¶m_j83b, 0, sizeof(param_j83b)); @@ -1660,6 +1704,16 @@ static int gxtv_demod_atsc_set_frontend(struct dvb_frontend *fe) atsc_write_reg_v4(ATSC_DEMOD_REG_0X6A, Val_0x6a.bits); atsc_write_reg_v4(ATSC_EQ_REG_0XA5, 0x8c); + if (fe->ops.tuner_ops.get_if_frequency) + fe->ops.tuner_ops. + get_if_frequency(fe, tuner_freq); + + /*bit 2: invert specturm, for r842 tuner AGC control*/ + if (tuner_freq[0] == 1) + atsc_write_reg_v4(ATSC_DEMOD_REG_0X56, 0x4); + else + atsc_write_reg_v4(ATSC_DEMOD_REG_0X56, 0x0); + if (demod_status.adc_freq == Adc_Clk_24M) { atsc_write_reg_v4(ATSC_DEMOD_REG_0X54, 0x1aaaaa); @@ -1787,6 +1841,16 @@ void atsc_detect_first(struct dvb_frontend *fe, enum fe_status *status) msleep(dvb_tuner_delay); strenth = tuner_get_ch_power(fe); + + /*agc control,fine tune strength*/ + if (is_ic_ver(IC_VER_TL1) && (dtvdd_devp->pin_name != NULL) && + (strncmp(fe->ops.tuner_ops.info.name, "r842", 4) == 0)) { + strenth += 15; + if (strenth <= -80) + strenth = atsc_get_power_strength( + atsc_read_reg_v4(0x44) & 0xfff, strenth); + } + if (strenth < THRD_TUNER_STRENTH_ATSC) { *status = FE_TIMEDOUT; PR_ATSC("tuner:no signal!\n"); @@ -1850,6 +1914,12 @@ static int atsc_j83b_detect_first(struct dvb_frontend *fe, enum fe_status *s) msleep(dvb_tuner_delay); strenth = tuner_get_ch_power(fe); + + /*agc control,fine tune strength*/ + if (is_ic_ver(IC_VER_TL1) && (dtvdd_devp->pin_name != NULL) && + (strncmp(fe->ops.tuner_ops.info.name, "r842", 4) == 0)) + strenth += 18; + if (strenth < THRD_TUNER_STRENTH_J83) { *s = FE_TIMEDOUT; PR_ATSC("tuner:no signal!j83\n"); @@ -2379,8 +2449,9 @@ static int gxtv_demod_dtmb_read_status_old PR_ERR("%s:not support %d!\n", __func__, get_dtmb_ver()); return -1; } + s = amdemod_dtmb_stat_islock(); -/* s=1;*/ + if (s == 1) { ilock = 1; *status = @@ -2409,8 +2480,20 @@ static int gxtv_demod_dtmb_read_ber(struct dvb_frontend *fe, u32 *ber) static int gxtv_demod_dtmb_read_signal_strength (struct dvb_frontend *fe, u16 *strength) { + int tuner_sr; - *strength = tuner_get_ch_power3(); + if (is_ic_ver(IC_VER_TL1) && + (dtvdd_devp->pin_name != NULL) && + (strncmp(fe->ops.tuner_ops.info.name, "r842", 4) == 0)) { + tuner_sr = tuner_get_ch_power2(); + tuner_sr += 16; + + if (tuner_sr < -100) + *strength = 0; + else + *strength = tuner_sr + 100; + } else + *strength = tuner_get_ch_power3(); return 0; } diff --git a/drivers/amlogic/media/dtv_demod/dvbc_v3.c b/drivers/amlogic/media/dtv_demod/dvbc_v3.c index 56d1b53..d94d842 100644 --- a/drivers/amlogic/media/dtv_demod/dvbc_v3.c +++ b/drivers/amlogic/media/dtv_demod/dvbc_v3.c @@ -301,6 +301,19 @@ void dvbc_reg_initial(struct aml_demod_sta *demod_sta) qam_write_reg(0x7, qam_read_reg(0x7) & ~(1 << 0)); /* Sw disable demod */ qam_write_reg(0x7, qam_read_reg(0x7) | (1 << 0)); + + if (is_ic_ver(IC_VER_TL1)) + if (agc_mode == 1) { + qam_write_reg(0x25, + qam_read_reg(0x25) & ~(0x1 << 10)); + qam_write_reg(0x24, + qam_read_reg(0x24) | (0x1 << 17)); + #if 0 + qam_write_reg(0x3d, + qam_read_reg(0x3d) | 0xf); + #endif + } + /* Sw enable demod */ qam_write_reg(0x0, 0x0); /* QAM_STATUS */ @@ -395,16 +408,19 @@ void dvbc_reg_initial(struct aml_demod_sta *demod_sta) /* agc control */ /* dvbc_write_reg(QAM_BASE+0x094, 0x7f800d2c);// AGC_CTRL ALPS tuner */ /* dvbc_write_reg(QAM_BASE+0x094, 0x7f80292c); // Pilips Tuner */ - if ((agc_mode & 1) == 0) - /* freeze if agc */ - qam_write_reg(0x25, - qam_read_reg(0x25) | (0x1 << 10)); - if ((agc_mode & 2) == 0) { - /* IF control */ - /*freeze rf agc */ - qam_write_reg(0x25, - qam_read_reg(0x25) | (0x1 << 13)); + if (!is_ic_ver(IC_VER_TL1)) { + if ((agc_mode & 1) == 0) + /* freeze if agc */ + qam_write_reg(0x25, + qam_read_reg(0x25) | (0x1 << 10)); + if ((agc_mode & 2) == 0) { + /* IF control */ + /*freeze rf agc */ + qam_write_reg(0x25, + qam_read_reg(0x25) | (0x1 << 13)); + } } + /*Maxlinear Tuner */ /*dvbc_write_reg(QAM_BASE+0x094, 0x7f80292d); */ /*dvbc_write_reg(QAM_BASE + 0x098, 0x9fcc8190);*/ diff --git a/drivers/amlogic/media/dtv_demod/include/demod_func.h b/drivers/amlogic/media/dtv_demod/include/demod_func.h index 8a47d1e..e2c0606 100644 --- a/drivers/amlogic/media/dtv_demod/include/demod_func.h +++ b/drivers/amlogic/media/dtv_demod/include/demod_func.h @@ -454,8 +454,9 @@ u16 tuner_get_ch_power3(void); int dtmb_get_power_strength(int agc_gain); - - +extern int dvbc_get_power_strength(int agc_gain, int tuner_strength); +extern int j83b_get_power_strength(int agc_gain, int tuner_strength); +extern int atsc_get_power_strength(int agc_gain, int tuner_strength); /* dvbt */ int dvbt_set_ch(struct aml_demod_sta *demod_sta, diff --git a/drivers/amlogic/media/dtv_demod/tuner_func.c b/drivers/amlogic/media/dtv_demod/tuner_func.c index 8fd69f6..bf3ba7d 100644 --- a/drivers/amlogic/media/dtv_demod/tuner_func.c +++ b/drivers/amlogic/media/dtv_demod/tuner_func.c @@ -264,4 +264,72 @@ int dtmb_get_power_strength(int agc_gain) return strength; } +/*tuner has 3 stage gain control, only last is controlled by demod agc*/ +static int dvbc_R842[20] = { + /*-90,-89,-88, -87, -86 , -85 , -84 , -83 , -82 , -81dbm*/ + 1200, 1180, 1150, 1130, 1100, 1065, 1040, 1030, 1000, 970 +}; + +int dvbc_get_power_strength(int agc_gain, int tuner_strength) +{ + int strength; + int i; + + for (i = 0; i < sizeof(dvbc_R842)/sizeof(int); i++) + if (agc_gain >= dvbc_R842[i]) + break; + + if (agc_gain >= 970) + strength = -90+i*1; + else + strength = tuner_strength + 22; + + return strength; +} + +static int j83b_R842[10] = { + /*-90,-89,-88, -87, -86 , -85 , -84 , -83 , -82 , -81dbm*/ + 1140, 1110, 1080, 1060, 1030, 1000, 980, 1000, 970, 1000, + /*-80,-79,-78, -77, -76 , -75 , -74 , -73 , -72 , -71dbm*/ + /*970 , 980, 960, 970, 950, 960, 970, 980, 960, 970*/ +}; + +int j83b_get_power_strength(int agc_gain, int tuner_strength) +{ + int strength; + int i; + + for (i = 0; i < sizeof(j83b_R842)/sizeof(int); i++) + if (agc_gain >= j83b_R842[i]) + break; + + if (agc_gain >= 970) + strength = -90+i*1; + else + strength = tuner_strength + 18; + + return strength; +} + +static int atsc_R842[6] = { + /*-90,-89,-88, -87, -86 , -85 , -84 , -83 , -82 , -81dbm*/ + 2160, 2110, 2060, 2010, 1960, 1910/*, 1870, 1910, 1860, 1900*/ +}; + +int atsc_get_power_strength(int agc_gain, int tuner_strength) +{ + int strength; + int i; + + for (i = 0; i < sizeof(atsc_R842)/sizeof(int); i++) + if (agc_gain >= atsc_R842[i]) + break; + + if (agc_gain >= 1910) + strength = -90+i*1; + else + strength = tuner_strength; + + return strength; +} -- 2.7.4