Enable jpeg enc & dec multi-hardwares for MT8196
Subsystems (4)
v13 cover Enable jpeg enc & dec multi-hardwares for MT8196
This series have the follow changing:
Firstly fix some bugs, including resolution change handleing, stop streaming sw flow, fix buffer layout and clock setting to support multi-hw jpeg working and others.
Secondly add mt8196 jpegdec and jpegenc compatible to support MT8196 kernel driver.
Lastly, Add smmu setting to support smmu and iommu at the same time.
This series has been tested with MT8196 tast test. Encoding and decoding worked for this chip.
Patches 1 fix jpeg hw count setting to support different chips. Patches 2 fix jpeg buffer payload setting to handle buffer size bug while resolution changed.
Patches 3 fix jpeg dst buffer layout.
Patches 4 fix multi-core stop streaming flow
Patches 5 fix multi-core clk suspend/resume setting Patches 6 fix decoding buffer number setting timing issue Patches 7 fix decoding resolution change operation Patches 8 fix remove buffer operation
Patches 9-11 Adds jpeg encoder and decoder compatible. Patches 12 add jpeg smmu sid setting.
---
Changes compared with v12:
--Rebased on top of the latest media tree
--fix kernel rebot build warnings in patch 5
Changes compared with v11:
--Rebased on top of the latest media tree --Some modifications for patch v11's review comments. --add reviewer to commit messages
Changes compared with v10:
--Rebased on top of the latest media tree
--add reviewer to commit messages
Changes compared with v9:
--Rebased on top of the latest media tree
Changes compared with v8:
--Rebased on top of the latest media tree
Changes compared with v7:
--Rebased on top of the latest media tree
Changes compared with v6:
--Rebased on top of the latest media tree
Changes compared with v5:
--reorder the patches set.
--fix commit message of patch 1-8.
Changes compared with v4:
--fix kernel robot build errors for patch 4.
--add reviewer for patch 1 and patch 2.
Changes compared with v3:
--change patch subject of jpeg encoder and decoder compatible.
Changes compared with v2:
--refactor smmu sid setting function interface --Some modifications for patch v2's review comments.
Changes compared with v1:
--refine jpeg dt-bindings for MT8196 --optimize software code to manage jpeg HW count --refactor smmu sid setting function interface --Some modifications for patch v1's review comments.
Kyrie Wu (12):
media: mediatek: jpeg: fix jpeg cores' amounts setting
media: mediatek: jpeg: fix jpeg buffer payload size setting
media: mediatek: jpeg: fix buffer structure size and layout
media: mediatek: jpeg: Fix buffer completion on multi-core streaming
stop
media: mediatek: jpeg: Fix multi-core clk suspend and resume setting
media: mediatek: jpeg: fix decoding buffer number setting timing issue
media: mediatek: jpeg: fix resolution change event handling in decoder
media: mediatek: jpeg: fix remove buffer removal timing for multi-core
media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec
compatible
media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgenc
compatible
media: mediatek: jpeg: add jpeg compatible
media: mediatek: jpeg: add jpeg smmu sid setting
.../media/mediatek,mt8195-jpegdec.yaml | 8 +- .../media/mediatek,mt8195-jpegenc.yaml | 8 +- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 151 +++++++++++++----- .../platform/mediatek/jpeg/mtk_jpeg_core.h | 19 ++- .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 90 ++++++++++- .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 88 +++++++++- 6 files changed, 308 insertions(+), 56 deletions(-)
Signature · 1 line
2.45.2
PATCH v13 1/12 media: mediatek: jpeg: fix jpeg cores' amounts setting
Different ICs have different amounts of cores,
use a variable to set the cores' amounts.
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 8 ++++---- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h | 2 ++ drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 1 + drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 1 + 4 files changed, 8 insertions(+), 4 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +4 -4
@@ -1460,7 +1460,7 @@ static int mtk_jpegenc_get_hw(struct mtk_jpeg_ctx *ctx)int i;spin_lock_irqsave (&jpeg->hw_lock, flags); -for (i =0 ; i <MTK_JPEGENC_HW_MAX ; i++) { +for (i =0 ; i < jpeg->max_hw_count; i++) { comp_jpeg = jpeg->enc_hw_dev[i];if (comp_jpeg->hw_state ==MTK_JPEG_HW_IDLE ) { hw_id = i;
@@ -1507,7 +1507,7 @@ static int mtk_jpegdec_get_hw(struct mtk_jpeg_ctx *ctx)int i;spin_lock_irqsave (&jpeg->hw_lock, flags); -for (i =0 ; i <MTK_JPEGDEC_HW_MAX ; i++) { +for (i =0 ; i < jpeg->max_hw_count; i++) { comp_jpeg = jpeg->dec_hw_dev[i];if (comp_jpeg->hw_state ==MTK_JPEG_HW_IDLE ) { hw_id = i;
@@ -1590,7 +1590,7 @@ static void mtk_jpegenc_worker(struct work_struct *work) jpeg_work);struct mtk_jpeg_dev *jpeg = ctx->jpeg; -for (i =0 ; i <MTK_JPEGENC_HW_MAX ; i++) +for (i =0 ; i < jpeg->max_hw_count; i++) comp_jpeg[i] = jpeg->enc_hw_dev[i]; i =0 ;
@@ -1685,7 +1685,7 @@ static void mtk_jpegdec_worker(struct work_struct *work)struct mtk_jpeg_fb fb;unsigned long flags; -for (i =0 ; i <MTK_JPEGDEC_HW_MAX ; i++) +for (i =0 ; i < jpeg->max_hw_count; i++) comp_jpeg[i] = jpeg->dec_hw_dev[i]; i =0 ;
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +2 -0
@@ -212,6 +212,7 @@ struct mtk_jpegdec_comp_dev {* @reg_decbase: jpg decode register base addr * @dec_hw_dev: jpg decode hardware device * @hw_index: jpg hw index +* @max_hw_count: jpeg hw-core count */ struct mtk_jpeg_dev {struct mutex lock;
@@ -234,6 +235,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; +u32 max_hw_count; };/**
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +1 -0
@@ -664,6 +664,7 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev) master_dev->dec_hw_dev[i] = dev; master_dev->reg_decbase[i] = dev->reg_base; dev->master_dev = master_dev; + master_dev->max_hw_count++;platform_set_drvdata (pdev, dev);pm_runtime_enable (&pdev->dev);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +1 -0
@@ -386,6 +386,7 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev) master_dev->enc_hw_dev[i] = dev; master_dev->reg_encbase[i] = dev->reg_base; dev->master_dev = master_dev; + master_dev->max_hw_count++;platform_set_drvdata (pdev, dev);pm_runtime_enable (&pdev->dev);
Signature · 1 line
2.45.2
PATCH v13 2/12 media: mediatek: jpeg: fix jpeg buffer payload size setting
In reply to Kyrie WuFor multi-core jpegdec, if one core gets resolution change event, the payload size, representing the size of Y/C data, needs to change. But others are decoding at the same time and it can not be changed immediately, which results in the payload size to not match the real buffer length.
The payload size must less than the real buffer length to remove the warnning logs.
--- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +14 -5
@@ -702,6 +702,7 @@ static int mtk_jpeg_buf_prepare(struct vb2_buffer *vb)struct mtk_jpeg_ctx *ctx =vb2_get_drv_priv (vb->vb2_queue);struct mtk_jpeg_q_data *q_data =NULL ;struct v4l2_plane_pix_format plane_fmt = {}; +size_t max_size;int i; q_data =mtk_jpeg_get_q_data (ctx, vb->vb2_queue->type);
@@ -710,12 +711,20 @@ static int mtk_jpeg_buf_prepare(struct vb2_buffer *vb)for (i =0 ; i < q_data->fmt->colplanes; i++) { plane_fmt = q_data->pix_mp.plane_fmt[i]; + max_size = plane_fmt.sizeimage; +if (ctx->enable_exif && - q_data->fmt->fourcc ==V4L2_PIX_FMT_JPEG ) -vb2_set_plane_payload (vb, i, plane_fmt.sizeimage + -MTK_JPEG_MAX_EXIF_SIZE ); -else -vb2_set_plane_payload (vb, i, plane_fmt.sizeimage); + q_data->fmt->fourcc ==V4L2_PIX_FMT_JPEG ) { + max_size +=MTK_JPEG_MAX_EXIF_SIZE ; + +vb2_set_plane_payload (vb, i, +MIN (vb->planes[i].length, + max_size)); + }else { +vb2_set_plane_payload (vb, i, +MIN (plane_fmt.sizeimage, + vb->planes[i].length)); + } }return 0 ;
Signature · 1 line
2.45.2
PATCH v13 3/12 media: mediatek: jpeg: fix buffer structure size and layout
In reply to Kyrie WuUpdates the buf_struct_size in the JPEG driver to use the correct structure mtk_jpeg_src_buf instead of v4l2_m2m_buffer, ensuring proper handling of source buffers. The previous buffer size led to mismatches and potential issues during video buffer handling.
Moves frame_num in the mtk_jpeg_src_buf structure to align with other members appropriately. The first field of the driver-specific buffer structure must be the subsystem-specificstruct (vb2_v4l2_buffer in the case of V4L2).
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 2 +- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +1 -1
@@ -1092,7 +1092,7 @@ static int mtk_jpeg_queue_init(void *priv, struct vb2_queue *src_vq, dst_vq->type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ; dst_vq->io_modes =VB2_DMABUF |VB2_MMAP ; dst_vq->drv_priv = ctx; - dst_vq->buf_struct_size =sizeof (struct v4l2_m2m_buffer ); + dst_vq->buf_struct_size =sizeof (struct mtk_jpeg_src_buf ); dst_vq->ops = jpeg->variant->qops; dst_vq->mem_ops = &vb2_dma_contig_memops; dst_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ;
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +1 -1
@@ -85,10 +85,10 @@ struct mtk_jpeg_variant { };struct mtk_jpeg_src_buf { -u32 frame_num;struct vb2_v4l2_buffer b;struct list_head list;u32 bs_size; +u32 frame_num;struct mtk_jpeg_dec_param dec_param;struct mtk_jpeg_ctx *curr_ctx;
Signature · 1 line
2.45.2
PATCH v13 4/12 media: mediatek: jpeg: Fix buffer completion on multi-core streaming stop
In reply to Kyrie WuEnhances the Mediatek JPEG driver's stability and reliability by ensuring that all queued buffers are processed before stopping the streaming in multi-core environments. It introduces a call to vb2_wait_for_all_buffers() in the mtk_jpeg_enc_stop_streaming() and mtk_jpeg_dec_stop_streaming() functions when the multi_core variant is enabled. This change ensures that no buffers are left unprocessed, preventing potential data loss or corruption during multi-core flow.
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +8 -0
@@ -850,8 +850,12 @@ static struct vb2_v4l2_buffer *mtk_jpeg_buf_remove(struct mtk_jpeg_ctx *ctx,static void mtk_jpeg_enc_stop_streaming (struct vb2_queue *q) {struct mtk_jpeg_ctx *ctx =vb2_get_drv_priv (q); +struct mtk_jpeg_dev *jpeg = ctx->jpeg;struct vb2_v4l2_buffer *vb; +if (jpeg->variant->multi_core) +vb2_wait_for_all_buffers (q); +while ((vb =mtk_jpeg_buf_remove (ctx, q->type)))v4l2_m2m_buf_done (vb,VB2_BUF_STATE_ERROR ); }
@@ -859,6 +863,7 @@ static void mtk_jpeg_enc_stop_streaming(struct vb2_queue *q)static void mtk_jpeg_dec_stop_streaming (struct vb2_queue *q) {struct mtk_jpeg_ctx *ctx =vb2_get_drv_priv (q); +struct mtk_jpeg_dev *jpeg = ctx->jpeg;struct vb2_v4l2_buffer *vb;/*
@@ -866,6 +871,9 @@ static void mtk_jpeg_dec_stop_streaming(struct vb2_queue *q)* Before STREAMOFF, we still have to return the old resolution and * subsampling. Update capture queue when the stream is off. */ +if (jpeg->variant->multi_core) +vb2_wait_for_all_buffers (q); +if (ctx->state ==MTK_JPEG_SOURCE_CHANGE &&V4L2_TYPE_IS_CAPTURE (q->type)) {struct mtk_jpeg_src_buf *src_buf;
Signature · 1 line
2.45.2
PATCH v13 5/12 media: mediatek: jpeg: Fix multi-core clk suspend and resume setting
In reply to Kyrie WuThe suspend/resume callback function is defined in the dev_pm_ops structure, which is defined in platform_driver. For multiple-core architecture, each hardware driver will register a platform_driver structure, so it is necessary to add a suspend/resume callback function for each hardware to support this operation.
--- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 28 +++------ .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 62 +++++++++++++++++-- .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 60 ++++++++++++++++-- 3 files changed, 121 insertions(+), 29 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +9 -19
@@ -1115,6 +1115,9 @@ static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg) {int ret; +if (jpeg->variant->multi_core) +return ; + ret =clk_bulk_prepare_enable (jpeg->variant->num_clks, jpeg->variant->clks);if (ret)
@@ -1123,6 +1126,9 @@ static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg)static void mtk_jpeg_clk_off (struct mtk_jpeg_dev *jpeg) { +if (jpeg->variant->multi_core) +return ; +clk_bulk_disable_unprepare (jpeg->variant->num_clks, jpeg->variant->clks); }
@@ -1645,13 +1651,6 @@ static void mtk_jpegenc_worker(struct work_struct *work) goto enc_end; } - ret =clk_prepare_enable (comp_jpeg[hw_id]->venc_clk.clks->clk); -if (ret) { -dev_err (jpeg->dev,"%s : %d, jpegenc clk_prepare_enable fail\n" , - __func__, __LINE__); - goto enc_end; - } -v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx);v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx);
@@ -1748,20 +1747,13 @@ static void mtk_jpegdec_worker(struct work_struct *work) jpeg_dst_buf->frame_num = ctx->total_frame_num;mtk_jpegdec_set_hw_param (ctx, hw_id, src_buf, dst_buf); - ret =pm_runtime_get_sync (comp_jpeg[hw_id]->dev); + ret =pm_runtime_resume_and_get (comp_jpeg[hw_id]->dev);if (ret <0 ) {dev_err (jpeg->dev,"%s : %d, pm_runtime_get_sync fail !!!\n" , __func__, __LINE__); goto dec_end; } - ret =clk_prepare_enable (comp_jpeg[hw_id]->jdec_clk.clks->clk); -if (ret) { -dev_err (jpeg->dev,"%s : %d, jpegdec clk_prepare_enable fail\n" , - __func__, __LINE__); - goto clk_end; - } -v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx);v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx);
@@ -1771,7 +1763,7 @@ static void mtk_jpegdec_worker(struct work_struct *work) &dst_buf->vb2_buf, &fb)) {dev_err (jpeg->dev,"%s : %d, mtk_jpeg_set_dec_dst fail\n" , __func__, __LINE__); - goto setdst_end; + goto set_dst_fail; } schedule_delayed_work(&comp_jpeg[hw_id]->job_timeout_work,
@@ -1792,9 +1784,7 @@ static void mtk_jpegdec_worker(struct work_struct *work)return ; -setdst_end: -clk_disable_unprepare (comp_jpeg[hw_id]->jdec_clk.clks->clk); -clk_end: +set_dst_fail:pm_runtime_put (comp_jpeg[hw_id]->dev); dec_end:v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +56 -6
110 lines not on this page · raw message
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +56 -4
96 lines not on this page · raw message
Signature · 1 line
2.45.2
PATCH v13 6/12 media: mediatek: jpeg: fix decoding buffer number setting timing issue
In reply to Kyrie WuThe src buffer doesn't need set information and dst buf parameters only need to set when the power set succussed and protect the setting by spinlock ensuring that any later operations acting on this buffer reflect accurate state and frame data.
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 9 +++------ drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 1 + drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 1 + 3 files changed, 5 insertions(+), 6 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +3 -6
@@ -1732,7 +1732,6 @@ static void mtk_jpegdec_worker(struct work_struct *work)v4l2_m2m_buf_copy_metadata (src_buf, dst_buf); jpeg_src_buf =mtk_jpeg_vb2_to_srcbuf (&src_buf->vb2_buf); - jpeg_dst_buf =mtk_jpeg_vb2_to_srcbuf (&dst_buf->vb2_buf);if (mtk_jpeg_check_resolution_change (ctx, &jpeg_src_buf->dec_param)) {
@@ -1741,11 +1740,6 @@ static void mtk_jpegdec_worker(struct work_struct *work) goto getbuf_fail; } - jpeg_src_buf->curr_ctx = ctx; - jpeg_src_buf->frame_num = ctx->total_frame_num; - jpeg_dst_buf->curr_ctx = ctx; - jpeg_dst_buf->frame_num = ctx->total_frame_num; -mtk_jpegdec_set_hw_param (ctx, hw_id, src_buf, dst_buf); ret =pm_runtime_resume_and_get (comp_jpeg[hw_id]->dev);if (ret <0 ) {
@@ -1770,6 +1764,9 @@ static void mtk_jpegdec_worker(struct work_struct *work) msecs_to_jiffies(MTK_JPEG_HW_TIMEOUT_MSEC));spin_lock_irqsave (&comp_jpeg[hw_id]->hw_lock, flags); + jpeg_dst_buf =mtk_jpeg_vb2_to_srcbuf (&dst_buf->vb2_buf); + jpeg_dst_buf->curr_ctx = ctx; + jpeg_dst_buf->frame_num = ctx->total_frame_num; ctx->total_frame_num++;mtk_jpeg_dec_reset (comp_jpeg[hw_id]->reg_base); mtk_jpeg_dec_set_config(comp_jpeg[hw_id]->reg_base,
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +1 -0
@@ -513,6 +513,7 @@ static void mtk_jpegdec_put_buf(struct mtk_jpegdec_comp_dev *jpeg)v4l2_m2m_buf_done (&tmp_dst_done_buf->b,VB2_BUF_STATE_DONE ); ctx->last_done_frame_num++; +break ; } } }
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +1 -0
@@ -242,6 +242,7 @@ static void mtk_jpegenc_put_buf(struct mtk_jpegenc_comp_dev *jpeg)v4l2_m2m_buf_done (&tmp_dst_done_buf->b,VB2_BUF_STATE_DONE ); ctx->last_done_frame_num++; +break ; } } }
Signature · 1 line
2.45.2
PATCH v13 7/12 media: mediatek: jpeg: fix resolution change event handling in decoder
In reply to Kyrie WuThis patch refines the handling of resolution change events within JPEG decoder worker. The mtk_jpeg_set_queue_data function is now called to set up queue data before signaling a source change through mtk_jpeg_queue_src_chg_event. By reorganizing these calls, the patch ensures that necessary queue information is updated prior to transitioning the context state to MTK_JPEG_SOURCE_CHANGE. A condition is added to exit early if the context is already in the MTK_JPEG_SOURCE_CHANGE state, preventing redundant operations and improving processing efficiency.
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +5 -1
@@ -1735,11 +1735,15 @@ static void mtk_jpegdec_worker(struct work_struct *work)if (mtk_jpeg_check_resolution_change (ctx, &jpeg_src_buf->dec_param)) { -mtk_jpeg_queue_src_chg_event (ctx); +mtk_jpeg_set_queue_data (ctx, &jpeg_src_buf->dec_param); ctx->state =MTK_JPEG_SOURCE_CHANGE ; +mtk_jpeg_queue_src_chg_event (ctx); goto getbuf_fail; } +if (ctx->state ==MTK_JPEG_SOURCE_CHANGE ) + goto getbuf_fail; +mtk_jpegdec_set_hw_param (ctx, hw_id, src_buf, dst_buf); ret =pm_runtime_resume_and_get (comp_jpeg[hw_id]->dev);if (ret <0 ) {
Signature · 1 line
2.45.2
PATCH v13 8/12 media: mediatek: jpeg: fix remove buffer removal timing for multi-core
In reply to Kyrie WuMove calls to v4l2_m2m_src/dst_buf_remove() inside of the spinlock protected scope to ensure all necessary operations are performed before buffers are removed from their queues and ensure proper synchronization of buffer handling to avoid buffer lost.
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +4 -6
@@ -1651,9 +1651,6 @@ 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 ));
@@ -1671,6 +1668,8 @@ static void mtk_jpegenc_worker(struct work_struct *work) &src_buf->vb2_buf);mtk_jpeg_set_enc_params (ctx, comp_jpeg[hw_id]->reg_base);mtk_jpeg_enc_start (comp_jpeg[hw_id]->reg_base); +v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx);v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx);spin_unlock_irqrestore (&comp_jpeg[hw_id]->hw_lock, flags);
@@ -1752,9 +1751,6 @@ static void mtk_jpegdec_worker(struct work_struct *work) goto dec_end; } -v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); -v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); -mtk_jpeg_set_dec_src (ctx, &src_buf->vb2_buf, &bs); if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param,
@@ -1779,6 +1775,8 @@ static void mtk_jpegdec_worker(struct work_struct *work) jpeg_src_buf->bs_size, &bs, &fb); +v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx);mtk_jpeg_dec_start (comp_jpeg[hw_id]->reg_base);v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx);spin_unlock_irqrestore (&comp_jpeg[hw_id]->hw_lock, flags);
Signature · 1 line
2.45.2
PATCH v13 9/12 media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible
In reply to Kyrie WuCompared to the previous generation IC, the MT8196 uses SMMU instead of IOMMU and supports features such as dynamic voltage and frequency scaling. Therefore, add "mediatek,mt8196-jpgdec" compatible to the binding document.
--- .../bindings/media/mediatek,mt8195-jpegdec.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml +6 -2
@@ -14,7 +14,9 @@ description: properties: compatible: - const: mediatek,mt8195-jpgdec + enum: + - mediatek,mt8195-jpgdec + - mediatek,mt8196-jpgdec power-domains: maxItems: 1
@@ -44,7 +46,9 @@ patternProperties: properties: compatible: - const: mediatek,mt8195-jpgdec-hw + enum: + - mediatek,mt8195-jpgdec-hw + - mediatek,mt8196-jpgdec-hw reg: maxItems: 1
Signature · 1 line
2.45.2
PATCH v13 10/12 media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgenc compatible
In reply to Kyrie WuCompared to the previous generation IC, the MT8196 uses SMMU instead of IOMMU and supports features such as dynamic voltage and frequency scaling. Therefore, add "mediatek,mt8196-jpgenc" compatible to the binding document.
--- .../bindings/media/mediatek,mt8195-jpegenc.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/media/mediatek,mt8195-jpegenc.yaml +6 -2
@@ -14,7 +14,9 @@ description: properties: compatible: - const: mediatek,mt8195-jpgenc + enum: + - mediatek,mt8195-jpgenc + - mediatek,mt8196-jpgenc power-domains: maxItems: 1
@@ -44,7 +46,9 @@ patternProperties: properties: compatible: - const: mediatek,mt8195-jpgenc-hw + enum: + - mediatek,mt8195-jpgenc-hw + - mediatek,mt8196-jpgenc-hw reg: maxItems: 1
Signature · 1 line
2.45.2
PATCH v13 11/12 media: mediatek: jpeg: add jpeg compatible
In reply to Kyrie WuAdd jpeg dec and enc compatible for mt8196
--- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 34 +++++++++++++++++++ .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 3 ++ .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 3 ++ 3 files changed, 40 insertions(+)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +34 -0
@@ -1916,6 +1916,19 @@ static struct mtk_jpeg_variant mtk8195_jpegenc_drvdata = { .jpeg_worker = mtk_jpegenc_worker, }; +static struct mtk_jpeg_variant mtk8196_jpegenc_drvdata = { + .formats = mtk_jpeg_enc_formats, + .num_formats =MTK_JPEG_ENC_NUM_FORMATS , + .qops = &mtk_jpeg_enc_qops, + .m2m_ops = &mtk_jpeg_multicore_enc_m2m_ops, + .dev_name ="mtk-jpeg-enc" , + .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, + .jpeg_worker = mtk_jpegenc_worker, +}; +static const struct mtk_jpeg_variant mtk8195_jpegdec_drvdata = { .formats = mtk_jpeg_dec_formats, .num_formats =MTK_JPEG_DEC_NUM_FORMATS ,
@@ -1929,6 +1942,19 @@ static const struct mtk_jpeg_variant mtk8195_jpegdec_drvdata = { .jpeg_worker = mtk_jpegdec_worker, }; +static const struct mtk_jpeg_variant mtk8196_jpegdec_drvdata = { + .formats = mtk_jpeg_dec_formats, + .num_formats =MTK_JPEG_DEC_NUM_FORMATS , + .qops = &mtk_jpeg_dec_qops, + .m2m_ops = &mtk_jpeg_multicore_dec_m2m_ops, + .dev_name ="mtk-jpeg-dec" , + .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, + .jpeg_worker = mtk_jpegdec_worker, +}; +static const struct of_device_id mtk_jpeg_match[] = { { .compatible ="mediatek,mt8173-jpgdec" ,
@@ -1950,6 +1976,14 @@ static const struct of_device_id mtk_jpeg_match[] = { .compatible = "mediatek,mt8195-jpgdec", .data = &mtk8195_jpegdec_drvdata, }, + { + .compatible = "mediatek,mt8196-jpgenc", + .data = &mtk8196_jpegenc_drvdata, + }, + { + .compatible = "mediatek,mt8196-jpgdec", + .data = &mtk8196_jpegdec_drvdata, + }, {}, };
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +3 -0
@@ -45,6 +45,9 @@ static const struct of_device_id mtk_jpegdec_hw_ids[] = { { .compatible = "mediatek,mt8195-jpgdec-hw", }, + { + .compatible = "mediatek,mt8196-jpgdec-hw", + }, {}, };MODULE_DEVICE_TABLE (of, mtk_jpegdec_hw_ids);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +3 -0
@@ -52,6 +52,9 @@ static const struct of_device_id mtk_jpegenc_drv_ids[] = { { .compatible = "mediatek,mt8195-jpgenc-hw", }, + { + .compatible = "mediatek,mt8196-jpgenc-hw", + }, {}, };MODULE_DEVICE_TABLE (of, mtk_jpegenc_drv_ids);
Signature · 1 line
2.45.2
PATCH v13 12/12 media: mediatek: jpeg: add jpeg smmu sid setting
In reply to Kyrie WuAdd a configuration to set jpeg dec & enc smmu sid
--- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 29 +++++++++++++++++++ .../platform/mediatek/jpeg/mtk_jpeg_core.h | 15 ++++++++++ .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 23 +++++++++++++++ .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 23 +++++++++++++++ 4 files changed, 90 insertions(+)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +29 -0
@@ -15,6 +15,7 @@#include <linux/of_platform.h> #include <linux/platform_device.h> #include <linux/pm_runtime.h> +#include <linux/regmap.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <media/v4l2-event.h>
@@ -1599,6 +1600,22 @@ static irqreturn_t mtk_jpeg_enc_done(struct mtk_jpeg_dev *jpeg)return IRQ_HANDLED ; } +static void mtk_jpeg_set_smmu_sid (struct regmap *smmu_regmap,unsigned int sid) +{ +if (sid ==JPG_REG_GUSER_ID_DEC_SID ) +regmap_update_bits (smmu_regmap,JPEG_DEC_SMMU_SID , +JPG_REG_GUSER_ID_MASK << +JPG_REG_DEC_GUSER_ID_SHIFT , +JPG_REG_GUSER_ID_DEC_SID << +JPG_REG_DEC_GUSER_ID_SHIFT ); +else +regmap_update_bits (smmu_regmap,JPEG_ENC_SMMU_SID , +JPG_REG_GUSER_ID_MASK << +JPG_REG_ENC_GUSER_ID_SHIFT , +JPG_REG_GUSER_ID_ENC_SID << +JPG_REG_ENC_GUSER_ID_SHIFT ); +} +static void mtk_jpegenc_worker (struct work_struct *work) {struct mtk_jpegenc_comp_dev *comp_jpeg[MTK_JPEGENC_HW_MAX ];
@@ -1660,6 +1677,11 @@ static void mtk_jpegenc_worker(struct work_struct *work) jpeg_dst_buf->frame_num = ctx->total_frame_num; ctx->total_frame_num++;mtk_jpeg_enc_reset (comp_jpeg[hw_id]->reg_base); + +if (jpeg->variant->support_smmu && comp_jpeg[hw_id]->smmu_regmap) +mtk_jpeg_set_smmu_sid (comp_jpeg[hw_id]->smmu_regmap, +JPG_REG_GUSER_ID_ENC_SID ); +mtk_jpeg_set_enc_dst (ctx, comp_jpeg[hw_id]->reg_base, &dst_buf->vb2_buf);
@@ -1769,6 +1791,11 @@ static void mtk_jpegdec_worker(struct work_struct *work) jpeg_dst_buf->frame_num = ctx->total_frame_num; ctx->total_frame_num++;mtk_jpeg_dec_reset (comp_jpeg[hw_id]->reg_base); + +if (jpeg->variant->support_smmu && comp_jpeg[hw_id]->smmu_regmap) +mtk_jpeg_set_smmu_sid (comp_jpeg[hw_id]->smmu_regmap, +JPG_REG_GUSER_ID_DEC_SID ); + mtk_jpeg_dec_set_config(comp_jpeg[hw_id]->reg_base, jpeg->variant->support_34bit, &jpeg_src_buf->dec_param,
@@ -1927,6 +1954,7 @@ static struct mtk_jpeg_variant mtk8196_jpegenc_drvdata = { .cap_q_default_fourcc = V4L2_PIX_FMT_JPEG, .multi_core = true, .jpeg_worker = mtk_jpegenc_worker, + .support_smmu = true, };static const struct mtk_jpeg_variant mtk8195_jpegdec_drvdata = {
@@ -1953,6 +1981,7 @@ static const struct mtk_jpeg_variant mtk8196_jpegdec_drvdata = { .cap_q_default_fourcc = V4L2_PIX_FMT_YUV420M, .multi_core = true, .jpeg_worker = mtk_jpegdec_worker, + .support_smmu = true, };static const struct of_device_id mtk_jpeg_match[] = {
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +15 -0
@@ -11,6 +11,7 @@#include <linux/clk.h> #include <linux/interrupt.h> +#include <linux/mfd/syscon.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <media/v4l2-fh.h>
@@ -34,6 +35,14 @@#define MTK_JPEG_MAX_EXIF_SIZE (64 * 1024) +#define JPEG_DEC_SMMU_SID 0 +#define JPEG_ENC_SMMU_SID 0 +#define JPG_REG_GUSER_ID_MASK 0x7 +#define JPG_REG_GUSER_ID_DEC_SID 0x4 +#define JPG_REG_GUSER_ID_ENC_SID 0x5 +#define JPG_REG_DEC_GUSER_ID_SHIFT 8 +#define JPG_REG_ENC_GUSER_ID_SHIFT 4 +#define MTK_JPEG_ADDR_MASK GENMASK(1, 0)/**
@@ -65,6 +74,7 @@ enum mtk_jpeg_ctx_state {* @multi_core: mark jpeg hw is multi_core or not * @jpeg_worker: jpeg dec or enc worker * @support_34bit: flag to check support for 34-bit DMA address +* @support_smmu: flag to check if support smmu */ struct mtk_jpeg_variant {struct clk_bulk_data *clks;
@@ -82,6 +92,7 @@ struct mtk_jpeg_variant {bool multi_core;void (*jpeg_worker)(struct work_struct *work);bool support_34bit; +bool support_smmu; };struct mtk_jpeg_src_buf {
@@ -150,6 +161,7 @@ struct mtk_jpegdec_clk {* @hw_param: jpeg encode hw parameters * @hw_state: record hw state * @hw_lock: spinlock protecting the hw device resource +* @smmu_regmap: SMMU registers mapping */ struct mtk_jpegenc_comp_dev {struct device *dev;
@@ -163,6 +175,7 @@ struct mtk_jpegenc_comp_dev {enum mtk_jpeg_hw_state hw_state;/* spinlock protecting the hw device resource */ spinlock_t hw_lock; +struct regmap *smmu_regmap; };/**
@@ -177,6 +190,7 @@ struct mtk_jpegenc_comp_dev {* @hw_param: jpeg decode hw parameters * @hw_state: record hw state * @hw_lock: spinlock protecting hw +* @smmu_regmap: SMMU registers mapping */ struct mtk_jpegdec_comp_dev {struct device *dev;
@@ -190,6 +204,7 @@ struct mtk_jpegdec_comp_dev {enum mtk_jpeg_hw_state hw_state;/* spinlock protecting the hw device resource */ spinlock_t hw_lock; +struct regmap *smmu_regmap; };/**
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +23 -0
@@ -613,6 +613,25 @@ static int mtk_jpegdec_hw_init_irq(struct mtk_jpegdec_comp_dev *dev)return 0 ; } +static int mtk_jpegdec_smmu_init (struct mtk_jpegdec_comp_dev *dev) +{ +struct mtk_jpeg_dev *master_dev = dev->master_dev; + +if (!master_dev->variant->support_smmu) +return 0 ; + + dev->smmu_regmap = +syscon_regmap_lookup_by_phandle (dev->plat_dev->dev.of_node, +"mediatek,smmu-config" ); +if (IS_ERR (dev->smmu_regmap)) { +return dev_err_probe (dev->dev,PTR_ERR (dev->smmu_regmap), +"mmap smmu_base failed(%ld)\n" , +PTR_ERR (dev->smmu_regmap)); + } + +return 0 ; +} +static int mtk_jpegdec_hw_probe (struct platform_device *pdev) {struct mtk_jpegdec_clk *jpegdec_clk;
@@ -666,6 +685,10 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev) dev->master_dev = master_dev; master_dev->max_hw_count++; + ret =mtk_jpegdec_smmu_init (dev); +if (ret) +return ret; +platform_set_drvdata (pdev, dev);pm_runtime_enable (&pdev->dev); ret = devm_clk_bulk_get(dev->dev,
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +23 -0
@@ -339,6 +339,25 @@ static int mtk_jpegenc_hw_init_irq(struct mtk_jpegenc_comp_dev *dev)return 0 ; } +static int mtk_jpegenc_smmu_init (struct mtk_jpegenc_comp_dev *dev) +{ +struct mtk_jpeg_dev *master_dev = dev->master_dev; + +if (!master_dev->variant->support_smmu) +return 0 ; + + dev->smmu_regmap = +syscon_regmap_lookup_by_phandle (dev->plat_dev->dev.of_node, +"mediatek,smmu-config" ); +if (IS_ERR (dev->smmu_regmap)) { +return dev_err_probe (dev->dev,PTR_ERR (dev->smmu_regmap), +"mmap smmu_base failed(%ld)\n" , +PTR_ERR (dev->smmu_regmap)); + } + +return 0 ; +} +static int mtk_jpegenc_hw_probe (struct platform_device *pdev) {struct mtk_jpegenc_clk *jpegenc_clk;
@@ -390,6 +409,10 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev) dev->master_dev = master_dev; master_dev->max_hw_count++; + ret =mtk_jpegenc_smmu_init (dev); +if (ret) +return ret; +platform_set_drvdata (pdev, dev);pm_runtime_enable (&pdev->dev); ret = devm_clk_bulk_get(dev->dev,
Signature · 1 line
2.45.2