atv_demod: modify atv demod code [1/1]
authornengwen.chen <nengwen.chen@amlogic.com>
Wed, 5 Dec 2018 05:37:41 +0000 (13:37 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Thu, 6 Dec 2018 05:28:12 +0000 (21:28 -0800)
PD#SWPL-2295

Problem:
1.modify atv demod code for coverity.
2.add ntsc-m ring filter for t962x2.
3.merge code optimization from android l.
4.add tuner compatible info in dts for tuner debug.

Solution:
1.modify atv demod code for coverity.
2.add ntsc-m ring filter for t962x2.
3.merge code optimization from android l.
4.add tuner compatible info in dts for tuner debug.

Verify:
verified by einstein

Change-Id: I9696aa628315ee11f0c9dd279c7cc03797f04331
Signed-off-by: nengwen.chen <nengwen.chen@amlogic.com>
35 files changed:
arch/arm/boot/dts/amlogic/tl1_pxp.dts
arch/arm/boot/dts/amlogic/tl1_t962x2_skt.dts
arch/arm/boot/dts/amlogic/tl1_t962x2_x301.dts
arch/arm/boot/dts/amlogic/txl_t950_p341.dts
arch/arm/boot/dts/amlogic/txl_t960_p346.dts
arch/arm/boot/dts/amlogic/txl_t962_p320.dts
arch/arm/boot/dts/amlogic/txl_t962_p321.dts
arch/arm/boot/dts/amlogic/txl_t962_p321_720p.dts
arch/arm/boot/dts/amlogic/txlx_t962e_r321.dts
arch/arm/boot/dts/amlogic/txlx_t962e_r321_buildroot.dts
arch/arm/boot/dts/amlogic/txlx_t962x_r311_1g.dts
arch/arm/boot/dts/amlogic/txlx_t962x_r311_2g.dts
arch/arm/boot/dts/amlogic/txlx_t962x_r311_720p.dts
arch/arm/boot/dts/amlogic/txlx_t962x_r314.dts
arch/arm64/boot/dts/amlogic/txl_t950_p341.dts
arch/arm64/boot/dts/amlogic/txl_t960_p346.dts
arch/arm64/boot/dts/amlogic/txl_t962_p320.dts
arch/arm64/boot/dts/amlogic/txl_t962_p321.dts
arch/arm64/boot/dts/amlogic/txl_t962_p321_720p.dts
arch/arm64/boot/dts/amlogic/txlx_t962e_r321.dts
arch/arm64/boot/dts/amlogic/txlx_t962e_r321_buildroot.dts
arch/arm64/boot/dts/amlogic/txlx_t962x_r311_1g.dts
arch/arm64/boot/dts/amlogic/txlx_t962x_r311_2g.dts
arch/arm64/boot/dts/amlogic/txlx_t962x_r311_720p.dts
arch/arm64/boot/dts/amlogic/txlx_t962x_r314.dts
drivers/amlogic/atv_demod/atv_demod_access.c
drivers/amlogic/atv_demod/atv_demod_access.h
drivers/amlogic/atv_demod/atv_demod_debug.c
drivers/amlogic/atv_demod/atv_demod_driver.c
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
drivers/amlogic/atv_demod/atvdemod_func.h

index b688aea8a5f3e82b4a173cc88c365ce0e99ab00d..074ccde576f37d7362da9952a3a8a721c4615477 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "mxl661_tuner";
                tuner_i2c_adap = <&i2c0>;
index ab0b82110655ccce2f519bbaeafb31735e878364..15a1ecdc8175859531a13fe00cddf530001b8221 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "mxl661_tuner";
                tuner_i2c_adap = <&i2c0>;
index 0c219484677b2740b0b379ef078d568ecdcfe055..5f73946894b71dda5178535459dccb0d9152ab2d 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "mxl661_tuner";
                tuner_i2c_adap = <&i2c0>;
index ff39ed64091cd82d38e2d286b3d20509d1771265..98a4212f81d4b04f781577da0927e872951db9b3 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "r842_tuner";
                tuner_i2c_adap = <&i2c1>;
index d4f91e2d0a69f1a9e441621796696c1c4247992f..ea7df1103c75be689629ad63334eafefe142f297 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "r842_tuner";
                tuner_i2c_adap = <&i2c1>;
index 5c2ebbebdf9e72910e063768687000c03c68e360..3f913ac4542dbb95a0e74baa3c0f01138c2848a2 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "si2151_tuner";
                tuner_i2c_adap = <&i2c1>;
index 2e7881fcd7c9bd249ad1ffab7cf8fa4dafc439e9..9662a7a1074d194ce054cd1b2ecdbc844b5ffac6 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "r842_tuner";
                tuner_i2c_adap = <&i2c1>;
index cb241a65c9a6ecb2d77c9b1b64a64de291ec71dc..068fa916289000c33383dbbf4a07857e72823614 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "r842_tuner";
                tuner_i2c_adap = <&i2c1>;
index 3d8cb6352dac0cfa841c6ac1dbafab90baf5559f..e1fee9de9d738f849c0951466e4fe2b7c07b95ef 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "si2151_tuner";
                tuner_i2c_adap = <&i2c1>;
index 48ac144d59e72efb552abddad4eb044d4f2f5b3a..8240af21efb4e9be361a92f7df184efddb97c5eb 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "si2151_tuner";
                tuner_i2c_adap = <&i2c1>;
index 8a65f4161541840065be3af625f1d7bde55129df..9d38489ef6a80f7c5502bc792fd09aba994fb00b 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "mxl661_tuner";
                tuner_i2c_adap = <&i2c1>;
index 95753b5f5542905c95a9d65d5d362c289added81..09477ca4c93e15ef31113d556f735f4e793570bf 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "mxl661_tuner";
                tuner_i2c_adap = <&i2c1>;
index acf5016e8e3cc376fce5d9266ae450a7dcf01bb3..94618ff44e754a6828abcc9f469a7a6d820175ff 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "mxl661_tuner";
                tuner_i2c_adap = <&i2c1>;
index 53cc709a26a9e575d12421af19fd6ba6b3894c08..9fcf354c72237f3ed2d6496f03edb0fca2000172 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "mxl661_tuner";
                tuner_i2c_adap = <&i2c1>;
index 61adfcfd97cc994f84b66e87e26e7177bc8548a0..f3290f81fe424de54e8ea11920a6a3d49a7e49dc 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "r842_tuner";
                tuner_i2c_adap = <&i2c1>;
index 48bb78e7d36d434ec4aeed798f2de4204381b524..493dc84ee9b7e476cad4482d6ae273b7441b891d 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "r842_tuner";
                tuner_i2c_adap = <&i2c1>;
index 37fe7c776d1e7d90d2be0b6a08ccbafc2a1818ef..9f40b0549495e4261a55d41613af67389802c9b7 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "si2151_tuner";
                tuner_i2c_adap = <&i2c1>;
index f34656c48080eea7021385a96e8f024ce9da2e9e..5745eebf4da57d7c524ac79d02a33e577808b78d 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "r842_tuner";
                tuner_i2c_adap = <&i2c1>;
index 8b42608d5e0c507d288e4c45b2c7726c6ad0da4d..439619b2f3ea0eb76571807e9abfe01d19ce25e8 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "r842_tuner";
                tuner_i2c_adap = <&i2c1>;
index abf3c56be82fba1b23919d832f42761b6bb462a1..1af5e2df984a17cc895dfd2d7f72b7a7f8be5785 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "si2151_tuner";
                tuner_i2c_adap = <&i2c1>;
index 71ae1696fa1c6b1161c80e271f01fb09cb90fab9..f18c895dd43a4f7859d33739ac7a421fbfc36ad1 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "si2151_tuner";
                tuner_i2c_adap = <&i2c1>;
index fbe808f93aef713107cc0333f0f8f33efc2517d7..6b8c7e5124636f4d81c5a6de1c957d431204dddc 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "mxl661_tuner";
                tuner_i2c_adap = <&i2c1>;
index b3b9a8acf7b4d0f1c954ec871f7a542002ea4e7d..d02cc3ce945b272b837146a4ea54db118c3b8270 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "mxl661_tuner";
                tuner_i2c_adap = <&i2c1>;
index cf64903df85b93eb20db2bfaa16c01525d49ad6e..4bf67afc683438e77c6de286ef035a1464625d59 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "mxl661_tuner";
                tuner_i2c_adap = <&i2c1>;
index 8cc857ebfb41eb9262cbef7c4616a675982f13d7..d97d59a262b3dec037a37365ed0d155b47999e11 100644 (file)
        };
 
        tuner: tuner {
+               compatible = "amlogic, tuner";
                status = "okay";
                tuner_name = "mxl661_tuner";
                tuner_i2c_adap = <&i2c1>;
index 796ddf1103cbabbcca2616219f0489bf08068a2c..61e957ed7de56b22ba1f0bfe32c4fea52b9c83bc 100644 (file)
@@ -102,8 +102,8 @@ int atvaudiodem_reg_read(unsigned int reg, unsigned int *val)
                }
        }
 #endif
-       if (amlatvdemod_devp->audio_reg_base)
-               *val = readl(amlatvdemod_devp->audio_reg_base + reg);
+       if (amlatvdemod_devp->audiodemod_reg_base)
+               *val = readl(amlatvdemod_devp->audiodemod_reg_base + reg);
 
        return 0;
 }
@@ -128,8 +128,32 @@ int atvaudiodem_reg_write(unsigned int reg, unsigned int val)
        }
 #endif
 
+       if (amlatvdemod_devp->audiodemod_reg_base)
+               writel(val, (amlatvdemod_devp->audiodemod_reg_base + reg));
+
+       return 0;
+}
+
+int atvaudio_reg_read(unsigned int *val)
+{
+       /* only 0xffd0d340 read */
+       /* bit0: I2s select in_src, 0 = atv_demod, 1 = adec */
+       /* bit1: Din5, 0 = atv_demod, 1 = adec */
+       /* bit2: L/R swap for adec audio data */
        if (amlatvdemod_devp->audio_reg_base)
-               writel(val, (amlatvdemod_devp->audio_reg_base + reg));
+               *val = readl(amlatvdemod_devp->audio_reg_base);
+
+       return 0;
+}
+
+int atvaudio_reg_write(unsigned int val)
+{
+       /* only 0xffd0d340 write */
+       /* bit0: I2s select in_src, 0 = atv_demod, 1 = adec */
+       /* bit1: Din5, 0 = atv_demod, 1 = adec */
+       /* bit2: L/R swap for adec audio data */
+       if (amlatvdemod_devp->audio_reg_base)
+               writel(val, amlatvdemod_devp->audio_reg_base);
 
        return 0;
 }
@@ -179,10 +203,10 @@ void atv_dmd_wr_reg(unsigned char block, unsigned char reg, unsigned long data)
 
 unsigned long atv_dmd_rd_reg(unsigned char block, unsigned char reg)
 {
-       unsigned long data = 0;
+       unsigned int data = 0;
        unsigned int reg_addr = (block << 8) + reg * 4;
 
-       amlatvdemod_reg_read(reg_addr, (unsigned int *)&data);
+       amlatvdemod_reg_read(reg_addr, &data);
        return data;
 }
 
index 51b21821b46af8cac4839b1a2a4509fbd8932ee8..d346a5a70c1293be1ee56f41940fc8123d6b5e75 100644 (file)
@@ -25,6 +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 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);
index d85343cae3a70d26f5653ad786ad47fe165fdae8..3c61faa3c56e49709949880f5998eaf34fb9e072 100644 (file)
@@ -94,6 +94,8 @@
        DEBUGFS_CREATE_NODE(audio_a2_power_threshold, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(audio_gain_shift, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(audio_gain_lpr, 0640, dentry, u32)\
+       DEBUGFS_CREATE_NODE(audio_atv_ov, 0640, dentry, u32)\
+       DEBUGFS_CREATE_NODE(audio_atv_ov_flag, 0640, dentry, u32)\
 }
 
 
@@ -176,12 +178,11 @@ static ssize_t debugfs_write(struct file *file, const char __user *userbuf,
        char buf[20] = { 0 };
        int len = ARRAY_SIZE(debugfs_dentry);
 
+       memset(buf, 0, sizeof(buf));
        count = min_t(size_t, count, (sizeof(buf) - 1));
        if (copy_from_user(buf, userbuf, count))
                return -EFAULT;
 
-       buf[count] = 0;
-
        /*i = sscanf(buf, "%d", &val);*/
        i = kstrtoint(buf, 0, &val);
        if (i == 0) {
index 6f69f4b9639bb3b94bccbeaaadf0982acd29c9a0..4ed543d9bf531889e20ec567938da1b9cdbaa829 100644 (file)
@@ -551,7 +551,7 @@ static int aml_atvdemod_probe(struct platform_device *pdev)
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!res) {
-               pr_err("get demod memory resource fail.\n");
+               pr_err("no demod memory resource.\n");
                goto fail_get_resource;
        }
 
@@ -569,7 +569,7 @@ static int aml_atvdemod_probe(struct platform_device *pdev)
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
        if (!res) {
-               pr_err("no hiu demod memory resource.\n");
+               pr_err("no hiu memory resource.\n");
                dev->hiu_reg_base = NULL;
        } else {
                size_io_reg = resource_size(res);
@@ -587,7 +587,7 @@ static int aml_atvdemod_probe(struct platform_device *pdev)
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
        if (!res) {
-               pr_err("no periphs demod memory resource.\n");
+               pr_err("no periphs memory resource.\n");
                dev->periphs_reg_base = NULL;
        } else {
                size_io_reg = resource_size(res);
@@ -605,35 +605,31 @@ static int aml_atvdemod_probe(struct platform_device *pdev)
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 3);
        if (!res) {
-               pr_err("no audio demod memory resource.\n");
-               dev->audio_reg_base = NULL;
+               pr_err("no audiodemod memory resource.\n");
+               dev->audiodemod_reg_base = NULL;
        } else {
                size_io_reg = resource_size(res);
-               dev->audio_reg_base = devm_ioremap_nocache(
+               dev->audiodemod_reg_base = devm_ioremap_nocache(
                                &pdev->dev, res->start, size_io_reg);
-               if (!dev->audio_reg_base) {
-                       pr_err("audio ioremap failed.\n");
+               if (!dev->audiodemod_reg_base) {
+                       pr_err("audiodemod ioremap failed.\n");
                        goto fail_get_resource;
                }
 
-               pr_info("audio start = 0x%p, size = 0x%x, base = 0x%p.\n",
+               pr_info("audiodemod start = 0x%p, size = 0x%x, base = 0x%p.\n",
                                        (void *) res->start, size_io_reg,
-                                       dev->audio_reg_base);
+                                       dev->audiodemod_reg_base);
        }
 
+       /* add for audio system control */
        if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) {
-               /* add for audio system control */
-               dev->audio_demod_reg_base = ioremap(
-                               round_down(0xffd0d340, 0x3), 4);
+               dev->audio_reg_base = ioremap(round_down(0xffd0d340, 0x3), 4);
 
-               pr_info("audio_demod_reg_base = 0x%p.\n",
-                               dev->audio_demod_reg_base);
+               pr_info("audio_reg_base = 0x%p.\n", dev->audio_reg_base);
        } else if (is_meson_tl1_cpu()) {
-               dev->audio_demod_reg_base = ioremap(
-                               round_down(0xff600340, 0x3), 4);
+               dev->audio_reg_base = ioremap(round_down(0xff600340, 0x3), 4);
 
-               pr_info("audio_demod_reg_base = 0x%p.\n",
-                               dev->audio_demod_reg_base);
+               pr_info("audio_reg_base = 0x%p.\n", dev->audio_reg_base);
        }
 
        aml_atvdemod_dt_parse(dev);
index 55d67a5eddc70a75cb911490211b0a3c2dfef8a6..d4ac1eff666a1370855d47b21d5231dc4f8b6fc3 100644 (file)
@@ -66,10 +66,10 @@ struct aml_atvdemod_device {
        bool tuner_attached;
 
        void __iomem *demod_reg_base;
-       void __iomem *audio_reg_base;
+       void __iomem *audiodemod_reg_base;
        void __iomem *hiu_reg_base;
        void __iomem *periphs_reg_base;
-       void __iomem *audio_demod_reg_base;
+       void __iomem *audio_reg_base;
 
        unsigned int reg_23cf; /* IIR filter */
        int btsc_sap_mode; /*0: off 1:monitor 2:auto */
index 10c52d64605fc36e4742da1919c5e52ce454c60b..286c0750142617e1b97ed3758646f191f8260cbd 100644 (file)
@@ -543,6 +543,7 @@ static void atvdemod_fe_try_analog_format(struct v4l2_frontend *v4l2_fe,
        int i = 0;
        int try_vfmt_cnt = 300;
        int varify_cnt = 0;
+       int cvbs_std = 0;
        v4l2_std_id std_bk = 0;
        unsigned int broad_std = 0;
        unsigned int audio = 0;
@@ -554,12 +555,12 @@ static void atvdemod_fe_try_analog_format(struct v4l2_frontend *v4l2_fe,
                                                __func__);
                                break;
                        }
-                       std_bk = aml_fe_hook_get_fmt();
-                       if (std_bk) {
+                       cvbs_std = aml_fe_hook_get_fmt();
+                       if (cvbs_std) {
                                varify_cnt++;
-                               pr_dbg("get varify_cnt:%d, cnt:%d, std_bk:0x%x\n",
+                               pr_dbg("get cvbs_std varify_cnt:%d, cnt:%d, cvbs_std:0x%x\n",
                                                varify_cnt, i,
-                                               (unsigned int) std_bk);
+                                               (unsigned int) cvbs_std);
                                if (((v4l2_fe->tuner_id == AM_TUNER_R840
                                        || v4l2_fe->tuner_id == AM_TUNER_R842)
                                        && varify_cnt > 0)
@@ -596,13 +597,13 @@ static void atvdemod_fe_try_analog_format(struct v4l2_frontend *v4l2_fe,
                        usleep_range(30 * 1000, 30 * 1000 + 100);
                }
 
-               pr_dbg("get std_bk cnt:%d, std_bk: 0x%x\n",
-                               i, (unsigned int) std_bk);
+               pr_dbg("get cvbs_std cnt:%d, cvbs_std: 0x%x\n",
+                               i, (unsigned int) cvbs_std);
 
-               if (std_bk == 0) {
+               if (cvbs_std == 0) {
                        pr_err("%s: failed to get video fmt, assume PAL.\n",
                                        __func__);
-                       std_bk = TVIN_SIG_FMT_CVBS_PAL_I;
+                       cvbs_std = TVIN_SIG_FMT_CVBS_PAL_I;
                        p->std = V4L2_COLOR_STD_PAL | V4L2_STD_PAL_DK;
                        p->frequency += 1;
                        p->audmode = V4L2_STD_PAL_DK;
@@ -617,7 +618,7 @@ static void atvdemod_fe_try_analog_format(struct v4l2_frontend *v4l2_fe,
                        usleep_range(20 * 1000, 20 * 1000 + 100);
                }
 
-               std_bk = atvdemod_fe_tvin_fmt_to_v4l2_std(std_bk);
+               std_bk = atvdemod_fe_tvin_fmt_to_v4l2_std(cvbs_std);
        } else {
                /* Only search std by user setting,
                 * so no need tvafe identify signal.
@@ -634,9 +635,14 @@ static void atvdemod_fe_try_analog_format(struct v4l2_frontend *v4l2_fe,
 
        if (std_bk & V4L2_COLOR_STD_NTSC) {
 #if 1 /* For TV Signal Generator(TG39) test, NTSC need support other audio.*/
-               amlatvdemod_set_std(AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK);
-               broad_std = aml_audiomode_autodet(v4l2_fe);
-               audio = atvdemod_fmt_2_v4l2_std(broad_std);
+               if (cvbs_std == TVIN_SIG_FMT_CVBS_NTSC_M) {
+                       broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M;
+                       audio = V4L2_STD_NTSC_M;
+               } else {
+                       amlatvdemod_set_std(AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC);
+                       broad_std = aml_audiomode_autodet(v4l2_fe);
+                       audio = atvdemod_fmt_2_v4l2_std(broad_std);
+               }
 #if 0 /* I don't know what's going on here */
                if (audio == V4L2_STD_PAL_M)
                        audio = V4L2_STD_NTSC_M;
@@ -656,9 +662,15 @@ static void atvdemod_fe_try_analog_format(struct v4l2_frontend *v4l2_fe,
 #endif
        } else {
                /* V4L2_COLOR_STD_PAL */
-               amlatvdemod_set_std(AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK);
-               broad_std = aml_audiomode_autodet(v4l2_fe);
-               audio = atvdemod_fmt_2_v4l2_std(broad_std);
+               if (cvbs_std == TVIN_SIG_FMT_CVBS_PAL_M) {
+                       broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M;
+                       audio = V4L2_STD_PAL_M;
+               } else {
+                       amlatvdemod_set_std(
+                                       AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK);
+                       broad_std = aml_audiomode_autodet(v4l2_fe);
+                       audio = atvdemod_fmt_2_v4l2_std(broad_std);
+               }
 #if 0 /* Why do this to me? We need support PAL_M.*/
                if (audio == V4L2_STD_PAL_M) {
                        audio = atvdemod_fmt_2_v4l2_std(broad_std_except_pal_m);
index beaad44f9670cf77e4248498626c9789d91aa012..4e228f6badcb88e9c7e2857580d4c6c7355b53e6 100644 (file)
@@ -587,7 +587,7 @@ static int v4l2_property_process_get(struct v4l2_frontend *v4l2_fe,
        return 0;
 }
 
-static int v4l2_frontend_ioctl_properties(struct file *filp,
+static long v4l2_frontend_ioctl_properties(struct file *filp,
                        unsigned int cmd, void *parg)
 {
        struct v4l2_frontend *v4l2_fe = video_get_drvdata(video_devdata(filp));
index 4bd92194ea5644003baa16603b6c52e2349c97df..42ba7edb93c6494714e38b5d80ce89d21beca415 100644 (file)
@@ -1355,14 +1355,10 @@ void set_output_left_right_exchange(unsigned int ch)
 {
        unsigned int read = 0;
 
-       if (amlatvdemod_devp->audio_demod_reg_base == NULL)
-               return;
-
-       read = readl(amlatvdemod_devp->audio_demod_reg_base);
+       atvaudio_reg_read(&read);
 
        if ((read & (1 << 2)) != ((ch & 0x01) << 2))
-               writel((read & ~(1 << 2)) | ((ch & 0x01) << 2),
-                               amlatvdemod_devp->audio_demod_reg_base);
+               atvaudio_reg_write((read & ~(1 << 2)) | ((ch & 0x01) << 2));
 }
 
 #endif /* __ATVAUDDEMOD_FUN_H */
index fac7140ad586137612292a6745eff44bfd5b0465..963e06e846888524b89fff48691a92e008564946 100644 (file)
@@ -96,6 +96,9 @@ unsigned int audio_a2_threshold = 0x800;
 unsigned int audio_a2_delay = 10;
 unsigned int audio_nicam_delay = 100;
 
+unsigned int audio_atv_ov;
+unsigned int audio_atv_ov_flag;
+
 enum AUDIO_SCAN_ID {
        ID_PAL_I = 0,
        ID_PAL_M,
@@ -261,6 +264,49 @@ void atv_dmd_misc(void)
                        carrier_amplif_val);
        }
 
+       if (audio_atv_ov) {
+               atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
+                               0x14, 0x8000015);
+               atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
+                               0x18, 0x7ffff);
+               atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
+                               0x1c, 0x0f000);
+               atvaudio_reg_write(0x0);
+               audio_atv_ov_flag = 1;
+       } else {
+               atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
+                               0x14, 0xf400000);
+               atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
+                               0x18, 0xc000);
+               atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
+                               0x1c, 0x1f000);
+               atvaudio_reg_write(0x7);
+               audio_atv_ov_flag = 0;
+       }
+}
+
+void atv_dmd_ring_filter(bool on)
+{
+       if (!is_meson_tl1_cpu())
+               return;
+
+       if (on) {
+               atv_dmd_wr_long(APB_BLOCK_ADDR_GDE_EQUAL, 0x10, 0x8274bf);
+               atv_dmd_wr_long(APB_BLOCK_ADDR_GDE_EQUAL, 0x14, 0x1d175c);
+               atv_dmd_wr_long(APB_BLOCK_ADDR_GDE_EQUAL, 0x18, 0x2aa526);
+               atv_dmd_wr_long(APB_BLOCK_ADDR_GDE_EQUAL, 0x1c, 0x1d175c);
+               atv_dmd_wr_long(APB_BLOCK_ADDR_GDE_EQUAL, 0x20, 0x2d19e4);
+               atv_dmd_wr_long(APB_BLOCK_ADDR_GDE_EQUAL, 0x24, 0x8274bf);
+               atv_dmd_wr_long(APB_BLOCK_ADDR_GDE_EQUAL, 0x28, 0x1d175c);
+               atv_dmd_wr_long(APB_BLOCK_ADDR_GDE_EQUAL, 0x2c, 0x2aa526);
+               atv_dmd_wr_long(APB_BLOCK_ADDR_GDE_EQUAL, 0x30, 0x1d175c);
+               atv_dmd_wr_long(APB_BLOCK_ADDR_GDE_EQUAL, 0x34, 0x2d19e4);
+
+               atv_dmd_wr_long(APB_BLOCK_ADDR_GDE_EQUAL, 0x4c, 0x1);
+       } else
+               atv_dmd_wr_long(APB_BLOCK_ADDR_GDE_EQUAL, 0x4c, 0x0);
+
+       pr_err("%s do atv_dmd_ring_filter %d ...\n", __func__, on);
 }
 
 void atv_dmd_non_std_set(bool enable)
@@ -491,7 +537,8 @@ void configure_receiver(int Broadcast_Standard, unsigned int Tuner_IF_Frequency,
                (Broadcast_Standard == AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M) ||
                (Broadcast_Standard == AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_DK) ||
                (Broadcast_Standard == AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_BG) ||
-               (Broadcast_Standard == AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_I)) {
+               (Broadcast_Standard == AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_I) ||
+               (Broadcast_Standard == AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_M)) {
                gp_coeff_1[0] = 0x57777;
                gp_coeff_1[1] = 0xdd777;
                gp_coeff_1[2] = 0x7d777;
@@ -1748,6 +1795,12 @@ int atvdemod_init(void)
        pr_err("%s do atv_dmd_misc ...\n", __func__);
        atv_dmd_misc();
 
+       if (broad_std == AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_M ||
+               broad_std == AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC)
+               atv_dmd_ring_filter(true);
+       else
+               atv_dmd_ring_filter(false);
+
        pr_err("%s do atv_dmd_soft_reset ...\n", __func__);
        /*4.software reset*/
        atv_dmd_soft_reset();
@@ -1894,14 +1947,14 @@ int aml_audiomode_autodet(struct v4l2_frontend *v4l2_fe)
        unsigned long carrier_power_average_max = 0;
        unsigned long carrier_power_average[4] = {0};
        unsigned long temp_data = 0;
-       int carrier_lock_count = 0;
-       int lock = 0;
+       int lock = 0, line_lock = 0;
        int broad_std_final = 0;
        int num = 0, i = 0, final_id = 0;
        int delay_ms = 10, delay_ms_default = 10;
        int cur_std = ID_PAL_DK;
        bool secam_signal = false;
-
+       bool ntsc_signal = false;
+       bool has_audio = false;
 #if 0
        temp_data = atv_dmd_rd_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x02);
        temp_data = temp_data | 0x80;/* 0x40 */
@@ -1920,7 +1973,10 @@ int aml_audiomode_autodet(struct v4l2_frontend *v4l2_fe)
        case AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_BG:
        case AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_M:
        case AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC:
-
+               ntsc_signal = true;
+               broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M;
+               break;
+#if 0 /* ntsc will try other audio */
                broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC_M;
                atvdemod_init();
                temp_data = atv_dmd_rd_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x02);
@@ -1928,7 +1984,7 @@ int aml_audiomode_autodet(struct v4l2_frontend *v4l2_fe)
                atv_dmd_wr_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x02, temp_data);
                /* pr_err("%s, SECAM ,audio set SECAM_L\n", __func__); */
                return broad_std;
-
+#endif
        case AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_L:
        case AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_DK2:
        case AML_ATV_DEMOD_VIDEO_MODE_PROP_SECAM_DK3:
@@ -2102,9 +2158,15 @@ int aml_audiomode_autodet(struct v4l2_frontend *v4l2_fe)
                        broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_M;
                        cur_std = ID_PAL_M;
 
-                       p->std = V4L2_COLOR_STD_PAL | V4L2_STD_PAL_M;
-                       p->frequency += 1;
-                       p->audmode = V4L2_STD_PAL_M;
+                       if (!ntsc_signal) {
+                               p->std = V4L2_COLOR_STD_PAL | V4L2_STD_PAL_M;
+                               p->frequency += 1;
+                               p->audmode = V4L2_STD_PAL_M;
+                       } else {
+                               p->std = V4L2_COLOR_STD_NTSC | V4L2_STD_NTSC_M;
+                               p->frequency += 1;
+                               p->audmode = V4L2_STD_NTSC_M;
+                       }
 
                        delay_ms = delay_ms_default;
                        break;
@@ -2132,32 +2194,37 @@ int aml_audiomode_autodet(struct v4l2_frontend *v4l2_fe)
 
                /* enable audio detect function */
                temp_data = atv_dmd_rd_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x02);
-               temp_data = temp_data | 0x80;/* 0x40 */
+               temp_data = temp_data | 0x87;/* 0x40 */
                atv_dmd_wr_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x02, temp_data);
 
                usleep_range(delay_ms * 1000, delay_ms * 1000 + 100);
 
-               carrier_lock_count = 0;
+               /* ----------------judgment signal state--------------------- */
                i = 4;
+               has_audio = false;
                while (i--) {
                        retrieve_vpll_carrier_lock(&lock);
-                       if (lock == 0)
+                       line_lock = atv_dmd_rd_byte(APB_BLOCK_ADDR_VDAGC, 0x4f);
+                       if (lock == 0 && (line_lock & 0x10) == 0) {
+                               has_audio = true;
                                break;
-                       carrier_lock_count++;
-                       if (carrier_lock_count >= 20) {
-                               pr_err("%s step2, retrieve_vpll_carrier_lock failed\n",
-                                       __func__);
-                       /* return broad_std; */
                        }
+
                        usleep_range(6000, 9000);
                }
                /* ----------------read carrier_power--------------------- */
-               for (i = 0; i < 100; i++) {
-                       carrier_power =
-                               atv_dmd_rd_reg(APB_BLOCK_ADDR_SIF_STG_2, 0x03);
-                       carrier_power_max += carrier_power;
+               if (has_audio) {
+                       for (i = 0; i < 100; i++) {
+                               carrier_power = atv_dmd_rd_reg(
+                                       APB_BLOCK_ADDR_SIF_STG_2, 0x03);
+                               carrier_power_max += carrier_power;
+                       }
+                       carrier_power = carrier_power_max/i;
+               } else {
+                       carrier_power = 0;
+                       pr_err("[%s] pll and line unlock.\n", __func__);
                }
-               carrier_power = carrier_power_max/i;
+
                carrier_power_max = 0;
                pr_err("[%s] [num:%d] [broad_std:%d] audio carrier power: %lu. @@@@@@@@@@\n",
                        __func__, num, broad_std, carrier_power);
@@ -2170,7 +2237,7 @@ int aml_audiomode_autodet(struct v4l2_frontend *v4l2_fe)
 
 void aml_audio_valume_gain_set(unsigned int audio_gain)
 {
-       unsigned long audio_gain_data, temp_data;
+       unsigned long audio_gain_data = 0, temp_data = 0;
 
        if (audio_gain > 0xfff) {
                pr_err("Error: atv in gain max 7.998, min 0.002! gain = value/512\n");
@@ -2185,7 +2252,7 @@ void aml_audio_valume_gain_set(unsigned int audio_gain)
 
 unsigned int aml_audio_valume_gain_get(void)
 {
-       unsigned long audio_gain_data;
+       unsigned long audio_gain_data = 0;
 
        audio_gain_data = atv_dmd_rd_word(APB_BLOCK_ADDR_MONO_PROC, 0x52);
        audio_gain_data = audio_gain_data & 0xfff;
@@ -2194,7 +2261,7 @@ unsigned int aml_audio_valume_gain_get(void)
 
 void aml_fix_PWM_adjust(int enable)
 {
-       unsigned long  temp_data;
+       unsigned long temp_data = 0;
        /*
         * temp_data = atv_dmd_rd_byte(APB_BLOCK_ADDR_AGC_PWM, 0x08);
         * temp_data = temp_data | 0x01;
@@ -2215,16 +2282,15 @@ void aml_fix_PWM_adjust(int enable)
 
 void aml_audio_overmodulation(int enable)
 {
-       static int ov_flag;
-       unsigned long tmp_v;
-       unsigned long tmp_v1;
+       unsigned long tmp_v = 0;
+       unsigned long tmp_v1 = 0;
        u32 Broadcast_Standard = broad_std;
 
        if (enable && Broadcast_Standard ==
                AML_ATV_DEMOD_VIDEO_MODE_PROP_PAL_DK) {
                tmp_v = atv_dmd_rd_long(APB_BLOCK_ADDR_SIF_STG_2, 0x28);
                tmp_v = tmp_v&0xffff;
-               if (tmp_v >= 0x10 && ov_flag == 0) {
+               if (tmp_v > 0x10 && audio_atv_ov_flag == 0) {
                        tmp_v1 =
                                atv_dmd_rd_long(APB_BLOCK_ADDR_SIF_STG_2, 0);
                        tmp_v1 = (tmp_v1&0xffffff)|(1<<24);
@@ -2232,19 +2298,12 @@ void aml_audio_overmodulation(int enable)
                        atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
                                        0x14, 0x8000015);
                        atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
-                                       0x1c, 0x0f000);
-               } else if (tmp_v >= 0x2500 && ov_flag == 0) {
-                       tmp_v1 = atv_dmd_rd_long(APB_BLOCK_ADDR_SIF_STG_2, 0);
-                       tmp_v1 = (tmp_v1&0xffffff)|(1<<24);
-                       atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2, 0, tmp_v1);
-                       atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
-                                       0x14, 0xf400015);
-                       atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
-                                       0x18, 0xc000);
+                                       0x18, 0x7ffff);
                        atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
                                        0x1c, 0x0f000);
-                       ov_flag = 1;
-               } else if (tmp_v <= 0x10 && ov_flag == 1) {
+                       atvaudio_reg_write(0x0);
+                       audio_atv_ov_flag = 1;
+               } 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);
                        atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2, 0, tmp_v1);
@@ -2254,7 +2313,8 @@ void aml_audio_overmodulation(int enable)
                                        0x18, 0xc000);
                        atv_dmd_wr_long(APB_BLOCK_ADDR_SIF_STG_2,
                                        0x1c, 0x1f000);
-                       ov_flag = 0;
+                       atvaudio_reg_write(0x7);
+                       audio_atv_ov_flag = 0;
                }
        }
 }
index 530982c45cdafcf188f39ae69155d26657541321..30ef9b8f9ef80e0c682506315ea02a577fab269e 100644 (file)
@@ -64,6 +64,7 @@ extern void read_version_register(void);
 extern void check_communication_interface(void);
 extern void power_on_receiver(void);
 extern void atv_dmd_misc(void);
+extern void atv_dmd_ring_filter(bool on);
 extern void configure_receiver(int Broadcast_Standard,
                               unsigned int Tuner_IF_Frequency,
                               int Tuner_Input_IF_inverted, int GDE_Curve,