media: mtk-jpeg: refactor some variables

Refactor some variables to reduce redundancy
and optimize the initialization process.

Signed-off-by: kyrie wu <kyrie.wu@mediatek.com>
Signed-off-by: irui wang <irui.wang@mediatek.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
This commit is contained in:
kyrie wu 2023-03-10 06:23:54 +00:00 committed by Mauro Carvalho Chehab
parent 6a7a883f02
commit 09aea13ecf
4 changed files with 37 additions and 44 deletions

View File

@ -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 @@ retry_select:
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 @@ enc_end:
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 @@ retry_select:
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 @@ dec_end:
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);

View File

@ -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;
};
/**

View File

@ -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;

View File

@ -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;