/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
/*
 * Copyright (c) 2020 MediaTek Inc.
 */
#ifndef _MTK_TV_DRM_PQMAP_H_
#define _MTK_TV_DRM_PQMAP_H_
#include <linux/dma-buf.h>
#include <linux/workqueue.h>

#include <drm/mtk_tv_drm.h>

#include "pqmap_utility.h"
#include "mtk_tv_sm.h"
#include "mtk_tv_drm_metabuf.h"

//-------------------------------------------------------------------------------------------------
//  Defines
//-------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
//  Enum
//-------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
//  Structures
//-------------------------------------------------------------------------------------------------
struct mtk_pqmap_info {
	int init;
	void *pim_handle;
	void *pim_va;
	uint32_t pim_size;
};
struct mtk_pqmap_context {
	struct mtk_pqmap_info pqmap[MTK_DRM_PQMAP_NUM_MAX];

	uint16_t last_nums[MTK_DRM_PQMAP_NUM_MAX];
	struct mtk_tv_drm_metabuf last_metabuf;
	struct delayed_work dwork;
};

//-------------------------------------------------------------------------------------------------
//  Global Functions
//-------------------------------------------------------------------------------------------------
int mtk_tv_drm_pqmap_init(
	struct mtk_pqmap_context *pqmap_ctx,
	struct drm_mtk_tv_pqmap_param *param);

int mtk_tv_drm_pqmap_deinit(
	struct mtk_pqmap_context *pqmap_ctx);

int mtk_tv_drm_pqmap_suspend(
	struct mtk_pqmap_context *pqmap_ctx);

int mtk_tv_drm_pqmap_resume(
	struct mtk_pqmap_context *pqmap_ctx);

int mtk_tv_drm_pqmap_set_nodes(
	struct mtk_pqmap_context *pqmap_ctx,
	struct drm_mtk_tv_pqmap_node_dmafd *node_dmafd);

int mtk_tv_drm_pqmap_update(
	struct mtk_pqmap_context *pqmap_ctx,
	struct mtk_sm_context *ml_ctx,
	struct drm_mtk_tv_pqmap_node_array *node_array);

int mtk_tv_drm_pqmap_write_ml(
	struct mtk_pqmap_context *pqmap_ctx,
	struct mtk_sm_context *ml_ctx,
	uint16_t *node_num,
	uint16_t *node_buf);

int mtk_tv_drm_pqmap_check_buffer(
	void *buffer,
	uint32_t size);

// sysfs
ssize_t render_qmap_show(struct device *dev,
	struct device_attribute *attr, char *buf);

ssize_t render_qmap_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t count);

// ioctl
int mtk_tv_drm_pqmap_set_info_ioctl(
	struct drm_device *drm,
	void *data,
	struct drm_file *file_priv);

int mtk_tv_drm_pqmap_set_nodes_ioctl(
	struct drm_device *dev,
	void *data,
	struct drm_file *file_priv);

#endif //_MTK_TV_DRM_PQMAP_H_
