/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
/*
 * Copyright (c) 2020 MediaTek Inc.
 */

#ifndef _DRV_DVBS_H_
#define _DRV_DVBS_H_

#include <media/dvb_frontend.h>
#include <linux/dvb/frontend.h>
#ifdef __cplusplus
extern "C"
{
#endif

enum DVBS_Param_2 {
	E_DMD_S2_TS_SERIAL = 0x00,
	E_DMD_S2_TS_CLK_RATE,
	E_DMD_S2_TS_OUT_INV,
	E_DMD_S2_TS_DATA_SWAP,
	//------------------------------------------
	E_DMD_S2_FW_VERSION_L,
	E_DMD_S2_FW_VERSION_H,
	E_DMD_S2_CHIP_VERSION,
	E_DMD_S2_FS_L,//Frequency
	E_DMD_S2_FS_H,//Frequency
	E_DMD_S2_MANUAL_TUNE_SYMBOLRATE_L,
	E_DMD_S2_MANUAL_TUNE_SYMBOLRATE_H,
	E_DMD_S2_SYSTEM_TYPE,//DVBS/S2
	E_DMD_S2_MODULATION_TYPE,//QPSK/8PSK
	E_DMD_S2_BLINDSCAN_CHECK,
	E_DMD_S2_UNCRT_PKT_NUM_7_0,
	E_DMD_S2_UNCRT_PKT_NUM_8_15,
	E_DMD_S2_STATE_FLAG,//0x10
	E_DMD_S2_SUBSTATE_FLAG,
	E_DMD_S2_HUM_DETECT_FLAG,
	E_DMD_S2_CCI_DETECT_FLAG,
	E_DMD_S2_IIS_DETECT_FLAG,
	E_DMD_S2_OPEN_HUM_VLD_IRQ_FLAG,
	E_DMD_S2_SRD_COARSE_DONE_FLAG,
	E_DMD_S2_SRD_FINE_DONE_FLAG,
	E_DMD_S2_FINEFE_DONE_FLAG,
	E_DMD_S2_REV_FRAME_FLAG,
	E_DMD_S2_DUMMY_FRAME_FLAG,
	E_DMD_S2_PLSC_DONE_FLAG,
	E_DMD_S2_GET_INFO_FROM_FRAME_LENGTH_DONE_FLAG,
	E_DMD_S2_IQ_SWAP_DETECT_FLAG,
	E_DMD_S2_FRAME_ACQUISITION_DONE_FLAG,
	E_DMD_S2_OLC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VCM_Set_ISID
};

extern int mdrv_dmd_dvbs_init(struct dvb_frontend *fe);

extern int mdrv_dmd_dvbs_exit(struct dvb_frontend *fe);

extern int mdrv_dmd_dvbs_config(struct dvb_frontend *fe);

extern int mdrv_dmd_dvbs_read_status(struct dvb_frontend *fe,
	enum fe_status *status);

extern int mdrv_dmd_dvbs_get_frontend(struct dvb_frontend *fe,
	struct dtv_frontend_properties *p);

extern  int mdrv_dmd_dvbs_get_ts_rate(u32 *clock_rate);

extern int mdrv_dmd_dvbs_blindScan_start(struct DMD_DVBS_BlindScan_Start_param *Start_param);

extern int mdrv_dmd_dvbs_blindScan_next_freq(
		struct DMD_DVBS_BlindScan_NextFreq_param *NextFreq_param);

extern int mdrv_dmd_dvbs_blindScan_get_tuner_freq(
		struct DMD_DVBS_BlindScan_GetTunerFreq_param *GetTunerFreq_param);

extern int mdrv_dmd_dvbs_blindScan_wait_finished(
		struct DMD_DVBS_BlindScan_WaitCurFreqFinished_param *WaitCurFreqFinished_param);

extern int mdrv_dmd_dvbs_blindScan_get_channel(
		struct DMD_DVBS_BlindScan_GetChannel_param *GetChannel_param);

extern int mdrv_dmd_dvbs_blindScan_cancel(void);

extern int mdrv_dmd_dvbs_blindScan_end(void);

extern int mdrv_dmd_dvbs_blindscan_config(struct dvb_frontend *fe);

extern  int mdrv_dmd_dvbs_diseqc_set_22k(enum fe_sec_tone_mode tone);

extern  int mdrv_dmd_dvbs_diseqc_send_cmd(struct dvb_diseqc_master_cmd *cmd);

extern  int mdrv_dmd_dvbs_diseqc_set_tone(enum fe_sec_mini_cmd minicmd);

extern  int mdrv_dmd_dvbs_diseqc_set_envelope_mode(bool b_enable_envelope);

extern ssize_t dvbs_get_information_show(struct device_driver *driver,
	char *buf);

extern ssize_t dvbs_get_information(char *buf);

#ifdef __cplusplus
}
#endif

#endif // _DRV_DVBS_H_

