From: kyrie wu <[email protected]>
This series is used to fix jpeg dec & enc crash in cuj test.
The problem was found frequently that executing CUJ
ui.EverydayMultiTaskingCUJ.*_ytmusic test cases on Tomato/Dojo
devices with the HW jpeg decoder enabled. Firstly the single core
and multi-core judgment methods were modified to make the driver
compatible with both cases. Secondly, the jpeg dec & enc worker
initialization method and the timing issue of remove buffer
were corrected, eliminating crash problems. Finally, some variables
and hw dev initialization methods are refactored to reduce code
redundancy and improve program robustness.
This series has been tested with MT8195 & MT8188.
Jpeg encoding and decoding worked for these devices.
Patch 1 fixes single core and multi-core judgment methods.
Patch 2 optimized jpeg single core initial methods.
Patch 3 optimized sw flow of jpeg enc&dec worker to remove buffer.
Patch 4 reconstructs the initialization mode of worker.
Patch 5 Remove some unnecessary variables.
Patch 6 refactor some variables.
Patch 7 refactor hw dev initializaiton sw flow.
kyrie wu (7):
media: mtk-jpeg: Fixes jpeghw multi-core judgement
media: mtk-jpeg: add jpeg single core initial function
media: mtk-jpeg: Fixes jpeg enc&dec worker sw flow
media: mtk-jpeg: reconstructs the initialization mode of worker
media: mtk-jpeg: Remove some unnecessary variables
media: mtk-jpeg: refactor some variables
media: mtk-jpeg: refactor hw dev initializaiton
.../platform/mediatek/jpeg/mtk_jpeg_core.c | 130 +++++++++++-------
.../platform/mediatek/jpeg/mtk_jpeg_core.h | 28 ++--
.../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 43 ++----
.../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 38 ++---
4 files changed, 113 insertions(+), 126 deletions(-)
--
2.18.0
From: kyrie wu <[email protected]>
add single core initial function to init reg_base,
irq and clk.
Signed-off-by: kyrie wu <[email protected]>
Signed-off-by: irui wang <[email protected]>
---
.../platform/mediatek/jpeg/mtk_jpeg_core.c | 74 +++++++++++--------
1 file changed, 44 insertions(+), 30 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index 6d052747a15e..daa4a6448311 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1671,10 +1671,50 @@ static void mtk_jpeg_job_timeout_work(struct work_struct *work)
v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
}
+static int mtk_jpeg_single_core_init(struct platform_device *pdev,
+ struct mtk_jpeg_dev *jpeg_dev)
+{
+ struct mtk_jpeg_dev *jpeg = jpeg_dev;
+ int jpeg_irq, ret;
+
+ INIT_DELAYED_WORK(&jpeg->job_timeout_work,
+ mtk_jpeg_job_timeout_work);
+
+ jpeg->reg_base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(jpeg->reg_base)) {
+ ret = PTR_ERR(jpeg->reg_base);
+ return ret;
+ }
+
+ jpeg_irq = platform_get_irq(pdev, 0);
+ if (jpeg_irq < 0)
+ return jpeg_irq;
+
+ ret = devm_request_irq(&pdev->dev,
+ jpeg_irq,
+ jpeg->variant->irq_handler,
+ 0,
+ pdev->name, jpeg);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to request jpeg_irq %d (%d)\n",
+ jpeg_irq, ret);
+ return ret;
+ }
+
+ ret = devm_clk_bulk_get(jpeg->dev,
+ jpeg->variant->num_clks,
+ jpeg->variant->clks);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to init clk\n");
+ return ret;
+ }
+
+ return 0;
+}
+
static int mtk_jpeg_probe(struct platform_device *pdev)
{
struct mtk_jpeg_dev *jpeg;
- int jpeg_irq;
int ret;
jpeg = devm_kzalloc(&pdev->dev, sizeof(*jpeg), GFP_KERNEL);
@@ -1693,36 +1733,10 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
}
if (!jpeg->variant->multi_core) {
- INIT_DELAYED_WORK(&jpeg->job_timeout_work,
- mtk_jpeg_job_timeout_work);
-
- jpeg->reg_base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(jpeg->reg_base)) {
- ret = PTR_ERR(jpeg->reg_base);
- return ret;
- }
-
- jpeg_irq = platform_get_irq(pdev, 0);
- if (jpeg_irq < 0)
- return jpeg_irq;
-
- ret = devm_request_irq(&pdev->dev,
- jpeg_irq,
- jpeg->variant->irq_handler,
- 0,
- pdev->name, jpeg);
- if (ret) {
- dev_err(&pdev->dev, "Failed to request jpeg_irq %d (%d)\n",
- jpeg_irq, ret);
- return ret;
- }
-
- ret = devm_clk_bulk_get(jpeg->dev,
- jpeg->variant->num_clks,
- jpeg->variant->clks);
+ ret = mtk_jpeg_single_core_init(pdev, jpeg);
if (ret) {
- dev_err(&pdev->dev, "Failed to init clk\n");
- return ret;
+ v4l2_err(&jpeg->v4l2_dev, "mtk_jpeg_single_core_init failed.");
+ return -EINVAL;
}
}
--
2.18.0
From: kyrie wu <[email protected]>
some chips have multi-hw, but others have only one,
modify the condition of multi-hw judgement
Fixes: 934e8bccac95 ("mtk-jpegenc: support jpegenc multi-hardware")
Signed-off-by: kyrie wu <[email protected]>
Signed-off-by: irui wang <[email protected]>
Reviewed-by: AngeloGioacchino Del Regno <[email protected]>
---
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 5 ++++-
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h | 2 ++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index 969516a940ba..6d052747a15e 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1692,7 +1692,7 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
return -EINVAL;
}
- if (list_empty(&pdev->dev.devres_head)) {
+ if (!jpeg->variant->multi_core) {
INIT_DELAYED_WORK(&jpeg->job_timeout_work,
mtk_jpeg_job_timeout_work);
@@ -1874,6 +1874,7 @@ static const struct mtk_jpeg_variant mtk_jpeg_drvdata = {
.ioctl_ops = &mtk_jpeg_enc_ioctl_ops,
.out_q_default_fourcc = V4L2_PIX_FMT_YUYV,
.cap_q_default_fourcc = V4L2_PIX_FMT_JPEG,
+ .multi_core = false,
};
static struct mtk_jpeg_variant mtk8195_jpegenc_drvdata = {
@@ -1885,6 +1886,7 @@ static struct mtk_jpeg_variant mtk8195_jpegenc_drvdata = {
.ioctl_ops = &mtk_jpeg_enc_ioctl_ops,
.out_q_default_fourcc = V4L2_PIX_FMT_YUYV,
.cap_q_default_fourcc = V4L2_PIX_FMT_JPEG,
+ .multi_core = true,
};
static const struct mtk_jpeg_variant mtk8195_jpegdec_drvdata = {
@@ -1896,6 +1898,7 @@ static const struct mtk_jpeg_variant mtk8195_jpegdec_drvdata = {
.ioctl_ops = &mtk_jpeg_dec_ioctl_ops,
.out_q_default_fourcc = V4L2_PIX_FMT_JPEG,
.cap_q_default_fourcc = V4L2_PIX_FMT_YUV420M,
+ .multi_core = true,
};
#if defined(CONFIG_OF)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
index b9126476be8f..f87358cc9f47 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
@@ -60,6 +60,7 @@ enum mtk_jpeg_ctx_state {
* @ioctl_ops: the callback of jpeg v4l2_ioctl_ops
* @out_q_default_fourcc: output queue default fourcc
* @cap_q_default_fourcc: capture queue default fourcc
+ * @multi_core: mark jpeg hw is multi_core or not
*/
struct mtk_jpeg_variant {
struct clk_bulk_data *clks;
@@ -74,6 +75,7 @@ struct mtk_jpeg_variant {
const struct v4l2_ioctl_ops *ioctl_ops;
u32 out_q_default_fourcc;
u32 cap_q_default_fourcc;
+ bool multi_core;
};
struct mtk_jpeg_src_buf {
--
2.18.0
From: kyrie wu <[email protected]>
exclude is_jpgenc_multihw or is_jpgdec_multihw for judgment,
and re-initialize jpeg worker.
Signed-off-by: kyrie wu <[email protected]>
Signed-off-by: irui wang <[email protected]>
---
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 9 +++------
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h | 2 ++
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index d940dc5ede74..e89195f1989c 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1575,12 +1575,7 @@ static int mtk_jpeg_open(struct file *file)
goto free;
}
- if (jpeg->is_jpgenc_multihw)
- INIT_WORK(&ctx->jpeg_work, mtk_jpegenc_worker);
-
- if (jpeg->is_jpgdec_multihw)
- INIT_WORK(&ctx->jpeg_work, mtk_jpegdec_worker);
-
+ INIT_WORK(&ctx->jpeg_work, jpeg->variant->jpeg_worker);
INIT_LIST_HEAD(&ctx->dst_done_queue);
spin_lock_init(&ctx->done_queue_lock);
v4l2_fh_init(&ctx->fh, vfd);
@@ -1901,6 +1896,7 @@ static struct mtk_jpeg_variant mtk8195_jpegenc_drvdata = {
.out_q_default_fourcc = V4L2_PIX_FMT_YUYV,
.cap_q_default_fourcc = V4L2_PIX_FMT_JPEG,
.multi_core = true,
+ .jpeg_worker = mtk_jpegenc_worker,
};
static const struct mtk_jpeg_variant mtk8195_jpegdec_drvdata = {
@@ -1913,6 +1909,7 @@ static const struct mtk_jpeg_variant mtk8195_jpegdec_drvdata = {
.out_q_default_fourcc = V4L2_PIX_FMT_JPEG,
.cap_q_default_fourcc = V4L2_PIX_FMT_YUV420M,
.multi_core = true,
+ .jpeg_worker = mtk_jpegdec_worker,
};
#if defined(CONFIG_OF)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
index f87358cc9f47..e118a0175f75 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
@@ -61,6 +61,7 @@ enum mtk_jpeg_ctx_state {
* @out_q_default_fourcc: output queue default fourcc
* @cap_q_default_fourcc: capture queue default fourcc
* @multi_core: mark jpeg hw is multi_core or not
+ * @jpeg_worker: jpeg dec or enc worker
*/
struct mtk_jpeg_variant {
struct clk_bulk_data *clks;
@@ -76,6 +77,7 @@ struct mtk_jpeg_variant {
u32 out_q_default_fourcc;
u32 cap_q_default_fourcc;
bool multi_core;
+ void (*jpeg_worker)(struct work_struct *work);
};
struct mtk_jpeg_src_buf {
--
2.18.0
From: kyrie wu <[email protected]>
1. Move removing buffer after sw setting and before hw setting
in enc&dec worker to prevents the operation of removing
the buffer twice if the sw setting fails.
2. Remove the redundant operation of queue work in the
jpegenc irq handler because the jpegenc worker has called
v4l2_m2m_job_finish to do it.
Fixes: 5fb1c2361e56 ("mtk-jpegenc: add jpeg encode worker interface")
Fixes: dedc21500334 ("media: mtk-jpegdec: add jpeg decode worker interface")
Signed-off-by: kyrie wu <[email protected]>
Signed-off-by: irui wang <[email protected]>
---
.../media/platform/mediatek/jpeg/mtk_jpeg_core.c | 14 +++++++-------
.../media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 4 ----
2 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index daa4a6448311..d940dc5ede74 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1025,9 +1025,6 @@ static void mtk_jpegenc_worker(struct work_struct *work)
if (!dst_buf)
goto getbuf_fail;
- v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
- v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
-
v4l2_m2m_buf_copy_metadata(src_buf, dst_buf, true);
mtk_jpegenc_set_hw_param(ctx, hw_id, src_buf, dst_buf);
@@ -1045,6 +1042,9 @@ static void mtk_jpegenc_worker(struct work_struct *work)
goto enc_end;
}
+ v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
+ v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
+
schedule_delayed_work(&comp_jpeg[hw_id]->job_timeout_work,
msecs_to_jiffies(MTK_JPEG_HW_TIMEOUT_MSEC));
@@ -1220,9 +1220,6 @@ static void mtk_jpegdec_worker(struct work_struct *work)
if (!dst_buf)
goto getbuf_fail;
- v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
- v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
-
v4l2_m2m_buf_copy_metadata(src_buf, dst_buf, true);
jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf);
jpeg_dst_buf = mtk_jpeg_vb2_to_srcbuf(&dst_buf->vb2_buf);
@@ -1231,7 +1228,7 @@ static void mtk_jpegdec_worker(struct work_struct *work)
&jpeg_src_buf->dec_param)) {
mtk_jpeg_queue_src_chg_event(ctx);
ctx->state = MTK_JPEG_SOURCE_CHANGE;
- goto dec_end;
+ goto getbuf_fail;
}
jpeg_src_buf->curr_ctx = ctx;
@@ -1254,6 +1251,9 @@ static void mtk_jpegdec_worker(struct work_struct *work)
goto clk_end;
}
+ v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
+ v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
+
schedule_delayed_work(&comp_jpeg[hw_id]->job_timeout_work,
msecs_to_jiffies(MTK_JPEG_HW_TIMEOUT_MSEC));
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
index 1bbb712d78d0..867f4c1a09fa 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
@@ -286,10 +286,6 @@ static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv)
mtk_jpegenc_put_buf(jpeg);
pm_runtime_put(ctx->jpeg->dev);
clk_disable_unprepare(jpeg->venc_clk.clks->clk);
- if (!list_empty(&ctx->fh.m2m_ctx->out_q_ctx.rdy_queue) ||
- !list_empty(&ctx->fh.m2m_ctx->cap_q_ctx.rdy_queue)) {
- queue_work(master_jpeg->workqueue, &ctx->jpeg_work);
- }
jpeg->hw_state = MTK_JPEG_HW_IDLE;
wake_up(&master_jpeg->enc_hw_wq);
--
2.18.0
From: kyrie wu <[email protected]>
Add a atomic_t variable for initialization of hw dev.
Signed-off-by: kyrie wu <[email protected]>
Signed-off-by: irui wang <[email protected]>
---
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 1 +
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h | 2 ++
.../media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 12 ++++--------
.../media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 12 ++++--------
4 files changed, 11 insertions(+), 16 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index ab06c1ee80d4..1dd03938df7e 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1742,6 +1742,7 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
num_child++;
atomic_set(&jpeg->hw_rdy, num_child);
+ atomic_set(&jpeg->hw_index, 0);
jpeg->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME,
WQ_MEM_RECLAIM
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
index 89242e407dc9..8ba6e757e11a 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
@@ -208,6 +208,7 @@ struct mtk_jpegdec_comp_dev {
* @hw_rdy: jpg hw ready flag
* @reg_decbase: jpg decode register base addr
* @dec_hw_dev: jpg decode hardware device
+ * @hw_index: jpg hw index
*/
struct mtk_jpeg_dev {
struct mutex lock;
@@ -229,6 +230,7 @@ struct mtk_jpeg_dev {
void __iomem *reg_decbase[MTK_JPEGDEC_HW_MAX];
struct mtk_jpegdec_comp_dev *dec_hw_dev[MTK_JPEGDEC_HW_MAX];
+ atomic_t hw_index;
};
/**
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
index b7c2de2489b0..869068fac5e2 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
@@ -638,14 +638,10 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, ret,
"Failed to register JPEGDEC irq handler.\n");
- for (i = 0; i < MTK_JPEGDEC_HW_MAX; i++) {
- if (master_dev->dec_hw_dev[i])
- continue;
-
- master_dev->dec_hw_dev[i] = dev;
- master_dev->reg_decbase[i] = dev->reg_base;
- dev->master_dev = master_dev;
- }
+ i = atomic_add_return(1, &master_dev->hw_index) - 1;
+ master_dev->dec_hw_dev[i] = dev;
+ master_dev->reg_decbase[i] = dev->reg_base;
+ dev->master_dev = master_dev;
platform_set_drvdata(pdev, dev);
pm_runtime_enable(&pdev->dev);
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
index e35ee1bdce3d..71e85b4bbf12 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
@@ -362,14 +362,10 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev)
if (ret)
return ret;
- for (i = 0; i < MTK_JPEGENC_HW_MAX; i++) {
- if (master_dev->enc_hw_dev[i])
- continue;
-
- master_dev->enc_hw_dev[i] = dev;
- master_dev->reg_encbase[i] = dev->reg_base;
- dev->master_dev = master_dev;
- }
+ i = atomic_add_return(1, &master_dev->hw_index) - 1;
+ master_dev->enc_hw_dev[i] = dev;
+ master_dev->reg_encbase[i] = dev->reg_base;
+ dev->master_dev = master_dev;
platform_set_drvdata(pdev, dev);
pm_runtime_enable(&pdev->dev);
--
2.18.0
From: kyrie wu <[email protected]>
remove is_jpgenc_multihw, is_jpgdec_multihw,
and unnecessary initialization.
Signed-off-by: kyrie wu <[email protected]>
Signed-off-by: irui wang <[email protected]>
---
.../platform/mediatek/jpeg/mtk_jpeg_core.h | 4 ---
.../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 29 ++++++++-----------
.../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 18 ++++--------
3 files changed, 18 insertions(+), 33 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
index e118a0175f75..83cf35a12b7a 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
@@ -204,12 +204,10 @@ struct mtk_jpegdec_comp_dev {
* @variant: driver variant to be used
* @reg_encbase: jpg encode register base addr
* @enc_hw_dev: jpg encode hardware device
- * @is_jpgenc_multihw: the flag of multi-hw core
* @enc_hw_wq: jpg encode wait queue
* @enchw_rdy: jpg encode hw ready flag
* @reg_decbase: jpg decode register base addr
* @dec_hw_dev: jpg decode hardware device
- * @is_jpgdec_multihw: the flag of dec multi-hw core
* @dec_hw_wq: jpg decode wait queue
* @dec_workqueue: jpg decode work queue
* @dechw_rdy: jpg decode hw ready flag
@@ -229,13 +227,11 @@ struct mtk_jpeg_dev {
void __iomem *reg_encbase[MTK_JPEGENC_HW_MAX];
struct mtk_jpegenc_comp_dev *enc_hw_dev[MTK_JPEGENC_HW_MAX];
- bool is_jpgenc_multihw;
wait_queue_head_t enc_hw_wq;
atomic_t enchw_rdy;
void __iomem *reg_decbase[MTK_JPEGDEC_HW_MAX];
struct mtk_jpegdec_comp_dev *dec_hw_dev[MTK_JPEGDEC_HW_MAX];
- bool is_jpgdec_multihw;
wait_queue_head_t dec_hw_wq;
struct workqueue_struct *dec_workqueue;
atomic_t dechw_rdy;
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
index 8c07fa02fd9a..5b47bd83c5ce 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
@@ -608,23 +608,18 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev)
dev->plat_dev = pdev;
dev->dev = &pdev->dev;
- if (!master_dev->is_jpgdec_multihw) {
- master_dev->is_jpgdec_multihw = true;
- for (i = 0; i < MTK_JPEGDEC_HW_MAX; i++)
- master_dev->dec_hw_dev[i] = NULL;
-
- init_waitqueue_head(&master_dev->dec_hw_wq);
- master_dev->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME,
- WQ_MEM_RECLAIM
- | WQ_FREEZABLE);
- if (!master_dev->workqueue)
- return -EINVAL;
-
- ret = devm_add_action_or_reset(&pdev->dev, mtk_jpegdec_destroy_workqueue,
- master_dev->workqueue);
- if (ret)
- return ret;
- }
+ init_waitqueue_head(&master_dev->dec_hw_wq);
+ master_dev->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME,
+ WQ_MEM_RECLAIM
+ | WQ_FREEZABLE);
+ if (!master_dev->workqueue)
+ return -EINVAL;
+
+ ret = devm_add_action_or_reset(&pdev->dev,
+ mtk_jpegdec_destroy_workqueue,
+ master_dev->workqueue);
+ if (ret)
+ return ret;
atomic_set(&master_dev->dechw_rdy, MTK_JPEGDEC_HW_MAX);
spin_lock_init(&dev->hw_lock);
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
index 867f4c1a09fa..c2bc0b531b32 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
@@ -340,18 +340,12 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev)
dev->plat_dev = pdev;
dev->dev = &pdev->dev;
- if (!master_dev->is_jpgenc_multihw) {
- master_dev->is_jpgenc_multihw = true;
- for (i = 0; i < MTK_JPEGENC_HW_MAX; i++)
- master_dev->enc_hw_dev[i] = NULL;
-
- init_waitqueue_head(&master_dev->enc_hw_wq);
- master_dev->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME,
- WQ_MEM_RECLAIM
- | WQ_FREEZABLE);
- if (!master_dev->workqueue)
- return -EINVAL;
- }
+ init_waitqueue_head(&master_dev->enc_hw_wq);
+ master_dev->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME,
+ WQ_MEM_RECLAIM
+ | WQ_FREEZABLE);
+ if (!master_dev->workqueue)
+ return -EINVAL;
atomic_set(&master_dev->enchw_rdy, MTK_JPEGENC_HW_MAX);
spin_lock_init(&dev->hw_lock);
--
2.18.0
From: kyrie wu <[email protected]>
Refactor some variables to reduce redundancy
and optimize the initialization process.
Signed-off-by: kyrie wu <[email protected]>
Signed-off-by: irui wang <[email protected]>
---
.../platform/mediatek/jpeg/mtk_jpeg_core.c | 31 ++++++++++++++-----
.../platform/mediatek/jpeg/mtk_jpeg_core.h | 18 ++++-------
.../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 16 +++-------
.../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 16 +++-------
4 files changed, 37 insertions(+), 44 deletions(-)
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index e89195f1989c..ab06c1ee80d4 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1004,8 +1004,8 @@ static void mtk_jpegenc_worker(struct work_struct *work)
retry_select:
hw_id = mtk_jpegenc_get_hw(ctx);
if (hw_id < 0) {
- ret = wait_event_interruptible(jpeg->enc_hw_wq,
- atomic_read(&jpeg->enchw_rdy) > 0);
+ ret = wait_event_interruptible(jpeg->hw_wq,
+ atomic_read(&jpeg->hw_rdy) > 0);
if (ret != 0 || (i++ > MTK_JPEG_MAX_RETRY_TIME)) {
dev_err(jpeg->dev, "%s : %d, all HW are busy\n",
__func__, __LINE__);
@@ -1016,7 +1016,7 @@ static void mtk_jpegenc_worker(struct work_struct *work)
goto retry_select;
}
- atomic_dec(&jpeg->enchw_rdy);
+ atomic_dec(&jpeg->hw_rdy);
src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
if (!src_buf)
goto getbuf_fail;
@@ -1073,7 +1073,7 @@ static void mtk_jpegenc_worker(struct work_struct *work)
v4l2_m2m_buf_done(src_buf, buf_state);
v4l2_m2m_buf_done(dst_buf, buf_state);
getbuf_fail:
- atomic_inc(&jpeg->enchw_rdy);
+ atomic_inc(&jpeg->hw_rdy);
mtk_jpegenc_put_hw(jpeg, hw_id);
v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
}
@@ -1198,8 +1198,8 @@ static void mtk_jpegdec_worker(struct work_struct *work)
retry_select:
hw_id = mtk_jpegdec_get_hw(ctx);
if (hw_id < 0) {
- ret = wait_event_interruptible_timeout(jpeg->dec_hw_wq,
- atomic_read(&jpeg->dechw_rdy) > 0,
+ ret = wait_event_interruptible_timeout(jpeg->hw_wq,
+ atomic_read(&jpeg->hw_rdy) > 0,
MTK_JPEG_HW_TIMEOUT_MSEC);
if (ret != 0 || (i++ > MTK_JPEG_MAX_RETRY_TIME)) {
dev_err(jpeg->dev, "%s : %d, all HW are busy\n",
@@ -1211,7 +1211,7 @@ static void mtk_jpegdec_worker(struct work_struct *work)
goto retry_select;
}
- atomic_dec(&jpeg->dechw_rdy);
+ atomic_dec(&jpeg->hw_rdy);
src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
if (!src_buf)
goto getbuf_fail;
@@ -1290,7 +1290,7 @@ static void mtk_jpegdec_worker(struct work_struct *work)
v4l2_m2m_buf_done(src_buf, buf_state);
v4l2_m2m_buf_done(dst_buf, buf_state);
getbuf_fail:
- atomic_inc(&jpeg->dechw_rdy);
+ atomic_inc(&jpeg->hw_rdy);
mtk_jpegdec_put_hw(jpeg, hw_id);
v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
}
@@ -1710,6 +1710,8 @@ static int mtk_jpeg_single_core_init(struct platform_device *pdev,
static int mtk_jpeg_probe(struct platform_device *pdev)
{
struct mtk_jpeg_dev *jpeg;
+ struct device_node *child;
+ int num_child = 0;
int ret;
jpeg = devm_kzalloc(&pdev->dev, sizeof(*jpeg), GFP_KERNEL);
@@ -1733,6 +1735,19 @@ static int mtk_jpeg_probe(struct platform_device *pdev)
v4l2_err(&jpeg->v4l2_dev, "mtk_jpeg_single_core_init failed.");
return -EINVAL;
}
+ } else {
+ init_waitqueue_head(&jpeg->hw_wq);
+
+ for_each_child_of_node(pdev->dev.of_node, child)
+ num_child++;
+
+ atomic_set(&jpeg->hw_rdy, num_child);
+
+ jpeg->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME,
+ WQ_MEM_RECLAIM
+ | WQ_FREEZABLE);
+ if (!jpeg->workqueue)
+ return -EINVAL;
}
ret = v4l2_device_register(&pdev->dev, &jpeg->v4l2_dev);
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
index 83cf35a12b7a..89242e407dc9 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
@@ -203,14 +203,11 @@ struct mtk_jpegdec_comp_dev {
* @job_timeout_work: IRQ timeout structure
* @variant: driver variant to be used
* @reg_encbase: jpg encode register base addr
- * @enc_hw_dev: jpg encode hardware device
- * @enc_hw_wq: jpg encode wait queue
- * @enchw_rdy: jpg encode hw ready flag
+ * @enc_hw_dev: jpg encode hardware device
+ * @hw_wq: jpg wait queue
+ * @hw_rdy: jpg hw ready flag
* @reg_decbase: jpg decode register base addr
- * @dec_hw_dev: jpg decode hardware device
- * @dec_hw_wq: jpg decode wait queue
- * @dec_workqueue: jpg decode work queue
- * @dechw_rdy: jpg decode hw ready flag
+ * @dec_hw_dev: jpg decode hardware device
*/
struct mtk_jpeg_dev {
struct mutex lock;
@@ -227,14 +224,11 @@ struct mtk_jpeg_dev {
void __iomem *reg_encbase[MTK_JPEGENC_HW_MAX];
struct mtk_jpegenc_comp_dev *enc_hw_dev[MTK_JPEGENC_HW_MAX];
- wait_queue_head_t enc_hw_wq;
- atomic_t enchw_rdy;
+ wait_queue_head_t hw_wq;
+ atomic_t hw_rdy;
void __iomem *reg_decbase[MTK_JPEGDEC_HW_MAX];
struct mtk_jpegdec_comp_dev *dec_hw_dev[MTK_JPEGDEC_HW_MAX];
- wait_queue_head_t dec_hw_wq;
- struct workqueue_struct *dec_workqueue;
- atomic_t dechw_rdy;
};
/**
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
index 5b47bd83c5ce..b7c2de2489b0 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
@@ -503,8 +503,8 @@ static void mtk_jpegdec_timeout_work(struct work_struct *work)
clk_disable_unprepare(cjpeg->jdec_clk.clks->clk);
pm_runtime_put(cjpeg->dev);
cjpeg->hw_state = MTK_JPEG_HW_IDLE;
- atomic_inc(&master_jpeg->dechw_rdy);
- wake_up(&master_jpeg->dec_hw_wq);
+ atomic_inc(&master_jpeg->hw_rdy);
+ wake_up(&master_jpeg->hw_wq);
v4l2_m2m_buf_done(src_buf, buf_state);
mtk_jpegdec_put_buf(cjpeg);
}
@@ -551,8 +551,8 @@ static irqreturn_t mtk_jpegdec_hw_irq_handler(int irq, void *priv)
clk_disable_unprepare(jpeg->jdec_clk.clks->clk);
jpeg->hw_state = MTK_JPEG_HW_IDLE;
- wake_up(&master_jpeg->dec_hw_wq);
- atomic_inc(&master_jpeg->dechw_rdy);
+ wake_up(&master_jpeg->hw_wq);
+ atomic_inc(&master_jpeg->hw_rdy);
return IRQ_HANDLED;
}
@@ -608,20 +608,12 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev)
dev->plat_dev = pdev;
dev->dev = &pdev->dev;
- init_waitqueue_head(&master_dev->dec_hw_wq);
- master_dev->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME,
- WQ_MEM_RECLAIM
- | WQ_FREEZABLE);
- if (!master_dev->workqueue)
- return -EINVAL;
-
ret = devm_add_action_or_reset(&pdev->dev,
mtk_jpegdec_destroy_workqueue,
master_dev->workqueue);
if (ret)
return ret;
- atomic_set(&master_dev->dechw_rdy, MTK_JPEGDEC_HW_MAX);
spin_lock_init(&dev->hw_lock);
dev->hw_state = MTK_JPEG_HW_IDLE;
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
index c2bc0b531b32..e35ee1bdce3d 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c
@@ -248,8 +248,8 @@ static void mtk_jpegenc_timeout_work(struct work_struct *work)
clk_disable_unprepare(cjpeg->venc_clk.clks->clk);
pm_runtime_put(cjpeg->dev);
cjpeg->hw_state = MTK_JPEG_HW_IDLE;
- atomic_inc(&master_jpeg->enchw_rdy);
- wake_up(&master_jpeg->enc_hw_wq);
+ atomic_inc(&master_jpeg->hw_rdy);
+ wake_up(&master_jpeg->hw_wq);
v4l2_m2m_buf_done(src_buf, buf_state);
mtk_jpegenc_put_buf(cjpeg);
}
@@ -288,8 +288,8 @@ static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv)
clk_disable_unprepare(jpeg->venc_clk.clks->clk);
jpeg->hw_state = MTK_JPEG_HW_IDLE;
- wake_up(&master_jpeg->enc_hw_wq);
- atomic_inc(&master_jpeg->enchw_rdy);
+ wake_up(&master_jpeg->hw_wq);
+ atomic_inc(&master_jpeg->hw_rdy);
return IRQ_HANDLED;
}
@@ -340,14 +340,6 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev)
dev->plat_dev = pdev;
dev->dev = &pdev->dev;
- init_waitqueue_head(&master_dev->enc_hw_wq);
- master_dev->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME,
- WQ_MEM_RECLAIM
- | WQ_FREEZABLE);
- if (!master_dev->workqueue)
- return -EINVAL;
-
- atomic_set(&master_dev->enchw_rdy, MTK_JPEGENC_HW_MAX);
spin_lock_init(&dev->hw_lock);
dev->hw_state = MTK_JPEG_HW_IDLE;
--
2.18.0