atv_demod: added protection when standby wakes up [1/1]
authornengwen.chen <nengwen.chen@amlogic.com>
Thu, 13 Sep 2018 06:05:55 +0000 (14:05 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Tue, 18 Sep 2018 10:36:42 +0000 (03:36 -0700)
PD#173542: added protection when standby wakes up

1.added protection when standby wakes up.
2.separate the register access, afc and monitor into a separate module.
3.optimize the code.
4.remove unused code.

Change-Id: Ib81ebb5a175d8e7c8934151fb3dd3033a29ae0f7
Signed-off-by: nengwen.chen <nengwen.chen@amlogic.com>
22 files changed:
drivers/amlogic/atv_demod/Makefile
drivers/amlogic/atv_demod/atv_demod_access.c [new file with mode: 0644]
drivers/amlogic/atv_demod/atv_demod_access.h [new file with mode: 0644]
drivers/amlogic/atv_demod/atv_demod_afc.c [new file with mode: 0644]
drivers/amlogic/atv_demod/atv_demod_afc.h [new file with mode: 0644]
drivers/amlogic/atv_demod/atv_demod_debug.c
drivers/amlogic/atv_demod/atv_demod_debug.h
drivers/amlogic/atv_demod/atv_demod_driver.c
drivers/amlogic/atv_demod/atv_demod_driver.h
drivers/amlogic/atv_demod/atv_demod_monitor.c [new file with mode: 0644]
drivers/amlogic/atv_demod/atv_demod_monitor.h [new file with mode: 0644]
drivers/amlogic/atv_demod/atv_demod_ops.c
drivers/amlogic/atv_demod/atv_demod_ops.h
drivers/amlogic/atv_demod/atv_demod_v4l2.c
drivers/amlogic/atv_demod/atv_demod_v4l2.h
drivers/amlogic/atv_demod/atvauddemod_func.c
drivers/amlogic/atv_demod/atvauddemod_func.h
drivers/amlogic/atv_demod/atvdemod_func.c
drivers/amlogic/atv_demod/atvdemod_func.h
drivers/amlogic/atv_demod/aud_demod_reg.h
drivers/amlogic/atv_demod/aud_demod_settings.c
drivers/amlogic/atv_demod/aud_demod_settings.h

index 3f309c5..6c6b578 100644 (file)
@@ -1,6 +1,14 @@
 obj-$(CONFIG_AMLOGIC_ATV_DEMOD) += atvdemod_fe.o
 
-atvdemod_fe-objs = atvdemod_func.o atvauddemod_func.o atv_demod_v4l2.o atv_demod_driver.o atv_demod_ops.o atv_demod_debug.o
+atvdemod_fe-objs = atvdemod_func.o \
+               atvauddemod_func.o \
+               atv_demod_v4l2.o \
+               atv_demod_driver.o \
+               atv_demod_ops.o \
+               atv_demod_afc.o \
+               atv_demod_monitor.o \
+               atv_demod_access.o \
+               atv_demod_debug.o
 
 ccflags-y += -I.
 ccflags-y += -Idrivers/media/dvb-core
\ No newline at end of file
diff --git a/drivers/amlogic/atv_demod/atv_demod_access.c b/drivers/amlogic/atv_demod/atv_demod_access.c
new file mode 100644 (file)
index 0000000..0b6243b
--- /dev/null
@@ -0,0 +1,262 @@
+/*
+ * drivers/amlogic/atv_demod/atv_demod_access.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/types.h>
+#include <linux/io.h>
+#include <linux/amlogic/cpu_version.h>
+
+#include "drivers/amlogic/media/vin/tvin/tvafe/tvafe_general.h"
+
+#include "atvdemod_func.h"
+#include "atv_demod_access.h"
+#include "atv_demod_debug.h"
+#include "atv_demod_driver.h"
+
+
+int amlatvdemod_reg_read(unsigned int reg, unsigned int *val)
+{
+       int ret = 0;
+
+       if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) {
+               amlatvdemod_hiu_reg_read(HHI_GCLK_MPEG0, &ret);
+               if (0 == ((1 << 29) & ret)) {
+                       pr_err("%s GCLK_MPEG0:0x%x\n", __func__, ret);
+                       return 0;
+               }
+       } else if (0 == (ADC_EN_ATV_DEMOD & tvafe_adc_get_pll_flag())) {
+               /* pr_dbg("%s atv demod pll not init\n", __func__); */
+               return 0;
+       }
+
+       *val = readl(amlatvdemod_devp->demod_reg_base + reg);
+       return 0;
+}
+
+int amlatvdemod_reg_write(unsigned int reg, unsigned int val)
+{
+       int ret = 0;
+
+       if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) {
+               amlatvdemod_hiu_reg_read(HHI_GCLK_MPEG0, &ret);
+               if (0 == ((1 << 29) & ret)) {
+                       pr_err("%s GCLK_MPEG0:0x%x\n", __func__, ret);
+                       return 0;
+               }
+       } else if (0 == (ADC_EN_ATV_DEMOD & tvafe_adc_get_pll_flag())) {
+               /* pr_dbg("%s atv demod pll not init\n", __func__); */
+               return 0;
+       }
+
+       writel(val, (amlatvdemod_devp->demod_reg_base + reg));
+       return 0;
+}
+
+int atvaudiodem_reg_read(unsigned int reg, unsigned int *val)
+{
+       int ret = 0;
+
+       if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) {
+               amlatvdemod_hiu_reg_read(HHI_GCLK_MPEG0, &ret);
+               if (0 == ((1 << 31) & ret)) {
+                       pr_err("%s GCLK_MPEG0:0x%x\n", __func__, ret);
+                       return 0;
+               }
+       }
+
+       if (amlatvdemod_devp->audio_reg_base)
+               *val = readl(amlatvdemod_devp->audio_reg_base + reg);
+
+       return 0;
+}
+
+int atvaudiodem_reg_write(unsigned int reg, unsigned int val)
+{
+       int ret = 0;
+
+       if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) {
+               amlatvdemod_hiu_reg_read(HHI_GCLK_MPEG0, &ret);
+               if (0 == ((1 << 31) & ret)) {
+                       pr_err("%s GCLK_MPEG0:0x%x\n", __func__, ret);
+                       return 0;
+               }
+       }
+
+       if (amlatvdemod_devp->audio_reg_base)
+               writel(val, (amlatvdemod_devp->audio_reg_base + reg));
+
+       return 0;
+}
+
+int amlatvdemod_hiu_reg_read(unsigned int reg, unsigned int *val)
+{
+       if (amlatvdemod_devp->hiu_reg_base)
+               *val = readl(amlatvdemod_devp->hiu_reg_base +
+                               ((reg - 0x1000) << 2));
+
+       return 0;
+}
+
+int amlatvdemod_hiu_reg_write(unsigned int reg, unsigned int val)
+{
+       if (amlatvdemod_devp->hiu_reg_base)
+               writel(val, (amlatvdemod_devp->hiu_reg_base +
+                               ((reg - 0x1000) << 2)));
+
+       return 0;
+}
+
+int amlatvdemod_periphs_reg_read(unsigned int reg, unsigned int *val)
+{
+       if (amlatvdemod_devp->periphs_reg_base)
+               *val = readl(amlatvdemod_devp->periphs_reg_base +
+                               ((reg - 0x1000) << 2));
+
+       return 0;
+}
+
+int amlatvdemod_periphs_reg_write(unsigned int reg, unsigned int val)
+{
+       if (amlatvdemod_devp->periphs_reg_base)
+               writel(val, (amlatvdemod_devp->periphs_reg_base +
+                               ((reg - 0x1000) << 2)));
+
+       return 0;
+}
+
+void atv_dmd_wr_reg(unsigned char block, unsigned char reg, unsigned long data)
+{
+       unsigned long reg_addr = (block << 8) + reg * 4;
+
+       amlatvdemod_reg_write(reg_addr, data);
+}
+
+unsigned long atv_dmd_rd_reg(unsigned char block, unsigned char reg)
+{
+       unsigned long data = 0;
+       unsigned int reg_addr = (block << 8) + reg * 4;
+
+       amlatvdemod_reg_read(reg_addr, (unsigned int *)&data);
+       return data;
+}
+
+unsigned long atv_dmd_rd_byte(unsigned long block_addr, unsigned long reg_addr)
+{
+       unsigned long data = 0;
+
+       data = atv_dmd_rd_long(block_addr, reg_addr);
+
+       if ((reg_addr & 0x3) == 0)
+               data = data >> 24;
+       else if ((reg_addr & 0x3) == 1)
+               data = (data >> 16 & 0xff);
+       else if ((reg_addr & 0x3) == 2)
+               data = (data >> 8 & 0xff);
+       else if ((reg_addr & 0x3) == 3)
+               data = (data >> 0 & 0xff);
+
+       return data;
+}
+
+unsigned long atv_dmd_rd_word(unsigned long block_addr, unsigned long reg_addr)
+{
+       unsigned long data = 0;
+
+       data = atv_dmd_rd_long(block_addr, reg_addr);
+
+       if ((reg_addr & 0x3) == 0)
+               data = data >> 16;
+       else if ((reg_addr & 0x3) == 1)
+               data = (data >> 8 & 0xffff);
+       else if ((reg_addr & 0x3) == 2)
+               data = (data >> 0 & 0xffff);
+       else if ((reg_addr & 0x3) == 3)
+               data = (((data & 0xff) << 8) | ((data >> 24) & 0xff));
+
+       return data;
+}
+
+unsigned long atv_dmd_rd_long(unsigned long block_addr, unsigned long reg_addr)
+{
+       unsigned long data = 0;
+
+       data = R_ATVDEMOD_REG((((block_addr & 0xff) << 6) +
+                       ((reg_addr & 0xff) >> 2)) << 2);
+
+       return data;
+}
+
+void atv_dmd_wr_long(unsigned long block_addr, unsigned long reg_addr,
+               unsigned long data)
+{
+       W_ATVDEMOD_REG((((block_addr & 0xff) << 6) +
+               ((reg_addr & 0xff) >> 2)) << 2, data);
+}
+
+void atv_dmd_wr_word(unsigned long block_addr, unsigned long reg_addr,
+               unsigned long data)
+{
+       unsigned long data_tmp = 0;
+
+       data_tmp = atv_dmd_rd_long(block_addr, reg_addr);
+       data = data & 0xffff;
+       if ((reg_addr & 0x3) == 0)
+               data = (data << 16 | (data_tmp & 0xffff));
+       else if ((reg_addr & 0x3) == 1)
+               data = ((data_tmp & 0xff000000) |
+                               (data << 8) | (data_tmp & 0xff));
+       else if ((reg_addr & 0x3) == 2)
+               data = (data | (data_tmp & 0xffff0000));
+       else if ((reg_addr & 0x3) == 3)
+               data = (((data & 0xff) << 24) |
+                               ((data_tmp & 0xffff0000) >> 8) |
+                               ((data & 0xff00) >> 8));
+
+       atv_dmd_wr_long(block_addr, reg_addr, data);
+}
+
+void atv_dmd_wr_byte(unsigned long block_addr, unsigned long reg_addr,
+               unsigned long data)
+{
+       unsigned long data_tmp = 0;
+
+       data_tmp = atv_dmd_rd_long(block_addr, reg_addr);
+
+       data = data & 0xff;
+
+       if ((reg_addr & 0x3) == 0) {
+               data = (data << 24 | (data_tmp & 0xffffff));
+       } else if ((reg_addr & 0x3) == 1)
+               data = ((data_tmp & 0xff000000) |
+                               (data << 16) | (data_tmp & 0xffff));
+       else if ((reg_addr & 0x3) == 2)
+               data = ((data_tmp & 0xffff0000) |
+                               (data << 8) | (data_tmp & 0xff));
+       else if ((reg_addr & 0x3) == 3)
+               data = ((data_tmp & 0xffffff00) | (data & 0xff));
+
+       atv_dmd_wr_long(block_addr, reg_addr, data);
+}
+
+void adec_wr_reg(uint32_t reg, uint32_t val)
+{
+       atvaudiodem_reg_write(reg << 2, val);
+}
+
+uint32_t adec_rd_reg(uint32_t addr)
+{
+       return R_AUDDEMOD_REG(addr);
+}
diff --git a/drivers/amlogic/atv_demod/atv_demod_access.h b/drivers/amlogic/atv_demod/atv_demod_access.h
new file mode 100644 (file)
index 0000000..51b2182
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * drivers/amlogic/atv_demod/atv_demod_access.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.
+ *
+ */
+
+#ifndef __ATV_DEMOD_ACCESS_H__
+#define __ATV_DEMOD_ACCESS_H__
+
+#include <linux/types.h>
+
+
+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 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);
+extern int amlatvdemod_periphs_reg_write(unsigned int reg, unsigned int val);
+
+extern void atv_dmd_wr_reg(unsigned char block, unsigned char reg,
+               unsigned long data);
+extern unsigned long atv_dmd_rd_reg(unsigned char block, unsigned char reg);
+extern unsigned long atv_dmd_rd_byte(unsigned long block_address,
+               unsigned long reg_addr);
+extern unsigned long atv_dmd_rd_word(unsigned long block_address,
+               unsigned long reg_addr);
+extern unsigned long atv_dmd_rd_long(unsigned long block_address,
+               unsigned long reg_addr);
+extern void atv_dmd_wr_long(unsigned long block_address,
+               unsigned long reg_addr, unsigned long data);
+extern void atv_dmd_wr_word(unsigned long block_address,
+               unsigned long reg_addr, unsigned long data);
+extern void atv_dmd_wr_byte(unsigned long block_address,
+               unsigned long reg_addr, unsigned long data);
+
+
+static inline uint32_t R_ATVDEMOD_REG(uint32_t reg)
+{
+       uint32_t val = 0;
+
+       amlatvdemod_reg_read(reg, &val);
+       return val;
+}
+
+static inline void W_ATVDEMOD_REG(uint32_t reg, const uint32_t val)
+{
+       amlatvdemod_reg_write(reg, val);
+}
+
+static inline void W_ATVDEMOD_BIT(uint32_t reg, const uint32_t value,
+               const uint32_t start, const uint32_t len)
+{
+       W_ATVDEMOD_REG(reg, ((R_ATVDEMOD_REG(reg) &
+                       ~(((1L << (len)) - 1) << (start))) |
+                       (((value) & ((1L << (len)) - 1)) << (start))));
+}
+
+static inline uint32_t R_ATVDEMOD_BIT(uint32_t reg, const uint32_t start,
+               const uint32_t len)
+{
+       uint32_t val = 0;
+
+       val = ((R_ATVDEMOD_REG(reg) >> (start)) & ((1L << (len)) - 1));
+
+       return val;
+}
+
+static inline uint32_t R_HIU_REG(uint32_t reg)
+{
+       uint32_t val = 0;
+
+       amlatvdemod_hiu_reg_read(reg, &val);
+
+       return val;
+}
+
+static inline void W_HIU_REG(uint32_t reg, const uint32_t val)
+{
+       amlatvdemod_hiu_reg_write(reg, val);
+}
+
+static inline void W_HIU_BIT(uint32_t reg, const uint32_t value,
+               const uint32_t start, const uint32_t len)
+{
+       W_HIU_REG(reg, ((R_HIU_REG(reg) &
+                       ~(((1L << (len)) - 1) << (start))) |
+                       (((value) & ((1L << (len)) - 1)) << (start))));
+}
+
+static inline uint32_t R_HIU_BIT(uint32_t reg, const uint32_t start,
+               const uint32_t len)
+{
+       uint32_t val = 0;
+
+       val = ((R_HIU_REG(reg) >> (start)) & ((1L << (len)) - 1));
+
+       return val;
+}
+
+static inline uint32_t R_AUDDEMOD_REG(uint32_t reg)
+{
+       uint32_t val = 0;
+
+       atvaudiodem_reg_read(reg << 2, &val);
+       return val;
+}
+
+static inline void W_AUDDEMOD_REG(uint32_t reg,
+               const uint32_t val)
+{
+       atvaudiodem_reg_write(reg << 2, val);
+}
+
+static inline void W_AUDDEMOD_BIT(uint32_t reg, const uint32_t value,
+               const uint32_t start, const uint32_t len)
+{
+       W_AUDDEMOD_REG(reg, ((R_AUDDEMOD_REG(reg) &
+                       ~(((1L << (len)) - 1) << (start))) |
+                       (((value) & ((1L << (len)) - 1)) << (start))));
+}
+
+static inline uint32_t R_AUDDEMOD_BIT(uint32_t reg, const uint32_t start,
+               const uint32_t len)
+{
+       uint32_t val = 0;
+
+       val = ((R_AUDDEMOD_REG(reg) >> (start)) & ((1L << (len)) - 1));
+
+       return val;
+}
+
+#endif /* __ATV_DEMOD_ACCESS_H__ */
diff --git a/drivers/amlogic/atv_demod/atv_demod_afc.c b/drivers/amlogic/atv_demod/atv_demod_afc.c
new file mode 100644 (file)
index 0000000..896d26a
--- /dev/null
@@ -0,0 +1,289 @@
+/*
+ * drivers/amlogic/atv_demod/atv_demod_afc.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/types.h>
+#include <uapi/linux/dvb/frontend.h>
+
+#include "atvdemod_func.h"
+#include "atv_demod_afc.h"
+#include "atv_demod_ops.h"
+#include "atv_demod_debug.h"
+
+static DEFINE_MUTEX(afc_mutex);
+
+
+unsigned int afc_limit = 2100;/* +/-2.1Mhz */
+unsigned int afc_timer_delay = 1;
+unsigned int afc_timer_delay2 = 10;
+unsigned int afc_timer_delay3 = 10; /* 100ms */
+unsigned int afc_wave_cnt = 4;
+
+static int afc_range[11] = {0, -500, 500, -1000, 1000,
+               -1500, 1500, -2000, 2000, -2500, 2500};
+
+bool afc_timer_en = true;
+
+
+static void atv_demod_afc_do_work_pre(struct atv_demod_afc *afc)
+{
+       struct atv_demod_priv *priv =
+                       container_of(afc, struct atv_demod_priv, afc);
+       struct dvb_frontend *fe = afc->fe;
+       struct analog_parameters *param = &priv->atvdemod_param.param;
+
+       afc->pre_unlock_cnt++;
+       if (!afc->lock) {
+               afc->pre_lock_cnt = 0;
+               if (afc->status != AFC_LOCK_STATUS_PRE_UNLOCK && afc->offset) {
+                       param->frequency -= afc->offset * 1000;
+                       afc->offset = 0;
+                       afc->pre_step = 0;
+                       afc->status = AFC_LOCK_STATUS_PRE_UNLOCK;
+               }
+
+               if (afc->pre_unlock_cnt <= afc->wave_cnt) {/*40ms*/
+                       afc->status = AFC_LOCK_STATUS_PRE_UNLOCK;
+                       return;
+               }
+
+               if (afc->offset == afc_range[afc->pre_step]) {
+                       param->frequency -= afc_range[afc->pre_step] * 1000;
+                       afc->offset -= afc_range[afc->pre_step];
+               }
+
+               afc->pre_step++;
+               if (afc->pre_step < AFC_LOCK_PRE_STEP_NUM) {
+                       param->frequency += afc_range[afc->pre_step] * 1000;
+                       afc->offset += afc_range[afc->pre_step];
+                       afc->status = AFC_LOCK_STATUS_PRE_UNLOCK;
+               } else {
+                       param->frequency -= afc->offset * 1000;
+                       afc->offset = 0;
+                       afc->pre_step = 0;
+                       afc->status = AFC_LOCK_STATUS_PRE_OVER_RANGE;
+               }
+
+               if (fe->ops.tuner_ops.set_analog_params)
+                       fe->ops.tuner_ops.set_analog_params(fe, param);
+
+               afc->pre_unlock_cnt = 0;
+               pr_afc("%s,unlock offset:%d KHz, set freq:%d\n",
+                               __func__, afc->offset, param->frequency);
+       } else {
+               afc->pre_lock_cnt++;
+               pr_afc("%s,afc_pre_lock_cnt:%d\n",
+                               __func__, afc->pre_lock_cnt);
+               if (afc->pre_lock_cnt >= afc->wave_cnt * 2) {/*100ms*/
+                       afc->pre_lock_cnt = 0;
+                       afc->pre_unlock_cnt = 0;
+                       afc->status = AFC_LOCK_STATUS_PRE_LOCK;
+               }
+       }
+}
+
+void atv_demod_afc_do_work(struct work_struct *work)
+{
+       struct atv_demod_afc *afc =
+                       container_of(work, struct atv_demod_afc, work);
+       struct atv_demod_priv *priv =
+                               container_of(afc, struct atv_demod_priv, afc);
+       struct dvb_frontend *fe = afc->fe;
+       struct analog_parameters *param = &priv->atvdemod_param.param;
+
+       int freq_offset = 100;
+       int tmp = 0;
+       int field_lock = 0;
+       static int audio_overmodul;
+
+       if (afc->state == false)
+               return;
+
+       retrieve_vpll_carrier_lock(&tmp);/* 0 means lock, 1 means unlock */
+       afc->lock = (tmp == 0);
+
+       /*pre afc:speed up afc*/
+       if ((afc->status != AFC_LOCK_STATUS_POST_PROCESS) &&
+               (afc->status != AFC_LOCK_STATUS_POST_LOCK) &&
+               (afc->status != AFC_LOCK_STATUS_PRE_LOCK)) {
+               atv_demod_afc_do_work_pre(afc);
+               return;
+       }
+
+       afc->pre_step = 0;
+
+       if (afc->lock) {
+               if (0 == ((audio_overmodul++) % 10))
+                       aml_audio_overmodulation(1);
+       }
+
+       retrieve_frequency_offset(&freq_offset);
+
+       if (++(afc->wave_cnt) <= afc_wave_cnt) {/*40ms*/
+               afc->status = AFC_LOCK_STATUS_POST_PROCESS;
+               pr_afc("%s,wave_cnt:%d is wave,lock:%d,freq_offset:%d ignore\n",
+                               __func__, afc->wave_cnt, afc->lock,
+                               freq_offset);
+               return;
+       }
+
+       /*retrieve_frequency_offset(&freq_offset);*/
+       retrieve_field_lock(&tmp);
+       field_lock = tmp;
+
+       pr_afc("%s,freq_offset:%d lock:%d field_lock:%d freq:%d\n",
+                       __func__, freq_offset, afc->lock, field_lock,
+                       param->frequency);
+
+       if (afc->lock && (abs(freq_offset) < AFC_BEST_LOCK &&
+               abs(afc->offset) <= afc_limit) && field_lock) {
+               afc->status = AFC_LOCK_STATUS_POST_LOCK;
+               afc->wave_cnt = 0;
+               pr_afc("%s,afc lock, set wave_cnt 0\n", __func__);
+               return;
+       }
+
+       if (!afc->lock || (afc->lock && !field_lock)) {
+               afc->status = AFC_LOCK_STATUS_POST_UNLOCK;
+               afc->pre_lock_cnt = 0;
+               param->frequency -= afc->offset * 1000;
+               if (fe->ops.tuner_ops.set_analog_params)
+                       fe->ops.tuner_ops.set_analog_params(fe, param);
+               pr_afc("%s,freq_offset:%d , set freq:%d\n",
+                               __func__, freq_offset, param->frequency);
+               afc->wave_cnt = 0;
+               afc->offset = 0;
+               pr_afc("%s, [post lock --> unlock]\n", __func__);
+               return;
+       }
+
+       if (abs(afc->offset) > afc_limit) {
+               afc->no_sig_cnt++;
+               if (afc->no_sig_cnt == 20) {
+                       param->frequency -= afc->offset * 1000;
+                       pr_afc("%s,afc no_sig trig, set freq:%d\n",
+                                               __func__, param->frequency);
+                       if (fe->ops.tuner_ops.set_analog_params)
+                               fe->ops.tuner_ops.set_analog_params(fe, param);
+                       afc->wave_cnt = 0;
+                       afc->offset = 0;
+                       afc->status = AFC_LOCK_STATUS_POST_OVER_RANGE;
+               }
+               return;
+       }
+
+       afc->no_sig_cnt = 0;
+       if (abs(freq_offset) >= AFC_BEST_LOCK) {
+               param->frequency += freq_offset * 1000;
+               afc->offset += freq_offset;
+               if (fe->ops.tuner_ops.set_analog_params)
+                       fe->ops.tuner_ops.set_analog_params(fe, param);
+
+               pr_afc("%s,freq_offset:%d , set freq:%d\n",
+                               __func__, freq_offset, param->frequency);
+       }
+
+       afc->wave_cnt = 0;
+       afc->status = AFC_LOCK_STATUS_POST_PROCESS;
+}
+
+static void atv_demod_afc_timer_handler(unsigned long arg)
+{
+       struct atv_demod_afc *afc = (struct atv_demod_afc *)arg;
+       struct dvb_frontend *fe = afc->fe;
+       unsigned int delay_ms = 0;
+
+       if (afc->state == false)
+               return;
+
+       if (afc->status == AFC_LOCK_STATUS_POST_OVER_RANGE ||
+               afc->status == AFC_LOCK_STATUS_PRE_OVER_RANGE ||
+               afc->status == AFC_LOCK_STATUS_POST_LOCK)
+               delay_ms = afc_timer_delay2;/*100ms*/
+       else
+               delay_ms = afc_timer_delay;/*10ms*/
+
+       afc->timer.function = atv_demod_afc_timer_handler;
+       afc->timer.data = arg;
+       afc->timer.expires = jiffies + ATVDEMOD_INTERVAL * delay_ms;
+       add_timer(&afc->timer);
+
+       if (afc->timer_delay_cnt > 0) {
+               afc->timer_delay_cnt--;
+               return;
+       }
+
+       if ((afc_timer_en == false) || (fe->ops.info.type != FE_ANALOG))
+               return;
+
+       schedule_work(&afc->work);
+}
+
+static void atv_demod_afc_disable(struct atv_demod_afc *afc)
+{
+       mutex_lock(&afc->mtx);
+
+       if (afc_timer_en && (afc->state == true)) {
+               afc->state = false;
+               del_timer_sync(&afc->timer);
+               cancel_work_sync(&afc->work);
+       }
+
+       mutex_unlock(&afc->mtx);
+
+       pr_afc("%s: state: %d.\n", __func__, afc->state);
+}
+
+static void atv_demod_afc_enable(struct atv_demod_afc *afc)
+{
+       mutex_lock(&afc->mtx);
+
+       if (afc_timer_en && (afc->state == false)) {
+               init_timer(&afc->timer);
+               afc->timer.function = atv_demod_afc_timer_handler;
+               afc->timer.data = (ulong) afc;
+               /* after afc_timer_delay3 enable demod auto detect */
+               afc->timer.expires = jiffies +
+                               ATVDEMOD_INTERVAL * afc_timer_delay3;
+               afc->offset = 0;
+               afc->no_sig_cnt = 0;
+               afc->pre_step = 0;
+               afc->status = AFC_LOCK_STATUS_NULL;
+               add_timer(&afc->timer);
+               afc->state = true;
+       }
+
+       mutex_unlock(&afc->mtx);
+
+       pr_afc("%s: state: %d.\n", __func__, afc->state);
+}
+
+void atv_demod_afc_init(struct atv_demod_afc *afc)
+{
+       mutex_lock(&afc_mutex);
+
+       mutex_init(&afc->mtx);
+
+       afc->state = false;
+       afc->timer_delay_cnt = 0;
+       afc->disable = atv_demod_afc_disable;
+       afc->enable = atv_demod_afc_enable;
+
+       INIT_WORK(&afc->work, atv_demod_afc_do_work);
+
+       mutex_unlock(&afc_mutex);
+}
+
diff --git a/drivers/amlogic/atv_demod/atv_demod_afc.h b/drivers/amlogic/atv_demod/atv_demod_afc.h
new file mode 100644 (file)
index 0000000..6beb882
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * drivers/amlogic/atv_demod/atv_demod_afc.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.
+ *
+ */
+
+#ifndef __ATV_DEMOD_AFC_H__
+#define __ATV_DEMOD_AFC_H__
+
+#include <linux/workqueue.h>
+#include <linux/timer.h>
+#include <linux/mutex.h>
+
+
+#define AFC_LOCK_STATUS_NULL 0
+#define AFC_LOCK_STATUS_PRE_UNLOCK 1
+#define AFC_LOCK_STATUS_PRE_LOCK 2
+#define AFC_LOCK_STATUS_PRE_OVER_RANGE 3
+#define AFC_LOCK_STATUS_POST_PROCESS 4
+#define AFC_LOCK_STATUS_POST_LOCK 5
+#define AFC_LOCK_STATUS_POST_UNLOCK 6
+#define AFC_LOCK_STATUS_POST_OVER_RANGE 7
+#define AFC_LOCK_STATUS_NUM 8
+#define AFC_LOCK_PRE_STEP_NUM 9
+
+#define AFC_BEST_LOCK 50
+
+struct atv_demod_afc {
+       struct work_struct work;
+       struct timer_list timer;
+
+       struct dvb_frontend *fe;
+
+       struct mutex mtx;
+
+       bool state;
+
+       int timer_delay_cnt;
+
+       unsigned int no_sig_cnt;
+       unsigned int pre_step;
+       unsigned int pre_lock_cnt;
+       unsigned int pre_unlock_cnt;
+       int offset;
+       unsigned int status;
+       unsigned int wave_cnt;
+
+       bool lock;
+
+       void (*disable)(struct atv_demod_afc *afc);
+       void (*enable)(struct atv_demod_afc *afc);
+};
+
+extern void atv_demod_afc_init(struct atv_demod_afc *afc);
+
+
+#endif /* __ATV_DEMOD_AFC_H__ */
index 567385e..d85343c 100644 (file)
        DEBUGFS_CREATE_NODE(btsc_sap_mode, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(afc_limit, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(afc_timer_en, 0640, dentry, bool)\
-       DEBUGFS_CREATE_NODE(timer_delay, 0640, dentry, u32)\
-       DEBUGFS_CREATE_NODE(timer_delay2, 0640, dentry, u32)\
-       DEBUGFS_CREATE_NODE(timer_delay3, 0640, dentry, u32)\
+       DEBUGFS_CREATE_NODE(afc_timer_delay, 0640, dentry, u32)\
+       DEBUGFS_CREATE_NODE(afc_timer_delay2, 0640, dentry, u32)\
+       DEBUGFS_CREATE_NODE(afc_timer_delay3, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(afc_wave_cnt, 0640, dentry, u32)\
-       DEBUGFS_CREATE_NODE(atvdemod_scan_mode, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(tuner_status_cnt, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(slow_mode, 0640, dentry, bool)\
        DEBUGFS_CREATE_NODE(broad_std, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(aud_auto, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(over_threshold, 0640, dentry, u64)\
        DEBUGFS_CREATE_NODE(input_amplitude, 0640, dentry, u64)\
+       DEBUGFS_CREATE_NODE(atvaudio_det_outputmode_en, 0640, dentry, bool)\
        DEBUGFS_CREATE_NODE(audio_det_en, 0640, dentry, bool)\
        DEBUGFS_CREATE_NODE(non_std_en, 0640, dentry, u32)\
-       DEBUGFS_CREATE_NODE(atvdemod_non_std_en, 0640, dentry, bool)\
+       DEBUGFS_CREATE_NODE(atvdemod_det_nonstd_en, 0640, dentry, bool)\
        DEBUGFS_CREATE_NODE(non_std_times, 0640, dentry, u32)\
+       DEBUGFS_CREATE_NODE(non_check_delay_times, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(atv_video_gain, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(carrier_amplif_val, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(extra_input_fil_val, 0640, dentry, u32)\
-       DEBUGFS_CREATE_NODE(audio_det_mode, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(aud_dmd_jilinTV, 0640, dentry, bool)\
        DEBUGFS_CREATE_NODE(if_freq, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(if_inv, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(atvdemod_afc_range, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(atvdemod_afc_offset, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(atvdemod_timer_en, 0640, dentry, bool)\
-       DEBUGFS_CREATE_NODE(atvdemod_tune_en, 0640, dentry, bool)\
-       DEBUGFS_CREATE_NODE(atvdemod_monitor_en, 0640, dentry, bool)\
+       DEBUGFS_CREATE_NODE(atvdemod_timer_delay, 0640, dentry, u32)\
+       DEBUGFS_CREATE_NODE(atvdemod_timer_delay2, 0640, dentry, u32)\
+       DEBUGFS_CREATE_NODE(atvdemod_mixer_tune_en, 0640, dentry, bool)\
+       DEBUGFS_CREATE_NODE(atvdemod_overmodulated_en, 0640, dentry, bool)\
        DEBUGFS_CREATE_NODE(audio_thd_en, 0640, dentry, bool)\
        DEBUGFS_CREATE_NODE(pwm_kp, 0640, dentry, u32)\
-       DEBUGFS_CREATE_NODE(reg_dbg_en, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(audio_gain_val, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(audio_a2_threshold, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(audio_a2_delay, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(audio_nicam_delay, 0640, dentry, u32)\
        DEBUGFS_CREATE_NODE(audio_a2_auto, 0640, dentry, u32)\
        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)\
 }
 
 
 /* int type add here for debugfs */
 #define DEBUG_FS_CREATE_FILES(dentry, fops)\
 {\
-       DEBUGFS_CREATE_FILE(afc_offset, 0640, dentry, fops, int)\
        DEBUGFS_CREATE_FILE(non_std_thld_4c_h, 0640, dentry, fops, int)\
        DEBUGFS_CREATE_FILE(non_std_thld_4c_l, 0640, dentry, fops, int)\
        DEBUGFS_CREATE_FILE(non_std_thld_54_h, 0640, dentry, fops, int)\
 #if defined(AML_ATVDEMOD_DEBUGFS)
 static struct dentry *debugfs_root;
 
-DEBUGFS_DENTRY_DEFINE(afc_offset);
 DEBUGFS_DENTRY_DEFINE(non_std_thld_4c_h);
 DEBUGFS_DENTRY_DEFINE(non_std_thld_4c_l);
 DEBUGFS_DENTRY_DEFINE(non_std_thld_54_h);
@@ -126,7 +127,6 @@ DEBUGFS_DENTRY_DEFINE(sum2_thd_l);
 DEBUGFS_DENTRY_DEFINE(afc_default);
 
 struct dentry_value *debugfs_dentry[] = {
-       DEBUGFS_DENTRY_VALUE(afc_offset),
        DEBUGFS_DENTRY_VALUE(non_std_thld_4c_h),
        DEBUGFS_DENTRY_VALUE(non_std_thld_4c_l),
        DEBUGFS_DENTRY_VALUE(non_std_thld_54_h),
index 3a8aa4b..c96f9ca 100644 (file)
@@ -1,14 +1,18 @@
 /*
- * amlogic atv demod driver
+ * drivers/amlogic/atv_demod/atv_demod_debug.h
  *
- * Author: nengwen.chen <nengwen.chen@amlogic.com>
+ * 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.
  *
- * Copyright (C) 2018 Amlogic Inc.
+ * 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.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
  */
 
 #ifndef __ATV_DEMOD_DEBUG_H__
index c70f363..f7284da 100644 (file)
@@ -1,14 +1,18 @@
 /*
- * amlogic atv demod driver
+ * drivers/amlogic/atv_demod/atv_demod_driver.c
  *
- * Author: nengwen.chen <nengwen.chen@amlogic.com>
+ * 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.
  *
- * Copyright (C) 2018 Amlogic Inc.
+ * 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.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
  */
 
 #define ATVDEMOD_DEVICE_NAME    "aml_atvdemod"
 #include "atv_demod_driver.h"
 #include "atv_demod_v4l2.h"
 #include "atv_demod_ops.h"
+#include "atv_demod_access.h"
 
 #include "atvdemod_func.h"
 #include "atvauddemod_func.h"
 
 
-#define AMLATVDEMOD_VER "V2.03"
+#define AMLATVDEMOD_VER "V2.04"
 
 struct aml_atvdemod_device *amlatvdemod_devp;
 
+unsigned int audio_gain_shift;
+unsigned int audio_gain_lpr;
+
 static ssize_t aml_atvdemod_store(struct class *class,
                struct class_attribute *attr, const char *buf, size_t count)
 {
@@ -55,11 +63,10 @@ static ssize_t aml_atvdemod_store(struct class *class,
        unsigned int data_snr_avg = 0;
        int data_afc = 0, block_addr = 0, block_reg = 0, block_val = 0;
        int i = 0, val = 0;
-       unsigned long tmp = 0;
-       struct aml_atvdemod_device *aml_atvdemod_dev = NULL;
-
-       aml_atvdemod_dev = container_of(&class,
-                       struct aml_atvdemod_device, cls);
+       unsigned long tmp = 0, data = 0;
+       struct aml_atvdemod_device *dev =
+                       container_of(class, struct aml_atvdemod_device, cls);
+       struct atv_demod_priv *priv = dev->v4l2_fe.fe.analog_demod_priv;
 
        buf_orig = kstrdup(buf, GFP_KERNEL);
        ps = buf_orig;
@@ -76,29 +83,25 @@ static ssize_t aml_atvdemod_store(struct class *class,
        if (parm[0] == NULL)
                goto EXIT;
 
+       if (priv->state != ATVDEMOD_STATE_WORK) {
+               pr_info("atvdemod_state not work  ....\n");
+               goto EXIT;
+       }
+
        if (!strncmp(parm[0], "init", 4)) {
-               ret = atv_demod_enter_mode(&amlatvdemod_devp->v4l2_fe.fe);
+               ret = atv_demod_enter_mode(&dev->v4l2_fe.fe);
                if (ret)
                        pr_info("atv init error.\n");
        } else if (!strncmp(parm[0], "audout_mode", 11)) {
-               if (atv_demod_get_state() == ATVDEMOD_STATE_WORK) {
-                       if (is_meson_txlx_cpu()) {
-                               atvauddemod_set_outputmode();
-                               pr_info("atvauddemod_set_outputmode done ....\n");
-                       }
-               } else {
-                       pr_info("atvdemod_state not work  ....\n");
+               if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) {
+                       atvauddemod_set_outputmode();
+                       pr_info("atvauddemod_set_outputmode done ....\n");
                }
        } else if (!strncmp(parm[0], "signal_audmode", 14)) {
                int stereo_flag, sap_flag;
-
-               if (atv_demod_get_state() == ATVDEMOD_STATE_WORK) {
-                       if (is_meson_txlx_cpu()) {
-                               update_btsc_mode(1, &stereo_flag, &sap_flag);
-                               pr_info("get signal_audmode done ....\n");
-                       }
-               } else {
-                       pr_info("atvdemod_state not work  ....\n");
+               if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) {
+                       update_btsc_mode(1, &stereo_flag, &sap_flag);
+                       pr_info("get signal_audmode done ....\n");
                }
        } else if (!strncmp(parm[0], "clk", 3)) {
                adc_set_pll_cntl(1, 0x1, NULL);
@@ -163,11 +166,7 @@ static ssize_t aml_atvdemod_store(struct class *class,
                pr_dbg("aml_atvdemod_ver %s.\n",
                                AMLATVDEMOD_VER);
        } else if (!strncmp(parm[0], "audio_autodet", 13)) {
-               aml_audiomode_autodet(&amlatvdemod_devp->v4l2_fe.fe);
-       } else if (!strncmp(parm[0], "overmodule_det", 14)) {
-               /* unsigned long over_threshold, */
-               /* int det_mode = auto_det_mode; */
-               aml_atvdemod_overmodule_det();
+               aml_audiomode_autodet(&dev->v4l2_fe.fe);
        } else if (!strncmp(parm[0], "audio_gain_set", 14)) {
                if (kstrtoul(buf + strlen("audio_gain_set") + 1, 16, &tmp) == 0)
                        val = tmp;
@@ -176,6 +175,27 @@ static ssize_t aml_atvdemod_store(struct class *class,
        } else if (!strncmp(parm[0], "audio_gain_get", 14)) {
                val = aml_audio_valume_gain_get();
                pr_dbg("audio_gain_get : %d\n", val);
+       } else if (!strncmp(parm[0], "audio_gain_shift", 16)) {
+               /* int db[] = {12, 6, 0, -6, -12, -18, -24, -30}; */
+               tmp = adec_rd_reg(0x16);
+               pr_info("audio_gain_shift : 0x%lx (%ld db).\n",
+                               (tmp & 0x7), (12 - (tmp & 0x7) * 6));
+               if (parm[1] && kstrtoul(parm[1], 0, &data) == 0) {
+                       tmp = (tmp & (~0x07)) | (data & 0x7);
+                       pr_info("set audio_gain_shift : 0x%lx (%ld db).\n",
+                                       (tmp & 0x7), (12 - (tmp & 0x7) * 6));
+                       adec_wr_reg(0x16, tmp);
+               }
+               audio_gain_shift = (tmp & 0x7);
+       } else if (!strncmp(parm[0], "audio_gain_lpr", 14)) {
+               tmp = adec_rd_reg(0x1c);
+               pr_info("audio_gain_lpr : 0x%lx\n", tmp);
+               if (parm[1] && kstrtoul(parm[1], 0, &tmp) == 0) {
+                       /*db = 20 * log(val / 0x200) */
+                       pr_info("set audio_gain_lpr : 0x%lx.\n", tmp);
+                       adec_wr_reg(0x1c, tmp);
+               }
+               audio_gain_lpr = tmp;
        } else if (!strncmp(parm[0], "fix_pwm_adj", 11)) {
                if (kstrtoul(parm[1], 10, &tmp) == 0) {
                        val = tmp;
@@ -206,7 +226,7 @@ static ssize_t aml_atvdemod_store(struct class *class,
                block_val = atv_dmd_rd_long(block_addr, block_reg);
                pr_dbg("readback_val:0x%x\n", block_val);
        } else if (!strncmp(parm[0], "snr_cur", 7)) {
-               data_snr_avg = aml_atvdemod_get_snr_ex();
+               data_snr_avg = atvdemod_get_snr_val();
                pr_dbg("**********snr_cur:%d*********\n", data_snr_avg);
        } else if (!strncmp(parm[0], "pll_status", 10)) {
                int vpll_lock;
@@ -238,21 +258,12 @@ static ssize_t aml_atvdemod_store(struct class *class,
                int priv_cfg = AML_ATVDEMOD_INIT;
                struct dvb_frontend *fe = NULL;
 
-               if (amlatvdemod_devp == NULL)
-                       pr_info("amlatvdemod_devp == NULL\n");
-
-               fe = &amlatvdemod_devp->v4l2_fe.fe;
+               fe = &dev->v4l2_fe.fe;
 
                if (parm[1] && kstrtoul(parm[1], 10, &tmp) == 0)
                        priv_cfg = tmp;
 
-               if (fe != NULL) {
-                       if (fe->ops.analog_ops.set_config != NULL)
-                               fe->ops.analog_ops.set_config(fe, &priv_cfg);
-                       else
-                               pr_info("fe->ops.analog_ops.set_config == NULL\n");
-               } else
-                       pr_info("fe == NULL\n");
+               fe->ops.analog_ops.set_config(fe, &priv_cfg);
 
                pr_info("mode_set mode %d\n", priv_cfg);
        } else if (!strncmp(parm[0], "params_set", 8)) {
@@ -261,29 +272,20 @@ static ssize_t aml_atvdemod_store(struct class *class,
                struct v4l2_analog_parameters *p = NULL;
                unsigned int std = 0;
 
-               if (amlatvdemod_devp == NULL)
-                       pr_info("amlatvdemod_devp == NULL\n");
+               fe = &dev->v4l2_fe.fe;
+               p = &dev->v4l2_fe.params;
 
-               fe = &amlatvdemod_devp->v4l2_fe.fe;
-               p = &amlatvdemod_devp->v4l2_fe.params;
-
-               if (fe != NULL && p != NULL) {
-                       if (parm[1] && kstrtoul(parm[1], 0, &tmp) == 0)
-                               std = tmp;
-                       else
-                               std = p->std;
+               if (parm[1] && kstrtoul(parm[1], 0, &tmp) == 0)
+                       std = tmp;
+               else
+                       std = p->std;
 
-                       params.frequency = p->frequency;
-                       params.mode = p->afc_range;
-                       params.audmode = p->audmode;
-                       params.std = std;
+               params.frequency = p->frequency;
+               params.mode = p->afc_range;
+               params.audmode = p->audmode;
+               params.std = std;
 
-                       if (fe->ops.analog_ops.set_params != NULL)
-                               fe->ops.analog_ops.set_params(fe, &params);
-                       else
-                               pr_info("fe->ops.analog_ops.set_params == NULL\n");
-               } else
-                       pr_info("fe == NULL\n");
+               fe->ops.analog_ops.set_params(fe, &params);
 
                pr_info("params_set std 0x%x\n", std);
        } else if (!strncmp(parm[0], "audio_set", 9)) {
@@ -297,38 +299,22 @@ static ssize_t aml_atvdemod_store(struct class *class,
 
                pr_info("audio_set std %d\n", std);
        } else if (!strncmp(parm[0], "atvdemod_status", 15)) {
-               struct v4l2_analog_parameters *p = NULL;
-
-               if (amlatvdemod_devp != NULL) {
-                       p = &amlatvdemod_devp->v4l2_fe.params;
-                       if (p != NULL) {
-                               pr_info("[atvdemod] afc_range: %d\n",
-                                               p->afc_range);
-                               pr_info("[atvdemod] frequency: %d\n",
-                                               p->frequency);
-                               pr_info("[atvdemod] soundsys: %d\n",
-                                               p->soundsys);
-                               pr_info("[atvdemod] std: 0x%x (%s %s)\n",
-                                       (unsigned int) amlatvdemod_devp->std,
-                                       v4l2_std_to_str(
-                                       (0xff000000 & amlatvdemod_devp->std)),
-                                       v4l2_std_to_str(
-                                       (0xffffff & amlatvdemod_devp->std)));
-                               pr_info("[atvdemod] audmode: 0x%x\n",
-                                               amlatvdemod_devp->audmode);
-                               pr_info("[atvdemod] flag: %d\n", p->flag);
-                               pr_info("[atvdemod] tuner_id: %d\n",
-                                               amlatvdemod_devp->tuner_id);
-                               pr_info("[atvdemod] if_freq: %d\n",
-                                               amlatvdemod_devp->if_freq);
-                               pr_info("[atvdemod] if_inv: %d\n",
-                                               amlatvdemod_devp->if_inv);
-                               pr_info("[atvdemod] fre_offset: %d\n",
-                                               amlatvdemod_devp->fre_offset);
-                               pr_info("[atvdemod] version: %s.\n",
-                                               AMLATVDEMOD_VER);
-                       }
-               }
+               struct v4l2_analog_parameters *p = &dev->v4l2_fe.params;
+
+               pr_info("[atvdemod] afc_range: %d\n", p->afc_range);
+               pr_info("[atvdemod] frequency: %d\n", p->frequency);
+               pr_info("[atvdemod] soundsys: %d\n", p->soundsys);
+               pr_info("[atvdemod] std: 0x%x (%s %s)\n",
+                               (unsigned int) dev->std,
+                               v4l2_std_to_str((0xff000000 & dev->std)),
+                               v4l2_std_to_str((0xffffff & dev->std)));
+               pr_info("[atvdemod] audmode: 0x%x\n", dev->audmode);
+               pr_info("[atvdemod] flag: %d\n", p->flag);
+               pr_info("[atvdemod] tuner_id: %d\n", dev->tuner_id);
+               pr_info("[atvdemod] if_freq: %d\n", dev->if_freq);
+               pr_info("[atvdemod] if_inv: %d\n", dev->if_inv);
+               pr_info("[atvdemod] fre_offset: %d\n", dev->fre_offset);
+               pr_info("[atvdemod] version: %s.\n", AMLATVDEMOD_VER);
        } else
                pr_dbg("invalid command\n");
 
@@ -357,12 +343,6 @@ static struct class_attribute aml_atvdemod_attrs[] = {
        __ATTR_NULL
 };
 
-struct class aml_atvdemod_class = {
-       .name        = ATVDEMOD_DEVICE_NAME,
-       .owner       = THIS_MODULE,
-       .class_attrs = aml_atvdemod_attrs,
-};
-
 static void aml_atvdemod_dt_parse(struct aml_atvdemod_device *pdev)
 {
        struct device_node *node = NULL;
@@ -402,10 +382,6 @@ static void aml_atvdemod_dt_parse(struct aml_atvdemod_device *pdev)
                pdev->agc_pin = NULL;
                pr_err("can't find agc pinmux.\n");
        } else {
-#if 0 /* Get it when you actually use it */
-               pdev->agc_pin = devm_pinctrl_get_select(
-                       pdev->dev, pdev->pin_name);
-#endif
                pr_err("atvdemod agc pinmux name: %s\n",
                                pdev->pin_name);
        }
@@ -560,8 +536,15 @@ static int aml_atvdemod_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        dev->name = ATVDEMOD_DEVICE_NAME;
-       dev->cls = &aml_atvdemod_class;
        dev->dev = &pdev->dev;
+       dev->cls.name = ATVDEMOD_DEVICE_NAME;
+       dev->cls.owner = THIS_MODULE;
+       dev->cls.class_attrs = aml_atvdemod_attrs;
+
+       if (class_register(&dev->cls)) {
+               pr_err("class register fail.\n");
+               goto fail_class_register;
+       }
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!res) {
@@ -577,7 +560,7 @@ static int aml_atvdemod_probe(struct platform_device *pdev)
                goto fail_get_resource;
        }
 
-       pr_info("demod start = 0x%p, size = 0x%x, demod_reg_base = 0x%p.\n",
+       pr_info("demod start = 0x%p, size = 0x%x, base = 0x%p.\n",
                        (void *) res->start, size_io_reg,
                        dev->demod_reg_base);
 
@@ -594,7 +577,7 @@ static int aml_atvdemod_probe(struct platform_device *pdev)
                        goto fail_get_resource;
                }
 
-               pr_info("hiu start = 0x%p, size = 0x%x, hiu_reg_base = 0x%p.\n",
+               pr_info("hiu start = 0x%p, size = 0x%x, base = 0x%p.\n",
                                        (void *) res->start, size_io_reg,
                                        dev->hiu_reg_base);
        }
@@ -612,7 +595,7 @@ static int aml_atvdemod_probe(struct platform_device *pdev)
                        goto fail_get_resource;
                }
 
-               pr_info("periphs start = 0x%p, size = 0x%x, periphs_reg_base = 0x%p.\n",
+               pr_info("periphs start = 0x%p, size = 0x%x, base = 0x%p.\n",
                                        (void *) res->start, size_io_reg,
                                        dev->periphs_reg_base);
        }
@@ -630,27 +613,11 @@ static int aml_atvdemod_probe(struct platform_device *pdev)
                        goto fail_get_resource;
                }
 
-               pr_info("audio start = 0x%p, size = 0x%x, audio_reg_base = 0x%p.\n",
+               pr_info("audio start = 0x%p, size = 0x%x, base = 0x%p.\n",
                                        (void *) res->start, size_io_reg,
                                        dev->audio_reg_base);
        }
 
-#if 0 /* form dts config */
-       if (is_meson_txlx_cpu() || is_meson_txhd_cpu())
-               dev->hiu_reg_base = ioremap(0xff63c000, 0x2000);
-       else
-               dev->hiu_reg_base = ioremap(0xc883c000, 0x2000);
-
-       pr_info("hiu_reg_base = 0x%p.\n", dev->hiu_reg_base);
-
-       if (is_meson_txlx_cpu() || is_meson_txhd_cpu())
-               dev->periphs_reg_base = ioremap(0xff634000, 0x2000);
-       else
-               dev->periphs_reg_base = ioremap(0xc8834000, 0x2000);
-
-       pr_info("periphs_reg_base = 0x%p.\n", dev->periphs_reg_base);
-#endif
-
        if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) {
                /* add for audio system control */
                dev->audio_demod_reg_base = ioremap(
@@ -684,6 +651,8 @@ static int aml_atvdemod_probe(struct platform_device *pdev)
 
 fail_register_v4l2:
 fail_get_resource:
+       class_unregister(&dev->cls);
+fail_class_register:
        kfree(dev);
 
        pr_info("%s: fail.\n", __func__);
@@ -701,6 +670,8 @@ static int aml_atvdemod_remove(struct platform_device *pdev)
        v4l2_unresister_frontend(&dev->v4l2_fe);
        aml_detach_demod_tuner(dev);
 
+       class_unregister(&dev->cls);
+
        amlatvdemod_devp = NULL;
 
        kfree(dev);
@@ -712,6 +683,10 @@ static int aml_atvdemod_remove(struct platform_device *pdev)
 
 static void aml_atvdemod_shutdown(struct platform_device *pdev)
 {
+       struct aml_atvdemod_device *dev = platform_get_drvdata(pdev);
+
+       v4l2_frontend_shutdown(&dev->v4l2_fe);
+
        pr_info("%s: OK.\n", __func__);
 }
 
@@ -763,14 +738,9 @@ static int __init aml_atvdemod_init(void)
 {
        int ret = 0;
 
-       ret = class_register(&aml_atvdemod_class);
-       if (ret < 0)
-               return ret;
-
        ret = aml_atvdemod_create_debugfs(ATVDEMOD_DRIVER_NAME);
        if (ret < 0) {
                pr_err("%s: failed to create debugfs.\n", __func__);
-               class_unregister(&aml_atvdemod_class);
                return ret;
        }
 
@@ -778,7 +748,6 @@ static int __init aml_atvdemod_init(void)
        if (ret < 0) {
                pr_err("%s: failed to register driver.\n", __func__);
                aml_atvdemod_remove_debugfs();
-               class_unregister(&aml_atvdemod_class);
                return ret;
        }
 
@@ -791,7 +760,6 @@ static void __exit aml_atvdemod_exit(void)
 {
        platform_driver_unregister(&aml_atvdemod_driver);
        aml_atvdemod_remove_debugfs();
-       class_unregister(&aml_atvdemod_class);
 
        pr_info("%s: OK.\n", __func__);
 }
index 405ba0e..55d67a5 100644 (file)
@@ -1,14 +1,18 @@
 /*
- * amlogic atv demod driver
+ * drivers/amlogic/atv_demod/atv_demod_driver.h
  *
- * Author: nengwen.chen <nengwen.chen@amlogic.com>
+ * 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.
  *
- * Copyright (C) 2018 Amlogic Inc.
+ * 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.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
  */
 
 #ifndef __ATV_DEMOD_DRIVER_H__
@@ -36,7 +40,7 @@ struct aml_atvdemod_parameters {
 
 struct aml_atvdemod_device {
        char *name;
-       struct class *cls;
+       struct class cls;
        struct device *dev;
 
        unsigned int tuner_id;
diff --git a/drivers/amlogic/atv_demod/atv_demod_monitor.c b/drivers/amlogic/atv_demod/atv_demod_monitor.c
new file mode 100644 (file)
index 0000000..86cd6fc
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * drivers/amlogic/atv_demod/atv_demod_monitor.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/types.h>
+#include <uapi/linux/dvb/frontend.h>
+#include <linux/amlogic/cpu_version.h>
+
+#include "atvdemod_func.h"
+#include "atvauddemod_func.h"
+#include "atv_demod_monitor.h"
+#include "atv_demod_ops.h"
+#include "atv_demod_debug.h"
+
+static DEFINE_MUTEX(monitor_mutex);
+
+bool atvdemod_mixer_tune_en;
+bool atvdemod_overmodulated_en;
+bool audio_det_en;
+bool atvdemod_det_snr_en = true;
+bool audio_thd_en = true;
+bool atvdemod_det_nonstd_en;
+bool atvaudio_det_outputmode_en = true;
+
+unsigned int atvdemod_timer_delay = 100; /* 1s */
+unsigned int atvdemod_timer_delay2 = 10; /* 100ms */
+
+bool atvdemod_timer_en = true;
+
+
+static void atv_demod_monitor_do_work(struct work_struct *work)
+{
+       struct atv_demod_monitor *monitor =
+                       container_of(work, struct atv_demod_monitor, work);
+
+       if (!monitor->state)
+               return;
+
+       if (atvdemod_mixer_tune_en)
+               atvdemod_mixer_tune();
+
+       if (atvdemod_overmodulated_en)
+               atvdemod_video_overmodulated();
+
+       if (atvdemod_det_snr_en)
+               atvdemod_det_snr_serice();
+
+       if (audio_thd_en)
+               audio_thd_det();
+
+       if (atvaudio_det_outputmode_en &&
+               (is_meson_txlx_cpu() || is_meson_txhd_cpu()))
+               atvauddemod_set_outputmode();
+
+       if (atvdemod_det_nonstd_en)
+               atv_dmd_non_std_set(true);
+}
+
+static void atv_demod_monitor_timer_handler(unsigned long arg)
+{
+       struct atv_demod_monitor *monitor = (struct atv_demod_monitor *)arg;
+
+       /* 100ms timer */
+       monitor->timer.data = arg;
+       monitor->timer.expires = jiffies +
+                       ATVDEMOD_INTERVAL * atvdemod_timer_delay2;
+       add_timer(&monitor->timer);
+
+       if (atvdemod_timer_en == 0)
+               return;
+
+       if (vdac_enable_check_dtv())
+               return;
+
+       schedule_work(&monitor->work);
+}
+
+static void atv_demod_monitor_enable(struct atv_demod_monitor *monitor)
+{
+       mutex_lock(&monitor->mtx);
+
+       if (atvdemod_timer_en && !monitor->state) {
+               atv_dmd_non_std_set(false);
+
+               init_timer(&monitor->timer);
+               monitor->timer.data = (ulong) monitor;
+               monitor->timer.function = atv_demod_monitor_timer_handler;
+               /* after 1s enable demod auto detect */
+               monitor->timer.expires = jiffies +
+                               ATVDEMOD_INTERVAL * atvdemod_timer_delay;
+               add_timer(&monitor->timer);
+               monitor->state = true;
+       }
+
+       mutex_unlock(&monitor->mtx);
+
+       pr_dbg("%s: state: %d.\n", __func__, monitor->state);
+}
+
+static void atv_demod_monitor_disable(struct atv_demod_monitor *monitor)
+{
+       mutex_lock(&monitor->mtx);
+
+       if (atvdemod_timer_en && monitor->state) {
+               monitor->state = false;
+               atv_dmd_non_std_set(false);
+               del_timer_sync(&monitor->timer);
+               cancel_work_sync(&monitor->work);
+       }
+
+       mutex_unlock(&monitor->mtx);
+
+       pr_dbg("%s: state: %d.\n", __func__, monitor->state);
+}
+
+void atv_demod_monitor_init(struct atv_demod_monitor *monitor)
+{
+       mutex_lock(&monitor_mutex);
+
+       mutex_init(&monitor->mtx);
+
+       monitor->state = false;
+       monitor->lock = false;
+       monitor->disable = atv_demod_monitor_disable;
+       monitor->enable = atv_demod_monitor_enable;
+
+       INIT_WORK(&monitor->work, atv_demod_monitor_do_work);
+
+       mutex_unlock(&monitor_mutex);
+}
+
diff --git a/drivers/amlogic/atv_demod/atv_demod_monitor.h b/drivers/amlogic/atv_demod/atv_demod_monitor.h
new file mode 100644 (file)
index 0000000..b9c1e6a
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * drivers/amlogic/atv_demod/atv_demod_monitor.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.
+ *
+ */
+
+#ifndef __ATV_DEMOD_MONITOR_H__
+#define __ATV_DEMOD_MONITOR_H__
+
+#include <linux/workqueue.h>
+#include <linux/timer.h>
+#include <linux/mutex.h>
+
+
+struct atv_demod_monitor {
+       struct work_struct work;
+       struct timer_list timer;
+
+       struct dvb_frontend *fe;
+
+       struct mutex mtx;
+
+       bool state;
+       bool lock;
+
+       void (*disable)(struct atv_demod_monitor *monitor);
+       void (*enable)(struct atv_demod_monitor *monitor);
+};
+
+extern void atv_demod_monitor_init(struct atv_demod_monitor *monitor);
+
+
+#endif /* __ATV_DEMOD_MONITOR_H__ */
index 537346b..60ff439 100644 (file)
@@ -1,14 +1,18 @@
 /*
- * amlogic atv demod driver
+ * drivers/amlogic/atv_demod/atv_demod_ops.c
  *
- * Author: nengwen.chen <nengwen.chen@amlogic.com>
+ * 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.
  *
- * Copyright (C) 2018 Amlogic Inc.
+ * 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.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
  */
 
 #include <linux/types.h>
 #include "atv_demod_driver.h"
 #include "atv_demod_ops.h"
 #include "atv_demod_v4l2.h"
+#include "atv_demod_afc.h"
+#include "atv_demod_monitor.h"
 
 #define DEVICE_NAME "aml_atvdemod"
 
-#define ATVDEMOD_STATE_IDEL  0
-#define ATVDEMOD_STATE_WORK  1
-#define ATVDEMOD_STATE_SLEEP 2
-static int atvdemod_state = ATVDEMOD_STATE_IDEL;
 
 static DEFINE_MUTEX(atv_demod_list_mutex);
 static LIST_HEAD(hybrid_tuner_instance_list);
@@ -41,350 +43,6 @@ static LIST_HEAD(hybrid_tuner_instance_list);
 unsigned int reg_23cf = 0x88188832; /*IIR filter*/
 unsigned int btsc_sap_mode = 1;        /*0: off 1:monitor 2:auto */
 
-unsigned int atvdemod_scan_mode;
-
-bool atvdemod_tune_en;
-bool atvdemod_monitor_en;
-bool audio_det_en;
-bool atvdemod_det_snr_en = true;
-bool audio_thd_en = true;
-bool atvdemod_non_std_en;
-
-int afc_offset;
-unsigned int afc_limit = 2100;/*+-2.1Mhz*/
-static int no_sig_cnt;
-static unsigned int afc_timer_init_state;
-static unsigned int aft_thread_delaycnt;
-bool afc_timer_en = true;
-unsigned int timer_delay = 1;
-unsigned int timer_delay2 = 10;
-unsigned int timer_delay3 = 10;/*100ms*/
-unsigned int afc_wave_cnt = 4;
-
-static unsigned int demod_timer_init_state;
-bool atvdemod_timer_en = true;
-
-#define AFC_LOCK_STATUS_NULL 0
-#define AFC_LOCK_STATUS_PRE_UNLOCK 1
-#define AFC_LOCK_STATUS_PRE_LOCK 2
-#define AFC_LOCK_STATUS_PRE_OVER_RANGE 3
-#define AFC_LOCK_STATUS_POST_PROCESS 4
-#define AFC_LOCK_STATUS_POST_LOCK 5
-#define AFC_LOCK_STATUS_POST_UNLOCK 6
-#define AFC_LOCK_STATUS_POST_OVER_RANGE 7
-#define AFC_LOCK_STATUS_NUM 8
-
-#define AFC_PRE_STEP_NUM 9
-static int afc_range[11] = {0, -500, 500, -1000, 1000,
-               -1500, 1500, -2000, 2000, -2500, 2500};
-static unsigned int afc_pre_step;
-static unsigned int afc_pre_lock_cnt;
-static unsigned int afc_pre_unlock_cnt;
-static unsigned int afc_lock_status = AFC_LOCK_STATUS_NULL;
-
-static int atv_demod_get_scan_mode(void);
-static void atv_demod_set_scan_mode(int val);
-
-
-static void aml_afc_do_work_pre(int lock)
-{
-       struct dvb_frontend *fe = &amlatvdemod_devp->v4l2_fe.fe;
-       struct atv_demod_priv *priv = fe->analog_demod_priv;
-       struct analog_parameters *param = &priv->atvdemod_param.param;
-
-       afc_pre_unlock_cnt++;
-       if (!lock) {
-               afc_pre_lock_cnt = 0;
-               if (afc_lock_status != AFC_LOCK_STATUS_PRE_UNLOCK &&
-                       afc_offset) {
-                       param->frequency -= afc_offset * 1000;
-                       afc_offset = 0;
-                       afc_pre_step = 0;
-                       afc_lock_status = AFC_LOCK_STATUS_PRE_UNLOCK;
-               }
-
-               if (afc_pre_unlock_cnt <= afc_wave_cnt) {/*40ms*/
-                       afc_lock_status = AFC_LOCK_STATUS_PRE_UNLOCK;
-                       return;
-               }
-
-               if (afc_offset == afc_range[afc_pre_step]) {
-                       param->frequency -= afc_range[afc_pre_step] * 1000;
-                       afc_offset -= afc_range[afc_pre_step];
-               }
-
-               afc_pre_step++;
-               if (afc_pre_step < AFC_PRE_STEP_NUM) {
-                       param->frequency += afc_range[afc_pre_step] * 1000;
-                       afc_offset += afc_range[afc_pre_step];
-                       afc_lock_status = AFC_LOCK_STATUS_PRE_UNLOCK;
-               } else {
-                       param->frequency -= afc_offset * 1000;
-                       afc_offset = 0;
-                       afc_pre_step = 0;
-                       afc_lock_status = AFC_LOCK_STATUS_PRE_OVER_RANGE;
-               }
-
-               if (fe->ops.tuner_ops.set_analog_params)
-                       fe->ops.tuner_ops.set_analog_params(fe, param);
-
-               afc_pre_unlock_cnt = 0;
-               pr_afc("%s,unlock afc_offset:%d KHz, set freq:%d\n",
-                               __func__, afc_offset, param->frequency);
-       } else {
-               afc_pre_lock_cnt++;
-               pr_afc("%s,afc_pre_lock_cnt:%d\n",
-                               __func__, afc_pre_lock_cnt);
-               if (afc_pre_lock_cnt >= afc_wave_cnt * 2) {/*100ms*/
-                       afc_pre_lock_cnt = 0;
-                       afc_pre_unlock_cnt = 0;
-                       afc_lock_status = AFC_LOCK_STATUS_PRE_LOCK;
-               }
-       }
-}
-
-static void aml_afc_do_work(struct work_struct *work)
-{
-       struct dvb_frontend *fe = &amlatvdemod_devp->v4l2_fe.fe;
-       struct atv_demod_priv *priv = fe->analog_demod_priv;
-       struct analog_parameters *param = &priv->atvdemod_param.param;
-       int afc = 100;
-       int lock = 0;
-       int tmp = 0;
-       int field_lock = 0;
-       static int audio_overmodul;
-       static int wave_cnt;
-
-       if (afc_timer_init_state == 0)
-               return;
-
-       retrieve_vpll_carrier_lock(&tmp);/* 0 means lock, 1 means unlock */
-       lock = !tmp;
-
-       /*pre afc:speed up afc*/
-       if ((afc_lock_status != AFC_LOCK_STATUS_POST_PROCESS) &&
-               (afc_lock_status != AFC_LOCK_STATUS_POST_LOCK) &&
-               (afc_lock_status != AFC_LOCK_STATUS_PRE_LOCK)) {
-               aml_afc_do_work_pre(lock);
-               return;
-       }
-
-       afc_pre_step = 0;
-
-       if (lock) {
-               if (0 == ((audio_overmodul++) % 10))
-                       aml_audio_overmodulation(1);
-       }
-
-       retrieve_frequency_offset(&afc);
-
-       if (++wave_cnt <= afc_wave_cnt) {/*40ms*/
-               afc_lock_status = AFC_LOCK_STATUS_POST_PROCESS;
-               pr_afc("%s,wave_cnt:%d is wave,lock:%d,afc:%d ignore\n",
-                               __func__, wave_cnt, lock, afc);
-               return;
-       }
-
-       /*retrieve_frequency_offset(&afc);*/
-       retrieve_field_lock(&tmp);
-       field_lock = tmp;
-
-       pr_afc("%s,afc:%d lock:%d field_lock:%d freq:%d\n",
-                       __func__, afc, lock, field_lock, param->frequency);
-
-       if (lock && (abs(afc) < AFC_BEST_LOCK &&
-               abs(afc_offset) <= afc_limit) && field_lock) {
-               afc_lock_status = AFC_LOCK_STATUS_POST_LOCK;
-               wave_cnt = 0;
-               pr_afc("%s,afc lock, set wave_cnt 0\n", __func__);
-               return;
-       }
-
-       if (!lock || (lock && !field_lock)) {
-               afc_lock_status = AFC_LOCK_STATUS_POST_UNLOCK;
-               afc_pre_lock_cnt = 0;
-               param->frequency -= afc_offset * 1000;
-               if (fe->ops.tuner_ops.set_analog_params)
-                       fe->ops.tuner_ops.set_analog_params(fe, param);
-               pr_afc("%s,afc:%d , set freq:%d\n",
-                               __func__, afc, param->frequency);
-               wave_cnt = 0;
-               afc_offset = 0;
-               pr_afc("%s, [post lock --> unlock]\n", __func__);
-               return;
-       }
-
-       if (abs(afc_offset) > afc_limit) {
-               no_sig_cnt++;
-               if (no_sig_cnt == 20) {
-                       param->frequency -= afc_offset * 1000;
-                       pr_afc("%s,afc no_sig trig, set freq:%d\n",
-                                               __func__, param->frequency);
-                       if (fe->ops.tuner_ops.set_analog_params)
-                               fe->ops.tuner_ops.set_analog_params(fe, param);
-                       wave_cnt = 0;
-                       afc_offset = 0;
-                       afc_lock_status = AFC_LOCK_STATUS_POST_OVER_RANGE;
-               }
-               return;
-       }
-
-       no_sig_cnt = 0;
-       if (abs(afc) >= AFC_BEST_LOCK) {
-               param->frequency += afc * 1000;
-               afc_offset += afc;
-               if (fe->ops.tuner_ops.set_analog_params)
-                       fe->ops.tuner_ops.set_analog_params(fe, param);
-
-               pr_afc("%s,afc:%d , set freq:%d\n",
-                               __func__, afc, param->frequency);
-       }
-
-       wave_cnt = 0;
-       afc_lock_status = AFC_LOCK_STATUS_POST_PROCESS;
-}
-
-void aml_afc_timer_handler(unsigned long arg)
-{
-       struct dvb_frontend *fe = (struct dvb_frontend *)arg;
-       struct atv_demod_priv *priv = fe->analog_demod_priv;
-       unsigned int delay_ms = 0;
-
-       if (afc_timer_init_state == 0)
-               return;
-
-       if (afc_lock_status == AFC_LOCK_STATUS_POST_OVER_RANGE ||
-               afc_lock_status == AFC_LOCK_STATUS_PRE_OVER_RANGE ||
-               afc_lock_status == AFC_LOCK_STATUS_POST_LOCK)
-               delay_ms = timer_delay2;/*100ms*/
-       else
-               delay_ms = timer_delay;/*10ms*/
-
-       priv->afc_timer.function = aml_afc_timer_handler;
-       priv->afc_timer.data = arg;
-       priv->afc_timer.expires = jiffies + ATVDEMOD_INTERVAL * delay_ms;
-       add_timer(&priv->afc_timer);
-
-       if (aft_thread_delaycnt > 0) {
-               aft_thread_delaycnt--;
-               return;
-       }
-
-       if ((afc_timer_en == false) || (fe->ops.info.type != FE_ANALOG))
-               return;
-
-       schedule_work(&priv->afc_wq);
-}
-
-static void aml_afc_timer_disable(struct dvb_frontend *fe)
-{
-       struct atv_demod_priv *priv = fe->analog_demod_priv;
-
-       if (afc_timer_en && (afc_timer_init_state == 1)) {
-               del_timer_sync(&priv->afc_timer);
-               cancel_work_sync(&priv->demod_wq);
-               afc_timer_init_state = 0;
-       }
-}
-
-static void aml_afc_timer_enable(struct dvb_frontend *fe)
-{
-       struct atv_demod_priv *priv = fe->analog_demod_priv;
-
-       if (afc_timer_en && (afc_timer_init_state == 0)) {
-               init_timer(&priv->afc_timer);
-               priv->afc_timer.function = aml_afc_timer_handler;
-               priv->afc_timer.data = (ulong) fe;
-               /* after 5s enable demod auto detect */
-               priv->afc_timer.expires = jiffies +
-                               ATVDEMOD_INTERVAL * timer_delay3;
-               afc_offset = 0;
-               no_sig_cnt = 0;
-               afc_pre_step = 0;
-               afc_lock_status = AFC_LOCK_STATUS_NULL;
-               add_timer(&priv->afc_timer);
-               afc_timer_init_state = 1;
-       }
-}
-
-static void aml_atvdemod_do_work(struct work_struct *work)
-{
-       if (demod_timer_init_state == 0)
-               return;
-
-       if (atvdemod_tune_en)
-               atvdemod_afc_tune();
-
-       if (atvdemod_monitor_en)
-               atvdemod_monitor_serice();
-
-       if (audio_det_en)
-               aml_atvdemod_overmodule_det();
-
-       if (atvdemod_det_snr_en)
-               atvdemod_det_snr_serice();
-
-       if (audio_thd_en)
-               audio_thd_det();
-
-#if 0
-       if (aml_atvdemod_get_btsc_sap_mode() == 1 &&
-                       aud_std == AUDIO_STANDARD_BTSC)
-               audio_mode_det(aud_mode);
-#endif
-
-       if (is_meson_txlx_cpu() || is_meson_txhd_cpu())
-               set_outputmode(aud_std, aud_mode);
-
-       if (atvdemod_non_std_en)
-               atv_dmd_non_std_set(true);
-}
-
-static void aml_atvdemod_timer_handler(unsigned long arg)
-{
-       struct dvb_frontend *fe = (struct dvb_frontend *)arg;
-       struct atv_demod_priv *priv = fe->analog_demod_priv;
-
-       /* 100ms timer */
-       priv->demod_timer.data = arg;
-       priv->demod_timer.expires = jiffies + ATVDEMOD_INTERVAL * 10;
-       add_timer(&priv->demod_timer);
-
-       if (atvdemod_timer_en == 0)
-               return;
-
-       if (vdac_enable_check_dtv())
-               return;
-
-       schedule_work(&priv->demod_wq);
-}
-
-static void aml_demod_timer_enable(struct dvb_frontend *fe)
-{
-       struct atv_demod_priv *priv = fe->analog_demod_priv;
-
-       if (atvdemod_timer_en && (demod_timer_init_state == 0)) {
-               init_timer(&priv->demod_timer);
-               priv->demod_timer.data = (ulong) fe;
-               priv->demod_timer.function = aml_atvdemod_timer_handler;
-               /* after 1s enable demod auto detect */
-               priv->demod_timer.expires = jiffies + ATVDEMOD_INTERVAL * 100;
-               add_timer(&priv->demod_timer);
-               demod_timer_init_state = 1;
-       }
-}
-
-static void aml_demod_timer_disable(struct dvb_frontend *fe)
-{
-       struct atv_demod_priv *priv = fe->analog_demod_priv;
-
-       if (atvdemod_timer_en && (demod_timer_init_state == 1)) {
-               del_timer_sync(&priv->demod_timer);
-               cancel_work_sync(&priv->demod_wq);
-               demod_timer_init_state = 0;
-       }
-}
-
 
 /*
  * add interface for audio driver to get atv audio state.
@@ -397,10 +55,17 @@ void aml_fe_get_atvaudio_state(int *state)
        int power = 0;
        int vpll_lock = 0;
        int line_lock = 0;
-       int atv_state = atv_demod_get_state();
+       struct atv_demod_priv *priv = amlatvdemod_devp != NULL
+                       ? amlatvdemod_devp->v4l2_fe.fe.analog_demod_priv : NULL;
+
+       if (priv == NULL) {
+               pr_err("priv == NULL\n");
+               *state = 0;
+               return;
+       }
 
        /* scan mode need mute */
-       if (atv_state == ATVDEMOD_STATE_WORK && !atv_demod_get_scan_mode()) {
+       if (priv->state == ATVDEMOD_STATE_WORK && !priv->scanning) {
                retrieve_vpll_carrier_lock(&vpll_lock);
                retrieve_vpll_carrier_line_lock(&line_lock);
                if ((vpll_lock == 0) && (line_lock == 0)) {
@@ -414,7 +79,7 @@ void aml_fe_get_atvaudio_state(int *state)
        } else {
                *state = 0;
                pr_audio("%s, atv is not work, atv_state: %d.\n",
-                               __func__, atv_state);
+                               __func__, priv->state);
        }
 
        /* If the atv signal is locked, it means there is audio data,
@@ -435,44 +100,10 @@ int aml_atvdemod_get_btsc_sap_mode(void)
        return btsc_sap_mode;
 }
 
-int is_atvdemod_work(void)
-{
-       int ret = 0;
-
-       if (atv_demod_get_state() == ATVDEMOD_STATE_WORK)
-               ret = 1;
-
-       return ret;
-}
-
-static int atv_demod_get_scan_mode(void)
-{
-       return atvdemod_scan_mode;
-}
-
-static void atv_demod_set_scan_mode(int val)
-{
-       atvdemod_scan_mode = val;
-}
-
-int atv_demod_get_state(void)
-{
-       return atvdemod_state;
-}
-
-static void atv_demod_set_state(int state)
-{
-       atvdemod_state = state;
-}
-
 int atv_demod_enter_mode(struct dvb_frontend *fe)
 {
        int err_code = 0;
 
-#if 0
-       if (atv_demod_get_state() == ATVDEMOD_STATE_WORK)
-               return 0;
-#endif
        if (amlatvdemod_devp->pin_name != NULL) {
                amlatvdemod_devp->agc_pin =
                        devm_pinctrl_get_select(amlatvdemod_devp->dev,
@@ -505,8 +136,6 @@ int atv_demod_enter_mode(struct dvb_frontend *fe)
        amlatvdemod_devp->audmode = 0;
        amlatvdemod_devp->soundsys = 0xFF;
 
-       atv_demod_set_state(ATVDEMOD_STATE_WORK);
-
        pr_info("%s: OK.\n", __func__);
 
        return 0;
@@ -514,11 +143,13 @@ int atv_demod_enter_mode(struct dvb_frontend *fe)
 
 int atv_demod_leave_mode(struct dvb_frontend *fe)
 {
-       if (atv_demod_get_state() == ATVDEMOD_STATE_IDEL)
-               return 0;
+       struct atv_demod_priv *priv = fe->analog_demod_priv;
+
+       if (priv->afc.disable)
+               priv->afc.disable(&priv->afc);
 
-       aml_demod_timer_disable(fe);
-       aml_afc_timer_disable(fe);
+       if (priv->monitor.disable)
+               priv->monitor.disable(&priv->monitor);
 
        atvdemod_uninit();
        if (!IS_ERR_OR_NULL(amlatvdemod_devp->agc_pin)) {
@@ -534,7 +165,8 @@ int atv_demod_leave_mode(struct dvb_frontend *fe)
        amlatvdemod_devp->std = 0;
        amlatvdemod_devp->audmode = 0;
        amlatvdemod_devp->soundsys = 0xFF;
-       atv_demod_set_state(ATVDEMOD_STATE_IDEL);
+
+       priv->state = ATVDEMOD_STATE_IDEL;
 
        pr_info("%s: OK.\n", __func__);
 
@@ -557,8 +189,11 @@ static void atv_demod_set_params(struct dvb_frontend *fe,
        p->param.std = params->std;
 
        /* afc tune disable,must cancel wq before set tuner freq*/
-       aml_afc_timer_disable(fe);
-       aml_demod_timer_disable(fe);
+       if (priv->afc.disable)
+               priv->afc.disable(&priv->afc);
+
+       if (priv->monitor.disable)
+               priv->monitor.disable(&priv->monitor);
 
        if (fe->ops.tuner_ops.set_analog_params)
                ret = fe->ops.tuner_ops.set_analog_params(fe, params);
@@ -589,16 +224,19 @@ static void atv_demod_set_params(struct dvb_frontend *fe,
        } else
                atv_dmd_soft_reset();
 
-       if (!atv_demod_get_scan_mode())
+       if (!priv->scanning)
                atvauddemod_init();
 
        /* afc tune enable */
        /* analog_search_flag == 0 or afc_range != 0 means searching */
        if ((fe->ops.info.type == FE_ANALOG)
-                       && (atv_demod_get_scan_mode() == 0)
+                       && (priv->scanning == false)
                        && (p->param.mode == 0)) {
-               aml_afc_timer_enable(fe);
-               aml_demod_timer_enable(fe);
+               if (priv->afc.enable)
+                       priv->afc.enable(&priv->afc);
+
+               if (priv->monitor.enable)
+                       priv->monitor.enable(&priv->monitor);
        }
 }
 
@@ -627,9 +265,11 @@ static int atv_demod_has_signal(struct dvb_frontend *fe, u16 *signal)
 
 static void atv_demod_standby(struct dvb_frontend *fe)
 {
-       if (atv_demod_get_state() != ATVDEMOD_STATE_IDEL) {
+       struct atv_demod_priv *priv = fe->analog_demod_priv;
+
+       if (priv->state != ATVDEMOD_STATE_IDEL) {
                atv_demod_leave_mode(fe);
-               atv_demod_set_state(ATVDEMOD_STATE_SLEEP);
+               priv->state = ATVDEMOD_STATE_SLEEP;
        }
 
        pr_info("%s: OK.\n", __func__);
@@ -652,10 +292,10 @@ static void atv_demod_release(struct dvb_frontend *fe)
        int instance = 0;
        struct atv_demod_priv *priv = fe->analog_demod_priv;
 
-       atv_demod_leave_mode(fe);
-
        mutex_lock(&atv_demod_list_mutex);
 
+       atv_demod_leave_mode(fe);
+
        if (priv)
                instance = hybrid_tuner_release_state(priv);
 
@@ -670,6 +310,7 @@ static void atv_demod_release(struct dvb_frontend *fe)
 static int atv_demod_set_config(struct dvb_frontend *fe, void *priv_cfg)
 {
        int *state = (int *) priv_cfg;
+       struct atv_demod_priv *priv = fe->analog_demod_priv;
 
        if (!state) {
                pr_err("%s: state == NULL.\n", __func__);
@@ -680,15 +321,16 @@ static int atv_demod_set_config(struct dvb_frontend *fe, void *priv_cfg)
 
        switch (*state) {
        case AML_ATVDEMOD_INIT:
-               if (atv_demod_get_state() != ATVDEMOD_STATE_WORK) {
+               if (priv->state != ATVDEMOD_STATE_WORK) {
                        if (fe->ops.tuner_ops.set_config)
                                fe->ops.tuner_ops.set_config(fe, NULL);
                        atv_demod_enter_mode(fe);
+                       priv->state = ATVDEMOD_STATE_WORK;
                }
                break;
 
        case AML_ATVDEMOD_UNINIT:
-               if (atv_demod_get_state() != ATVDEMOD_STATE_IDEL) {
+               if (priv->state != ATVDEMOD_STATE_IDEL) {
                        atv_demod_leave_mode(fe);
                        if (fe->ops.tuner_ops.release)
                                fe->ops.tuner_ops.release(fe);
@@ -696,23 +338,28 @@ static int atv_demod_set_config(struct dvb_frontend *fe, void *priv_cfg)
                break;
 
        case AML_ATVDEMOD_RESUME:
-               if (atv_demod_get_state() == ATVDEMOD_STATE_SLEEP) {
+               if (priv->state == ATVDEMOD_STATE_SLEEP) {
                        atv_demod_enter_mode(fe);
-                       if (fe->ops.tuner_ops.resume)
-                               fe->ops.tuner_ops.resume(fe);
+                       priv->state = ATVDEMOD_STATE_WORK;
                }
                break;
 
        case AML_ATVDEMOD_SCAN_MODE:
-               atv_demod_set_scan_mode(1);
-               aml_afc_timer_disable(fe);
-               aml_demod_timer_disable(fe);
+               priv->scanning = true;
+               if (priv->afc.disable)
+                       priv->afc.disable(&priv->afc);
+
+               if (priv->monitor.disable)
+                       priv->monitor.disable(&priv->monitor);
                break;
 
        case AML_ATVDEMOD_UNSCAN_MODE:
-               atv_demod_set_scan_mode(0);
-               aml_afc_timer_enable(fe);
-               aml_demod_timer_enable(fe);
+               priv->scanning = false;
+               if (priv->afc.enable)
+                       priv->afc.enable(&priv->afc);
+
+               if (priv->monitor.enable)
+                       priv->monitor.enable(&priv->monitor);
                break;
        }
 
@@ -1125,12 +772,6 @@ static int atvdemod_fe_set_property(struct v4l2_frontend *v4l2_fe,
                if (amlatvdemod_devp->soundsys != 0xFF)
                        aud_mode = amlatvdemod_devp->soundsys;
                priv->sound_sys.output_mode = tvp->data & 0xFF;
-#if 0
-               if (atv_demod_get_state() == ATVDEMOD_STATE_WORK) {
-                       if (is_meson_txlx_cpu() || is_meson_txhd_cpu())
-                               atvauddemod_set_outputmode();
-               }
-#endif
                break;
 
        case V4L2_SLOW_SEARCH_MODE:
@@ -1175,6 +816,7 @@ static enum v4l2_search atvdemod_fe_search(struct v4l2_frontend *v4l2_fe)
 {
        struct analog_parameters params;
        struct dvb_frontend *fe = &v4l2_fe->fe;
+       struct atv_demod_priv *priv = NULL;
        struct v4l2_analog_parameters *p = &v4l2_fe->params;
        enum v4l2_status tuner_state = V4L2_TIMEDOUT;
        enum v4l2_status ade_state = V4L2_TIMEDOUT;
@@ -1203,6 +845,12 @@ static enum v4l2_search atvdemod_fe_search(struct v4l2_frontend *v4l2_fe)
                return V4L2_SEARCH_INVALID;
        }
 
+       priv = fe->analog_demod_priv;
+       if (priv->state != ATVDEMOD_STATE_WORK) {
+               pr_err("[%s] ATV state is not work.\n", __func__);
+               return V4L2_SEARCH_INVALID;
+       }
+
        if (p->afc_range == 0) {
                pr_err("[%s] afc_range == 0, skip the search\n", __func__);
                return V4L2_SEARCH_INVALID;
@@ -1472,11 +1120,17 @@ struct dvb_frontend *aml_atvdemod_attach(struct dvb_frontend *fe,
                mutex_unlock(&atv_demod_list_mutex);
                return NULL;
        case 1:
-               INIT_WORK(&priv->afc_wq, aml_afc_do_work);
-               INIT_WORK(&priv->demod_wq, aml_atvdemod_do_work);
                fe->analog_demod_priv = priv;
+
+               priv->afc.fe = fe;
+               atv_demod_afc_init(&priv->afc);
+
+               priv->monitor.fe = fe;
+               atv_demod_monitor_init(&priv->monitor);
+
                priv->standby = true;
-               pr_info("aml_atvdemod found\n");
+
+               pr_info("%s: aml_atvdemod found.\n", __func__);
                break;
        default:
                fe->analog_demod_priv = priv;
index 45a9897..d6a091e 100644 (file)
@@ -1,14 +1,18 @@
 /*
- * amlogic atv demod driver
+ * drivers/amlogic/atv_demod/atv_demod_ops.h
  *
- * Author: nengwen.chen <nengwen.chen@amlogic.com>
+ * 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.
  *
- * Copyright (C) 2018 Amlogic Inc.
+ * 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.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
  */
 
 #ifndef __ATV_DEMOD_OPS_H__
@@ -18,6 +22,8 @@
 #include "drivers/media/tuners/tuner-i2c.h"
 
 #include "atv_demod_driver.h"
+#include "atv_demod_afc.h"
+#include "atv_demod_monitor.h"
 
 
 #define AML_ATVDEMOD_UNINIT         0x0
 #define AML_ATVDEMOD_SCAN_MODE      0x3
 #define AML_ATVDEMOD_UNSCAN_MODE    0x4
 
+#define ATVDEMOD_STATE_IDEL  0
+#define ATVDEMOD_STATE_WORK  1
+#define ATVDEMOD_STATE_SLEEP 2
+
 #define AFC_BEST_LOCK    50
 #define ATV_AFC_500KHZ   500000
 #define ATV_AFC_1_0MHZ   1000000
@@ -50,11 +60,12 @@ struct atv_demod_priv {
        struct aml_atvdemod_parameters atvdemod_param;
        struct atv_demod_sound_system sound_sys;
 
-       struct work_struct afc_wq;
-       struct timer_list afc_timer;
+       struct atv_demod_afc afc;
+
+       struct atv_demod_monitor monitor;
 
-       struct work_struct demod_wq;
-       struct timer_list demod_timer;
+       int state;
+       bool scanning;
 };
 
 
index 7274ab7..76413a9 100644 (file)
@@ -1,14 +1,18 @@
 /*
- * amlogic atv demod driver
+ * drivers/amlogic/atv_demod/atv_demod_v4l2.c
  *
- * Author: nengwen.chen <nengwen.chen@amlogic.com>
+ * 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.
  *
- * Copyright (C) 2018 Amlogic Inc.
+ * 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.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
  */
 
 #include <linux/fs.h>
@@ -966,6 +970,12 @@ void v4l2_frontend_detach(struct v4l2_frontend *v4l2_fe)
                v4l2_fe->fe.ops.release(&v4l2_fe->fe);
 }
 
+int v4l2_frontend_shutdown(struct v4l2_frontend *v4l2_fe)
+{
+       pr_info("%s: OK.\n", __func__);
+       return 0;
+}
+
 int v4l2_frontend_suspend(struct v4l2_frontend *v4l2_fe)
 {
        int ret = 0;
@@ -993,12 +1003,14 @@ int v4l2_frontend_resume(struct v4l2_frontend *v4l2_fe)
        struct analog_demod_ops analog_ops = fe->ops.analog_ops;
        int priv_cfg = AML_ATVDEMOD_RESUME;
 
+       fepriv->exit = V4L2_FE_DEVICE_RESUME;
        if (analog_ops.set_config)
                analog_ops.set_config(fe, &priv_cfg);
 
        if (tuner_ops.resume)
                tuner_ops.resume(fe);
 
+       fepriv->exit = V4L2_FE_NO_EXIT;
        fepriv->state = V4L2FE_STATE_RETUNE;
        v4l2_frontend_wakeup(v4l2_fe);
 
index 0f61126..0b2c9cd 100644 (file)
@@ -1,14 +1,18 @@
 /*
- * amlogic atv demod driver
+ * drivers/amlogic/atv_demod/atv_demod_v4l2.h
  *
- * Author: nengwen.chen <nengwen.chen@amlogic.com>
+ * 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.
  *
- * Copyright (C) 2018 Amlogic Inc.
+ * 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.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
  */
 
 #ifndef __ATV_DEMOD_V4L2_H__
@@ -50,6 +54,7 @@
 #define V4L2_FE_NO_EXIT 0
 #define V4L2_FE_NORMAL_EXIT 1
 #define V4L2_FE_DEVICE_REMOVED 2
+#define V4L2_FE_DEVICE_RESUME 3
 
 #define V4L2FE_STATE_IDLE 1
 #define V4L2FE_STATE_RETUNE 2
@@ -221,6 +226,7 @@ int v4l2_resister_frontend(struct v4l2_frontend *v4l2_fe);
 int v4l2_unresister_frontend(struct v4l2_frontend *v4l2_fe);
 
 void v4l2_frontend_detach(struct v4l2_frontend *v4l2_fe);
+int v4l2_frontend_shutdown(struct v4l2_frontend *v4l2_fe);
 int v4l2_frontend_suspend(struct v4l2_frontend *v4l2_fe);
 int v4l2_frontend_resume(struct v4l2_frontend *v4l2_fe);
 
index 7c0b58b..b787edc 100644 (file)
@@ -1,3 +1,20 @@
+/*
+ * drivers/amlogic/atv_demod/atvauddemod_func.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.
+ *
+ */
+
 #ifndef __ATVAUDDEMOD_FUN_H
 #define __ATVAUDDEMOD_FUN_H
 
@@ -14,6 +31,7 @@
 #include "aud_demod_settings.c"
 #include "atvdemod_func.h"
 #include "atv_demod_driver.h"
+#include "atv_demod_access.h"
 
 /* #define AUDIO_MOD_DET_INTERNAL */
 
@@ -101,51 +119,6 @@ static int thd_flag;
 static uint32_t thd_tmp_v;
 static uint8_t thd_cnt;
 
-static inline uint32_t R_AUDDEMOD_REG(uint32_t reg)
-{
-       unsigned int val;
-
-       atvaudiodem_reg_read(reg<<2, &val);
-       return val;
-}
-
-static inline void W_AUDDEMOD_REG(uint32_t reg,
-                                const uint32_t val)
-{
-       atvaudiodem_reg_write(reg<<2, val);
-}
-
-static inline void W_AUDDEMOD_BIT(uint32_t reg,
-                                   const uint32_t value,
-                                   const uint32_t start,
-                                   const uint32_t len)
-{
-       W_AUDDEMOD_REG(reg, ((R_AUDDEMOD_REG(reg) &
-                            ~(((1L << (len)) - 1) << (start))) |
-                           (((value) & ((1L << (len)) - 1)) << (start))));
-}
-
-static inline uint32_t R_AUDDEMOD_BIT(uint32_t reg,
-                                   const uint32_t start,
-                                   const uint32_t len)
-{
-       uint32_t val;
-
-       val = ((R_AUDDEMOD_REG(reg) >> (start)) & ((1L << (len)) - 1));
-
-       return val;
-}
-
-void adec_wr_reg(uint32_t reg, uint32_t val)
-{
-       atvaudiodem_reg_write(reg<<2, val);
-}
-
-uint32_t adec_rd_reg(uint32_t addr)
-{
-       return R_AUDDEMOD_REG(addr);
-}
-
 
 void set_filter(int *filter, int start_addr, int taps)
 {
@@ -1378,79 +1351,6 @@ void audio_thd_det(void)
        }
 }
 
-void audio_mode_det(int mode)
-{
-       if (is_atvdemod_work() &&
-                       (is_meson_txlx_cpu() || is_meson_txhd_cpu())) {
-               uint32_t reg_value;
-               uint32_t tmp_value, tmp_value1;
-               int stereo_flag, sap_flag;
-               static int last_stereo_flag = -1, last_sap_flag = -1;
-
-               reg_value = adec_rd_reg(AUDIO_MODE_REPORT);
-               stereo_flag = reg_value&0x1;
-               sap_flag = (reg_value>>1)&0x1;
-               reg_value = adec_rd_reg(ADDR_ADEC_CTRL);
-
-               if (sap_flag != last_sap_flag
-                       || stereo_flag != last_stereo_flag) {
-                       switch (mode) {
-                       case AUDIO_OUTMODE_BTSC_MONO:
-                               tmp_value = (reg_value & 0xf)|(0 << 4);
-                               adec_wr_reg(ADDR_ADEC_CTRL, tmp_value);
-                               break;
-
-                       case AUDIO_OUTMODE_BTSC_STEREO:
-                               if (stereo_flag) {
-                                       tmp_value = (reg_value & 0xf)|(1 << 4);
-                                       adec_wr_reg(ADDR_ADEC_CTRL, tmp_value);
-
-                                       reg_value =
-                                               adec_rd_reg(ADDR_LPR_COMP_CTRL);
-                                       tmp_value1 = (reg_value & 0xffff);
-                                       adec_wr_reg(ADDR_LPR_COMP_CTRL,
-                                               tmp_value1);
-                               } else {
-                                       tmp_value = (reg_value & 0xf)|(0 << 4);
-                                       adec_wr_reg(ADDR_ADEC_CTRL, tmp_value);
-                               }
-                               break;
-
-                       case AUDIO_OUTMODE_BTSC_SAP:
-                               if (sap_flag) {
-                                       tmp_value = (reg_value & 0xf)|(6 << 4);
-                                       adec_wr_reg(ADDR_ADEC_CTRL, tmp_value);
-
-                                       reg_value =
-                                               adec_rd_reg(ADDR_LPR_COMP_CTRL);
-                                       tmp_value1 =
-                                               (reg_value & 0xffff)|(1 << 16);
-                                       adec_wr_reg(ADDR_LPR_COMP_CTRL,
-                                               tmp_value1);
-                               } else if (stereo_flag) {
-                                       tmp_value = (reg_value & 0xf)|(1 << 4);
-                                       adec_wr_reg(ADDR_ADEC_CTRL, tmp_value);
-
-                                       reg_value =
-                                               adec_rd_reg(ADDR_LPR_COMP_CTRL);
-                                       tmp_value1 = (reg_value & 0xffff);
-                                       adec_wr_reg(ADDR_LPR_COMP_CTRL,
-                                               tmp_value1);
-                               } else {
-                                       tmp_value = (reg_value & 0xf)|(0 << 4);
-                                       adec_wr_reg(ADDR_ADEC_CTRL, tmp_value);
-                               }
-                               break;
-                       }
-               }
-
-               last_stereo_flag = stereo_flag;
-               last_sap_flag = sap_flag;
-
-               pr_info("atvdemod_monitor_audio done ....\n");
-       }
-}
-
 void set_output_left_right_exchange(unsigned int ch)
 {
        unsigned int read = 0;
index 497a81b..fcdb246 100644 (file)
@@ -1,4 +1,20 @@
-/* atvauddemod_func.h */
+/*
+ * drivers/amlogic/atv_demod/atvauddemod_func.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.
+ *
+ */
+
 #ifndef __ATVAUDDEMOD_H_
 #define __ATVAUDDEMOD_H_
 
@@ -6,14 +22,9 @@
 
 extern unsigned int signal_audmode;
 
-extern int atvaudiodem_reg_read(unsigned int reg, unsigned int *val);
-extern int atvaudiodem_reg_write(unsigned int reg, unsigned int val);
 extern uint32_t adec_rd_reg(uint32_t addr);
 extern void adec_wr_reg(uint32_t reg, uint32_t val);
-extern int atv_demod_get_state(void);
-extern int is_atvdemod_work(void);
 extern int aml_atvdemod_get_btsc_sap_mode(void);
-extern void audio_mode_det(int mode);
 
 void set_outputmode(uint32_t standard, uint32_t outmode);
 void aud_demod_clk_gate(int on);
index b05a588..11ec350 100644 (file)
@@ -1,14 +1,18 @@
 /*
- * Silicon labs amlogic Atvdemod Device Driver
+ * drivers/amlogic/atv_demod/atvdemod_func.c
  *
- * Author: dezhi kong <dezhi.kong@amlogic.com>
+ * 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.
  *
- * Copyright (C) 2014 Amlogic Inc.
+ * 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.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
  */
 
 /* Standard Liniux Headers */
@@ -30,6 +34,7 @@
 #include "atvauddemod_func.h"
 #include "atv_demod_ops.h"
 #include "atv_demod_driver.h"
+#include "atv_demod_access.h"
 
 unsigned int broad_std = AML_ATV_DEMOD_VIDEO_MODE_PROP_NTSC;
 unsigned int aud_std = AUDIO_STANDARD_NICAM_DK;
@@ -41,6 +46,7 @@ unsigned long input_amplitude = 0xffff;
 unsigned int non_std_en;
 
 unsigned int non_std_times = 50;
+unsigned int non_check_delay_times = 50;
 int non_std_thld_4c_h = 100;
 int non_std_thld_4c_l = 30;
 int non_std_thld_54_h = 500;
@@ -53,7 +59,6 @@ int sum2_thd_l = 0x7fffffff;
 unsigned int atv_video_gain;
 unsigned int carrier_amplif_val = 0xc030901;
 unsigned int extra_input_fil_val = 0x1030501;
-unsigned int audio_det_mode = AUDIO_AUTO_DETECT;
 bool aud_dmd_jilinTV;
 unsigned int if_freq = 4250000;        /*PAL-DK:3250000;NTSC-M:4250000*/
 unsigned int if_inv;
@@ -86,7 +91,6 @@ unsigned int atvdemod_afc_range = 5;
 unsigned int atvdemod_afc_offset = 500;
 
 unsigned int pwm_kp = 0x19;
-unsigned int reg_dbg_en;
 unsigned int audio_gain_val = 512;
 unsigned int audio_a2_threshold = 0x800;
 unsigned int audio_a2_delay = 10;
@@ -105,169 +109,15 @@ static int snr_val;
 int broad_std_except_pal_m;
 
 
-int get_atvdemod_snr_val(void)
+int atvdemod_get_snr_val(void)
 {
        return snr_val;
 }
-//EXPORT_SYMBOL(get_atvdemod_snr_val);
 
 void amlatvdemod_set_std(int val)
 {
        broad_std = val;
 }
-//EXPORT_SYMBOL(amlatvdemod_set_std);
-
-void atv_dmd_wr_reg(unsigned char block, unsigned char reg, unsigned long data)
-{
-       /* unsigned long data_tmp; */
-       unsigned long reg_addr = (block<<8) + reg * 4;
-
-       amlatvdemod_reg_write(reg_addr, data);
-}
-
-unsigned long atv_dmd_rd_reg(unsigned char block, unsigned char reg)
-{
-       unsigned long data = 0;
-       unsigned int reg_addr = (block<<8) + reg * 4;
-
-       amlatvdemod_reg_read(reg_addr, (unsigned int *)&data);
-       return data;
-}
-
-unsigned long atv_dmd_rd_byte(unsigned long block_addr, unsigned long reg_addr)
-{
-       unsigned long data;
-
-       data = atv_dmd_rd_long(block_addr, reg_addr);
-       /*R_APB_REG((((block_addr & 0xff) <<6) + */
-       /* ((reg_addr & 0xff) >>2)) << 2);*/
-       /*((volatile unsigned long *) (ATV_DMD_APB_BASE_ADDR+*/
-       /*((((block_addr & 0xff) <<6) + ((reg_addr & 0xff) >>2)) << 2)));*/
-       if ((reg_addr & 0x3) == 0)
-               data = data >> 24;
-       else if ((reg_addr & 0x3) == 1)
-               data = (data >> 16 & 0xff);
-       else if ((reg_addr & 0x3) == 2)
-               data = (data >> 8 & 0xff);
-       else if ((reg_addr & 0x3) == 3)
-               data = (data >> 0 & 0xff);
-       return data;
-}
-
-unsigned long atv_dmd_rd_word(unsigned long block_addr, unsigned long reg_addr)
-{
-       unsigned long data;
-
-       data = atv_dmd_rd_long(block_addr, reg_addr);
-       /*R_APB_REG((((block_addr & 0xff) <<6) + */
-       /*((reg_addr & 0xff) >>2)) << 2);*/
-       /*((volatile unsigned long *) (ATV_DMD_APB_BASE_ADDR+*/
-       /*((((block_addr & 0xff) <<6) + ((reg_addr & 0xff) >>2)) << 2)));*/
-       if ((reg_addr & 0x3) == 0)
-               data = data >> 16;
-       else if ((reg_addr & 0x3) == 1)
-               data = (data >> 8 & 0xffff);
-       else if ((reg_addr & 0x3) == 2)
-               data = (data >> 0 & 0xffff);
-       else if ((reg_addr & 0x3) == 3)
-               data = (((data & 0xff) << 8) | ((data >> 24) & 0xff));
-       return data;
-}
-
-unsigned long atv_dmd_rd_long(unsigned long block_addr, unsigned long reg_addr)
-{
-       unsigned long data;
-       /*data = *((volatile unsigned long *) (ATV_DMD_APB_BASE_ADDR+*/
-       /*((((block_addr & 0xff) <<6) + ((reg_addr & 0xff) >>2)) << 2)));*/
-       data =
-           R_ATVDEMOD_REG((((block_addr & 0xff) << 6) +
-           ((reg_addr & 0xff) >> 2)) << 2);
-
-       return data;
-}
-//EXPORT_SYMBOL(atv_dmd_rd_long);
-
-void atv_dmd_wr_long(unsigned long block_addr, unsigned long reg_addr,
-                    unsigned long data)
-{
-       W_ATVDEMOD_REG((((block_addr & 0xff) << 6) +
-               ((reg_addr & 0xff) >> 2)) << 2, data);
-       if (reg_dbg_en)
-               pr_dbg("block_addr:0x%x,reg_addr:0x%x;data:0x%x\n",
-               (unsigned int)block_addr, (unsigned int)reg_addr,
-               (unsigned int)data);
-       /**((volatile unsigned long *)*/
-       /*(ATV_DMD_APB_BASE_ADDR+((((block_addr & 0xff) << 6) +*/
-       /*((reg_addr & 0xff) >> 2)) << 2))) = data;*/
-
-}
-//EXPORT_SYMBOL(atv_dmd_wr_long);
-
-void atv_dmd_wr_word(unsigned long block_addr, unsigned long reg_addr,
-                    unsigned long data)
-{
-       unsigned long data_tmp;
-
-       data_tmp = atv_dmd_rd_long(block_addr, reg_addr);
-       data = data & 0xffff;
-       if ((reg_addr & 0x3) == 0)
-               data = (data << 16 | (data_tmp & 0xffff));
-       else if ((reg_addr & 0x3) == 1)
-               data =
-                   ((data_tmp & 0xff000000) | (data << 8) | (data_tmp & 0xff));
-       else if ((reg_addr & 0x3) == 2)
-               data = (data | (data_tmp & 0xffff0000));
-       else if ((reg_addr & 0x3) == 3)
-               data =
-                   (((data & 0xff) << 24) | ((data_tmp & 0xffff0000) >> 8) |
-                    ((data & 0xff00) >> 8));
-
-       /**((volatile unsigned long *) (ATV_DMD_APB_BASE_ADDR+*/
-       /*((((block_addr & 0xff) <<6) + */
-       /*((reg_addr & 0xff) >>2)) << 2))) = data;*/
-       atv_dmd_wr_long(block_addr, reg_addr, data);
-       /*W_ATVDEMOD_REG(((((block_addr & 0xff) <<6) +*/
-       /*((reg_addr & 0xff) >>2)) << 2), data);*/
-
-}
-
-void atv_dmd_wr_byte(unsigned long block_addr, unsigned long reg_addr,
-                    unsigned long data)
-{
-       unsigned long data_tmp;
-
-       data_tmp = atv_dmd_rd_long(block_addr, reg_addr);
-
-       /*pr_info("atv demod wr byte, read block addr %lx\n",block_addr);*/
-       /*pr_info("atv demod wr byte, read reg addr %lx\n", reg_addr);*/
-       /*pr_info("atv demod wr byte, wr data %lx\n",data);*/
-       /*pr_info("atv demod wr byte, read data out %lx\n",data_tmp);*/
-
-       data = data & 0xff;
-       /*pr_info("atv demod wr byte, data & 0xff %lx\n",data);*/
-       if ((reg_addr & 0x3) == 0) {
-               data = (data << 24 | (data_tmp & 0xffffff));
-               /*pr_info("atv demod wr byte, reg_addr & 0x3 == 0,*/
-               /*wr data %lx\n",data);*/
-       } else if ((reg_addr & 0x3) == 1)
-               data =
-                   ((data_tmp & 0xff000000) | (data << 16) |
-                    (data_tmp & 0xffff));
-       else if ((reg_addr & 0x3) == 2)
-               data =
-                   ((data_tmp & 0xffff0000) | (data << 8) | (data_tmp & 0xff));
-       else if ((reg_addr & 0x3) == 3)
-               data = ((data_tmp & 0xffffff00) | (data & 0xff));
-
-       /*pr_info("atv demod wr byte, wr data %lx\n",data);*/
-
-       /**((volatile unsigned long *) (ATV_DMD_APB_BASE_ADDR+*/
-       /*((((block_addr & 0xff) <<6) + */
-       /*((reg_addr & 0xff) >>2)) << 2))) = data;*/
-       atv_dmd_wr_long(block_addr, reg_addr, data);
-       /*W_ATVDEMOD_REG(((((block_addr & 0xff) <<6) +*/
-       /*((reg_addr & 0xff) >>2)) << 2), data);*/
-}
 
 void set_audio_gain_val(int val)
 {
@@ -304,8 +154,8 @@ void read_version_register(void)
 
        pr_info("atv demod read version register data out %lx\n", data);
 
-       if ((data != 0x516EAB13)
-           || (((Byte1 << 24) | (Byte2 << 16) | Word) != 0x516EAB13))
+       if ((data != 0x516EAB13) || (((Byte1 << 24) | (Byte2 << 16) | Word)
+                       != 0x516EAB13))
                pr_info("atv demod read version reg failed\n");
 }
 
@@ -432,6 +282,7 @@ void atv_dmd_non_std_set(bool enable)
        static int sum2;
        static unsigned char delay_times;
        static bool has_entry;
+       static unsigned char non_std_counter;
 
        int vpll_lock = 0;
        int line_lock = 0;
@@ -448,6 +299,7 @@ void atv_dmd_non_std_set(bool enable)
                sum2 = 0;
                delay_times = 0;
                has_entry = false;
+               non_std_counter = 0;
 
                return;
        }
@@ -472,13 +324,28 @@ void atv_dmd_non_std_set(bool enable)
                times = 0;
                sum1 = 0;
                sum2 = 0;
+               non_std_counter = 0;
 
                return;
        }
 
-       /* delay 5s entry checking */
-       if (delay_times++ <= 50 && !has_entry)
+       /* delay total 5s = 100ms (timer) * non_check_delay_times (times). */
+       if (delay_times++ <= non_check_delay_times && !has_entry) {
+               /* reset non std params */
+               vdagc1_d1 = 0;
+               vdagc2_d1 = 0;
+
+               vdagc1_max = 0;
+               vdagc1_min = 0xffff;
+               vdagc2_max = -0x7fff;
+               vdagc2_min = 0x7fff;
+               times = 0;
+               sum1 = 0;
+               sum2 = 0;
+               non_std_counter = 0;
+
                return;
+       }
 
        delay_times = 0;
        has_entry = true;
@@ -513,10 +380,18 @@ void atv_dmd_non_std_set(bool enable)
                        vdagc2_diff > non_std_thld_54_h &&
                        sum1 > sum1_thd_h &&
                        sum2 > sum2_thd_h)) {
-                       atv_dmd_wr_long(0x09, 0x00, 0x2030503);
-                       atv_dmd_wr_long(0x0f, 0x44, 0x4d0808c1);
-                       atv_dmd_wr_long(APB_BLOCK_ADDR_CARR_RCVY,
-                                       0x24, 0x0c010801);
+
+                       non_std_counter++;
+                       if (non_std_counter == 2) {
+                               atv_dmd_wr_long(0x09, 0x00, 0x2030503);
+                               atv_dmd_wr_long(0x0f, 0x44, 0x4d0808c1);
+                               atv_dmd_wr_long(APB_BLOCK_ADDR_CARR_RCVY,
+                                               0x24, 0x0c010801);
+
+                               non_std_counter = 0;
+
+                               pr_info("===> atv entry non std setting\n");
+                       }
                } else if (vdagc1_diff < non_std_thld_4c_l &&
                                vdagc2_diff < non_std_thld_54_l &&
                                sum1 < sum1_thd_l &&
@@ -528,6 +403,10 @@ void atv_dmd_non_std_set(bool enable)
                                atv_dmd_wr_long(0x0f, 0x44, 0xfc0808c1);
                        atv_dmd_wr_long(APB_BLOCK_ADDR_CARR_RCVY, 0x24,
                                carrier_amplif_val);
+
+                       non_std_counter = 0;
+
+                       pr_info("===> atv exit non std setting\n");
                }
 
                times = 0;
@@ -1484,7 +1363,7 @@ void retrieve_fh_frequency(int *fh)
        *fh = data1 + data2;
 }
 /*tune mix to adapt afc*/
-void atvdemod_afc_tune(void)
+void atvdemod_mixer_tune(void)
 {
        /* int adc_level,lock,freq_offset,fh; */
        int freq_offset, lock, mix1_freq_cur, delta_mix1_freq;
@@ -1520,67 +1399,10 @@ void atvdemod_afc_tune(void)
        /* pr_info("horizontal frequency:%d Hz\n",fh*190735/100000); */
 }
 
-/* ret:5~100;the val is bigger,the signal is better */
-int aml_atvdemod_get_snr(struct dvb_frontend *fe)
-{
-#if 1
-       return get_atvdemod_snr_val();
-#else
-       unsigned int snr_val;
-       int ret;
-
-       snr_val = atv_dmd_rd_long(APB_BLOCK_ADDR_VDAGC, 0x50) >> 8;
-       /* snr_val:900000~0xffffff,ret:5~15 */
-       if (snr_val > 900000)
-               ret = 15 - (snr_val - 900000)*10/(0xffffff - 900000);
-       /* snr_val:158000~900000,ret:15~30 */
-       else if (snr_val > 158000)
-               ret = 30 - (snr_val - 158000)*15/(900000 - 158000);
-       /* snr_val:31600~158000,ret:30~50 */
-       else if (snr_val > 31600)
-               ret = 50 - (snr_val - 31600)*20/(158000 - 31600);
-       /* snr_val:316~31600,ret:50~80 */
-       else if (snr_val > 316)
-               ret = 80 - (snr_val - 316)*30/(31600 - 316);
-       /* snr_val:0~316,ret:80~100 */
-       else
-               ret = 100 - (316 - snr_val)*20/316;
-       return ret;
-#endif
-}
-
-int aml_atvdemod_get_snr_ex(void)
-{
-#if 1
-       return get_atvdemod_snr_val();
-#else
-       unsigned int snr_val;
-       int ret;
-
-       snr_val = atv_dmd_rd_long(APB_BLOCK_ADDR_VDAGC, 0x50) >> 8;
-       /* snr_val:900000~0xffffff,ret:5~15 */
-       if (snr_val > 900000)
-               ret = 15 - (snr_val - 900000)*10/(0xffffff - 900000);
-       /* snr_val:158000~900000,ret:15~30 */
-       else if (snr_val > 158000)
-               ret = 30 - (snr_val - 158000)*15/(900000 - 158000);
-       /* snr_val:31600~158000,ret:30~50 */
-       else if (snr_val > 31600)
-               ret = 50 - (snr_val - 31600)*20/(158000 - 31600);
-       /* snr_val:316~31600,ret:50~80 */
-       else if (snr_val > 316)
-               ret = 80 - (snr_val - 316)*30/(31600 - 316);
-       /* snr_val:0~316,ret:80~100 */
-       else
-               ret = 100 - (316 - snr_val)*20/316;
-       return ret;
-#endif
-}
-
-static enum amlatvdemod_snr_level_e aml_atvdemod_get_snr_level(void)
+static enum atvdemod_snr_level_e atvdemod_get_snr_level(void)
 {
        unsigned int snr_val = 0, i = 0, snr_d[8] = { 0 };
-       enum amlatvdemod_snr_level_e ret = very_low;
+       enum atvdemod_snr_level_e ret = very_low;
        unsigned long fsnr = 0;
 
        snr_val = atv_dmd_rd_long(APB_BLOCK_ADDR_VDAGC, 0x50) >> 8;
@@ -1604,13 +1426,13 @@ static enum amlatvdemod_snr_level_e aml_atvdemod_get_snr_level(void)
        return ret;
 }
 
-void atvdemod_monitor_serice(void)
+void atvdemod_video_overmodulated(void)
 {
-       enum amlatvdemod_snr_level_e snr_level;
+       enum atvdemod_snr_level_e snr_level;
        unsigned int vagc_bw_typ, vagc_bw_fast, vpll_kptrack, vpll_kitrack;
        unsigned int agc_register, vfmat_reg, agc_pll_kptrack, agc_pll_kitrack;
        /*1.get current snr*/
-       snr_level = aml_atvdemod_get_snr_level();
+       snr_level = atvdemod_get_snr_level();
        /*2.*/
        if (snr_level > very_low) {
                vagc_bw_typ = 0x1818;
@@ -1668,17 +1490,17 @@ void atvdemod_monitor_serice(void)
                                        0x6);
                        else
                                atv_dmd_wr_byte(APB_BLOCK_ADDR_VFORMAT, 0xe,
-                                       0x6);
+                                       0xe);
                }
        } else {
                if (atv_dmd_rd_byte(APB_BLOCK_ADDR_VFORMAT, 0xe) == 0x0f)
                        atv_dmd_wr_byte(APB_BLOCK_ADDR_VFORMAT, 0xe, 0xe);
                else
-                       atv_dmd_wr_byte(APB_BLOCK_ADDR_VFORMAT, 0xe, 0xe);
+                       atv_dmd_wr_byte(APB_BLOCK_ADDR_VFORMAT, 0xe, 0x6);
        }
 }
 
-static int atvdemod_get_snr(struct dvb_frontend *fe)
+static int atvdemod_get_snr(void)
 {
        unsigned int snr_val = 0;
        int ret = 0;
@@ -1704,7 +1526,7 @@ static int atvdemod_get_snr(struct dvb_frontend *fe)
 
 void atvdemod_det_snr_serice(void)
 {
-       snr_val = atvdemod_get_snr(NULL);
+       snr_val = atvdemod_get_snr();
 }
 
 int atvdemod_clk_init(void)
@@ -2360,112 +2182,6 @@ unsigned int aml_audio_valume_gain_get(void)
        return audio_gain_data;
 }
 
-void aml_atvdemod_overmodule_det(void)
-{
-       unsigned long temp_data, temp_data2;/* , temp_data3, temp_data4; */
-       unsigned long counter_report;
-       int carrier_lock_count = 0;
-       int vlock = 0;
-
-       switch (audio_det_mode) {
-       case AUDIO_AUTO_DETECT:
-               aml_audiomode_autodet(NULL);
-               return;
-#if 0
-               while (1) {
-                       retrieve_vpll_carrier_lock(&vlock);
-                       if (vlock)
-                               break;
-                       carrier_lock_count++;
-                       if (carrier_lock_count >= 1000)
-                               return;
-       /* ------------whether need timer delays between the detect lock---- */
-               }
-       /* -----------------enable auto_adjust_en------------- */
-               temp_data = atv_dmd_rd_word(APB_BLOCK_ADDR_SIF_STG_2, 0x02);
-               temp_data = temp_data | 0x100;
-               /* set the bit 9 of the temp_data to 1 */
-               atv_dmd_wr_word(APB_BLOCK_ADDR_SIF_STG_2, 0x02, temp_data);
-       /* -----------------enable auto_adjust_en end----------------- */
-       /* -----------------begain to set ov_cnt_en enable------------- */
-               temp_data2 = atv_dmd_rd_word(APB_BLOCK_ADDR_SIF_STG_2, 0x02);
-               temp_data2 = temp_data2 | 0x80;
-               /* set the bit 8 of the temp_data to 1 */
-               atv_dmd_wr_word(APB_BLOCK_ADDR_SIF_STG_2, 0x02, temp_data2);
-       /* ------------------set ov_cnt_en enable end---------------- */
-               udelay(1000);/* timer delay needed , */
-       /* ------------------------------------------------------------ */
-               /* -----------------disable auto_adjust_en------------- */
-               temp_data3 = atv_dmd_rd_word(APB_BLOCK_ADDR_SIF_STG_2, 0x02);
-               temp_data3 = temp_data3 & 0xfeff;
-               /* set the bit 9 of the temp_data to 0 */
-               atv_dmd_wr_word(APB_BLOCK_ADDR_SIF_STG_2, 0x02, temp_data3);
-       /* -----------------disable auto_adjust_en end------------ */
-       /* -----------------begain to set ov_cnt_en disable------------- */
-               temp_data4 = atv_dmd_rd_word(APB_BLOCK_ADDR_SIF_STG_2, 0x02);
-               temp_data4 = temp_data4 & 0xff7f;
-               /* set the bit 8 of the temp_data to 0 */
-               atv_dmd_wr_word(APB_BLOCK_ADDR_SIF_STG_2, 0x02, temp_data4);
-               break;
-       /* ------------------set ov_cnt_en disable end------ */
-#endif
-       case AUDIO_MANUAL_DETECT:
-               while (1) {
-                       retrieve_vpll_carrier_lock(&vlock);
-                       if (vlock)
-                               break;
-                       carrier_lock_count++;
-                       if (carrier_lock_count >= 1000)
-                               return;
-               }
-
-               /* -----------------begain to set ov_cnt_en enable---- */
-               temp_data = atv_dmd_rd_word(APB_BLOCK_ADDR_SIF_STG_2, 0x02);
-               temp_data = temp_data | 0x80;
-               /* set the bit 8 of the temp_data to 1 */
-               atv_dmd_wr_word(APB_BLOCK_ADDR_SIF_STG_2, 0x02, temp_data);
-       /* ------------------set ov_cnt_en enable end--------------- */
-       /* -----------------disable auto_adjust_en------------- */
-               temp_data2 = atv_dmd_rd_word(APB_BLOCK_ADDR_SIF_STG_2, 0x02);
-               temp_data2 = temp_data2 & 0xfeff;
-               /* set the bit 9 of the temp_data to 0 */
-               atv_dmd_wr_word(APB_BLOCK_ADDR_SIF_STG_2, 0x02, temp_data2);
-       /* -----------------disable auto_adjust_en end------------ */
-                       udelay(1000);/* timer delay needed , */
-       /* ------------------------------------------------------- */
-               counter_report =
-                       atv_dmd_rd_word(APB_BLOCK_ADDR_SIF_STG_2, 0x04);
-
-               while (counter_report > over_threshold) {
-
-                       unsigned long shift_gain, shift_gain_report;
-
-                       temp_data2 = atv_dmd_rd_byte(
-                               APB_BLOCK_ADDR_SIF_STG_2, 0x00);
-                       shift_gain = temp_data2 & 0x07;
-                       shift_gain--;
-                       temp_data2 = (temp_data2 & 0xf8) | shift_gain;
-                       atv_dmd_wr_byte(APB_BLOCK_ADDR_SIF_STG_2, 0x00,
-                                       temp_data2);
-                       shift_gain_report = (
-                       (atv_dmd_rd_long(APB_BLOCK_ADDR_SIF_STG_2, 0x04)
-                                               & 0x00070000) >> 16);
-
-                       if (shift_gain_report != shift_gain)
-                               pr_info("[atvdemo...]:set shift_gain error\n");
-                       /* ------------------timer delay needed- */
-                       udelay(1000);/* timer delay needed , */
-                       /* ----------------------- */
-                       counter_report =
-                       atv_dmd_rd_word(APB_BLOCK_ADDR_SIF_STG_2, 0x04);
-               }
-               break;
-       default:
-               pr_info("invalid over_module_det mode!!!\n");
-               break;
-       }
-}
-
 void aml_fix_PWM_adjust(int enable)
 {
        unsigned long  temp_data;
@@ -2532,113 +2248,3 @@ void aml_audio_overmodulation(int enable)
                }
        }
 }
-
-int amlatvdemod_reg_read(unsigned int reg, unsigned int *val)
-{
-       int ret = 0;
-
-       if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) {
-               amlatvdemod_hiu_reg_read(HHI_GCLK_MPEG0, &ret);
-               if (0 == ((1<<29) & ret)) {
-                       pr_err("%s GCLK_MPEG0:0x%x\n", __func__, ret);
-                       return 0;
-               }
-       } else if (0 == (ADC_EN_ATV_DEMOD & tvafe_adc_get_pll_flag())) {
-               /* pr_dbg("%s atv demod pll not init\n", __func__); */
-               return 0;
-       }
-
-       *val = readl(amlatvdemod_devp->demod_reg_base + reg);
-       return 0;
-}
-
-int amlatvdemod_reg_write(unsigned int reg, unsigned int val)
-{
-       int ret = 0;
-
-       if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) {
-               amlatvdemod_hiu_reg_read(HHI_GCLK_MPEG0, &ret);
-               if (0 == ((1<<29) & ret)) {
-                       pr_err("%s GCLK_MPEG0:0x%x\n", __func__, ret);
-                       return 0;
-               }
-       } else if (0 == (ADC_EN_ATV_DEMOD & tvafe_adc_get_pll_flag())) {
-               /* pr_dbg("%s atv demod pll not init\n", __func__); */
-               return 0;
-       }
-
-       writel(val, (amlatvdemod_devp->demod_reg_base + reg));
-       return 0;
-}
-
-int atvaudiodem_reg_read(unsigned int reg, unsigned int *val)
-{
-       int ret = 0;
-
-       if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) {
-               amlatvdemod_hiu_reg_read(HHI_GCLK_MPEG0, &ret);
-               if (0 == ((1<<31) & ret)) {
-                       pr_err("%s GCLK_MPEG0:0x%x\n", __func__, ret);
-                       return 0;
-               }
-       }
-
-       if (amlatvdemod_devp->audio_reg_base)
-               *val = readl(amlatvdemod_devp->audio_reg_base + reg);
-
-       return 0;
-}
-
-int atvaudiodem_reg_write(unsigned int reg, unsigned int val)
-{
-       int ret = 0;
-
-       if (is_meson_txlx_cpu() || is_meson_txhd_cpu()) {
-               amlatvdemod_hiu_reg_read(HHI_GCLK_MPEG0, &ret);
-               if (0 == ((1<<31) & ret)) {
-                       pr_err("%s GCLK_MPEG0:0x%x\n", __func__, ret);
-                       return 0;
-               }
-       }
-
-       if (amlatvdemod_devp->audio_reg_base)
-               writel(val, (amlatvdemod_devp->audio_reg_base + reg));
-
-       return 0;
-}
-
-int amlatvdemod_hiu_reg_read(unsigned int reg, unsigned int *val)
-{
-       if (amlatvdemod_devp->hiu_reg_base)
-               *val = readl(amlatvdemod_devp->hiu_reg_base +
-                               ((reg - 0x1000) << 2));
-
-       return 0;
-}
-
-int amlatvdemod_hiu_reg_write(unsigned int reg, unsigned int val)
-{
-       if (amlatvdemod_devp->hiu_reg_base)
-               writel(val, (amlatvdemod_devp->hiu_reg_base +
-                               ((reg - 0x1000) << 2)));
-
-       return 0;
-}
-
-int amlatvdemod_periphs_reg_read(unsigned int reg, unsigned int *val)
-{
-       if (amlatvdemod_devp->periphs_reg_base)
-               *val = readl(amlatvdemod_devp->periphs_reg_base +
-                               ((reg - 0x1000) << 2));
-
-       return 0;
-}
-
-int amlatvdemod_periphs_reg_write(unsigned int reg, unsigned int val)
-{
-       if (amlatvdemod_devp->periphs_reg_base)
-               writel(val, (amlatvdemod_devp->periphs_reg_base +
-                               ((reg - 0x1000) << 2)));
-
-       return 0;
-}
index de5cde4..a2e3ac2 100644 (file)
@@ -1,30 +1,25 @@
 /*
- * ATVDEMOD Device Driver
+ * drivers/amlogic/atv_demod/atvdemod_func.h
  *
- * Author: dezhi kong <dezhi.kong@amlogic.com>
+ * 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.
  *
- * Copyright (C) 2014 Amlogic Inc.
+ * 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.
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
  */
 
-#ifndef __ATVDEMOD_FUN_H
-#define __ATVDEMOD_FUN_H
-
-/*#include "../aml_fe.h"*/
-/*#include <linux/amlogic/tvin/tvin.h>*/
-/*#include "../aml_fe.h"*/
-#include <linux/amlogic/iomap.h>
+#ifndef __ATV_DEMOD_FUNC_H__
+#define __ATV_DEMOD_FUNC_H__
 
 struct dvb_frontend;
 
-/*#define TVFE_APB_BASE_ADDR 0xd0046000*/
-#define ATV_DMD_APB_BASE_ADDR 0xc8008000
-#define ATV_DMD_APB_BASE_ADDR_GXTVBB 0xc8840000
-
 #define HHI_ATV_DMD_SYS_CLK_CNTL               0x10f3
 
 extern unsigned int reg_23cf; /* IIR filter */
@@ -33,81 +28,6 @@ extern unsigned int aud_std;
 extern unsigned int aud_mode;
 extern bool audio_thd_en;
 
-extern int amlatvdemod_reg_read(unsigned int reg, unsigned int *val);
-extern int amlatvdemod_reg_write(unsigned int reg, 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);
-
-static inline uint32_t R_ATVDEMOD_REG(uint32_t reg)
-{
-       unsigned int val;
-
-       amlatvdemod_reg_read(reg, &val);
-       return val;
-}
-
-static inline void W_ATVDEMOD_REG(uint32_t reg,
-                                const uint32_t val)
-{
-       amlatvdemod_reg_write(reg, val);
-}
-
-static inline void W_ATVDEMOD_BIT(uint32_t reg,
-                                   const uint32_t value,
-                                   const uint32_t start,
-                                   const uint32_t len)
-{
-       W_ATVDEMOD_REG(reg, ((R_ATVDEMOD_REG(reg) &
-                            ~(((1L << (len)) - 1) << (start))) |
-                           (((value) & ((1L << (len)) - 1)) << (start))));
-}
-
-static inline uint32_t R_ATVDEMOD_BIT(uint32_t reg,
-                                   const uint32_t start,
-                                   const uint32_t len)
-{
-       uint32_t val;
-
-       val = ((R_ATVDEMOD_REG(reg) >> (start)) & ((1L << (len)) - 1));
-
-       return val;
-}
-
-static inline uint32_t R_HIU_REG(uint32_t reg)
-{
-       unsigned int val;
-
-       amlatvdemod_hiu_reg_read(reg, &val);
-       return val;
-}
-
-static inline void W_HIU_REG(uint32_t reg,
-                                const uint32_t val)
-{
-       amlatvdemod_hiu_reg_write(reg, val);
-}
-
-static inline void W_HIU_BIT(uint32_t reg,
-                                   const uint32_t value,
-                                   const uint32_t start,
-                                   const uint32_t len)
-{
-       W_HIU_REG(reg, ((R_HIU_REG(reg) &
-                            ~(((1L << (len)) - 1) << (start))) |
-                           (((value) & ((1L << (len)) - 1)) << (start))));
-}
-
-static inline uint32_t R_HIU_BIT(uint32_t reg,
-                                   const uint32_t start,
-                                   const uint32_t len)
-{
-       uint32_t val;
-
-       val = ((R_HIU_REG(reg) >> (start)) & ((1L << (len)) - 1));
-
-       return val;
-}
-
 enum broadcast_standard_e {
        ATVDEMOD_STD_NTSC = 0,
        ATVDEMOD_STD_NTSC_J,
@@ -135,24 +55,7 @@ enum sound_format_e {
        ATVDEMOD_SOUND_STD_NICAM,
        ATVDEMOD_SOUND_STD_MAX,
 };
-extern void atv_dmd_wr_reg(unsigned char block, unsigned char reg,
-       unsigned long data);
-extern unsigned long atv_dmd_rd_reg(unsigned char block, unsigned char reg);
-extern unsigned long atv_dmd_rd_byte(unsigned long block_address,
-                                    unsigned long reg_addr);
-extern unsigned long atv_dmd_rd_word(unsigned long block_address,
-                                    unsigned long reg_addr);
-extern unsigned long atv_dmd_rd_long(unsigned long block_address,
-                                    unsigned long reg_addr);
-extern void atv_dmd_wr_long(unsigned long block_address,
-                               unsigned long reg_addr,
-                               unsigned long data);
-extern void atv_dmd_wr_word(unsigned long block_address,
-                               unsigned long reg_addr,
-                               unsigned long data);
-extern void atv_dmd_wr_byte(unsigned long block_address,
-                               unsigned long reg_addr,
-                               unsigned long data);
+
 extern void set_audio_gain_val(int val);
 extern void set_video_gain_val(int val);
 extern void atv_dmd_soft_reset(void);
@@ -177,11 +80,10 @@ extern void retrieve_video_lock(int *lock);
 extern int retrieve_vpll_carrier_afc(void);
 
 extern void atv_dmd_non_std_set(bool enable);
-extern void atvdemod_monitor_serice(void);
+extern void atvdemod_video_overmodulated(void);
 extern void atvdemod_det_snr_serice(void);
-extern int get_atvdemod_snr_val(void);
-extern int aml_atvdemod_get_snr(struct dvb_frontend *fe);
-extern void atvdemod_afc_tune(void);
+extern int atvdemod_get_snr_val(void);
+extern void atvdemod_mixer_tune(void);
 
 /*atv demod block address*/
 /*address interval is 4, because it's 32bit interface,*/
@@ -283,7 +185,7 @@ extern void atvdemod_afc_tune(void);
 
 #define CARR_AFC_DEFAULT_VAL 0xffff
 
-enum amlatvdemod_snr_level_e {
+enum atvdemod_snr_level_e {
        very_low = 1,
        low,
        ok_minus,
@@ -291,37 +193,19 @@ enum amlatvdemod_snr_level_e {
        high,
 };
 
-enum audio_detect_mode {
-       AUDIO_AUTO_DETECT = 0,
-       AUDIO_MANUAL_DETECT,
-};
-
-#if 0
-struct amlatvdemod_device_s {
-       struct class *clsp;
-       struct device *dev;
-       struct analog_parameters parm;
-       int fre_offset;
-       struct pinctrl *pin;
-       const char *pin_name;
-};
-#endif
-
-extern int amlatvdemod_hiu_reg_read(unsigned int reg, unsigned int *val);
 extern void aml_audio_overmodulation(int enable);
 extern void amlatvdemod_set_std(int val);
 extern void aml_fix_PWM_adjust(int enable);
 extern void aml_audio_valume_gain_set(unsigned int audio_gain);
 extern unsigned int aml_audio_valume_gain_get(void);
-extern void aml_atvdemod_overmodule_det(void);
 extern int aml_audiomode_autodet(struct dvb_frontend *fe);
 extern void retrieve_frequency_offset(int *freq_offset);
 extern void retrieve_field_lock(int *lock);
-extern int aml_atvdemod_get_snr_ex(void);
 extern void set_atvdemod_scan_mode(int val);
 extern int atvauddemod_init(void);
 extern void atvauddemod_set_outputmode(void);
 
 /*from amldemod/amlfrontend.c*/
 extern int vdac_enable_check_dtv(void);
-#endif /* __ATVDEMOD_FUN_H */
+
+#endif /* __ATV_DEMOD_FUNC_H__ */
index 1c22732..cacc8ca 100644 (file)
-#ifndef AUD_DEMOD_REG_H
-
-#define AUD_DEMOD_REG_H
-
-#define ADEC_CTRL                 0x010
-#define FREQ0_CTRL                0x011
-#define FREQ1_CTRL                0x012
-#define ID_FREQ_STEREO_CTRL       0x013
-#define ID_FREQ_DUAL_CTRL         0x014
-#define ID_FREQ_CARRIER_CTRL      0x015
-#define DEMOD_GAIN_CTRL           0x016
-#define BTSC_BYPASS_CTRL          0x017
-#define EXPANDER_SPEC_ADJ         0x018
-#define EXPANDER_GAIN_ADJ         0x019
-#define LMR_GAIN_ADJ              0x01a
-#define SAP_GAIN_ADJ              0x01b
-#define LPR_GAIN_ADJ              0x01c
-#define BTSC_STEREO_THD           0x01d
-#define DELAY_COMP_CRTL           0x01e
-#define EXPANDER_B_CTRL           0x01f
-#define EXPANDER_B2C_ADJ          0x020
-#define TEST_SEL_CTRL             0x021
-#define IIR_SPEED_CTRL            0x022
-#define STEREO_DET_THD            0x023
-#define DUAL_DET_THD              0x024
-#define SAP_DET_THD               0x025
-#define MODE_DET_CNT_THD          0x026
-#define ADEC_RESET                0x027
-
-#define DDC_FIR_COEF0_0           0x030
-#define DDC_FIR_COEF0_1           0x031
-#define DDC_FIR_COEF0_2           0x032
-#define DDC_FIR_COEF0_3           0x033
-#define DDC_FIR_COEF0_4           0x034
-#define DDC_FIR_COEF0_5           0x035
-#define DDC_FIR_COEF0_6           0x036
-#define DDC_FIR_COEF0_7           0x037
-#define DDC_FIR_COEF0_8           0x038
-#define DDC_FIR_COEF0_9           0x039
-#define DDC_FIR_COEF0_10          0x03a
-#define DDC_FIR_COEF0_11          0x03b
-#define DDC_FIR_COEF0_12          0x03c
-#define DDC_FIR_COEF0_13          0x03d
-#define DDC_FIR_COEF0_14          0x03e
-#define DDC_FIR_COEF0_15          0x03f
-#define DDC_FIR_COEF0_16          0x040
-#define DDC_FIR_COEF1_0           0x041
-#define DDC_FIR_COEF1_1           0x042
-#define DDC_FIR_COEF1_2           0x043
-#define DDC_FIR_COEF1_3           0x044
-#define DDC_FIR_COEF1_4           0x045
-#define DDC_FIR_COEF1_5           0x046
-#define DDC_FIR_COEF1_6           0x047
-#define DDC_FIR_COEF1_7           0x048
-#define DDC_FIR_COEF1_8           0x049
-#define DDC_FIR_COEF1_9           0x04a
-#define DDC_FIR_COEF1_10          0x04b
-#define DDC_FIR_COEF1_11          0x04c
-#define DDC_FIR_COEF1_12          0x04d
-#define DDC_FIR_COEF1_13          0x04e
-#define DDC_FIR_COEF1_14          0x04f
-#define DDC_FIR_COEF1_15          0x050
-#define DDC_FIR_COEF1_16          0x051
-#define FILTER_00_0               0x052
-#define FILTER_00_1               0x053
-#define FILTER_00_2               0x054
-#define FILTER_01_0               0x055
-#define FILTER_01_1               0x056
-#define FILTER_01_2               0x057
-#define FILTER_02_0               0x058
-#define FILTER_02_1               0x059
-#define FILTER_02_2               0x05a
-#define FILTER_03_0               0x05b
-#define FILTER_03_1               0x05c
-#define FILTER_03_2               0x05d
-#define FILTER_04_0               0x05e
-#define FILTER_04_1               0x05f
-#define FILTER_04_2               0x060
-#define FILTER_05_0               0x061
-#define FILTER_05_1               0x062
-#define FILTER_05_2               0x063
-#define FILTER_06_0               0x064
-#define FILTER_06_1               0x065
-#define FILTER_06_2               0x066
-#define FILTER_07_0               0x067
-#define FILTER_07_1               0x068
-#define FILTER_07_2               0x069
-#define FILTER_08_0               0x06a
-#define FILTER_08_1               0x06b
-#define FILTER_08_2               0x06c
-#define FILTER_09_0               0x06d
-#define FILTER_09_1               0x06e
-#define FILTER_09_2               0x06f
-#define FILTER_10_0               0x070
-#define FILTER_10_1               0x071
-#define FILTER_10_2               0x072
-#define FILTER_11_0               0x073
-#define FILTER_11_1               0x074
-#define FILTER_11_2               0x075
-#define FILTER_12_0               0x076
-#define FILTER_12_1               0x077
-#define FILTER_12_2               0x078
-#define FILTER_13_0               0x079
-#define FILTER_13_1               0x07a
-#define FILTER_13_2               0x07b
-#define FILTER_14_0               0x07c
-#define FILTER_14_1               0x07d
-#define FILTER_14_2               0x07e
-#define FILTER_15_0               0x07f
-#define FILTER_15_1               0x080
-#define FILTER_15_2               0x081
-
-#define DBX_FILTER_01_0           0x085
-#define DBX_FILTER_01_1           0x086
-#define DBX_FILTER_01_2           0x087
-#define DBX_FILTER_02_0           0x088
-#define DBX_FILTER_02_1           0x089
-#define DBX_FILTER_02_2           0x08a
-#define DBX_FILTER_03_0           0x08b
-#define DBX_FILTER_03_1           0x08c
-#define DBX_FILTER_03_2           0x08d
-#define DBX_FILTER_04_0           0x08e
-#define DBX_FILTER_04_1           0x08f
-#define DBX_FILTER_04_2           0x090
-#define DBX_FILTER_05_0           0x091
-#define DBX_FILTER_05_1           0x092
-#define DBX_FILTER_05_2           0x093
-#define DBX_FILTER_06_0           0x094
-#define DBX_FILTER_06_1           0x095
-#define DBX_FILTER_06_2           0x096
-#define DBX_FILTER_07_0           0x097
-#define DBX_FILTER_07_1           0x098
-#define DBX_FILTER_07_2           0x099
-#define DBX_FILTER_08_0           0x09a
-#define DBX_FILTER_08_1           0x09b
-#define DBX_FILTER_08_2           0x09c
-
-#define BB_COEF0_A_0              0x0a0
-#define BB_COEF0_A_1              0x0a1
-#define BB_COEF0_A_2              0x0a2
-#define BB_COEF0_A_3              0x0a3
-#define BB_COEF1_A_0              0x0a4
-#define BB_COEF1_A_1              0x0a5
-#define BB_COEF1_A_2              0x0a6
-#define BB_COEF1_A_3              0x0a7
-#define BB_COEF2_A_0              0x0a8
-#define BB_COEF2_A_1              0x0a9
-#define BB_COEF2_A_2              0x0aa
-#define BB_COEF2_A_3              0x0ab
-#define BB_COEF0_B_0              0x0ac
-#define BB_COEF0_B_1              0x0ad
-#define BB_COEF0_B_2              0x0ae
-#define BB_COEF0_B_3              0x0af
-#define BB_COEF1_B_0              0x0b0
-#define BB_COEF1_B_1              0x0b1
-#define BB_COEF1_B_2              0x0b2
-#define BB_COEF1_B_3              0x0b3
-#define BB_COEF2_B_0              0x0b4
-#define BB_COEF2_B_1              0x0b5
-#define BB_COEF2_B_2              0x0b6
-#define BB_COEF2_B_3              0x0b7
-#define MUTE_THD0                 0x0b8
-#define MUTE_THD1                 0x0b9
-#define MUTE_THD2                 0x0ba
-#define NOISE_THD0                0x0bb
-#define NOISE_THD1                0x0bc
-#define NOISE_THD2                0x0bd
-#define BB_SPEED                  0x0be
-#define SRC_CTRL0                 0x0c0
-#define SRC_CTRL1                 0x0c1
-#define SRC_CTRL2                 0x0c2
-#define SRC_CTRL3                 0x0c3
-#define SRC_CTRL4                 0x0c4
-#define SRC_CTRL5                 0x0c5
-#define SRC_CTRL6                 0x0c6
-#define SRC_CTRL7                 0x0c7
-#define SRC_CTRL8                 0x0c8
-#define SRC_CTRL9                 0x0c9
-#define THD_P0                    0x0d0
-#define THD_M0                    0x0d1
-#define THD_OV0                   0x0d2
-#define THD_CNT0                  0x0d3
-#define CNT_MAX0                  0x0d4
-#define THD_P1                    0x0d5
-#define THD_M1                    0x0d6
-#define THD_OV1                   0x0d7
-#define THD_CNT1                  0x0d8
-#define CNT_MAX1                  0x0d9
-
-#define OV_CNT_REPORT             0x0da
-#define OV_FLAG_REPORT            0x0db
-
-#define PILOT_BIAS_REPORT         0x0f0
-#define STEREO_LEVEL_REPORT       0x0f1
-#define SNR_REPORT                0x0f2
-#define SNR_SAP_REPORT            0x0f3
-#define POWER_REPORT              0x0f4
-#define DC_REPORT                 0x0f5
-#define CARRIER_MAG_REPORT        0x0f6
-#define BTSC_AB_REPORT            0x0f7
-#define AUDIO_MODE_REPORT         0x0f8
-#define NICAM_LEVEL_REPORT        0x1a3
-#define NICAM_MODE_REPORT         0x1a4
-
-#define CTRL_SEL            0x0ff
-
-#define           FCLK    32e6
-#define    ADDR_ADEC_CTRL             (ADEC_CTRL)
-
-#define    ADDR_BTSC_BYPASS_CTRL     (BTSC_BYPASS_CTRL)
-#define    ADDR_EXPANDER_SPECTRAL_ADJ (EXPANDER_SPEC_ADJ)
-#define    ADDR_EXPANDER_GAIN_ADJ    (EXPANDER_GAIN_ADJ)
-#define    ADDR_LMR_ADJ              (LMR_GAIN_ADJ)
-#define    ADDR_SAP_ADJ              (SAP_GAIN_ADJ)
-#define    ADDR_LPR_GAIN_ADJ         (LPR_GAIN_ADJ)
-#define    ADDR_STEREO_THRESHOLD     (BTSC_STEREO_THD)
-#define    ADDR_LPR_COMP_CTRL        (DELAY_COMP_CRTL)
-#define    ADDR_EXPANDER_B_CTRL      (EXPANDER_B_CTRL)
-#define    ADDR_EXPANDER_B2C_ADJ     (EXPANDER_B2C_ADJ)
-#define    ADDR_TEST_SEL_CTRL        (TEST_SEL_CTRL)
-
-#define    ADDR_SAP_FIR_COEF     (DDC_FIR_COEF1_0)
-
-#define         ADDR_SAP_DTO         (FREQ1_CTRL)
-
-#define         ADDR_DDC_FREQ0         (FREQ0_CTRL)
-#define         ADDR_DDC_FREQ1         (FREQ1_CTRL)
-
-#define                ADDR_DEMOD_GAIN                 (DEMOD_GAIN_CTRL)
-
-
-#define         ADDR_DDC_FIR0_COEF         (DDC_FIR_COEF0_0)
-#define         ADDR_DDC_FIR1_COEF         (DDC_FIR_COEF1_0)
-#define         ADDR_BB_FIR0_A_COEF         (BB_COEF0_A_0)
-#define         ADDR_BB_FIR1_A_COEF         (BB_COEF1_A_0)
-#define         ADDR_BB_FIR2_A_COEF         (BB_COEF2_A_0)
-
-#define         ADDR_BB_FIR0_B_COEF         (BB_COEF0_B_0)
-#define         ADDR_BB_FIR1_B_COEF         (BB_COEF0_B_1)
-#define         ADDR_BB_FIR2_B_COEF         (BB_COEF0_B_2)
-
-#define    ADDR_BB_MUTE_THRESHOLD0   (MUTE_THD0)
-#define    ADDR_BB_MUTE_THRESHOLD1   (MUTE_THD1)
-#define    ADDR_BB_MUTE_THRESHOLD2   (MUTE_THD2)
-
-#define    ADDR_BB_NOISE_THRESHOLD0   (NOISE_THD0)
-#define    ADDR_BB_NOISE_THRESHOLD1   (NOISE_THD1)
-#define    ADDR_BB_NOISE_THRESHOLD2   (NOISE_THD2)
-
-#define         ADDR_INDICATOR_STEREO_DTO  (ID_FREQ_STEREO_CTRL)
-#define  ADDR_INDICATOR_DUAL_DTO       (ID_FREQ_DUAL_CTRL)
-
-#define  ADDR_INDICATOR_CENTER_DTO  (ID_FREQ_CARRIER_CTRL)
-
-#define  ADDR_IIR_LPR_15K_0    (FILTER_00_0)
-#define  ADDR_IIR_LPR_15K_1    (FILTER_01_0)
-#define  ADDR_IIR_LPR_15K_2    (FILTER_02_0)
-#define  ADDR_IIR_LPR_15K_3    (FILTER_03_0)
-#define  ADDR_IIR_LPR_15K_4    (FILTER_04_0)
-
-#define  ADDR_IIR_LMR_15K_0    (FILTER_05_0)
-#define  ADDR_IIR_LMR_15K_1    (FILTER_06_0)
-#define  ADDR_IIR_LMR_15K_2    (FILTER_07_0)
-#define  ADDR_IIR_LMR_15K_3    (FILTER_08_0)
-#define  ADDR_IIR_LMR_15K_4    (FILTER_09_0)
-
-#define  ADDR_IIR_LPR_DEEMPHASIS       (FILTER_10_0)
-#define  ADDR_IIR_PILOT_0      (FILTER_11_0)
-#define  ADDR_IIR_PILOT_1      (FILTER_12_0)
-#define  ADDR_IIR_PILOT_2      (FILTER_13_0)
-#define  ADDR_IIR_LPR_COMP     (FILTER_14_0)
-#define  ADDR_IIR_LMR_DEEMPHASIS       (FILTER_15_0)
-
-#define  ADDR_IIR_FIXED_DEEM_0 (DBX_FILTER_01_0)
-#define  ADDR_IIR_FIXED_DEEM_1 (DBX_FILTER_02_0)
-#define  ADDR_IIR_FIXED_DEEM_2 (DBX_FILTER_03_0)
-
-#define  ADDR_IIR_Q_FILTER_0   (DBX_FILTER_04_0)
-#define  ADDR_IIR_Q_FILTER_1   (DBX_FILTER_05_0)
-#define  ADDR_IIR_Q_FILTER_2   (DBX_FILTER_06_0)
-#define  ADDR_IIR_P_FILTER_0   (DBX_FILTER_07_0)
-#define  ADDR_IIR_P_FILTER_1   (DBX_FILTER_08_0)
-
-#define  ADDR_IIR_SPEED_CTRL    (IIR_SPEED_CTRL)
-#define  ADDR_SEL_CTRL (CTRL_SEL)
-
-
-#define        AUDIO_STANDARD_BTSC                             0x00
-#define        AUDIO_STANDARD_EIAJ                             0x01
-#define        AUDIO_STANDARD_A2_K                             0x02
-#define        AUDIO_STANDARD_A2_BG                    0x03
-#define        AUDIO_STANDARD_A2_DK1                   0x04
-#define        AUDIO_STANDARD_A2_DK2                   0x05
-#define        AUDIO_STANDARD_A2_DK3                   0x06
-#define        AUDIO_STANDARD_NICAM_I                  0x07
-#define AUDIO_STANDARD_NICAM_BG                        0x08
-#define        AUDIO_STANDARD_NICAM_L                  0x09
-#define        AUDIO_STANDARD_NICAM_DK                 0x0A
-#define AUDIO_STANDARD_FM_USA                  0x0B
-#define        AUDIO_STANDARD_FM_EU                    0x0C
-#define AUDIO_STANDARD_CHINA                   0x0E
-#define        AUDIO_STANDARD_INDIAN                   0x0F
-#define        AUDIO_STANDARD_BTSC_SA                  0x10
-#define AUDIO_STANDARD_MONO_ONLY               0x11
-
-#define AUDIO_OUTMODE_MONO 0
-#define AUDIO_OUTMODE_STEREO 1
-#define AUDIO_OUTMODE_SAP_DUAL 2
-
-
-#define AUDIO_OUTMODE_BTSC_MONO 0
-#define AUDIO_OUTMODE_BTSC_STEREO 1
-#define AUDIO_OUTMODE_BTSC_SAP 2
-
-#define AUDIO_OUTMODE_EIAJ_MONO 0
-#define AUDIO_OUTMODE_EIAJ_STEREO 1
-#define AUDIO_OUTMODE_EIAJ_MAIN 2
-#define AUDIO_OUTMODE_EIAJ_SUB 3
+/*
+ * drivers/amlogic/atv_demod/aud_demod_reg.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.
+ *
+ */
+
+#ifndef __AUD_DEMOD_REG_H__
+#define __AUD_DEMOD_REG_H__
+
+#define ADEC_CTRL                  0x010
+#define FREQ0_CTRL                 0x011
+#define FREQ1_CTRL                 0x012
+#define ID_FREQ_STEREO_CTRL        0x013
+#define ID_FREQ_DUAL_CTRL          0x014
+#define ID_FREQ_CARRIER_CTRL       0x015
+#define DEMOD_GAIN_CTRL            0x016
+#define BTSC_BYPASS_CTRL           0x017
+#define EXPANDER_SPEC_ADJ          0x018
+#define EXPANDER_GAIN_ADJ          0x019
+#define LMR_GAIN_ADJ               0x01a
+#define SAP_GAIN_ADJ               0x01b
+#define LPR_GAIN_ADJ               0x01c
+#define BTSC_STEREO_THD            0x01d
+#define DELAY_COMP_CRTL            0x01e
+#define EXPANDER_B_CTRL            0x01f
+#define EXPANDER_B2C_ADJ           0x020
+#define TEST_SEL_CTRL              0x021
+#define IIR_SPEED_CTRL             0x022
+#define STEREO_DET_THD             0x023
+#define DUAL_DET_THD               0x024
+#define SAP_DET_THD                0x025
+#define MODE_DET_CNT_THD           0x026
+#define ADEC_RESET                 0x027
+
+#define DDC_FIR_COEF0_0            0x030
+#define DDC_FIR_COEF0_1            0x031
+#define DDC_FIR_COEF0_2            0x032
+#define DDC_FIR_COEF0_3            0x033
+#define DDC_FIR_COEF0_4            0x034
+#define DDC_FIR_COEF0_5            0x035
+#define DDC_FIR_COEF0_6            0x036
+#define DDC_FIR_COEF0_7            0x037
+#define DDC_FIR_COEF0_8            0x038
+#define DDC_FIR_COEF0_9            0x039
+#define DDC_FIR_COEF0_10           0x03a
+#define DDC_FIR_COEF0_11           0x03b
+#define DDC_FIR_COEF0_12           0x03c
+#define DDC_FIR_COEF0_13           0x03d
+#define DDC_FIR_COEF0_14           0x03e
+#define DDC_FIR_COEF0_15           0x03f
+#define DDC_FIR_COEF0_16           0x040
+#define DDC_FIR_COEF1_0            0x041
+#define DDC_FIR_COEF1_1            0x042
+#define DDC_FIR_COEF1_2            0x043
+#define DDC_FIR_COEF1_3            0x044
+#define DDC_FIR_COEF1_4            0x045
+#define DDC_FIR_COEF1_5            0x046
+#define DDC_FIR_COEF1_6            0x047
+#define DDC_FIR_COEF1_7            0x048
+#define DDC_FIR_COEF1_8            0x049
+#define DDC_FIR_COEF1_9            0x04a
+#define DDC_FIR_COEF1_10           0x04b
+#define DDC_FIR_COEF1_11           0x04c
+#define DDC_FIR_COEF1_12           0x04d
+#define DDC_FIR_COEF1_13           0x04e
+#define DDC_FIR_COEF1_14           0x04f
+#define DDC_FIR_COEF1_15           0x050
+#define DDC_FIR_COEF1_16           0x051
+#define FILTER_00_0                0x052
+#define FILTER_00_1                0x053
+#define FILTER_00_2                0x054
+#define FILTER_01_0                0x055
+#define FILTER_01_1                0x056
+#define FILTER_01_2                0x057
+#define FILTER_02_0                0x058
+#define FILTER_02_1                0x059
+#define FILTER_02_2                0x05a
+#define FILTER_03_0                0x05b
+#define FILTER_03_1                0x05c
+#define FILTER_03_2                0x05d
+#define FILTER_04_0                0x05e
+#define FILTER_04_1                0x05f
+#define FILTER_04_2                0x060
+#define FILTER_05_0                0x061
+#define FILTER_05_1                0x062
+#define FILTER_05_2                0x063
+#define FILTER_06_0                0x064
+#define FILTER_06_1                0x065
+#define FILTER_06_2                0x066
+#define FILTER_07_0                0x067
+#define FILTER_07_1                0x068
+#define FILTER_07_2                0x069
+#define FILTER_08_0                0x06a
+#define FILTER_08_1                0x06b
+#define FILTER_08_2                0x06c
+#define FILTER_09_0                0x06d
+#define FILTER_09_1                0x06e
+#define FILTER_09_2                0x06f
+#define FILTER_10_0                0x070
+#define FILTER_10_1                0x071
+#define FILTER_10_2                0x072
+#define FILTER_11_0                0x073
+#define FILTER_11_1                0x074
+#define FILTER_11_2                0x075
+#define FILTER_12_0                0x076
+#define FILTER_12_1                0x077
+#define FILTER_12_2                0x078
+#define FILTER_13_0                0x079
+#define FILTER_13_1                0x07a
+#define FILTER_13_2                0x07b
+#define FILTER_14_0                0x07c
+#define FILTER_14_1                0x07d
+#define FILTER_14_2                0x07e
+#define FILTER_15_0                0x07f
+#define FILTER_15_1                0x080
+#define FILTER_15_2                0x081
+
+#define DBX_FILTER_01_0            0x085
+#define DBX_FILTER_01_1            0x086
+#define DBX_FILTER_01_2            0x087
+#define DBX_FILTER_02_0            0x088
+#define DBX_FILTER_02_1            0x089
+#define DBX_FILTER_02_2            0x08a
+#define DBX_FILTER_03_0            0x08b
+#define DBX_FILTER_03_1            0x08c
+#define DBX_FILTER_03_2            0x08d
+#define DBX_FILTER_04_0            0x08e
+#define DBX_FILTER_04_1            0x08f
+#define DBX_FILTER_04_2            0x090
+#define DBX_FILTER_05_0            0x091
+#define DBX_FILTER_05_1            0x092
+#define DBX_FILTER_05_2            0x093
+#define DBX_FILTER_06_0            0x094
+#define DBX_FILTER_06_1            0x095
+#define DBX_FILTER_06_2            0x096
+#define DBX_FILTER_07_0            0x097
+#define DBX_FILTER_07_1            0x098
+#define DBX_FILTER_07_2            0x099
+#define DBX_FILTER_08_0            0x09a
+#define DBX_FILTER_08_1            0x09b
+#define DBX_FILTER_08_2            0x09c
+
+#define BB_COEF0_A_0               0x0a0
+#define BB_COEF0_A_1               0x0a1
+#define BB_COEF0_A_2               0x0a2
+#define BB_COEF0_A_3               0x0a3
+#define BB_COEF1_A_0               0x0a4
+#define BB_COEF1_A_1               0x0a5
+#define BB_COEF1_A_2               0x0a6
+#define BB_COEF1_A_3               0x0a7
+#define BB_COEF2_A_0               0x0a8
+#define BB_COEF2_A_1               0x0a9
+#define BB_COEF2_A_2               0x0aa
+#define BB_COEF2_A_3               0x0ab
+#define BB_COEF0_B_0               0x0ac
+#define BB_COEF0_B_1               0x0ad
+#define BB_COEF0_B_2               0x0ae
+#define BB_COEF0_B_3               0x0af
+#define BB_COEF1_B_0               0x0b0
+#define BB_COEF1_B_1               0x0b1
+#define BB_COEF1_B_2               0x0b2
+#define BB_COEF1_B_3               0x0b3
+#define BB_COEF2_B_0               0x0b4
+#define BB_COEF2_B_1               0x0b5
+#define BB_COEF2_B_2               0x0b6
+#define BB_COEF2_B_3               0x0b7
+#define MUTE_THD0                  0x0b8
+#define MUTE_THD1                  0x0b9
+#define MUTE_THD2                  0x0ba
+#define NOISE_THD0                 0x0bb
+#define NOISE_THD1                 0x0bc
+#define NOISE_THD2                 0x0bd
+#define BB_SPEED                   0x0be
+#define SRC_CTRL0                  0x0c0
+#define SRC_CTRL1                  0x0c1
+#define SRC_CTRL2                  0x0c2
+#define SRC_CTRL3                  0x0c3
+#define SRC_CTRL4                  0x0c4
+#define SRC_CTRL5                  0x0c5
+#define SRC_CTRL6                  0x0c6
+#define SRC_CTRL7                  0x0c7
+#define SRC_CTRL8                  0x0c8
+#define SRC_CTRL9                  0x0c9
+#define THD_P0                     0x0d0
+#define THD_M0                     0x0d1
+#define THD_OV0                    0x0d2
+#define THD_CNT0                   0x0d3
+#define CNT_MAX0                   0x0d4
+#define THD_P1                     0x0d5
+#define THD_M1                     0x0d6
+#define THD_OV1                    0x0d7
+#define THD_CNT1                   0x0d8
+#define CNT_MAX1                   0x0d9
+
+#define OV_CNT_REPORT              0x0da
+#define OV_FLAG_REPORT             0x0db
+
+#define PILOT_BIAS_REPORT          0x0f0
+#define STEREO_LEVEL_REPORT        0x0f1
+#define SNR_REPORT                 0x0f2
+#define SNR_SAP_REPORT             0x0f3
+#define POWER_REPORT               0x0f4
+#define DC_REPORT                  0x0f5
+#define CARRIER_MAG_REPORT         0x0f6
+#define BTSC_AB_REPORT             0x0f7
+#define AUDIO_MODE_REPORT          0x0f8
+#define NICAM_LEVEL_REPORT         0x1a3
+#define NICAM_MODE_REPORT          0x1a4
+
+#define CTRL_SEL                   0x0ff
+
+#define FCLK                       32e6
+#define ADDR_ADEC_CTRL             (ADEC_CTRL)
+
+#define ADDR_BTSC_BYPASS_CTRL      (BTSC_BYPASS_CTRL)
+#define ADDR_EXPANDER_SPECTRAL_ADJ (EXPANDER_SPEC_ADJ)
+#define ADDR_EXPANDER_GAIN_ADJ     (EXPANDER_GAIN_ADJ)
+#define ADDR_LMR_ADJ               (LMR_GAIN_ADJ)
+#define ADDR_SAP_ADJ               (SAP_GAIN_ADJ)
+#define ADDR_LPR_GAIN_ADJ          (LPR_GAIN_ADJ)
+#define ADDR_STEREO_THRESHOLD      (BTSC_STEREO_THD)
+#define ADDR_LPR_COMP_CTRL         (DELAY_COMP_CRTL)
+#define ADDR_EXPANDER_B_CTRL       (EXPANDER_B_CTRL)
+#define ADDR_EXPANDER_B2C_ADJ      (EXPANDER_B2C_ADJ)
+#define ADDR_TEST_SEL_CTRL         (TEST_SEL_CTRL)
+
+#define ADDR_SAP_FIR_COEF          (DDC_FIR_COEF1_0)
+
+#define ADDR_SAP_DTO               (FREQ1_CTRL)
+
+#define ADDR_DDC_FREQ0             (FREQ0_CTRL)
+#define ADDR_DDC_FREQ1             (FREQ1_CTRL)
+
+#define ADDR_DEMOD_GAIN            (DEMOD_GAIN_CTRL)
+
+
+#define ADDR_DDC_FIR0_COEF          (DDC_FIR_COEF0_0)
+#define ADDR_DDC_FIR1_COEF          (DDC_FIR_COEF1_0)
+#define ADDR_BB_FIR0_A_COEF         (BB_COEF0_A_0)
+#define ADDR_BB_FIR1_A_COEF         (BB_COEF1_A_0)
+#define ADDR_BB_FIR2_A_COEF         (BB_COEF2_A_0)
+
+#define ADDR_BB_FIR0_B_COEF         (BB_COEF0_B_0)
+#define ADDR_BB_FIR1_B_COEF         (BB_COEF0_B_1)
+#define ADDR_BB_FIR2_B_COEF         (BB_COEF0_B_2)
+
+#define ADDR_BB_MUTE_THRESHOLD0     (MUTE_THD0)
+#define ADDR_BB_MUTE_THRESHOLD1     (MUTE_THD1)
+#define ADDR_BB_MUTE_THRESHOLD2     (MUTE_THD2)
+
+#define ADDR_BB_NOISE_THRESHOLD0    (NOISE_THD0)
+#define ADDR_BB_NOISE_THRESHOLD1    (NOISE_THD1)
+#define ADDR_BB_NOISE_THRESHOLD2    (NOISE_THD2)
+
+#define ADDR_INDICATOR_STEREO_DTO   (ID_FREQ_STEREO_CTRL)
+#define ADDR_INDICATOR_DUAL_DTO     (ID_FREQ_DUAL_CTRL)
+
+#define ADDR_INDICATOR_CENTER_DTO   (ID_FREQ_CARRIER_CTRL)
+
+#define ADDR_IIR_LPR_15K_0          (FILTER_00_0)
+#define ADDR_IIR_LPR_15K_1          (FILTER_01_0)
+#define ADDR_IIR_LPR_15K_2          (FILTER_02_0)
+#define ADDR_IIR_LPR_15K_3          (FILTER_03_0)
+#define ADDR_IIR_LPR_15K_4          (FILTER_04_0)
+
+#define ADDR_IIR_LMR_15K_0          (FILTER_05_0)
+#define ADDR_IIR_LMR_15K_1          (FILTER_06_0)
+#define ADDR_IIR_LMR_15K_2          (FILTER_07_0)
+#define ADDR_IIR_LMR_15K_3          (FILTER_08_0)
+#define ADDR_IIR_LMR_15K_4          (FILTER_09_0)
+
+#define ADDR_IIR_LPR_DEEMPHASIS     (FILTER_10_0)
+#define ADDR_IIR_PILOT_0            (FILTER_11_0)
+#define ADDR_IIR_PILOT_1            (FILTER_12_0)
+#define ADDR_IIR_PILOT_2            (FILTER_13_0)
+#define ADDR_IIR_LPR_COMP           (FILTER_14_0)
+#define ADDR_IIR_LMR_DEEMPHASIS     (FILTER_15_0)
+
+#define ADDR_IIR_FIXED_DEEM_0       (DBX_FILTER_01_0)
+#define ADDR_IIR_FIXED_DEEM_1       (DBX_FILTER_02_0)
+#define ADDR_IIR_FIXED_DEEM_2       (DBX_FILTER_03_0)
+
+#define ADDR_IIR_Q_FILTER_0         (DBX_FILTER_04_0)
+#define ADDR_IIR_Q_FILTER_1         (DBX_FILTER_05_0)
+#define ADDR_IIR_Q_FILTER_2         (DBX_FILTER_06_0)
+#define ADDR_IIR_P_FILTER_0         (DBX_FILTER_07_0)
+#define ADDR_IIR_P_FILTER_1         (DBX_FILTER_08_0)
+
+#define ADDR_IIR_SPEED_CTRL         (IIR_SPEED_CTRL)
+#define ADDR_SEL_CTRL               (CTRL_SEL)
+
+
+#define AUDIO_STANDARD_BTSC         0x00
+#define AUDIO_STANDARD_EIAJ         0x01
+#define AUDIO_STANDARD_A2_K         0x02
+#define AUDIO_STANDARD_A2_BG        0x03
+#define AUDIO_STANDARD_A2_DK1       0x04
+#define AUDIO_STANDARD_A2_DK2       0x05
+#define AUDIO_STANDARD_A2_DK3       0x06
+#define AUDIO_STANDARD_NICAM_I      0x07
+#define AUDIO_STANDARD_NICAM_BG     0x08
+#define AUDIO_STANDARD_NICAM_L      0x09
+#define AUDIO_STANDARD_NICAM_DK     0x0A
+#define AUDIO_STANDARD_FM_USA       0x0B
+#define AUDIO_STANDARD_FM_EU        0x0C
+#define AUDIO_STANDARD_CHINA        0x0E
+#define AUDIO_STANDARD_INDIAN       0x0F
+#define AUDIO_STANDARD_BTSC_SA      0x10
+#define AUDIO_STANDARD_MONO_ONLY    0x11
+
+#define AUDIO_OUTMODE_MONO          0
+#define AUDIO_OUTMODE_STEREO        1
+#define AUDIO_OUTMODE_SAP_DUAL      2
+
+#define AUDIO_OUTMODE_BTSC_MONO     0
+#define AUDIO_OUTMODE_BTSC_STEREO   1
+#define AUDIO_OUTMODE_BTSC_SAP      2
+
+#define AUDIO_OUTMODE_EIAJ_MONO     0
+#define AUDIO_OUTMODE_EIAJ_STEREO   1
+#define AUDIO_OUTMODE_EIAJ_MAIN     2
+#define AUDIO_OUTMODE_EIAJ_SUB      3
 #define AUDIO_OUTMODE_EIAJ_MAIN_SUB 4
 
-#define AUDIO_OUTMODE_A2_MONO 0
-#define AUDIO_OUTMODE_A2_STEREO 1
-#define AUDIO_OUTMODE_A2_DUAL_A 2
-#define AUDIO_OUTMODE_A2_DUAL_B 3
-#define AUDIO_OUTMODE_A2_DUAL_AB 4
-
-#define AUDIO_OUTMODE_NICAM_MONO 0
-#define AUDIO_OUTMODE_NICAM_MONO1 1
-#define AUDIO_OUTMODE_NICAM_STEREO 2
-#define AUDIO_OUTMODE_NICAM_DUAL_A 3
-#define AUDIO_OUTMODE_NICAM_DUAL_B 4
+#define AUDIO_OUTMODE_A2_MONO       0
+#define AUDIO_OUTMODE_A2_STEREO     1
+#define AUDIO_OUTMODE_A2_DUAL_A     2
+#define AUDIO_OUTMODE_A2_DUAL_B     3
+#define AUDIO_OUTMODE_A2_DUAL_AB    4
+
+#define AUDIO_OUTMODE_NICAM_MONO    0
+#define AUDIO_OUTMODE_NICAM_MONO1   1
+#define AUDIO_OUTMODE_NICAM_STEREO  2
+#define AUDIO_OUTMODE_NICAM_DUAL_A  3
+#define AUDIO_OUTMODE_NICAM_DUAL_B  4
 #define AUDIO_OUTMODE_NICAM_DUAL_AB 5
 
-#define AUDIO_DEEM_75US 0
-#define AUDIO_DEEM_50US 1
-#define AUDIO_DEEM_J17  2
+#define AUDIO_DEEM_75US             0
+#define AUDIO_DEEM_50US             1
+#define AUDIO_DEEM_J17              2
 
 
-#endif
+#endif /* __AUD_DEMOD_REG_H__ */
index 7f147c4..0c39285 100644 (file)
@@ -1,3 +1,20 @@
+/*
+ * drivers/amlogic/atv_demod/aud_demod_settings.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 "aud_demod_settings.h"
 
 int M_DTO = 0x170a3d;
index de80ab5..2eaa1cb 100644 (file)
@@ -1,5 +1,22 @@
-#ifndef _Aud_Demod_Settings_h_
-#define _Aud_Demod_Settings_h_
+/*
+ * drivers/amlogic/atv_demod/aud_demod_settings.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.
+ *
+ */
+
+#ifndef __AUD_DEMOD_SETTINGS_H__
+#define __AUD_DEMOD_SETTINGS_H__
 
 extern int M_DTO;
 extern int A2K_DTO;
@@ -165,4 +182,5 @@ extern int filter_sap_12k_4[];
 
 extern int filter_sap_15k_2[];
 extern int filter_sap_15k_4[];
-#endif  /* _Settings_h_ */
+
+#endif /* __AUD_DEMOD_SETTINGS_H__ */