2021-08-10 11:56:39

by Yunfei Dong

[permalink] [raw]
Subject: [PATCH v4, 00/15] Using component framework to support multi hardware decode

This series adds support for multi hardware decode into mtk-vcodec, by first
adding component framework to manage each hardware information: interrupt,
clock, register bases and power. Secondly add core thread to deal with core
hardware message, at the same time, add msg queue for different hardware
share messages. Lastly, the architecture of different specs are not the same,
using specs type to separate them.

This series has been tested with both MT8183 and MT8173. Decoding was working
for both chips.

Patches 1~3 rewrite get register bases and power on/off interface.

Patch 4 add component framework to support multi hardware.

Patch 5 separate video encoder and decoder document

Patches 6-15 add interfaces to support core hardware.
----
This patch dependents on "media: mtk-vcodec: support for MT8183 decoder"[1].

Multi hardware decode is based on stateless decoder, MT8183 is the first time
to add stateless decoder. Otherwise it will cause conflict. Please also accept
this patch together with [1].

[1]https://lore.kernel.org/patchwork/project/lkml/list/?series=507084
----
Changes compared with v3:
- Fix return value for patch 1/15
- Fix comments for patch 4/15
> Looking up "mediatek,mtk-vcodec-core" to determine if it uses component framwork sounds like...
Add prameter in pdata, for all platform will use compoent after mt8183

>> + if (dev->is_comp_supported) {
>> + ret = mtk_vcodec_init_master(dev);
>> + if (ret < 0)
>> + goto err_component_match;
>> + } else {
>> + platform_set_drvdata(pdev, dev);
>> + }
> + Has asked the same question in [1]. Why it removes the
> +platform_set_drvdata() above? mtk_vcodec_init_master() also calls platform_set_drvdata().
Must call component_master_add_with_match after platform_set_drvdata for component architecture.
- Fix yaml files check fail for patch 5/15
- Fix yaml file check fail for patch 14/15

Changes compared with v1:
- Fix many comments for patch 3/14
- Remove unnecessary code for patch 4/14
- Using enum mtk_vdec_hw_count instead of magic numbers for patch 6/14
- Reconstructed get/put lat buffer for lat and core hardware for patch 7/14
- Using yaml format to instead of txt file for patch 12/14

Yunfei Dong (15):
media: mtk-vcodec: Get numbers of register bases from DT
media: mtk-vcodec: Align vcodec wake up interrupt interface
media: mtk-vcodec: Refactor vcodec pm interface
media: mtk-vcodec: Use component framework to manage each hardware
information
dt-bindings: media: mtk-vcodec: Separate video encoder and decoder
dt-bindings
media: mtk-vcodec: Use pure single core for MT8183
media: mtk-vcodec: Add irq interface for multi hardware
media: mtk-vcodec: Add msg queue feature for lat and core architecture
media: mtk-vcodec: Generalize power and clock on/off interfaces
media: mtk-vcodec: Add new interface to lock different hardware
media: mtk-vcodec: Add core thread
media: mtk-vcodec: Support 34bits dma address for vdec
dt-bindings: media: mtk-vcodec: Adds decoder dt-bindings for mt8192
media: mtk-vcodec: Add core dec and dec end ipi msg
media: mtk-vcodec: Use codec type to separate different hardware

.../media/mediatek,vcodec-comp-decoder.yaml | 172 +++++++++++
.../media/mediatek,vcodec-decoder.yaml | 175 +++++++++++
.../media/mediatek,vcodec-encoder.yaml | 185 +++++++++++
.../bindings/media/mediatek-vcodec.txt | 130 --------
drivers/media/platform/mtk-vcodec/Makefile | 2 +
.../platform/mtk-vcodec/mtk_vcodec_dec.c | 4 +-
.../platform/mtk-vcodec/mtk_vcodec_dec.h | 1 +
.../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 280 ++++++++++++++---
.../platform/mtk-vcodec/mtk_vcodec_dec_hw.c | 184 +++++++++++
.../platform/mtk-vcodec/mtk_vcodec_dec_hw.h | 53 ++++
.../platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 98 ++++--
.../platform/mtk-vcodec/mtk_vcodec_dec_pm.h | 13 +-
.../mtk-vcodec/mtk_vcodec_dec_stateful.c | 2 +
.../mtk-vcodec/mtk_vcodec_dec_stateless.c | 2 +
.../platform/mtk-vcodec/mtk_vcodec_drv.h | 71 ++++-
.../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 12 +-
.../platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 1 -
.../platform/mtk-vcodec/mtk_vcodec_intr.c | 27 +-
.../platform/mtk-vcodec/mtk_vcodec_intr.h | 4 +-
.../platform/mtk-vcodec/mtk_vcodec_util.c | 87 +++++-
.../platform/mtk-vcodec/mtk_vcodec_util.h | 8 +-
.../platform/mtk-vcodec/vdec/vdec_h264_if.c | 2 +-
.../mtk-vcodec/vdec/vdec_h264_req_if.c | 2 +-
.../platform/mtk-vcodec/vdec/vdec_vp8_if.c | 2 +-
.../platform/mtk-vcodec/vdec/vdec_vp9_if.c | 2 +-
.../media/platform/mtk-vcodec/vdec_drv_if.c | 21 +-
.../media/platform/mtk-vcodec/vdec_ipi_msg.h | 16 +-
.../platform/mtk-vcodec/vdec_msg_queue.c | 290 ++++++++++++++++++
.../platform/mtk-vcodec/vdec_msg_queue.h | 157 ++++++++++
.../media/platform/mtk-vcodec/vdec_vpu_if.c | 46 ++-
.../media/platform/mtk-vcodec/vdec_vpu_if.h | 22 ++
.../platform/mtk-vcodec/venc/venc_h264_if.c | 2 +-
.../platform/mtk-vcodec/venc/venc_vp8_if.c | 2 +-
33 files changed, 1795 insertions(+), 280 deletions(-)
create mode 100644 Documentation/devicetree/bindings/media/mediatek,vcodec-comp-decoder.yaml
create mode 100644 Documentation/devicetree/bindings/media/mediatek,vcodec-decoder.yaml
create mode 100644 Documentation/devicetree/bindings/media/mediatek,vcodec-encoder.yaml
delete mode 100644 Documentation/devicetree/bindings/media/mediatek-vcodec.txt
create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.h
create mode 100644 drivers/media/platform/mtk-vcodec/vdec_msg_queue.c
create mode 100644 drivers/media/platform/mtk-vcodec/vdec_msg_queue.h

--
2.25.1


2021-08-10 11:56:51

by Yunfei Dong

[permalink] [raw]
Subject: [PATCH v4, 06/15] media: mtk-vcodec: Use pure single core for MT8183

Separates different architecture for hardware: pure_sin_core
and lat_sin_core. MT8183 is pure single core. Uses .hw_arch to
distinguish.

Change-Id: Ie771c7f7233ff9caa8c7aac0c787bdff757f7b0e
Signed-off-by: Yunfei Dong <[email protected]>
---
v4: no change
---
.../platform/mtk-vcodec/mtk_vcodec_dec_stateful.c | 1 +
.../platform/mtk-vcodec/mtk_vcodec_dec_stateless.c | 1 +
drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h | 10 ++++++++++
3 files changed, 12 insertions(+)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateful.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateful.c
index 4f9a80ce15d8..138f6fcb36bb 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateful.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateful.c
@@ -624,4 +624,5 @@ const struct mtk_vcodec_dec_pdata mtk_vdec_8173_pdata = {
.worker = mtk_vdec_worker,
.flush_decoder = mtk_vdec_flush_decoder,
.is_comp_supported = false,
+ .hw_arch = MTK_VDEC_PURE_SINGLE_CORE,
};
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c
index 762633572b49..12c243d6dff3 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c
@@ -358,4 +358,5 @@ const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata = {
.worker = mtk_vdec_worker,
.flush_decoder = mtk_vdec_flush_decoder,
.is_comp_supported = false,
+ .hw_arch = MTK_VDEC_PURE_SINGLE_CORE,
};
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
index e530757a9b5a..1d0798fd9adf 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -323,6 +323,14 @@ enum mtk_chip {
MTK_MT8192,
};

+/**
+ * struct 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_vcodec_dec_pdata - compatible data for each IC
* @init_vdec_params: init vdec params
@@ -341,6 +349,7 @@ enum mtk_chip {
* @num_framesizes: count of video decoder frame sizes
*
* @chip: chip this decoder is compatible with
+ * @hw_arch: hardware arch is used to separate pure_sin_core and lat_sin_core
*
* @is_comp_supported: true: using compoent framework, false: not support
* @uses_stateless_api: whether the decoder uses the stateless API with requests
@@ -363,6 +372,7 @@ struct mtk_vcodec_dec_pdata {
const int num_framesizes;

enum mtk_chip chip;
+ enum mtk_vdec_hw_arch hw_arch;

bool is_comp_supported;
bool uses_stateless_api;
--
2.25.1

2021-08-10 11:57:47

by Yunfei Dong

[permalink] [raw]
Subject: [PATCH v4, 07/15] media: mtk-vcodec: Add irq interface for multi hardware

Adds irq interface for multi hardware.

Change-Id: I9ed8f9538c83d9376a70bc125f77686ac85cedb9
Signed-off-by: Yunfei Dong <[email protected]>
---
v4: no change
---
.../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 33 +++++++++++++++++--
.../platform/mtk-vcodec/mtk_vcodec_dec_hw.c | 2 +-
.../platform/mtk-vcodec/mtk_vcodec_drv.h | 25 ++++++++++----
.../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 4 +--
.../platform/mtk-vcodec/mtk_vcodec_intr.c | 27 +++++++--------
.../platform/mtk-vcodec/mtk_vcodec_intr.h | 4 +--
.../platform/mtk-vcodec/vdec/vdec_h264_if.c | 2 +-
.../mtk-vcodec/vdec/vdec_h264_req_if.c | 2 +-
.../platform/mtk-vcodec/vdec/vdec_vp8_if.c | 2 +-
.../platform/mtk-vcodec/vdec/vdec_vp9_if.c | 2 +-
.../platform/mtk-vcodec/venc/venc_h264_if.c | 2 +-
.../platform/mtk-vcodec/venc/venc_vp8_if.c | 2 +-
12 files changed, 71 insertions(+), 36 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index d93ea5c63e1e..d52e975292dc 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -68,6 +68,20 @@ static const struct component_master_ops mtk_vdec_ops = {
.unbind = mtk_vdec_unbind,
};

+static int mtk_vcodec_get_hw_count(struct mtk_vcodec_dev *dev)
+{
+ switch (dev->vdec_pdata->hw_arch) {
+ case MTK_VDEC_PURE_SINGLE_CORE:
+ return MTK_VDEC_ONE_CORE;
+ case MTK_VDEC_LAT_SINGLE_CORE:
+ return MTK_VDEC_ONE_LAT_ONE_CORE;
+ default:
+ mtk_v4l2_err("not support hw arch:%d",
+ dev->vdec_pdata->hw_arch);
+ return MTK_VDEC_NO_HW;
+ }
+}
+
static struct component_match *mtk_vcodec_match_add(
struct mtk_vcodec_dev *vdec_dev)
{
@@ -134,7 +148,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);
+ wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0);

mtk_v4l2_debug(3,
"mtk_vcodec_dec_irq_handler :wake up ctx %d, dec_done_status=%x",
@@ -224,7 +238,7 @@ static int fops_vcodec_open(struct file *file)
{
struct mtk_vcodec_dev *dev = video_drvdata(file);
struct mtk_vcodec_ctx *ctx = NULL;
- int ret = 0;
+ int ret = 0, i, hw_count;
struct vb2_queue *src_vq;

ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
@@ -238,7 +252,19 @@ static int fops_vcodec_open(struct file *file)
v4l2_fh_add(&ctx->fh);
INIT_LIST_HEAD(&ctx->list);
ctx->dev = dev;
- init_waitqueue_head(&ctx->queue);
+
+ if (ctx->dev->vdec_pdata->is_comp_supported) {
+ hw_count = mtk_vcodec_get_hw_count(dev);
+ if (!hw_count) {
+ ret = -EINVAL;
+ goto err_init_queue;
+ }
+ for (i = 0; i < hw_count; i++)
+ init_waitqueue_head(&ctx->queue[i]);
+ } else {
+ init_waitqueue_head(&ctx->queue[0]);
+ }
+
mutex_init(&ctx->lock);

ctx->type = MTK_INST_DECODER;
@@ -295,6 +321,7 @@ static int fops_vcodec_open(struct file *file)
err_m2m_ctx_init:
v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
err_ctrls_setup:
+err_init_queue:
v4l2_fh_del(&ctx->fh);
v4l2_fh_exit(&ctx->fh);
kfree(ctx);
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
index 5e1b7670ba5b..7a31afd294ba 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
@@ -87,7 +87,7 @@ static irqreturn_t mtk_vdec_comp_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);
+ wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, dev->comp_idx);

mtk_v4l2_debug(3, "wake up ctx %d, dec_done_status=%x",
ctx->id, dec_done_status);
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
index 1d0798fd9adf..08fd43106fc7 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -104,6 +104,16 @@ enum mtk_vdec_hw_id {
MTK_VDEC_HW_MAX,
};

+/**
+ * struct 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,
+};
+
/*
* struct mtk_video_fmt - Structure used to store information about pixelformats
*/
@@ -293,9 +303,9 @@ struct mtk_vcodec_ctx {
struct vdec_pic_info picinfo;
int dpb_size;

- int int_cond;
- int int_type;
- wait_queue_head_t queue;
+ 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;
@@ -501,11 +511,12 @@ static inline struct mtk_vcodec_ctx *ctrl_to_ctx(struct v4l2_ctrl *ctrl)
}

/* Wake up context wait_queue */
-static inline void wake_up_ctx(struct mtk_vcodec_ctx *ctx, unsigned int reason)
+static inline void wake_up_ctx(struct mtk_vcodec_ctx *ctx, unsigned int reason,
+ unsigned int hw_id)
{
- ctx->int_cond = 1;
- ctx->int_type = reason;
- wake_up_interruptible(&ctx->queue);
+ 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/mtk-vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
index 2828df77020c..c7540c0cdcea 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
@@ -114,7 +114,7 @@ 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);
+ wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0);
return IRQ_HANDLED;
}

@@ -140,7 +140,7 @@ static int fops_vcodec_open(struct file *file)
v4l2_fh_add(&ctx->fh);
INIT_LIST_HEAD(&ctx->list);
ctx->dev = dev;
- init_waitqueue_head(&ctx->queue);
+ init_waitqueue_head(&ctx->queue[0]);

ctx->type = MTK_INST_ENCODER;
ret = mtk_vcodec_enc_ctrls_setup(ctx);
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.c
index 70580c2525ba..8147533da98b 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.c
@@ -11,34 +11,31 @@
#include "mtk_vcodec_intr.h"
#include "mtk_vcodec_util.h"

-int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx, int command,
- unsigned int timeout_ms)
+int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx,
+ int command, unsigned int timeout_ms, unsigned hw_id)
{
- wait_queue_head_t *waitqueue;
long timeout_jiff, ret;
int status = 0;

- waitqueue = (wait_queue_head_t *)&ctx->queue;
timeout_jiff = msecs_to_jiffies(timeout_ms);
-
- ret = wait_event_interruptible_timeout(*waitqueue,
- ctx->int_cond,
+ ret = wait_event_interruptible_timeout(ctx->queue[hw_id],
+ ctx->int_cond[hw_id],
timeout_jiff);

if (!ret) {
status = -1; /* timeout */
- mtk_v4l2_err("[%d] ctx->type=%d, cmd=%d, wait_event_interruptible_timeout time=%ums out %d %d!",
- ctx->id, ctx->type, command, timeout_ms,
- ctx->int_cond, ctx->int_type);
+ mtk_v4l2_err("[%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) {
- mtk_v4l2_err("[%d] ctx->type=%d, cmd=%d, wait_event_interruptible_timeout interrupted by a signal %d %d",
- ctx->id, ctx->type, command, ctx->int_cond,
- ctx->int_type);
status = -1;
+ mtk_v4l2_err("[%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]);
}

- ctx->int_cond = 0;
- ctx->int_type = 0;
+ ctx->int_cond[hw_id] = 0;
+ ctx->int_type[hw_id] = 0;

return status;
}
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.h
index 638cd1f3526a..2bf4cabfaa43 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.h
@@ -12,7 +12,7 @@
struct mtk_vcodec_ctx;

/* timeout is ms */
-int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *data, int command,
- unsigned int timeout_ms);
+int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx,
+ int command, unsigned int timeout_ms, unsigned int hw_id);

#endif /* _MTK_VCODEC_INTR_H_ */
diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c b/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c
index 40d6e6c5ac7a..481655bb6016 100644
--- a/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c
+++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c
@@ -413,7 +413,7 @@ static int vdec_h264_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
/* wait decoder done interrupt */
err = mtk_vcodec_wait_for_done_ctx(inst->ctx,
MTK_INST_IRQ_RECEIVED,
- WAIT_INTR_TIMEOUT_MS);
+ WAIT_INTR_TIMEOUT_MS, 0);
if (err)
goto err_free_fb_out;

diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_req_if.c b/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_req_if.c
index 4dde9ee786b4..d23baa364246 100644
--- a/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_req_if.c
+++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_req_if.c
@@ -724,7 +724,7 @@ static int vdec_h264_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
/* wait decoder done interrupt */
err = mtk_vcodec_wait_for_done_ctx(inst->ctx,
MTK_INST_IRQ_RECEIVED,
- WAIT_INTR_TIMEOUT_MS);
+ WAIT_INTR_TIMEOUT_MS, 0);
if (err)
goto err_free_fb_out;
vpu_dec_end(vpu);
diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c
index e5393f841080..88c046731754 100644
--- a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c
+++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c
@@ -488,7 +488,7 @@ static int vdec_vp8_decode(void *h_vdec, struct mtk_vcodec_mem *bs,

/* wait decoder done interrupt */
mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED,
- WAIT_INTR_TIMEOUT_MS);
+ WAIT_INTR_TIMEOUT_MS, 0);

if (inst->vsi->load_data)
load_dec_table(inst);
diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
index 71cdc3ddafcb..70b8383f7c8e 100644
--- a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
+++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
@@ -539,7 +539,7 @@ static bool vp9_wait_dec_end(struct vdec_vp9_inst *inst)

mtk_vcodec_wait_for_done_ctx(inst->ctx,
MTK_INST_IRQ_RECEIVED,
- WAIT_INTR_TIMEOUT_MS);
+ WAIT_INTR_TIMEOUT_MS, 0);

if (ctx->irq_status & MTK_VDEC_IRQ_STATUS_DEC_SUCCESS)
return true;
diff --git a/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c b/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c
index b6a4f2074fa5..9ae1bd8dbc32 100644
--- a/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c
+++ b/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c
@@ -335,7 +335,7 @@ static unsigned int h264_enc_wait_venc_done(struct venc_h264_inst *inst)
struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)inst->ctx;

if (!mtk_vcodec_wait_for_done_ctx(ctx, MTK_INST_IRQ_RECEIVED,
- WAIT_INTR_TIMEOUT_MS)) {
+ WAIT_INTR_TIMEOUT_MS, 0)) {
irq_status = ctx->irq_status;
mtk_vcodec_debug(inst, "irq_status %x <-", irq_status);
}
diff --git a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c b/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
index 8267a9c4fd25..f96564277577 100644
--- a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
+++ b/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c
@@ -222,7 +222,7 @@ static unsigned int vp8_enc_wait_venc_done(struct venc_vp8_inst *inst)
struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)inst->ctx;

if (!mtk_vcodec_wait_for_done_ctx(ctx, MTK_INST_IRQ_RECEIVED,
- WAIT_INTR_TIMEOUT_MS)) {
+ WAIT_INTR_TIMEOUT_MS, 0)) {
irq_status = ctx->irq_status;
mtk_vcodec_debug(inst, "isr return %x", irq_status);
}
--
2.25.1

2021-08-10 11:57:54

by Yunfei Dong

[permalink] [raw]
Subject: [PATCH v4, 04/15] media: mtk-vcodec: Use component framework to manage each hardware information

Uses component framework to manage each hardware information which
includes irq/power/clk. The hardware includes LAT0, LAT1 and CORE.

Change-Id: I90b4da74a1ea482551bf8c3e7c07917a7bae2e7a
Signed-off-by: Yunfei Dong <[email protected]>
---
v4: Fix many coments
> Looking up "mediatek,mtk-vcodec-core" to determine if it uses component framwork sounds like...
Add prameter in pdata, for all platform will use compoent after mt8183

>> + if (dev->is_comp_supported) {
>> + ret = mtk_vcodec_init_master(dev);
>> + if (ret < 0)
>> + goto err_component_match;
>> + } else {
>> + platform_set_drvdata(pdev, dev);
>> + }
> + Has asked the same question in [1]. Why it removes the
> +platform_set_drvdata() above? mtk_vcodec_init_master() also calls platform_set_drvdata().
Must call component_master_add_with_match after platform_set_drvdata for component architecture.
---
drivers/media/platform/mtk-vcodec/Makefile | 1 +
.../platform/mtk-vcodec/mtk_vcodec_dec.h | 1 +
.../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 198 ++++++++++++++----
.../platform/mtk-vcodec/mtk_vcodec_dec_hw.c | 184 ++++++++++++++++
.../platform/mtk-vcodec/mtk_vcodec_dec_hw.h | 49 +++++
.../mtk-vcodec/mtk_vcodec_dec_stateful.c | 1 +
.../mtk-vcodec/mtk_vcodec_dec_stateless.c | 1 +
.../platform/mtk-vcodec/mtk_vcodec_drv.h | 19 ++
8 files changed, 419 insertions(+), 35 deletions(-)
create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.h

diff --git a/drivers/media/platform/mtk-vcodec/Makefile b/drivers/media/platform/mtk-vcodec/Makefile
index ca8e9e7a9c4e..edeb3b66e9e9 100644
--- a/drivers/media/platform/mtk-vcodec/Makefile
+++ b/drivers/media/platform/mtk-vcodec/Makefile
@@ -15,6 +15,7 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \
mtk_vcodec_dec_stateful.o \
mtk_vcodec_dec_stateless.o \
mtk_vcodec_dec_pm.o \
+ mtk_vcodec_dec_hw.o \

mtk-vcodec-enc-y := venc/venc_vp8_if.o \
venc/venc_h264_if.o \
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
index 9fbd24186c1a..c509224cbff4 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
@@ -66,6 +66,7 @@ extern const struct v4l2_ioctl_ops mtk_vdec_ioctl_ops;
extern const struct v4l2_m2m_ops mtk_vdec_m2m_ops;
extern const struct media_device_ops mtk_vcodec_media_ops;

+extern struct platform_driver mtk_vdec_comp_driver;

/*
* mtk_vdec_lock/mtk_vdec_unlock are for ctx instance to
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index dd749d41c75a..d93ea5c63e1e 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -5,6 +5,7 @@
* Tiffany Lin <[email protected]>
*/

+#include <linux/component.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
@@ -18,19 +19,90 @@

#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_dec.h"
+#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"

-#define VDEC_HW_ACTIVE 0x10
-#define VDEC_IRQ_CFG 0x11
-#define VDEC_IRQ_CLR 0x10
-#define VDEC_IRQ_CFG_REG 0xa4
-
module_param(mtk_v4l2_dbg_level, int, 0644);
module_param(mtk_vcodec_dbg, bool, 0644);

+static struct of_device_id mtk_vdec_drv_ids[] = {
+ {
+ .compatible = "mediatek,mtk-vcodec-lat",
+ .data = (void *)MTK_VDEC_LAT0,
+ },
+ {
+ .compatible = "mediatek,mtk-vcodec-core",
+ .data = (void *)MTK_VDEC_CORE,
+ },
+ {},
+};
+
+static inline int mtk_vdec_compare_of(struct device *dev, void *data)
+{
+ return dev->of_node == data;
+}
+
+static inline void mtk_vdec_release_of(struct device *dev, void *data)
+{
+ of_node_put(data);
+}
+
+static inline int mtk_vdec_bind(struct device *dev)
+{
+ struct mtk_vcodec_dev *data = dev_get_drvdata(dev);
+
+ return component_bind_all(dev, data);
+}
+
+static inline void mtk_vdec_unbind(struct device *dev)
+{
+ struct mtk_vcodec_dev *data = dev_get_drvdata(dev);
+
+ component_unbind_all(dev, data);
+}
+
+static const struct component_master_ops mtk_vdec_ops = {
+ .bind = mtk_vdec_bind,
+ .unbind = mtk_vdec_unbind,
+};
+
+static struct component_match *mtk_vcodec_match_add(
+ struct mtk_vcodec_dev *vdec_dev)
+ {
+ struct platform_device *pdev = vdec_dev->plat_dev;
+ struct component_match *match = NULL;
+ struct device_node *comp_node;
+ enum mtk_vdec_hw_id comp_idx;
+ const struct of_device_id *of_id;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(mtk_vdec_drv_ids); i++) {
+ of_id = &mtk_vdec_drv_ids[i];
+ comp_node = of_find_compatible_node(NULL, NULL,
+ of_id->compatible);
+ if (!comp_node)
+ continue;
+
+ if (!of_device_is_available(comp_node)) {
+ of_node_put(comp_node);
+ dev_err(&pdev->dev, "Fail to get MMSYS node\n");
+ continue;
+ }
+
+ comp_idx = (enum mtk_vdec_hw_id)of_id->data;
+ mtk_v4l2_debug(4, "Get component:hw_id(%d),vdec_dev(0x%p),comp_node(0x%p)\n",
+ comp_idx, vdec_dev, comp_node);
+ vdec_dev->component_node[comp_idx] = comp_node;
+
+ component_match_add_release(&pdev->dev, &match, mtk_vdec_release_of,
+ mtk_vdec_compare_of, comp_node);
+ }
+
+ return match;
+}
+
static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv)
{
struct mtk_vcodec_dev *dev = priv;
@@ -95,6 +167,59 @@ static int mtk_vcodec_get_reg_bases(struct mtk_vcodec_dev *dev)
return 0;
}

+static int mtk_vcodec_init_master(struct mtk_vcodec_dev *dev)
+{
+ struct platform_device *pdev = dev->plat_dev;
+ struct component_match *match;
+ int ret;
+
+ match = mtk_vcodec_match_add(dev);
+ if (IS_ERR_OR_NULL(match))
+ return -EINVAL;
+
+ platform_set_drvdata(pdev, dev);
+ ret = component_master_add_with_match(&pdev->dev, &mtk_vdec_ops, match);
+ if (ret < 0)
+ return ret;
+
+ return 0;
+}
+
+static int mtk_vcodec_init_dec_params(struct mtk_vcodec_dev *dev)
+{
+ struct platform_device *pdev = dev->plat_dev;
+ int ret;
+
+ ret = mtk_vcodec_get_reg_bases(dev);
+ if (ret)
+ return ret;
+
+ if (!dev->vdec_pdata->is_comp_supported) {
+ dev->dec_irq = platform_get_irq(pdev, 0);
+ if (dev->dec_irq < 0) {
+ dev_err(&pdev->dev, "failed to get irq number");
+ return dev->dec_irq;
+ }
+
+ irq_set_status_flags(dev->dec_irq, IRQ_NOAUTOEN);
+ ret = devm_request_irq(&pdev->dev, dev->dec_irq,
+ mtk_vcodec_dec_irq_handler, 0, pdev->name, dev);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to install dev->dec_irq %d (%d)",
+ dev->dec_irq, ret);
+ return ret;
+ }
+
+ ret = mtk_vcodec_init_dec_pm(pdev, &dev->pm);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "failed to get mt vcodec clock source");
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
static int fops_vcodec_open(struct file *file)
{
struct mtk_vcodec_dev *dev = video_drvdata(file);
@@ -220,7 +345,6 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
{
struct mtk_vcodec_dev *dev;
struct video_device *vfd_dec;
- struct resource *res;
phandle rproc_phandle;
enum mtk_vcodec_fw_type fw_type;
int ret;
@@ -249,32 +373,10 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
if (IS_ERR(dev->fw_handler))
return PTR_ERR(dev->fw_handler);

- ret = mtk_vcodec_init_dec_pm(dev->plat_dev, &dev->pm);
- if (ret < 0) {
- dev_err(&pdev->dev, "Failed to get mt vcodec clock source");
- goto err_dec_pm;
- }
-
- ret = mtk_vcodec_get_reg_bases(dev);
- if (ret)
- goto err_res;
-
- res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
- if (res == NULL) {
- dev_err(&pdev->dev, "failed to get irq resource");
- ret = -ENOENT;
- goto err_res;
- }
-
- dev->dec_irq = platform_get_irq(pdev, 0);
- irq_set_status_flags(dev->dec_irq, IRQ_NOAUTOEN);
- ret = devm_request_irq(&pdev->dev, dev->dec_irq,
- mtk_vcodec_dec_irq_handler, 0, pdev->name, dev);
+ ret = mtk_vcodec_init_dec_params(dev);
if (ret) {
- dev_err(&pdev->dev, "Failed to install dev->dec_irq %d (%d)",
- dev->dec_irq,
- ret);
- goto err_res;
+ dev_err(&pdev->dev, "Failed to init pm and registers");
+ goto err_dec_pm;
}

mutex_init(&dev->dec_mutex);
@@ -311,7 +413,6 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
MTK_VCODEC_DEC_NAME);
video_set_drvdata(vfd_dec, dev);
dev->vfd_dec = vfd_dec;
- platform_set_drvdata(pdev, dev);

dev->m2m_dev_dec = v4l2_m2m_init(&mtk_vdec_m2m_ops);
if (IS_ERR((__force void *)dev->m2m_dev_dec)) {
@@ -362,8 +463,16 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
mtk_v4l2_debug(0, "decoder registered as /dev/video%d",
vfd_dec->num);

- return 0;
+ if (dev->vdec_pdata->is_comp_supported) {
+ ret = mtk_vcodec_init_master(dev);
+ if (ret < 0)
+ goto err_component_match;
+ } else {
+ platform_set_drvdata(pdev, dev);
+ }

+ return 0;
+err_component_match:
err_dec_reg:
if (dev->vdec_pdata->uses_stateless_api)
media_device_unregister(&dev->mdev_dec);
@@ -382,6 +491,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
mtk_vcodec_release_dec_pm(&dev->pm);
err_dec_pm:
mtk_vcodec_fw_release(dev->fw_handler);
+
return ret;
}

@@ -436,7 +546,25 @@ static struct platform_driver mtk_vcodec_dec_driver = {
},
};

-module_platform_driver(mtk_vcodec_dec_driver);
+static struct platform_driver * const mtk_vdec_drivers[] = {
+ &mtk_vdec_comp_driver,
+ &mtk_vcodec_dec_driver,
+};
+
+static int __init mtk_vdec_init(void)
+{
+ return platform_register_drivers(mtk_vdec_drivers,
+ ARRAY_SIZE(mtk_vdec_drivers));
+}
+
+static void __exit mtk_vdec_exit(void)
+{
+ platform_unregister_drivers(mtk_vdec_drivers,
+ ARRAY_SIZE(mtk_vdec_drivers));
+}
+
+module_init(mtk_vdec_init);
+module_exit(mtk_vdec_exit);

MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("Mediatek video codec V4L2 decoder driver");
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
new file mode 100644
index 000000000000..5e1b7670ba5b
--- /dev/null
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c
@@ -0,0 +1,184 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Yunfei Dong <[email protected]>
+ */
+
+#include <linux/component.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.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"
+#include "mtk_vcodec_intr.h"
+#include "mtk_vcodec_util.h"
+
+static int mtk_vdec_comp_bind(struct device *dev, struct device *master,
+ void *data)
+{
+ struct mtk_vdec_comp_dev *comp_dev = dev_get_drvdata(dev);
+ struct mtk_vcodec_dev *master_dev = data;
+ int i;
+
+ for (i = 0; i < MTK_VDEC_HW_MAX; i++) {
+ if (dev->of_node != master_dev->component_node[i])
+ continue;
+
+ master_dev->comp_dev[i] = comp_dev;
+ comp_dev->comp_idx = i;
+ comp_dev->master_dev = master_dev;
+ break;
+ }
+
+ if (i == MTK_VDEC_HW_MAX) {
+ dev_err(dev, "Failed to get component node\n");
+ return -EINVAL;
+ }
+
+ comp_dev->reg_base[VDEC_COMP_SYS] =
+ master_dev->reg_base[VDEC_COMP_SYS];
+ return 0;
+}
+
+static void mtk_vdec_comp_unbind(struct device *dev, struct device *master,
+ void *data)
+{
+ struct mtk_vdec_comp_dev *comp_dev = dev_get_drvdata(dev);
+
+ comp_dev->reg_base[VDEC_COMP_SYS] = NULL;
+}
+
+static const struct component_ops mtk_vdec_hw_component_ops = {
+ .bind = mtk_vdec_comp_bind,
+ .unbind = mtk_vdec_comp_unbind,
+};
+
+static irqreturn_t mtk_vdec_comp_irq_handler(int irq, void *priv)
+{
+ struct mtk_vdec_comp_dev *dev = priv;
+ struct mtk_vcodec_ctx *ctx;
+ u32 cg_status;
+ unsigned int dec_done_status;
+ void __iomem *vdec_misc_addr = dev->reg_base[VDEC_COMP_MISC] +
+ VDEC_IRQ_CFG_REG;
+
+ ctx = mtk_vcodec_get_curr_ctx(dev->master_dev);
+
+ /* check if HW active or not */
+ cg_status = readl(dev->reg_base[VDEC_COMP_SYS]);
+ if ((cg_status & VDEC_HW_ACTIVE) != 0) {
+ mtk_v4l2_err("vdec active is not 0x0 (0x%08x)",
+ cg_status);
+ return IRQ_HANDLED;
+ }
+
+ dec_done_status = readl(vdec_misc_addr);
+ if ((dec_done_status & MTK_VDEC_IRQ_STATUS_DEC_SUCCESS) !=
+ MTK_VDEC_IRQ_STATUS_DEC_SUCCESS)
+ return IRQ_HANDLED;
+
+ /* clear interrupt */
+ 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);
+
+ mtk_v4l2_debug(3, "wake up ctx %d, dec_done_status=%x",
+ ctx->id, dec_done_status);
+
+ return IRQ_HANDLED;
+}
+
+static int mtk_vdec_comp_init_irq(struct mtk_vdec_comp_dev *dev)
+{
+ struct platform_device *pdev = dev->plat_dev;
+ int ret;
+
+ dev->dec_irq = platform_get_irq(pdev, 0);
+ if (dev->dec_irq < 0) {
+ dev_err(&pdev->dev, "Failed to get irq resource");
+ return dev->dec_irq;
+ }
+
+ irq_set_status_flags(dev->dec_irq, IRQ_NOAUTOEN);
+ ret = devm_request_irq(&pdev->dev, dev->dec_irq,
+ mtk_vdec_comp_irq_handler, 0, pdev->name, dev);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to install dev->dec_irq %d (%d)",
+ dev->dec_irq, ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int mtk_vdec_comp_probe(struct platform_device *pdev)
+{
+ struct mtk_vdec_comp_dev *dev;
+ int ret;
+
+ dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
+ if (!dev)
+ return -ENOMEM;
+
+ dev->plat_dev = pdev;
+ ret = mtk_vcodec_init_dec_pm(pdev, &dev->pm);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to get mt vcodec clock source");
+ return ret;
+ }
+
+ dev->reg_base[VDEC_COMP_MISC] =
+ devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR((__force void *)dev->reg_base[VDEC_COMP_MISC])) {
+ ret = PTR_ERR((__force void *)dev->reg_base[VDEC_COMP_MISC]);
+ goto err;
+ }
+
+ if (of_get_property(pdev->dev.of_node, "dma-ranges", NULL))
+ dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(34));
+
+ ret = mtk_vdec_comp_init_irq(dev);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to register irq handler.\n");
+ goto err;
+ }
+
+ platform_set_drvdata(pdev, dev);
+
+ ret = component_add(&pdev->dev, &mtk_vdec_hw_component_ops);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to add component: %d\n", ret);
+ goto err;
+ }
+
+ return 0;
+err:
+ mtk_vcodec_release_dec_pm(&dev->pm);
+ return ret;
+}
+
+static const struct of_device_id mtk_vdec_comp_ids[] = {
+ {
+ .compatible = "mediatek,mtk-vcodec-lat",
+ },
+ {
+ .compatible = "mediatek,mtk-vcodec-core",
+ },
+ {},
+};
+MODULE_DEVICE_TABLE(of, mtk_vdec_comp_ids);
+
+struct platform_driver mtk_vdec_comp_driver = {
+ .probe = mtk_vdec_comp_probe,
+ .driver = {
+ .name = "mtk-vdec-comp",
+ .of_match_table = mtk_vdec_comp_ids,
+ },
+};
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.h
new file mode 100644
index 000000000000..8d6e818a3474
--- /dev/null
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.h
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2021 MediaTek Inc.
+ * Author: Yunfei Dong <[email protected]>
+ */
+
+#ifndef _MTK_VCODEC_DEC_HW_H_
+#define _MTK_VCODEC_DEC_HW_H_
+
+#include <linux/io.h>
+#include <linux/platform_device.h>
+
+#include "mtk_vcodec_drv.h"
+
+#define VDEC_HW_ACTIVE 0x10
+#define VDEC_IRQ_CFG 0x11
+#define VDEC_IRQ_CLR 0x10
+#define VDEC_IRQ_CFG_REG 0xa4
+
+/**
+ * enum mtk_comp_hw_reg_idx - component register base index
+ */
+enum mtk_comp_hw_reg_idx {
+ VDEC_COMP_SYS,
+ VDEC_COMP_MISC,
+ VDEC_COMP_MAX
+};
+
+/**
+ * struct mtk_vdec_comp_dev - component framwork driver data
+ * @plat_dev: platform device
+ * @master_dev: master device
+ * @reg_base: Mapped address of MTK Vcodec registers.
+ *
+ * @dec_irq: decoder irq resource
+ * @pm: power management control
+ * @comp_idx: component index
+ */
+struct mtk_vdec_comp_dev {
+ struct platform_device *plat_dev;
+ struct mtk_vcodec_dev *master_dev;
+ void __iomem *reg_base[VDEC_COMP_MAX];
+
+ int dec_irq;
+ struct mtk_vcodec_pm pm;
+ int comp_idx;
+};
+
+#endif /* _MTK_VCODEC_DEC_HW_H_ */
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateful.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateful.c
index 59c24b22ab6d..4f9a80ce15d8 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateful.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateful.c
@@ -623,4 +623,5 @@ const struct mtk_vcodec_dec_pdata mtk_vdec_8173_pdata = {
.num_framesizes = NUM_SUPPORTED_FRAMESIZE,
.worker = mtk_vdec_worker,
.flush_decoder = mtk_vdec_flush_decoder,
+ .is_comp_supported = false,
};
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c
index 8f4a1f0a0769..762633572b49 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_stateless.c
@@ -357,4 +357,5 @@ const struct mtk_vcodec_dec_pdata mtk_vdec_8183_pdata = {
.uses_stateless_api = true,
.worker = mtk_vdec_worker,
.flush_decoder = mtk_vdec_flush_decoder,
+ .is_comp_supported = false,
};
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
index 973b0b3649c6..e530757a9b5a 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
@@ -93,6 +93,17 @@ enum mtk_fmt_type {
MTK_FMT_FRAME = 2,
};

+/**
+ * struct 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_HW_MAX,
+};
+
/*
* struct mtk_video_fmt - Structure used to store information about pixelformats
*/
@@ -331,6 +342,7 @@ enum mtk_chip {
*
* @chip: chip this decoder is compatible with
*
+ * @is_comp_supported: true: using compoent framework, false: not support
* @uses_stateless_api: whether the decoder uses the stateless API with requests
*/

@@ -352,6 +364,7 @@ struct mtk_vcodec_dec_pdata {

enum mtk_chip chip;

+ bool is_comp_supported;
bool uses_stateless_api;
};

@@ -422,6 +435,9 @@ struct mtk_vcodec_enc_pdata {
* @pm: power management control
* @dec_capability: used to identify decode capability, ex: 4k
* @enc_capability: used to identify encode capability
+ *
+ * @comp_dev: component hardware device
+ * @component_node: component node
*/
struct mtk_vcodec_dev {
struct v4l2_device v4l2_dev;
@@ -459,6 +475,9 @@ struct mtk_vcodec_dev {
struct mtk_vcodec_pm pm;
unsigned int dec_capability;
unsigned int enc_capability;
+
+ void *comp_dev[MTK_VDEC_HW_MAX];
+ struct device_node *component_node[MTK_VDEC_HW_MAX];
};

static inline struct mtk_vcodec_ctx *fh_to_ctx(struct v4l2_fh *fh)
--
2.25.1

2021-08-10 12:05:23

by Yunfei Dong

[permalink] [raw]
Subject: [PATCH v4, 14/15] media: mtk-vcodec: Add core dec and dec end ipi msg

Add core dec and dec end ipi msg: AP_IPIMSG_DEC_CORE/AP_IPIMSG_DEC_CORE_END.

Signed-off-by: Yunfei Dong <[email protected]>
---
v4: no change
---
.../media/platform/mtk-vcodec/vdec_ipi_msg.h | 4 ++++
.../media/platform/mtk-vcodec/vdec_vpu_if.c | 12 ++++++++++++
.../media/platform/mtk-vcodec/vdec_vpu_if.h | 18 ++++++++++++++++++
3 files changed, 34 insertions(+)

diff --git a/drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h b/drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h
index 5f45a537beb4..9d8079c4f976 100644
--- a/drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h
+++ b/drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h
@@ -18,12 +18,16 @@ enum vdec_ipi_msgid {
AP_IPIMSG_DEC_END = 0xA002,
AP_IPIMSG_DEC_DEINIT = 0xA003,
AP_IPIMSG_DEC_RESET = 0xA004,
+ AP_IPIMSG_DEC_CORE = 0xA005,
+ AP_IPIMSG_DEC_CORE_END = 0xA006,

VPU_IPIMSG_DEC_INIT_ACK = 0xB000,
VPU_IPIMSG_DEC_START_ACK = 0xB001,
VPU_IPIMSG_DEC_END_ACK = 0xB002,
VPU_IPIMSG_DEC_DEINIT_ACK = 0xB003,
VPU_IPIMSG_DEC_RESET_ACK = 0xB004,
+ VPU_IPIMSG_DEC_CORE_ACK = 0xB005,
+ VPU_IPIMSG_DEC_CORE_END_ACK = 0xB006,
};

/**
diff --git a/drivers/media/platform/mtk-vcodec/vdec_vpu_if.c b/drivers/media/platform/mtk-vcodec/vdec_vpu_if.c
index 5dffc459a33d..bfd8e87dceff 100644
--- a/drivers/media/platform/mtk-vcodec/vdec_vpu_if.c
+++ b/drivers/media/platform/mtk-vcodec/vdec_vpu_if.c
@@ -85,6 +85,8 @@ static void vpu_dec_ipi_handler(void *data, unsigned int len, void *priv)
case VPU_IPIMSG_DEC_END_ACK:
case VPU_IPIMSG_DEC_DEINIT_ACK:
case VPU_IPIMSG_DEC_RESET_ACK:
+ case VPU_IPIMSG_DEC_CORE_ACK:
+ case VPU_IPIMSG_DEC_CORE_END_ACK:
break;

default:
@@ -191,11 +193,21 @@ int vpu_dec_start(struct vdec_vpu_inst *vpu, uint32_t *data, unsigned int len)
return err;
}

+int vpu_dec_core(struct vdec_vpu_inst *vpu)
+{
+ return vcodec_send_ap_ipi(vpu, AP_IPIMSG_DEC_CORE);
+}
+
int vpu_dec_end(struct vdec_vpu_inst *vpu)
{
return vcodec_send_ap_ipi(vpu, AP_IPIMSG_DEC_END);
}

+int vpu_dec_core_end(struct vdec_vpu_inst *vpu)
+{
+ return vcodec_send_ap_ipi(vpu, AP_IPIMSG_DEC_CORE_END);
+}
+
int vpu_dec_deinit(struct vdec_vpu_inst *vpu)
{
return vcodec_send_ap_ipi(vpu, AP_IPIMSG_DEC_DEINIT);
diff --git a/drivers/media/platform/mtk-vcodec/vdec_vpu_if.h b/drivers/media/platform/mtk-vcodec/vdec_vpu_if.h
index c2ed5b6cab8b..ae24b75d1649 100644
--- a/drivers/media/platform/mtk-vcodec/vdec_vpu_if.h
+++ b/drivers/media/platform/mtk-vcodec/vdec_vpu_if.h
@@ -82,4 +82,22 @@ int vpu_dec_deinit(struct vdec_vpu_inst *vpu);
*/
int vpu_dec_reset(struct vdec_vpu_inst *vpu);

+/**
+ * vpu_dec_core - core start decoding, basically the function will be invoked once
+ * every frame.
+ *
+ * @vpu : instance for vdec_vpu_inst
+ */
+int vpu_dec_core(struct vdec_vpu_inst *vpu);
+
+/**
+ * vpu_dec_core_end - core end decoding, basically the function will be invoked once
+ * when core HW decoding done and receive interrupt successfully. The
+ * decoder in VPU will updata hardware information and deinit hardware
+ * and check if there is a new decoded frame available to display.
+ *
+ * @vpu : instance for vdec_vpu_inst
+ */
+int vpu_dec_core_end(struct vdec_vpu_inst *vpu);
+
#endif
--
2.25.1

2021-08-10 13:42:12

by Tzung-Bi Shih

[permalink] [raw]
Subject: Re: [PATCH v4, 04/15] media: mtk-vcodec: Use component framework to manage each hardware information

On Tue, Aug 10, 2021 at 04:30:36PM +0800, Yunfei Dong wrote:
> > Looking up "mediatek,mtk-vcodec-core" to determine if it uses component framwork sounds like...
> Add prameter in pdata, for all platform will use compoent after mt8183
>
> >> + if (dev->is_comp_supported) {
> >> + ret = mtk_vcodec_init_master(dev);
> >> + if (ret < 0)
> >> + goto err_component_match;
> >> + } else {
> >> + platform_set_drvdata(pdev, dev);
> >> + }
> > + Has asked the same question in [1]. Why it removes the
> > +platform_set_drvdata() above? mtk_vcodec_init_master() also calls platform_set_drvdata().
> Must call component_master_add_with_match after platform_set_drvdata for component architecture.
I am confused. The condition "call component_master_add_with_match
after platform_set_drvdata" is already true even if without the
change. See below.

> +static int mtk_vcodec_init_master(struct mtk_vcodec_dev *dev)
> +{
> + struct platform_device *pdev = dev->plat_dev;
> + struct component_match *match;
> + int ret;
> +
> + match = mtk_vcodec_match_add(dev);
> + if (IS_ERR_OR_NULL(match))
> + return -EINVAL;
> +
> + platform_set_drvdata(pdev, dev);
> + ret = component_master_add_with_match(&pdev->dev, &mtk_vdec_ops, match);
Point [1].

> @@ -311,7 +413,6 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> MTK_VCODEC_DEC_NAME);
> video_set_drvdata(vfd_dec, dev);
> dev->vfd_dec = vfd_dec;
> - platform_set_drvdata(pdev, dev);
Point [2].

> @@ -362,8 +463,16 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
> mtk_v4l2_debug(0, "decoder registered as /dev/video%d",
> vfd_dec->num);
>
> - return 0;
> + if (dev->vdec_pdata->is_comp_supported) {
> + ret = mtk_vcodec_init_master(dev);
Point [3].


The calling sequence is: [2] -> component_master_add_with_match() -> [1] -> [3].

Don't understand why it removes the platform_set_drvdata() at point [2].

2021-08-10 16:26:02

by Tzung-Bi Shih

[permalink] [raw]
Subject: Re: [PATCH v4, 00/15] Using component framework to support multi hardware decode

On Tue, Aug 10, 2021 at 04:30:32PM +0800, Yunfei Dong wrote:
> This patch dependents on "media: mtk-vcodec: support for MT8183 decoder"[1].
>
> Multi hardware decode is based on stateless decoder, MT8183 is the first time
> to add stateless decoder. Otherwise it will cause conflict. Please also accept
> this patch together with [1].
>
> [1]https://lore.kernel.org/patchwork/project/lkml/list/?series=507084
Didn't see anything from the link but I guess you mean the series
https://patchwork.linuxtv.org/project/linux-media/list/?series=6057


Some obvious issues from the series:
- Please remove all unneeded "Change-Id" tags.
- Please include Reviewed-by tags if no significant changes.
- E.g. https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
- E.g. https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/