18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci    Auvitek AU8522 QAM/8VSB demodulator driver
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci    Copyright (C) 2008 Steven Toth <stoth@linuxtv.org>
68c2ecf20Sopenharmony_ci    Copyright (C) 2008 Devin Heitmueller <dheitmueller@linuxtv.org>
78c2ecf20Sopenharmony_ci    Copyright (C) 2005-2008 Auvitek International, Ltd.
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci*/
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/kernel.h>
138c2ecf20Sopenharmony_ci#include <linux/init.h>
148c2ecf20Sopenharmony_ci#include <linux/module.h>
158c2ecf20Sopenharmony_ci#include <linux/string.h>
168c2ecf20Sopenharmony_ci#include <linux/slab.h>
178c2ecf20Sopenharmony_ci#include <linux/delay.h>
188c2ecf20Sopenharmony_ci#include <linux/videodev2.h>
198c2ecf20Sopenharmony_ci#include <media/v4l2-device.h>
208c2ecf20Sopenharmony_ci#include <media/v4l2-ctrls.h>
218c2ecf20Sopenharmony_ci#include <media/v4l2-mc.h>
228c2ecf20Sopenharmony_ci#include <linux/i2c.h>
238c2ecf20Sopenharmony_ci#include <media/dvb_frontend.h>
248c2ecf20Sopenharmony_ci#include "au8522.h"
258c2ecf20Sopenharmony_ci#include "tuner-i2c.h"
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define AU8522_ANALOG_MODE 0
288c2ecf20Sopenharmony_ci#define AU8522_DIGITAL_MODE 1
298c2ecf20Sopenharmony_ci#define AU8522_SUSPEND_MODE 2
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cienum au8522_pads {
328c2ecf20Sopenharmony_ci	AU8522_PAD_IF_INPUT,
338c2ecf20Sopenharmony_ci	AU8522_PAD_VID_OUT,
348c2ecf20Sopenharmony_ci	AU8522_PAD_AUDIO_OUT,
358c2ecf20Sopenharmony_ci	AU8522_NUM_PADS
368c2ecf20Sopenharmony_ci};
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistruct au8522_state {
398c2ecf20Sopenharmony_ci	struct i2c_client *c;
408c2ecf20Sopenharmony_ci	struct i2c_adapter *i2c;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	u8 operational_mode;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	/* Used for sharing of the state between analog and digital mode */
458c2ecf20Sopenharmony_ci	struct tuner_i2c_props i2c_props;
468c2ecf20Sopenharmony_ci	struct list_head hybrid_tuner_instance_list;
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	/* configuration settings */
498c2ecf20Sopenharmony_ci	struct au8522_config config;
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	struct dvb_frontend frontend;
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	u32 current_frequency;
548c2ecf20Sopenharmony_ci	enum fe_modulation current_modulation;
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	u32 fe_status;
578c2ecf20Sopenharmony_ci	unsigned int led_state;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	/* Analog settings */
608c2ecf20Sopenharmony_ci	struct v4l2_subdev sd;
618c2ecf20Sopenharmony_ci	v4l2_std_id std;
628c2ecf20Sopenharmony_ci	int vid_input;
638c2ecf20Sopenharmony_ci	int aud_input;
648c2ecf20Sopenharmony_ci	u32 id;
658c2ecf20Sopenharmony_ci	u32 rev;
668c2ecf20Sopenharmony_ci	struct v4l2_ctrl_handler hdl;
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#ifdef CONFIG_MEDIA_CONTROLLER
698c2ecf20Sopenharmony_ci	struct media_pad pads[AU8522_NUM_PADS];
708c2ecf20Sopenharmony_ci#endif
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* These are routines shared by both the VSB/QAM demodulator and the analog
748c2ecf20Sopenharmony_ci   decoder */
758c2ecf20Sopenharmony_ciint au8522_writereg(struct au8522_state *state, u16 reg, u8 data);
768c2ecf20Sopenharmony_ciu8 au8522_readreg(struct au8522_state *state, u16 reg);
778c2ecf20Sopenharmony_ciint au8522_init(struct dvb_frontend *fe);
788c2ecf20Sopenharmony_ciint au8522_sleep(struct dvb_frontend *fe);
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ciint au8522_get_state(struct au8522_state **state, struct i2c_adapter *i2c,
818c2ecf20Sopenharmony_ci		     u8 client_address);
828c2ecf20Sopenharmony_civoid au8522_release_state(struct au8522_state *state);
838c2ecf20Sopenharmony_ciint au8522_i2c_gate_ctrl(struct dvb_frontend *fe, int enable);
848c2ecf20Sopenharmony_ciint au8522_analog_i2c_gate_ctrl(struct dvb_frontend *fe, int enable);
858c2ecf20Sopenharmony_ciint au8522_led_ctrl(struct au8522_state *state, int led);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/* REGISTERS */
888c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H			0x081
898c2ecf20Sopenharmony_ci#define AU8522_PGA_CONTROL_REG082H			0x082
908c2ecf20Sopenharmony_ci#define AU8522_CLAMPING_CONTROL_REG083H			0x083
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H		0x0A3
938c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H		0x0A4
948c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H		0x0A5
958c2ecf20Sopenharmony_ci#define AU8522_AGC_CONTROL_RANGE_REG0A6H		0x0A6
968c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_GAIN_CONTROL_REG0A7H		0x0A7
978c2ecf20Sopenharmony_ci#define AU8522_TUNER_AGC_RF_STOP_REG0A8H		0x0A8
988c2ecf20Sopenharmony_ci#define AU8522_TUNER_AGC_RF_START_REG0A9H		0x0A9
998c2ecf20Sopenharmony_ci#define AU8522_TUNER_RF_AGC_DEFAULT_REG0AAH		0x0AA
1008c2ecf20Sopenharmony_ci#define AU8522_TUNER_AGC_IF_STOP_REG0ABH		0x0AB
1018c2ecf20Sopenharmony_ci#define AU8522_TUNER_AGC_IF_START_REG0ACH		0x0AC
1028c2ecf20Sopenharmony_ci#define AU8522_TUNER_AGC_IF_DEFAULT_REG0ADH		0x0AD
1038c2ecf20Sopenharmony_ci#define AU8522_TUNER_AGC_STEP_REG0AEH			0x0AE
1048c2ecf20Sopenharmony_ci#define AU8522_TUNER_GAIN_STEP_REG0AFH			0x0AF
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/* Receiver registers */
1078c2ecf20Sopenharmony_ci#define AU8522_FRMREGTHRD1_REG0B0H			0x0B0
1088c2ecf20Sopenharmony_ci#define AU8522_FRMREGAGC1H_REG0B1H			0x0B1
1098c2ecf20Sopenharmony_ci#define AU8522_FRMREGSHIFT1_REG0B2H			0x0B2
1108c2ecf20Sopenharmony_ci#define AU8522_TOREGAGC1_REG0B3H			0x0B3
1118c2ecf20Sopenharmony_ci#define AU8522_TOREGASHIFT1_REG0B4H			0x0B4
1128c2ecf20Sopenharmony_ci#define AU8522_FRMREGBBH_REG0B5H			0x0B5
1138c2ecf20Sopenharmony_ci#define AU8522_FRMREGBBM_REG0B6H			0x0B6
1148c2ecf20Sopenharmony_ci#define AU8522_FRMREGBBL_REG0B7H			0x0B7
1158c2ecf20Sopenharmony_ci/* 0xB8 TO 0xD7 are the filter coefficients */
1168c2ecf20Sopenharmony_ci#define AU8522_FRMREGTHRD2_REG0D8H			0x0D8
1178c2ecf20Sopenharmony_ci#define AU8522_FRMREGAGC2H_REG0D9H			0x0D9
1188c2ecf20Sopenharmony_ci#define AU8522_TOREGAGC2_REG0DAH			0x0DA
1198c2ecf20Sopenharmony_ci#define AU8522_TOREGSHIFT2_REG0DBH			0x0DB
1208c2ecf20Sopenharmony_ci#define AU8522_FRMREGPILOTH_REG0DCH			0x0DC
1218c2ecf20Sopenharmony_ci#define AU8522_FRMREGPILOTM_REG0DDH			0x0DD
1228c2ecf20Sopenharmony_ci#define AU8522_FRMREGPILOTL_REG0DEH			0x0DE
1238c2ecf20Sopenharmony_ci#define AU8522_TOREGFREQ_REG0DFH			0x0DF
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci#define AU8522_RX_PGA_RFOUT_REG0EBH			0x0EB
1268c2ecf20Sopenharmony_ci#define AU8522_RX_PGA_IFOUT_REG0ECH			0x0EC
1278c2ecf20Sopenharmony_ci#define AU8522_RX_PGA_PGAOUT_REG0EDH			0x0ED
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci#define AU8522_CHIP_MODE_REG0FEH			0x0FE
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/* I2C bus control registers */
1328c2ecf20Sopenharmony_ci#define AU8522_I2C_CONTROL_REG0_REG090H			0x090
1338c2ecf20Sopenharmony_ci#define AU8522_I2C_CONTROL_REG1_REG091H			0x091
1348c2ecf20Sopenharmony_ci#define AU8522_I2C_STATUS_REG092H			0x092
1358c2ecf20Sopenharmony_ci#define AU8522_I2C_WR_DATA0_REG093H			0x093
1368c2ecf20Sopenharmony_ci#define AU8522_I2C_WR_DATA1_REG094H			0x094
1378c2ecf20Sopenharmony_ci#define AU8522_I2C_WR_DATA2_REG095H			0x095
1388c2ecf20Sopenharmony_ci#define AU8522_I2C_WR_DATA3_REG096H			0x096
1398c2ecf20Sopenharmony_ci#define AU8522_I2C_WR_DATA4_REG097H			0x097
1408c2ecf20Sopenharmony_ci#define AU8522_I2C_WR_DATA5_REG098H			0x098
1418c2ecf20Sopenharmony_ci#define AU8522_I2C_WR_DATA6_REG099H			0x099
1428c2ecf20Sopenharmony_ci#define AU8522_I2C_WR_DATA7_REG09AH			0x09A
1438c2ecf20Sopenharmony_ci#define AU8522_I2C_RD_DATA0_REG09BH			0x09B
1448c2ecf20Sopenharmony_ci#define AU8522_I2C_RD_DATA1_REG09CH			0x09C
1458c2ecf20Sopenharmony_ci#define AU8522_I2C_RD_DATA2_REG09DH			0x09D
1468c2ecf20Sopenharmony_ci#define AU8522_I2C_RD_DATA3_REG09EH			0x09E
1478c2ecf20Sopenharmony_ci#define AU8522_I2C_RD_DATA4_REG09FH			0x09F
1488c2ecf20Sopenharmony_ci#define AU8522_I2C_RD_DATA5_REG0A0H			0x0A0
1498c2ecf20Sopenharmony_ci#define AU8522_I2C_RD_DATA6_REG0A1H			0x0A1
1508c2ecf20Sopenharmony_ci#define AU8522_I2C_RD_DATA7_REG0A2H			0x0A2
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci#define AU8522_ENA_USB_REG101H				0x101
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci#define AU8522_I2S_CTRL_0_REG110H			0x110
1558c2ecf20Sopenharmony_ci#define AU8522_I2S_CTRL_1_REG111H			0x111
1568c2ecf20Sopenharmony_ci#define AU8522_I2S_CTRL_2_REG112H			0x112
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci#define AU8522_FRMREGFFECONTROL_REG121H			0x121
1598c2ecf20Sopenharmony_ci#define AU8522_FRMREGDFECONTROL_REG122H			0x122
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#define AU8522_CARRFREQOFFSET0_REG201H			0x201
1628c2ecf20Sopenharmony_ci#define AU8522_CARRFREQOFFSET1_REG202H			0x202
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci#define AU8522_DECIMATION_GAIN_REG21AH			0x21A
1658c2ecf20Sopenharmony_ci#define AU8522_FRMREGIFSLP_REG21BH			0x21B
1668c2ecf20Sopenharmony_ci#define AU8522_FRMREGTHRDL2_REG21CH			0x21C
1678c2ecf20Sopenharmony_ci#define AU8522_FRMREGSTEP3DB_REG21DH			0x21D
1688c2ecf20Sopenharmony_ci#define AU8522_DAGC_GAIN_ADJUSTMENT_REG21EH		0x21E
1698c2ecf20Sopenharmony_ci#define AU8522_FRMREGPLLMODE_REG21FH			0x21F
1708c2ecf20Sopenharmony_ci#define AU8522_FRMREGCSTHRD_REG220H			0x220
1718c2ecf20Sopenharmony_ci#define AU8522_FRMREGCRLOCKDMAX_REG221H			0x221
1728c2ecf20Sopenharmony_ci#define AU8522_FRMREGCRPERIODMASK_REG222H		0x222
1738c2ecf20Sopenharmony_ci#define AU8522_FRMREGCRLOCK0THH_REG223H			0x223
1748c2ecf20Sopenharmony_ci#define AU8522_FRMREGCRLOCK1THH_REG224H			0x224
1758c2ecf20Sopenharmony_ci#define AU8522_FRMREGCRLOCK0THL_REG225H			0x225
1768c2ecf20Sopenharmony_ci#define AU8522_FRMREGCRLOCK1THL_REG226H			0x226
1778c2ecf20Sopenharmony_ci#define AU_FRMREGPLLACQPHASESCL_REG227H			0x227
1788c2ecf20Sopenharmony_ci#define AU8522_FRMREGFREQFBCTRL_REG228H			0x228
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci/* Analog TV Decoder */
1818c2ecf20Sopenharmony_ci#define AU8522_TVDEC_STATUS_REG000H			0x000
1828c2ecf20Sopenharmony_ci#define AU8522_TVDEC_INT_STATUS_REG001H			0x001
1838c2ecf20Sopenharmony_ci#define AU8522_TVDEC_MACROVISION_STATUS_REG002H		0x002
1848c2ecf20Sopenharmony_ci#define AU8522_TVDEC_SHARPNESSREG009H			0x009
1858c2ecf20Sopenharmony_ci#define AU8522_TVDEC_BRIGHTNESS_REG00AH			0x00A
1868c2ecf20Sopenharmony_ci#define AU8522_TVDEC_CONTRAST_REG00BH			0x00B
1878c2ecf20Sopenharmony_ci#define AU8522_TVDEC_SATURATION_CB_REG00CH		0x00C
1888c2ecf20Sopenharmony_ci#define AU8522_TVDEC_SATURATION_CR_REG00DH		0x00D
1898c2ecf20Sopenharmony_ci#define AU8522_TVDEC_HUE_H_REG00EH			0x00E
1908c2ecf20Sopenharmony_ci#define AU8522_TVDEC_HUE_L_REG00FH			0x00F
1918c2ecf20Sopenharmony_ci#define AU8522_TVDEC_INT_MASK_REG010H			0x010
1928c2ecf20Sopenharmony_ci#define AU8522_VIDEO_MODE_REG011H			0x011
1938c2ecf20Sopenharmony_ci#define AU8522_TVDEC_PGA_REG012H			0x012
1948c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_MODE_REG015H			0x015
1958c2ecf20Sopenharmony_ci#define AU8522_REG016H					0x016
1968c2ecf20Sopenharmony_ci#define AU8522_TVDED_DBG_MODE_REG060H			0x060
1978c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H		0x061
1988c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL2_REG062H		0x062
1998c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VCR_DET_LLIM_REG063H		0x063
2008c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VCR_DET_HLIM_REG064H		0x064
2018c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_VDIF_THR1_REG065H		0x065
2028c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_VDIF_THR2_REG066H		0x066
2038c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_VDIF_THR3_REG067H		0x067
2048c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_NOTCH_THR_REG068H		0x068
2058c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_HDIF_THR1_REG069H		0x069
2068c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_HDIF_THR2_REG06AH		0x06A
2078c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_HDIF_THR3_REG06BH		0x06B
2088c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH		0x06C
2098c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH		0x06D
2108c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH		0x06E
2118c2ecf20Sopenharmony_ci#define AU8522_TVDEC_UV_SEP_THR_REG06FH			0x06F
2128c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H		0x070
2138c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H		0x073
2148c2ecf20Sopenharmony_ci#define AU8522_TVDEC_DCAGC_CTRL_REG077H			0x077
2158c2ecf20Sopenharmony_ci#define AU8522_TVDEC_PIC_START_ADJ_REG078H		0x078
2168c2ecf20Sopenharmony_ci#define AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H		0x079
2178c2ecf20Sopenharmony_ci#define AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH	0x07A
2188c2ecf20Sopenharmony_ci#define AU8522_TVDEC_INTRP_CTRL_REG07BH			0x07B
2198c2ecf20Sopenharmony_ci#define AU8522_TVDEC_PLL_STATUS_REG07EH			0x07E
2208c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FSC_FREQ_REG07FH			0x07F
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci#define AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H		0x0E4
2238c2ecf20Sopenharmony_ci#define AU8522_TOREGAAGC_REG0E5H			0x0E5
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci#define AU8522_TVDEC_CHROMA_AGC_REG401H		0x401
2268c2ecf20Sopenharmony_ci#define AU8522_TVDEC_CHROMA_SFT_REG402H		0x402
2278c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R410			0x410
2288c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R411			0x411
2298c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R412			0x412
2308c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R413			0x413
2318c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R414			0x414
2328c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R415			0x415
2338c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R416			0x416
2348c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R417			0x417
2358c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R418			0x418
2368c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R419			0x419
2378c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R41A			0x41A
2388c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R41B			0x41B
2398c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R41C			0x41C
2408c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R41D			0x41D
2418c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R41E			0x41E
2428c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R41F			0x41F
2438c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R420			0x420
2448c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R421			0x421
2458c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R422			0x422
2468c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R423			0x423
2478c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R424			0x424
2488c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R425			0x425
2498c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R426			0x426
2508c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R427			0x427
2518c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R428			0x428
2528c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R429			0x429
2538c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R42A			0x42A
2548c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R42B			0x42B
2558c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R42C			0x42C
2568c2ecf20Sopenharmony_ci#define AU8522_FILTER_COEF_R42D			0x42D
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci/* VBI Control Registers */
2598c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_RX_FIFO_CONTAIN_REG004H	0x004
2608c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_TX_FIFO_CONTAIN_REG005H	0x005
2618c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_RX_FIFO_READ_REG006H		0x006
2628c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_FIFO_STATUS_REG007H		0x007
2638c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_CTRL_H_REG017H			0x017
2648c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_CTRL_L_REG018H			0x018
2658c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_USER_TOTAL_BITS_REG019H	0x019
2668c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_USER_TUNIT_H_REG01AH		0x01A
2678c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_USER_TUNIT_L_REG01BH		0x01B
2688c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_USER_THRESH1_REG01CH		0x01C
2698c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_USER_FRAME_PAT2_REG01EH	0x01E
2708c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_USER_FRAME_PAT1_REG01FH	0x01F
2718c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_USER_FRAME_PAT0_REG020H	0x020
2728c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_USER_FRAME_MASK2_REG021H	0x021
2738c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_USER_FRAME_MASK1_REG022H	0x022
2748c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_USER_FRAME_MASK0_REG023H	0x023
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci#define AU8522_REG071H					0x071
2778c2ecf20Sopenharmony_ci#define AU8522_REG072H					0x072
2788c2ecf20Sopenharmony_ci#define AU8522_REG074H					0x074
2798c2ecf20Sopenharmony_ci#define AU8522_REG075H					0x075
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci/* Digital Demodulator Registers */
2828c2ecf20Sopenharmony_ci#define AU8522_FRAME_COUNT0_REG084H			0x084
2838c2ecf20Sopenharmony_ci#define AU8522_RS_STATUS_G0_REG085H			0x085
2848c2ecf20Sopenharmony_ci#define AU8522_RS_STATUS_B0_REG086H			0x086
2858c2ecf20Sopenharmony_ci#define AU8522_RS_STATUS_E_REG087H			0x087
2868c2ecf20Sopenharmony_ci#define AU8522_DEMODULATION_STATUS_REG088H		0x088
2878c2ecf20Sopenharmony_ci#define AU8522_TOREGTRESTATUS_REG0E6H			0x0E6
2888c2ecf20Sopenharmony_ci#define AU8522_TSPORT_CONTROL_REG10BH			0x10B
2898c2ecf20Sopenharmony_ci#define AU8522_TSTHES_REG10CH				0x10C
2908c2ecf20Sopenharmony_ci#define AU8522_FRMREGDFEKEEP_REG301H			0x301
2918c2ecf20Sopenharmony_ci#define AU8522_DFE_AVERAGE_REG302H			0x302
2928c2ecf20Sopenharmony_ci#define AU8522_FRMREGEQLERRWIN_REG303H			0x303
2938c2ecf20Sopenharmony_ci#define AU8522_FRMREGFFEKEEP_REG304H			0x304
2948c2ecf20Sopenharmony_ci#define AU8522_FRMREGDFECONTROL1_REG305H		0x305
2958c2ecf20Sopenharmony_ci#define AU8522_FRMREGEQLERRLOW_REG306H			0x306
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci#define AU8522_REG42EH				0x42E
2988c2ecf20Sopenharmony_ci#define AU8522_REG42FH				0x42F
2998c2ecf20Sopenharmony_ci#define AU8522_REG430H				0x430
3008c2ecf20Sopenharmony_ci#define AU8522_REG431H				0x431
3018c2ecf20Sopenharmony_ci#define AU8522_REG432H				0x432
3028c2ecf20Sopenharmony_ci#define AU8522_REG433H				0x433
3038c2ecf20Sopenharmony_ci#define AU8522_REG434H				0x434
3048c2ecf20Sopenharmony_ci#define AU8522_REG435H				0x435
3058c2ecf20Sopenharmony_ci#define AU8522_REG436H				0x436
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci/* GPIO Registers */
3088c2ecf20Sopenharmony_ci#define AU8522_GPIO_CONTROL_REG0E0H			0x0E0
3098c2ecf20Sopenharmony_ci#define AU8522_GPIO_STATUS_REG0E1H			0x0E1
3108c2ecf20Sopenharmony_ci#define AU8522_GPIO_DATA_REG0E2H			0x0E2
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci/* Audio Control Registers */
3138c2ecf20Sopenharmony_ci#define AU8522_AUDIOAGC_REG0EEH				0x0EE
3148c2ecf20Sopenharmony_ci#define AU8522_AUDIO_STATUS_REG0F0H			0x0F0
3158c2ecf20Sopenharmony_ci#define AU8522_AUDIO_MODE_REG0F1H			0x0F1
3168c2ecf20Sopenharmony_ci#define AU8522_AUDIO_VOLUME_L_REG0F2H			0x0F2
3178c2ecf20Sopenharmony_ci#define AU8522_AUDIO_VOLUME_R_REG0F3H			0x0F3
3188c2ecf20Sopenharmony_ci#define AU8522_AUDIO_VOLUME_REG0F4H			0x0F4
3198c2ecf20Sopenharmony_ci#define AU8522_FRMREGAUPHASE_REG0F7H			0x0F7
3208c2ecf20Sopenharmony_ci#define AU8522_REG0F9H					0x0F9
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci#define AU8522_AUDIOAGC2_REG605H			0x605
3238c2ecf20Sopenharmony_ci#define AU8522_AUDIOFREQ_REG606H			0x606
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci/**************************************************************/
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci/* Format control 1 */
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci/* VCR Mode 7-6 */
3318c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_VCR_MODE_YES		0x80
3328c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_VCR_MODE_NO		0x40
3338c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_VCR_MODE_AUTO		0x00
3348c2ecf20Sopenharmony_ci/* Field len 5-4 */
3358c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_FIELD_LEN_625		0x20
3368c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_FIELD_LEN_525		0x10
3378c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_FIELD_LEN_AUTO	0x00
3388c2ecf20Sopenharmony_ci/* Line len (us) 3-2 */
3398c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_LINE_LEN_64_000	0x0b
3408c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_LINE_LEN_63_492	0x08
3418c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_LINE_LEN_63_556	0x04
3428c2ecf20Sopenharmony_ci/* Subcarrier freq 1-0 */
3438c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_AUTO	0x03
3448c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_443	0x02
3458c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_MN	0x01
3468c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_50	0x00
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci/* Format control 2 */
3498c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_AUTODETECT	0x00
3508c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_NTSC		0x01
3518c2ecf20Sopenharmony_ci#define AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_PAL_M		0x02
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H_ATSC			0xC4
3558c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H_ATVRF			0xC4
3568c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H_ATVRF13			0xC4
3578c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H_J83B64			0xC4
3588c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H_J83B256			0xC4
3598c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H_CVBS			0x20
3608c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH1			0xA2
3618c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH2			0xA0
3628c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH3			0x69
3638c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH4			0x68
3648c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF		0x28
3658c2ecf20Sopenharmony_ci/* CH1 AS Y,CH3 AS C */
3668c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13		0x23
3678c2ecf20Sopenharmony_ci/* CH2 AS Y,CH4 AS C */
3688c2ecf20Sopenharmony_ci#define AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24		0x20
3698c2ecf20Sopenharmony_ci#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_ATSC		0x0C
3708c2ecf20Sopenharmony_ci#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_J83B64		0x09
3718c2ecf20Sopenharmony_ci#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_J83B256		0x09
3728c2ecf20Sopenharmony_ci#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS		0x12
3738c2ecf20Sopenharmony_ci#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_ATVRF		0x1A
3748c2ecf20Sopenharmony_ci#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_ATVRF13		0x1A
3758c2ecf20Sopenharmony_ci#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_SVIDEO		0x02
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CLEAR		0x00
3788c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_SVIDEO		0x9C
3798c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS		0x9D
3808c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_ATSC		0xE8
3818c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_J83B256		0xCA
3828c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_J83B64		0xCA
3838c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_ATVRF		0xDD
3848c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_ATVRF13		0xDD
3858c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_PAL		0xDD
3868c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_FM		0xDD
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_ATSC		0x80
3898c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_J83B256		0x80
3908c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_J83B64		0x80
3918c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_ATSC	0x40
3928c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_J83B256	0x40
3938c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_J83B64	0x40
3948c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_CLEAR	0x00
3958c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_ATVRF		0x01
3968c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_ATVRF13		0x01
3978c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_SVIDEO		0x04
3988c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_CVBS		0x01
3998c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_PWM		0x03
4008c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_IIS		0x09
4018c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_PAL		0x01
4028c2ecf20Sopenharmony_ci#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_FM		0x01
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci/* STILL NEED TO BE REFACTORED @@@@@@@@@@@@@@ */
4058c2ecf20Sopenharmony_ci#define AU8522_TVDEC_CONTRAST_REG00BH_CVBS			0x79
4068c2ecf20Sopenharmony_ci#define AU8522_TVDEC_SATURATION_CB_REG00CH_CVBS			0x80
4078c2ecf20Sopenharmony_ci#define AU8522_TVDEC_SATURATION_CR_REG00DH_CVBS			0x80
4088c2ecf20Sopenharmony_ci#define AU8522_TVDEC_HUE_H_REG00EH_CVBS				0x00
4098c2ecf20Sopenharmony_ci#define AU8522_TVDEC_HUE_L_REG00FH_CVBS				0x00
4108c2ecf20Sopenharmony_ci#define AU8522_TVDEC_PGA_REG012H_CVBS				0x0F
4118c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_MODE_REG015H_CVBS			0x00
4128c2ecf20Sopenharmony_ci#define AU8522_REG016H_CVBS					0x00
4138c2ecf20Sopenharmony_ci#define AU8522_TVDED_DBG_MODE_REG060H_CVBS			0x00
4148c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VCR_DET_LLIM_REG063H_CVBS			0x19
4158c2ecf20Sopenharmony_ci#define AU8522_REG0F9H_AUDIO					0x20
4168c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VCR_DET_HLIM_REG064H_CVBS			0xA7
4178c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_VDIF_THR1_REG065H_CVBS		0x0A
4188c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_VDIF_THR2_REG066H_CVBS		0x32
4198c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_VDIF_THR3_REG067H_CVBS		0x19
4208c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_NOTCH_THR_REG068H_CVBS		0x23
4218c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_HDIF_THR1_REG069H_CVBS		0x41
4228c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS		0x0A
4238c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS		0x32
4248c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS		0x34
4258c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_SVIDEO		0x2a
4268c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS		0x05
4278c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_SVIDEO		0x15
4288c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS		0x6E
4298c2ecf20Sopenharmony_ci#define AU8522_TVDEC_UV_SEP_THR_REG06FH_CVBS			0x0F
4308c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H_CVBS		0x80
4318c2ecf20Sopenharmony_ci#define AU8522_REG071H_CVBS					0x18
4328c2ecf20Sopenharmony_ci#define AU8522_REG072H_CVBS					0x30
4338c2ecf20Sopenharmony_ci#define AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H_CVBS		0xF0
4348c2ecf20Sopenharmony_ci#define AU8522_REG074H_CVBS					0x80
4358c2ecf20Sopenharmony_ci#define AU8522_REG075H_CVBS					0xF0
4368c2ecf20Sopenharmony_ci#define AU8522_TVDEC_DCAGC_CTRL_REG077H_CVBS			0xFB
4378c2ecf20Sopenharmony_ci#define AU8522_TVDEC_PIC_START_ADJ_REG078H_CVBS			0x04
4388c2ecf20Sopenharmony_ci#define AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H_CVBS		0x00
4398c2ecf20Sopenharmony_ci#define AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH_CVBS		0x00
4408c2ecf20Sopenharmony_ci#define AU8522_TVDEC_INTRP_CTRL_REG07BH_CVBS			0xEE
4418c2ecf20Sopenharmony_ci#define AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H_CVBS			0xFE
4428c2ecf20Sopenharmony_ci#define AU8522_TOREGAAGC_REG0E5H_CVBS				0x00
4438c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI6A_REG035H_CVBS				0x40
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci/* Enables Closed captioning */
4468c2ecf20Sopenharmony_ci#define AU8522_TVDEC_VBI_CTRL_H_REG017H_CCON			0x21
447