2023-06-07 08:59:29

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: [PATCH v2,0/10] media: mediatek: vcodec: separate encoder and decoder

With the driver more and more complex, encoder and decoder need to add more parameter
in shared struct 'mtk_vcodec_ctx' and 'mtk_vcodec_dev'. Encoder use about 40% and
decoder use 60% parameter. Need to allocate extra unused memory when encoder and decoder
working.

Separate encoder and decoder in different folder and use independent data struct.

patch 1 remove unused parameter.
patch 2~3 align fw and interrupt related interface.
patch 4~5 remove the dependency of debug log
patch 6~7 separate mtk_vcodec_ctx and mtk_vcodec_dev
patch 8 fix unreasonable parameter
patch 9 removed unused header files
patch 10 separate encoder and decoder in different folder
---
Changed from v1:
- Change pr_dbg to dev_dbg for mtk_v4l2_level and mtk_vcodec_dbg for patch 4.
- Change pr_err to dev_err for mtk_v4l2_err and mtk_vcodec_err for patch 5.
- Fix unreasonable parameter for patch 8.
---
Yunfei Dong (10):
media: mediatek: vcodec: remove unused parameter
media: mediatek: vcodec: align fw interface
media: mediatek: vcodec: re-write shared interface
media: mediatek: vcodec: remove the dependency of debug log
mediatek: vcodec: replace pr_* with dev_* for v4l2 debug message
mediatek: vcodec: separate struct mtk_vcodec_ctx
mediatek: vcodec: separate struct mtk_vcodec_dev
mediatek: vcodec: fix unreasonable parameter definition and style
mediatek: vcodec: remove unused include header
mediatek: vcodec: separete decoder and encoder

.../media/platform/mediatek/vcodec/Makefile | 55 +-
.../platform/mediatek/vcodec/common/Makefile | 21 +
.../vcodec/common/mtk_vcodec_com_drv.h | 147 +++++
.../vcodec/{ => common}/mtk_vcodec_dbgfs.c | 57 +-
.../vcodec/{ => common}/mtk_vcodec_dbgfs.h | 24 +-
.../vcodec/{ => common}/mtk_vcodec_fw.c | 21 +-
.../vcodec/{ => common}/mtk_vcodec_fw.h | 8 +-
.../vcodec/{ => common}/mtk_vcodec_fw_priv.h | 14 +-
.../vcodec/{ => common}/mtk_vcodec_fw_scp.c | 26 +-
.../vcodec/{ => common}/mtk_vcodec_fw_vpu.c | 64 +-
.../mediatek/vcodec/common/mtk_vcodec_intr.c | 68 +++
.../vcodec/{ => common}/mtk_vcodec_intr.h | 6 +-
.../mediatek/vcodec/common/mtk_vcodec_util.c | 165 ++++++
.../mediatek/vcodec/common/mtk_vcodec_util.h | 77 +++
.../platform/mediatek/vcodec/decoder/Makefile | 25 +
.../vcodec/{ => decoder}/mtk_vcodec_dec.c | 179 +++---
.../vcodec/{ => decoder}/mtk_vcodec_dec.h | 10 +-
.../vcodec/{ => decoder}/mtk_vcodec_dec_drv.c | 85 ++-
.../vcodec/decoder/mtk_vcodec_dec_drv.h | 306 ++++++++++
.../vcodec/{ => decoder}/mtk_vcodec_dec_hw.c | 16 +-
.../vcodec/{ => decoder}/mtk_vcodec_dec_hw.h | 6 +-
.../vcodec/{ => decoder}/mtk_vcodec_dec_pm.c | 43 +-
.../vcodec/{ => decoder}/mtk_vcodec_dec_pm.h | 6 +-
.../{ => decoder}/mtk_vcodec_dec_stateful.c | 118 ++--
.../{ => decoder}/mtk_vcodec_dec_stateless.c | 77 +--
.../{ => decoder}/vdec/vdec_av1_req_lat_if.c | 152 +++--
.../vcodec/{ => decoder}/vdec/vdec_h264_if.c | 71 ++-
.../{ => decoder}/vdec/vdec_h264_req_common.c | 4 +-
.../{ => decoder}/vdec/vdec_h264_req_common.h | 6 +-
.../{ => decoder}/vdec/vdec_h264_req_if.c | 54 +-
.../vdec/vdec_h264_req_multi_if.c | 102 ++--
.../vdec/vdec_hevc_req_multi_if.c | 90 +--
.../vcodec/{ => decoder}/vdec/vdec_vp8_if.c | 82 +--
.../{ => decoder}/vdec/vdec_vp8_req_if.c | 59 +-
.../vcodec/{ => decoder}/vdec/vdec_vp9_if.c | 162 +++---
.../{ => decoder}/vdec/vdec_vp9_req_lat_if.c | 105 ++--
.../vcodec/{ => decoder}/vdec_drv_base.h | 2 +-
.../vcodec/{ => decoder}/vdec_drv_if.c | 13 +-
.../vcodec/{ => decoder}/vdec_drv_if.h | 10 +-
.../vcodec/{ => decoder}/vdec_ipi_msg.h | 0
.../vcodec/{ => decoder}/vdec_msg_queue.c | 49 +-
.../vcodec/{ => decoder}/vdec_msg_queue.h | 12 +-
.../vcodec/{ => decoder}/vdec_vpu_if.c | 66 ++-
.../vcodec/{ => decoder}/vdec_vpu_if.h | 6 +-
.../platform/mediatek/vcodec/encoder/Makefile | 11 +
.../vcodec/{ => encoder}/mtk_vcodec_enc.c | 278 +++++----
.../vcodec/{ => encoder}/mtk_vcodec_enc.h | 12 +-
.../vcodec/{ => encoder}/mtk_vcodec_enc_drv.c | 68 +--
.../vcodec/encoder/mtk_vcodec_enc_drv.h | 245 ++++++++
.../vcodec/{ => encoder}/mtk_vcodec_enc_pm.c | 17 +-
.../vcodec/{ => encoder}/mtk_vcodec_enc_pm.h | 4 +-
.../vcodec/{ => encoder}/venc/venc_h264_if.c | 106 ++--
.../vcodec/{ => encoder}/venc/venc_vp8_if.c | 64 +-
.../vcodec/{ => encoder}/venc_drv_base.h | 4 +-
.../vcodec/{ => encoder}/venc_drv_if.c | 10 +-
.../vcodec/{ => encoder}/venc_drv_if.h | 11 +-
.../vcodec/{ => encoder}/venc_ipi_msg.h | 0
.../vcodec/{ => encoder}/venc_vpu_if.c | 67 ++-
.../vcodec/{ => encoder}/venc_vpu_if.h | 3 +-
.../platform/mediatek/vcodec/mtk_vcodec_drv.h | 548 ------------------
.../mediatek/vcodec/mtk_vcodec_intr.c | 43 --
.../mediatek/vcodec/mtk_vcodec_util.c | 143 -----
.../mediatek/vcodec/mtk_vcodec_util.h | 83 ---
63 files changed, 2400 insertions(+), 1986 deletions(-)
create mode 100644 drivers/media/platform/mediatek/vcodec/common/Makefile
create mode 100644 drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_com_drv.h
rename drivers/media/platform/mediatek/vcodec/{ => common}/mtk_vcodec_dbgfs.c (76%)
rename drivers/media/platform/mediatek/vcodec/{ => common}/mtk_vcodec_dbgfs.h (62%)
rename drivers/media/platform/mediatek/vcodec/{ => common}/mtk_vcodec_fw.c (75%)
rename drivers/media/platform/mediatek/vcodec/{ => common}/mtk_vcodec_fw.h (86%)
rename drivers/media/platform/mediatek/vcodec/{ => common}/mtk_vcodec_fw_priv.h (75%)
rename drivers/media/platform/mediatek/vcodec/{ => common}/mtk_vcodec_fw_scp.c (70%)
rename drivers/media/platform/mediatek/vcodec/{ => common}/mtk_vcodec_fw_vpu.c (58%)
create mode 100644 drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_intr.c
rename drivers/media/platform/mediatek/vcodec/{ => common}/mtk_vcodec_intr.h (68%)
create mode 100644 drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.c
create mode 100644 drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_util.h
create mode 100644 drivers/media/platform/mediatek/vcodec/decoder/Makefile
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/mtk_vcodec_dec.c (83%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/mtk_vcodec_dec.h (91%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/mtk_vcodec_dec_drv.c (83%)
create mode 100644 drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/mtk_vcodec_dec_hw.c (92%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/mtk_vcodec_dec_hw.h (92%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/mtk_vcodec_dec_pm.c (78%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/mtk_vcodec_dec_pm.h (61%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/mtk_vcodec_dec_stateful.c (79%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/mtk_vcodec_dec_stateless.c (85%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec/vdec_av1_req_lat_if.c (92%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec/vdec_h264_if.c (82%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec/vdec_h264_req_common.c (98%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec/vdec_h264_req_common.h (97%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec/vdec_h264_req_if.c (87%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec/vdec_h264_req_multi_if.c (87%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec/vdec_hevc_req_multi_if.c (91%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec/vdec_vp8_if.c (83%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec/vdec_vp8_req_if.c (83%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec/vdec_vp9_if.c (82%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec/vdec_vp9_req_lat_if.c (94%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec_drv_base.h (95%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec_drv_if.c (85%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec_drv_if.h (89%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec_ipi_msg.h (100%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec_msg_queue.c (85%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec_msg_queue.h (96%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec_vpu_if.c (71%)
rename drivers/media/platform/mediatek/vcodec/{ => decoder}/vdec_vpu_if.h (97%)
create mode 100644 drivers/media/platform/mediatek/vcodec/encoder/Makefile
rename drivers/media/platform/mediatek/vcodec/{ => encoder}/mtk_vcodec_enc.c (82%)
rename drivers/media/platform/mediatek/vcodec/{ => encoder}/mtk_vcodec_enc.h (78%)
rename drivers/media/platform/mediatek/vcodec/{ => encoder}/mtk_vcodec_enc_drv.c (87%)
create mode 100644 drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h
rename drivers/media/platform/mediatek/vcodec/{ => encoder}/mtk_vcodec_enc_pm.c (77%)
rename drivers/media/platform/mediatek/vcodec/{ => encoder}/mtk_vcodec_enc_pm.h (78%)
rename drivers/media/platform/mediatek/vcodec/{ => encoder}/venc/venc_h264_if.c (85%)
rename drivers/media/platform/mediatek/vcodec/{ => encoder}/venc/venc_vp8_if.c (84%)
rename drivers/media/platform/mediatek/vcodec/{ => encoder}/venc_drv_base.h (94%)
rename drivers/media/platform/mediatek/vcodec/{ => encoder}/venc_drv_if.c (86%)
rename drivers/media/platform/mediatek/vcodec/{ => encoder}/venc_drv_if.h (94%)
rename drivers/media/platform/mediatek/vcodec/{ => encoder}/venc_ipi_msg.h (100%)
rename drivers/media/platform/mediatek/vcodec/{ => encoder}/venc_vpu_if.c (77%)
rename drivers/media/platform/mediatek/vcodec/{ => encoder}/venc_vpu_if.h (96%)
delete mode 100644 drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
delete mode 100644 drivers/media/platform/mediatek/vcodec/mtk_vcodec_intr.c
delete mode 100644 drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.c
delete mode 100644 drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h

--
2.18.0



2023-06-07 09:01:46

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: [PATCH v2,06/10] mediatek: vcodec: separate struct mtk_vcodec_ctx

Adding different context struct for encoder and decoder, remove
'struct mtk_vcodec_ctx'.

Signed-off-by: Yunfei Dong <[email protected]>
---
.../mediatek/vcodec/mtk_vcodec_com_drv.h | 76 +++++
.../mediatek/vcodec/mtk_vcodec_dbgfs.c | 6 +-
.../mediatek/vcodec/mtk_vcodec_dbgfs.h | 10 +-
.../platform/mediatek/vcodec/mtk_vcodec_dec.c | 60 ++--
.../platform/mediatek/vcodec/mtk_vcodec_dec.h | 10 +-
.../mediatek/vcodec/mtk_vcodec_dec_drv.c | 8 +-
.../mediatek/vcodec/mtk_vcodec_dec_drv.h | 158 ++++++++++
.../mediatek/vcodec/mtk_vcodec_dec_hw.c | 4 +-
.../mediatek/vcodec/mtk_vcodec_dec_hw.h | 2 +-
.../mediatek/vcodec/mtk_vcodec_dec_pm.c | 8 +-
.../mediatek/vcodec/mtk_vcodec_dec_pm.h | 4 +-
.../mediatek/vcodec/mtk_vcodec_dec_stateful.c | 28 +-
.../vcodec/mtk_vcodec_dec_stateless.c | 22 +-
.../platform/mediatek/vcodec/mtk_vcodec_drv.h | 269 +-----------------
.../platform/mediatek/vcodec/mtk_vcodec_enc.c | 78 ++---
.../platform/mediatek/vcodec/mtk_vcodec_enc.h | 12 +-
.../mediatek/vcodec/mtk_vcodec_enc_drv.c | 10 +-
.../mediatek/vcodec/mtk_vcodec_enc_drv.h | 158 ++++++++++
.../mediatek/vcodec/mtk_vcodec_fw_vpu.c | 25 +-
.../mediatek/vcodec/mtk_vcodec_intr.c | 33 ++-
.../mediatek/vcodec/mtk_vcodec_intr.h | 3 +-
.../mediatek/vcodec/mtk_vcodec_util.c | 62 ++--
.../mediatek/vcodec/mtk_vcodec_util.h | 8 +-
.../vcodec/vdec/vdec_av1_req_lat_if.c | 22 +-
.../mediatek/vcodec/vdec/vdec_h264_if.c | 6 +-
.../vcodec/vdec/vdec_h264_req_common.c | 4 +-
.../vcodec/vdec/vdec_h264_req_common.h | 4 +-
.../mediatek/vcodec/vdec/vdec_h264_req_if.c | 8 +-
.../vcodec/vdec/vdec_h264_req_multi_if.c | 10 +-
.../vcodec/vdec/vdec_hevc_req_multi_if.c | 16 +-
.../mediatek/vcodec/vdec/vdec_vp8_if.c | 4 +-
.../mediatek/vcodec/vdec/vdec_vp8_req_if.c | 10 +-
.../mediatek/vcodec/vdec/vdec_vp9_if.c | 8 +-
.../vcodec/vdec/vdec_vp9_req_lat_if.c | 18 +-
.../platform/mediatek/vcodec/vdec_drv_base.h | 2 +-
.../platform/mediatek/vcodec/vdec_drv_if.c | 8 +-
.../platform/mediatek/vcodec/vdec_drv_if.h | 8 +-
.../platform/mediatek/vcodec/vdec_msg_queue.c | 8 +-
.../platform/mediatek/vcodec/vdec_msg_queue.h | 8 +-
.../platform/mediatek/vcodec/vdec_vpu_if.h | 4 +-
.../mediatek/vcodec/venc/venc_h264_if.c | 12 +-
.../mediatek/vcodec/venc/venc_vp8_if.c | 8 +-
.../platform/mediatek/vcodec/venc_drv_base.h | 2 +-
.../platform/mediatek/vcodec/venc_drv_if.c | 14 +-
.../platform/mediatek/vcodec/venc_drv_if.h | 8 +-
.../platform/mediatek/vcodec/venc_vpu_if.h | 2 +-
46 files changed, 730 insertions(+), 518 deletions(-)
create mode 100644 drivers/media/platform/mediatek/vcodec/mtk_vcodec_com_drv.h
create mode 100644 drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.h
create mode 100644 drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.h

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_com_drv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_com_drv.h
new file mode 100644
index 000000000000..3b6e1faf60ce
--- /dev/null
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_com_drv.h
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ * Author: Yunfei Dong <[email protected]>
+ */
+
+#ifndef _MTK_VCODEC_COM_DRV_H_
+#define _MTK_VCODEC_COM_DRV_H_
+
+#include <linux/platform_device.h>
+#include <linux/videodev2.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-ioctl.h>
+#include <media/v4l2-mem2mem.h>
+#include <media/videobuf2-core.h>
+
+#define MTK_VCODEC_MAX_PLANES 3
+
+/**
+ * enum mtk_instance_state - The state of an MTK Vcodec instance.
+ * @MTK_STATE_FREE: default state when instance is created
+ * @MTK_STATE_INIT: vcodec instance is initialized
+ * @MTK_STATE_HEADER: vdec had sps/pps header parsed or venc
+ * had sps/pps header encoded
+ * @MTK_STATE_FLUSH: vdec is flushing. Only used by decoder
+ * @MTK_STATE_ABORT: vcodec should be aborted
+ */
+enum mtk_instance_state {
+ MTK_STATE_FREE = 0,
+ MTK_STATE_INIT = 1,
+ MTK_STATE_HEADER = 2,
+ MTK_STATE_FLUSH = 3,
+ MTK_STATE_ABORT = 4,
+};
+
+enum mtk_fmt_type {
+ MTK_FMT_DEC = 0,
+ MTK_FMT_ENC = 1,
+ MTK_FMT_FRAME = 2,
+};
+
+/*
+ * struct mtk_video_fmt - Structure used to store information about pixelformats
+ */
+struct mtk_video_fmt {
+ u32 fourcc;
+ enum mtk_fmt_type type;
+ u32 num_planes;
+ u32 flags;
+ struct v4l2_frmsize_stepwise frmsize;
+};
+
+/*
+ * struct mtk_q_data - Structure used to store information about queue
+ */
+struct mtk_q_data {
+ unsigned int visible_width;
+ unsigned int visible_height;
+ unsigned int coded_width;
+ unsigned int coded_height;
+ enum v4l2_field field;
+ unsigned int bytesperline[MTK_VCODEC_MAX_PLANES];
+ unsigned int sizeimage[MTK_VCODEC_MAX_PLANES];
+ const struct mtk_video_fmt *fmt;
+};
+
+/*
+ * enum mtk_instance_type - The type of an MTK Vcodec instance.
+ */
+enum mtk_instance_type {
+ MTK_INST_DECODER = 0,
+ MTK_INST_ENCODER = 1,
+};
+
+#endif /* _MTK_VCODEC_COM_DRV_H_ */
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c
index 2151c3967684..b88fc0a0c102 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c
@@ -10,7 +10,7 @@
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_util.h"

-static void mtk_vdec_dbgfs_get_format_type(struct mtk_vcodec_ctx *ctx, char *buf,
+static void mtk_vdec_dbgfs_get_format_type(struct mtk_vcodec_dec_ctx *ctx, char *buf,
int *used, int total)
{
int curr_len;
@@ -91,7 +91,7 @@ static ssize_t mtk_vdec_dbgfs_read(struct file *filp, char __user *ubuf,
struct mtk_vcodec_dev *vcodec_dev = filp->private_data;
struct mtk_vcodec_dbgfs *dbgfs = &vcodec_dev->dbgfs;
struct mtk_vcodec_dbgfs_inst *dbgfs_inst;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
int total_len = 200 * (dbgfs->inst_count == 0 ? 1 : dbgfs->inst_count);
int used_len = 0, curr_len, ret;
bool dbgfs_index[MTK_VDEC_DBGFS_MAX] = {0};
@@ -143,7 +143,7 @@ static const struct file_operations vdec_fops = {
.read = mtk_vdec_dbgfs_read,
};

-void mtk_vcodec_dbgfs_create(struct mtk_vcodec_ctx *ctx)
+void mtk_vcodec_dbgfs_create(struct mtk_vcodec_dec_ctx *ctx)
{
struct mtk_vcodec_dbgfs_inst *dbgfs_inst;
struct mtk_vcodec_dev *vcodec_dev = ctx->dev;
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.h
index 241ff8197e73..372413d590c5 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.h
@@ -8,7 +8,7 @@
#define __MTK_VCODEC_DBGFS_H__

struct mtk_vcodec_dev;
-struct mtk_vcodec_ctx;
+struct mtk_vcodec_dec_ctx;

/*
* enum mtk_vdec_dbgfs_log_index - used to get different debug information
@@ -22,12 +22,12 @@ enum mtk_vdec_dbgfs_log_index {
/**
* struct mtk_vcodec_dbgfs_inst - debugfs information for each inst
* @node: list node for each inst
- * @vcodec_ctx: struct mtk_vcodec_ctx
+ * @vcodec_ctx: struct mtk_vcodec_dec_ctx
* @inst_id: index of the context that the same with ctx->id
*/
struct mtk_vcodec_dbgfs_inst {
struct list_head node;
- struct mtk_vcodec_ctx *vcodec_ctx;
+ struct mtk_vcodec_dec_ctx *vcodec_ctx;
int inst_id;
};

@@ -50,12 +50,12 @@ struct mtk_vcodec_dbgfs {
};

#if defined(CONFIG_DEBUG_FS)
-void mtk_vcodec_dbgfs_create(struct mtk_vcodec_ctx *ctx);
+void mtk_vcodec_dbgfs_create(struct mtk_vcodec_dec_ctx *ctx);
void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id);
void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev, bool is_encode);
void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dev *vcodec_dev);
#else
-static inline void mtk_vcodec_dbgfs_create(struct mtk_vcodec_ctx *ctx)
+static inline void mtk_vcodec_dbgfs_create(struct mtk_vcodec_dec_ctx *ctx)
{
}

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c
index aae89a82d2a5..1a9887fe1a53 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c
@@ -35,7 +35,7 @@ mtk_vdec_find_format(struct v4l2_format *f,
return NULL;
}

-static bool mtk_vdec_get_cap_fmt(struct mtk_vcodec_ctx *ctx, int format_index)
+static bool mtk_vdec_get_cap_fmt(struct mtk_vcodec_dec_ctx *ctx, int format_index)
{
const struct mtk_vcodec_dec_pdata *dec_pdata = ctx->dev->vdec_pdata;
const struct mtk_video_fmt *fmt;
@@ -55,7 +55,7 @@ static bool mtk_vdec_get_cap_fmt(struct mtk_vcodec_ctx *ctx, int format_index)
return false;
}

-static struct mtk_q_data *mtk_vdec_get_q_data(struct mtk_vcodec_ctx *ctx,
+static struct mtk_q_data *mtk_vdec_get_q_data(struct mtk_vcodec_dec_ctx *ctx,
enum v4l2_buf_type type)
{
if (V4L2_TYPE_IS_OUTPUT(type))
@@ -74,7 +74,7 @@ static int vidioc_try_decoder_cmd(struct file *file, void *priv,
static int vidioc_decoder_cmd(struct file *file, void *priv,
struct v4l2_decoder_cmd *cmd)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
struct vb2_queue *src_vq, *dst_vq;
int ret;

@@ -114,23 +114,23 @@ static int vidioc_decoder_cmd(struct file *file, void *priv,
return 0;
}

-void mtk_vdec_unlock(struct mtk_vcodec_ctx *ctx)
+void mtk_vdec_unlock(struct mtk_vcodec_dec_ctx *ctx)
{
mutex_unlock(&ctx->dev->dec_mutex[ctx->hw_id]);
}

-void mtk_vdec_lock(struct mtk_vcodec_ctx *ctx)
+void mtk_vdec_lock(struct mtk_vcodec_dec_ctx *ctx)
{
mutex_lock(&ctx->dev->dec_mutex[ctx->hw_id]);
}

-void mtk_vcodec_dec_release(struct mtk_vcodec_ctx *ctx)
+void mtk_vcodec_dec_release(struct mtk_vcodec_dec_ctx *ctx)
{
vdec_if_deinit(ctx);
ctx->state = MTK_STATE_FREE;
}

-void mtk_vcodec_dec_set_default_params(struct mtk_vcodec_ctx *ctx)
+void mtk_vcodec_dec_set_default_params(struct mtk_vcodec_dec_ctx *ctx)
{
struct mtk_q_data *q_data;

@@ -171,7 +171,7 @@ void mtk_vcodec_dec_set_default_params(struct mtk_vcodec_ctx *ctx)
static int vidioc_vdec_qbuf(struct file *file, void *priv,
struct v4l2_buffer *buf)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);

if (ctx->state == MTK_STATE_ABORT) {
mtk_v4l2_err(ctx->dev->plat_dev, "[%d] Call on QBUF after unrecoverable error",
@@ -185,7 +185,7 @@ static int vidioc_vdec_qbuf(struct file *file, void *priv,
static int vidioc_vdec_dqbuf(struct file *file, void *priv,
struct v4l2_buffer *buf)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);

if (ctx->state == MTK_STATE_ABORT) {
mtk_v4l2_err(ctx->dev->plat_dev, "[%d] Call on DQBUF after unrecoverable error",
@@ -198,7 +198,7 @@ static int vidioc_vdec_dqbuf(struct file *file, void *priv,

static int mtk_vcodec_dec_get_chip_name(void *priv)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
struct device *dev = &ctx->dev->plat_dev->dev;

if (of_device_is_compatible(dev->of_node, "mediatek,mt8173-vcodec-dec"))
@@ -220,7 +220,7 @@ static int mtk_vcodec_dec_get_chip_name(void *priv)
static int vidioc_vdec_querycap(struct file *file, void *priv,
struct v4l2_capability *cap)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
struct device *dev = &ctx->dev->plat_dev->dev;
int platform_name = mtk_vcodec_dec_get_chip_name(priv);

@@ -233,7 +233,7 @@ static int vidioc_vdec_querycap(struct file *file, void *priv,
static int vidioc_vdec_subscribe_evt(struct v4l2_fh *fh,
const struct v4l2_event_subscription *sub)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(fh);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(fh);

if (ctx->dev->vdec_pdata->uses_stateless_api)
return v4l2_ctrl_subscribe_event(fh, sub);
@@ -248,7 +248,7 @@ static int vidioc_vdec_subscribe_evt(struct v4l2_fh *fh,
}
}

-static int vidioc_try_fmt(struct mtk_vcodec_ctx *ctx, struct v4l2_format *f,
+static int vidioc_try_fmt(struct mtk_vcodec_dec_ctx *ctx, struct v4l2_format *f,
const struct mtk_video_fmt *fmt)
{
struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
@@ -316,7 +316,7 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *priv,
struct v4l2_format *f)
{
const struct mtk_video_fmt *fmt;
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
const struct mtk_vcodec_dec_pdata *dec_pdata = ctx->dev->vdec_pdata;

fmt = mtk_vdec_find_format(f, dec_pdata);
@@ -334,7 +334,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
{
struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
const struct mtk_video_fmt *fmt;
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
const struct mtk_vcodec_dec_pdata *dec_pdata = ctx->dev->vdec_pdata;

fmt = mtk_vdec_find_format(f, dec_pdata);
@@ -355,7 +355,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
static int vidioc_vdec_g_selection(struct file *file, void *priv,
struct v4l2_selection *s)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
struct mtk_q_data *q_data;

if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
@@ -404,7 +404,7 @@ static int vidioc_vdec_g_selection(struct file *file, void *priv,
static int vidioc_vdec_s_selection(struct file *file, void *priv,
struct v4l2_selection *s)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);

if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL;
@@ -426,7 +426,7 @@ static int vidioc_vdec_s_selection(struct file *file, void *priv,
static int vidioc_vdec_s_fmt(struct file *file, void *priv,
struct v4l2_format *f)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
struct v4l2_pix_format_mplane *pix_mp;
struct mtk_q_data *q_data;
int ret = 0;
@@ -555,7 +555,7 @@ static int vidioc_enum_framesizes(struct file *file, void *priv,
struct v4l2_frmsizeenum *fsize)
{
int i = 0;
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
const struct mtk_vcodec_dec_pdata *dec_pdata = ctx->dev->vdec_pdata;

if (fsize->index != 0)
@@ -587,7 +587,7 @@ static int vidioc_enum_framesizes(struct file *file, void *priv,
static int vidioc_enum_fmt(struct v4l2_fmtdesc *f, void *priv,
bool output_queue)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
const struct mtk_vcodec_dec_pdata *dec_pdata = ctx->dev->vdec_pdata;
const struct mtk_video_fmt *fmt;
int i, j = 0;
@@ -633,7 +633,7 @@ static int vidioc_vdec_enum_fmt_vid_out(struct file *file, void *priv,
static int vidioc_vdec_g_fmt(struct file *file, void *priv,
struct v4l2_format *f)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(priv);
struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
struct vb2_queue *vq;
struct mtk_q_data *q_data;
@@ -723,7 +723,7 @@ int vb2ops_vdec_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
unsigned int *nplanes, unsigned int sizes[],
struct device *alloc_devs[])
{
- struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(vq);
+ struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(vq);
struct mtk_q_data *q_data;
unsigned int i;

@@ -765,7 +765,7 @@ int vb2ops_vdec_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,

int vb2ops_vdec_buf_prepare(struct vb2_buffer *vb)
{
- struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+ struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct mtk_q_data *q_data;
int i;

@@ -790,7 +790,7 @@ int vb2ops_vdec_buf_prepare(struct vb2_buffer *vb)

void vb2ops_vdec_buf_finish(struct vb2_buffer *vb)
{
- struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+ struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct vb2_v4l2_buffer *vb2_v4l2;
struct mtk_video_dec_buf *buf;
bool buf_error;
@@ -828,7 +828,7 @@ int vb2ops_vdec_buf_init(struct vb2_buffer *vb)

int vb2ops_vdec_start_streaming(struct vb2_queue *q, unsigned int count)
{
- struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(q);
+ struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(q);

if (ctx->state == MTK_STATE_FLUSH)
ctx->state = MTK_STATE_HEADER;
@@ -839,7 +839,7 @@ int vb2ops_vdec_start_streaming(struct vb2_queue *q, unsigned int count)
void vb2ops_vdec_stop_streaming(struct vb2_queue *q)
{
struct vb2_v4l2_buffer *src_buf = NULL, *dst_buf = NULL;
- struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(q);
+ struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(q);
int ret;

mtk_v4l2_debug(ctx->dev->plat_dev, 3, "[%d] (%d) state=(%x) ctx->decoded_frame_cnt=%d",
@@ -894,7 +894,7 @@ void vb2ops_vdec_stop_streaming(struct vb2_queue *q)

static void m2mops_vdec_device_run(void *priv)
{
- struct mtk_vcodec_ctx *ctx = priv;
+ struct mtk_vcodec_dec_ctx *ctx = priv;
struct mtk_vcodec_dev *dev = ctx->dev;

queue_work(dev->decode_workqueue, &ctx->decode_work);
@@ -902,7 +902,7 @@ static void m2mops_vdec_device_run(void *priv)

static int m2mops_vdec_job_ready(void *m2m_priv)
{
- struct mtk_vcodec_ctx *ctx = m2m_priv;
+ struct mtk_vcodec_dec_ctx *ctx = m2m_priv;

mtk_v4l2_debug(ctx->dev->plat_dev, 3, "[%d]", ctx->id);

@@ -921,7 +921,7 @@ static int m2mops_vdec_job_ready(void *m2m_priv)

static void m2mops_vdec_job_abort(void *priv)
{
- struct mtk_vcodec_ctx *ctx = priv;
+ struct mtk_vcodec_dec_ctx *ctx = priv;

ctx->state = MTK_STATE_ABORT;
}
@@ -969,7 +969,7 @@ const struct v4l2_ioctl_ops mtk_vdec_ioctl_ops = {
int mtk_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq,
struct vb2_queue *dst_vq)
{
- struct mtk_vcodec_ctx *ctx = priv;
+ struct mtk_vcodec_dec_ctx *ctx = priv;
int ret = 0;

mtk_v4l2_debug(ctx->dev->plat_dev, 3, "[%d]", ctx->id);
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
index 4572f92826f2..ece27c880e50 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.h
@@ -11,6 +11,8 @@
#include <media/videobuf2-core.h>
#include <media/v4l2-mem2mem.h>

+#include "mtk_vcodec_dec_drv.h"
+
#define VCODEC_DEC_ALIGNED_64 64
#define VCODEC_CAPABILITY_4K_DISABLED 0x10
#define VCODEC_DEC_4K_CODED_WIDTH 4096U
@@ -78,12 +80,12 @@ extern const struct mtk_vcodec_dec_pdata mtk_vdec_single_core_pdata;
* mtk_vdec_lock get decoder hw lock and set curr_ctx
* to ctx instance that get lock
*/
-void mtk_vdec_unlock(struct mtk_vcodec_ctx *ctx);
-void mtk_vdec_lock(struct mtk_vcodec_ctx *ctx);
+void mtk_vdec_unlock(struct mtk_vcodec_dec_ctx *ctx);
+void mtk_vdec_lock(struct mtk_vcodec_dec_ctx *ctx);
int mtk_vcodec_dec_queue_init(void *priv, struct vb2_queue *src_vq,
struct vb2_queue *dst_vq);
-void mtk_vcodec_dec_set_default_params(struct mtk_vcodec_ctx *ctx);
-void mtk_vcodec_dec_release(struct mtk_vcodec_ctx *ctx);
+void mtk_vcodec_dec_set_default_params(struct mtk_vcodec_dec_ctx *ctx);
+void mtk_vcodec_dec_release(struct mtk_vcodec_dec_ctx *ctx);

/*
* VB2 ops
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
index b79470da72ba..b809a30f913d 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
@@ -42,7 +42,7 @@ static int mtk_vcodec_get_hw_count(struct mtk_vcodec_dev *dev)
static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv)
{
struct mtk_vcodec_dev *dev = priv;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
u32 cg_status = 0;
unsigned int dec_done_status = 0;
void __iomem *vdec_misc_addr = dev->reg_base[VDEC_MISC] +
@@ -70,7 +70,7 @@ static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv)
writel((readl(vdec_misc_addr) & ~VDEC_IRQ_CLR),
dev->reg_base[VDEC_MISC] + VDEC_IRQ_CFG_REG);

- wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0);
+ wake_up_dec_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0);

mtk_v4l2_debug(dev->plat_dev, 3, "wake up ctx %d, dec_done_status=%x",
ctx->id, dec_done_status);
@@ -140,7 +140,7 @@ static int mtk_vcodec_init_dec_resources(struct mtk_vcodec_dev *dev)
static int fops_vcodec_open(struct file *file)
{
struct mtk_vcodec_dev *dev = video_drvdata(file);
- struct mtk_vcodec_ctx *ctx = NULL;
+ struct mtk_vcodec_dec_ctx *ctx = NULL;
int ret = 0, i, hw_count;
struct vb2_queue *src_vq;

@@ -238,7 +238,7 @@ static int fops_vcodec_open(struct file *file)
static int fops_vcodec_release(struct file *file)
{
struct mtk_vcodec_dev *dev = video_drvdata(file);
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(file->private_data);
+ struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(file->private_data);

mtk_v4l2_debug(dev->plat_dev, 0, "[%d] decoder", ctx->id);
mutex_lock(&dev->dev_mutex);
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.h
new file mode 100644
index 000000000000..94870b651919
--- /dev/null
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.h
@@ -0,0 +1,158 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ * Author: Yunfei Dong <[email protected]>
+ */
+
+#ifndef _MTK_VCODEC_DEC_DRV_H_
+#define _MTK_VCODEC_DEC_DRV_H_
+
+#include "mtk_vcodec_com_drv.h"
+#include "mtk_vcodec_fw_priv.h"
+#include "vdec_msg_queue.h"
+
+/**
+ * struct vdec_pic_info - picture size information
+ * @pic_w: picture width
+ * @pic_h: picture height
+ * @buf_w: picture buffer width (64 aligned up from pic_w)
+ * @buf_h: picture buffer heiht (64 aligned up from pic_h)
+ * @fb_sz: bitstream size of each plane
+ * E.g. suppose picture size is 176x144,
+ * buffer size will be aligned to 176x160.
+ * @cap_fourcc: fourcc number(may changed when resolution change)
+ * @reserved: align struct to 64-bit in order to adjust 32-bit and 64-bit os.
+ */
+struct vdec_pic_info {
+ unsigned int pic_w;
+ unsigned int pic_h;
+ unsigned int buf_w;
+ unsigned int buf_h;
+ unsigned int fb_sz[VIDEO_MAX_PLANES];
+ unsigned int cap_fourcc;
+ unsigned int reserved;
+};
+
+/*
+ * enum mtk_vdec_hw_id - Hardware index used to separate
+ * different hardware
+ */
+enum mtk_vdec_hw_id {
+ MTK_VDEC_CORE,
+ MTK_VDEC_LAT0,
+ MTK_VDEC_LAT1,
+ MTK_VDEC_LAT_SOC,
+ MTK_VDEC_HW_MAX,
+};
+
+/**
+ * struct mtk_vcodec_dec_ctx - Context (instance) private data.
+ *
+ * @type: type of the instance - decoder or encoder
+ * @dev: pointer to the mtk_vcodec_dev of the device
+ * @list: link to ctx_list of mtk_vcodec_dev
+ *
+ * @fh: struct v4l2_fh
+ * @m2m_ctx: pointer to the v4l2_m2m_ctx of the context
+ * @q_data: store information of input and output queue
+ * of the context
+ * @id: index of the context that this structure describes
+ * @state: state of the context
+ *
+ * @dec_if: hooked decoder driver interface
+ * @drv_handle: driver handle for specific decode/encode instance
+ *
+ * @picinfo: store picture info after header parsing
+ * @dpb_size: store dpb count after header parsing
+ *
+ * @int_cond: variable used by the waitqueue
+ * @int_type: type of the last interrupt
+ * @queue: waitqueue that can be used to wait for this context to
+ * finish
+ * @irq_status: irq status
+ *
+ * @ctrl_hdl: handler for v4l2 framework
+ * @decode_work: worker for the decoding
+ * @last_decoded_picinfo: pic information get from latest decode
+ * @empty_flush_buf: a fake size-0 capture buffer that indicates flush. Only
+ * to be used with encoder and stateful decoder.
+ * @is_flushing: set to true if flushing is in progress.
+ *
+ * @current_codec: current set input codec, in V4L2 pixel format
+ * @capture_fourcc: capture queue type in V4L2 pixel format
+ *
+ * @colorspace: enum v4l2_colorspace; supplemental to pixelformat
+ * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
+ * @quantization: enum v4l2_quantization, colorspace quantization
+ * @xfer_func: enum v4l2_xfer_func, colorspace transfer function
+ *
+ * @decoded_frame_cnt: number of decoded frames
+ * @lock: protect variables accessed by V4L2 threads and worker thread such as
+ * mtk_video_dec_buf.
+ * @hw_id: hardware index used to identify different hardware.
+ *
+ * @msg_queue: msg queue used to store lat buffer information.
+ */
+struct mtk_vcodec_dec_ctx {
+ enum mtk_instance_type type;
+ struct mtk_vcodec_dev *dev;
+ struct list_head list;
+
+ struct v4l2_fh fh;
+ struct v4l2_m2m_ctx *m2m_ctx;
+ struct mtk_q_data q_data[2];
+ int id;
+ enum mtk_instance_state state;
+
+ const struct vdec_common_if *dec_if;
+ void *drv_handle;
+
+ struct vdec_pic_info picinfo;
+ int dpb_size;
+
+ int int_cond[MTK_VDEC_HW_MAX];
+ int int_type[MTK_VDEC_HW_MAX];
+ wait_queue_head_t queue[MTK_VDEC_HW_MAX];
+ unsigned int irq_status;
+
+ struct v4l2_ctrl_handler ctrl_hdl;
+ struct work_struct decode_work;
+ struct vdec_pic_info last_decoded_picinfo;
+ struct v4l2_m2m_buffer empty_flush_buf;
+ bool is_flushing;
+
+ u32 current_codec;
+ u32 capture_fourcc;
+
+ enum v4l2_colorspace colorspace;
+ enum v4l2_ycbcr_encoding ycbcr_enc;
+ enum v4l2_quantization quantization;
+ enum v4l2_xfer_func xfer_func;
+
+ int decoded_frame_cnt;
+ struct mutex lock;
+ int hw_id;
+
+ struct vdec_msg_queue msg_queue;
+};
+
+static inline struct mtk_vcodec_dec_ctx *fh_to_dec_ctx(struct v4l2_fh *fh)
+{
+ return container_of(fh, struct mtk_vcodec_dec_ctx, fh);
+}
+
+static inline struct mtk_vcodec_dec_ctx *ctrl_to_dec_ctx(struct v4l2_ctrl *ctrl)
+{
+ return container_of(ctrl->handler, struct mtk_vcodec_dec_ctx, ctrl_hdl);
+}
+
+/* Wake up context wait_queue */
+static inline void
+wake_up_dec_ctx(struct mtk_vcodec_dec_ctx *ctx, unsigned int reason, unsigned int hw_id)
+{
+ ctx->int_cond[hw_id] = 1;
+ ctx->int_type[hw_id] = reason;
+ wake_up_interruptible(&ctx->queue[hw_id]);
+}
+
+#endif /* _MTK_VCODEC_DEC_DRV_H_ */
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c
index 2ed2ac1521fb..3714e3956ead 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c
@@ -66,7 +66,7 @@ static int mtk_vdec_hw_prob_done(struct mtk_vcodec_dev *vdec_dev)
static irqreturn_t mtk_vdec_hw_irq_handler(int irq, void *priv)
{
struct mtk_vdec_hw_dev *dev = priv;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
u32 cg_status;
unsigned int dec_done_status;
void __iomem *vdec_misc_addr = dev->reg_base[VDEC_HW_MISC] +
@@ -91,7 +91,7 @@ static irqreturn_t mtk_vdec_hw_irq_handler(int irq, void *priv)
writel(dec_done_status | VDEC_IRQ_CFG, vdec_misc_addr);
writel(dec_done_status & ~VDEC_IRQ_CLR, vdec_misc_addr);

- wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, dev->hw_idx);
+ wake_up_dec_ctx(ctx, MTK_INST_IRQ_RECEIVED, dev->hw_idx);

mtk_v4l2_debug(dev->plat_dev, 3, "wake up ctx %d, dec_done_status=%x",
ctx->id, dec_done_status);
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.h
index 36faa8d9d681..d62c7f961cfa 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.h
@@ -48,7 +48,7 @@ struct mtk_vdec_hw_dev {
struct mtk_vcodec_dev *main_dev;
void __iomem *reg_base[VDEC_HW_MAX];

- struct mtk_vcodec_ctx *curr_ctx;
+ struct mtk_vcodec_dec_ctx *curr_ctx;

int dec_irq;
struct mtk_vcodec_pm pm;
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c
index 4b2ccfdc273f..12ac61b92190 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c
@@ -146,7 +146,7 @@ static void mtk_vcodec_dec_disable_irq(struct mtk_vcodec_dev *vdec_dev, int hw_i
}
}

-static void mtk_vcodec_load_racing_info(struct mtk_vcodec_ctx *ctx)
+static void mtk_vcodec_load_racing_info(struct mtk_vcodec_dec_ctx *ctx)
{
void __iomem *vdec_racing_addr;
int j;
@@ -160,7 +160,7 @@ static void mtk_vcodec_load_racing_info(struct mtk_vcodec_ctx *ctx)
mutex_unlock(&ctx->dev->dec_racing_info_mutex);
}

-static void mtk_vcodec_record_racing_info(struct mtk_vcodec_ctx *ctx)
+static void mtk_vcodec_record_racing_info(struct mtk_vcodec_dec_ctx *ctx)
{
void __iomem *vdec_racing_addr;
int j;
@@ -234,7 +234,7 @@ static void mtk_vcodec_dec_child_dev_off(struct mtk_vcodec_dev *vdec_dev,
}
}

-void mtk_vcodec_dec_enable_hardware(struct mtk_vcodec_ctx *ctx, int hw_idx)
+void mtk_vcodec_dec_enable_hardware(struct mtk_vcodec_dec_ctx *ctx, int hw_idx)
{
mutex_lock(&ctx->dev->dec_mutex[hw_idx]);

@@ -250,7 +250,7 @@ void mtk_vcodec_dec_enable_hardware(struct mtk_vcodec_ctx *ctx, int hw_idx)
}
EXPORT_SYMBOL_GPL(mtk_vcodec_dec_enable_hardware);

-void mtk_vcodec_dec_disable_hardware(struct mtk_vcodec_ctx *ctx, int hw_idx)
+void mtk_vcodec_dec_disable_hardware(struct mtk_vcodec_dec_ctx *ctx, int hw_idx)
{
if (IS_VDEC_INNER_RACING(ctx->dev->dec_capability))
mtk_vcodec_record_racing_info(ctx);
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.h
index dbcf3cabe6f3..f6c68e57bcc1 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.h
@@ -11,7 +11,7 @@

int mtk_vcodec_init_dec_clk(struct platform_device *pdev, struct mtk_vcodec_pm *pm);

-void mtk_vcodec_dec_enable_hardware(struct mtk_vcodec_ctx *ctx, int hw_idx);
-void mtk_vcodec_dec_disable_hardware(struct mtk_vcodec_ctx *ctx, int hw_idx);
+void mtk_vcodec_dec_enable_hardware(struct mtk_vcodec_dec_ctx *ctx, int hw_idx);
+void mtk_vcodec_dec_disable_hardware(struct mtk_vcodec_dec_ctx *ctx, int hw_idx);

#endif /* _MTK_VCODEC_DEC_PM_H_ */
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c
index 6e7e4f10bb2f..aba3ac04ed94 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c
@@ -55,7 +55,7 @@ static const unsigned int num_supported_formats =
* Note the buffers returned from codec driver may still be in driver's
* reference list.
*/
-static struct vb2_buffer *get_display_buffer(struct mtk_vcodec_ctx *ctx)
+static struct vb2_buffer *get_display_buffer(struct mtk_vcodec_dec_ctx *ctx)
{
struct vdec_fb *disp_frame_buffer = NULL;
struct mtk_video_dec_buf *dstbuf;
@@ -98,7 +98,7 @@ static struct vb2_buffer *get_display_buffer(struct mtk_vcodec_ctx *ctx)
* previous sps/pps/resolution change decode, or do nothing if user
* space still owns this buffer
*/
-static struct vb2_buffer *get_free_buffer(struct mtk_vcodec_ctx *ctx)
+static struct vb2_buffer *get_free_buffer(struct mtk_vcodec_dec_ctx *ctx)
{
struct mtk_video_dec_buf *dstbuf;
struct vdec_fb *free_frame_buffer = NULL;
@@ -174,19 +174,19 @@ static struct vb2_buffer *get_free_buffer(struct mtk_vcodec_ctx *ctx)
return &vb->vb2_buf;
}

-static void clean_display_buffer(struct mtk_vcodec_ctx *ctx)
+static void clean_display_buffer(struct mtk_vcodec_dec_ctx *ctx)
{
while (get_display_buffer(ctx))
;
}

-static void clean_free_buffer(struct mtk_vcodec_ctx *ctx)
+static void clean_free_buffer(struct mtk_vcodec_dec_ctx *ctx)
{
while (get_free_buffer(ctx))
;
}

-static void mtk_vdec_queue_res_chg_event(struct mtk_vcodec_ctx *ctx)
+static void mtk_vdec_queue_res_chg_event(struct mtk_vcodec_dec_ctx *ctx)
{
static const struct v4l2_event ev_src_ch = {
.type = V4L2_EVENT_SOURCE_CHANGE,
@@ -197,7 +197,7 @@ static void mtk_vdec_queue_res_chg_event(struct mtk_vcodec_ctx *ctx)
v4l2_event_queue_fh(&ctx->fh, &ev_src_ch);
}

-static int mtk_vdec_flush_decoder(struct mtk_vcodec_ctx *ctx)
+static int mtk_vdec_flush_decoder(struct mtk_vcodec_dec_ctx *ctx)
{
bool res_chg;
int ret;
@@ -212,7 +212,7 @@ static int mtk_vdec_flush_decoder(struct mtk_vcodec_ctx *ctx)
return 0;
}

-static void mtk_vdec_update_fmt(struct mtk_vcodec_ctx *ctx,
+static void mtk_vdec_update_fmt(struct mtk_vcodec_dec_ctx *ctx,
unsigned int pixelformat)
{
const struct mtk_video_fmt *fmt;
@@ -233,7 +233,7 @@ static void mtk_vdec_update_fmt(struct mtk_vcodec_ctx *ctx,
mtk_v4l2_err(ctx->dev->plat_dev, "Cannot get fourcc(%d), using init value", pixelformat);
}

-static int mtk_vdec_pic_info_update(struct mtk_vcodec_ctx *ctx)
+static int mtk_vdec_pic_info_update(struct mtk_vcodec_dec_ctx *ctx)
{
unsigned int dpbsize = 0;
int ret;
@@ -278,8 +278,8 @@ static int mtk_vdec_pic_info_update(struct mtk_vcodec_ctx *ctx)

static void mtk_vdec_worker(struct work_struct *work)
{
- struct mtk_vcodec_ctx *ctx =
- container_of(work, struct mtk_vcodec_ctx, decode_work);
+ struct mtk_vcodec_dec_ctx *ctx =
+ container_of(work, struct mtk_vcodec_dec_ctx, decode_work);
struct mtk_vcodec_dev *dev = ctx->dev;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
struct mtk_vcodec_mem buf;
@@ -421,7 +421,7 @@ static void vb2ops_vdec_stateful_buf_queue(struct vb2_buffer *vb)
bool res_chg = false;
int ret;
unsigned int dpbsize = 1, i;
- struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+ struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct vb2_v4l2_buffer *vb2_v4l2;
struct mtk_q_data *dst_q_data;

@@ -532,7 +532,7 @@ static void vb2ops_vdec_stateful_buf_queue(struct vb2_buffer *vb)

static int mtk_vdec_g_v_ctrl(struct v4l2_ctrl *ctrl)
{
- struct mtk_vcodec_ctx *ctx = ctrl_to_ctx(ctrl);
+ struct mtk_vcodec_dec_ctx *ctx = ctrl_to_dec_ctx(ctrl);
int ret = 0;

switch (ctrl->id) {
@@ -554,7 +554,7 @@ static const struct v4l2_ctrl_ops mtk_vcodec_dec_ctrl_ops = {
.g_volatile_ctrl = mtk_vdec_g_v_ctrl,
};

-static int mtk_vcodec_dec_ctrls_setup(struct mtk_vcodec_ctx *ctx)
+static int mtk_vcodec_dec_ctrls_setup(struct mtk_vcodec_dec_ctx *ctx)
{
struct v4l2_ctrl *ctrl;

@@ -585,7 +585,7 @@ static int mtk_vcodec_dec_ctrls_setup(struct mtk_vcodec_ctx *ctx)
return 0;
}

-static void mtk_init_vdec_params(struct mtk_vcodec_ctx *ctx)
+static void mtk_init_vdec_params(struct mtk_vcodec_dec_ctx *ctx)
{
unsigned int i;

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
index 4c97cd9afd16..d2ab24c96086 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
@@ -218,7 +218,7 @@ static const struct v4l2_frmsize_stepwise stepwise_fhd = {
.step_height = 16
};

-static void mtk_vdec_stateless_cap_to_disp(struct mtk_vcodec_ctx *ctx, int error,
+static void mtk_vdec_stateless_cap_to_disp(struct mtk_vcodec_dec_ctx *ctx, int error,
struct media_request *src_buf_req)
{
struct vb2_v4l2_buffer *vb2_dst;
@@ -242,7 +242,7 @@ static void mtk_vdec_stateless_cap_to_disp(struct mtk_vcodec_ctx *ctx, int error
v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl);
}

-static struct vdec_fb *vdec_get_cap_buffer(struct mtk_vcodec_ctx *ctx)
+static struct vdec_fb *vdec_get_cap_buffer(struct mtk_vcodec_dec_ctx *ctx)
{
struct mtk_video_dec_buf *framebuf;
struct vb2_v4l2_buffer *vb2_v4l2;
@@ -279,15 +279,15 @@ static struct vdec_fb *vdec_get_cap_buffer(struct mtk_vcodec_ctx *ctx)

static void vb2ops_vdec_buf_request_complete(struct vb2_buffer *vb)
{
- struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+ struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);

v4l2_ctrl_request_complete(vb->req_obj.req, &ctx->ctrl_hdl);
}

static void mtk_vdec_worker(struct work_struct *work)
{
- struct mtk_vcodec_ctx *ctx =
- container_of(work, struct mtk_vcodec_ctx, decode_work);
+ struct mtk_vcodec_dec_ctx *ctx =
+ container_of(work, struct mtk_vcodec_dec_ctx, decode_work);
struct mtk_vcodec_dev *dev = ctx->dev;
struct vb2_v4l2_buffer *vb2_v4l2_src;
struct vb2_buffer *vb2_src;
@@ -361,7 +361,7 @@ static void mtk_vdec_worker(struct work_struct *work)

static void vb2ops_vdec_stateless_buf_queue(struct vb2_buffer *vb)
{
- struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+ struct mtk_vcodec_dec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct vb2_v4l2_buffer *vb2_v4l2 = to_vb2_v4l2_buffer(vb);

mtk_v4l2_debug(ctx->dev->plat_dev, 3, "[%d] (%d) id=%d, vb=%p", ctx->id,
@@ -383,14 +383,14 @@ static void vb2ops_vdec_stateless_buf_queue(struct vb2_buffer *vb)
}
}

-static int mtk_vdec_flush_decoder(struct mtk_vcodec_ctx *ctx)
+static int mtk_vdec_flush_decoder(struct mtk_vcodec_dec_ctx *ctx)
{
bool res_chg;

return vdec_if_decode(ctx, NULL, NULL, &res_chg);
}

-static int mtk_vcodec_dec_ctrls_setup(struct mtk_vcodec_ctx *ctx)
+static int mtk_vcodec_dec_ctrls_setup(struct mtk_vcodec_dec_ctx *ctx)
{
unsigned int i;

@@ -444,7 +444,7 @@ const struct media_device_ops mtk_vcodec_media_ops = {
};

static void mtk_vcodec_add_formats(unsigned int fourcc,
- struct mtk_vcodec_ctx *ctx)
+ struct mtk_vcodec_dec_ctx *ctx)
{
struct mtk_vcodec_dev *dev = ctx->dev;
const struct mtk_vcodec_dec_pdata *pdata = dev->vdec_pdata;
@@ -485,7 +485,7 @@ static void mtk_vcodec_add_formats(unsigned int fourcc,
count_formats, ctx->dev->dec_capability);
}

-static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_ctx *ctx)
+static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_dec_ctx *ctx)
{
int cap_format_count = 0, out_format_count = 0;

@@ -528,7 +528,7 @@ static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_ctx *ctx)
mtk_video_formats[cap_format_count + out_format_count - 1];
}

-static void mtk_init_vdec_params(struct mtk_vcodec_ctx *ctx)
+static void mtk_init_vdec_params(struct mtk_vcodec_dec_ctx *ctx)
{
struct vb2_queue *src_vq;

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
index e3230a4d7b8e..76db7770d981 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
@@ -17,13 +17,14 @@
#include <media/videobuf2-core.h>

#include "mtk_vcodec_dbgfs.h"
+#include "mtk_vcodec_dec_drv.h"
+#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_util.h"
#include "vdec_msg_queue.h"

#define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec"
#define MTK_VCODEC_ENC_NAME "mtk-vcodec-enc"

-#define MTK_VCODEC_MAX_PLANES 3
#define MTK_V4L2_BENCHMARK 0
#define WAIT_INTR_TIMEOUT_MS 1000
#define IS_VDEC_LAT_ARCH(hw_arch) ((hw_arch) >= MTK_VDEC_LAT_SINGLE_CORE)
@@ -53,60 +54,7 @@ enum mtk_hw_reg_idx {
NUM_MAX_VCODEC_REG_BASE
};

-/*
- * enum mtk_instance_type - The type of an MTK Vcodec instance.
- */
-enum mtk_instance_type {
- MTK_INST_DECODER = 0,
- MTK_INST_ENCODER = 1,
-};

-/**
- * enum mtk_instance_state - The state of an MTK Vcodec instance.
- * @MTK_STATE_FREE: default state when instance is created
- * @MTK_STATE_INIT: vcodec instance is initialized
- * @MTK_STATE_HEADER: vdec had sps/pps header parsed or venc
- * had sps/pps header encoded
- * @MTK_STATE_FLUSH: vdec is flushing. Only used by decoder
- * @MTK_STATE_ABORT: vcodec should be aborted
- */
-enum mtk_instance_state {
- MTK_STATE_FREE = 0,
- MTK_STATE_INIT = 1,
- MTK_STATE_HEADER = 2,
- MTK_STATE_FLUSH = 3,
- MTK_STATE_ABORT = 4,
-};
-
-/*
- * enum mtk_encode_param - General encoding parameters type
- */
-enum mtk_encode_param {
- MTK_ENCODE_PARAM_NONE = 0,
- MTK_ENCODE_PARAM_BITRATE = (1 << 0),
- MTK_ENCODE_PARAM_FRAMERATE = (1 << 1),
- MTK_ENCODE_PARAM_INTRA_PERIOD = (1 << 2),
- MTK_ENCODE_PARAM_FORCE_INTRA = (1 << 3),
- MTK_ENCODE_PARAM_GOP_SIZE = (1 << 4),
-};
-
-enum mtk_fmt_type {
- MTK_FMT_DEC = 0,
- MTK_FMT_ENC = 1,
- MTK_FMT_FRAME = 2,
-};
-
-/*
- * enum mtk_vdec_hw_id - Hardware index used to separate
- * different hardware
- */
-enum mtk_vdec_hw_id {
- MTK_VDEC_CORE,
- MTK_VDEC_LAT0,
- MTK_VDEC_LAT1,
- MTK_VDEC_LAT_SOC,
- MTK_VDEC_HW_MAX,
-};

/*
* enum mtk_vdec_hw_count - Supported hardware count
@@ -118,17 +66,6 @@ enum mtk_vdec_hw_count {
MTK_VDEC_MAX_HW_COUNT,
};

-/*
- * struct mtk_video_fmt - Structure used to store information about pixelformats
- */
-struct mtk_video_fmt {
- u32 fourcc;
- enum mtk_fmt_type type;
- u32 num_planes;
- u32 flags;
- struct v4l2_frmsize_stepwise frmsize;
-};
-
/*
* enum mtk_q_type - Type of queue
*/
@@ -137,54 +74,6 @@ enum mtk_q_type {
MTK_Q_DATA_DST = 1,
};

-/*
- * struct mtk_q_data - Structure used to store information about queue
- */
-struct mtk_q_data {
- unsigned int visible_width;
- unsigned int visible_height;
- unsigned int coded_width;
- unsigned int coded_height;
- enum v4l2_field field;
- unsigned int bytesperline[MTK_VCODEC_MAX_PLANES];
- unsigned int sizeimage[MTK_VCODEC_MAX_PLANES];
- const struct mtk_video_fmt *fmt;
-};
-
-/**
- * struct mtk_enc_params - General encoding parameters
- * @bitrate: target bitrate in bits per second
- * @num_b_frame: number of b frames between p-frame
- * @rc_frame: frame based rate control
- * @rc_mb: macroblock based rate control
- * @seq_hdr_mode: H.264 sequence header is encoded separately or joined
- * with the first frame
- * @intra_period: I frame period
- * @gop_size: group of picture size, it's used as the intra frame period
- * @framerate_num: frame rate numerator. ex: framerate_num=30 and
- * framerate_denom=1 means FPS is 30
- * @framerate_denom: frame rate denominator. ex: framerate_num=30 and
- * framerate_denom=1 means FPS is 30
- * @h264_max_qp: Max value for H.264 quantization parameter
- * @h264_profile: V4L2 defined H.264 profile
- * @h264_level: V4L2 defined H.264 level
- * @force_intra: force/insert intra frame
- */
-struct mtk_enc_params {
- unsigned int bitrate;
- unsigned int num_b_frame;
- unsigned int rc_frame;
- unsigned int rc_mb;
- unsigned int seq_hdr_mode;
- unsigned int intra_period;
- unsigned int gop_size;
- unsigned int framerate_num;
- unsigned int framerate_denom;
- unsigned int h264_max_qp;
- unsigned int h264_profile;
- unsigned int h264_level;
- unsigned int force_intra;
-};

/*
* struct mtk_vcodec_clk_info - Structure used to store clock name
@@ -211,125 +100,6 @@ struct mtk_vcodec_pm {
struct device *dev;
};

-/**
- * struct vdec_pic_info - picture size information
- * @pic_w: picture width
- * @pic_h: picture height
- * @buf_w: picture buffer width (64 aligned up from pic_w)
- * @buf_h: picture buffer heiht (64 aligned up from pic_h)
- * @fb_sz: bitstream size of each plane
- * E.g. suppose picture size is 176x144,
- * buffer size will be aligned to 176x160.
- * @cap_fourcc: fourcc number(may changed when resolution change)
- * @reserved: align struct to 64-bit in order to adjust 32-bit and 64-bit os.
- */
-struct vdec_pic_info {
- unsigned int pic_w;
- unsigned int pic_h;
- unsigned int buf_w;
- unsigned int buf_h;
- unsigned int fb_sz[VIDEO_MAX_PLANES];
- unsigned int cap_fourcc;
- unsigned int reserved;
-};
-
-/**
- * struct mtk_vcodec_ctx - Context (instance) private data.
- *
- * @type: type of the instance - decoder or encoder
- * @dev: pointer to the mtk_vcodec_dev of the device
- * @list: link to ctx_list of mtk_vcodec_dev
- * @fh: struct v4l2_fh
- * @m2m_ctx: pointer to the v4l2_m2m_ctx of the context
- * @q_data: store information of input and output queue
- * of the context
- * @id: index of the context that this structure describes
- * @state: state of the context
- * @param_change: indicate encode parameter type
- * @enc_params: encoding parameters
- * @dec_if: hooked decoder driver interface
- * @enc_if: hooked encoder driver interface
- * @drv_handle: driver handle for specific decode/encode instance
- *
- * @picinfo: store picture info after header parsing
- * @dpb_size: store dpb count after header parsing
- * @int_cond: variable used by the waitqueue
- * @int_type: type of the last interrupt
- * @queue: waitqueue that can be used to wait for this context to
- * finish
- * @irq_status: irq status
- *
- * @ctrl_hdl: handler for v4l2 framework
- * @decode_work: worker for the decoding
- * @encode_work: worker for the encoding
- * @last_decoded_picinfo: pic information get from latest decode
- * @empty_flush_buf: a fake size-0 capture buffer that indicates flush. Only
- * to be used with encoder and stateful decoder.
- * @is_flushing: set to true if flushing is in progress.
- * @current_codec: current set input codec, in V4L2 pixel format
- * @capture_fourcc: capture queue type in V4L2 pixel format
- *
- * @colorspace: enum v4l2_colorspace; supplemental to pixelformat
- * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
- * @quantization: enum v4l2_quantization, colorspace quantization
- * @xfer_func: enum v4l2_xfer_func, colorspace transfer function
- * @decoded_frame_cnt: number of decoded frames
- * @lock: protect variables accessed by V4L2 threads and worker thread such as
- * mtk_video_dec_buf.
- * @hw_id: hardware index used to identify different hardware.
- *
- * @msg_queue: msg queue used to store lat buffer information.
- * @q_mutex: vb2_queue mutex.
- */
-struct mtk_vcodec_ctx {
- enum mtk_instance_type type;
- struct mtk_vcodec_dev *dev;
- struct list_head list;
-
- struct v4l2_fh fh;
- struct v4l2_m2m_ctx *m2m_ctx;
- struct mtk_q_data q_data[2];
- int id;
- enum mtk_instance_state state;
- enum mtk_encode_param param_change;
- struct mtk_enc_params enc_params;
-
- const struct vdec_common_if *dec_if;
- const struct venc_common_if *enc_if;
- void *drv_handle;
-
- struct vdec_pic_info picinfo;
- int dpb_size;
-
- int int_cond[MTK_VDEC_HW_MAX];
- int int_type[MTK_VDEC_HW_MAX];
- wait_queue_head_t queue[MTK_VDEC_HW_MAX];
- unsigned int irq_status;
-
- struct v4l2_ctrl_handler ctrl_hdl;
- struct work_struct decode_work;
- struct work_struct encode_work;
- struct vdec_pic_info last_decoded_picinfo;
- struct v4l2_m2m_buffer empty_flush_buf;
- bool is_flushing;
-
- u32 current_codec;
- u32 capture_fourcc;
-
- enum v4l2_colorspace colorspace;
- enum v4l2_ycbcr_encoding ycbcr_enc;
- enum v4l2_quantization quantization;
- enum v4l2_xfer_func xfer_func;
-
- int decoded_frame_cnt;
- struct mutex lock;
- int hw_id;
-
- struct vdec_msg_queue msg_queue;
-
- struct mutex q_mutex;
-};
-
/*
* enum mtk_vdec_hw_arch - Used to separate different hardware architecture
*/
@@ -375,12 +145,12 @@ enum mtk_vdec_format_types {
*/

struct mtk_vcodec_dec_pdata {
- void (*init_vdec_params)(struct mtk_vcodec_ctx *ctx);
- int (*ctrls_setup)(struct mtk_vcodec_ctx *ctx);
+ void (*init_vdec_params)(struct mtk_vcodec_dec_ctx *ctx);
+ int (*ctrls_setup)(struct mtk_vcodec_dec_ctx *ctx);
void (*worker)(struct work_struct *work);
- int (*flush_decoder)(struct mtk_vcodec_ctx *ctx);
- struct vdec_fb *(*get_cap_buffer)(struct mtk_vcodec_ctx *ctx);
- void (*cap_to_disp)(struct mtk_vcodec_ctx *ctx, int error,
+ int (*flush_decoder)(struct mtk_vcodec_dec_ctx *ctx);
+ struct vdec_fb *(*get_cap_buffer)(struct mtk_vcodec_dec_ctx *ctx);
+ void (*cap_to_disp)(struct mtk_vcodec_dec_ctx *ctx, int error,
struct media_request *src_buf_req);

struct vb2_ops *vdec_vb2_ops;
@@ -434,9 +204,10 @@ struct mtk_vcodec_enc_pdata {
* @m2m_dev_dec: m2m device for decoder
* @m2m_dev_enc: m2m device for encoder.
* @plat_dev: platform device
- * @ctx_list: list of struct mtk_vcodec_ctx
+ * @ctx_list: list of struct mtk_vcodec_dec_ctx
* @irqlock: protect data access by irq handler and work thread
* @curr_ctx: The context that is waiting for codec hardware
+ * @curr_enc_ctx: The encoder context that is waiting for codec hardware
*
* @reg_base: Mapped address of MTK Vcodec registers.
* @vdec_pdata: decoder IC-specific data
@@ -482,7 +253,8 @@ struct mtk_vcodec_dev {
struct platform_device *plat_dev;
struct list_head ctx_list;
spinlock_t irqlock;
- struct mtk_vcodec_ctx *curr_ctx;
+ struct mtk_vcodec_dec_ctx *curr_ctx;
+ struct mtk_vcodec_enc_ctx *curr_enc_ctx;
void __iomem *reg_base[NUM_MAX_VCODEC_REG_BASE];
const struct mtk_vcodec_dec_pdata *vdec_pdata;
const struct mtk_vcodec_enc_pdata *venc_pdata;
@@ -520,23 +292,4 @@ struct mtk_vcodec_dev {
struct mtk_vcodec_dbgfs dbgfs;
};

-static inline struct mtk_vcodec_ctx *fh_to_ctx(struct v4l2_fh *fh)
-{
- return container_of(fh, struct mtk_vcodec_ctx, fh);
-}
-
-static inline struct mtk_vcodec_ctx *ctrl_to_ctx(struct v4l2_ctrl *ctrl)
-{
- return container_of(ctrl->handler, struct mtk_vcodec_ctx, ctrl_hdl);
-}
-
-/* Wake up context wait_queue */
-static inline void
-wake_up_ctx(struct mtk_vcodec_ctx *ctx, unsigned int reason, unsigned int hw_id)
-{
- ctx->int_cond[hw_id] = 1;
- ctx->int_type[hw_id] = reason;
- wake_up_interruptible(&ctx->queue[hw_id]);
-}
-
#endif /* _MTK_VCODEC_DRV_H_ */
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
index 630ecc9f2240..38cacb58fa60 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
@@ -45,7 +45,7 @@ static const struct v4l2_frmsize_stepwise mtk_venc_4k_framesizes = {

static int vidioc_venc_s_ctrl(struct v4l2_ctrl *ctrl)
{
- struct mtk_vcodec_ctx *ctx = ctrl_to_ctx(ctrl);
+ struct mtk_vcodec_enc_ctx *ctx = ctrl_to_enc_ctx(ctrl);
struct mtk_enc_params *p = &ctx->enc_params;
int ret = 0;

@@ -174,7 +174,7 @@ static int vidioc_enum_framesizes(struct file *file, void *fh,
struct v4l2_frmsizeenum *fsize)
{
const struct mtk_video_fmt *fmt;
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(fh);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(fh);

if (fsize->index != 0)
return -EINVAL;
@@ -198,7 +198,7 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
const struct mtk_vcodec_enc_pdata *pdata =
- fh_to_ctx(priv)->dev->venc_pdata;
+ fh_to_enc_ctx(priv)->dev->venc_pdata;

return vidioc_enum_fmt(f, pdata->capture_formats,
pdata->num_capture_formats);
@@ -208,7 +208,7 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
struct v4l2_fmtdesc *f)
{
const struct mtk_vcodec_enc_pdata *pdata =
- fh_to_ctx(priv)->dev->venc_pdata;
+ fh_to_enc_ctx(priv)->dev->venc_pdata;

return vidioc_enum_fmt(f, pdata->output_formats,
pdata->num_output_formats);
@@ -216,7 +216,7 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,

static int mtk_vcodec_enc_get_chip_name(void *priv)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
struct device *dev = &ctx->dev->plat_dev->dev;

if (of_device_is_compatible(dev->of_node, "mediatek,mt8173-vcodec-enc"))
@@ -236,7 +236,7 @@ static int mtk_vcodec_enc_get_chip_name(void *priv)
static int vidioc_venc_querycap(struct file *file, void *priv,
struct v4l2_capability *cap)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
struct device *dev = &ctx->dev->plat_dev->dev;
int platform_name = mtk_vcodec_enc_get_chip_name(priv);

@@ -249,7 +249,7 @@ static int vidioc_venc_querycap(struct file *file, void *priv,
static int vidioc_venc_s_parm(struct file *file, void *priv,
struct v4l2_streamparm *a)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
struct v4l2_fract *timeperframe = &a->parm.output.timeperframe;

if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
@@ -272,7 +272,7 @@ static int vidioc_venc_s_parm(struct file *file, void *priv,
static int vidioc_venc_g_parm(struct file *file, void *priv,
struct v4l2_streamparm *a)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);

if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
return -EINVAL;
@@ -286,7 +286,7 @@ static int vidioc_venc_g_parm(struct file *file, void *priv,
return 0;
}

-static struct mtk_q_data *mtk_venc_get_q_data(struct mtk_vcodec_ctx *ctx,
+static struct mtk_q_data *mtk_venc_get_q_data(struct mtk_vcodec_enc_ctx *ctx,
enum v4l2_buf_type type)
{
if (V4L2_TYPE_IS_OUTPUT(type))
@@ -306,7 +306,7 @@ static void vidioc_try_fmt_cap(struct v4l2_format *f)
/* V4L2 specification suggests the driver corrects the format struct if any of
* the dimensions is unsupported
*/
-static int vidioc_try_fmt_out(struct mtk_vcodec_ctx *ctx, struct v4l2_format *f,
+static int vidioc_try_fmt_out(struct mtk_vcodec_enc_ctx *ctx, struct v4l2_format *f,
const struct mtk_video_fmt *fmt)
{
struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;
@@ -379,8 +379,8 @@ static int vidioc_try_fmt_out(struct mtk_vcodec_ctx *ctx, struct v4l2_format *f,
return 0;
}

-static void mtk_venc_set_param(struct mtk_vcodec_ctx *ctx,
- struct venc_enc_param *param)
+static void mtk_venc_set_param(struct mtk_vcodec_enc_ctx *ctx,
+ struct venc_enc_param *param)
{
struct mtk_q_data *q_data_src = &ctx->q_data[MTK_Q_DATA_SRC];
struct mtk_enc_params *enc_params = &ctx->enc_params;
@@ -429,7 +429,7 @@ static void mtk_venc_set_param(struct mtk_vcodec_ctx *ctx,
static int vidioc_venc_s_fmt_cap(struct file *file, void *priv,
struct v4l2_format *f)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
struct vb2_queue *vq;
struct mtk_q_data *q_data = mtk_venc_get_q_data(ctx, f->type);
@@ -484,7 +484,7 @@ static int vidioc_venc_s_fmt_cap(struct file *file, void *priv,
static int vidioc_venc_s_fmt_out(struct file *file, void *priv,
struct v4l2_format *f)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;
struct vb2_queue *vq;
struct mtk_q_data *q_data = mtk_venc_get_q_data(ctx, f->type);
@@ -539,7 +539,7 @@ static int vidioc_venc_g_fmt(struct file *file, void *priv,
struct v4l2_format *f)
{
struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
struct vb2_queue *vq;
struct mtk_q_data *q_data = mtk_venc_get_q_data(ctx, f->type);
int i;
@@ -572,7 +572,7 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *priv,
struct v4l2_format *f)
{
const struct mtk_video_fmt *fmt;
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;

fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
@@ -594,7 +594,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
struct v4l2_format *f)
{
const struct mtk_video_fmt *fmt;
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata;

fmt = mtk_venc_find_format(f->fmt.pix.pixelformat, pdata);
@@ -615,7 +615,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
static int vidioc_venc_g_selection(struct file *file, void *priv,
struct v4l2_selection *s)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
struct mtk_q_data *q_data = mtk_venc_get_q_data(ctx, s->type);

if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
@@ -645,7 +645,7 @@ static int vidioc_venc_g_selection(struct file *file, void *priv,
static int vidioc_venc_s_selection(struct file *file, void *priv,
struct v4l2_selection *s)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
struct mtk_q_data *q_data = mtk_venc_get_q_data(ctx, s->type);

if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
@@ -670,7 +670,7 @@ static int vidioc_venc_s_selection(struct file *file, void *priv,
static int vidioc_venc_qbuf(struct file *file, void *priv,
struct v4l2_buffer *buf)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);

if (ctx->state == MTK_STATE_ABORT) {
mtk_v4l2_err(ctx->dev->plat_dev, "[%d] Call on QBUF after unrecoverable error",
@@ -684,7 +684,7 @@ static int vidioc_venc_qbuf(struct file *file, void *priv,
static int vidioc_venc_dqbuf(struct file *file, void *priv,
struct v4l2_buffer *buf)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
int ret;

if (ctx->state == MTK_STATE_ABORT) {
@@ -722,7 +722,7 @@ static int vidioc_venc_dqbuf(struct file *file, void *priv,
static int vidioc_encoder_cmd(struct file *file, void *priv,
struct v4l2_encoder_cmd *cmd)
{
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv);
struct vb2_queue *src_vq, *dst_vq;
int ret;

@@ -818,7 +818,7 @@ static int vb2ops_venc_queue_setup(struct vb2_queue *vq,
unsigned int sizes[],
struct device *alloc_devs[])
{
- struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(vq);
+ struct mtk_vcodec_enc_ctx *ctx = vb2_get_drv_priv(vq);
struct mtk_q_data *q_data = mtk_venc_get_q_data(ctx, vq->type);
unsigned int i;

@@ -840,7 +840,7 @@ static int vb2ops_venc_queue_setup(struct vb2_queue *vq,

static int vb2ops_venc_buf_prepare(struct vb2_buffer *vb)
{
- struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+ struct mtk_vcodec_enc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct mtk_q_data *q_data = mtk_venc_get_q_data(ctx, vb->vb2_queue->type);
int i;

@@ -859,7 +859,7 @@ static int vb2ops_venc_buf_prepare(struct vb2_buffer *vb)

static void vb2ops_venc_buf_queue(struct vb2_buffer *vb)
{
- struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+ struct mtk_vcodec_enc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
struct vb2_v4l2_buffer *vb2_v4l2 =
container_of(vb, struct vb2_v4l2_buffer, vb2_buf);

@@ -882,7 +882,7 @@ static void vb2ops_venc_buf_queue(struct vb2_buffer *vb)

static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
{
- struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(q);
+ struct mtk_vcodec_enc_ctx *ctx = vb2_get_drv_priv(q);
struct venc_enc_param param;
int ret, pm_ret;
int i;
@@ -962,7 +962,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)

static void vb2ops_venc_stop_streaming(struct vb2_queue *q)
{
- struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(q);
+ struct mtk_vcodec_enc_ctx *ctx = vb2_get_drv_priv(q);
struct vb2_v4l2_buffer *src_buf, *dst_buf;
int ret;

@@ -1051,7 +1051,7 @@ static const struct vb2_ops mtk_venc_vb2_ops = {

static int mtk_venc_encode_header(void *priv)
{
- struct mtk_vcodec_ctx *ctx = priv;
+ struct mtk_vcodec_enc_ctx *ctx = priv;
int ret;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
struct mtk_vcodec_mem bs_buf;
@@ -1098,7 +1098,7 @@ static int mtk_venc_encode_header(void *priv)
return 0;
}

-static int mtk_venc_param_change(struct mtk_vcodec_ctx *ctx)
+static int mtk_venc_param_change(struct mtk_vcodec_enc_ctx *ctx)
{
struct venc_enc_param enc_prm;
struct vb2_v4l2_buffer *vb2_v4l2 = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
@@ -1171,7 +1171,7 @@ static int mtk_venc_param_change(struct mtk_vcodec_ctx *ctx)
*/
static void mtk_venc_worker(struct work_struct *work)
{
- struct mtk_vcodec_ctx *ctx = container_of(work, struct mtk_vcodec_ctx,
+ struct mtk_vcodec_enc_ctx *ctx = container_of(work, struct mtk_vcodec_enc_ctx,
encode_work);
struct vb2_v4l2_buffer *src_buf, *dst_buf;
struct venc_frm_buf frm_buf;
@@ -1256,7 +1256,7 @@ static void mtk_venc_worker(struct work_struct *work)

static void m2mops_venc_device_run(void *priv)
{
- struct mtk_vcodec_ctx *ctx = priv;
+ struct mtk_vcodec_enc_ctx *ctx = priv;

if ((ctx->q_data[MTK_Q_DATA_DST].fmt->fourcc == V4L2_PIX_FMT_H264) &&
(ctx->state != MTK_STATE_HEADER)) {
@@ -1272,7 +1272,7 @@ static void m2mops_venc_device_run(void *priv)

static int m2mops_venc_job_ready(void *m2m_priv)
{
- struct mtk_vcodec_ctx *ctx = m2m_priv;
+ struct mtk_vcodec_enc_ctx *ctx = m2m_priv;

if (ctx->state == MTK_STATE_ABORT || ctx->state == MTK_STATE_FREE) {
mtk_v4l2_debug(ctx->dev->plat_dev, 3, "[%d]Not ready: state=0x%x.",
@@ -1285,7 +1285,7 @@ static int m2mops_venc_job_ready(void *m2m_priv)

static void m2mops_venc_job_abort(void *priv)
{
- struct mtk_vcodec_ctx *ctx = priv;
+ struct mtk_vcodec_enc_ctx *ctx = priv;

ctx->state = MTK_STATE_ABORT;
}
@@ -1296,7 +1296,7 @@ const struct v4l2_m2m_ops mtk_venc_m2m_ops = {
.job_abort = m2mops_venc_job_abort,
};

-void mtk_vcodec_enc_set_default_params(struct mtk_vcodec_ctx *ctx)
+void mtk_vcodec_enc_set_default_params(struct mtk_vcodec_enc_ctx *ctx)
{
struct mtk_q_data *q_data;

@@ -1357,7 +1357,7 @@ void mtk_vcodec_enc_set_default_params(struct mtk_vcodec_ctx *ctx)
ctx->enc_params.framerate_denom = MTK_DEFAULT_FRAMERATE_DENOM;
}

-int mtk_vcodec_enc_ctrls_setup(struct mtk_vcodec_ctx *ctx)
+int mtk_vcodec_enc_ctrls_setup(struct mtk_vcodec_enc_ctx *ctx)
{
const struct v4l2_ctrl_ops *ops = &mtk_vcodec_enc_ctrl_ops;
struct v4l2_ctrl_handler *handler = &ctx->ctrl_hdl;
@@ -1423,7 +1423,7 @@ int mtk_vcodec_enc_ctrls_setup(struct mtk_vcodec_ctx *ctx)
int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queue *src_vq,
struct vb2_queue *dst_vq)
{
- struct mtk_vcodec_ctx *ctx = priv;
+ struct mtk_vcodec_enc_ctx *ctx = priv;
int ret;

/* Note: VB2_USERPTR works with dma-contig because mt8173
@@ -1458,7 +1458,7 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queue *src_vq,
return vb2_queue_init(dst_vq);
}

-int mtk_venc_unlock(struct mtk_vcodec_ctx *ctx)
+int mtk_venc_unlock(struct mtk_vcodec_enc_ctx *ctx)
{
struct mtk_vcodec_dev *dev = ctx->dev;

@@ -1466,7 +1466,7 @@ int mtk_venc_unlock(struct mtk_vcodec_ctx *ctx)
return 0;
}

-int mtk_venc_lock(struct mtk_vcodec_ctx *ctx)
+int mtk_venc_lock(struct mtk_vcodec_enc_ctx *ctx)
{
struct mtk_vcodec_dev *dev = ctx->dev;

@@ -1474,7 +1474,7 @@ int mtk_venc_lock(struct mtk_vcodec_ctx *ctx)
return 0;
}

-void mtk_vcodec_enc_release(struct mtk_vcodec_ctx *ctx)
+void mtk_vcodec_enc_release(struct mtk_vcodec_enc_ctx *ctx)
{
int ret = venc_if_deinit(ctx);

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.h
index 513ee7993e34..82246401ed4a 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.h
@@ -11,6 +11,8 @@
#include <media/videobuf2-core.h>
#include <media/v4l2-mem2mem.h>

+#include "mtk_vcodec_enc_drv.h"
+
#define MTK_VENC_IRQ_STATUS_SPS 0x1
#define MTK_VENC_IRQ_STATUS_PPS 0x2
#define MTK_VENC_IRQ_STATUS_FRM 0x4
@@ -39,12 +41,12 @@ struct mtk_video_enc_buf {
extern const struct v4l2_ioctl_ops mtk_venc_ioctl_ops;
extern const struct v4l2_m2m_ops mtk_venc_m2m_ops;

-int mtk_venc_unlock(struct mtk_vcodec_ctx *ctx);
-int mtk_venc_lock(struct mtk_vcodec_ctx *ctx);
+int mtk_venc_unlock(struct mtk_vcodec_enc_ctx *ctx);
+int mtk_venc_lock(struct mtk_vcodec_enc_ctx *ctx);
int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queue *src_vq,
struct vb2_queue *dst_vq);
-void mtk_vcodec_enc_release(struct mtk_vcodec_ctx *ctx);
-int mtk_vcodec_enc_ctrls_setup(struct mtk_vcodec_ctx *ctx);
-void mtk_vcodec_enc_set_default_params(struct mtk_vcodec_ctx *ctx);
+void mtk_vcodec_enc_release(struct mtk_vcodec_enc_ctx *ctx);
+int mtk_vcodec_enc_ctrls_setup(struct mtk_vcodec_enc_ctx *ctx);
+void mtk_vcodec_enc_set_default_params(struct mtk_vcodec_enc_ctx *ctx);

#endif /* _MTK_VCODEC_ENC_H_ */
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c
index 83685db506ef..193262de2d9f 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c
@@ -86,13 +86,13 @@ static void clean_irq_status(unsigned int irq_status, void __iomem *addr)
static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, void *priv)
{
struct mtk_vcodec_dev *dev = priv;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_enc_ctx *ctx;
unsigned long flags;
void __iomem *addr;
int core_id;

spin_lock_irqsave(&dev->irqlock, flags);
- ctx = dev->curr_ctx;
+ ctx = dev->curr_enc_ctx;
spin_unlock_irqrestore(&dev->irqlock, flags);

core_id = dev->venc_pdata->core_id;
@@ -110,14 +110,14 @@ static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, void *priv)

clean_irq_status(ctx->irq_status, addr);

- wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0);
+ wake_up_enc_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0);
return IRQ_HANDLED;
}

static int fops_vcodec_open(struct file *file)
{
struct mtk_vcodec_dev *dev = video_drvdata(file);
- struct mtk_vcodec_ctx *ctx = NULL;
+ struct mtk_vcodec_enc_ctx *ctx = NULL;
int ret = 0;
struct vb2_queue *src_vq;

@@ -204,7 +204,7 @@ static int fops_vcodec_open(struct file *file)
static int fops_vcodec_release(struct file *file)
{
struct mtk_vcodec_dev *dev = video_drvdata(file);
- struct mtk_vcodec_ctx *ctx = fh_to_ctx(file->private_data);
+ struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(file->private_data);

mtk_v4l2_debug(dev->plat_dev, 1, "[%d] encoder", ctx->id);
mutex_lock(&dev->dev_mutex);
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.h
new file mode 100644
index 000000000000..6aa4afe5b796
--- /dev/null
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.h
@@ -0,0 +1,158 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2023 MediaTek Inc.
+ * Author: Yunfei Dong <[email protected]>
+ */
+
+#ifndef _MTK_VCODEC_ENC_DRV_H_
+#define _MTK_VCODEC_ENC_DRV_H_
+
+#include "mtk_vcodec_com_drv.h"
+#include "mtk_vcodec_fw_priv.h"
+
+/*
+ * enum mtk_encode_param - General encoding parameters type
+ */
+enum mtk_encode_param {
+ MTK_ENCODE_PARAM_NONE = 0,
+ MTK_ENCODE_PARAM_BITRATE = (1 << 0),
+ MTK_ENCODE_PARAM_FRAMERATE = (1 << 1),
+ MTK_ENCODE_PARAM_INTRA_PERIOD = (1 << 2),
+ MTK_ENCODE_PARAM_FORCE_INTRA = (1 << 3),
+ MTK_ENCODE_PARAM_GOP_SIZE = (1 << 4),
+};
+
+/**
+ * struct mtk_enc_params - General encoding parameters
+ * @bitrate: target bitrate in bits per second
+ * @num_b_frame: number of b frames between p-frame
+ * @rc_frame: frame based rate control
+ * @rc_mb: macroblock based rate control
+ * @seq_hdr_mode: H.264 sequence header is encoded separately or joined
+ * with the first frame
+ * @intra_period: I frame period
+ * @gop_size: group of picture size, it's used as the intra frame period
+ * @framerate_num: frame rate numerator. ex: framerate_num=30 and
+ * framerate_denom=1 means FPS is 30
+ * @framerate_denom: frame rate denominator. ex: framerate_num=30 and
+ * framerate_denom=1 means FPS is 30
+ * @h264_max_qp: Max value for H.264 quantization parameter
+ * @h264_profile: V4L2 defined H.264 profile
+ * @h264_level: V4L2 defined H.264 level
+ * @force_intra: force/insert intra frame
+ */
+struct mtk_enc_params {
+ unsigned int bitrate;
+ unsigned int num_b_frame;
+ unsigned int rc_frame;
+ unsigned int rc_mb;
+ unsigned int seq_hdr_mode;
+ unsigned int intra_period;
+ unsigned int gop_size;
+ unsigned int framerate_num;
+ unsigned int framerate_denom;
+ unsigned int h264_max_qp;
+ unsigned int h264_profile;
+ unsigned int h264_level;
+ unsigned int force_intra;
+};
+
+/**
+ * struct mtk_vcodec_enc_ctx - Context (instance) private data.
+ *
+ * @type: type of the instance - decoder or encoder
+ * @dev: pointer to the mtk_vcodec_dev of the device
+ * @list: link to ctx_list of mtk_vcodec_dev
+ *
+ * @fh: struct v4l2_fh
+ * @m2m_ctx: pointer to the v4l2_m2m_ctx of the context
+ * @q_data: store information of input and output queue
+ * of the context
+ * @id: index of the context that this structure describes
+ * @state: state of the context
+ * @param_change: indicate encode parameter type
+ * @enc_params: encoding parameters
+ *
+ * @enc_if: hooked encoder driver interface
+ * @drv_handle: driver handle for specific decode/encode instance
+ *
+ * @int_cond: variable used by the waitqueue
+ * @int_type: type of the last interrupt
+ * @queue: waitqueue that can be used to wait for this context to
+ * finish
+ * @irq_status: irq status
+ *
+ * @ctrl_hdl: handler for v4l2 framework
+ * @encode_work: worker for the encoding
+ * @empty_flush_buf: a fake size-0 capture buffer that indicates flush. Only
+ * to be used with encoder and stateful decoder.
+ * @is_flushing: set to true if flushing is in progress.
+ *
+ * @colorspace: enum v4l2_colorspace; supplemental to pixelformat
+ * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
+ * @quantization: enum v4l2_quantization, colorspace quantization
+ * @xfer_func: enum v4l2_xfer_func, colorspace transfer function
+ *
+ * @lock: protect variables accessed by V4L2 threads and worker thread such as
+ * mtk_video_dec_buf.
+ * @hw_id: hardware index used to identify different hardware.
+ *
+ * @q_mutex: vb2_queue mutex.
+ */
+struct mtk_vcodec_enc_ctx {
+ enum mtk_instance_type type;
+ struct mtk_vcodec_dev *dev;
+ struct list_head list;
+
+ struct v4l2_fh fh;
+ struct v4l2_m2m_ctx *m2m_ctx;
+ struct mtk_q_data q_data[2];
+ int id;
+ enum mtk_instance_state state;
+ enum mtk_encode_param param_change;
+ struct mtk_enc_params enc_params;
+
+ const struct venc_common_if *enc_if;
+ void *drv_handle;
+
+ int int_cond[MTK_VDEC_HW_MAX];
+ int int_type[MTK_VDEC_HW_MAX];
+ wait_queue_head_t queue[MTK_VDEC_HW_MAX];
+ unsigned int irq_status;
+
+ struct v4l2_ctrl_handler ctrl_hdl;
+ struct work_struct encode_work;
+ struct v4l2_m2m_buffer empty_flush_buf;
+ bool is_flushing;
+
+ enum v4l2_colorspace colorspace;
+ enum v4l2_ycbcr_encoding ycbcr_enc;
+ enum v4l2_quantization quantization;
+ enum v4l2_xfer_func xfer_func;
+
+ struct mutex lock;
+ int hw_id;
+
+ struct mutex q_mutex;
+};
+
+static inline struct mtk_vcodec_enc_ctx *fh_to_enc_ctx(struct v4l2_fh *fh)
+{
+ return container_of(fh, struct mtk_vcodec_enc_ctx, fh);
+}
+
+static inline struct mtk_vcodec_enc_ctx *ctrl_to_enc_ctx(struct v4l2_ctrl *ctrl)
+{
+ return container_of(ctrl->handler, struct mtk_vcodec_enc_ctx, ctrl_hdl);
+}
+
+/* Wake up context wait_queue */
+static inline void
+wake_up_enc_ctx(struct mtk_vcodec_enc_ctx *ctx, unsigned int reason, unsigned int hw_id)
+{
+ ctx->int_cond[hw_id] = 1;
+ ctx->int_type[hw_id] = reason;
+ wake_up_interruptible(&ctx->queue[hw_id]);
+}
+
+#endif /* _MTK_VCODEC_ENC_DRV_H_ */
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_vpu.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_vpu.c
index a3656041c4ec..22096a108166 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_vpu.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_vpu.c
@@ -51,10 +51,26 @@ static void mtk_vcodec_vpu_release(struct mtk_vcodec_fw *fw)
put_device(&fw->pdev->dev);
}

-static void mtk_vcodec_vpu_reset_handler(void *priv)
+static void mtk_vcodec_vpu_reset_dec_handler(void *priv)
{
struct mtk_vcodec_dev *dev = priv;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
+
+ mtk_v4l2_err(dev->plat_dev, "Watchdog timeout!!");
+
+ mutex_lock(&dev->dev_mutex);
+ list_for_each_entry(ctx, &dev->ctx_list, list) {
+ ctx->state = MTK_STATE_ABORT;
+ mtk_v4l2_debug(ctx->dev->plat_dev, 0, "[%d] Change to state MTK_STATE_ABORT",
+ ctx->id);
+ }
+ mutex_unlock(&dev->dev_mutex);
+}
+
+static void mtk_vcodec_vpu_reset_enc_handler(void *priv)
+{
+ struct mtk_vcodec_dev *dev = priv;
+ struct mtk_vcodec_enc_ctx *ctx;

mtk_v4l2_err(dev->plat_dev, "Watchdog timeout!!");

@@ -102,7 +118,10 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_vpu_init(void *priv, enum mtk_vcodec_fw_use
return ERR_PTR(-EINVAL);
}

- vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_vpu_reset_handler, dev, rst_id);
+ if (fw_use == DECODER)
+ vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_vpu_reset_dec_handler, dev, rst_id);
+ else
+ vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_vpu_reset_enc_handler, dev, rst_id);

fw = devm_kzalloc(&plat_dev->dev, sizeof(*fw), GFP_KERNEL);
if (!fw)
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_intr.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_intr.c
index 9a44dfff51bf..f541a7bcbb96 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_intr.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_intr.c
@@ -14,17 +14,34 @@
int mtk_vcodec_wait_for_done_ctx(void *priv, int command, unsigned int timeout_ms,
unsigned int hw_id)
{
- struct mtk_vcodec_ctx *ctx = priv;
+ int instance_type = *((int *)priv);
+ struct mtk_vcodec_dec_ctx *vdec_ctx;
+ struct mtk_vcodec_enc_ctx *venc_ctx;
long timeout_jiff, ret;
int status = 0, ctx_id, ctx_type;
int *ctx_int_cond, *ctx_int_type;
wait_queue_head_t *ctx_queue;
+ struct platform_device *pdev;

- ctx_id = ctx->id;
- ctx_type = ctx->type;
- ctx_int_cond = ctx->int_cond;
- ctx_int_type = ctx->int_type;
- ctx_queue = ctx->queue;
+ if (instance_type == DECODER) {
+ vdec_ctx = priv;
+
+ ctx_id = vdec_ctx->id;
+ ctx_type = vdec_ctx->type;
+ ctx_int_cond = vdec_ctx->int_cond;
+ ctx_int_type = vdec_ctx->int_type;
+ ctx_queue = vdec_ctx->queue;
+ pdev = vdec_ctx->dev->plat_dev;
+ } else {
+ venc_ctx = priv;
+
+ ctx_id = venc_ctx->id;
+ ctx_type = venc_ctx->type;
+ ctx_int_cond = venc_ctx->int_cond;
+ ctx_int_type = venc_ctx->int_type;
+ ctx_queue = venc_ctx->queue;
+ pdev = venc_ctx->dev->plat_dev;
+ }

timeout_jiff = msecs_to_jiffies(timeout_ms);
ret = wait_event_interruptible_timeout(ctx_queue[hw_id],
@@ -33,12 +50,12 @@ int mtk_vcodec_wait_for_done_ctx(void *priv, int command, unsigned int timeout_m

if (!ret) {
status = -1; /* timeout */
- mtk_v4l2_err(ctx->dev->plat_dev, "[%d] cmd=%d, type=%d, dec timeout=%ums (%d %d)",
+ mtk_v4l2_err(pdev, "[%d] cmd=%d, type=%d, dec timeout=%ums (%d %d)",
ctx_id, command, ctx_type, timeout_ms,
ctx_int_cond[hw_id], ctx_int_type[hw_id]);
} else if (-ERESTARTSYS == ret) {
status = -1;
- mtk_v4l2_err(ctx->dev->plat_dev, "[%d] cmd=%d, type=%d, dec inter fail (%d %d)",
+ mtk_v4l2_err(pdev, "[%d] cmd=%d, type=%d, dec inter fail (%d %d)",
ctx_id, command, ctx_type,
ctx_int_cond[hw_id], ctx_int_type[hw_id]);
}
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_intr.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_intr.h
index 11bf0ef94d5d..3e3cc71ee572 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_intr.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_intr.h
@@ -9,7 +9,8 @@

#define MTK_INST_IRQ_RECEIVED 0x1

-struct mtk_vcodec_ctx;
+struct mtk_vcodec_dec_ctx;
+struct mtk_vcodec_enc_ctx;

/* timeout is ms */
int mtk_vcodec_wait_for_done_ctx(void *priv, int command, unsigned int timeout_ms,
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.c
index a4345c25cc29..e63285670b47 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.c
@@ -35,20 +35,33 @@ EXPORT_SYMBOL(mtk_vcodec_get_reg_addr);
int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem)
{
unsigned long size = mem->size;
- struct mtk_vcodec_ctx *ctx = priv;
- struct device *dev = &ctx->dev->plat_dev->dev;
+ int instance_type = *((int *)priv);
+ struct mtk_vcodec_dec_ctx *vdec_ctx;
+ struct mtk_vcodec_enc_ctx *venc_ctx;
+ struct platform_device *pdev;
+ int ctx_id;
+
+ if (instance_type == DECODER) {
+ vdec_ctx = priv;
+ pdev = vdec_ctx->dev->plat_dev;
+ ctx_id = vdec_ctx->id;
+ } else {
+ venc_ctx = priv;
+ pdev = venc_ctx->dev->plat_dev;
+ ctx_id = venc_ctx->id;
+ }

- mem->va = dma_alloc_coherent(dev, size, &mem->dma_addr, GFP_KERNEL);
+ mem->va = dma_alloc_coherent(&pdev->dev, size, &mem->dma_addr, GFP_KERNEL);
if (!mem->va) {
- mtk_v4l2_err(ctx->dev->plat_dev, "%s dma_alloc size=%ld failed!", dev_name(dev),
+ mtk_v4l2_err(pdev, "%s dma_alloc size=%ld failed!", dev_name(&pdev->dev),
size);
return -ENOMEM;
}

- mtk_v4l2_debug(ctx->dev->plat_dev, 3, "[%d] - va = %p", ctx->id, mem->va);
- mtk_v4l2_debug(ctx->dev->plat_dev, 3, "[%d] - dma = 0x%lx", ctx->id,
+ mtk_v4l2_debug(pdev, 3, "[%d] - va = %p", ctx_id, mem->va);
+ mtk_v4l2_debug(pdev, 3, "[%d] - dma = 0x%lx", ctx_id,
(unsigned long)mem->dma_addr);
- mtk_v4l2_debug(ctx->dev->plat_dev, 3, "[%d] size = 0x%lx", ctx->id, size);
+ mtk_v4l2_debug(pdev, 3, "[%d] size = 0x%lx", ctx_id, size);

return 0;
}
@@ -57,21 +70,34 @@ EXPORT_SYMBOL(mtk_vcodec_mem_alloc);
void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem)
{
unsigned long size = mem->size;
- struct mtk_vcodec_ctx *ctx = priv;
- struct device *dev = &ctx->dev->plat_dev->dev;
+ int instance_type = *((int *)priv);
+ struct mtk_vcodec_dec_ctx *vdec_ctx;
+ struct mtk_vcodec_enc_ctx *venc_ctx;
+ struct platform_device *pdev;
+ int ctx_id;
+
+ if (instance_type == DECODER) {
+ vdec_ctx = priv;
+ pdev = vdec_ctx->dev->plat_dev;
+ ctx_id = vdec_ctx->id;
+ } else {
+ venc_ctx = priv;
+ pdev = venc_ctx->dev->plat_dev;
+ ctx_id = venc_ctx->id;
+ }

if (!mem->va) {
- mtk_v4l2_err(ctx->dev->plat_dev, "%s dma_free size=%ld failed!", dev_name(dev),
+ mtk_v4l2_err(pdev, "%s dma_free size=%ld failed!", dev_name(&pdev->dev),
size);
return;
}

- mtk_v4l2_debug(ctx->dev->plat_dev, 3, "[%d] - va = %p", ctx->id, mem->va);
- mtk_v4l2_debug(ctx->dev->plat_dev, 3, "[%d] - dma = 0x%lx", ctx->id,
+ mtk_v4l2_debug(pdev, 3, "[%d] - va = %p", ctx_id, mem->va);
+ mtk_v4l2_debug(pdev, 3, "[%d] - dma = 0x%lx", ctx_id,
(unsigned long)mem->dma_addr);
- mtk_v4l2_debug(ctx->dev->plat_dev, 3, "[%d] size = 0x%lx", ctx->id, size);
+ mtk_v4l2_debug(pdev, 3, "[%d] size = 0x%lx", ctx_id, size);

- dma_free_coherent(dev, size, mem->va, mem->dma_addr);
+ dma_free_coherent(&pdev->dev, size, mem->va, mem->dma_addr);
mem->va = NULL;
mem->dma_addr = 0;
mem->size = 0;
@@ -90,7 +116,7 @@ void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dev *dev, int hw_idx)
EXPORT_SYMBOL(mtk_vcodec_get_hw_dev);

void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
- struct mtk_vcodec_ctx *ctx, int hw_idx)
+ struct mtk_vcodec_dec_ctx *ctx, int hw_idx)
{
unsigned long flags;
struct mtk_vdec_hw_dev *subdev_dev;
@@ -111,11 +137,11 @@ void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
}
EXPORT_SYMBOL(mtk_vcodec_set_curr_ctx);

-struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
- unsigned int hw_idx)
+struct mtk_vcodec_dec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
+ unsigned int hw_idx)
{
unsigned long flags;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
struct mtk_vdec_hw_dev *subdev_dev;

spin_lock_irqsave(&vdec_dev->irqlock, flags);
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h
index 9809f7af6402..fc53dc4fd639 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h
@@ -22,7 +22,7 @@ struct mtk_vcodec_fb {
dma_addr_t dma_addr;
};

-struct mtk_vcodec_ctx;
+struct mtk_vcodec_dec_ctx;
struct mtk_vcodec_dev;

#undef pr_fmt
@@ -69,9 +69,9 @@ void __iomem *mtk_vcodec_get_reg_addr(struct platform_device *pdev, void __iomem
int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem);
void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem);
void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
- struct mtk_vcodec_ctx *ctx, int hw_idx);
-struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
- unsigned int hw_idx);
+ struct mtk_vcodec_dec_ctx *ctx, int hw_idx);
+struct mtk_vcodec_dec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
+ unsigned int hw_idx);
void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dev *dev, int hw_idx);

#endif /* _MTK_VCODEC_UTIL_H_ */
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c
index 39606d685d2e..4c5cd37e4c5f 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c
@@ -706,7 +706,7 @@ struct vdec_av1_slice_pfc {
* @seq: global picture sequence
*/
struct vdec_av1_slice_instance {
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
struct vdec_vpu_inst vpu;

struct mtk_vcodec_mem iq_table;
@@ -756,7 +756,7 @@ static inline bool vdec_av1_slice_need_scale(u32 ref_width, u32 ref_height,
(this_height <= (ref_height << 4));
}

-static void *vdec_av1_get_ctrl_ptr(struct mtk_vcodec_ctx *ctx, int id)
+static void *vdec_av1_get_ctrl_ptr(struct mtk_vcodec_dec_ctx *ctx, int id)
{
struct v4l2_ctrl *ctrl = v4l2_ctrl_find(&ctx->ctrl_hdl, id);

@@ -769,7 +769,7 @@ static void *vdec_av1_get_ctrl_ptr(struct mtk_vcodec_ctx *ctx, int id)
static int vdec_av1_slice_init_cdf_table(struct vdec_av1_slice_instance *instance)
{
u8 *remote_cdf_table;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
struct vdec_av1_slice_init_vsi *vsi;
int ret;

@@ -801,7 +801,7 @@ static int vdec_av1_slice_init_cdf_table(struct vdec_av1_slice_instance *instanc
static int vdec_av1_slice_init_iq_table(struct vdec_av1_slice_instance *instance)
{
u8 *remote_iq_table;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
struct vdec_av1_slice_init_vsi *vsi;
int ret;

@@ -941,7 +941,7 @@ static void vdec_av1_slice_setup_slot(struct vdec_av1_slice_instance *instance,
static int vdec_av1_slice_alloc_working_buffer(struct vdec_av1_slice_instance *instance,
struct vdec_av1_slice_vsi *vsi)
{
- struct mtk_vcodec_ctx *ctx = instance->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = instance->ctx;
enum vdec_av1_slice_resolution_level level;
u32 max_sb_w, max_sb_h, max_w, max_h, w, h;
int i, ret;
@@ -1024,7 +1024,7 @@ static int vdec_av1_slice_alloc_working_buffer(struct vdec_av1_slice_instance *i

static void vdec_av1_slice_free_working_buffer(struct vdec_av1_slice_instance *instance)
{
- struct mtk_vcodec_ctx *ctx = instance->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = instance->ctx;
int i;

for (i = 0; i < ARRAY_SIZE(instance->mv); i++)
@@ -1878,7 +1878,7 @@ static int vdec_av1_slice_update_core(struct vdec_av1_slice_instance *instance,
return 0;
}

-static int vdec_av1_slice_init(struct mtk_vcodec_ctx *ctx)
+static int vdec_av1_slice_init(struct mtk_vcodec_dec_ctx *ctx)
{
struct vdec_av1_slice_instance *instance;
struct vdec_av1_slice_init_vsi *vsi;
@@ -1979,7 +1979,7 @@ static int vdec_av1_slice_flush(void *h_vdec, struct mtk_vcodec_mem *bs,

static void vdec_av1_slice_get_pic_info(struct vdec_av1_slice_instance *instance)
{
- struct mtk_vcodec_ctx *ctx = instance->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = instance->ctx;
u32 data[3];

mtk_vcodec_debug(instance->ctx->dev->plat_dev, ctx->id, "w %u h %u\n",
@@ -2006,7 +2006,7 @@ static inline void vdec_av1_slice_get_dpb_size(struct vdec_av1_slice_instance *i
static void vdec_av1_slice_get_crop_info(struct vdec_av1_slice_instance *instance,
struct v4l2_rect *cr)
{
- struct mtk_vcodec_ctx *ctx = instance->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = instance->ctx;

cr->left = 0;
cr->top = 0;
@@ -2047,7 +2047,7 @@ static int vdec_av1_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
struct vdec_lat_buf *lat_buf;
struct vdec_av1_slice_pfc *pfc;
struct vdec_av1_slice_vsi *vsi;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
int ret;

if (!instance || !instance->ctx)
@@ -2158,7 +2158,7 @@ static int vdec_av1_slice_core_decode(struct vdec_lat_buf *lat_buf)
{
struct vdec_av1_slice_instance *instance;
struct vdec_av1_slice_pfc *pfc;
- struct mtk_vcodec_ctx *ctx = NULL;
+ struct mtk_vcodec_dec_ctx *ctx = NULL;
struct vdec_fb *fb = NULL;
int ret = -EINVAL;

diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_if.c
index fba4efd59729..64ec91d5bb13 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_if.c
@@ -117,7 +117,7 @@ struct vdec_h264_vsi {
/**
* struct vdec_h264_inst - h264 decoder instance
* @num_nalu : how many nalus be decoded
- * @ctx : point to mtk_vcodec_ctx
+ * @ctx : point to mtk_vcodec_dec_ctx
* @pred_buf : HW working predication buffer
* @mv_buf : HW working motion vector buffer
* @vpu : VPU instance
@@ -125,7 +125,7 @@ struct vdec_h264_vsi {
*/
struct vdec_h264_inst {
unsigned int num_nalu;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
struct mtk_vcodec_mem pred_buf;
struct mtk_vcodec_mem mv_buf[H264_MAX_FB_NUM];
struct vdec_vpu_inst vpu;
@@ -274,7 +274,7 @@ static void get_dpb_size(struct vdec_h264_inst *inst, unsigned int *dpb_sz)
mtk_vcodec_debug(inst->ctx->dev->plat_dev, inst->ctx->id, "sz=%d", *dpb_sz);
}

-static int vdec_h264_init(struct mtk_vcodec_ctx *ctx)
+static int vdec_h264_init(struct mtk_vcodec_dec_ctx *ctx)
{
struct vdec_h264_inst *inst = NULL;
int err;
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c
index 580ce979e2a3..5ca20d75dc8e 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.c
@@ -33,7 +33,7 @@ void mtk_vdec_h264_get_ref_list(u8 *ref_list,
memset(&ref_list[num_valid], 0x20, 32 - num_valid);
}

-void *mtk_vdec_h264_get_ctrl_ptr(struct mtk_vcodec_ctx *ctx, int id)
+void *mtk_vdec_h264_get_ctrl_ptr(struct mtk_vcodec_dec_ctx *ctx, int id)
{
struct v4l2_ctrl *ctrl = v4l2_ctrl_find(&ctx->ctrl_hdl, id);

@@ -43,7 +43,7 @@ void *mtk_vdec_h264_get_ctrl_ptr(struct mtk_vcodec_ctx *ctx, int id)
return ctrl->p_cur.p;
}

-void mtk_vdec_h264_fill_dpb_info(struct mtk_vcodec_ctx *ctx,
+void mtk_vdec_h264_fill_dpb_info(struct mtk_vcodec_dec_ctx *ctx,
struct slice_api_h264_decode_param *decode_params,
struct mtk_h264_dpb_info *h264_dpb_info)
{
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h
index 53d0a7c962a9..0dda9e2315c0 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h
@@ -182,7 +182,7 @@ void mtk_vdec_h264_get_ref_list(u8 *ref_list,
*
* Return: returns CID ctrl address.
*/
-void *mtk_vdec_h264_get_ctrl_ptr(struct mtk_vcodec_ctx *ctx, int id);
+void *mtk_vdec_h264_get_ctrl_ptr(struct mtk_vcodec_dec_ctx *ctx, int id);

/**
* mtk_vdec_h264_fill_dpb_info - get each CID contrl address.
@@ -191,7 +191,7 @@ void *mtk_vdec_h264_get_ctrl_ptr(struct mtk_vcodec_ctx *ctx, int id);
* @decode_params: slice decode params
* @h264_dpb_info: dpb buffer information
*/
-void mtk_vdec_h264_fill_dpb_info(struct mtk_vcodec_ctx *ctx,
+void mtk_vdec_h264_fill_dpb_info(struct mtk_vcodec_dec_ctx *ctx,
struct slice_api_h264_decode_param *decode_params,
struct mtk_h264_dpb_info *h264_dpb_info);

diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_if.c
index 3c91395a8d5c..410da85bd478 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_if.c
@@ -74,7 +74,7 @@ struct vdec_h264_vsi {
/**
* struct vdec_h264_slice_inst - h264 decoder instance
* @num_nalu : how many nalus be decoded
- * @ctx : point to mtk_vcodec_ctx
+ * @ctx : point to mtk_vcodec_dec_ctx
* @pred_buf : HW working predication buffer
* @mv_buf : HW working motion vector buffer
* @vpu : VPU instance
@@ -84,7 +84,7 @@ struct vdec_h264_vsi {
*/
struct vdec_h264_slice_inst {
unsigned int num_nalu;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
struct mtk_vcodec_mem pred_buf;
struct mtk_vcodec_mem mv_buf[H264_MAX_MV_NUM];
struct vdec_vpu_inst vpu;
@@ -224,7 +224,7 @@ static void free_mv_buf(struct vdec_h264_slice_inst *inst)
static void get_pic_info(struct vdec_h264_slice_inst *inst,
struct vdec_pic_info *pic)
{
- struct mtk_vcodec_ctx *ctx = inst->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = inst->ctx;

ctx->picinfo.buf_w = ALIGN(ctx->picinfo.pic_w, VCODEC_DEC_ALIGNED_64);
ctx->picinfo.buf_h = ALIGN(ctx->picinfo.pic_h, VCODEC_DEC_ALIGNED_64);
@@ -273,7 +273,7 @@ static void get_dpb_size(struct vdec_h264_slice_inst *inst, unsigned int *dpb_sz
mtk_vcodec_debug(inst->ctx->dev->plat_dev, inst->ctx->id, "sz=%d", *dpb_sz);
}

-static int vdec_h264_slice_init(struct mtk_vcodec_ctx *ctx)
+static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx)
{
struct vdec_h264_slice_inst *inst;
int err;
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
index ee6a69b0f148..37ed8f5abccb 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
@@ -133,7 +133,7 @@ struct vdec_h264_slice_share_info {
* struct vdec_h264_slice_inst - h264 decoder instance
*
* @slice_dec_num: how many picture be decoded
- * @ctx: point to mtk_vcodec_ctx
+ * @ctx: point to mtk_vcodec_dec_ctx
* @pred_buf: HW working predication buffer
* @mv_buf: HW working motion vector buffer
* @vpu: VPU instance
@@ -153,7 +153,7 @@ struct vdec_h264_slice_share_info {
*/
struct vdec_h264_slice_inst {
unsigned int slice_dec_num;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
struct mtk_vcodec_mem pred_buf;
struct mtk_vcodec_mem mv_buf[H264_MAX_MV_NUM];
struct vdec_vpu_inst vpu;
@@ -347,7 +347,7 @@ static void vdec_h264_slice_free_mv_buf(struct vdec_h264_slice_inst *inst)

static void vdec_h264_slice_get_pic_info(struct vdec_h264_slice_inst *inst)
{
- struct mtk_vcodec_ctx *ctx = inst->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = inst->ctx;
u32 data[3];

data[0] = ctx->picinfo.pic_w;
@@ -396,7 +396,7 @@ static void vdec_h264_slice_get_crop_info(struct vdec_h264_slice_inst *inst,
cr->left, cr->top, cr->width, cr->height);
}

-static int vdec_h264_slice_init(struct mtk_vcodec_ctx *ctx)
+static int vdec_h264_slice_init(struct mtk_vcodec_dec_ctx *ctx)
{
struct vdec_h264_slice_inst *inst;
int err, vsi_size;
@@ -462,7 +462,7 @@ static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf)
u64 vdec_fb_va;
u64 y_fb_dma, c_fb_dma;
int err, timeout, i;
- struct mtk_vcodec_ctx *ctx = lat_buf->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = lat_buf->ctx;
struct vdec_h264_slice_inst *inst = ctx->drv_handle;
struct vb2_v4l2_buffer *vb2_v4l2;
struct vdec_h264_slice_share_info *share_info = lat_buf->private_data;
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_hevc_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_hevc_req_multi_if.c
index 1a8f2a189ab3..ef3bc5bd87a5 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_hevc_req_multi_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_hevc_req_multi_if.c
@@ -344,7 +344,7 @@ struct vdec_hevc_slice_share_info {
* struct vdec_hevc_slice_inst - hevc decoder instance
*
* @slice_dec_num: how many picture be decoded
- * @ctx: point to mtk_vcodec_ctx
+ * @ctx: point to mtk_vcodec_dec_ctx
* @mv_buf: HW working motion vector buffer
* @vpu: VPU instance
* @vsi: vsi used for lat
@@ -359,7 +359,7 @@ struct vdec_hevc_slice_share_info {
*/
struct vdec_hevc_slice_inst {
unsigned int slice_dec_num;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
struct mtk_vcodec_mem mv_buf[HEVC_MAX_MV_NUM];
struct vdec_vpu_inst vpu;
struct vdec_hevc_slice_vsi *vsi;
@@ -380,7 +380,7 @@ static unsigned int vdec_hevc_get_mv_buf_size(unsigned int width, unsigned int h
return 64 * unit_size;
}

-static void *vdec_hevc_get_ctrl_ptr(struct mtk_vcodec_ctx *ctx, int id)
+static void *vdec_hevc_get_ctrl_ptr(struct mtk_vcodec_dec_ctx *ctx, int id)
{
struct v4l2_ctrl *ctrl = v4l2_ctrl_find(&ctx->ctrl_hdl, id);

@@ -390,7 +390,7 @@ static void *vdec_hevc_get_ctrl_ptr(struct mtk_vcodec_ctx *ctx, int id)
return ctrl->p_cur.p;
}

-static void vdec_hevc_fill_dpb_info(struct mtk_vcodec_ctx *ctx,
+static void vdec_hevc_fill_dpb_info(struct mtk_vcodec_dec_ctx *ctx,
struct slice_api_hevc_decode_param *decode_params,
struct mtk_hevc_dpb_info *hevc_dpb_info)
{
@@ -680,7 +680,7 @@ static void vdec_hevc_slice_free_mv_buf(struct vdec_hevc_slice_inst *inst)

static void vdec_hevc_slice_get_pic_info(struct vdec_hevc_slice_inst *inst)
{
- struct mtk_vcodec_ctx *ctx = inst->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = inst->ctx;
u32 data[3];

data[0] = ctx->picinfo.pic_w;
@@ -801,7 +801,7 @@ static int vdec_hevc_slice_setup_core_buffer(struct vdec_hevc_slice_inst *inst,
struct vdec_lat_buf *lat_buf)
{
struct mtk_vcodec_mem *mem;
- struct mtk_vcodec_ctx *ctx = inst->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = inst->ctx;
struct vb2_v4l2_buffer *vb2_v4l2;
struct vdec_fb *fb;
u64 y_fb_dma, c_fb_dma;
@@ -857,7 +857,7 @@ static int vdec_hevc_slice_setup_core_buffer(struct vdec_hevc_slice_inst *inst,
return 0;
}

-static int vdec_hevc_slice_init(struct mtk_vcodec_ctx *ctx)
+static int vdec_hevc_slice_init(struct mtk_vcodec_dec_ctx *ctx)
{
struct vdec_hevc_slice_inst *inst;
int err, vsi_size;
@@ -930,7 +930,7 @@ static void vdec_hevc_slice_deinit(void *h_vdec)
static int vdec_hevc_slice_core_decode(struct vdec_lat_buf *lat_buf)
{
int err, timeout;
- struct mtk_vcodec_ctx *ctx = lat_buf->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = lat_buf->ctx;
struct vdec_hevc_slice_inst *inst = ctx->drv_handle;
struct vdec_hevc_slice_share_info *share_info = lat_buf->private_data;
struct vdec_vpu_inst *vpu = &inst->vpu;
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_if.c
index fba6b1289434..0e9a44cbdc44 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_if.c
@@ -160,7 +160,7 @@ struct vdec_vp8_inst {
struct mtk_vcodec_mem working_buf;
struct vdec_vp8_hw_reg_base reg_base;
unsigned int frm_cnt;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
struct vdec_vpu_inst vpu;
struct vdec_vp8_vsi *vsi;
};
@@ -397,7 +397,7 @@ static void free_working_buf(struct vdec_vp8_inst *inst)
inst->vsi->dec.working_buf_dma = 0;
}

-static int vdec_vp8_init(struct mtk_vcodec_ctx *ctx)
+static int vdec_vp8_init(struct mtk_vcodec_dec_ctx *ctx)
{
struct vdec_vp8_inst *inst;
int err;
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c
index 72e837911330..807d426d6e82 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c
@@ -101,12 +101,12 @@ struct vdec_vp8_slice_inst {
struct mtk_vcodec_mem wrap_y_buf;
struct mtk_vcodec_mem wrap_c_buf;
struct mtk_vcodec_mem vld_wrapper_buf;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
struct vdec_vpu_inst vpu;
struct vdec_vp8_slice_vsi *vsi;
};

-static void *vdec_vp8_slice_get_ctrl_ptr(struct mtk_vcodec_ctx *ctx, int id)
+static void *vdec_vp8_slice_get_ctrl_ptr(struct mtk_vcodec_dec_ctx *ctx, int id)
{
struct v4l2_ctrl *ctrl = v4l2_ctrl_find(&ctx->ctrl_hdl, id);

@@ -118,7 +118,7 @@ static void *vdec_vp8_slice_get_ctrl_ptr(struct mtk_vcodec_ctx *ctx, int id)

static void vdec_vp8_slice_get_pic_info(struct vdec_vp8_slice_inst *inst)
{
- struct mtk_vcodec_ctx *ctx = inst->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = inst->ctx;
unsigned int data[3];

data[0] = ctx->picinfo.pic_w;
@@ -237,7 +237,7 @@ static u64 vdec_vp8_slice_get_ref_by_ts(const struct v4l2_ctrl_vp8_frame *frame_
static int vdec_vp8_slice_get_decode_parameters(struct vdec_vp8_slice_inst *inst)
{
const struct v4l2_ctrl_vp8_frame *frame_header;
- struct mtk_vcodec_ctx *ctx = inst->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = inst->ctx;
struct vb2_queue *vq;
struct vb2_buffer *vb;
u64 referenct_ts;
@@ -277,7 +277,7 @@ static int vdec_vp8_slice_get_decode_parameters(struct vdec_vp8_slice_inst *inst
return 0;
}

-static int vdec_vp8_slice_init(struct mtk_vcodec_ctx *ctx)
+static int vdec_vp8_slice_init(struct mtk_vcodec_dec_ctx *ctx)
{
struct vdec_vp8_slice_inst *inst;
int err;
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_if.c
index 5cceb5f7b1b3..9d7337c61577 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_if.c
@@ -196,7 +196,7 @@ struct vdec_vp9_inst {
struct list_head fb_free_list;
struct list_head fb_disp_list;
struct vdec_fb *cur_fb;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
struct vdec_vpu_inst vpu;
struct vdec_vp9_vsi *vsi;
unsigned int total_frm_cnt;
@@ -539,7 +539,7 @@ static void vp9_swap_frm_bufs(struct vdec_vp9_inst *inst)

static bool vp9_wait_dec_end(struct vdec_vp9_inst *inst)
{
- struct mtk_vcodec_ctx *ctx = inst->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = inst->ctx;

mtk_vcodec_wait_for_done_ctx(inst->ctx,
MTK_INST_IRQ_RECEIVED,
@@ -551,7 +551,7 @@ static bool vp9_wait_dec_end(struct vdec_vp9_inst *inst)
return false;
}

-static struct vdec_vp9_inst *vp9_alloc_inst(struct mtk_vcodec_ctx *ctx)
+static struct vdec_vp9_inst *vp9_alloc_inst(struct mtk_vcodec_dec_ctx *ctx)
{
int result;
struct mtk_vcodec_mem mem;
@@ -797,7 +797,7 @@ static void vdec_vp9_deinit(void *h_vdec)
vp9_free_inst(inst);
}

-static int vdec_vp9_init(struct mtk_vcodec_ctx *ctx)
+static int vdec_vp9_init(struct mtk_vcodec_dec_ctx *ctx)
{
struct vdec_vp9_inst *inst;

diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
index e3e12aadbab0..20605e1832e3 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
@@ -445,7 +445,7 @@ struct vdec_vp9_slice_ref {
* @counts_helper: counts table according to newest kernel spec
*/
struct vdec_vp9_slice_instance {
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
struct vdec_vpu_inst vpu;

int seq;
@@ -506,7 +506,7 @@ static int vdec_vp9_slice_init_default_frame_ctx(struct vdec_vp9_slice_instance
{
struct vdec_vp9_slice_frame_ctx *remote_frame_ctx;
struct vdec_vp9_slice_frame_ctx *frame_ctx;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
struct vdec_vp9_slice_init_vsi *vsi;
int ret = 0;

@@ -543,7 +543,7 @@ static int vdec_vp9_slice_init_default_frame_ctx(struct vdec_vp9_slice_instance
static int vdec_vp9_slice_alloc_working_buffer(struct vdec_vp9_slice_instance *instance,
struct vdec_vp9_slice_vsi *vsi)
{
- struct mtk_vcodec_ctx *ctx = instance->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = instance->ctx;
enum vdec_vp9_slice_resolution_level level;
/* super blocks */
unsigned int max_sb_w;
@@ -636,7 +636,7 @@ static int vdec_vp9_slice_alloc_working_buffer(struct vdec_vp9_slice_instance *i

static void vdec_vp9_slice_free_working_buffer(struct vdec_vp9_slice_instance *instance)
{
- struct mtk_vcodec_ctx *ctx = instance->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = instance->ctx;
int i;

for (i = 0; i < ARRAY_SIZE(instance->mv); i++) {
@@ -1864,7 +1864,7 @@ static int vdec_vp9_slice_update_core(struct vdec_vp9_slice_instance *instance,
return 0;
}

-static int vdec_vp9_slice_init(struct mtk_vcodec_ctx *ctx)
+static int vdec_vp9_slice_init(struct mtk_vcodec_dec_ctx *ctx)
{
struct vdec_vp9_slice_instance *instance;
struct vdec_vp9_slice_init_vsi *vsi;
@@ -1950,7 +1950,7 @@ static int vdec_vp9_slice_flush(void *h_vdec, struct mtk_vcodec_mem *bs,

static void vdec_vp9_slice_get_pic_info(struct vdec_vp9_slice_instance *instance)
{
- struct mtk_vcodec_ctx *ctx = instance->ctx;
+ struct mtk_vcodec_dec_ctx *ctx = instance->ctx;
unsigned int data[3];

mtk_vcodec_debug(ctx->dev->plat_dev, ctx->id, "w %u h %u\n",
@@ -2004,7 +2004,7 @@ static int vdec_vp9_slice_single_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
struct vdec_vp9_slice_instance *instance = h_vdec;
struct vdec_vp9_slice_pfc *pfc = &instance->sc_pfc;
struct vdec_vp9_slice_vsi *vsi;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
int ret;

if (!instance || !instance->ctx)
@@ -2063,7 +2063,7 @@ static int vdec_vp9_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
struct vdec_lat_buf *lat_buf;
struct vdec_vp9_slice_pfc *pfc;
struct vdec_vp9_slice_vsi *vsi;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
int ret;

if (!instance || !instance->ctx)
@@ -2160,7 +2160,7 @@ static int vdec_vp9_slice_core_decode(struct vdec_lat_buf *lat_buf)
{
struct vdec_vp9_slice_instance *instance;
struct vdec_vp9_slice_pfc *pfc;
- struct mtk_vcodec_ctx *ctx = NULL;
+ struct mtk_vcodec_dec_ctx *ctx = NULL;
struct vdec_fb *fb = NULL;
int ret = -EINVAL;

diff --git a/drivers/media/platform/mediatek/vcodec/vdec_drv_base.h b/drivers/media/platform/mediatek/vcodec/vdec_drv_base.h
index e913f963b7db..f6abb9365234 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_drv_base.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec_drv_base.h
@@ -15,7 +15,7 @@ struct vdec_common_if {
* @ctx : [in] mtk v4l2 context
* @h_vdec : [out] driver handle
*/
- int (*init)(struct mtk_vcodec_ctx *ctx);
+ int (*init)(struct mtk_vcodec_dec_ctx *ctx);

/**
* (*decode)() - trigger decode
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_drv_if.c b/drivers/media/platform/mediatek/vcodec/vdec_drv_if.c
index ae93f68b8473..0c8385886996 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_drv_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec_drv_if.c
@@ -14,7 +14,7 @@
#include "vdec_drv_base.h"
#include "mtk_vcodec_dec_pm.h"

-int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
+int vdec_if_init(struct mtk_vcodec_dec_ctx *ctx, unsigned int fourcc)
{
enum mtk_vdec_hw_arch hw_arch = ctx->dev->vdec_pdata->hw_arch;
int ret = 0;
@@ -68,7 +68,7 @@ int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
return ret;
}

-int vdec_if_decode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs,
+int vdec_if_decode(struct mtk_vcodec_dec_ctx *ctx, struct mtk_vcodec_mem *bs,
struct vdec_fb *fb, bool *res_chg)
{
int ret = 0;
@@ -101,7 +101,7 @@ int vdec_if_decode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs,
return ret;
}

-int vdec_if_get_param(struct mtk_vcodec_ctx *ctx, enum vdec_get_param_type type,
+int vdec_if_get_param(struct mtk_vcodec_dec_ctx *ctx, enum vdec_get_param_type type,
void *out)
{
int ret = 0;
@@ -116,7 +116,7 @@ int vdec_if_get_param(struct mtk_vcodec_ctx *ctx, enum vdec_get_param_type type,
return ret;
}

-void vdec_if_deinit(struct mtk_vcodec_ctx *ctx)
+void vdec_if_deinit(struct mtk_vcodec_dec_ctx *ctx)
{
if (!ctx->drv_handle)
return;
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_drv_if.h b/drivers/media/platform/mediatek/vcodec/vdec_drv_if.h
index a8da6a59a6a5..816ed6ab1ed0 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_drv_if.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec_drv_if.h
@@ -69,14 +69,14 @@ extern const struct vdec_common_if vdec_av1_slice_lat_if;
* @ctx : [in] v4l2 context
* @fourcc : [in] video format fourcc, V4L2_PIX_FMT_H264/VP8/VP9..
*/
-int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc);
+int vdec_if_init(struct mtk_vcodec_dec_ctx *ctx, unsigned int fourcc);

/**
* vdec_if_deinit() - deinitialize decode driver
* @ctx : [in] v4l2 context
*
*/
-void vdec_if_deinit(struct mtk_vcodec_ctx *ctx);
+void vdec_if_deinit(struct mtk_vcodec_dec_ctx *ctx);

/**
* vdec_if_decode() - trigger decode
@@ -90,7 +90,7 @@ void vdec_if_deinit(struct mtk_vcodec_ctx *ctx);
*
* Return: 0 on success. -EIO on unrecoverable error.
*/
-int vdec_if_decode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs,
+int vdec_if_decode(struct mtk_vcodec_dec_ctx *ctx, struct mtk_vcodec_mem *bs,
struct vdec_fb *fb, bool *res_chg);

/**
@@ -99,7 +99,7 @@ int vdec_if_decode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs,
* @type : [in] input parameter type
* @out : [out] buffer to store query result
*/
-int vdec_if_get_param(struct mtk_vcodec_ctx *ctx, enum vdec_get_param_type type,
+int vdec_if_get_param(struct mtk_vcodec_dec_ctx *ctx, enum vdec_get_param_type type,
void *out);

#endif
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
index 36c17f1fb43a..e66d0b75788e 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
@@ -204,7 +204,7 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue)
}

void vdec_msg_queue_deinit(struct vdec_msg_queue *msg_queue,
- struct mtk_vcodec_ctx *ctx)
+ struct mtk_vcodec_dec_ctx *ctx)
{
struct vdec_lat_buf *lat_buf;
struct mtk_vcodec_mem *mem;
@@ -242,8 +242,8 @@ static void vdec_msg_queue_core_work(struct work_struct *work)
{
struct vdec_msg_queue *msg_queue =
container_of(work, struct vdec_msg_queue, core_work);
- struct mtk_vcodec_ctx *ctx =
- container_of(msg_queue, struct mtk_vcodec_ctx, msg_queue);
+ struct mtk_vcodec_dec_ctx *ctx =
+ container_of(msg_queue, struct mtk_vcodec_dec_ctx, msg_queue);
struct mtk_vcodec_dev *dev = ctx->dev;
struct vdec_lat_buf *lat_buf;

@@ -283,7 +283,7 @@ static void vdec_msg_queue_core_work(struct work_struct *work)
}

int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,
- struct mtk_vcodec_ctx *ctx, core_decode_cb_t core_decode,
+ struct mtk_vcodec_dec_ctx *ctx, core_decode_cb_t core_decode,
int private_size)
{
struct vdec_lat_buf *lat_buf;
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
index 2a745e902ad1..eea56f24b60e 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
@@ -17,7 +17,7 @@
#define NUM_BUFFER_COUNT 3

struct vdec_lat_buf;
-struct mtk_vcodec_ctx;
+struct mtk_vcodec_dec_ctx;
struct mtk_vcodec_dev;
typedef int (*core_decode_cb_t)(struct vdec_lat_buf *lat_buf);

@@ -76,7 +76,7 @@ struct vdec_lat_buf {
struct media_request *src_buf_req;

void *private_data;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
core_decode_cb_t core_decode;
struct list_head lat_list;
struct list_head core_list;
@@ -130,7 +130,7 @@ struct vdec_msg_queue {
* Return: returns 0 if init successfully, or fail.
*/
int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,
- struct mtk_vcodec_ctx *ctx, core_decode_cb_t core_decode,
+ struct mtk_vcodec_dec_ctx *ctx, core_decode_cb_t core_decode,
int private_size);

/**
@@ -186,6 +186,6 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue);
* @ctx: v4l2 ctx
*/
void vdec_msg_queue_deinit(struct vdec_msg_queue *msg_queue,
- struct mtk_vcodec_ctx *ctx);
+ struct mtk_vcodec_dec_ctx *ctx);

#endif
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.h b/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.h
index 0436bba91457..c9766c108209 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.h
@@ -9,7 +9,7 @@

#include "mtk_vcodec_fw.h"

-struct mtk_vcodec_ctx;
+struct mtk_vcodec_dec_ctx;

/**
* struct vdec_vpu_inst - VPU instance for video codec
@@ -40,7 +40,7 @@ struct vdec_vpu_inst {
uint32_t fw_abi_version;
uint32_t inst_id;
unsigned int signaled;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_dec_ctx *ctx;
wait_queue_head_t wq;
mtk_vcodec_ipi_handler handler;
unsigned int codec_type;
diff --git a/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c b/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c
index fc3e021d24e8..66bbb892d8e7 100644
--- a/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c
+++ b/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c
@@ -221,7 +221,7 @@ struct venc_h264_inst {
struct venc_vpu_inst vpu_inst;
struct venc_h264_vsi *vsi;
struct venc_h264_vsi_34 *vsi_34;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_enc_ctx *ctx;
};

static inline u32 h264_read_reg(struct venc_h264_inst *inst, u32 addr)
@@ -422,7 +422,7 @@ static int h264_enc_alloc_work_buf(struct venc_h264_inst *inst, bool is_34bit)
static unsigned int h264_enc_wait_venc_done(struct venc_h264_inst *inst)
{
unsigned int irq_status = 0;
- struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)inst->ctx;
+ struct mtk_vcodec_enc_ctx *ctx = (struct mtk_vcodec_enc_ctx *)inst->ctx;

if (!mtk_vcodec_wait_for_done_ctx(ctx, MTK_INST_IRQ_RECEIVED,
WAIT_INTR_TIMEOUT_MS, 0)) {
@@ -533,7 +533,7 @@ static int h264_encode_frame(struct venc_h264_inst *inst,
unsigned int intra_period;
unsigned int irq_status;
struct venc_frame_info frame_info;
- struct mtk_vcodec_ctx *ctx = inst->ctx;
+ struct mtk_vcodec_enc_ctx *ctx = inst->ctx;

mtk_vcodec_debug_enter(inst->ctx->dev->plat_dev, inst->ctx->id);
mtk_vcodec_debug(inst->ctx->dev->plat_dev, inst->ctx->id, "frm_cnt = %d\n ", inst->frm_cnt);
@@ -607,7 +607,7 @@ static void h264_encode_filler(struct venc_h264_inst *inst, void *buf,
memset(p, 0xff, size);
}

-static int h264_enc_init(struct mtk_vcodec_ctx *ctx)
+static int h264_enc_init(struct mtk_vcodec_enc_ctx *ctx)
{
const bool is_ext = MTK_ENC_CTX_IS_EXT(ctx);
int ret = 0;
@@ -650,7 +650,7 @@ static int h264_enc_encode(void *handle,
{
int ret = 0;
struct venc_h264_inst *inst = (struct venc_h264_inst *)handle;
- struct mtk_vcodec_ctx *ctx = inst->ctx;
+ struct mtk_vcodec_enc_ctx *ctx = inst->ctx;

mtk_vcodec_debug(inst->ctx->dev->plat_dev, inst->ctx->id, "opt %d ->", opt);

@@ -784,7 +784,7 @@ static int h264_enc_set_param(void *handle,
{
int ret = 0;
struct venc_h264_inst *inst = (struct venc_h264_inst *)handle;
- struct mtk_vcodec_ctx *ctx = inst->ctx;
+ struct mtk_vcodec_enc_ctx *ctx = inst->ctx;
const bool is_34bit = MTK_ENC_IOVA_IS_34BIT(ctx);

mtk_vcodec_debug(inst->ctx->dev->plat_dev, inst->ctx->id, "->type=%d", type);
diff --git a/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c b/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c
index 4e1c49093385..dc48bf881aa7 100644
--- a/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c
+++ b/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c
@@ -129,7 +129,7 @@ struct venc_vp8_inst {
unsigned int ts_mode;
struct venc_vpu_inst vpu_inst;
struct venc_vp8_vsi *vsi;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_enc_ctx *ctx;
};

static inline u32 vp8_enc_read_reg(struct venc_vp8_inst *inst, u32 addr)
@@ -219,7 +219,7 @@ static int vp8_enc_alloc_work_buf(struct venc_vp8_inst *inst)
static unsigned int vp8_enc_wait_venc_done(struct venc_vp8_inst *inst)
{
unsigned int irq_status = 0;
- struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)inst->ctx;
+ struct mtk_vcodec_enc_ctx *ctx = (struct mtk_vcodec_enc_ctx *)inst->ctx;

if (!mtk_vcodec_wait_for_done_ctx(ctx, MTK_INST_IRQ_RECEIVED,
WAIT_INTR_TIMEOUT_MS, 0)) {
@@ -328,7 +328,7 @@ static int vp8_enc_encode_frame(struct venc_vp8_inst *inst,
return ret;
}

-static int vp8_enc_init(struct mtk_vcodec_ctx *ctx)
+static int vp8_enc_init(struct mtk_vcodec_enc_ctx *ctx)
{
int ret = 0;
struct venc_vp8_inst *inst;
@@ -367,7 +367,7 @@ static int vp8_enc_encode(void *handle,
{
int ret = 0;
struct venc_vp8_inst *inst = (struct venc_vp8_inst *)handle;
- struct mtk_vcodec_ctx *ctx = inst->ctx;
+ struct mtk_vcodec_enc_ctx *ctx = inst->ctx;

mtk_vcodec_debug_enter(inst->ctx->dev->plat_dev, inst->ctx->id);

diff --git a/drivers/media/platform/mediatek/vcodec/venc_drv_base.h b/drivers/media/platform/mediatek/vcodec/venc_drv_base.h
index 3d718411dc73..17f8183461b5 100644
--- a/drivers/media/platform/mediatek/vcodec/venc_drv_base.h
+++ b/drivers/media/platform/mediatek/vcodec/venc_drv_base.h
@@ -19,7 +19,7 @@ struct venc_common_if {
* @ctx: [in] mtk v4l2 context
* @handle: [out] driver handle
*/
- int (*init)(struct mtk_vcodec_ctx *ctx);
+ int (*init)(struct mtk_vcodec_enc_ctx *ctx);

/**
* (*encode)() - trigger encode
diff --git a/drivers/media/platform/mediatek/vcodec/venc_drv_if.c b/drivers/media/platform/mediatek/vcodec/venc_drv_if.c
index ce0bce811615..08083030516e 100644
--- a/drivers/media/platform/mediatek/vcodec/venc_drv_if.c
+++ b/drivers/media/platform/mediatek/vcodec/venc_drv_if.c
@@ -16,7 +16,7 @@
#include "mtk_vcodec_enc.h"
#include "mtk_vcodec_enc_pm.h"

-int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
+int venc_if_init(struct mtk_vcodec_enc_ctx *ctx, unsigned int fourcc)
{
int ret = 0;

@@ -40,8 +40,8 @@ int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
return ret;
}

-int venc_if_set_param(struct mtk_vcodec_ctx *ctx,
- enum venc_set_param_type type, struct venc_enc_param *in)
+int venc_if_set_param(struct mtk_vcodec_enc_ctx *ctx,
+ enum venc_set_param_type type, struct venc_enc_param *in)
{
int ret = 0;

@@ -54,7 +54,7 @@ int venc_if_set_param(struct mtk_vcodec_ctx *ctx,
return ret;
}

-int venc_if_encode(struct mtk_vcodec_ctx *ctx,
+int venc_if_encode(struct mtk_vcodec_enc_ctx *ctx,
enum venc_start_opt opt, struct venc_frm_buf *frm_buf,
struct mtk_vcodec_mem *bs_buf,
struct venc_done_result *result)
@@ -65,7 +65,7 @@ int venc_if_encode(struct mtk_vcodec_ctx *ctx,
mtk_venc_lock(ctx);

spin_lock_irqsave(&ctx->dev->irqlock, flags);
- ctx->dev->curr_ctx = ctx;
+ ctx->dev->curr_enc_ctx = ctx;
spin_unlock_irqrestore(&ctx->dev->irqlock, flags);

mtk_vcodec_enc_clock_on(&ctx->dev->pm);
@@ -74,14 +74,14 @@ int venc_if_encode(struct mtk_vcodec_ctx *ctx,
mtk_vcodec_enc_clock_off(&ctx->dev->pm);

spin_lock_irqsave(&ctx->dev->irqlock, flags);
- ctx->dev->curr_ctx = NULL;
+ ctx->dev->curr_enc_ctx = NULL;
spin_unlock_irqrestore(&ctx->dev->irqlock, flags);

mtk_venc_unlock(ctx);
return ret;
}

-int venc_if_deinit(struct mtk_vcodec_ctx *ctx)
+int venc_if_deinit(struct mtk_vcodec_enc_ctx *ctx)
{
int ret = 0;

diff --git a/drivers/media/platform/mediatek/vcodec/venc_drv_if.h b/drivers/media/platform/mediatek/vcodec/venc_drv_if.h
index 0b04a1020873..90d714e86ede 100644
--- a/drivers/media/platform/mediatek/vcodec/venc_drv_if.h
+++ b/drivers/media/platform/mediatek/vcodec/venc_drv_if.h
@@ -132,14 +132,14 @@ extern const struct venc_common_if venc_vp8_if;
* @fourcc: encoder input format
* Return: 0 if creating handle successfully, otherwise it is failed.
*/
-int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc);
+int venc_if_init(struct mtk_vcodec_enc_ctx *ctx, unsigned int fourcc);

/*
* venc_if_deinit - Release the driver handle
* @ctx: device context
* Return: 0 if releasing handle successfully, otherwise it is failed.
*/
-int venc_if_deinit(struct mtk_vcodec_ctx *ctx);
+int venc_if_deinit(struct mtk_vcodec_enc_ctx *ctx);

/*
* venc_if_set_param - Set parameter to driver
@@ -148,7 +148,7 @@ int venc_if_deinit(struct mtk_vcodec_ctx *ctx);
* @in: input parameter
* Return: 0 if setting param successfully, otherwise it is failed.
*/
-int venc_if_set_param(struct mtk_vcodec_ctx *ctx,
+int venc_if_set_param(struct mtk_vcodec_enc_ctx *ctx,
enum venc_set_param_type type,
struct venc_enc_param *in);

@@ -161,7 +161,7 @@ int venc_if_set_param(struct mtk_vcodec_ctx *ctx,
* @result: encode result
* Return: 0 if encoding frame successfully, otherwise it is failed.
*/
-int venc_if_encode(struct mtk_vcodec_ctx *ctx,
+int venc_if_encode(struct mtk_vcodec_enc_ctx *ctx,
enum venc_start_opt opt,
struct venc_frm_buf *frm_buf,
struct mtk_vcodec_mem *bs_buf,
diff --git a/drivers/media/platform/mediatek/vcodec/venc_vpu_if.h b/drivers/media/platform/mediatek/vcodec/venc_vpu_if.h
index f83bc1b3f2bf..71370ab98809 100644
--- a/drivers/media/platform/mediatek/vcodec/venc_vpu_if.h
+++ b/drivers/media/platform/mediatek/vcodec/venc_vpu_if.h
@@ -35,7 +35,7 @@ struct venc_vpu_inst {
unsigned int inst_addr;
void *vsi;
int id;
- struct mtk_vcodec_ctx *ctx;
+ struct mtk_vcodec_enc_ctx *ctx;
};

int vpu_enc_init(struct venc_vpu_inst *vpu);
--
2.18.0


2023-06-07 09:02:41

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: [PATCH v2,07/10] mediatek: vcodec: separate struct mtk_vcodec_dev

Adding different dev struct for encoder and decoder, remove
'struct mtk_vcodec_dev'.

Signed-off-by: Yunfei Dong <[email protected]>
---
.../mediatek/vcodec/mtk_vcodec_com_drv.h | 71 +++++
.../mediatek/vcodec/mtk_vcodec_dbgfs.c | 51 ++-
.../mediatek/vcodec/mtk_vcodec_dbgfs.h | 14 +-
.../platform/mediatek/vcodec/mtk_vcodec_dec.c | 4 +-
.../mediatek/vcodec/mtk_vcodec_dec_drv.c | 19 +-
.../mediatek/vcodec/mtk_vcodec_dec_drv.h | 172 +++++++++-
.../mediatek/vcodec/mtk_vcodec_dec_hw.c | 5 +-
.../mediatek/vcodec/mtk_vcodec_dec_hw.h | 4 +-
.../mediatek/vcodec/mtk_vcodec_dec_pm.c | 10 +-
.../mediatek/vcodec/mtk_vcodec_dec_pm.h | 2 +-
.../mediatek/vcodec/mtk_vcodec_dec_stateful.c | 3 +-
.../vcodec/mtk_vcodec_dec_stateless.c | 5 +-
.../platform/mediatek/vcodec/mtk_vcodec_drv.h | 295 ------------------
.../platform/mediatek/vcodec/mtk_vcodec_enc.c | 5 +-
.../mediatek/vcodec/mtk_vcodec_enc_drv.c | 15 +-
.../mediatek/vcodec/mtk_vcodec_enc_drv.h | 93 +++++-
.../mediatek/vcodec/mtk_vcodec_enc_pm.c | 4 +-
.../mediatek/vcodec/mtk_vcodec_enc_pm.h | 4 +-
.../platform/mediatek/vcodec/mtk_vcodec_fw.c | 13 +-
.../platform/mediatek/vcodec/mtk_vcodec_fw.h | 3 +-
.../mediatek/vcodec/mtk_vcodec_fw_priv.h | 3 +-
.../mediatek/vcodec/mtk_vcodec_fw_scp.c | 19 +-
.../mediatek/vcodec/mtk_vcodec_fw_vpu.c | 31 +-
.../mediatek/vcodec/mtk_vcodec_intr.c | 4 +-
.../mediatek/vcodec/mtk_vcodec_util.c | 10 +-
.../mediatek/vcodec/mtk_vcodec_util.h | 8 +-
.../vcodec/vdec/vdec_h264_req_common.h | 2 +-
.../vcodec/vdec/vdec_h264_req_multi_if.c | 2 +-
.../platform/mediatek/vcodec/vdec_drv_if.h | 1 -
.../platform/mediatek/vcodec/vdec_msg_queue.c | 4 +-
.../platform/mediatek/vcodec/vdec_msg_queue.h | 2 +-
.../platform/mediatek/vcodec/vdec_vpu_if.c | 3 +-
.../mediatek/vcodec/venc/venc_h264_if.c | 2 +-
.../mediatek/vcodec/venc/venc_vp8_if.c | 2 +-
.../platform/mediatek/vcodec/venc_drv_base.h | 2 +-
.../platform/mediatek/vcodec/venc_drv_if.c | 4 +-
.../platform/mediatek/vcodec/venc_drv_if.h | 3 +-
.../platform/mediatek/vcodec/venc_vpu_if.c | 2 +-
38 files changed, 469 insertions(+), 427 deletions(-)
delete mode 100644 drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_com_drv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_com_drv.h
index 3b6e1faf60ce..6087e27bd604 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_com_drv.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_com_drv.h
@@ -17,6 +17,77 @@

#define MTK_VCODEC_MAX_PLANES 3

+#define WAIT_INTR_TIMEOUT_MS 1000
+
+/*
+ * enum mtk_q_type - Type of queue
+ */
+enum mtk_q_type {
+ MTK_Q_DATA_SRC = 0,
+ MTK_Q_DATA_DST = 1,
+};
+
+/*
+ * enum mtk_hw_reg_idx - MTK hw register base index
+ */
+enum mtk_hw_reg_idx {
+ VDEC_SYS,
+ VDEC_MISC,
+ VDEC_LD,
+ VDEC_TOP,
+ VDEC_CM,
+ VDEC_AD,
+ VDEC_AV,
+ VDEC_PP,
+ VDEC_HWD,
+ VDEC_HWQ,
+ VDEC_HWB,
+ VDEC_HWG,
+ NUM_MAX_VDEC_REG_BASE,
+ /* h264 encoder */
+ VENC_SYS = NUM_MAX_VDEC_REG_BASE,
+ /* vp8 encoder */
+ VENC_LT_SYS,
+ NUM_MAX_VCODEC_REG_BASE
+};
+
+/*
+ * struct mtk_vcodec_clk_info - Structure used to store clock name
+ */
+struct mtk_vcodec_clk_info {
+ const char *clk_name;
+ struct clk *vcodec_clk;
+};
+
+/*
+ * struct mtk_vcodec_clk - Structure used to store vcodec clock information
+ */
+struct mtk_vcodec_clk {
+ struct mtk_vcodec_clk_info *clk_info;
+ int clk_num;
+};
+
+/*
+ * struct mtk_vcodec_pm - Power management data structure
+ */
+struct mtk_vcodec_pm {
+ struct mtk_vcodec_clk vdec_clk;
+ struct mtk_vcodec_clk venc_clk;
+ struct device *dev;
+};
+
+/*
+ * enum mtk_vdec_hw_id - Hardware index used to separate
+ * different hardware
+ */
+enum mtk_vdec_hw_id {
+ MTK_VDEC_CORE,
+ MTK_VDEC_LAT0,
+ MTK_VDEC_LAT1,
+ MTK_VDEC_LAT_SOC,
+ MTK_VDEC_HW_MAX,
+};
+
/**
* enum mtk_instance_state - The state of an MTK Vcodec instance.
* @MTK_STATE_FREE: default state when instance is created
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c
index b88fc0a0c102..7c25f6e23901 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c
@@ -7,7 +7,8 @@
#include <linux/debugfs.h>

#include "mtk_vcodec_dbgfs.h"
-#include "mtk_vcodec_drv.h"
+#include "mtk_vcodec_dec_drv.h"
+#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_util.h"

static void mtk_vdec_dbgfs_get_format_type(struct mtk_vcodec_dec_ctx *ctx, char *buf,
@@ -72,7 +73,7 @@ static void mtk_vdec_dbgfs_get_help(char *buf, int *used, int total)
static ssize_t mtk_vdec_dbgfs_write(struct file *filp, const char __user *ubuf,
size_t count, loff_t *ppos)
{
- struct mtk_vcodec_dev *vcodec_dev = filp->private_data;
+ struct mtk_vcodec_dec_dev *vcodec_dev = filp->private_data;
struct mtk_vcodec_dbgfs *dbgfs = &vcodec_dev->dbgfs;

mutex_lock(&dbgfs->dbgfs_lock);
@@ -88,7 +89,7 @@ static ssize_t mtk_vdec_dbgfs_write(struct file *filp, const char __user *ubuf,
static ssize_t mtk_vdec_dbgfs_read(struct file *filp, char __user *ubuf,
size_t count, loff_t *ppos)
{
- struct mtk_vcodec_dev *vcodec_dev = filp->private_data;
+ struct mtk_vcodec_dec_dev *vcodec_dev = filp->private_data;
struct mtk_vcodec_dbgfs *dbgfs = &vcodec_dev->dbgfs;
struct mtk_vcodec_dbgfs_inst *dbgfs_inst;
struct mtk_vcodec_dec_ctx *ctx;
@@ -146,7 +147,7 @@ static const struct file_operations vdec_fops = {
void mtk_vcodec_dbgfs_create(struct mtk_vcodec_dec_ctx *ctx)
{
struct mtk_vcodec_dbgfs_inst *dbgfs_inst;
- struct mtk_vcodec_dev *vcodec_dev = ctx->dev;
+ struct mtk_vcodec_dec_dev *vcodec_dev = ctx->dev;

dbgfs_inst = kzalloc(sizeof(*dbgfs_inst), GFP_KERNEL);
if (!dbgfs_inst)
@@ -161,7 +162,7 @@ void mtk_vcodec_dbgfs_create(struct mtk_vcodec_dec_ctx *ctx)
}
EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_create);

-void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id)
+void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dec_dev *vcodec_dev, int ctx_id)
{
struct mtk_vcodec_dbgfs_inst *dbgfs_inst;

@@ -179,16 +180,13 @@ void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id)
}
EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_remove);

-void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev, bool is_encode)
+static void mtk_vcodec_dbgfs_vdec_init(struct mtk_vcodec_dec_dev *vcodec_dev)
{
struct dentry *vcodec_root;

- if (is_encode)
- vcodec_dev->dbgfs.vcodec_root = debugfs_create_dir("vcodec-enc", NULL);
- else
- vcodec_dev->dbgfs.vcodec_root = debugfs_create_dir("vcodec-dec", NULL);
+ vcodec_dev->dbgfs.vcodec_root = debugfs_create_dir("vcodec-dec", NULL);
if (IS_ERR(vcodec_dev->dbgfs.vcodec_root))
- dev_err(&vcodec_dev->plat_dev->dev, "create vcodec dir err:%d\n",
+ dev_err(&vcodec_dev->plat_dev->dev, "create vdec dir err:%d\n",
IS_ERR(vcodec_dev->dbgfs.vcodec_root));

vcodec_root = vcodec_dev->dbgfs.vcodec_root;
@@ -196,18 +194,39 @@ void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev, bool is_encode)
debugfs_create_x32("mtk_vcodec_dbg", 0644, vcodec_root, &mtk_vcodec_dbg);

vcodec_dev->dbgfs.inst_count = 0;
- if (is_encode)
- return;
-
INIT_LIST_HEAD(&vcodec_dev->dbgfs.dbgfs_head);
debugfs_create_file("vdec", 0200, vcodec_root, vcodec_dev, &vdec_fops);
mutex_init(&vcodec_dev->dbgfs.dbgfs_lock);
}
+
+static void mtk_vcodec_dbgfs_venc_init(struct mtk_vcodec_enc_dev *vcodec_dev)
+{
+ struct dentry *vcodec_root;
+
+ vcodec_dev->dbgfs.vcodec_root = debugfs_create_dir("vcodec-enc", NULL);
+ if (IS_ERR(vcodec_dev->dbgfs.vcodec_root))
+ dev_err(&vcodec_dev->plat_dev->dev, "create venc dir err:%d\n",
+ IS_ERR(vcodec_dev->dbgfs.vcodec_root));
+
+ vcodec_root = vcodec_dev->dbgfs.vcodec_root;
+ debugfs_create_x32("mtk_v4l2_dbg_level", 0644, vcodec_root, &mtk_v4l2_dbg_level);
+ debugfs_create_x32("mtk_vcodec_dbg", 0644, vcodec_root, &mtk_vcodec_dbg);
+
+ vcodec_dev->dbgfs.inst_count = 0;
+}
+
+void mtk_vcodec_dbgfs_init(void *vcodec_dev, bool is_encode)
+{
+ if (is_encode)
+ mtk_vcodec_dbgfs_venc_init(vcodec_dev);
+ else
+ mtk_vcodec_dbgfs_vdec_init(vcodec_dev);
+}
EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_init);

-void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dev *vcodec_dev)
+void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dbgfs *dbgfs)
{
- debugfs_remove_recursive(vcodec_dev->dbgfs.vcodec_root);
+ debugfs_remove_recursive(dbgfs->vcodec_root);
}
EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_deinit);

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.h
index 372413d590c5..073d2fedb54a 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.h
@@ -7,7 +7,7 @@
#ifndef __MTK_VCODEC_DBGFS_H__
#define __MTK_VCODEC_DBGFS_H__

-struct mtk_vcodec_dev;
+struct mtk_vcodec_dec_dev;
struct mtk_vcodec_dec_ctx;

/*
@@ -51,23 +51,23 @@ struct mtk_vcodec_dbgfs {

#if defined(CONFIG_DEBUG_FS)
void mtk_vcodec_dbgfs_create(struct mtk_vcodec_dec_ctx *ctx);
-void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id);
-void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev, bool is_encode);
-void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dev *vcodec_dev);
+void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dec_dev *vcodec_dev, int ctx_id);
+void mtk_vcodec_dbgfs_init(void *vcodec_dev, bool is_encode);
+void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dbgfs *dbgfs);
#else
static inline void mtk_vcodec_dbgfs_create(struct mtk_vcodec_dec_ctx *ctx)
{
}

-static inline void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id)
+static inline void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dec_dev *vcodec_dev, int ctx_id)
{
}

-static inline void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev, bool is_encode)
+static inline void mtk_vcodec_dbgfs_init(void *vcodec_dev, bool is_encode)
{
}

-static inline void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dev *vcodec_dev)
+static inline void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dbgfs *dbgfs)
{
}
#endif
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c
index 1a9887fe1a53..0abdc0a10425 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c
@@ -9,7 +9,7 @@
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>

-#include "mtk_vcodec_drv.h"
+#include "mtk_vcodec_dec_drv.h"
#include "mtk_vcodec_dec.h"
#include "mtk_vcodec_intr.h"
#include "mtk_vcodec_util.h"
@@ -895,7 +895,7 @@ void vb2ops_vdec_stop_streaming(struct vb2_queue *q)
static void m2mops_vdec_device_run(void *priv)
{
struct mtk_vcodec_dec_ctx *ctx = priv;
- struct mtk_vcodec_dev *dev = ctx->dev;
+ struct mtk_vcodec_dec_dev *dev = ctx->dev;

queue_work(dev->decode_workqueue, &ctx->decode_work);
}
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
index b809a30f913d..004d5e20dfc3 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
@@ -17,7 +17,6 @@
#include <media/videobuf2-dma-contig.h>
#include <media/v4l2-device.h>

-#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec.h"
#include "mtk_vcodec_dec_hw.h"
#include "mtk_vcodec_dec_pm.h"
@@ -25,7 +24,7 @@
#include "mtk_vcodec_util.h"
#include "mtk_vcodec_fw.h"

-static int mtk_vcodec_get_hw_count(struct mtk_vcodec_dev *dev)
+static int mtk_vcodec_get_hw_count(struct mtk_vcodec_dec_dev *dev)
{
switch (dev->vdec_pdata->hw_arch) {
case MTK_VDEC_PURE_SINGLE_CORE:
@@ -41,7 +40,7 @@ static int mtk_vcodec_get_hw_count(struct mtk_vcodec_dev *dev)

static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv)
{
- struct mtk_vcodec_dev *dev = priv;
+ struct mtk_vcodec_dec_dev *dev = priv;
struct mtk_vcodec_dec_ctx *ctx;
u32 cg_status = 0;
unsigned int dec_done_status = 0;
@@ -78,7 +77,7 @@ static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv)
return IRQ_HANDLED;
}

-static int mtk_vcodec_get_reg_bases(struct mtk_vcodec_dev *dev)
+static int mtk_vcodec_get_reg_bases(struct mtk_vcodec_dec_dev *dev)
{
struct platform_device *pdev = dev->plat_dev;
int reg_num, i;
@@ -102,7 +101,7 @@ static int mtk_vcodec_get_reg_bases(struct mtk_vcodec_dev *dev)
return 0;
}

-static int mtk_vcodec_init_dec_resources(struct mtk_vcodec_dev *dev)
+static int mtk_vcodec_init_dec_resources(struct mtk_vcodec_dec_dev *dev)
{
struct platform_device *pdev = dev->plat_dev;
int ret;
@@ -139,7 +138,7 @@ static int mtk_vcodec_init_dec_resources(struct mtk_vcodec_dev *dev)

static int fops_vcodec_open(struct file *file)
{
- struct mtk_vcodec_dev *dev = video_drvdata(file);
+ struct mtk_vcodec_dec_dev *dev = video_drvdata(file);
struct mtk_vcodec_dec_ctx *ctx = NULL;
int ret = 0, i, hw_count;
struct vb2_queue *src_vq;
@@ -237,7 +236,7 @@ static int fops_vcodec_open(struct file *file)

static int fops_vcodec_release(struct file *file)
{
- struct mtk_vcodec_dev *dev = video_drvdata(file);
+ struct mtk_vcodec_dec_dev *dev = video_drvdata(file);
struct mtk_vcodec_dec_ctx *ctx = fh_to_dec_ctx(file->private_data);

mtk_v4l2_debug(dev->plat_dev, 0, "[%d] decoder", ctx->id);
@@ -274,7 +273,7 @@ static const struct v4l2_file_operations mtk_vcodec_fops = {

static int mtk_vcodec_probe(struct platform_device *pdev)
{
- struct mtk_vcodec_dev *dev;
+ struct mtk_vcodec_dec_dev *dev;
struct video_device *vfd_dec;
phandle rproc_phandle;
enum mtk_vcodec_fw_type fw_type;
@@ -482,7 +481,7 @@ MODULE_DEVICE_TABLE(of, mtk_vcodec_match);

static void mtk_vcodec_dec_remove(struct platform_device *pdev)
{
- struct mtk_vcodec_dev *dev = platform_get_drvdata(pdev);
+ struct mtk_vcodec_dec_dev *dev = platform_get_drvdata(pdev);

destroy_workqueue(dev->decode_workqueue);

@@ -498,7 +497,7 @@ static void mtk_vcodec_dec_remove(struct platform_device *pdev)
if (dev->vfd_dec)
video_unregister_device(dev->vfd_dec);

- mtk_vcodec_dbgfs_deinit(dev);
+ mtk_vcodec_dbgfs_deinit(&dev->dbgfs);
v4l2_device_unregister(&dev->v4l2_dev);
if (!dev->vdec_pdata->is_subdev_supported)
pm_runtime_disable(dev->pm.dev);
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.h
index 94870b651919..a18ba8f32d41 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.h
@@ -8,9 +8,49 @@
#define _MTK_VCODEC_DEC_DRV_H_

#include "mtk_vcodec_com_drv.h"
+#include "mtk_vcodec_dbgfs.h"
#include "mtk_vcodec_fw_priv.h"
+#include "mtk_vcodec_util.h"
#include "vdec_msg_queue.h"

+#define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec"
+
+#define IS_VDEC_LAT_ARCH(hw_arch) ((hw_arch) >= MTK_VDEC_LAT_SINGLE_CORE)
+#define IS_VDEC_INNER_RACING(capability) ((capability) & MTK_VCODEC_INNER_RACING)
+
+/*
+ * struct mtk_vdec_format_types - Structure used to get supported
+ * format types according to decoder capability
+ */
+enum mtk_vdec_format_types {
+ MTK_VDEC_FORMAT_MM21 = 0x20,
+ MTK_VDEC_FORMAT_MT21C = 0x40,
+ MTK_VDEC_FORMAT_H264_SLICE = 0x100,
+ MTK_VDEC_FORMAT_VP8_FRAME = 0x200,
+ MTK_VDEC_FORMAT_VP9_FRAME = 0x400,
+ MTK_VDEC_FORMAT_AV1_FRAME = 0x800,
+ MTK_VDEC_FORMAT_HEVC_FRAME = 0x1000,
+ MTK_VCODEC_INNER_RACING = 0x20000,
+};
+
+/*
+ * enum mtk_vdec_hw_count - Supported hardware count
+ */
+enum mtk_vdec_hw_count {
+ MTK_VDEC_NO_HW = 0,
+ MTK_VDEC_ONE_CORE,
+ MTK_VDEC_ONE_LAT_ONE_CORE,
+ MTK_VDEC_MAX_HW_COUNT,
+};
+
+/*
+ * enum mtk_vdec_hw_arch - Used to separate different hardware architecture
+ */
+enum mtk_vdec_hw_arch {
+ MTK_VDEC_PURE_SINGLE_CORE,
+ MTK_VDEC_LAT_SINGLE_CORE,
+};
+
/**
* struct vdec_pic_info - picture size information
* @pic_w: picture width
@@ -33,24 +73,54 @@ struct vdec_pic_info {
unsigned int reserved;
};

-/*
- * enum mtk_vdec_hw_id - Hardware index used to separate
- * different hardware
+/**
+ * struct mtk_vcodec_dec_pdata - compatible data for each IC
+ * @init_vdec_params: init vdec params
+ * @ctrls_setup: init vcodec dec ctrls
+ * @worker: worker to start a decode job
+ * @flush_decoder: function that flushes the decoder
+ * @get_cap_buffer: get capture buffer from capture queue
+ * @cap_to_disp: put capture buffer to disp list for lat and core arch
+ * @vdec_vb2_ops: struct vb2_ops
+ *
+ * @vdec_formats: supported video decoder formats
+ * @num_formats: count of video decoder formats
+ * @default_out_fmt: default output buffer format
+ * @default_cap_fmt: default capture buffer format
+ *
+ * @hw_arch: hardware arch is used to separate pure_sin_core and lat_sin_core
+ *
+ * @is_subdev_supported: whether support parent-node architecture(subdev)
+ * @uses_stateless_api: whether the decoder uses the stateless API with requests
*/
-enum mtk_vdec_hw_id {
- MTK_VDEC_CORE,
- MTK_VDEC_LAT0,
- MTK_VDEC_LAT1,
- MTK_VDEC_LAT_SOC,
- MTK_VDEC_HW_MAX,
+struct mtk_vcodec_dec_pdata {
+ void (*init_vdec_params)(struct mtk_vcodec_dec_ctx *ctx);
+ int (*ctrls_setup)(struct mtk_vcodec_dec_ctx *ctx);
+ void (*worker)(struct work_struct *work);
+ int (*flush_decoder)(struct mtk_vcodec_dec_ctx *ctx);
+ struct vdec_fb *(*get_cap_buffer)(struct mtk_vcodec_dec_ctx *ctx);
+ void (*cap_to_disp)(struct mtk_vcodec_dec_ctx *ctx, int error,
+ struct media_request *src_buf_req);
+
+ const struct vb2_ops *vdec_vb2_ops;
+
+ const struct mtk_video_fmt *vdec_formats;
+ const int *num_formats;
+ const struct mtk_video_fmt *default_out_fmt;
+ const struct mtk_video_fmt *default_cap_fmt;
+
+ enum mtk_vdec_hw_arch hw_arch;
+
+ bool is_subdev_supported;
+ bool uses_stateless_api;
};

/**
* struct mtk_vcodec_dec_ctx - Context (instance) private data.
*
* @type: type of the instance - decoder or encoder
- * @dev: pointer to the mtk_vcodec_dev of the device
- * @list: link to ctx_list of mtk_vcodec_dev
+ * @dev: pointer to the mtk_vcodec_dec_dev of the device
+ * @list: link to ctx_list of mtk_vcodec_dec_dev
*
* @fh: struct v4l2_fh
* @m2m_ctx: pointer to the v4l2_m2m_ctx of the context
@@ -95,7 +165,7 @@ enum mtk_vdec_hw_id {
*/
struct mtk_vcodec_dec_ctx {
enum mtk_instance_type type;
- struct mtk_vcodec_dev *dev;
+ struct mtk_vcodec_dec_dev *dev;
struct list_head list;

struct v4l2_fh fh;
@@ -136,6 +206,84 @@ struct mtk_vcodec_dec_ctx {
struct vdec_msg_queue msg_queue;
};

+/**
+ * struct mtk_vcodec_dec_dev - driver data
+ * @v4l2_dev: V4L2 device to register video devices for.
+ * @vfd_dec: Video device for decoder
+ * @mdev_dec: Media device for decoder
+ *
+ * @m2m_dev_dec: m2m device for decoder
+ * @plat_dev: platform device
+ * @ctx_list: list of struct mtk_vcodec_ctx
+ * @curr_ctx: The context that is waiting for codec hardware
+ *
+ * @reg_base: Mapped address of MTK Vcodec registers.
+ * @vdec_pdata: decoder IC-specific data
+ *
+ * @fw_handler: used to communicate with the firmware.
+ * @id_counter: used to identify current opened instance
+ *
+ * @dec_mutex: decoder hardware lock
+ * @dev_mutex: video_device lock
+ * @decode_workqueue: decode work queue
+ *
+ * @irqlock: protect data access by irq handler and work thread
+ * @dec_irq: decoder irq resource
+ *
+ * @pm: power management control
+ * @dec_capability: used to identify decode capability, ex: 4k
+ *
+ * @core_workqueue: queue used for core hardware decode
+ *
+ * @subdev_dev: subdev hardware device
+ * @subdev_prob_done: check whether all used hw device is prob done
+ * @subdev_bitmap: used to record hardware is ready or not
+ *
+ * @dec_active_cnt: used to mark whether need to record register value
+ * @vdec_racing_info: record register value
+ * @dec_racing_info_mutex: mutex lock used for inner racing mode
+ * @dbgfs: debug log related information
+ */
+struct mtk_vcodec_dec_dev {
+ struct v4l2_device v4l2_dev;
+ struct video_device *vfd_dec;
+ struct media_device mdev_dec;
+
+ struct v4l2_m2m_dev *m2m_dev_dec;
+ struct platform_device *plat_dev;
+ struct list_head ctx_list;
+ struct mtk_vcodec_dec_ctx *curr_ctx;
+
+ void __iomem *reg_base[NUM_MAX_VCODEC_REG_BASE];
+ const struct mtk_vcodec_dec_pdata *vdec_pdata;
+
+ struct mtk_vcodec_fw *fw_handler;
+ unsigned long id_counter;
+
+ /* decoder hardware mutex lock */
+ struct mutex dec_mutex[MTK_VDEC_HW_MAX];
+ struct mutex dev_mutex;
+ struct workqueue_struct *decode_workqueue;
+
+ spinlock_t irqlock;
+ int dec_irq;
+
+ struct mtk_vcodec_pm pm;
+ unsigned int dec_capability;
+
+ struct workqueue_struct *core_workqueue;
+
+ void *subdev_dev[MTK_VDEC_HW_MAX];
+ int (*subdev_prob_done)(struct mtk_vcodec_dec_dev *vdec_dev);
+ DECLARE_BITMAP(subdev_bitmap, MTK_VDEC_HW_MAX);
+
+ atomic_t dec_active_cnt;
+ u32 vdec_racing_info[132];
+ /* Protects access to vdec_racing_info data */
+ struct mutex dec_racing_info_mutex;
+ struct mtk_vcodec_dbgfs dbgfs;
+};
+
static inline struct mtk_vcodec_dec_ctx *fh_to_dec_ctx(struct v4l2_fh *fh)
{
return container_of(fh, struct mtk_vcodec_dec_ctx, fh);
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c
index 3714e3956ead..82e064b0b72f 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c
@@ -12,7 +12,6 @@
#include <linux/pm_runtime.h>
#include <linux/slab.h>

-#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec.h"
#include "mtk_vcodec_dec_hw.h"
#include "mtk_vcodec_dec_pm.h"
@@ -36,7 +35,7 @@ static const struct of_device_id mtk_vdec_hw_match[] = {
};
MODULE_DEVICE_TABLE(of, mtk_vdec_hw_match);

-static int mtk_vdec_hw_prob_done(struct mtk_vcodec_dev *vdec_dev)
+static int mtk_vdec_hw_prob_done(struct mtk_vcodec_dec_dev *vdec_dev)
{
struct platform_device *pdev = vdec_dev->plat_dev;
struct device_node *subdev_node;
@@ -124,7 +123,7 @@ static int mtk_vdec_hw_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct mtk_vdec_hw_dev *subdev_dev;
- struct mtk_vcodec_dev *main_dev;
+ struct mtk_vcodec_dec_dev *main_dev;
const struct of_device_id *of_id;
int hw_idx;
int ret;
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.h
index d62c7f961cfa..2b33f00e931e 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.h
@@ -10,7 +10,7 @@
#include <linux/io.h>
#include <linux/platform_device.h>

-#include "mtk_vcodec_drv.h"
+#include "mtk_vcodec_dec_drv.h"

#define VDEC_HW_ACTIVE 0x10
#define VDEC_IRQ_CFG 0x11
@@ -45,7 +45,7 @@ enum mtk_vdec_hw_reg_idx {
*/
struct mtk_vdec_hw_dev {
struct platform_device *plat_dev;
- struct mtk_vcodec_dev *main_dev;
+ struct mtk_vcodec_dec_dev *main_dev;
void __iomem *reg_base[VDEC_HW_MAX];

struct mtk_vcodec_dec_ctx *curr_ctx;
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c
index 12ac61b92190..3d7b9729be4a 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c
@@ -110,7 +110,7 @@ static void mtk_vcodec_dec_clock_off(struct mtk_vcodec_pm *pm)
clk_disable_unprepare(dec_clk->clk_info[i].vcodec_clk);
}

-static void mtk_vcodec_dec_enable_irq(struct mtk_vcodec_dev *vdec_dev, int hw_idx)
+static void mtk_vcodec_dec_enable_irq(struct mtk_vcodec_dec_dev *vdec_dev, int hw_idx)
{
struct mtk_vdec_hw_dev *subdev_dev;

@@ -128,7 +128,7 @@ static void mtk_vcodec_dec_enable_irq(struct mtk_vcodec_dev *vdec_dev, int hw_id
}
}

-static void mtk_vcodec_dec_disable_irq(struct mtk_vcodec_dev *vdec_dev, int hw_idx)
+static void mtk_vcodec_dec_disable_irq(struct mtk_vcodec_dec_dev *vdec_dev, int hw_idx)
{
struct mtk_vdec_hw_dev *subdev_dev;

@@ -174,7 +174,7 @@ static void mtk_vcodec_record_racing_info(struct mtk_vcodec_dec_ctx *ctx)
mutex_unlock(&ctx->dev->dec_racing_info_mutex);
}

-static struct mtk_vcodec_pm *mtk_vcodec_dec_get_pm(struct mtk_vcodec_dev *vdec_dev,
+static struct mtk_vcodec_pm *mtk_vcodec_dec_get_pm(struct mtk_vcodec_dec_dev *vdec_dev,
int hw_idx)
{
struct mtk_vdec_hw_dev *subdev_dev;
@@ -194,7 +194,7 @@ static struct mtk_vcodec_pm *mtk_vcodec_dec_get_pm(struct mtk_vcodec_dev *vdec_d
return &vdec_dev->pm;
}

-static void mtk_vcodec_dec_child_dev_on(struct mtk_vcodec_dev *vdec_dev,
+static void mtk_vcodec_dec_child_dev_on(struct mtk_vcodec_dec_dev *vdec_dev,
int hw_idx)
{
struct mtk_vcodec_pm *pm;
@@ -214,7 +214,7 @@ static void mtk_vcodec_dec_child_dev_on(struct mtk_vcodec_dev *vdec_dev,
}
}

-static void mtk_vcodec_dec_child_dev_off(struct mtk_vcodec_dev *vdec_dev,
+static void mtk_vcodec_dec_child_dev_off(struct mtk_vcodec_dec_dev *vdec_dev,
int hw_idx)
{
struct mtk_vcodec_pm *pm;
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.h
index f6c68e57bcc1..87a50d589d42 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.h
@@ -7,7 +7,7 @@
#ifndef _MTK_VCODEC_DEC_PM_H_
#define _MTK_VCODEC_DEC_PM_H_

-#include "mtk_vcodec_drv.h"
+#include "mtk_vcodec_dec_drv.h"

int mtk_vcodec_init_dec_clk(struct platform_device *pdev, struct mtk_vcodec_pm *pm);

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c
index aba3ac04ed94..72ce22620cc6 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c
@@ -4,7 +4,6 @@
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>

-#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec.h"
#include "mtk_vcodec_intr.h"
#include "mtk_vcodec_util.h"
@@ -280,7 +279,7 @@ static void mtk_vdec_worker(struct work_struct *work)
{
struct mtk_vcodec_dec_ctx *ctx =
container_of(work, struct mtk_vcodec_dec_ctx, decode_work);
- struct mtk_vcodec_dev *dev = ctx->dev;
+ struct mtk_vcodec_dec_dev *dev = ctx->dev;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
struct mtk_vcodec_mem buf;
struct vdec_fb *pfb;
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
index d2ab24c96086..8725f6631d5f 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
@@ -6,7 +6,6 @@
#include <media/v4l2-mem2mem.h>
#include <linux/module.h>

-#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec.h"
#include "mtk_vcodec_intr.h"
#include "mtk_vcodec_util.h"
@@ -288,7 +287,7 @@ static void mtk_vdec_worker(struct work_struct *work)
{
struct mtk_vcodec_dec_ctx *ctx =
container_of(work, struct mtk_vcodec_dec_ctx, decode_work);
- struct mtk_vcodec_dev *dev = ctx->dev;
+ struct mtk_vcodec_dec_dev *dev = ctx->dev;
struct vb2_v4l2_buffer *vb2_v4l2_src;
struct vb2_buffer *vb2_src;
struct mtk_vcodec_mem *bs_src;
@@ -446,7 +445,7 @@ const struct media_device_ops mtk_vcodec_media_ops = {
static void mtk_vcodec_add_formats(unsigned int fourcc,
struct mtk_vcodec_dec_ctx *ctx)
{
- struct mtk_vcodec_dev *dev = ctx->dev;
+ struct mtk_vcodec_dec_dev *dev = ctx->dev;
const struct mtk_vcodec_dec_pdata *pdata = dev->vdec_pdata;
int count_formats = *pdata->num_formats;

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
deleted file mode 100644
index 76db7770d981..000000000000
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
+++ /dev/null
@@ -1,295 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
-* Copyright (c) 2016 MediaTek Inc.
-* Author: PC Chen <[email protected]>
-* Tiffany Lin <[email protected]>
-*/
-
-#ifndef _MTK_VCODEC_DRV_H_
-#define _MTK_VCODEC_DRV_H_
-
-#include <linux/platform_device.h>
-#include <linux/videodev2.h>
-#include <media/v4l2-ctrls.h>
-#include <media/v4l2-device.h>
-#include <media/v4l2-ioctl.h>
-#include <media/v4l2-mem2mem.h>
-#include <media/videobuf2-core.h>
-
-#include "mtk_vcodec_dbgfs.h"
-#include "mtk_vcodec_dec_drv.h"
-#include "mtk_vcodec_enc_drv.h"
-#include "mtk_vcodec_util.h"
-#include "vdec_msg_queue.h"
-
-#define MTK_VCODEC_DEC_NAME "mtk-vcodec-dec"
-#define MTK_VCODEC_ENC_NAME "mtk-vcodec-enc"
-
-#define MTK_V4L2_BENCHMARK 0
-#define WAIT_INTR_TIMEOUT_MS 1000
-#define IS_VDEC_LAT_ARCH(hw_arch) ((hw_arch) >= MTK_VDEC_LAT_SINGLE_CORE)
-#define IS_VDEC_INNER_RACING(capability) ((capability) & MTK_VCODEC_INNER_RACING)
-
-/*
- * enum mtk_hw_reg_idx - MTK hw register base index
- */
-enum mtk_hw_reg_idx {
- VDEC_SYS,
- VDEC_MISC,
- VDEC_LD,
- VDEC_TOP,
- VDEC_CM,
- VDEC_AD,
- VDEC_AV,
- VDEC_PP,
- VDEC_HWD,
- VDEC_HWQ,
- VDEC_HWB,
- VDEC_HWG,
- NUM_MAX_VDEC_REG_BASE,
- /* h264 encoder */
- VENC_SYS = NUM_MAX_VDEC_REG_BASE,
- /* vp8 encoder */
- VENC_LT_SYS,
- NUM_MAX_VCODEC_REG_BASE
-};
-
-
-
-/*
- * enum mtk_vdec_hw_count - Supported hardware count
- */
-enum mtk_vdec_hw_count {
- MTK_VDEC_NO_HW = 0,
- MTK_VDEC_ONE_CORE,
- MTK_VDEC_ONE_LAT_ONE_CORE,
- MTK_VDEC_MAX_HW_COUNT,
-};
-
-/*
- * enum mtk_q_type - Type of queue
- */
-enum mtk_q_type {
- MTK_Q_DATA_SRC = 0,
- MTK_Q_DATA_DST = 1,
-};
-
-
-/*
- * struct mtk_vcodec_clk_info - Structure used to store clock name
- */
-struct mtk_vcodec_clk_info {
- const char *clk_name;
- struct clk *vcodec_clk;
-};
-
-/*
- * struct mtk_vcodec_clk - Structure used to store vcodec clock information
- */
-struct mtk_vcodec_clk {
- struct mtk_vcodec_clk_info *clk_info;
- int clk_num;
-};
-
-/*
- * struct mtk_vcodec_pm - Power management data structure
- */
-struct mtk_vcodec_pm {
- struct mtk_vcodec_clk vdec_clk;
- struct mtk_vcodec_clk venc_clk;
- struct device *dev;
-};
-
-/*
- * enum mtk_vdec_hw_arch - Used to separate different hardware architecture
- */
-enum mtk_vdec_hw_arch {
- MTK_VDEC_PURE_SINGLE_CORE,
- MTK_VDEC_LAT_SINGLE_CORE,
-};
-
-/*
- * struct mtk_vdec_format_types - Structure used to get supported
- * format types according to decoder capability
- */
-enum mtk_vdec_format_types {
- MTK_VDEC_FORMAT_MM21 = 0x20,
- MTK_VDEC_FORMAT_MT21C = 0x40,
- MTK_VDEC_FORMAT_H264_SLICE = 0x100,
- MTK_VDEC_FORMAT_VP8_FRAME = 0x200,
- MTK_VDEC_FORMAT_VP9_FRAME = 0x400,
- MTK_VDEC_FORMAT_AV1_FRAME = 0x800,
- MTK_VDEC_FORMAT_HEVC_FRAME = 0x1000,
- MTK_VCODEC_INNER_RACING = 0x20000,
-};
-
-/**
- * struct mtk_vcodec_dec_pdata - compatible data for each IC
- * @init_vdec_params: init vdec params
- * @ctrls_setup: init vcodec dec ctrls
- * @worker: worker to start a decode job
- * @flush_decoder: function that flushes the decoder
- * @get_cap_buffer: get capture buffer from capture queue
- * @cap_to_disp: put capture buffer to disp list for lat and core arch
- * @vdec_vb2_ops: struct vb2_ops
- *
- * @vdec_formats: supported video decoder formats
- * @num_formats: count of video decoder formats
- * @default_out_fmt: default output buffer format
- * @default_cap_fmt: default capture buffer format
- *
- * @hw_arch: hardware arch is used to separate pure_sin_core and lat_sin_core
- *
- * @is_subdev_supported: whether support parent-node architecture(subdev)
- * @uses_stateless_api: whether the decoder uses the stateless API with requests
- */
-
-struct mtk_vcodec_dec_pdata {
- void (*init_vdec_params)(struct mtk_vcodec_dec_ctx *ctx);
- int (*ctrls_setup)(struct mtk_vcodec_dec_ctx *ctx);
- void (*worker)(struct work_struct *work);
- int (*flush_decoder)(struct mtk_vcodec_dec_ctx *ctx);
- struct vdec_fb *(*get_cap_buffer)(struct mtk_vcodec_dec_ctx *ctx);
- void (*cap_to_disp)(struct mtk_vcodec_dec_ctx *ctx, int error,
- struct media_request *src_buf_req);
-
- struct vb2_ops *vdec_vb2_ops;
-
- const struct mtk_video_fmt *vdec_formats;
- const int *num_formats;
- const struct mtk_video_fmt *default_out_fmt;
- const struct mtk_video_fmt *default_cap_fmt;
-
- enum mtk_vdec_hw_arch hw_arch;
-
- bool is_subdev_supported;
- bool uses_stateless_api;
-};
-
-/**
- * struct mtk_vcodec_enc_pdata - compatible data for each IC
- *
- * @uses_ext: whether the encoder uses the extended firmware messaging format
- * @min_bitrate: minimum supported encoding bitrate
- * @max_bitrate: maximum supported encoding bitrate
- * @capture_formats: array of supported capture formats
- * @num_capture_formats: number of entries in capture_formats
- * @output_formats: array of supported output formats
- * @num_output_formats: number of entries in output_formats
- * @core_id: stand for h264 or vp8 encode index
- * @uses_34bit: whether the encoder uses 34-bit iova
- */
-struct mtk_vcodec_enc_pdata {
- bool uses_ext;
- unsigned long min_bitrate;
- unsigned long max_bitrate;
- const struct mtk_video_fmt *capture_formats;
- size_t num_capture_formats;
- const struct mtk_video_fmt *output_formats;
- size_t num_output_formats;
- int core_id;
- bool uses_34bit;
-};
-
-#define MTK_ENC_CTX_IS_EXT(ctx) ((ctx)->dev->venc_pdata->uses_ext)
-#define MTK_ENC_IOVA_IS_34BIT(ctx) ((ctx)->dev->venc_pdata->uses_34bit)
-
-/**
- * struct mtk_vcodec_dev - driver data
- * @v4l2_dev: V4L2 device to register video devices for.
- * @vfd_dec: Video device for decoder
- * @mdev_dec: Media device for decoder
- * @vfd_enc: Video device for encoder.
- *
- * @m2m_dev_dec: m2m device for decoder
- * @m2m_dev_enc: m2m device for encoder.
- * @plat_dev: platform device
- * @ctx_list: list of struct mtk_vcodec_dec_ctx
- * @irqlock: protect data access by irq handler and work thread
- * @curr_ctx: The context that is waiting for codec hardware
- * @curr_enc_ctx: The encoder context that is waiting for codec hardware
- *
- * @reg_base: Mapped address of MTK Vcodec registers.
- * @vdec_pdata: decoder IC-specific data
- * @venc_pdata: encoder IC-specific data
- *
- * @fw_handler: used to communicate with the firmware.
- * @id_counter: used to identify current opened instance
- *
- * @decode_workqueue: decode work queue
- * @encode_workqueue: encode work queue
- *
- * @dev_mutex: video_device lock
- *
- * @dec_irq: decoder irq resource
- * @enc_irq: h264 encoder irq resource
- *
- * @dec_mutex: decoder hardware lock
- * @enc_mutex: encoder hardware lock.
- *
- * @pm: power management control
- * @dec_capability: used to identify decode capability, ex: 4k
- * @enc_capability: used to identify encode capability
- *
- * @core_workqueue: queue used for core hardware decode
- *
- * @subdev_dev: subdev hardware device
- * @subdev_prob_done: check whether all used hw device is prob done
- * @subdev_bitmap: used to record hardware is ready or not
- *
- * @dec_active_cnt: used to mark whether need to record register value
- * @vdec_racing_info: record register value
- * @dec_racing_info_mutex: mutex lock used for inner racing mode
- * @dbgfs: debug log related information
- */
-struct mtk_vcodec_dev {
- struct v4l2_device v4l2_dev;
- struct video_device *vfd_dec;
- struct media_device mdev_dec;
- struct video_device *vfd_enc;
-
- struct v4l2_m2m_dev *m2m_dev_dec;
- struct v4l2_m2m_dev *m2m_dev_enc;
- struct platform_device *plat_dev;
- struct list_head ctx_list;
- spinlock_t irqlock;
- struct mtk_vcodec_dec_ctx *curr_ctx;
- struct mtk_vcodec_enc_ctx *curr_enc_ctx;
- void __iomem *reg_base[NUM_MAX_VCODEC_REG_BASE];
- const struct mtk_vcodec_dec_pdata *vdec_pdata;
- const struct mtk_vcodec_enc_pdata *venc_pdata;
-
- struct mtk_vcodec_fw *fw_handler;
-
- unsigned long id_counter;
-
- struct workqueue_struct *decode_workqueue;
- struct workqueue_struct *encode_workqueue;
- struct mutex dev_mutex;
-
- int dec_irq;
- int enc_irq;
-
- /* decoder hardware mutex lock */
- struct mutex dec_mutex[MTK_VDEC_HW_MAX];
- struct mutex enc_mutex;
-
- struct mtk_vcodec_pm pm;
- unsigned int dec_capability;
- unsigned int enc_capability;
-
- struct workqueue_struct *core_workqueue;
-
- void *subdev_dev[MTK_VDEC_HW_MAX];
- int (*subdev_prob_done)(struct mtk_vcodec_dev *vdec_dev);
- DECLARE_BITMAP(subdev_bitmap, MTK_VDEC_HW_MAX);
-
- atomic_t dec_active_cnt;
- u32 vdec_racing_info[132];
- /* Protects access to vdec_racing_info data */
- struct mutex dec_racing_info_mutex;
-
- struct mtk_vcodec_dbgfs dbgfs;
-};
-
-#endif /* _MTK_VCODEC_DRV_H_ */
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
index 38cacb58fa60..8be7565bad57 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
@@ -10,7 +10,6 @@
#include <media/videobuf2-dma-contig.h>
#include <linux/pm_runtime.h>

-#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_enc.h"
#include "mtk_vcodec_intr.h"
#include "mtk_vcodec_util.h"
@@ -1460,7 +1459,7 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queue *src_vq,

int mtk_venc_unlock(struct mtk_vcodec_enc_ctx *ctx)
{
- struct mtk_vcodec_dev *dev = ctx->dev;
+ struct mtk_vcodec_enc_dev *dev = ctx->dev;

mutex_unlock(&dev->enc_mutex);
return 0;
@@ -1468,7 +1467,7 @@ int mtk_venc_unlock(struct mtk_vcodec_enc_ctx *ctx)

int mtk_venc_lock(struct mtk_vcodec_enc_ctx *ctx)
{
- struct mtk_vcodec_dev *dev = ctx->dev;
+ struct mtk_vcodec_enc_dev *dev = ctx->dev;

mutex_lock(&dev->enc_mutex);
return 0;
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c
index 193262de2d9f..a756eae2e53e 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c
@@ -16,7 +16,6 @@
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>

-#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_enc.h"
#include "mtk_vcodec_enc_pm.h"
#include "mtk_vcodec_intr.h"
@@ -85,14 +84,14 @@ static void clean_irq_status(unsigned int irq_status, void __iomem *addr)
}
static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, void *priv)
{
- struct mtk_vcodec_dev *dev = priv;
+ struct mtk_vcodec_enc_dev *dev = priv;
struct mtk_vcodec_enc_ctx *ctx;
unsigned long flags;
void __iomem *addr;
int core_id;

spin_lock_irqsave(&dev->irqlock, flags);
- ctx = dev->curr_enc_ctx;
+ ctx = dev->curr_ctx;
spin_unlock_irqrestore(&dev->irqlock, flags);

core_id = dev->venc_pdata->core_id;
@@ -116,7 +115,7 @@ static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, void *priv)

static int fops_vcodec_open(struct file *file)
{
- struct mtk_vcodec_dev *dev = video_drvdata(file);
+ struct mtk_vcodec_enc_dev *dev = video_drvdata(file);
struct mtk_vcodec_enc_ctx *ctx = NULL;
int ret = 0;
struct vb2_queue *src_vq;
@@ -203,7 +202,7 @@ static int fops_vcodec_open(struct file *file)

static int fops_vcodec_release(struct file *file)
{
- struct mtk_vcodec_dev *dev = video_drvdata(file);
+ struct mtk_vcodec_enc_dev *dev = video_drvdata(file);
struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(file->private_data);

mtk_v4l2_debug(dev->plat_dev, 1, "[%d] encoder", ctx->id);
@@ -232,7 +231,7 @@ static const struct v4l2_file_operations mtk_vcodec_fops = {

static int mtk_vcodec_probe(struct platform_device *pdev)
{
- struct mtk_vcodec_dev *dev;
+ struct mtk_vcodec_enc_dev *dev;
struct video_device *vfd_enc;
phandle rproc_phandle;
enum mtk_vcodec_fw_type fw_type;
@@ -454,7 +453,7 @@ MODULE_DEVICE_TABLE(of, mtk_vcodec_enc_match);

static void mtk_vcodec_enc_remove(struct platform_device *pdev)
{
- struct mtk_vcodec_dev *dev = platform_get_drvdata(pdev);
+ struct mtk_vcodec_enc_dev *dev = platform_get_drvdata(pdev);

mtk_v4l2_debug_enter(pdev);
destroy_workqueue(dev->encode_workqueue);
@@ -464,7 +463,7 @@ static void mtk_vcodec_enc_remove(struct platform_device *pdev)
if (dev->vfd_enc)
video_unregister_device(dev->vfd_enc);

- mtk_vcodec_dbgfs_deinit(dev);
+ mtk_vcodec_dbgfs_deinit(&dev->dbgfs);
v4l2_device_unregister(&dev->v4l2_dev);
pm_runtime_disable(dev->pm.dev);
mtk_vcodec_fw_release(dev->fw_handler);
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.h
index 6aa4afe5b796..a88ef9078848 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.h
@@ -8,7 +8,39 @@
#define _MTK_VCODEC_ENC_DRV_H_

#include "mtk_vcodec_com_drv.h"
+#include "mtk_vcodec_dbgfs.h"
#include "mtk_vcodec_fw_priv.h"
+#include "mtk_vcodec_util.h"
+
+#define MTK_VCODEC_ENC_NAME "mtk-vcodec-enc"
+
+#define MTK_ENC_CTX_IS_EXT(ctx) ((ctx)->dev->venc_pdata->uses_ext)
+#define MTK_ENC_IOVA_IS_34BIT(ctx) ((ctx)->dev->venc_pdata->uses_34bit)
+
+/**
+ * struct mtk_vcodec_enc_pdata - compatible data for each IC
+ *
+ * @uses_ext: whether the encoder uses the extended firmware messaging format
+ * @min_bitrate: minimum supported encoding bitrate
+ * @max_bitrate: maximum supported encoding bitrate
+ * @capture_formats: array of supported capture formats
+ * @num_capture_formats: number of entries in capture_formats
+ * @output_formats: array of supported output formats
+ * @num_output_formats: number of entries in output_formats
+ * @core_id: stand for h264 or vp8 encode index
+ * @uses_34bit: whether the encoder uses 34-bit iova
+ */
+struct mtk_vcodec_enc_pdata {
+ bool uses_ext;
+ unsigned long min_bitrate;
+ unsigned long max_bitrate;
+ const struct mtk_video_fmt *capture_formats;
+ size_t num_capture_formats;
+ const struct mtk_video_fmt *output_formats;
+ size_t num_output_formats;
+ int core_id;
+ bool uses_34bit;
+};

/*
* enum mtk_encode_param - General encoding parameters type
@@ -61,8 +93,8 @@ struct mtk_enc_params {
* struct mtk_vcodec_enc_ctx - Context (instance) private data.
*
* @type: type of the instance - decoder or encoder
- * @dev: pointer to the mtk_vcodec_dev of the device
- * @list: link to ctx_list of mtk_vcodec_dev
+ * @dev: pointer to the mtk_vcodec_enc_dev of the device
+ * @list: link to ctx_list of mtk_vcodec_enc_dev
*
* @fh: struct v4l2_fh
* @m2m_ctx: pointer to the v4l2_m2m_ctx of the context
@@ -101,7 +133,7 @@ struct mtk_enc_params {
*/
struct mtk_vcodec_enc_ctx {
enum mtk_instance_type type;
- struct mtk_vcodec_dev *dev;
+ struct mtk_vcodec_enc_dev *dev;
struct list_head list;

struct v4l2_fh fh;
@@ -136,6 +168,61 @@ struct mtk_vcodec_enc_ctx {
struct mutex q_mutex;
};

+/**
+ * struct mtk_vcodec_enc_dev - driver data
+ * @v4l2_dev: V4L2 device to register video devices for.
+ * @vfd_enc: Video device for encoder.
+ *
+ * @m2m_dev_enc: m2m device for encoder.
+ * @plat_dev: platform device
+ * @ctx_list: list of struct mtk_vcodec_ctx
+ * @curr_ctx: The context that is waiting for codec hardware
+ *
+ * @reg_base: Mapped address of MTK Vcodec registers.
+ * @venc_pdata: encoder IC-specific data
+ *
+ * @fw_handler: used to communicate with the firmware.
+ * @id_counter: used to identify current opened instance
+ *
+ * @enc_mutex: encoder hardware lock.
+ * @dev_mutex: video_device lock
+ * @encode_workqueue: encode work queue
+ *
+ * @enc_irq: h264 encoder irq resource
+ * @irqlock: protect data access by irq handler and work thread
+ *
+ * @pm: power management control
+ * @enc_capability: used to identify encode capability
+ * @dbgfs: debug log related information
+ */
+struct mtk_vcodec_enc_dev {
+ struct v4l2_device v4l2_dev;
+ struct video_device *vfd_enc;
+
+ struct v4l2_m2m_dev *m2m_dev_enc;
+ struct platform_device *plat_dev;
+ struct list_head ctx_list;
+ struct mtk_vcodec_enc_ctx *curr_ctx;
+
+ void __iomem *reg_base[NUM_MAX_VCODEC_REG_BASE];
+ const struct mtk_vcodec_enc_pdata *venc_pdata;
+
+ struct mtk_vcodec_fw *fw_handler;
+ unsigned long id_counter;
+
+ /* encoder hardware mutex lock */
+ struct mutex enc_mutex;
+ struct mutex dev_mutex;
+ struct workqueue_struct *encode_workqueue;
+
+ int enc_irq;
+ spinlock_t irqlock;
+
+ struct mtk_vcodec_pm pm;
+ unsigned int enc_capability;
+ struct mtk_vcodec_dbgfs dbgfs;
+};
+
static inline struct mtk_vcodec_enc_ctx *fh_to_enc_ctx(struct v4l2_fh *fh)
{
return container_of(fh, struct mtk_vcodec_enc_ctx, fh);
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.c
index c63e60c5aaf7..851a5239cbeb 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.c
@@ -9,10 +9,10 @@
#include <linux/of_platform.h>
#include <linux/pm_runtime.h>

+#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_enc_pm.h"
-#include "mtk_vcodec_util.h"

-int mtk_vcodec_init_enc_clk(struct mtk_vcodec_dev *mtkdev)
+int mtk_vcodec_init_enc_clk(struct mtk_vcodec_enc_dev *mtkdev)
{
struct platform_device *pdev;
struct mtk_vcodec_pm *pm;
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.h
index bc455cefc0cd..e50be0575190 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.h
@@ -7,9 +7,9 @@
#ifndef _MTK_VCODEC_ENC_PM_H_
#define _MTK_VCODEC_ENC_PM_H_

-#include "mtk_vcodec_drv.h"
+#include "mtk_vcodec_enc_drv.h"

-int mtk_vcodec_init_enc_clk(struct mtk_vcodec_dev *dev);
+int mtk_vcodec_init_enc_clk(struct mtk_vcodec_enc_dev *dev);

void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm);
void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm);
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.c
index 540e3dd27384..09d865a80bc0 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.c
@@ -1,14 +1,19 @@
// SPDX-License-Identifier: GPL-2.0

+#include "mtk_vcodec_dec_drv.h"
+#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_fw.h"
#include "mtk_vcodec_fw_priv.h"
-#include "mtk_vcodec_util.h"
-#include "mtk_vcodec_drv.h"

struct mtk_vcodec_fw *mtk_vcodec_fw_select(void *priv, enum mtk_vcodec_fw_type type,
enum mtk_vcodec_fw_use fw_use)
{
- struct mtk_vcodec_dev *dev = priv;
+ struct platform_device *plat_dev;
+
+ if (fw_use == ENCODER)
+ plat_dev = ((struct mtk_vcodec_enc_dev *)priv)->plat_dev;
+ else
+ plat_dev = ((struct mtk_vcodec_dec_dev *)priv)->plat_dev;

switch (type) {
case VPU:
@@ -16,7 +21,7 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_select(void *priv, enum mtk_vcodec_fw_type t
case SCP:
return mtk_vcodec_fw_scp_init(priv, fw_use);
default:
- mtk_v4l2_err(dev->plat_dev, "invalid vcodec fw type");
+ mtk_v4l2_err(plat_dev, "invalid vcodec fw type");
return ERR_PTR(-EINVAL);
}
}
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.h
index d8cfbec323d5..83479ab70385 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.h
@@ -8,7 +8,8 @@

#include "../vpu/mtk_vpu.h"

-struct mtk_vcodec_dev;
+struct mtk_vcodec_dec_dev;
+struct mtk_vcodec_enc_dev;

enum mtk_vcodec_fw_type {
VPU,
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_priv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_priv.h
index 3438a4917344..99603accd82e 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_priv.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_priv.h
@@ -5,7 +5,8 @@

#include "mtk_vcodec_fw.h"

-struct mtk_vcodec_dev;
+struct mtk_vcodec_dec_dev;
+struct mtk_vcodec_enc_dev;

struct mtk_vcodec_fw {
enum mtk_vcodec_fw_type type;
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_scp.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_scp.c
index 39f361da5412..0de8d792f1a6 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_scp.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_scp.c
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: GPL-2.0

+#include "mtk_vcodec_dec_drv.h"
+#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_fw_priv.h"
-#include "mtk_vcodec_util.h"
-#include "mtk_vcodec_drv.h"

static int mtk_vcodec_scp_load_firmware(struct mtk_vcodec_fw *fw)
{
@@ -56,11 +56,22 @@ static const struct mtk_vcodec_fw_ops mtk_vcodec_rproc_msg = {
struct mtk_vcodec_fw *mtk_vcodec_fw_scp_init(void *priv, enum mtk_vcodec_fw_use fw_use)
{
struct mtk_vcodec_fw *fw;
- struct mtk_vcodec_dev *dev = priv;
struct platform_device *plat_dev;
struct mtk_scp *scp;

- plat_dev = dev->plat_dev;
+ if (fw_use == ENCODER) {
+ struct mtk_vcodec_enc_dev *enc_dev = priv;
+
+ plat_dev = enc_dev->plat_dev;
+ } else if (fw_use == DECODER) {
+ struct mtk_vcodec_dec_dev *dec_dev = priv;
+
+ plat_dev = dec_dev->plat_dev;
+ } else {
+ pr_err("Invalid fw_use %d (use a resonable fw id here)\n", fw_use);
+ return ERR_PTR(-EINVAL);
+ }
+
scp = scp_get(plat_dev);
if (!scp) {
mtk_v4l2_err(plat_dev, "could not get vdec scp handle");
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_vpu.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_vpu.c
index 22096a108166..d26fe00004b9 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_vpu.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw_vpu.c
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: GPL-2.0

+#include "mtk_vcodec_dec_drv.h"
+#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_fw_priv.h"
-#include "mtk_vcodec_util.h"
-#include "mtk_vcodec_drv.h"

static int mtk_vcodec_vpu_load_firmware(struct mtk_vcodec_fw *fw)
{
@@ -53,7 +53,7 @@ static void mtk_vcodec_vpu_release(struct mtk_vcodec_fw *fw)

static void mtk_vcodec_vpu_reset_dec_handler(void *priv)
{
- struct mtk_vcodec_dev *dev = priv;
+ struct mtk_vcodec_dec_dev *dev = priv;
struct mtk_vcodec_dec_ctx *ctx;

mtk_v4l2_err(dev->plat_dev, "Watchdog timeout!!");
@@ -69,7 +69,7 @@ static void mtk_vcodec_vpu_reset_dec_handler(void *priv)

static void mtk_vcodec_vpu_reset_enc_handler(void *priv)
{
- struct mtk_vcodec_dev *dev = priv;
+ struct mtk_vcodec_enc_dev *dev = priv;
struct mtk_vcodec_enc_ctx *ctx;

mtk_v4l2_err(dev->plat_dev, "Watchdog timeout!!");
@@ -96,22 +96,25 @@ static const struct mtk_vcodec_fw_ops mtk_vcodec_vpu_msg = {
struct mtk_vcodec_fw *mtk_vcodec_fw_vpu_init(void *priv, enum mtk_vcodec_fw_use fw_use)
{
struct platform_device *fw_pdev;
- struct mtk_vcodec_dev *dev = priv;
struct platform_device *plat_dev;
struct mtk_vcodec_fw *fw;
enum rst_id rst_id;

- switch (fw_use) {
- case ENCODER:
+ if (fw_use == ENCODER) {
+ struct mtk_vcodec_enc_dev *enc_dev = priv;
+
+ plat_dev = enc_dev->plat_dev;
rst_id = VPU_RST_ENC;
- break;
- case DECODER:
- default:
+ } else if (fw_use == DECODER) {
+ struct mtk_vcodec_dec_dev *dec_dev = priv;
+
+ plat_dev = dec_dev->plat_dev;
rst_id = VPU_RST_DEC;
- break;
+ } else {
+ pr_err("Invalid fw_use %d (use a resonable fw id here)\n", fw_use);
+ return ERR_PTR(-EINVAL);
}

- plat_dev = dev->plat_dev;
fw_pdev = vpu_get_plat_device(plat_dev);
if (!fw_pdev) {
mtk_v4l2_err(plat_dev, "firmware device is not ready");
@@ -119,9 +122,9 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_vpu_init(void *priv, enum mtk_vcodec_fw_use
}

if (fw_use == DECODER)
- vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_vpu_reset_dec_handler, dev, rst_id);
+ vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_vpu_reset_dec_handler, priv, rst_id);
else
- vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_vpu_reset_enc_handler, dev, rst_id);
+ vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_vpu_reset_enc_handler, priv, rst_id);

fw = devm_kzalloc(&plat_dev->dev, sizeof(*fw), GFP_KERNEL);
if (!fw)
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_intr.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_intr.c
index f541a7bcbb96..db6020beca39 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_intr.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_intr.c
@@ -7,9 +7,9 @@
#include <linux/errno.h>
#include <linux/wait.h>

-#include "mtk_vcodec_drv.h"
+#include "mtk_vcodec_dec_drv.h"
+#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_intr.h"
-#include "mtk_vcodec_util.h"

int mtk_vcodec_wait_for_done_ctx(void *priv, int command, unsigned int timeout_ms,
unsigned int hw_id)
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.c
index e63285670b47..62226b80673d 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.c
@@ -9,9 +9,9 @@
#include <linux/of.h>
#include <linux/of_device.h>

+#include "mtk_vcodec_dec_drv.h"
+#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_dec_hw.h"
-#include "mtk_vcodec_drv.h"
-#include "mtk_vcodec_util.h"

#if defined(CONFIG_DEBUG_FS)
int mtk_vcodec_dbg;
@@ -104,7 +104,7 @@ void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem)
}
EXPORT_SYMBOL(mtk_vcodec_mem_free);

-void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dev *dev, int hw_idx)
+void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dec_dev *dev, int hw_idx)
{
if (hw_idx >= MTK_VDEC_HW_MAX || hw_idx < 0 || !dev->subdev_dev[hw_idx]) {
mtk_v4l2_err(dev->plat_dev, "hw idx is out of range:%d", hw_idx);
@@ -115,7 +115,7 @@ void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dev *dev, int hw_idx)
}
EXPORT_SYMBOL(mtk_vcodec_get_hw_dev);

-void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
+void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dec_dev *vdec_dev,
struct mtk_vcodec_dec_ctx *ctx, int hw_idx)
{
unsigned long flags;
@@ -137,7 +137,7 @@ void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
}
EXPORT_SYMBOL(mtk_vcodec_set_curr_ctx);

-struct mtk_vcodec_dec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
+struct mtk_vcodec_dec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dec_dev *vdec_dev,
unsigned int hw_idx)
{
unsigned long flags;
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h
index fc53dc4fd639..fa6b06752cae 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h
@@ -23,7 +23,7 @@ struct mtk_vcodec_fb {
};

struct mtk_vcodec_dec_ctx;
-struct mtk_vcodec_dev;
+struct mtk_vcodec_dec_dev;

#undef pr_fmt
#define pr_fmt(fmt) "%s(),%d: " fmt, __func__, __LINE__
@@ -68,10 +68,10 @@ void __iomem *mtk_vcodec_get_reg_addr(struct platform_device *pdev, void __iomem
unsigned int reg_idx);
int mtk_vcodec_mem_alloc(void *priv, struct mtk_vcodec_mem *mem);
void mtk_vcodec_mem_free(void *priv, struct mtk_vcodec_mem *mem);
-void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
+void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dec_dev *vdec_dev,
struct mtk_vcodec_dec_ctx *ctx, int hw_idx);
-struct mtk_vcodec_dec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *vdec_dev,
+struct mtk_vcodec_dec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dec_dev *vdec_dev,
unsigned int hw_idx);
-void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dev *dev, int hw_idx);
+void *mtk_vcodec_get_hw_dev(struct mtk_vcodec_dec_dev *dev, int hw_idx);

#endif /* _MTK_VCODEC_UTIL_H_ */
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h
index 0dda9e2315c0..ac82be336055 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_common.h
@@ -13,7 +13,7 @@
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>

-#include "../mtk_vcodec_drv.h"
+#include "../mtk_vcodec_dec_drv.h"

#define NAL_NON_IDR_SLICE 0x01
#define NAL_IDR_SLICE 0x05
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
index 37ed8f5abccb..1bfcc3cc3c3c 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
@@ -548,7 +548,7 @@ static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf)
return 0;
}

-static void vdec_h264_insert_startcode(struct mtk_vcodec_dev *vcodec_dev, unsigned char *buf,
+static void vdec_h264_insert_startcode(struct mtk_vcodec_dec_dev *vcodec_dev, unsigned char *buf,
size_t *bs_size, struct mtk_h264_pps_param *pps)
{
struct device *dev = &vcodec_dev->plat_dev->dev;
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_drv_if.h b/drivers/media/platform/mediatek/vcodec/vdec_drv_if.h
index 816ed6ab1ed0..7b41ce23158b 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_drv_if.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec_drv_if.h
@@ -8,7 +8,6 @@
#ifndef _VDEC_DRV_IF_H_
#define _VDEC_DRV_IF_H_

-#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec.h"
#include "mtk_vcodec_util.h"

diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
index e66d0b75788e..d9d5e9ae0579 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
@@ -8,8 +8,8 @@
#include <linux/interrupt.h>
#include <linux/kthread.h>

+#include "mtk_vcodec_dec_drv.h"
#include "mtk_vcodec_dec_pm.h"
-#include "mtk_vcodec_drv.h"
#include "vdec_msg_queue.h"

#define VDEC_MSG_QUEUE_TIMEOUT_MS 1500
@@ -244,7 +244,7 @@ static void vdec_msg_queue_core_work(struct work_struct *work)
container_of(work, struct vdec_msg_queue, core_work);
struct mtk_vcodec_dec_ctx *ctx =
container_of(msg_queue, struct mtk_vcodec_dec_ctx, msg_queue);
- struct mtk_vcodec_dev *dev = ctx->dev;
+ struct mtk_vcodec_dec_dev *dev = ctx->dev;
struct vdec_lat_buf *lat_buf;

spin_lock(&msg_queue->core_ctx.ready_lock);
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
index eea56f24b60e..af2636244af0 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
@@ -18,7 +18,7 @@

struct vdec_lat_buf;
struct mtk_vcodec_dec_ctx;
-struct mtk_vcodec_dev;
+struct mtk_vcodec_dec_dev;
typedef int (*core_decode_cb_t)(struct vdec_lat_buf *lat_buf);

/**
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.c b/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.c
index e971f385723c..29a99dd5d61a 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.c
@@ -4,8 +4,7 @@
* Author: PC Chen <[email protected]>
*/

-#include "mtk_vcodec_drv.h"
-#include "mtk_vcodec_util.h"
+#include "mtk_vcodec_dec_drv.h"
#include "vdec_drv_if.h"
#include "vdec_ipi_msg.h"
#include "vdec_vpu_if.h"
diff --git a/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c b/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c
index 66bbb892d8e7..3e8f3a9f3088 100644
--- a/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c
+++ b/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c
@@ -10,7 +10,7 @@
#include <linux/kernel.h>
#include <linux/slab.h>

-#include "../mtk_vcodec_drv.h"
+#include "../mtk_vcodec_enc_drv.h"
#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_intr.h"
#include "../mtk_vcodec_enc.h"
diff --git a/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c b/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c
index dc48bf881aa7..efa33c2f093d 100644
--- a/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c
+++ b/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c
@@ -9,7 +9,7 @@
#include <linux/kernel.h>
#include <linux/slab.h>

-#include "../mtk_vcodec_drv.h"
+#include "../mtk_vcodec_enc_drv.h"
#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_intr.h"
#include "../mtk_vcodec_enc.h"
diff --git a/drivers/media/platform/mediatek/vcodec/venc_drv_base.h b/drivers/media/platform/mediatek/vcodec/venc_drv_base.h
index 17f8183461b5..856d50151bf6 100644
--- a/drivers/media/platform/mediatek/vcodec/venc_drv_base.h
+++ b/drivers/media/platform/mediatek/vcodec/venc_drv_base.h
@@ -9,7 +9,7 @@
#ifndef _VENC_DRV_BASE_
#define _VENC_DRV_BASE_

-#include "mtk_vcodec_drv.h"
+#include "mtk_vcodec_enc_drv.h"

#include "venc_drv_if.h"

diff --git a/drivers/media/platform/mediatek/vcodec/venc_drv_if.c b/drivers/media/platform/mediatek/vcodec/venc_drv_if.c
index 08083030516e..1bdaecdd64a7 100644
--- a/drivers/media/platform/mediatek/vcodec/venc_drv_if.c
+++ b/drivers/media/platform/mediatek/vcodec/venc_drv_if.c
@@ -65,7 +65,7 @@ int venc_if_encode(struct mtk_vcodec_enc_ctx *ctx,
mtk_venc_lock(ctx);

spin_lock_irqsave(&ctx->dev->irqlock, flags);
- ctx->dev->curr_enc_ctx = ctx;
+ ctx->dev->curr_ctx = ctx;
spin_unlock_irqrestore(&ctx->dev->irqlock, flags);

mtk_vcodec_enc_clock_on(&ctx->dev->pm);
@@ -74,7 +74,7 @@ int venc_if_encode(struct mtk_vcodec_enc_ctx *ctx,
mtk_vcodec_enc_clock_off(&ctx->dev->pm);

spin_lock_irqsave(&ctx->dev->irqlock, flags);
- ctx->dev->curr_enc_ctx = NULL;
+ ctx->dev->curr_ctx = NULL;
spin_unlock_irqrestore(&ctx->dev->irqlock, flags);

mtk_venc_unlock(ctx);
diff --git a/drivers/media/platform/mediatek/vcodec/venc_drv_if.h b/drivers/media/platform/mediatek/vcodec/venc_drv_if.h
index 90d714e86ede..d00fb68b8235 100644
--- a/drivers/media/platform/mediatek/vcodec/venc_drv_if.h
+++ b/drivers/media/platform/mediatek/vcodec/venc_drv_if.h
@@ -9,8 +9,7 @@
#ifndef _VENC_DRV_IF_H_
#define _VENC_DRV_IF_H_

-#include "mtk_vcodec_drv.h"
-#include "mtk_vcodec_util.h"
+#include "mtk_vcodec_enc_drv.h"

/*
* enum venc_yuv_fmt - The type of input yuv format
diff --git a/drivers/media/platform/mediatek/vcodec/venc_vpu_if.c b/drivers/media/platform/mediatek/vcodec/venc_vpu_if.c
index 629d0bfb4102..fc69698bc526 100644
--- a/drivers/media/platform/mediatek/vcodec/venc_vpu_if.c
+++ b/drivers/media/platform/mediatek/vcodec/venc_vpu_if.c
@@ -4,7 +4,7 @@
* Author: PoChun Lin <[email protected]>
*/

-#include "mtk_vcodec_drv.h"
+#include "mtk_vcodec_enc_drv.h"
#include "mtk_vcodec_fw.h"
#include "venc_ipi_msg.h"
#include "venc_vpu_if.h"
--
2.18.0


2023-06-07 09:02:45

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: [PATCH v2,01/10] media: mediatek: vcodec: remove unused parameter

remove unused parameter in struct mtk_vcodec_dev.

Signed-off-by: Yunfei Dong <[email protected]>
---
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c | 2 --
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h | 6 ------
drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c | 2 --
3 files changed, 10 deletions(-)

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
index d41f2121b94f..03721eda2769 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
@@ -336,8 +336,6 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
goto err_core_workq;
}

- init_waitqueue_head(&dev->queue);
-
vfd_dec = video_device_alloc();
if (!vfd_dec) {
mtk_v4l2_err("Failed to allocate video device");
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
index f17d67e781c9..e3230a4d7b8e 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
@@ -448,10 +448,7 @@ struct mtk_vcodec_enc_pdata {
* @decode_workqueue: decode work queue
* @encode_workqueue: encode work queue
*
- * @int_cond: used to identify interrupt condition happen
- * @int_type: used to identify what kind of interrupt condition happen
* @dev_mutex: video_device lock
- * @queue: waitqueue for waiting for completion of device commands
*
* @dec_irq: decoder irq resource
* @enc_irq: h264 encoder irq resource
@@ -496,10 +493,7 @@ struct mtk_vcodec_dev {

struct workqueue_struct *decode_workqueue;
struct workqueue_struct *encode_workqueue;
- int int_cond;
- int int_type;
struct mutex dev_mutex;
- wait_queue_head_t queue;

int dec_irq;
int enc_irq;
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c
index 5df0a22ff3b5..a56652e476c2 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c
@@ -311,8 +311,6 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
goto err_res;
}

- init_waitqueue_head(&dev->queue);
-
/* allocate video device for encoder and register it */
vfd_enc = video_device_alloc();
if (!vfd_enc) {
--
2.18.0


2023-06-07 09:05:32

by Yunfei Dong (董云飞)

[permalink] [raw]
Subject: [PATCH v2,09/10] mediatek: vcodec: remove unused include header

remove unused include header for .c files

Signed-off-by: Yunfei Dong <[email protected]>
---
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c | 2 --
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c | 2 --
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c | 1 -
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c | 1 -
.../media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c | 2 --
.../media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c | 2 --
drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c | 2 --
drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c | 2 --
drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.c | 1 -
.../media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c | 1 -
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_if.c | 1 -
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_if.c | 1 -
.../platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c | 1 -
.../platform/mediatek/vcodec/vdec/vdec_hevc_req_multi_if.c | 1 -
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_if.c | 1 -
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c | 1 -
.../media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c | 1 -
drivers/media/platform/mediatek/vcodec/vdec_drv_if.h | 1 -
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h | 2 --
drivers/media/platform/mediatek/vcodec/vdec_vpu_if.c | 1 -
drivers/media/platform/mediatek/vcodec/vdec_vpu_if.h | 2 --
drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c | 1 -
drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c | 1 -
drivers/media/platform/mediatek/vcodec/venc_vpu_if.c | 1 -
drivers/media/platform/mediatek/vcodec/venc_vpu_if.h | 1 -
25 files changed, 33 deletions(-)

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c
index 0abdc0a10425..873778888f5b 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c
@@ -11,8 +11,6 @@

#include "mtk_vcodec_dec_drv.h"
#include "mtk_vcodec_dec.h"
-#include "mtk_vcodec_intr.h"
-#include "mtk_vcodec_util.h"
#include "vdec_drv_if.h"
#include "mtk_vcodec_dec_pm.h"

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
index 004d5e20dfc3..d979018dcd20 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c
@@ -21,8 +21,6 @@
#include "mtk_vcodec_dec_hw.h"
#include "mtk_vcodec_dec_pm.h"
#include "mtk_vcodec_intr.h"
-#include "mtk_vcodec_util.h"
-#include "mtk_vcodec_fw.h"

static int mtk_vcodec_get_hw_count(struct mtk_vcodec_dec_dev *dev)
{
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c
index 82e064b0b72f..8a10ad28b920 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c
@@ -16,7 +16,6 @@
#include "mtk_vcodec_dec_hw.h"
#include "mtk_vcodec_dec_pm.h"
#include "mtk_vcodec_intr.h"
-#include "mtk_vcodec_util.h"

static const struct of_device_id mtk_vdec_hw_match[] = {
{
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c
index 3d7b9729be4a..152a43e850f7 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_pm.c
@@ -12,7 +12,6 @@

#include "mtk_vcodec_dec_hw.h"
#include "mtk_vcodec_dec_pm.h"
-#include "mtk_vcodec_util.h"

int mtk_vcodec_init_dec_clk(struct platform_device *pdev, struct mtk_vcodec_pm *pm)
{
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c
index 72ce22620cc6..7424717189e6 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c
@@ -5,8 +5,6 @@
#include <media/videobuf2-dma-contig.h>

#include "mtk_vcodec_dec.h"
-#include "mtk_vcodec_intr.h"
-#include "mtk_vcodec_util.h"
#include "mtk_vcodec_dec_pm.h"
#include "vdec_drv_if.h"

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
index 8725f6631d5f..a1dcf17dfd04 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
@@ -7,8 +7,6 @@
#include <linux/module.h>

#include "mtk_vcodec_dec.h"
-#include "mtk_vcodec_intr.h"
-#include "mtk_vcodec_util.h"
#include "mtk_vcodec_dec_pm.h"
#include "vdec_drv_if.h"

diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
index 8be7565bad57..dad19c69dffc 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
@@ -11,8 +11,6 @@
#include <linux/pm_runtime.h>

#include "mtk_vcodec_enc.h"
-#include "mtk_vcodec_intr.h"
-#include "mtk_vcodec_util.h"
#include "venc_drv_if.h"

#define MTK_VENC_MIN_W 160U
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c
index a756eae2e53e..1f2b56f76931 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c
@@ -19,8 +19,6 @@
#include "mtk_vcodec_enc.h"
#include "mtk_vcodec_enc_pm.h"
#include "mtk_vcodec_intr.h"
-#include "mtk_vcodec_util.h"
-#include "mtk_vcodec_fw.h"

static const struct mtk_video_fmt mtk_video_formats_output[] = {
{
diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.c
index 09d865a80bc0..d87a05000002 100644
--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.c
+++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_fw.c
@@ -2,7 +2,6 @@

#include "mtk_vcodec_dec_drv.h"
#include "mtk_vcodec_enc_drv.h"
-#include "mtk_vcodec_fw.h"
#include "mtk_vcodec_fw_priv.h"

struct mtk_vcodec_fw *mtk_vcodec_fw_select(void *priv, enum mtk_vcodec_fw_type type,
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c
index 4c5cd37e4c5f..da1ada8a5727 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c
@@ -8,7 +8,6 @@
#include <linux/slab.h>
#include <media/videobuf2-dma-contig.h>

-#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_dec.h"
#include "../mtk_vcodec_intr.h"
#include "../vdec_drv_base.h"
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_if.c
index 64ec91d5bb13..3ad7d41f53ba 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_if.c
@@ -8,7 +8,6 @@
#include <linux/slab.h>

#include "../vdec_drv_if.h"
-#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_dec.h"
#include "../mtk_vcodec_intr.h"
#include "../vdec_vpu_if.h"
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_if.c
index 410da85bd478..633dc1b4e8b6 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_if.c
@@ -6,7 +6,6 @@
#include <media/v4l2-h264.h>
#include <media/videobuf2-dma-contig.h>

-#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_dec.h"
#include "../mtk_vcodec_intr.h"
#include "../vdec_drv_base.h"
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
index 1bfcc3cc3c3c..16cc4e9b451f 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
@@ -10,7 +10,6 @@
#include <media/v4l2-mem2mem.h>
#include <media/videobuf2-dma-contig.h>

-#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_dec.h"
#include "../mtk_vcodec_intr.h"
#include "../vdec_drv_base.h"
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_hevc_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_hevc_req_multi_if.c
index ef3bc5bd87a5..3c58fbb6ade3 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_hevc_req_multi_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_hevc_req_multi_if.c
@@ -8,7 +8,6 @@
#include <linux/slab.h>
#include <media/videobuf2-dma-contig.h>

-#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_dec.h"
#include "../mtk_vcodec_intr.h"
#include "../vdec_drv_base.h"
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_if.c
index 0e9a44cbdc44..54236a74fa13 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_if.c
@@ -7,7 +7,6 @@

#include <linux/slab.h>
#include "../vdec_drv_if.h"
-#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_dec.h"
#include "../mtk_vcodec_intr.h"
#include "../vdec_vpu_if.h"
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c
index 807d426d6e82..7449691d3b54 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp8_req_if.c
@@ -9,7 +9,6 @@
#include <media/videobuf2-dma-contig.h>
#include <uapi/linux/v4l2-controls.h>

-#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_dec.h"
#include "../mtk_vcodec_intr.h"
#include "../vdec_drv_base.h"
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
index 20605e1832e3..7a2c5ac7a196 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
@@ -9,7 +9,6 @@
#include <media/videobuf2-dma-contig.h>
#include <media/v4l2-vp9.h>

-#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_dec.h"
#include "../mtk_vcodec_intr.h"
#include "../vdec_drv_base.h"
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_drv_if.h b/drivers/media/platform/mediatek/vcodec/vdec_drv_if.h
index 7b41ce23158b..bfd297c96850 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_drv_if.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec_drv_if.h
@@ -9,7 +9,6 @@
#define _VDEC_DRV_IF_H_

#include "mtk_vcodec_dec.h"
-#include "mtk_vcodec_util.h"


/**
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
index af2636244af0..654468a169b1 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h
@@ -12,8 +12,6 @@
#include <linux/slab.h>
#include <media/videobuf2-v4l2.h>

-#include "mtk_vcodec_util.h"
-
#define NUM_BUFFER_COUNT 3

struct vdec_lat_buf;
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.c b/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.c
index 29a99dd5d61a..deba0fe618d9 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.c
+++ b/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.c
@@ -8,7 +8,6 @@
#include "vdec_drv_if.h"
#include "vdec_ipi_msg.h"
#include "vdec_vpu_if.h"
-#include "mtk_vcodec_fw.h"

static void handle_init_ack_msg(const struct vdec_vpu_ipi_init_ack *msg)
{
diff --git a/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.h b/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.h
index c9766c108209..fbb3f34a73f0 100644
--- a/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.h
+++ b/drivers/media/platform/mediatek/vcodec/vdec_vpu_if.h
@@ -7,8 +7,6 @@
#ifndef _VDEC_VPU_IF_H_
#define _VDEC_VPU_IF_H_

-#include "mtk_vcodec_fw.h"
-
struct mtk_vcodec_dec_ctx;

/**
diff --git a/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c b/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c
index 3e8f3a9f3088..0d1a8c4dc27b 100644
--- a/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c
+++ b/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c
@@ -11,7 +11,6 @@
#include <linux/slab.h>

#include "../mtk_vcodec_enc_drv.h"
-#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_intr.h"
#include "../mtk_vcodec_enc.h"
#include "../mtk_vcodec_enc_pm.h"
diff --git a/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c b/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c
index efa33c2f093d..0d5c6b0b23c8 100644
--- a/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c
+++ b/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c
@@ -10,7 +10,6 @@
#include <linux/slab.h>

#include "../mtk_vcodec_enc_drv.h"
-#include "../mtk_vcodec_util.h"
#include "../mtk_vcodec_intr.h"
#include "../mtk_vcodec_enc.h"
#include "../mtk_vcodec_enc_pm.h"
diff --git a/drivers/media/platform/mediatek/vcodec/venc_vpu_if.c b/drivers/media/platform/mediatek/vcodec/venc_vpu_if.c
index fc69698bc526..95f684bc29f7 100644
--- a/drivers/media/platform/mediatek/vcodec/venc_vpu_if.c
+++ b/drivers/media/platform/mediatek/vcodec/venc_vpu_if.c
@@ -5,7 +5,6 @@
*/

#include "mtk_vcodec_enc_drv.h"
-#include "mtk_vcodec_fw.h"
#include "venc_ipi_msg.h"
#include "venc_vpu_if.h"

diff --git a/drivers/media/platform/mediatek/vcodec/venc_vpu_if.h b/drivers/media/platform/mediatek/vcodec/venc_vpu_if.h
index 71370ab98809..ede55fc3bd07 100644
--- a/drivers/media/platform/mediatek/vcodec/venc_vpu_if.h
+++ b/drivers/media/platform/mediatek/vcodec/venc_vpu_if.h
@@ -7,7 +7,6 @@
#ifndef _VENC_VPU_IF_H_
#define _VENC_VPU_IF_H_

-#include "mtk_vcodec_fw.h"
#include "venc_drv_if.h"

/*
--
2.18.0