dtv_demod: tl1,dvbc, new method for fast channel searching [1/1]
authorZhiwei Yuan <zhiwei.yuan@amlogic.com>
Fri, 18 Jan 2019 07:09:12 +0000 (15:09 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Thu, 24 Jan 2019 06:32:45 +0000 (22:32 -0800)
PD#TV-2154

Problem:
[Hisense-T962X2-P-customer-DTV]:DVBC QAM is set to auto to search channels

Solution:
add new searching method
note:
use "demod_dvbc_speedup_en" to mark the new method
it's disabled as default, can be enabled if needed
we can make it always enabled after all testing are passed
enable: echo fast_search on > /sys/kernel/debug/demod/dvbc_channel_fast

Verify:
verified by t962x2_x301

Change-Id: Icaaab9f27eb058a062d7048c6ca9fa2e3bff008e
Signed-off-by: Zhiwei Yuan <zhiwei.yuan@amlogic.com>
MAINTAINERS
drivers/amlogic/media/dtv_demod/Makefile
drivers/amlogic/media/dtv_demod/aml_demod.c
drivers/amlogic/media/dtv_demod/amlfrontend.c
drivers/amlogic/media/dtv_demod/demod_dbg.c [new file with mode: 0644]
drivers/amlogic/media/dtv_demod/dvbc_v3.c
drivers/amlogic/media/dtv_demod/include/amlfrontend.h
drivers/amlogic/media/dtv_demod/include/demod_dbg.h [new file with mode: 0644]
drivers/amlogic/media/dtv_demod/include/demod_func.h

index a02e95b..5117158 100644 (file)
@@ -14499,6 +14499,8 @@ F:      drivers/amlogic/media/dtv_demod/*
 AMLOGIC DTV DEMOD DRIVER
 M:      Zhiwei Yuan <zhiwei.yuan@amlogic.com>
 F:      drivers/amlogic/media/dtv_demod/include/addr_atsc*.h
+F:      drivers/amlogic/media/dtv_demod/include/demod_dbg.h
+F:      drivers/amlogic/media/dtv_demod/demod_dbg.c
 
 AMLOGIC DEFENDKEY DRIVER
 M:     Zhongfu Luo <zhongfu.luo@amlogic.com>
index 4d75e20..d88c5f6 100644 (file)
@@ -5,7 +5,7 @@ obj-$(CONFIG_AMLOGIC_DTV_DEMOD) += dtvdemod.o
 
 dtvdemod-objs := demod_func.o  dvbc_func.o i2c_func.o tuner_func.o atsc_func.o dvbc_v2.o dvbc_v3.o dtmb_func.o dvbt_v2.o#dvbt_func.o
 
-dtvdemod-objs += amlfrontend.o
+dtvdemod-objs += amlfrontend.o demod_dbg.o
 
 dtvdemod-objs  += aml_demod.o
 
index cd82367..181c4a3 100644 (file)
 /* #include <mach/am_regs.h> */
 #include <linux/device.h>
 #include <linux/cdev.h>
-#include <linux/debugfs.h>
 
 /* #include <asm/fiq.h> */
 #include <linux/uaccess.h>
 #include <linux/dvb/aml_demod.h>
 #include "demod_func.h"
+#include "demod_dbg.h"
 
 #include <linux/slab.h>
 #ifdef CONFIG_COMPAT
 #include <linux/compat.h>
 #endif
+
 /*#include "sdio/sdio_init.h"*/
 #define DRIVER_NAME "aml_demod"
 #define MODULE_NAME "aml_demod"
@@ -493,287 +494,6 @@ static const struct file_operations aml_demod_fops = {
 #endif
 };
 
-#if 0
-static int aml_demod_dbg_open(struct inode *inode, struct file *file)
-{
-       pr_dbg("Amlogic Demod debug Open\n");
-       return 0;
-}
-
-static int aml_demod_dbg_release(struct inode *inode, struct file *file)
-{
-       pr_dbg("Amlogic Demod debug Release\n");
-       return 0;
-}
-
-static unsigned int addr_for_read;
-static unsigned int register_val;
-static unsigned int symb_rate;
-static unsigned int ch_freq;
-static unsigned int modulation;
-static char *dbg_name[] = {
-       "demod top r/w",
-       "dvbc r/w",
-       "atsc r/w",
-       "dtmb r/w",
-       "front r/w",
-       "isdbt r/w",
-       "dvbc init",
-       "atsc init",
-       "dtmb init",
-};
-
-unsigned int get_symbol_rate(void)
-{// / 1000
-       return symb_rate;
-}
-
-unsigned int get_ch_freq(void)
-{// / 1000
-       return ch_freq;
-}
-
-unsigned int get_modu(void)
-{
-       return modulation;
-}
-
-/*
- *TVFE_VAFE_CTRL0      0x000d0710
- *TVFE_VAFE_CTRL1      0x00003000
- *TVFE_VAFE_CTRL2      0x1fe09e31
- *HHI_DADC_CNTL                0x0030303c
- *HHI_DADC_CNTL2               0x00003480
- *HHI_DADC_CNTL3               0x08700b83
- *HHI_VDAC_CNTL1               0x0000000
-
- *ADC_PLL_CNTL0                0X012004e0
- *ADC_PLL_CNTL0                0X312004e0
- *ADC_PLL_CNTL1                0X05400000
- *ADC_PLL_CNTL2                0xe1800000
- *ADC_PLL_CNTL3                0x48681c00
- *ADC_PLL_CNTL4                0x88770290
- *ADC_PLL_CNTL5                0x39272000
- *ADC_PLL_CNTL6                0x56540000
- *ADC_PLL_CNTL0                0X111104e0
- */
-static void aml_demod_adc_init(void)
-{
-       PR_INFO("%s\n", __func__);
-       demod_init_mutex();
-       demod_power_switch(PWR_ON);
-       //TVFE_VAFE_CTRL0
-       demod_set_tvfe_reg(0x000d0710, 0xff654ec0);
-       //TVFE_VAFE_CTRL1
-       demod_set_tvfe_reg(0x00003000, 0xff654ec4);
-       //TVFE_VAFE_CTRL2
-       demod_set_tvfe_reg(0x1fe09e31, 0xff654ec8);
-       //HHI_DADC_CNTL
-       dd_tvafe_hiu_reg_write(0x9c, 0x0030303c);
-       //HHI_DADC_CNTL2
-       dd_tvafe_hiu_reg_write(0xa0, 0x00003480);
-       //HHI_DADC_CNTL3
-       //dd_tvafe_hiu_reg_write(0xa8, 0x08700b83);
-       dd_tvafe_hiu_reg_write(0xa8, 0x08300b83);
-       //HHI_VDAC_CNTL1
-       dd_tvafe_hiu_reg_write(0x2f0, 0x0000000);
-       //ADC_PLL_CNTL0
-       dd_tvafe_hiu_reg_write(0x2c0, 0X012004e0);
-       dd_tvafe_hiu_reg_write(0x2c0, 0X312004e0);
-       //ADC_PLL_CNTL1
-       dd_tvafe_hiu_reg_write(0x2c4, 0X05400000);
-       //ADC_PLL_CNTL2
-       //dd_tvafe_hiu_reg_write(0x2c8, 0xe1800000);
-       dd_tvafe_hiu_reg_write(0x2c8, 0xE0800000);//shijie modify, crystal 24M
-       //dd_tvafe_hiu_reg_write(0x2c8, 0xe9800000);
-       //ADC_PLL_CNTL3
-       dd_tvafe_hiu_reg_write(0x2cc, 0x48681c00);
-       //ADC_PLL_CNTL4
-       dd_tvafe_hiu_reg_write(0x2d0, 0x88770290);
-       //ADC_PLL_CNTL5
-       dd_tvafe_hiu_reg_write(0x2d4, 0x39272000);
-       //ADC_PLL_CNTL6
-       dd_tvafe_hiu_reg_write(0x2d8, 0x56540000);
-       //ADC_PLL_CNTL0
-       dd_tvafe_hiu_reg_write(0x2c0, 0X111104e0);
-       //zou weihua
-       dd_tvafe_hiu_reg_write(0x3cc, 0x00800000);
-       //shijie
-       dd_tvafe_hiu_reg_write(0x1d0, 0x501);//0x705
-       //shixi, switch to demod mode, enable pclk
-       //demod_write_reg(DEMOD_TOP_REG0, 0x11);
-       dtvpll_init_flag(1);
-}
-
-static ssize_t aml_demod_dbg_show(struct file *file, char __user *userbuf,
-                                size_t count, loff_t *ppos)
-{
-       char buf[80];
-       ssize_t len = 0;
-
-       #if 1
-       len = snprintf(buf, sizeof(buf), "%s :0x%x = %i\n",
-               dbg_name[addr_for_read >> 28], addr_for_read & 0xff,
-               register_val);
-       #else
-       len = snprintf(buf, sizeof(buf), "%s\n", __func__);
-       #endif
-       //demod_read_reg(DEMOD_TOP_REGC);
-       //dtmb_read_reg(0);
-       //dd_tvafe_hiu_reg_write(0x9c, 0x0030303c);
-       PR_INFO("%s\n", __func__);
-       //PR_INFO("0xec0 = 0x%x\n", dd_tvafe_hiu_reg_read(0x9c));
-       //dvbt_read_reg(0x38);
-
-       return simple_read_from_buffer(userbuf, count, ppos, buf, len);
-}
-
-/*echo dbg_md [0xaddr] [val] > /sys/kernel/debug/demod/xxxx*/
-static ssize_t aml_demod_dbg_store(struct file *file,
-               const char __user *userbuf, size_t count, loff_t *ppos)
-{
-       char buf[80];
-       unsigned int reg, val, dbg_md;
-       int ret;
-
-       count = min_t(size_t, count, (sizeof(buf)-1));
-       if (copy_from_user(buf, userbuf, count))
-               return -EFAULT;
-
-       buf[count] = 0;
-
-       ret = sscanf(buf, "%d %x %i", &dbg_md, &reg, &val);
-       aml_demod_adc_init();
-
-       switch (ret) {
-       case 1://cmd
-               switch (dbg_md) {
-               case AML_DBG_DVBC_INIT:
-                       break;
-               case AML_DBG_ATSC_INIT:
-                       demod_set_sys_atsc_v4();
-                       break;
-               case AML_DBG_DTMB_INIT:
-                       break;
-               default:
-                       break;
-               }
-
-               PR_INFO("%s\n", dbg_name[dbg_md]);
-               break;
-       case 2://read register, set param
-               switch (dbg_md) {
-               case AML_DBG_DEMOD_TOP_RW:
-                       addr_for_read = (AML_DBG_DEMOD_TOP_RW << 28) | reg;
-                       register_val = demod_read_reg(reg);
-                       break;
-               case AML_DBG_DVBC_RW:
-                       addr_for_read = (AML_DBG_DVBC_RW << 28) | reg;
-                       register_val = dvbc_read_reg(reg);
-                       break;
-               case AML_DBG_ATSC_RW:
-                       addr_for_read = (AML_DBG_ATSC_RW << 28) | reg;
-                       register_val = atsc_read_reg_v4(reg);
-                       break;
-               case AML_DBG_DTMB_RW:
-                       addr_for_read = (AML_DBG_DTMB_RW << 28) | reg;
-                       register_val = dtmb_read_reg(reg);
-                       break;
-               case AML_DBG_FRONT_RW:
-                       addr_for_read = (AML_DBG_FRONT_RW << 28) | reg;
-                       register_val = front_read_reg_v4(reg);
-                       break;
-               case AML_DBG_ISDBT_RW:
-                       addr_for_read = (AML_DBG_ISDBT_RW << 28) | reg;
-                       register_val = isdbt_read_reg_v4(reg);
-                       break;
-               case AML_DBG_DEMOD_SYMB_RATE:
-                       symb_rate = reg;
-                       break;
-               case AML_DBG_DEMOD_CH_FREQ:
-                       ch_freq = reg;
-                       break;
-               case AML_DBG_DEMOD_MODUL:
-                       modulation = reg;
-                       break;
-               default:
-                       break;
-               }
-
-               PR_INFO("%s reg:0x%x\n", dbg_name[dbg_md], reg);
-               break;
-       case 3://write register
-               switch (dbg_md) {
-               case AML_DBG_DEMOD_TOP_RW:
-                       demod_write_reg(reg, val);
-                       break;
-               case AML_DBG_DVBC_RW:
-                       dvbc_write_reg(reg, val);
-                       break;
-               case AML_DBG_ATSC_RW:
-                       atsc_write_reg_v4(reg, val);
-                       break;
-               case AML_DBG_DTMB_RW:
-                       dtmb_write_reg(reg, val);
-                       break;
-               case AML_DBG_FRONT_RW:
-                       front_write_reg_v4(reg, val);
-                       break;
-               case AML_DBG_ISDBT_RW:
-                       isdbt_write_reg_v4(reg, val);
-                       break;
-               default:
-                       break;
-               }
-
-               PR_INFO("%s reg:0x%x,val=%d\n", dbg_name[dbg_md], reg, val);
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       return count;
-}
-
-static const struct file_operations aml_demod_dvbc_dbg_fops = {
-       .owner          = THIS_MODULE,
-       .open           = aml_demod_dbg_open,
-       .release        = aml_demod_dbg_release,
-       //.unlocked_ioctl = aml_demod_ioctl,
-       .read = aml_demod_dbg_show,
-       .write = aml_demod_dbg_store,
-};
-
-static void aml_demod_dbg_init(void)
-{
-       struct dentry *root_entry = dtvdd_devp->demod_root;
-       struct dentry *entry;
-
-       PR_INFO("%s\n", __func__);
-
-       root_entry = debugfs_create_dir("frontend", NULL);
-       if (!root_entry) {
-               PR_INFO("Can't create debugfs dir frontend.\n");
-               return;
-       }
-
-       entry = debugfs_create_file("demod", S_IFREG | 0644, root_entry, NULL,
-                                      &aml_demod_dvbc_dbg_fops);
-       if (!entry) {
-               PR_INFO("Can't create debugfs file demod.\n");
-               return;
-       }
-}
-
-static void aml_demod_dbg_exit(void)
-{
-       struct dentry *root_entry = dtvdd_devp->demod_root;
-
-       if (dtvdd_devp && root_entry)
-               debugfs_remove_recursive(root_entry);
-}
-#endif
-
 static int aml_demod_ui_open(struct inode *inode, struct file *file)
 {
        pr_dbg("Amlogic aml_demod_ui_open Open\n");
@@ -987,7 +707,7 @@ static int __init aml_demod_init(void)
        sdio_init();
 #endif
        aml_demod_ui_init();
-       //aml_demod_dbg_init();
+       aml_demod_dbg_init();
 
        return 0;
 
@@ -1027,7 +747,7 @@ static void __exit aml_demod_exit(void)
        class_unregister(&aml_demod_class);
 
        aml_demod_exit_ui();
-       //aml_demod_dbg_exit();
+       aml_demod_dbg_exit();
 }
 
 #ifndef CONFIG_AM_DEMOD_DVBAPI
index 780c4fd..9894e73 100644 (file)
@@ -51,8 +51,6 @@
 #include <linux/dvb/aml_demod.h>
 #include "demod_func.h"
 
-#include "amlfrontend.h"
-
 /*dma_get_cma_size_int_byte*/
 #include <linux/amlogic/media/codec_mm/codec_mm.h>
 #include <linux/dma-contiguous.h>
@@ -71,12 +69,21 @@ module_param(auto_search_std, int, 0644);
 MODULE_PARM_DESC(std_lock_timeout, "\n\t\t atsc-c std lock timeout");
 static unsigned int std_lock_timeout = 1000;
 module_param(std_lock_timeout, int, 0644);
-/*0.001for field,0.002 for performance*/
-static char *demod_version = "V0.03";
+
+/*0.001for field,0.002 for performance
+ *0.04: new method of tl1 dvbc channel fast search(Hisense project)
+ */
+static char *demod_version = "V0.04";
 
 
 int aml_demod_debug = DBG_INFO;
 
+/*use this flag to mark the new method for dvbc channel fast search
+ *it's disabled as default, can be enabled if needed
+ *we can make it always enabled after all testing are passed
+ */
+static unsigned int demod_dvbc_speedup_en;
+
 
 #if 0
 #define PR_DBG(fmt, args ...) \
@@ -213,7 +220,7 @@ static ssize_t dvbc_auto_sym_store(struct class *cls,
 
 static unsigned int dtmb_mode;
 static unsigned int atsc_mode_para;
-static unsigned int demod_mode_para;
+static enum demod_md demod_mode_para;
 
 
 enum {
@@ -231,20 +238,10 @@ enum {
        ATSC_READ_FREQ = 4,
 };
 
-enum {
-       UNKNOWN = 0,
-       AML_DVBC,
-       AML_DTMB,
-       AML_DVBT,
-       AML_ATSC,
-       AML_J83B,
-       AML_ISDBT,
-       AML_DVBT2
-};
-
-
-
-
+enum demod_md demod_get_current_mode(void)
+{
+       return demod_mode_para;
+}
 
 int convert_snr(int in_snr)
 {
@@ -995,12 +992,11 @@ static int demod_dvbc_speed_up(enum fe_status *status)
                                check_ok = 1;
                        } else {
                                for (i = 0; i < dvbc_count; i++) {
+                                       msleep(25);
                                        sts = dvbc_get_status();
 
                                        if (sts >= 0x3)
                                                break;
-
-                                       msleep(25);
                                }
 
                                PR_DBG("[rsj]dvbc_status is 0x%x\n", sts);
@@ -1009,6 +1005,7 @@ static int demod_dvbc_speed_up(enum fe_status *status)
                                        *status = FE_TIMEDOUT;
                                        ilock = 0;
                                        check_ok = 1;
+                                       timer_disable(D_TIMER_DETECT);
                                }
                        }
 
@@ -1139,7 +1136,9 @@ static int gxtv_demod_dvbc_set_frontend(struct dvb_frontend *fe)
 }
 
 static int gxtv_demod_dvbc_get_frontend(struct dvb_frontend *fe)
-{                               /*these content will be writed into eeprom .*/
+{
+       #if 0
+       /*these content will be writed into eeprom .*/
        struct dtv_frontend_properties *c = &fe->dtv_property_cache;
        u32 qam_mode;
 
@@ -1147,6 +1146,7 @@ static int gxtv_demod_dvbc_get_frontend(struct dvb_frontend *fe)
        qam_mode = dvbc_get_qam_mode();
        c->modulation = qam_mode + 1;
        PR_DBG("[mode] is %d\n", c->modulation);
+       #endif
 
        return 0;
 }
@@ -1653,10 +1653,8 @@ static int gxtv_demod_atsc_set_frontend(struct dvb_frontend *fe)
                        qam_write_reg(0x12, 0x50e1000);
                        qam_write_reg(0x30, 0x41f2f69);
                }
-
        } else if (c->modulation > QAM_AUTO) {
                if (is_ic_ver(IC_VER_TL1)) {
-                       //demod_set_sys_atsc_v4();
                        Val_0x6a.bits = atsc_read_reg_v4(ATSC_DEMOD_REG_0X6A);
                        Val_0x6a.b.peak_thd = 0x6;//Let CCFO Quality over 6
                        atsc_write_reg_v4(ATSC_DEMOD_REG_0X6A, Val_0x6a.bits);
@@ -2508,11 +2506,134 @@ int Gxtv_Demod_Dtmb_Init(struct amldtvdemod_device_s *dev)
 }
 
 #ifdef DVB_CORE_ORI
+unsigned int demod_dvbc_get_fast_search(void)
+{
+       return demod_dvbc_speedup_en;
+}
+
+void demod_dvbc_set_fast_search(unsigned int en)
+{
+       if (en)
+               demod_dvbc_speedup_en = 1;
+       else
+               demod_dvbc_speedup_en = 0;
+}
+
+void demod_dvbc_fsm_reset(void)
+{
+       //qam_write_reg(0x7, 0xf23);
+       qam_write_reg(0x7, qam_read_reg(0x7) & ~(1 << 4));
+       qam_write_reg(0x3a, 0x0);
+       //qam_write_reg(0x7, 0xf33);
+       qam_write_reg(0x7, qam_read_reg(0x7) | (1 << 4));
+       qam_write_reg(0x3a, 0x4);
+}
+
+//return val : 0=no signal,1=has signal,2=waiting
+unsigned int demod_dvbc_64_256_auto_fast(unsigned int *delay)
+{
+       static unsigned int times, no_sig_cnt;
+       static unsigned int qam64 = 1;
+
+       if (tuner_get_ch_power2() < -87)
+               return 0;
+
+       times++;
+       PR_DVBC("fast search : times = %d\n", times);
+       if (times < 6)
+               *delay = HZ / 8;//125ms
+       else
+               *delay = HZ / 2;//500ms
+
+       if ((qam_read_reg(0x31) & 0xf) < 3) {
+               no_sig_cnt++;
+
+               if (no_sig_cnt == 2 && times == 2) {//250ms
+                       no_sig_cnt = 0;
+                       times = 0;
+                       *delay = HZ / 4;
+                       qam64 = 1;
+                       return 0;
+               }
+       } else if ((qam_read_reg(0x31) & 0xf) == 5) {
+               no_sig_cnt = 0;
+               times = 0;
+               *delay = HZ / 4;
+               qam64 = 1;
+               return 1;
+       }
+
+       if (times == 14) {
+               times = 0;
+               no_sig_cnt = 0;
+               *delay = HZ / 4;
+               qam64 = 1;
+               return 0;
+       }
+
+       qam64 = !qam64;
+
+       PR_DVBC("fast search : qam64 = %d\n", qam64);
+       if (qam64)
+               demod_dvbc_set_qam(2);//64qam
+       else
+               demod_dvbc_set_qam(4);//256qam
+
+       demod_dvbc_fsm_reset();
+
+       return 2;
+}
+
+//return val : 0=no signal,1=has signal,2=waiting
+unsigned int demod_dvbc_fast_search(unsigned int *delay)
+{
+       static unsigned int times, no_sig_cnt;
+
+       if (tuner_get_ch_power2() < -87)
+               return 0;
+
+       times++;
+       PR_DVBC("fast search : times = %d\n", times);
+       if (times < 3)
+               *delay = HZ / 8;//125ms
+       else
+               *delay = HZ / 2;//500ms
+
+       if ((qam_read_reg(0x31) & 0xf) < 3) {
+               no_sig_cnt++;
+
+               if (no_sig_cnt == 2 && times == 2) {//250ms
+                       no_sig_cnt = 0;
+                       times = 0;
+                       *delay = HZ / 4;
+                       return 0;
+               }
+       } else if ((qam_read_reg(0x31) & 0xf) == 5) {
+               no_sig_cnt = 0;
+               times = 0;
+               *delay = HZ / 4;
+               return 1;
+       }
+
+       if (times == 7) {
+               times = 0;
+               no_sig_cnt = 0;
+               *delay = HZ / 4;
+               return 0;
+       }
+
+       demod_dvbc_fsm_reset();
+
+       return 2;
+}
+
 static int gxtv_demod_dvbc_tune(struct dvb_frontend *fe, bool re_tune,
        unsigned int mode_flags, unsigned int *delay, enum fe_status *status)
 {
        /*struct dtv_frontend_properties *c = &fe->dtv_property_cache;*/
        int ret = 0;
+       unsigned int sig_flg;
+       static unsigned int fast_search_finish = 1;
        /*unsigned int up_delay;*/
        /*unsigned int firstdetet;*/
 
@@ -2526,6 +2647,26 @@ static int gxtv_demod_dvbc_tune(struct dvb_frontend *fe, bool re_tune,
                dtvdd_devp->en_detect = 1;
 
                gxtv_demod_dvbc_set_frontend(fe);
+
+               if (demod_dvbc_speedup_en == 1) {
+                       fast_search_finish = 0;
+                       *status = 0;
+                       *delay = HZ / 8;
+                       qam_write_reg(0x65, 0x400c);
+                       qam_write_reg(0x60, 0x10466000);
+                       qam_write_reg(0xac, (qam_read_reg(0xac) & (~0xff00))
+                               | 0x800);
+                       qam_write_reg(0xae, (qam_read_reg(0xae)
+                               & (~0xff000000)) | 0x8000000);
+
+                       if (fe->dtv_property_cache.modulation == QAM_AUTO)
+                               demod_dvbc_set_qam(2);//64 QAM
+               } else
+                       qam_write_reg(0x65, 0x800c);
+
+               if (demod_dvbc_speedup_en == 1)
+                       return 0;
+
                /*timer_set_max(D_TIMER_DETECT, 4000);*/
                timer_begain(D_TIMER_DETECT);
                gxtv_demod_dvbc_read_status_timer(fe, status);
@@ -2543,7 +2684,42 @@ static int gxtv_demod_dvbc_tune(struct dvb_frontend *fe, bool re_tune,
                return ret;
        }
 
-       gxtv_demod_dvbc_read_status_timer(fe, status);
+       if (demod_dvbc_speedup_en == 1) {
+               if (!fast_search_finish) {
+                       if (fe->dtv_property_cache.modulation == QAM_AUTO)
+                               sig_flg = demod_dvbc_64_256_auto_fast(delay);
+                       else
+                               sig_flg = demod_dvbc_fast_search(delay);
+
+                       switch (sig_flg) {
+                       case 0:
+                               *status = FE_TIMEDOUT;
+                               fast_search_finish = 1;
+                               PR_DVBC(">>>unlock<<<\n");
+                               break;
+                       case 1:
+                               *status =
+                               FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER |
+                               FE_HAS_VITERBI | FE_HAS_SYNC;
+                               fast_search_finish = 1;
+                               PR_DVBC(">>>lock<<<\n");
+                               break;
+                       case 2:
+                               *status = 0;
+                               break;
+                       default:
+                               PR_DVBC("wrong return value\n");
+                               break;
+                       }
+               }       else {
+                       gxtv_demod_dvbc_read_status_timer(fe, status);
+               }
+       }       else {
+               gxtv_demod_dvbc_read_status_timer(fe, status);
+       }
+
+       if (demod_dvbc_speedup_en == 1)
+               return 0;
 
        #if 0
        if (is_ic_ver(IC_VER_TL1))
@@ -4148,6 +4324,7 @@ static int aml_dtvdm_read_snr(struct dvb_frontend *fe, u16 *snr)
        return ret;
 
 }
+
 static int aml_dtvdm_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
 {
        enum aml_fe_n_mode_t nmode = dtvdd_devp->n_mode;
diff --git a/drivers/amlogic/media/dtv_demod/demod_dbg.c b/drivers/amlogic/media/dtv_demod/demod_dbg.c
new file mode 100644 (file)
index 0000000..b73b9ac
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ * drivers/amlogic/media/dtv_demod/demod_dbg.c
+ *
+ * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ */
+
+#include <linux/debugfs.h>
+#include "demod_func.h"
+#include "amlfrontend.h"
+#include "demod_dbg.h"
+#include <linux/string.h>
+
+static void demod_dump_atsc_reg(struct seq_file *seq)
+{
+       unsigned int reg_start, reg_end;
+
+       if (is_ic_ver(IC_VER_TXLX)) {
+               reg_start = 0x0;
+               reg_end = 0xfff;
+
+               for (; reg_start <= reg_end; reg_start++) {
+                       if (reg_start % 8 == 0)
+                               seq_printf(seq, "\n[addr 0x%03x] ", reg_start);
+                       seq_printf(seq, "0x%02x\t", atsc_read_reg(reg_start));
+               }
+
+               seq_puts(seq, "\n");
+       } else if (is_ic_ver(IC_VER_TL1)) {
+       }
+}
+
+static int seq_file_demod_dump_reg_show(struct seq_file *seq, void *v)
+{
+       if (demod_get_current_mode() == AML_ATSC)
+               demod_dump_atsc_reg(seq);
+       else if (demod_get_current_mode() == UNKNOWN)
+               seq_puts(seq, "current mode is unknown\n");
+
+       return 0;
+}
+
+#define DEFINE_SHOW_DEMOD(__name) \
+static int __name ## _open(struct inode *inode, struct file *file)     \
+{ \
+       return single_open(file, __name ## _show, inode->i_private);    \
+} \
+                                                                       \
+static const struct file_operations __name ## _fops = {                        \
+       .owner = THIS_MODULE,           \
+       .open = __name ## _open,        \
+       .read = seq_read,               \
+       .llseek = seq_lseek,            \
+       .release = single_release,      \
+}
+
+DEFINE_SHOW_DEMOD(seq_file_demod_dump_reg);
+
+static struct demod_debugfs_files_t demod_debugfs_files[] = {
+       {"dump_reg", S_IFREG | 0644, &seq_file_demod_dump_reg_fops},
+};
+
+static int demod_dbg_dvbc_fast_search_open(struct inode *inode,
+       struct file *file)
+{
+       PR_INFO("Demod debug Open\n");
+       return 0;
+}
+
+static int demod_dbg_dvbc_fast_search_release(struct inode *inode,
+       struct file *file)
+{
+       PR_INFO("Demod debug Release\n");
+       return 0;
+}
+
+#define BUFFER_SIZE 100
+static ssize_t demod_dbg_dvbc_fast_search_show(struct file *file,
+       char __user *userbuf, size_t count, loff_t *ppos)
+{
+       char buf[BUFFER_SIZE];
+       unsigned int len;
+
+       len = snprintf(buf, BUFFER_SIZE, "channel fast search en : %d\n",
+               demod_dvbc_get_fast_search());
+       //len += snprintf(buf + len, BUFFER_SIZE - len, "");
+
+       return simple_read_from_buffer(userbuf, count, ppos, buf, len);
+}
+
+static ssize_t demod_dbg_dvbc_fast_search_store(struct file *file,
+               const char __user *userbuf, size_t count, loff_t *ppos)
+{
+       char buf[80];
+       char cmd[80], para[80];
+       int ret;
+
+       count = min_t(size_t, count, (sizeof(buf)-1));
+       if (copy_from_user(buf, userbuf, count))
+               return -EFAULT;
+
+       buf[count] = 0;
+
+       ret = sscanf(buf, "%s %s", cmd, para);
+
+       if (!strcmp(cmd, "fast_search")) {
+               PR_INFO("channel fast search: ");
+
+               if (!strcmp(para, "on")) {
+                       PR_INFO("on\n");
+                       demod_dvbc_set_fast_search(1);
+               } else if (!strcmp(para, "off")) {
+                       PR_INFO("off\n");
+                       demod_dvbc_set_fast_search(0);
+               }
+       }
+
+       return count;
+}
+
+static const struct file_operations demod_dbg_dvbc_fast_search_fops = {
+       .owner          = THIS_MODULE,
+       .open           = demod_dbg_dvbc_fast_search_open,
+       .release        = demod_dbg_dvbc_fast_search_release,
+       //.unlocked_ioctl = aml_demod_ioctl,
+       .read = demod_dbg_dvbc_fast_search_show,
+       .write = demod_dbg_dvbc_fast_search_store,
+};
+
+void aml_demod_dbg_init(void)
+{
+       struct dentry *root_entry = dtvdd_devp->demod_root;
+       struct dentry *entry;
+       unsigned int i;
+
+       PR_INFO("%s\n", __func__);
+
+       root_entry = debugfs_create_dir("demod", NULL);
+       if (!root_entry) {
+               PR_INFO("Can't create debugfs dir frontend.\n");
+               return;
+       }
+
+       for (i = 0; i < ARRAY_SIZE(demod_debugfs_files); i++) {
+               entry = debugfs_create_file(demod_debugfs_files[i].name,
+                       demod_debugfs_files[i].mode,
+                       root_entry, NULL,
+                       demod_debugfs_files[i].fops);
+               if (!entry)
+                       PR_INFO("Can't create debugfs seq file.\n");
+       }
+
+       entry = debugfs_create_file("dvbc_channel_fast", S_IFREG | 0644,
+               root_entry, NULL,
+               &demod_dbg_dvbc_fast_search_fops);
+       if (!entry)
+               PR_INFO("Can't create debugfs fast search.\n");
+
+}
+
+void aml_demod_dbg_exit(void)
+{
+       struct dentry *root_entry = dtvdd_devp->demod_root;
+
+       if (dtvdd_devp && root_entry)
+               debugfs_remove_recursive(root_entry);
+}
+
+
index 3457a51..56d1b53 100644 (file)
@@ -179,57 +179,12 @@ static unsigned int get_adc_freq(void)
        return 24000;
 }
 
-void dvbc_reg_initial(struct aml_demod_sta *demod_sta)
+void demod_dvbc_set_qam(unsigned int qam)
 {
-       u32 clk_freq;
-       u32 adc_freq;
-       /*ary no use u8 tuner;*/
-       u8 ch_mode;
-       u8 agc_mode;
-       u32 ch_freq;
-       u16 ch_if;
-       u16 ch_bw;
-       u16 symb_rate;
-       u32 phs_cfg;
-       int afifo_ctr;
-       int max_frq_off, tmp, adc_format;
-
-       clk_freq = demod_sta->clk_freq; /* kHz */
-       /*no use adc_freq = demod_sta->adc_freq;*/      /* kHz */
-       if (is_ic_ver(IC_VER_TL1))
-               adc_freq  = demod_sta->adc_freq;
-       else
-               adc_freq  = get_adc_freq();/*24000*/;
-       adc_format = 1;
-       /*ary no use tuner = demod_sta->tuner;*/
-       ch_mode = demod_sta->ch_mode;
-       agc_mode = demod_sta->agc_mode;
-       ch_freq = demod_sta->ch_freq;   /* kHz */
-       ch_if = demod_sta->ch_if;       /* kHz */
-       ch_bw = demod_sta->ch_bw;       /* kHz */
-       symb_rate = demod_sta->symb_rate;       /* k/sec */
-       PR_DVBC("ch_if is %d,  %d,  %d,  %d, %d %d\n",
-               ch_if, ch_mode, ch_freq, ch_bw, symb_rate, adc_freq);
-/*    ch_mode=4;*/
-       /* disable irq */
-       qam_write_reg(0x34, 0);
-
-       /* reset */
-       /*dvbc_reset(); */
-       qam_write_reg(0x7, qam_read_reg(0x7) & ~(1 << 4));
-       /* disable fsm_en */
-       qam_write_reg(0x7, qam_read_reg(0x7) & ~(1 << 0));
-       /* Sw disable demod */
-       qam_write_reg(0x7, qam_read_reg(0x7) | (1 << 0));
-       /* Sw enable demod */
-       qam_write_reg(0x0, 0x0);
-       /* QAM_STATUS */
-       qam_write_reg(0x7, 0x00000f00);
        /* QAM_GCTL0 */
-       qam_write_reg(0x2, (qam_read_reg(0x2) & ~7) | (ch_mode & 7));
-       /* qam mode */
+       qam_write_reg(0x2, (qam_read_reg(0x2) & ~7) | (qam & 7));
 
-       switch (ch_mode) {
+       switch (qam) {
        case 0: /*16qam*/
                qam_write_reg(0x71, 0x000a2200);
 
@@ -265,6 +220,10 @@ void dvbc_reg_initial(struct aml_demod_sta *demod_sta)
                qam_write_reg(0x94, 0x0c1a1a00);
                break;
        case 2:/*64qam*/
+               if (is_ic_ver(IC_VER_TL1)) {
+                       qam_write_reg(0x9c, 0x2a132100);
+                       qam_write_reg(0x57, 0x606060d);
+               }
                break;
        case 3:/*128qam*/
                qam_write_reg(0x71, 0x0002c200);
@@ -291,13 +250,62 @@ void dvbc_reg_initial(struct aml_demod_sta *demod_sta)
                qam_write_reg(0x93, 0x642a240c);
                qam_write_reg(0x94, 0x0c262600);
                break;
-       case 4:
+       case 4://256 QAM
                if (is_ic_ver(IC_VER_TL1)) {
                        qam_write_reg(0x9c, 0x2a232100);
                        qam_write_reg(0x57, 0x606040d);
                }
                break;
        }
+}
+
+void dvbc_reg_initial(struct aml_demod_sta *demod_sta)
+{
+       u32 clk_freq;
+       u32 adc_freq;
+       /*ary no use u8 tuner;*/
+       u8 ch_mode;
+       u8 agc_mode;
+       u32 ch_freq;
+       u16 ch_if;
+       u16 ch_bw;
+       u16 symb_rate;
+       u32 phs_cfg;
+       int afifo_ctr;
+       int max_frq_off, tmp, adc_format;
+
+       clk_freq = demod_sta->clk_freq; /* kHz */
+       /*no use adc_freq = demod_sta->adc_freq;*/      /* kHz */
+       if (is_ic_ver(IC_VER_TL1))
+               adc_freq  = demod_sta->adc_freq;
+       else
+               adc_freq  = get_adc_freq();/*24000*/;
+       adc_format = 1;
+       /*ary no use tuner = demod_sta->tuner;*/
+       ch_mode = demod_sta->ch_mode;
+       agc_mode = demod_sta->agc_mode;
+       ch_freq = demod_sta->ch_freq;   /* kHz */
+       ch_if = demod_sta->ch_if;       /* kHz */
+       ch_bw = demod_sta->ch_bw;       /* kHz */
+       symb_rate = demod_sta->symb_rate;       /* k/sec */
+       PR_DVBC("ch_if is %d,  %d,  %d,  %d, %d %d\n",
+               ch_if, ch_mode, ch_freq, ch_bw, symb_rate, adc_freq);
+/*    ch_mode=4;*/
+       /* disable irq */
+       qam_write_reg(0x34, 0);
+
+       /* reset */
+       /*dvbc_reset(); */
+       qam_write_reg(0x7, qam_read_reg(0x7) & ~(1 << 4));
+       /* disable fsm_en */
+       qam_write_reg(0x7, qam_read_reg(0x7) & ~(1 << 0));
+       /* Sw disable demod */
+       qam_write_reg(0x7, qam_read_reg(0x7) | (1 << 0));
+       /* Sw enable demod */
+       qam_write_reg(0x0, 0x0);
+       /* QAM_STATUS */
+       qam_write_reg(0x7, 0x00000f00);
+       demod_dvbc_set_qam(ch_mode);
        /*dvbc_write_reg(QAM_BASE+0x00c, 0xfffffffe);*/
        /* // adc_cnt, symb_cnt*/
        qam_write_reg(0x3, 0xffff8ffe);
index 5d43cab..743caac 100644 (file)
@@ -39,6 +39,18 @@ enum Gxtv_Demod_Dvb_Mode {
        Gxtv_Atsc = 2,
        Gxtv_Dtmb = 3,
 };
+
+enum demod_md {
+       UNKNOWN = 0,
+       AML_DVBC,
+       AML_DTMB,
+       AML_DVBT,
+       AML_ATSC,
+       AML_J83B,
+       AML_ISDBT,
+       AML_DVBT2
+};
+
 #define Adc_Clk_35M             35714  /* adc clk    dvbc */
 #define Demod_Clk_71M   71428  /* demod clk */
 
@@ -448,4 +460,7 @@ extern unsigned int dtmb_is_update_delay(void);
 extern unsigned int dtmb_get_delay_clear(void);
 extern unsigned int dtmb_is_have_check(void);
 extern void dtmb_poll_v3(void);
+extern enum demod_md demod_get_current_mode(void);
+extern unsigned int demod_dvbc_get_fast_search(void);
+extern void demod_dvbc_set_fast_search(unsigned int en);
 #endif
diff --git a/drivers/amlogic/media/dtv_demod/include/demod_dbg.h b/drivers/amlogic/media/dtv_demod/include/demod_dbg.h
new file mode 100644 (file)
index 0000000..a0b8661
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * drivers/amlogic/media/dtv_demod/include/demod_dbg.h
+ *
+ * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ */
+
+struct demod_debugfs_files_t {
+       const char *name;
+       const umode_t mode;
+       const struct file_operations *fops;
+};
+
+extern void aml_demod_dbg_init(void);
+extern void aml_demod_dbg_exit(void);
index 3329c30..8a47d1e 100644 (file)
@@ -498,6 +498,7 @@ extern void dvbc_reg_initial_old(struct aml_demod_sta *demod_sta);
 
 /*txlx*/
 extern void dvbc_reg_initial(struct aml_demod_sta *demod_sta);
+extern void demod_dvbc_set_qam(unsigned int qam);
 extern void dvbc_init_reg_ext(void);
 extern u32 dvbc_get_ch_sts(void);
 extern u32 dvbc_get_qam_mode(void);