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

#ifndef MTK_SCRM_H
#define MTK_SCRM_H

#include <media/dvbdev.h>
#include <media/dvb_ca_en50221.h>
#include <linux/platform_device.h>
#include <linux/module.h>
#include "mtk_dmx_internal_if.h"
#include "mtk_dmx_dev.h"

#ifdef pr_fmt
#undef pr_fmt
#endif
#define pr_fmt(fmt) "mtk_ca_scrmb: " fmt

#ifdef __cplusplus
extern "C" {
#endif

#define SCRAMBLER_ERR(fmt, ...)	\
	pr_err("[%s][%d]" fmt,	\
	__func__, __LINE__, ##__VA_ARGS__)
#define SCRAMBLER_WARN(fmt, ...)	\
	pr_warn("[%s][%d]" fmt,	\
	__func__, __LINE__, ##__VA_ARGS__)
#define SCRAMBLER_INFO(fmt, ...)	\
	pr_info("[%s][%d]" fmt,	\
	__func__, __LINE__, ##__VA_ARGS__)
#define SCRAMBLER_DEBUG(fmt, ...)	\
	pr_debug("[%s][%d]" fmt,	\
	__func__, __LINE__, ##__VA_ARGS__)

#ifndef REC_TA_UUID
#define REC_TA_UUID	\
	{0x4e501575, 0xee69, 0x4eee, \
	{0x94, 0xe1, 0x26, 0xb9, 0xed, 0x96, 0xc8, 0x5a}}
#endif
#ifdef __cplusplus
}
#endif
extern struct dvb_adapter *mdrv_get_dvb_adapter(void);

struct mdrv_scrambler_res {
	void __iomem *RIU_vaddr;
	void __iomem *extRIU_vaddr;
};

struct mdrv_scrambler {
	//int irq;
	struct mdrv_scrambler_res *regmaps;
};

struct scrambler_connect_info {
	bool set_tlv_avsrc;
	u16 path_id;
	u16 pid;
	u16 pid_flt_id;
	dmx_purpose_t purpose;
	enum filter_dst_type filter_dst_type;
	u16 fifo_id;
};

#define DRVAES_NAME    "mediatek,scrambler"
struct mtk_dvb_scrambler {
	struct platform_device *pdev;
	struct mdrv_scrambler_res resource;
	struct dvb_ca_en50221 ca;
	struct dvb_adapter *adapter;
};

struct dmx_tee_info {
	u32 pipeline_id;
	dmx_crypto_type cryption_type;
};

void mdrv_scrambler_connect_pid(struct scrambler_connect_info connect_info);
void mdrv_scrambler_disconnect_pid(struct scrambler_connect_info connect_info);
int mdrv_scrambler_dev_init(struct platform_device *pdev, struct mtk_dmx2dev *mtkdev);
int mdrv_scrambler_dev_exit(struct platform_device *pdev);
u64 mdrv_scrambler_get_keytoken(u16 path_id, unsigned int purpose);

#endif				/* MTK_SCRM_H */
