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

#include <linux/delay.h>
#include <linux/module.h>
#include <linux/io.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/slab.h>
#include <linux/dma-mapping.h>
#include "mhal_demux_common.h"
#include "mhal_mvd_parser.h"
#include "mhal_mvd_parser_reg.h"
#include "mdrv_mvd_parser.h"

typedef struct {
	bool bIsInit[MAX_HAL_VPAS_NUM];
} VPAS_CTX_HAL;

static VPAS_CTX_HAL *g_pHalVPASCtx;

VPAS_CTX_HAL g_stVPASHalCtx;

int log_level = 1;
#define PAS_ADDR_SHIFT 3

VPAS_Result _HAL_VPAS_InitContext(void)
{
#ifdef ALLOC_CTX
	if (g_pHalVPASCtx == NULL) {
		g_pHalVPASCtx = kzalloc(sizeof(*g_pHalVPASCtx), GFP_KERNEL);
		memset((u8 *)g_pHalVPASCtx, 0, sizeof(VPAS_CTX_HAL));
	} else {
		return E_VPAS_RET_INIT_ALREADY_EXIST;
	}
#else
	g_pHalVPASCtx =	 &g_stVPASHalCtx;
#endif

	return E_VPAS_OK;
}

bool HAL_VPAS_InitVar(u8 u8ParserID)
{
	VPAS_Result eRet = E_VPAS_OK;

	eRet = _HAL_VPAS_InitContext();
	if (eRet == E_VPAS_RET_INIT_FAIL) {
		PAS_DEBUG_LOG(PAS_LOG_LEVEL_WARN, "VPAS Context Init failed!\n");
		return false;
	} else if (eRet == E_VPAS_RET_INIT_ALREADY_EXIST) {
		if (g_pHalVPASCtx->bIsInit[u8ParserID]) {
			PAS_DEBUG_LOG(PAS_LOG_LEVEL_INFO, "Main VPAS Context has Initialized!\n");
			return true;
		}
	}
	g_pHalVPASCtx->bIsInit[u8ParserID] = 1;

	return true;
}

void HAL_VPAS_SetStart(u8 u8ParserID)
{
	if (u8ParserID == 0) {
		//VD_PES Parser start
		//wriu -w 0x2330c0 0x0402
		VPAS_Write2Byte(REG_VPAS_PAS1_CTRL, BIT_REG_PAS_HK_PARSER_PAUSE);
	} else if (u8ParserID == 1) {
		VPAS_Write2Byte(REG_VPAS_PAS2_CTRL, BIT_REG_PAS_HK_PARSER_PAUSE);
	}
}
EXPORT_SYMBOL(HAL_VPAS_SetStart);

void HAL_VPAS_SetBypass(u8 u8ParserID, u32 enable)
{
	u16 value = 0;

	if (u8ParserID == 0) {
		if (enable)
			value = (BIT_REG_PAS_HK_PARSER_DIS | VPAS_Read2Byte(REG_VPAS_PAS1_CTRL));
		else
			value = (~BIT_REG_PAS_HK_PARSER_DIS & VPAS_Read2Byte(REG_VPAS_PAS1_CTRL));
		VPAS_Write2Byte(REG_VPAS_PAS1_CTRL, value);
	} else if (u8ParserID == 1) {
		if (enable)
			value = (BIT_REG_PAS_HK_PARSER_DIS | VPAS_Read2Byte(REG_VPAS_PAS2_CTRL));
		else
			value = (~BIT_REG_PAS_HK_PARSER_DIS & VPAS_Read2Byte(REG_VPAS_PAS2_CTRL));
		VPAS_Write2Byte(REG_VPAS_PAS2_CTRL, value);
	}
}
EXPORT_SYMBOL(HAL_VPAS_SetBypass);

void HAL_VPAS_SetTLV(u8 u8ParserID, u32 enable)
{
	u16 value = 0;

	if (u8ParserID == 0) {
		if (enable)
			value = (BIT_REG_PAS_PAS_TLV_MODE | VPAS_Read2Byte(REG_VPAS_PAS1_HK_CTL));
		else
			value = (~BIT_REG_PAS_PAS_TLV_MODE & VPAS_Read2Byte(REG_VPAS_PAS1_HK_CTL));
		VPAS_Write2Byte(REG_VPAS_PAS1_HK_CTL, value);
	} else if (u8ParserID == 1) {
		if (enable)
			value = (BIT_REG_PAS_PAS_TLV_MODE | VPAS_Read2Byte(REG_VPAS_PAS2_HK_CTL));
		else
			value = (~BIT_REG_PAS_PAS_TLV_MODE & VPAS_Read2Byte(REG_VPAS_PAS2_HK_CTL));
		VPAS_Write2Byte(REG_VPAS_PAS2_HK_CTL, value);
	}
}

void HAL_VPAS_SetStop(u8 u8ParserID)
{
	if (u8ParserID == 0)
		VPAS_Write2Byte(REG_VPAS_PAS1_CTRL, BIT_REG_PAS_HK_PARSER_STOP);
	else if (u8ParserID == 1)
		VPAS_Write2Byte(REG_VPAS_PAS2_CTRL, BIT_REG_PAS_HK_PARSER_STOP);
}
EXPORT_SYMBOL(HAL_VPAS_SetStop);

void HAL_VPAS_Exit(u8 u8ParserID)
{
	g_pHalVPASCtx->bIsInit[u8ParserID] = false;
}

void HAL_VPAS_SetPauseMode(u8 u8ParserID, u32 enable)
{
	u16 value = 0;

	if (u8ParserID == 0) {
		if (enable)
			value = (BIT_REG_PAS_HK_PARSER_PAUSE | VPAS_Read2Byte(REG_VPAS_PAS1_CTRL));
		else
			value = (~BIT_REG_PAS_HK_PARSER_PAUSE & VPAS_Read2Byte(REG_VPAS_PAS1_CTRL));
		VPAS_Write2Byte(REG_VPAS_PAS1_CTRL, value);
	} else if (u8ParserID == 1) {
		if (enable)
			value = (BIT_REG_PAS_HK_PARSER_PAUSE | VPAS_Read2Byte(REG_VPAS_PAS2_CTRL));
		else
			value = (~BIT_REG_PAS_HK_PARSER_PAUSE & VPAS_Read2Byte(REG_VPAS_PAS2_CTRL));
		VPAS_Write2Byte(REG_VPAS_PAS2_CTRL, value);
	}
}

void HAL_VPAS_SetEsOffset(u8 u8ParserID, u32 u32EsRAddr)
{
	if (u8ParserID == 0) {
		// TODO: REG_VPAS_CUR_ESB1_RADR_LO
		PAS_DEBUG_LOG(PAS_LOG_LEVEL_INFO, "to do\n");
	} else if (u8ParserID == 1) {
		// TODO:
		PAS_DEBUG_LOG(PAS_LOG_LEVEL_INFO, "to do\n");
	}
}

void HAL_VPAS_SW_RST(u8 u8ParserID)
{
	u16 value = 0;

	if (u8ParserID == 0) {
		value = (BIT_REG_SW_PAS1_REG_RST | VPAS_Read2Byte(REG_VPAS_SW_RST_CTRL));
		VPAS_Write2Byte(REG_VPAS_SW_RST_CTRL, value);
		value = (~BIT_REG_SW_PAS1_REG_RST & VPAS_Read2Byte(REG_VPAS_SW_RST_CTRL));
		VPAS_Write2Byte(REG_VPAS_SW_RST_CTRL, value);
	} else if (u8ParserID == 1) {
		value = (BIT_REG_SW_PAS2_REG_RST | VPAS_Read2Byte(REG_VPAS_SW_RST_CTRL));
		VPAS_Write2Byte(REG_VPAS_SW_RST_CTRL, value);
		value = (~BIT_REG_SW_PAS2_REG_RST & VPAS_Read2Byte(REG_VPAS_SW_RST_CTRL));
		VPAS_Write2Byte(REG_VPAS_SW_RST_CTRL, value);	}

	if (u8ParserID == 0) {
		value = (BIT_REG_PAS_HK_SW_PAS_RST | VPAS_Read2Byte(REG_VPAS_PAS1_CTRL));
		VPAS_Write2Byte(REG_VPAS_PAS1_CTRL, value);
		value = (~BIT_REG_PAS_HK_SW_PAS_RST & VPAS_Read2Byte(REG_VPAS_PAS1_CTRL));
		VPAS_Write2Byte(REG_VPAS_PAS1_CTRL, value);
	} else if (u8ParserID == 1) {
		value = (BIT_REG_PAS_HK_SW_PAS_RST | VPAS_Read2Byte(REG_VPAS_PAS2_CTRL));
		VPAS_Write2Byte(REG_VPAS_PAS2_CTRL, value);
		value = (~BIT_REG_PAS_HK_SW_PAS_RST & VPAS_Read2Byte(REG_VPAS_PAS2_CTRL));
		VPAS_Write2Byte(REG_VPAS_PAS2_CTRL, value);	}

	if (u8ParserID == 0) {
		value = (BIT_REG_PAS_CLR_SW_PAS_RST | VPAS_Read2Byte(REG_VPAS_PAS1_HK_CTL));
		VPAS_Write2Byte(REG_VPAS_PAS1_HK_CTL, value);
		value = (~BIT_REG_PAS_CLR_SW_PAS_RST & VPAS_Read2Byte(REG_VPAS_PAS1_HK_CTL));
		VPAS_Write2Byte(REG_VPAS_PAS1_HK_CTL, value);
	} else if (u8ParserID == 1) {
		value = (BIT_REG_PAS_CLR_SW_PAS_RST | VPAS_Read2Byte(REG_VPAS_PAS2_HK_CTL));
		VPAS_Write2Byte(REG_VPAS_PAS2_HK_CTL, value);
		value = (~BIT_REG_PAS_CLR_SW_PAS_RST & VPAS_Read2Byte(REG_VPAS_PAS2_HK_CTL));
		VPAS_Write2Byte(REG_VPAS_PAS2_HK_CTL, value);	}
}

void HAL_VPAS_SetReset(u8 u8ParserID, u64 u32ParserBufAddr, u32 u32ParserBufSize)
{
	HAL_VPAS_SW_RST(u8ParserID);

	if (u8ParserID == 0) {
		// Configure PAS
//wriu -w 0x233000 0xf000
		VPAS_Write2Byte(REG_VPAS_SW_RST_CTRL, (BIT_REG_PAS1WADR_MODE|BIT_REG_PAS2WADR_MODE|
			BIT_REG_PAS3WADR_MODE|BIT_REG_PAS4WADR_MODE));
//wriu -w 0x2330B0 0x0001
		VPAS_Write2Byte(REG_VPAS_INT_CTRL, BIT_REG_VD_PAS_INT_EN);
//wriu -w 0x2330B2 0x0000
		VPAS_Write2Byte(REG_VPAS_INT_MASK, 0);
//Initial PAS1

//wriu -w  0x233076 0x00e0
		VPAS_Write2Byte(REG_VPAS_DBG_CTRL, 0Xe0);
//wriu -w  0x233010 0x0000
//wriu -w  0x233012 0x0008
		if (u32ParserBufAddr != 0) {
			VPAS_Write4Byte(REG_VPAS_VBUF1_WADR_LO, u32ParserBufAddr >> PAS_ADDR_SHIFT);
//wriu -w  0x23300e 0x0001
			VPAS_Write2Byte(REG_VPAS_BASE_CTRL, BIT_REG_VBUF1_WADR_RELOAD);
//wriu -w  0x233018 0x0000
//wriu -w  0x23301a 0x000c
//wriu -w  0x23301c 0x0000
//wriu -w  0x23301e 0x0008
			VPAS_Write4Byte(REG_VPAS_VBUF1_LBND_LO, u32ParserBufAddr >> PAS_ADDR_SHIFT);
			VPAS_Write4Byte(REG_VPAS_VBUF1_UBND_LO,
				(u32ParserBufAddr+u32ParserBufSize) >> PAS_ADDR_SHIFT);
		}

//wriu -w  0x2330c4 0x00e0
//wriu -w  0x2330c6 0x00e0
		VPAS_Write2Byte(REG_VPAS_PAS1_HK_ID1, 0x0FE0);
		VPAS_Write2Byte(REG_VPAS_PAS1_HK_ID2, 0x0FE0);

//wriu -w 0x2330d2 0x318e
		VPAS_Write2Byte(REG_VPAS_PAS1_HK_INT_MASK,
			BIT_REG_PAS_HK_SNUM_INT_MASK|BIT_REG_PAS_HK_SID_INT_MASK|
			BIT_REG_PAS_HK_P_FLAG_INT_MASK|BIT_REG_PAS_HK_FF_REQ_THRESH|
			BIT_REG_PAS_HK_DMA_WCNT|BIT_REG_PAS_HK_FF_PRI_THRESH);

//wriu -w 0x2330a0 0x0000
//wriu -w 0x2330a2 0x0200
//wriu -w 0x2330a4 0x000c

//wriu -w 0x2330a0 0x0400
//wriu -w 0x2330a2 0x0040
//wriu -w 0x2330a0 0x0800
//wriu -w 0x2330a2 0x0200
//wriu -w 0x2330a4 0x000c

//wriu -w 0x2330a0 0x0c00
//wriu -w 0x2330a2 0x027f
//wriu -w 0x2330a4 0x000c
//wriu -w 0x2330a0 0x0011

//wriu -w 0x2330d6 0x0008
	VPAS_Write2Byte(REG_VPAS_PAS1_OBF, BIT_REG_PAS_HK_PTS_ESBUF_EN);

//wriu -w 0x2330d8 0x0000
	VPAS_Write2Byte(REG_VPAS_PAS1_P_FLAG, 0);

// pause
	if (u32ParserBufAddr != 0)
		VPAS_Write2Byte(REG_VPAS_PAS1_CTRL, BIT_REG_PAS_HK_PARSER_PAUSE);
	else
		VPAS_Write2Byte(REG_VPAS_PAS1_CTRL,
			BIT_REG_PAS_HK_PARSER_PAUSE | BIT_REG_PAS_HK_PARSER_STOP);
//VD_PES Parser start
//wriu -w 0x2330c0 0x0402
	} else if (u8ParserID == 1) {
		// Configure PAS
//wriu -w 0x233000 0xf000
		VPAS_Write2Byte(REG_VPAS_SW_RST_CTRL, (BIT_REG_PAS1WADR_MODE|BIT_REG_PAS2WADR_MODE|
			BIT_REG_PAS3WADR_MODE|BIT_REG_PAS4WADR_MODE));
//wriu -w 0x2330B0 0x0001
		VPAS_Write2Byte(REG_VPAS_INT_CTRL, BIT_REG_VD_PAS_INT_EN);
//wriu -w 0x2330B2 0x0000
		VPAS_Write2Byte(REG_VPAS_INT_MASK, 0);
//Initial PAS1

//wriu -w  0x233076 0x00e0
		VPAS_Write2Byte(REG_VPAS_DBG_CTRL, 0Xe0);
//wriu -w  0x233010 0x0000
//wriu -w  0x233012 0x0008
		if (u32ParserBufAddr != 0) {
			VPAS_Write4Byte(REG_VPAS_VBUF2_WADR_LO, u32ParserBufAddr >> PAS_ADDR_SHIFT);
//wriu -w  0x23300e 0x0001
			VPAS_Write2Byte(REG_VPAS_BASE_CTRL, BIT_REG_VBUF2_WADR_RELOAD);
//wriu -w  0x233018 0x0000
//wriu -w  0x23301a 0x000c
//wriu -w  0x23301c 0x0000
//wriu -w  0x23301e 0x0008
			VPAS_Write4Byte(REG_VPAS_VBUF2_LBND_LO, u32ParserBufAddr >> PAS_ADDR_SHIFT);
			VPAS_Write4Byte(REG_VPAS_VBUF2_UBND_LO,
				(u32ParserBufAddr+u32ParserBufSize) >> PAS_ADDR_SHIFT);
		}
//wriu -w  0x2330c4 0x00e0
//wriu -w  0x2330c6 0x00e0
		VPAS_Write2Byte(REG_VPAS_PAS2_HK_ID1, 0xE0);
		VPAS_Write2Byte(REG_VPAS_PAS2_HK_ID2, 0xE0);

//wriu -w 0x2330d2 0x318e
		VPAS_Write2Byte(REG_VPAS_PAS2_HK_INT_MASK,
		BIT_REG_PAS_HK_SNUM_INT_MASK|BIT_REG_PAS_HK_SID_INT_MASK|
			BIT_REG_PAS_HK_P_FLAG_INT_MASK|BIT_REG_PAS_HK_FF_REQ_THRESH|
			BIT_REG_PAS_HK_DMA_WCNT|BIT_REG_PAS_HK_FF_PRI_THRESH);

//wriu -w 0x2330a0 0x0000
//wriu -w 0x2330a2 0x0200
//wriu -w 0x2330a4 0x000c

//wriu -w 0x2330a0 0x0400
//wriu -w 0x2330a2 0x0040
//wriu -w 0x2330a0 0x0800
//wriu -w 0x2330a2 0x0200
//wriu -w 0x2330a4 0x000c

//wriu -w 0x2330a0 0x0c00
//wriu -w 0x2330a2 0x027f
//wriu -w 0x2330a4 0x000c
//wriu -w 0x2330a0 0x0011

//wriu -w 0x2330d6 0x0008
	VPAS_Write2Byte(REG_VPAS_PAS2_OBF, BIT_REG_PAS_HK_PTS_ESBUF_EN);

//wriu -w 0x2330d8 0x0000
	VPAS_Write2Byte(REG_VPAS_PAS2_P_FLAG, 0);

// pause
	if (u32ParserBufAddr != 0)
		VPAS_Write2Byte(REG_VPAS_PAS2_CTRL, BIT_REG_PAS_HK_PARSER_PAUSE);
	else
		VPAS_Write2Byte(REG_VPAS_PAS2_CTRL,
			BIT_REG_PAS_HK_PARSER_PAUSE | BIT_REG_PAS_HK_PARSER_STOP);
//VD_PES Parser start
//wriu -w 0x2330c0 0x0402
	}
}
EXPORT_SYMBOL(HAL_VPAS_SetReset);

void HAL_VPAS_SetBuf(u8 u8ParserID, u64 u32ParserBufAddr, u32 u32ParserBufSize)
{
	if (u8ParserID == 0) {
		if (u32ParserBufAddr != 0) {
			VPAS_Write4Byte(REG_VPAS_VBUF1_WADR_LO, u32ParserBufAddr >> PAS_ADDR_SHIFT);
//wriu -w  0x23300e 0x0001
			VPAS_Write2Byte(REG_VPAS_BASE_CTRL, BIT_REG_VBUF1_WADR_RELOAD);
//wriu -w  0x233018 0x0000
//wriu -w  0x23301a 0x000c
//wriu -w  0x23301c 0x0000
//wriu -w  0x23301e 0x0008
			VPAS_Write4Byte(REG_VPAS_VBUF1_LBND_LO, u32ParserBufAddr >> PAS_ADDR_SHIFT);
			VPAS_Write4Byte(REG_VPAS_VBUF1_UBND_LO,
				(u32ParserBufAddr+u32ParserBufSize) >> PAS_ADDR_SHIFT);
		}
	} else if (u8ParserID == 1) {
		if (u32ParserBufAddr != 0) {
			VPAS_Write4Byte(REG_VPAS_VBUF2_WADR_LO, u32ParserBufAddr >> PAS_ADDR_SHIFT);
//wriu -w  0x23300e 0x0001
			VPAS_Write2Byte(REG_VPAS_BASE_CTRL, BIT_REG_VBUF2_WADR_RELOAD);
//wriu -w  0x233018 0x0000
//wriu -w  0x23301a 0x000c
//wriu -w  0x23301c 0x0000
//wriu -w  0x23301e 0x0008
			VPAS_Write4Byte(REG_VPAS_VBUF2_LBND_LO, u32ParserBufAddr >> PAS_ADDR_SHIFT);
			VPAS_Write4Byte(REG_VPAS_VBUF2_UBND_LO,
				(u32ParserBufAddr+u32ParserBufSize) >> PAS_ADDR_SHIFT);
		}
	}
}
EXPORT_SYMBOL(HAL_VPAS_SetBuf);

void HAL_VPAS_SetClk(u8 u8ParserID, u8 u8Enable)
{
	PAS_DEBUG_LOG(PAS_LOG_LEVEL_INFO, "u8ParserID=%u, u8Enable=%u\n", u8ParserID, u8Enable);
	if (u8Enable) {
		//wriu !Vw 0x10258c 0x4
		//CLKGEN_WriteWordMask(REG_VPAS_CKG, BIT_REG_PAS_CKG_EN, BIT_REG_PAS_CKG_EN);
	} else {
		//CLKGEN_WriteWordMask(REG_VPAS_CKG, ~BIT_REG_PAS_CKG_EN, BIT_REG_PAS_CKG_EN);
	}
}

void HAL_VPAS_GetWritePointer(u8 u8ParserID, u32 *param)
{
	u32 u32Ret = 0;
	u32 u32Ret1 = 0;
	u16 value = (VPAS_Read2Byte(REG_VPAS_VBUF_CADDR_CTRL) & (~0x30));

	value = value | ((u8ParserID & 0x3)<<4) | BIT_REG_VBUF_CADDR_RELOAD;
	VPAS_Write2Byte(REG_VPAS_VBUF_CADDR_CTRL, value);

	if (u8ParserID == 0) {
		u32Ret = VPAS_Read2Byte(REG_VPAS_VBUF_CADDR_LO);
		u32Ret1 = (VPAS_Read2Byte(REG_VPAS_VBUF_CADDR_HI));
		*param = ((u32Ret1<<16) | u32Ret);
	} else if (u8ParserID == 1) {
		u32Ret = VPAS_Read2Byte(REG_VPAS_VBUF_CADDR_LO);
		u32Ret1 = (VPAS_Read2Byte(REG_VPAS_VBUF_CADDR_HI));
		*param = ((u32Ret1<<16) | u32Ret);
	}
}
EXPORT_SYMBOL(HAL_VPAS_GetWritePointer);

u8 HAL_VPAS_Sel_Interrupt(void)
{
	u8 u8interrupt1;
	u8 u8interrupt2;
	u8 u8Ret = 0;

	if (u64RiuVPASBaseAdd == 0) {
		PAS_DEBUG_LOG(PAS_LOG_LEVEL_WARN, "u64RiuVPASBaseAdd == 0\n");
		return 0;
	}

	if (VPAS_Read2Byte(REG_VPAS_PAS1_CLR_INT) & BIT_REG_PAS_HK_PTS_INT)
		u8interrupt1 = true;
	else
		u8interrupt1 = false;
	if (VPAS_Read2Byte(REG_VPAS_PAS2_CLR_INT) & BIT_REG_PAS_HK_PTS_INT)
		u8interrupt2 = true;
	else
		u8interrupt2 = false;

	if (u8interrupt1 == 1)
		u8Ret |= (1 << E_VPAS1_DEV);
	if (u8interrupt2 == 1)
		u8Ret |= (1 << E_VPAS2_DEV);

	return u8Ret;
}
EXPORT_SYMBOL(HAL_VPAS_Sel_Interrupt);

u64 HAL_VPAS_ReadPTS(u8 u8ParserID)
{
	u64 u64Pts = 0;

	if (u8ParserID == 0)
		u64Pts = ((u64)(VPAS_Read4Byte(REG_VPAS_PAS1_HK_PTS_HI)&0x1)<<32)|
			VPAS_Read4Byte(REG_VPAS_PAS1_HK_PTS_LO);
	else if (u8ParserID == 1)
		u64Pts = ((u64)(VPAS_Read4Byte(REG_VPAS_PAS2_HK_PTS_HI)&0x1)<<32)|
			VPAS_Read4Byte(REG_VPAS_PAS2_HK_PTS_LO);

	return u64Pts;
}
EXPORT_SYMBOL(HAL_VPAS_ReadPTS);

bool HAL_VPAS_RegSetBase(void)
{
	u64RiuCLKGENBaseAdd = (u64)REG_PAS0_BASE;
	u64RiuVPASBaseAdd = (u64)REG_PAS0_BASE;
	if (u64RiuCLKGENBaseAdd == 0 || u64RiuVPASBaseAdd == 0) {
		PAS_DEBUG_LOG(PAS_LOG_LEVEL_WARN,
			"u64RiuCLKGENBaseAdd == 0x%llx, u64RiuVPASBaseAdd = 0x%llx\n",
			u64RiuCLKGENBaseAdd,
			u64RiuVPASBaseAdd);
		return false;
	}
	return true;
}
EXPORT_SYMBOL(HAL_VPAS_RegSetBase);

void HAL_VPAS_CLR_Interrupt(u8 u8ParserID)
{
	if (u64RiuVPASBaseAdd == 0) {
		PAS_DEBUG_LOG(PAS_LOG_LEVEL_WARN, "u64RiuVPASBaseAdd == 0\n");
		return;
	}
	if (u8ParserID == 0) {
		VPAS_WriteWordMask(REG_VPAS_INT_CTRL,
			BIT_REG_VD_PAS_INT_CLR, BIT_REG_VD_PAS_INT_CLR);
		VPAS_WriteWordMask(REG_VPAS_PAS1_CLR_INT,
			BIT_REG_PAS_HK_CLR_PTS_INT, BIT_REG_PAS_HK_CLR_PTS_INT);
	} else if (u8ParserID == 1) {
		VPAS_WriteWordMask(REG_VPAS_INT_CTRL,
			BIT_REG_VD_PAS_INT_CLR, BIT_REG_VD_PAS_INT_CLR);
		VPAS_WriteWordMask(REG_VPAS_PAS2_CLR_INT,
		BIT_REG_PAS_HK_CLR_PTS_INT, BIT_REG_PAS_HK_CLR_PTS_INT);
	}
}
EXPORT_SYMBOL(HAL_VPAS_CLR_Interrupt);

void HAL_VPAS_GetByteCount(u8 u8ParserID, u32 *param)
{
	u32 u32Ret = 0;
	u32 u32Ret1 = 0;

	if (u8ParserID == 0) {
		u32Ret = VPAS_Read2Byte(REG_VPAS_PAS1_ES_CNT_LO);
		u32Ret1 = (VPAS_Read2Byte(REG_VPAS_PAS1_ES_CNT_HI) & 0x3FF);
		*param = ((u32Ret1<<16) | u32Ret);
	} else if (u8ParserID == 1) {
		u32Ret = VPAS_Read2Byte(REG_VPAS_PAS2_ES_CNT_LO);
		u32Ret1 = (VPAS_Read2Byte(REG_VPAS_PAS2_ES_CNT_HI) & 0x3FF);
		*param = ((u32Ret1<<16) | u32Ret);
	}
	VPAS_WriteByteMask(REG_VPAS_PAS1_CTRL,
		BIT_REG_PAS_HK_CLR_ES_COUNTER, BIT_REG_PAS_HK_CLR_ES_COUNTER);
}
EXPORT_SYMBOL(HAL_VPAS_GetByteCount);

void HAL_VPAS_SetAid(u8 u8ParserID, u32 *param)
{
	if (u8ParserID == 0) {
		VPAS_WriteWordMask(REG_VPAS_PAS1_P_FLAG,
			*param, BIT_REG_PAS_HK_P_FLAG_SW);
	} else if (u8ParserID == 1) {
		VPAS_WriteWordMask(REG_VPAS_PAS2_P_FLAG,
			*param, BIT_REG_PAS_HK_P_FLAG_SW);
	}
}
EXPORT_SYMBOL(HAL_VPAS_SetAid);

