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

#include <linux/dvb/dmx.h>
#include <linux/clk.h>
#include <linux/mutex.h>
#include <linux/dvb/dmx_mtk.h>

#include <media/dvb_demux.h>

#define DEMUX_PATH_NULL		((u16)-1)

enum demux_tsio_caps {
	DEMUX_TSIO_CAPS_SUPPORT_FILEIN,
	DEMUX_TSIO_CAPS_MAX
};

struct demux_fiq_cfg {
	bool bFiqEnable, bFiqNormalMode;
	u16 src_mux;
};

struct demux_path_cfg {
	struct mdrv_demux_tsio *parent;
	u16 path_id;
	u16 cilink_id;
	bool bSupportFilein;
	struct demux_fiq_cfg fiq_cfg;
	dmx_source_t eInputSrc;
	struct kobject kobj;
	struct clk *clk_src;	// @TODO: use this to control tsif source mux
};

struct mdrv_demux_tsio {
	struct mdrv_demux_res *res;
	struct mutex tsio_mutex;
	struct pinctrl *pin_ctrl;
	struct demux_path_cfg *path_cfg;
	u16 total_num;
	u16 tsif_num, tlvif_num, alpif_num, cilink_num;
};

int mdrv_demux_tsio_init(struct platform_device *pdev, struct mdrv_demux_tsio *tsio);
int mdrv_demux_tsio_exit(struct platform_device *pdev, struct mdrv_demux_tsio *tsio);
int mdrv_demux_tsio_suspend(struct mdrv_demux_tsio *tsio);
int mdrv_demux_tsio_resume(struct mdrv_demux_tsio *tsio);

u32 mdrv_demux_tsio_get_caps(struct mdrv_demux_tsio *tsio, enum demux_tsio_caps cap_type,
				 void *arg);
int mdrv_demux_tsio_set_input_src(struct mdrv_demux_tsio *tsio, u16 path_id,
	dmx_source_t src);
int mdrv_demux_tsio_connect_ca(struct mdrv_demux_tsio *tsio, u16 path_id, u16 eng_id);
int mdrv_demux_tsio_disconnect_ca(struct mdrv_demux_tsio *tsio, u16 path_id, u16 eng_id);

// filein
int mdrv_demux_tsio_write(struct mdrv_demux_tsio *tsio, u16 path_id,
			  const char __user *buf, u32 count, int non_blocking);
int mdrv_demux_tsio_reset_engine(struct mdrv_demux_tsio *tsio, u16 path_id);
int mdrv_demux_tsio_pause_engine(struct mdrv_demux_tsio *tsio, u16 path_id);
int mdrv_demux_tsio_resume_engine(struct mdrv_demux_tsio *tsio, u16 path_id);
int mdrv_demux_tsio_get_state(struct mdrv_demux_tsio *tsio, u16 path_id,
	dmx_module_state *pstate);
int mdrv_demux_tsio_set_play_cfg(struct mdrv_demux_tsio *tsio, u16 path_id,
	struct dvr_play_config *pCfg);
int mdrv_demux_tsio_set_play_time(struct mdrv_demux_tsio *tsio, u16 path_id,
	u64 timestamp);
int mdrv_demux_tsio_get_play_time(struct mdrv_demux_tsio *tsio, u16 path_id,
	u64 *ptimestamp);
int mdrv_demux_tsio_get_pkt_time(struct mdrv_demux_tsio *tsio, u16 path_id,
	u64 *ptimestamp);

// fast zapping
int mdrv_demux_tsio_enable_fiq(struct mdrv_demux_tsio *tsio, u16 path_id,
				   bool bNormalMode, bool bEnable);
int mdrv_demux_tsio_trigger_fiq_rush(struct mdrv_demux_tsio *tsio,
	u16 path_id, u64 rush_addr);

#endif				/* MDRV_DEMUX_TSIO_H */
