From ff129142f6eade542fcf6735c8aec8e6e998f5fb Mon Sep 17 00:00:00 2001 From: "nengwen.chen" Date: Wed, 5 Dec 2018 13:37:41 +0800 Subject: [PATCH] atv_demod: modify atv demod code [1/1] 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 --- arch/arm/boot/dts/amlogic/tl1_pxp.dts | 1 + arch/arm/boot/dts/amlogic/tl1_t962x2_skt.dts | 1 + arch/arm/boot/dts/amlogic/tl1_t962x2_x301.dts | 1 + arch/arm/boot/dts/amlogic/txl_t950_p341.dts | 1 + arch/arm/boot/dts/amlogic/txl_t960_p346.dts | 1 + arch/arm/boot/dts/amlogic/txl_t962_p320.dts | 1 + arch/arm/boot/dts/amlogic/txl_t962_p321.dts | 1 + arch/arm/boot/dts/amlogic/txl_t962_p321_720p.dts | 1 + arch/arm/boot/dts/amlogic/txlx_t962e_r321.dts | 1 + .../boot/dts/amlogic/txlx_t962e_r321_buildroot.dts | 1 + arch/arm/boot/dts/amlogic/txlx_t962x_r311_1g.dts | 1 + arch/arm/boot/dts/amlogic/txlx_t962x_r311_2g.dts | 1 + arch/arm/boot/dts/amlogic/txlx_t962x_r311_720p.dts | 1 + arch/arm/boot/dts/amlogic/txlx_t962x_r314.dts | 1 + arch/arm64/boot/dts/amlogic/txl_t950_p341.dts | 1 + arch/arm64/boot/dts/amlogic/txl_t960_p346.dts | 1 + arch/arm64/boot/dts/amlogic/txl_t962_p320.dts | 1 + arch/arm64/boot/dts/amlogic/txl_t962_p321.dts | 1 + arch/arm64/boot/dts/amlogic/txl_t962_p321_720p.dts | 1 + arch/arm64/boot/dts/amlogic/txlx_t962e_r321.dts | 1 + .../boot/dts/amlogic/txlx_t962e_r321_buildroot.dts | 1 + arch/arm64/boot/dts/amlogic/txlx_t962x_r311_1g.dts | 1 + arch/arm64/boot/dts/amlogic/txlx_t962x_r311_2g.dts | 1 + .../boot/dts/amlogic/txlx_t962x_r311_720p.dts | 1 + arch/arm64/boot/dts/amlogic/txlx_t962x_r314.dts | 1 + drivers/amlogic/atv_demod/atv_demod_access.c | 34 ++++- drivers/amlogic/atv_demod/atv_demod_access.h | 2 + drivers/amlogic/atv_demod/atv_demod_debug.c | 5 +- drivers/amlogic/atv_demod/atv_demod_driver.c | 34 +++-- drivers/amlogic/atv_demod/atv_demod_driver.h | 4 +- drivers/amlogic/atv_demod/atv_demod_ops.c | 42 +++--- drivers/amlogic/atv_demod/atv_demod_v4l2.c | 2 +- drivers/amlogic/atv_demod/atvauddemod_func.c | 8 +- drivers/amlogic/atv_demod/atvdemod_func.c | 142 +++++++++++++++------ drivers/amlogic/atv_demod/atvdemod_func.h | 1 + 35 files changed, 208 insertions(+), 91 deletions(-) diff --git a/arch/arm/boot/dts/amlogic/tl1_pxp.dts b/arch/arm/boot/dts/amlogic/tl1_pxp.dts index b688aea..074ccde 100644 --- a/arch/arm/boot/dts/amlogic/tl1_pxp.dts +++ b/arch/arm/boot/dts/amlogic/tl1_pxp.dts @@ -614,6 +614,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "mxl661_tuner"; tuner_i2c_adap = <&i2c0>; diff --git a/arch/arm/boot/dts/amlogic/tl1_t962x2_skt.dts b/arch/arm/boot/dts/amlogic/tl1_t962x2_skt.dts index ab0b821..15a1ecd 100644 --- a/arch/arm/boot/dts/amlogic/tl1_t962x2_skt.dts +++ b/arch/arm/boot/dts/amlogic/tl1_t962x2_skt.dts @@ -1094,6 +1094,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "mxl661_tuner"; tuner_i2c_adap = <&i2c0>; diff --git a/arch/arm/boot/dts/amlogic/tl1_t962x2_x301.dts b/arch/arm/boot/dts/amlogic/tl1_t962x2_x301.dts index 0c21948..5f73946 100644 --- a/arch/arm/boot/dts/amlogic/tl1_t962x2_x301.dts +++ b/arch/arm/boot/dts/amlogic/tl1_t962x2_x301.dts @@ -1100,6 +1100,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "mxl661_tuner"; tuner_i2c_adap = <&i2c0>; diff --git a/arch/arm/boot/dts/amlogic/txl_t950_p341.dts b/arch/arm/boot/dts/amlogic/txl_t950_p341.dts index ff39ed6..98a4212 100644 --- a/arch/arm/boot/dts/amlogic/txl_t950_p341.dts +++ b/arch/arm/boot/dts/amlogic/txl_t950_p341.dts @@ -436,6 +436,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "r842_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm/boot/dts/amlogic/txl_t960_p346.dts b/arch/arm/boot/dts/amlogic/txl_t960_p346.dts index d4f91e2..ea7df11 100644 --- a/arch/arm/boot/dts/amlogic/txl_t960_p346.dts +++ b/arch/arm/boot/dts/amlogic/txl_t960_p346.dts @@ -437,6 +437,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "r842_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm/boot/dts/amlogic/txl_t962_p320.dts b/arch/arm/boot/dts/amlogic/txl_t962_p320.dts index 5c2ebbe..3f913ac 100644 --- a/arch/arm/boot/dts/amlogic/txl_t962_p320.dts +++ b/arch/arm/boot/dts/amlogic/txl_t962_p320.dts @@ -427,6 +427,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "si2151_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm/boot/dts/amlogic/txl_t962_p321.dts b/arch/arm/boot/dts/amlogic/txl_t962_p321.dts index 2e7881f..9662a7a 100644 --- a/arch/arm/boot/dts/amlogic/txl_t962_p321.dts +++ b/arch/arm/boot/dts/amlogic/txl_t962_p321.dts @@ -432,6 +432,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "r842_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm/boot/dts/amlogic/txl_t962_p321_720p.dts b/arch/arm/boot/dts/amlogic/txl_t962_p321_720p.dts index cb241a6..068fa91 100644 --- a/arch/arm/boot/dts/amlogic/txl_t962_p321_720p.dts +++ b/arch/arm/boot/dts/amlogic/txl_t962_p321_720p.dts @@ -432,6 +432,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "r842_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm/boot/dts/amlogic/txlx_t962e_r321.dts b/arch/arm/boot/dts/amlogic/txlx_t962e_r321.dts index 3d8cb63..e1fee9d 100644 --- a/arch/arm/boot/dts/amlogic/txlx_t962e_r321.dts +++ b/arch/arm/boot/dts/amlogic/txlx_t962e_r321.dts @@ -626,6 +626,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "si2151_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm/boot/dts/amlogic/txlx_t962e_r321_buildroot.dts b/arch/arm/boot/dts/amlogic/txlx_t962e_r321_buildroot.dts index 48ac144..8240af2 100644 --- a/arch/arm/boot/dts/amlogic/txlx_t962e_r321_buildroot.dts +++ b/arch/arm/boot/dts/amlogic/txlx_t962e_r321_buildroot.dts @@ -670,6 +670,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "si2151_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm/boot/dts/amlogic/txlx_t962x_r311_1g.dts b/arch/arm/boot/dts/amlogic/txlx_t962x_r311_1g.dts index 8a65f41..9d38489 100644 --- a/arch/arm/boot/dts/amlogic/txlx_t962x_r311_1g.dts +++ b/arch/arm/boot/dts/amlogic/txlx_t962x_r311_1g.dts @@ -632,6 +632,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "mxl661_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm/boot/dts/amlogic/txlx_t962x_r311_2g.dts b/arch/arm/boot/dts/amlogic/txlx_t962x_r311_2g.dts index 95753b5..09477ca 100644 --- a/arch/arm/boot/dts/amlogic/txlx_t962x_r311_2g.dts +++ b/arch/arm/boot/dts/amlogic/txlx_t962x_r311_2g.dts @@ -629,6 +629,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "mxl661_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm/boot/dts/amlogic/txlx_t962x_r311_720p.dts b/arch/arm/boot/dts/amlogic/txlx_t962x_r311_720p.dts index acf5016..94618ff 100644 --- a/arch/arm/boot/dts/amlogic/txlx_t962x_r311_720p.dts +++ b/arch/arm/boot/dts/amlogic/txlx_t962x_r311_720p.dts @@ -625,6 +625,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "mxl661_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm/boot/dts/amlogic/txlx_t962x_r314.dts b/arch/arm/boot/dts/amlogic/txlx_t962x_r314.dts index 53cc709..9fcf354 100644 --- a/arch/arm/boot/dts/amlogic/txlx_t962x_r314.dts +++ b/arch/arm/boot/dts/amlogic/txlx_t962x_r314.dts @@ -632,6 +632,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "mxl661_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm64/boot/dts/amlogic/txl_t950_p341.dts b/arch/arm64/boot/dts/amlogic/txl_t950_p341.dts index 61adfcf..f3290f8 100644 --- a/arch/arm64/boot/dts/amlogic/txl_t950_p341.dts +++ b/arch/arm64/boot/dts/amlogic/txl_t950_p341.dts @@ -436,6 +436,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "r842_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm64/boot/dts/amlogic/txl_t960_p346.dts b/arch/arm64/boot/dts/amlogic/txl_t960_p346.dts index 48bb78e..493dc84 100644 --- a/arch/arm64/boot/dts/amlogic/txl_t960_p346.dts +++ b/arch/arm64/boot/dts/amlogic/txl_t960_p346.dts @@ -436,6 +436,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "r842_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm64/boot/dts/amlogic/txl_t962_p320.dts b/arch/arm64/boot/dts/amlogic/txl_t962_p320.dts index 37fe7c7..9f40b05 100644 --- a/arch/arm64/boot/dts/amlogic/txl_t962_p320.dts +++ b/arch/arm64/boot/dts/amlogic/txl_t962_p320.dts @@ -427,6 +427,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "si2151_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm64/boot/dts/amlogic/txl_t962_p321.dts b/arch/arm64/boot/dts/amlogic/txl_t962_p321.dts index f34656c..5745eeb 100644 --- a/arch/arm64/boot/dts/amlogic/txl_t962_p321.dts +++ b/arch/arm64/boot/dts/amlogic/txl_t962_p321.dts @@ -424,6 +424,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "r842_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm64/boot/dts/amlogic/txl_t962_p321_720p.dts b/arch/arm64/boot/dts/amlogic/txl_t962_p321_720p.dts index 8b42608..439619b 100644 --- a/arch/arm64/boot/dts/amlogic/txl_t962_p321_720p.dts +++ b/arch/arm64/boot/dts/amlogic/txl_t962_p321_720p.dts @@ -424,6 +424,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "r842_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm64/boot/dts/amlogic/txlx_t962e_r321.dts b/arch/arm64/boot/dts/amlogic/txlx_t962e_r321.dts index abf3c56..1af5e2d 100644 --- a/arch/arm64/boot/dts/amlogic/txlx_t962e_r321.dts +++ b/arch/arm64/boot/dts/amlogic/txlx_t962e_r321.dts @@ -625,6 +625,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "si2151_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm64/boot/dts/amlogic/txlx_t962e_r321_buildroot.dts b/arch/arm64/boot/dts/amlogic/txlx_t962e_r321_buildroot.dts index 71ae169..f18c895 100644 --- a/arch/arm64/boot/dts/amlogic/txlx_t962e_r321_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/txlx_t962e_r321_buildroot.dts @@ -669,6 +669,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "si2151_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm64/boot/dts/amlogic/txlx_t962x_r311_1g.dts b/arch/arm64/boot/dts/amlogic/txlx_t962x_r311_1g.dts index fbe808f..6b8c7e5 100644 --- a/arch/arm64/boot/dts/amlogic/txlx_t962x_r311_1g.dts +++ b/arch/arm64/boot/dts/amlogic/txlx_t962x_r311_1g.dts @@ -626,6 +626,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "mxl661_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm64/boot/dts/amlogic/txlx_t962x_r311_2g.dts b/arch/arm64/boot/dts/amlogic/txlx_t962x_r311_2g.dts index b3b9a8a..d02cc3c 100644 --- a/arch/arm64/boot/dts/amlogic/txlx_t962x_r311_2g.dts +++ b/arch/arm64/boot/dts/amlogic/txlx_t962x_r311_2g.dts @@ -626,6 +626,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "mxl661_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm64/boot/dts/amlogic/txlx_t962x_r311_720p.dts b/arch/arm64/boot/dts/amlogic/txlx_t962x_r311_720p.dts index cf64903..4bf67af 100644 --- a/arch/arm64/boot/dts/amlogic/txlx_t962x_r311_720p.dts +++ b/arch/arm64/boot/dts/amlogic/txlx_t962x_r311_720p.dts @@ -625,6 +625,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "mxl661_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/arch/arm64/boot/dts/amlogic/txlx_t962x_r314.dts b/arch/arm64/boot/dts/amlogic/txlx_t962x_r314.dts index 8cc857e..d97d59a 100644 --- a/arch/arm64/boot/dts/amlogic/txlx_t962x_r314.dts +++ b/arch/arm64/boot/dts/amlogic/txlx_t962x_r314.dts @@ -627,6 +627,7 @@ }; tuner: tuner { + compatible = "amlogic, tuner"; status = "okay"; tuner_name = "mxl661_tuner"; tuner_i2c_adap = <&i2c1>; diff --git a/drivers/amlogic/atv_demod/atv_demod_access.c b/drivers/amlogic/atv_demod/atv_demod_access.c index 796ddf1..61e957e 100644 --- a/drivers/amlogic/atv_demod/atv_demod_access.c +++ b/drivers/amlogic/atv_demod/atv_demod_access.c @@ -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; } diff --git a/drivers/amlogic/atv_demod/atv_demod_access.h b/drivers/amlogic/atv_demod/atv_demod_access.h index 51b2182..d346a5a 100644 --- a/drivers/amlogic/atv_demod/atv_demod_access.h +++ b/drivers/amlogic/atv_demod/atv_demod_access.h @@ -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); diff --git a/drivers/amlogic/atv_demod/atv_demod_debug.c b/drivers/amlogic/atv_demod/atv_demod_debug.c index d85343c..3c61faa 100644 --- a/drivers/amlogic/atv_demod/atv_demod_debug.c +++ b/drivers/amlogic/atv_demod/atv_demod_debug.c @@ -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) { diff --git a/drivers/amlogic/atv_demod/atv_demod_driver.c b/drivers/amlogic/atv_demod/atv_demod_driver.c index 6f69f4b..4ed543d 100644 --- a/drivers/amlogic/atv_demod/atv_demod_driver.c +++ b/drivers/amlogic/atv_demod/atv_demod_driver.c @@ -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); diff --git a/drivers/amlogic/atv_demod/atv_demod_driver.h b/drivers/amlogic/atv_demod/atv_demod_driver.h index 55d67a5..d4ac1ef 100644 --- a/drivers/amlogic/atv_demod/atv_demod_driver.h +++ b/drivers/amlogic/atv_demod/atv_demod_driver.h @@ -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 */ diff --git a/drivers/amlogic/atv_demod/atv_demod_ops.c b/drivers/amlogic/atv_demod/atv_demod_ops.c index 10c52d6..286c075 100644 --- a/drivers/amlogic/atv_demod/atv_demod_ops.c +++ b/drivers/amlogic/atv_demod/atv_demod_ops.c @@ -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); diff --git a/drivers/amlogic/atv_demod/atv_demod_v4l2.c b/drivers/amlogic/atv_demod/atv_demod_v4l2.c index beaad44..4e228f6 100644 --- a/drivers/amlogic/atv_demod/atv_demod_v4l2.c +++ b/drivers/amlogic/atv_demod/atv_demod_v4l2.c @@ -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)); diff --git a/drivers/amlogic/atv_demod/atvauddemod_func.c b/drivers/amlogic/atv_demod/atvauddemod_func.c index 4bd9219..42ba7ed 100644 --- a/drivers/amlogic/atv_demod/atvauddemod_func.c +++ b/drivers/amlogic/atv_demod/atvauddemod_func.c @@ -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 */ diff --git a/drivers/amlogic/atv_demod/atvdemod_func.c b/drivers/amlogic/atv_demod/atvdemod_func.c index fac7140..963e06e 100644 --- a/drivers/amlogic/atv_demod/atvdemod_func.c +++ b/drivers/amlogic/atv_demod/atvdemod_func.c @@ -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; } } } diff --git a/drivers/amlogic/atv_demod/atvdemod_func.h b/drivers/amlogic/atv_demod/atvdemod_func.h index 530982c..30ef9b8f 100644 --- a/drivers/amlogic/atv_demod/atvdemod_func.h +++ b/drivers/amlogic/atv_demod/atvdemod_func.h @@ -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, -- 2.7.4