linux/drivers/media/dvb-frontends/au8522_priv.h

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
    Auvitek AU8522 QAM/8VSB demodulator driver

    Copyright (C) 2008 Steven Toth <[email protected]>
    Copyright (C) 2008 Devin Heitmueller <[email protected]>
    Copyright (C) 2005-2008 Auvitek International, Ltd.


*/

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/videodev2.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-mc.h>
#include <linux/i2c.h>
#include <media/dvb_frontend.h>
#include "au8522.h"
#include "tuner-i2c.h"

#define AU8522_ANALOG_MODE
#define AU8522_DIGITAL_MODE
#define AU8522_SUSPEND_MODE

enum au8522_pads {};

struct au8522_state {};

/* These are routines shared by both the VSB/QAM demodulator and the analog
   decoder */
int au8522_writereg(struct au8522_state *state, u16 reg, u8 data);
u8 au8522_readreg(struct au8522_state *state, u16 reg);
int au8522_init(struct dvb_frontend *fe);
int au8522_sleep(struct dvb_frontend *fe);

int au8522_get_state(struct au8522_state **state, struct i2c_adapter *i2c,
		     u8 client_address);
void au8522_release_state(struct au8522_state *state);
int au8522_i2c_gate_ctrl(struct dvb_frontend *fe, int enable);
int au8522_analog_i2c_gate_ctrl(struct dvb_frontend *fe, int enable);
int au8522_led_ctrl(struct au8522_state *state, int led);

/* REGISTERS */
#define AU8522_INPUT_CONTROL_REG081H
#define AU8522_PGA_CONTROL_REG082H
#define AU8522_CLAMPING_CONTROL_REG083H

#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H
#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H
#define AU8522_AGC_CONTROL_RANGE_REG0A6H
#define AU8522_SYSTEM_GAIN_CONTROL_REG0A7H
#define AU8522_TUNER_AGC_RF_STOP_REG0A8H
#define AU8522_TUNER_AGC_RF_START_REG0A9H
#define AU8522_TUNER_RF_AGC_DEFAULT_REG0AAH
#define AU8522_TUNER_AGC_IF_STOP_REG0ABH
#define AU8522_TUNER_AGC_IF_START_REG0ACH
#define AU8522_TUNER_AGC_IF_DEFAULT_REG0ADH
#define AU8522_TUNER_AGC_STEP_REG0AEH
#define AU8522_TUNER_GAIN_STEP_REG0AFH

/* Receiver registers */
#define AU8522_FRMREGTHRD1_REG0B0H
#define AU8522_FRMREGAGC1H_REG0B1H
#define AU8522_FRMREGSHIFT1_REG0B2H
#define AU8522_TOREGAGC1_REG0B3H
#define AU8522_TOREGASHIFT1_REG0B4H
#define AU8522_FRMREGBBH_REG0B5H
#define AU8522_FRMREGBBM_REG0B6H
#define AU8522_FRMREGBBL_REG0B7H
/* 0xB8 TO 0xD7 are the filter coefficients */
#define AU8522_FRMREGTHRD2_REG0D8H
#define AU8522_FRMREGAGC2H_REG0D9H
#define AU8522_TOREGAGC2_REG0DAH
#define AU8522_TOREGSHIFT2_REG0DBH
#define AU8522_FRMREGPILOTH_REG0DCH
#define AU8522_FRMREGPILOTM_REG0DDH
#define AU8522_FRMREGPILOTL_REG0DEH
#define AU8522_TOREGFREQ_REG0DFH

#define AU8522_RX_PGA_RFOUT_REG0EBH
#define AU8522_RX_PGA_IFOUT_REG0ECH
#define AU8522_RX_PGA_PGAOUT_REG0EDH

#define AU8522_CHIP_MODE_REG0FEH

/* I2C bus control registers */
#define AU8522_I2C_CONTROL_REG0_REG090H
#define AU8522_I2C_CONTROL_REG1_REG091H
#define AU8522_I2C_STATUS_REG092H
#define AU8522_I2C_WR_DATA0_REG093H
#define AU8522_I2C_WR_DATA1_REG094H
#define AU8522_I2C_WR_DATA2_REG095H
#define AU8522_I2C_WR_DATA3_REG096H
#define AU8522_I2C_WR_DATA4_REG097H
#define AU8522_I2C_WR_DATA5_REG098H
#define AU8522_I2C_WR_DATA6_REG099H
#define AU8522_I2C_WR_DATA7_REG09AH
#define AU8522_I2C_RD_DATA0_REG09BH
#define AU8522_I2C_RD_DATA1_REG09CH
#define AU8522_I2C_RD_DATA2_REG09DH
#define AU8522_I2C_RD_DATA3_REG09EH
#define AU8522_I2C_RD_DATA4_REG09FH
#define AU8522_I2C_RD_DATA5_REG0A0H
#define AU8522_I2C_RD_DATA6_REG0A1H
#define AU8522_I2C_RD_DATA7_REG0A2H

#define AU8522_ENA_USB_REG101H

#define AU8522_I2S_CTRL_0_REG110H
#define AU8522_I2S_CTRL_1_REG111H
#define AU8522_I2S_CTRL_2_REG112H

#define AU8522_FRMREGFFECONTROL_REG121H
#define AU8522_FRMREGDFECONTROL_REG122H

#define AU8522_CARRFREQOFFSET0_REG201H
#define AU8522_CARRFREQOFFSET1_REG202H

#define AU8522_DECIMATION_GAIN_REG21AH
#define AU8522_FRMREGIFSLP_REG21BH
#define AU8522_FRMREGTHRDL2_REG21CH
#define AU8522_FRMREGSTEP3DB_REG21DH
#define AU8522_DAGC_GAIN_ADJUSTMENT_REG21EH
#define AU8522_FRMREGPLLMODE_REG21FH
#define AU8522_FRMREGCSTHRD_REG220H
#define AU8522_FRMREGCRLOCKDMAX_REG221H
#define AU8522_FRMREGCRPERIODMASK_REG222H
#define AU8522_FRMREGCRLOCK0THH_REG223H
#define AU8522_FRMREGCRLOCK1THH_REG224H
#define AU8522_FRMREGCRLOCK0THL_REG225H
#define AU8522_FRMREGCRLOCK1THL_REG226H
#define AU_FRMREGPLLACQPHASESCL_REG227H
#define AU8522_FRMREGFREQFBCTRL_REG228H

/* Analog TV Decoder */
#define AU8522_TVDEC_STATUS_REG000H
#define AU8522_TVDEC_INT_STATUS_REG001H
#define AU8522_TVDEC_MACROVISION_STATUS_REG002H
#define AU8522_TVDEC_SHARPNESSREG009H
#define AU8522_TVDEC_BRIGHTNESS_REG00AH
#define AU8522_TVDEC_CONTRAST_REG00BH
#define AU8522_TVDEC_SATURATION_CB_REG00CH
#define AU8522_TVDEC_SATURATION_CR_REG00DH
#define AU8522_TVDEC_HUE_H_REG00EH
#define AU8522_TVDEC_HUE_L_REG00FH
#define AU8522_TVDEC_INT_MASK_REG010H
#define AU8522_VIDEO_MODE_REG011H
#define AU8522_TVDEC_PGA_REG012H
#define AU8522_TVDEC_COMB_MODE_REG015H
#define AU8522_REG016H
#define AU8522_TVDED_DBG_MODE_REG060H
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H
#define AU8522_TVDEC_FORMAT_CTRL2_REG062H
#define AU8522_TVDEC_VCR_DET_LLIM_REG063H
#define AU8522_TVDEC_VCR_DET_HLIM_REG064H
#define AU8522_TVDEC_COMB_VDIF_THR1_REG065H
#define AU8522_TVDEC_COMB_VDIF_THR2_REG066H
#define AU8522_TVDEC_COMB_VDIF_THR3_REG067H
#define AU8522_TVDEC_COMB_NOTCH_THR_REG068H
#define AU8522_TVDEC_COMB_HDIF_THR1_REG069H
#define AU8522_TVDEC_COMB_HDIF_THR2_REG06AH
#define AU8522_TVDEC_COMB_HDIF_THR3_REG06BH
#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH
#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH
#define AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH
#define AU8522_TVDEC_UV_SEP_THR_REG06FH
#define AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H
#define AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H
#define AU8522_TVDEC_DCAGC_CTRL_REG077H
#define AU8522_TVDEC_PIC_START_ADJ_REG078H
#define AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H
#define AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH
#define AU8522_TVDEC_INTRP_CTRL_REG07BH
#define AU8522_TVDEC_PLL_STATUS_REG07EH
#define AU8522_TVDEC_FSC_FREQ_REG07FH

#define AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H
#define AU8522_TOREGAAGC_REG0E5H

#define AU8522_TVDEC_CHROMA_AGC_REG401H
#define AU8522_TVDEC_CHROMA_SFT_REG402H
#define AU8522_FILTER_COEF_R410
#define AU8522_FILTER_COEF_R411
#define AU8522_FILTER_COEF_R412
#define AU8522_FILTER_COEF_R413
#define AU8522_FILTER_COEF_R414
#define AU8522_FILTER_COEF_R415
#define AU8522_FILTER_COEF_R416
#define AU8522_FILTER_COEF_R417
#define AU8522_FILTER_COEF_R418
#define AU8522_FILTER_COEF_R419
#define AU8522_FILTER_COEF_R41A
#define AU8522_FILTER_COEF_R41B
#define AU8522_FILTER_COEF_R41C
#define AU8522_FILTER_COEF_R41D
#define AU8522_FILTER_COEF_R41E
#define AU8522_FILTER_COEF_R41F
#define AU8522_FILTER_COEF_R420
#define AU8522_FILTER_COEF_R421
#define AU8522_FILTER_COEF_R422
#define AU8522_FILTER_COEF_R423
#define AU8522_FILTER_COEF_R424
#define AU8522_FILTER_COEF_R425
#define AU8522_FILTER_COEF_R426
#define AU8522_FILTER_COEF_R427
#define AU8522_FILTER_COEF_R428
#define AU8522_FILTER_COEF_R429
#define AU8522_FILTER_COEF_R42A
#define AU8522_FILTER_COEF_R42B
#define AU8522_FILTER_COEF_R42C
#define AU8522_FILTER_COEF_R42D

/* VBI Control Registers */
#define AU8522_TVDEC_VBI_RX_FIFO_CONTAIN_REG004H
#define AU8522_TVDEC_VBI_TX_FIFO_CONTAIN_REG005H
#define AU8522_TVDEC_VBI_RX_FIFO_READ_REG006H
#define AU8522_TVDEC_VBI_FIFO_STATUS_REG007H
#define AU8522_TVDEC_VBI_CTRL_H_REG017H
#define AU8522_TVDEC_VBI_CTRL_L_REG018H
#define AU8522_TVDEC_VBI_USER_TOTAL_BITS_REG019H
#define AU8522_TVDEC_VBI_USER_TUNIT_H_REG01AH
#define AU8522_TVDEC_VBI_USER_TUNIT_L_REG01BH
#define AU8522_TVDEC_VBI_USER_THRESH1_REG01CH
#define AU8522_TVDEC_VBI_USER_FRAME_PAT2_REG01EH
#define AU8522_TVDEC_VBI_USER_FRAME_PAT1_REG01FH
#define AU8522_TVDEC_VBI_USER_FRAME_PAT0_REG020H
#define AU8522_TVDEC_VBI_USER_FRAME_MASK2_REG021H
#define AU8522_TVDEC_VBI_USER_FRAME_MASK1_REG022H
#define AU8522_TVDEC_VBI_USER_FRAME_MASK0_REG023H

#define AU8522_REG071H
#define AU8522_REG072H
#define AU8522_REG074H
#define AU8522_REG075H

/* Digital Demodulator Registers */
#define AU8522_FRAME_COUNT0_REG084H
#define AU8522_RS_STATUS_G0_REG085H
#define AU8522_RS_STATUS_B0_REG086H
#define AU8522_RS_STATUS_E_REG087H
#define AU8522_DEMODULATION_STATUS_REG088H
#define AU8522_TOREGTRESTATUS_REG0E6H
#define AU8522_TSPORT_CONTROL_REG10BH
#define AU8522_TSTHES_REG10CH
#define AU8522_FRMREGDFEKEEP_REG301H
#define AU8522_DFE_AVERAGE_REG302H
#define AU8522_FRMREGEQLERRWIN_REG303H
#define AU8522_FRMREGFFEKEEP_REG304H
#define AU8522_FRMREGDFECONTROL1_REG305H
#define AU8522_FRMREGEQLERRLOW_REG306H

#define AU8522_REG42EH
#define AU8522_REG42FH
#define AU8522_REG430H
#define AU8522_REG431H
#define AU8522_REG432H
#define AU8522_REG433H
#define AU8522_REG434H
#define AU8522_REG435H
#define AU8522_REG436H

/* GPIO Registers */
#define AU8522_GPIO_CONTROL_REG0E0H
#define AU8522_GPIO_STATUS_REG0E1H
#define AU8522_GPIO_DATA_REG0E2H

/* Audio Control Registers */
#define AU8522_AUDIOAGC_REG0EEH
#define AU8522_AUDIO_STATUS_REG0F0H
#define AU8522_AUDIO_MODE_REG0F1H
#define AU8522_AUDIO_VOLUME_L_REG0F2H
#define AU8522_AUDIO_VOLUME_R_REG0F3H
#define AU8522_AUDIO_VOLUME_REG0F4H
#define AU8522_FRMREGAUPHASE_REG0F7H
#define AU8522_REG0F9H

#define AU8522_AUDIOAGC2_REG605H
#define AU8522_AUDIOFREQ_REG606H


/**************************************************************/

/* Format control 1 */

/* VCR Mode 7-6 */
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_VCR_MODE_YES
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_VCR_MODE_NO
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_VCR_MODE_AUTO
/* Field len 5-4 */
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_FIELD_LEN_625
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_FIELD_LEN_525
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_FIELD_LEN_AUTO
/* Line len (us) 3-2 */
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_LINE_LEN_64_000
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_LINE_LEN_63_492
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_LINE_LEN_63_556
/* Subcarrier freq 1-0 */
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_AUTO
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_443
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_MN
#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_SUBCARRIER_NTSC_50

/* Format control 2 */
#define AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_AUTODETECT
#define AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_NTSC
#define AU8522_TVDEC_FORMAT_CTRL2_REG062H_STD_PAL_M


#define AU8522_INPUT_CONTROL_REG081H_ATSC
#define AU8522_INPUT_CONTROL_REG081H_ATVRF
#define AU8522_INPUT_CONTROL_REG081H_ATVRF13
#define AU8522_INPUT_CONTROL_REG081H_J83B64
#define AU8522_INPUT_CONTROL_REG081H_J83B256
#define AU8522_INPUT_CONTROL_REG081H_CVBS
#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH1
#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH2
#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH3
#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH4
#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF
/* CH1 AS Y,CH3 AS C */
#define AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13
/* CH2 AS Y,CH4 AS C */
#define AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24
#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_ATSC
#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_J83B64
#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_J83B256
#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS
#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_ATVRF
#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_ATVRF13
#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_SVIDEO

#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CLEAR
#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_SVIDEO
#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS
#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_ATSC
#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_J83B256
#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_J83B64
#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_ATVRF
#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_ATVRF13
#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_PAL
#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_FM

#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_ATSC
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_J83B256
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_J83B64
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_ATSC
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_J83B256
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_J83B64
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_CLEAR
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_ATVRF
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_ATVRF13
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_SVIDEO
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_CVBS
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_PWM
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_IIS
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_PAL
#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_FM

/* STILL NEED TO BE REFACTORED @@@@@@@@@@@@@@ */
#define AU8522_TVDEC_CONTRAST_REG00BH_CVBS
#define AU8522_TVDEC_SATURATION_CB_REG00CH_CVBS
#define AU8522_TVDEC_SATURATION_CR_REG00DH_CVBS
#define AU8522_TVDEC_HUE_H_REG00EH_CVBS
#define AU8522_TVDEC_HUE_L_REG00FH_CVBS
#define AU8522_TVDEC_PGA_REG012H_CVBS
#define AU8522_TVDEC_COMB_MODE_REG015H_CVBS
#define AU8522_REG016H_CVBS
#define AU8522_TVDED_DBG_MODE_REG060H_CVBS
#define AU8522_TVDEC_VCR_DET_LLIM_REG063H_CVBS
#define AU8522_REG0F9H_AUDIO
#define AU8522_TVDEC_VCR_DET_HLIM_REG064H_CVBS
#define AU8522_TVDEC_COMB_VDIF_THR1_REG065H_CVBS
#define AU8522_TVDEC_COMB_VDIF_THR2_REG066H_CVBS
#define AU8522_TVDEC_COMB_VDIF_THR3_REG067H_CVBS
#define AU8522_TVDEC_COMB_NOTCH_THR_REG068H_CVBS
#define AU8522_TVDEC_COMB_HDIF_THR1_REG069H_CVBS
#define AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS
#define AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS
#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS
#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_SVIDEO
#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS
#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_SVIDEO
#define AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS
#define AU8522_TVDEC_UV_SEP_THR_REG06FH_CVBS
#define AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H_CVBS
#define AU8522_REG071H_CVBS
#define AU8522_REG072H_CVBS
#define AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H_CVBS
#define AU8522_REG074H_CVBS
#define AU8522_REG075H_CVBS
#define AU8522_TVDEC_DCAGC_CTRL_REG077H_CVBS
#define AU8522_TVDEC_PIC_START_ADJ_REG078H_CVBS
#define AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H_CVBS
#define AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH_CVBS
#define AU8522_TVDEC_INTRP_CTRL_REG07BH_CVBS
#define AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H_CVBS
#define AU8522_TOREGAAGC_REG0E5H_CVBS
#define AU8522_TVDEC_VBI6A_REG035H_CVBS

/* Enables Closed captioning */
#define AU8522_TVDEC_VBI_CTRL_H_REG017H_CCON