Enable jpeg enc & dec multi-hardwares for MT8196
Subsystems (4)
v2 cover Enable jpeg enc & dec multi-hardwares for MT8196
This series adds support for mt8196 multi-hardwares jpeg enc & dec, by first adding mt8196 jpegdec and jpegenc compatible to install kernel driver. Add smmu setting to support smmu and iommu at the same time.
Secondly refactor buffer and clock setting to support multi-hw jpeg working.
Lastly, fix some bugs, including resolution change handleing, stop streaming sw flow and others.
This series has been tested with MT8196 tast test. Encoding and decoding worked for this chip.
Patches 1-3 Adds jpeg encoder and decoder compatible. Patches 4 add jpeg smmu sid setting.
Patches 5 fix jpeg hw count setting to support different chips. Patches 6 refactor jpeg buffer payload setting to handle buffer size bug while resolution changed.
Patches 7 reconstruct jpeg dst buffer layout.
Patches 8 fix multi-core stop streaming flow
Patches 9 refactor multi-core clk suspend/resume setting Patches 10 fix decoding buffer number setting timing issue Patches 11 refactor decoding resolution change operation Patches 12 fix remove buffer operation
---
This series patches dependent on:
[1]
https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
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):
dt-bindings: mediatek: Add mediatek, mt8196-jpgdec compatible
dt-bindings: mediatek: Add mediatek, mt8196-jpgenc compatible
media: mediatek: jpeg: add jpeg compatible
media: mediatek: jpeg: add jpeg smmu sid setting
media: mediatek: jpeg: fix jpeg hw count setting
media: mediatek: jpeg: refactor jpeg buffer payload setting
media: mediatek: jpeg: refactor jpeg dst buffer layout
media: mediatek: jpeg: fix stop streaming flow for multi-core
media: mediatek: jpeg: refactor multi-core clk suspend and resume
setting
media: mediatek: jpeg: fix decoding buffer number setting timing issue
media: mediatek: jpeg: refactor decoding resolution change operation
media: mediatek: jpeg: fix remove buffer operation for multi-core
.../media/mediatek,mt8195-jpegdec.yaml | 8 +- .../media/mediatek,mt8195-jpegenc.yaml | 8 +- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 166 +++++++++++++----- .../platform/mediatek/jpeg/mtk_jpeg_core.h | 25 ++- .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 113 +++++++++++- .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 114 +++++++++++- 6 files changed, 381 insertions(+), 53 deletions(-)
Signature · 1 line
2.46.0
PATCH v2 1/12 dt-bindings: mediatek: Add mediatek, mt8196-jpgdec compatible
Add mediatek,mt8196-jpgdec compatible to 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.46.0
Re: [PATCH v2 01/12] dt-bindings: mediatek: Add mediatek, mt8196-jpgdec compatible
Quoted 3 lines · kyrie.wu
Add mediatek,mt8196-jpgdec compatible to binding document.
Signed-off-by kyrie.wu <[email protected]>
Usual mediatek comment - looks like copy paste of username. Please reach to your colleagues how to fix it.
Quoted 9 lines
--- .../bindings/media/mediatek,mt8195-jpegdec.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml +0
-0
Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml description: · line 19
Quoted 7 lines
Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml +3
-1@@ -14,7 +14,9 @@ description: properties: compatible: - const: mediatek,mt8195-jpgdec + enum: + - mediatek,mt8195-jpgdec + - mediatek,mt8196-jpgdec
And devices are not compatible?
Best regards,
Krzysztof
Re: [PATCH v2 01/12] dt-bindings: mediatek: Add mediatek, mt8196-jpgdec compatible
Quoted 4 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 8 lines
Quoted 3 lines · kyrie.wu
Add mediatek,mt8196-jpgdec compatible to binding document.
Signed-off-by kyrie.wu <[email protected]>Usual mediatek comment - looks like copy paste of username. Please reach
to your colleagues how to fix it.
Dear Krzysztof,
Do I need to change the username like that: Kyrie Wu < [email protected]>?
Thanks.
Quoted 18 lines
Quoted 18 lines
--- .../bindings/media/mediatek,mt8195-jpegdec.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)diff --git a/Documentation/devicetree/bindings/media/mediatek,mt8195-
jpegdec.yamlb/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
indexe5448c60e3eb..28a9a9bfdbf8100644
--- a/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
+++ b/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml(quoted diff) +0
-0@@ -14,7 +14,9 @@ description:
Quoted 8 lines
Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml description: · line 19
Quoted 6 lines
Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml +3
-1properties: compatible: - const: mediatek,mt8195-jpgdec + enum: + - mediatek,mt8195-jpgdec + - mediatek,mt8196-jpgdecAnd devices are not compatible?
Sorry, I don't understand the question exactly. Do you mean using the compatible string of MT8195 for both MT8195 and MT8196?
Thanks.
Quoted 4 lines
Best regards,
Krzysztof
Regards,
Kyrie
Re: [PATCH v2 01/12] dt-bindings: mediatek: Add mediatek, mt8196-jpgdec compatible
Quoted 10 lines · Kyrie Wu (吴晗)
Quoted 9 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 3 lines · kyrie.wu
Add mediatek,mt8196-jpgdec compatible to binding document.
Signed-off-by kyrie.wu <[email protected]>
Quoted 8 lines
Quoted 3 lines
Usual mediatek comment - looks like copy paste of username. Please reach
to your colleagues how to fix it.Dear Krzysztof,
Do I need to change the username like that: Kyrie Wu < [email protected]>?
And what did your colleagues say? Please use Mediatek resources prior asking community for review.
Quoted 29 lines
Thanks.
Quoted 18 lines
Quoted 18 lines
--- .../bindings/media/mediatek,mt8195-jpegdec.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)diff --git a/Documentation/devicetree/bindings/media/mediatek,mt8195-
jpegdec.yamlb/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
indexe5448c60e3eb..28a9a9bfdbf8100644
--- a/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
+++ b/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml(quoted diff) +0
-0@@ -14,7 +14,9 @@ description:Quoted 8 lines
Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml description: · line 19
Quoted 6 lines
Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml +3
-1properties: compatible: - const: mediatek,mt8195-jpgdec + enum: + - mediatek,mt8195-jpgdec + - mediatek,mt8196-jpgdecAnd devices are not compatible?
Quoted 2 lines
Sorry, I don't understand the question exactly. Do you mean using the compatible string of MT8195 for both MT8195 and MT8196?
No, expressing compatibility with fallbacks or explaining in commit msg the hardware, e.g. why these are not compatible.
Best regards,
Krzysztof
Re: [PATCH v2 01/12] dt-bindings: mediatek: Add mediatek, mt8196-jpgdec compatible
Quoted 21 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 16 lines · Kyrie Wu (吴晗)
Quoted 14 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until
you have verified the sender or the content.Quoted 3 lines · kyrie.wu
Add mediatek,mt8196-jpgdec compatible to binding document.
Signed-off-by kyrie.wu <[email protected]>Usual mediatek comment - looks like copy paste of username. Please
reach
to your colleagues how to fix it.
Quoted 7 lines
Quoted 4 lines
Dear Krzysztof,
Do I need to change the username like that: Kyrie Wu < [email protected]>?
And what did your colleagues say? Please use Mediatek resources prior asking community for review.
Dear Krzysztof,
The above username is suggested by my colleagues. I queried with you to avoid made this mistake again.
Thanks.
Quoted 30 lines
Quoted 30 lines
Thanks.
Quoted 26 lines
Quoted 17 lines
--- .../bindings/media/mediatek,mt8195-jpegdec.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)diff --git a/Documentation/devicetree/bindings/media/mediatek,mt8195-
jpegdec.yamlb/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
indexe5448c60e3eb..28a9a9bfdbf8100644
--- a/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml
+++ b/Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yamlDocumentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml description: · line 19
Quoted 7 lines
Documentation/devicetree/bindings/media/mediatek,mt8195-jpegdec.yaml +3
-1@@ -14,7 +14,9 @@ description: properties: compatible: - const: mediatek,mt8195-jpgdec + enum: + - mediatek,mt8195-jpgdec + - mediatek,mt8196-jpgdecAnd devices are not compatible?
Quoted 7 lines
Quoted 3 lines
Sorry, I don't understand the question exactly. Do you mean using the
compatible string of MT8195 for both MT8195 and MT8196?No, expressing compatibility with fallbacks or explaining in commit msg
the hardware, e.g. why these are not compatible.
Thanks.
I will fix the commit message. There are several differeances between the two chips. e.g. 8195 uses iommu but smmu is used in 8196. And 8196 will support dynamic voltage and frequency scale.
Quoted 4 lines
Best regards,
Krzysztof
Regards,
Kyrie.
PATCH v2 2/12 dt-bindings: mediatek: Add mediatek, mt8196-jpgenc compatible
In reply to kyrie.wuAdd mediatek,mt8196-jpgenc compatible to 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.46.0
Re: [PATCH v2 02/12] dt-bindings: mediatek: Add mediatek, mt8196-jpgenc compatible
Quoted 3 lines · kyrie.wu
Add mediatek,mt8196-jpgenc compatible to binding document.
Signed-off-by kyrie.wu <[email protected]>
Same comments.
Also: missing media prefix in subject.
Please use subject prefixes matching the subsystem. You can get them for example with 'git log --oneline -- DIRECTORY_OR_FILE' on the directory your patch is touching. For bindings, the preferred subjects are explained here:
https://www.kernel.org/doc/html/latest/devicetree/bindings/submitting-patches.html#i-for-patch-submitters
Best regards,
Krzysztof
Re: [PATCH v2 02/12] dt-bindings: mediatek: Add mediatek, mt8196-jpgenc compatible
Quoted 11 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 3 lines · kyrie.wu
Add mediatek,mt8196-jpgenc compatible to binding document.
Signed-off-by kyrie.wu <[email protected]>Same comments.
Quoted 9 lines
Also: missing media prefix in subject.
Please use subject prefixes matching the subsystem. You can get them for
example with 'git log --oneline --DIRECTORY_OR_FILE' on the directory
your patch is touching. For bindings, the preferred subjects are explained here:
Quoted 4 lines
Best regards,
Krzysztof
Dear Krzysztof,
Thanks for your comment. I will change subject in the next version like following:
dt-bindings: media: mediatek,jpeg: xxx
Regards,
Kyrie
Re: [PATCH v2 02/12] dt-bindings: mediatek: Add mediatek, mt8196-jpgenc compatible
Quoted 26 lines · Kyrie Wu (吴晗)
Quoted 11 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 3 lines · kyrie.wu
Add mediatek,mt8196-jpgenc compatible to binding document.
Signed-off-by kyrie.wu <[email protected]>Same comments.
Quoted 9 lines
Also: missing media prefix in subject.
Please use subject prefixes matching the subsystem. You can get them for
example with 'git log --oneline --DIRECTORY_OR_FILE' on the directory
your patch is touching. For bindings, the preferred subjects are explained here:Quoted 4 lines
Best regards,
Krzysztof
Quoted 6 lines
Dear Krzysztof,
Thanks for your comment. I will change subject in the next version like following:
dt-bindings: media: mediatek,jpeg: xxx
Did you even read the link I provided? How can I be more specific?
Best regards,
Krzysztof
Re: [PATCH v2 02/12] dt-bindings: mediatek: Add mediatek, mt8196-jpgenc compatible
Quoted 4 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 26 lines
Quoted 25 lines · Kyrie Wu (吴晗)
Quoted 22 lines · Krzysztof Kozlowski
External email : Please do not click links or open attachments until
you have verified the sender or the content.Quoted 3 lines · kyrie.wu
Add mediatek,mt8196-jpgenc compatible to binding document.
Signed-off-by kyrie.wu <[email protected]>Same comments.
Also: missing media prefix in subject.
Please use subject prefixes matching the subsystem. You can get them
for
example with 'git log --oneline --DIRECTORY_OR_FILE' on the directory
your patch is touching. For bindings, the preferred subjects are explained here:
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Best regards,
KrzysztofDear Krzysztof,
Thanks for your comment. I will change subject in the next version like following:
Quoted 6 lines
Quoted 1 line
dt-bindings: media: mediatek,jpeg: xxx
Did you even read the link I provided? How can I be more specific?
Best regards,
Krzysztof
Dear Krzysztof,
I'm terriably to bother you again.
I used the cmd of 'git log --oneline -- Documentation/devicetree/bindings/media/', the below string were got:
...
dt-bindings: media: mediatek,jpeg: Relax IOMMU max item count
...
But these contents are shown from the link you supplied:
Few subsystems, like ASoC, media, regulators and SPI, expect reverse order of the prefixes:
"<binding dir>: dt-bindings: ..."
The two results are different. Which do I need to take to fix my patch in the next version?
Thanks.
Regards,
Kyrie.
PATCH v2 3/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
@@ -1922,6 +1922,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 ,
@@ -1935,6 +1948,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 mtk_jpeg_variant mtk8188_jpegenc_drvdata = { .clks = mtk_jpeg_clocks, .num_clks =ARRAY_SIZE (mtk_jpeg_clocks),
@@ -1996,6 +2022,14 @@ static const struct of_device_id mtk_jpeg_match[] = { .compatible = "mediatek,mt8188-jpgdec", .data = &mtk8188_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.46.0
PATCH v2 4/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 | 34 +++++++++++++++++++ .../platform/mediatek/jpeg/mtk_jpeg_core.h | 19 +++++++++++ .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 24 +++++++++++++ .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 25 ++++++++++++++ 4 files changed, 102 insertions(+)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +34 -0
@@ -1584,6 +1584,18 @@ static irqreturn_t mtk_jpeg_enc_done(struct mtk_jpeg_dev *jpeg)return IRQ_HANDLED ; } +static void mtk_jpeg_enc_set_smmu_sid (struct mtk_jpegenc_comp_dev *jpeg) +{ +u32 val, mask; + + val =readl (jpeg->smmu_info.smmu_base); + mask = ~(jpeg->smmu_info.mask << jpeg->smmu_info.shift); + val &= mask; + val |= (jpeg->smmu_info.sid << jpeg->smmu_info.shift); + +writel (val, jpeg->smmu_info.smmu_base); +} +static void mtk_jpegenc_worker (struct work_struct *work) {struct mtk_jpegenc_comp_dev *comp_jpeg[MTK_JPEGENC_HW_MAX ];
@@ -1655,6 +1667,10 @@ 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_flag) +mtk_jpeg_enc_set_smmu_sid (comp_jpeg[hw_id]); +mtk_jpeg_set_enc_dst (ctx, comp_jpeg[hw_id]->reg_base, &dst_buf->vb2_buf);
@@ -1679,6 +1695,18 @@ static void mtk_jpegenc_worker(struct work_struct *work)v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); } +static void mtk_jpeg_dec_set_smmu_sid (struct mtk_jpegdec_comp_dev *jpeg) +{ +u32 val, mask; + + val =readl (jpeg->smmu_info.smmu_base); + mask = ~(jpeg->smmu_info.mask << jpeg->smmu_info.shift); + val &= mask; + val |= (jpeg->smmu_info.sid << jpeg->smmu_info.shift); + +writel (val, jpeg->smmu_info.smmu_base); +} +static void mtk_jpegdec_worker (struct work_struct *work) { struct mtk_jpeg_ctx *ctx = container_of(work, struct mtk_jpeg_ctx,
@@ -1771,6 +1799,10 @@ static void mtk_jpegdec_worker(struct work_struct *work)spin_lock_irqsave (&comp_jpeg[hw_id]->hw_lock, flags); ctx->total_frame_num++;mtk_jpeg_dec_reset (comp_jpeg[hw_id]->reg_base); + +if (jpeg->variant->support_smmu_flag) +mtk_jpeg_dec_set_smmu_sid (comp_jpeg[hw_id]); + mtk_jpeg_dec_set_config(comp_jpeg[hw_id]->reg_base, jpeg->variant->support_34bit, &jpeg_src_buf->dec_param,
@@ -1933,6 +1965,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_flag = true, };static const struct mtk_jpeg_variant mtk8195_jpegdec_drvdata = {
@@ -1959,6 +1992,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_flag = true, };static const struct mtk_jpeg_variant mtk8188_jpegenc_drvdata = {
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +19 -0
@@ -82,6 +82,7 @@ struct mtk_jpeg_variant {bool multi_core;void (*jpeg_worker)(struct work_struct *work);bool support_34bit; +bool support_smmu_flag; };struct mtk_jpeg_src_buf {
@@ -138,6 +139,20 @@ struct mtk_jpegdec_clk {int clk_num; }; +/** +* struct mtk_smmu_info - Structure used to store smmu information +* @smmu_base: JPEG encode smmu register mapping +* @sid: JPEG encode smmu hw sid +* @shift: JPEG encode smmu hw bit shift +* @mask: JPEG encode smmu hw bit mask +*/ +struct mtk_smmu_info { +void __iomem *smmu_base; +unsigned int sid; +unsigned int shift; +unsigned int mask; +}; +/** * struct mtk_jpegenc_comp_dev - JPEG COREX abstraction * @dev: JPEG device
@@ -150,6 +165,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_info: SMMU information */ struct mtk_jpegenc_comp_dev {struct device *dev;
@@ -163,6 +179,7 @@ struct mtk_jpegenc_comp_dev {enum mtk_jpeg_hw_state hw_state;/* spinlock protecting the hw device resource */ spinlock_t hw_lock; +struct mtk_smmu_info smmu_info; };/**
@@ -177,6 +194,7 @@ struct mtk_jpegenc_comp_dev {* @hw_param: jpeg decode hw parameters * @hw_state: record hw state * @hw_lock: spinlock protecting hw +* @smmu_info: SMMU information */ struct mtk_jpegdec_comp_dev {struct device *dev;
@@ -190,6 +208,7 @@ struct mtk_jpegdec_comp_dev {enum mtk_jpeg_hw_state hw_state;/* spinlock protecting the hw device resource */ spinlock_t hw_lock; +struct mtk_smmu_info smmu_info; };/**
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +24 -0
@@ -618,6 +618,29 @@ static int mtk_jpegdec_hw_init_irq(struct mtk_jpegdec_comp_dev *dev)return 0 ; } +static void mtk_jpegdec_smmu_init (struct mtk_jpegdec_comp_dev *dev) +{ +struct resource *r; + + r =platform_get_resource (dev->plat_dev,IORESOURCE_MEM ,1 ); +if (!r) { +dev_err (&dev->plat_dev->dev,"get smmu_base failed\n" ); +return ; + } + + dev->smmu_info.smmu_base = +devm_ioremap (&dev->plat_dev->dev, r->start, +resource_size (r)); +if (IS_ERR (dev->smmu_info.smmu_base)) { +dev_err (&dev->plat_dev->dev,"mmap smmu_base failed(%ld)\n" , +PTR_ERR (dev->smmu_info.smmu_base)); +return ; + } + + dev->smmu_info.sid =0x4 ; + dev->smmu_info.shift =8 ; + dev->smmu_info.mask =0x7 ; +}static int mtk_jpegdec_hw_probe (struct platform_device *pdev) {struct mtk_jpegdec_clk *jpegdec_clk;
@@ -670,6 +693,7 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev) master_dev->reg_decbase[i] = dev->reg_base; dev->master_dev = master_dev; +mtk_jpegdec_smmu_init (dev);platform_set_drvdata (pdev, dev);pm_runtime_enable (&pdev->dev);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +25 -0
@@ -353,6 +353,30 @@ static int mtk_jpegenc_hw_init_irq(struct mtk_jpegenc_comp_dev *dev)return 0 ; } +static void mtk_jpegenc_smmu_init (struct mtk_jpegenc_comp_dev *dev) +{ +struct resource *r; + + r =platform_get_resource (dev->plat_dev,IORESOURCE_MEM ,1 ); +if (!r) { +dev_err (&dev->plat_dev->dev,"get smmu_base failed\n" ); +return ; + } + + dev->smmu_info.smmu_base = +devm_ioremap (&dev->plat_dev->dev, r->start, +resource_size (r)); +if (IS_ERR (dev->smmu_info.smmu_base)) { +dev_err (&dev->plat_dev->dev,"mmap smmu_base failed(%ld)\n" , +PTR_ERR (dev->smmu_info.smmu_base)); +return ; + } + + dev->smmu_info.sid =0x5 ; + dev->smmu_info.shift =4 ; + dev->smmu_info.mask =0x7 ; +} +static int mtk_jpegenc_hw_probe (struct platform_device *pdev) {struct mtk_jpegenc_clk *jpegenc_clk;
@@ -403,6 +427,7 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev) master_dev->reg_encbase[i] = dev->reg_base; dev->master_dev = master_dev; +mtk_jpegenc_smmu_init (dev);platform_set_drvdata (pdev, dev);pm_runtime_enable (&pdev->dev);
Signature · 1 line
2.46.0
PATCH v2 5/12 media: mediatek: jpeg: fix jpeg hw count setting
In reply to kyrie.wu1. different IC has different hw core;
2. use a parameter to set jpeg hw count.
--- 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
@@ -1468,7 +1468,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;
@@ -1515,7 +1515,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;
@@ -1610,7 +1610,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 ;
@@ -1721,7 +1721,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
@@ -231,6 +231,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;
@@ -253,6 +254,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
@@ -692,6 +692,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++;mtk_jpegdec_smmu_init (dev);platform_set_drvdata (pdev, dev);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +1 -0
@@ -426,6 +426,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++;mtk_jpegenc_smmu_init (dev);platform_set_drvdata (pdev, dev);
Signature · 1 line
2.46.0
PATCH v2 6/12 media: mediatek: jpeg: refactor jpeg buffer payload setting
In reply to kyrie.wu1. for multi-core jpegdec:
core0: |<-------- decoding buffer0 and resolution changed to smaller
core1: |<-------- decoding buffer1
core0: |<- handling resolution changing
core0: |<- vb2_set_plane_payload
2. the payload size is changed on the step of set format. Because core1 is running and streaming has not been stopped, the format cannot be set again, resulting in no change in the payload size.
3. at this time, the payload size is bigger than buffer length, it will print a warnning call trace
4. set payload size must less than buffer length
--- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +15 -3
@@ -719,10 +719,22 @@ static int mtk_jpeg_buf_prepare(struct vb2_buffer *vb) plane_fmt = q_data->pix_mp.plane_fmt[i];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 ); +if (vb->planes[i].length > (plane_fmt.sizeimage + +MTK_JPEG_MAX_EXIF_SIZE )) +vb2_set_plane_payload (vb, i, + plane_fmt.sizeimage + +MTK_JPEG_MAX_EXIF_SIZE ); +else +vb2_set_plane_payload (vb, i, + vb->planes[i].length); +else -vb2_set_plane_payload (vb, i, plane_fmt.sizeimage); +if (vb->planes[i].length > plane_fmt.sizeimage) +vb2_set_plane_payload (vb, i, + plane_fmt.sizeimage); +else +vb2_set_plane_payload (vb, i, + vb->planes[i].length); }return 0 ;
Signature · 1 line
2.46.0
PATCH v2 7/12 media: mediatek: jpeg: refactor jpeg dst buffer layout
In reply to kyrie.wu1. change dst buffer size to same as struct mtk_jpeg_src_buf to make sure all params of mtk_jpeg_src_buf could get a memory.
2. For memory alloc operation:
the v4l2 framework malloc a memory, the base addr is vb2_buffer and the size is sizeof(struct mtk_jpeg_src_buf), mtk_jpeg_src_buf could get itself addr by container_of like that:vb2_buffer -> vb2_v4l2_buffer -> mtk_jpeg_src_buf. vb2_v4l2_buffer must keep on the top of mtk_jpeg_src_buf.
--- 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
@@ -1102,7 +1102,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
@@ -86,10 +86,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.46.0
PATCH v2 8/12 media: mediatek: jpeg: fix stop streaming flow for multi-core
In reply to kyrie.wu1. For multi-core jpegdec, the all hws may run at the same time, if one hw decoded firstly, the function of mtk_jpeg_dec_stop_streaming would be called, but others input buffers are decoding, this will cause some running buffers to be buffer done, causing errors;
2. add a parameter to calculate the decoding buffer counts, it wil decrease to 0 until the all buffers decoded and the mtk_jpeg_dec_stop_streaming could continue to be executed.
--- .../media/platform/mediatek/jpeg/mtk_jpeg_core.c | 16 ++++++++++++++++ .../media/platform/mediatek/jpeg/mtk_jpeg_core.h | 2 ++ .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 9 +++++++++ .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 9 +++++++++ 4 files changed, 36 insertions(+)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +16 -0
@@ -860,8 +860,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) +wait_event (jpeg->hw_wq, (atomic_read (&ctx->buf_list_cnt) ==0 )); +while ((vb =mtk_jpeg_buf_remove (ctx, q->type)))v4l2_m2m_buf_done (vb,VB2_BUF_STATE_ERROR ); }
@@ -869,6 +873,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;/*
@@ -876,6 +881,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) +wait_event (jpeg->hw_wq, (atomic_read (&ctx->buf_list_cnt) ==0 )); +if (ctx->state ==MTK_JPEG_SOURCE_CHANGE &&V4L2_TYPE_IS_CAPTURE (q->type)) {struct mtk_jpeg_src_buf *src_buf;
@@ -1185,6 +1193,7 @@ static int mtk_jpeg_open(struct file *file)v4l2_fh_init (&ctx->fh, vfd); file->private_data = &ctx->fh;v4l2_fh_add (&ctx->fh); +atomic_set (&ctx->buf_list_cnt,0 ); ctx->jpeg = jpeg; ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(jpeg->m2m_dev, ctx,
@@ -1567,6 +1576,11 @@ static int mtk_jpegdec_set_hw_param(struct mtk_jpeg_ctx *ctx,return 0 ; } +static void jpeg_buf_queue_inc (struct mtk_jpeg_ctx *ctx) +{ +atomic_inc (&ctx->buf_list_cnt); +} +static irqreturn_t mtk_jpeg_enc_done (struct mtk_jpeg_dev *jpeg) {struct mtk_jpeg_ctx *ctx;
@@ -1691,6 +1705,7 @@ 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); +jpeg_buf_queue_inc (ctx);v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx);spin_unlock_irqrestore (&comp_jpeg[hw_id]->hw_lock, flags);
@@ -1822,6 +1837,7 @@ static void mtk_jpegdec_worker(struct work_struct *work) &bs, &fb);mtk_jpeg_dec_start (comp_jpeg[hw_id]->reg_base); +jpeg_buf_queue_inc (ctx);v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx);spin_unlock_irqrestore (&comp_jpeg[hw_id]->hw_lock, flags);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +2 -0
@@ -307,6 +307,7 @@ struct mtk_jpeg_q_data {* @dst_done_queue: encoded frame buffer queue * @done_queue_lock: encoded frame operation spinlock * @last_done_frame_num: the last encoded frame number +* @buf_list_cnt: the frame buffer count own by jpeg driver */ struct mtk_jpeg_ctx {struct mtk_jpeg_dev *jpeg;
@@ -325,6 +326,7 @@ struct mtk_jpeg_ctx {/* spinlock protecting the encode done buffer */ spinlock_t done_queue_lock;u32 last_done_frame_num; + atomic_t buf_list_cnt; };#endif /* _MTK_JPEG_CORE_H */
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +9 -0
@@ -524,6 +524,11 @@ static void mtk_jpegdec_put_buf(struct mtk_jpegdec_comp_dev *jpeg)spin_unlock_irqrestore (&ctx->done_queue_lock, flags); } +static void jpeg_buf_queue_dec (struct mtk_jpeg_ctx *ctx) +{ +atomic_dec (&ctx->buf_list_cnt); +} +static void mtk_jpegdec_timeout_work (struct work_struct *work) {enum vb2_buffer_state buf_state =VB2_BUF_STATE_ERROR ;
@@ -532,9 +537,11 @@ static void mtk_jpegdec_timeout_work(struct work_struct *work) job_timeout_work.work);struct mtk_jpeg_dev *master_jpeg = cjpeg->master_dev;struct vb2_v4l2_buffer *src_buf, *dst_buf; +struct mtk_jpeg_ctx *ctx; src_buf = cjpeg->hw_param.src_buffer; dst_buf = cjpeg->hw_param.dst_buffer; + ctx = cjpeg->hw_param.curr_ctx;v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, true);mtk_jpeg_dec_reset (cjpeg->reg_base);
@@ -545,6 +552,7 @@ static void mtk_jpegdec_timeout_work(struct work_struct *work)wake_up (&master_jpeg->hw_wq);v4l2_m2m_buf_done (src_buf, buf_state);mtk_jpegdec_put_buf (cjpeg); +jpeg_buf_queue_dec (ctx); }static irqreturn_t mtk_jpegdec_hw_irq_handler (int irq,void *priv)
@@ -585,6 +593,7 @@ static irqreturn_t mtk_jpegdec_hw_irq_handler(int irq, void *priv) buf_state =VB2_BUF_STATE_DONE ;v4l2_m2m_buf_done (src_buf, buf_state);mtk_jpegdec_put_buf (jpeg); +jpeg_buf_queue_dec (ctx);pm_runtime_put (ctx->jpeg->dev);clk_disable_unprepare (jpeg->jdec_clk.clks->clk);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +9 -0
@@ -264,6 +264,11 @@ static void mtk_jpegenc_put_buf(struct mtk_jpegenc_comp_dev *jpeg)spin_unlock_irqrestore (&ctx->done_queue_lock, flags); } +static void jpeg_buf_queue_dec (struct mtk_jpeg_ctx *ctx) +{ +atomic_dec (&ctx->buf_list_cnt); +} +static void mtk_jpegenc_timeout_work (struct work_struct *work) {struct delayed_work *dly_work =to_delayed_work (work);
@@ -274,9 +279,11 @@ static void mtk_jpegenc_timeout_work(struct work_struct *work)struct mtk_jpeg_dev *master_jpeg = cjpeg->master_dev;enum vb2_buffer_state buf_state =VB2_BUF_STATE_ERROR ;struct vb2_v4l2_buffer *src_buf, *dst_buf; +struct mtk_jpeg_ctx *ctx; src_buf = cjpeg->hw_param.src_buffer; dst_buf = cjpeg->hw_param.dst_buffer; + ctx = cjpeg->hw_param.curr_ctx;v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, true);mtk_jpeg_enc_reset (cjpeg->reg_base);
@@ -287,6 +294,7 @@ static void mtk_jpegenc_timeout_work(struct work_struct *work)wake_up (&master_jpeg->hw_wq);v4l2_m2m_buf_done (src_buf, buf_state);mtk_jpegenc_put_buf (cjpeg); +jpeg_buf_queue_dec (ctx); }static irqreturn_t mtk_jpegenc_hw_irq_handler (int irq,void *priv)
@@ -320,6 +328,7 @@ static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv) buf_state =VB2_BUF_STATE_DONE ;v4l2_m2m_buf_done (src_buf, buf_state);mtk_jpegenc_put_buf (jpeg); +jpeg_buf_queue_dec (ctx);pm_runtime_put (ctx->jpeg->dev);clk_disable_unprepare (jpeg->venc_clk.clks->clk);
Signature · 1 line
2.46.0
PATCH v2 9/12 media: mediatek: jpeg: refactor multi-core clk suspend and resume setting
In reply to kyrie.wurefactor jpeg clk suspend and resume setting for multi-core
--- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 28 +++---- .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 75 ++++++++++++++++++- .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 75 ++++++++++++++++++- 3 files changed, 151 insertions(+), 27 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +9 -19
@@ -1125,6 +1125,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)
@@ -1133,6 +1136,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); }
@@ -1674,13 +1680,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);
@@ -1794,20 +1793,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);
@@ -1817,7 +1809,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,
@@ -1843,9 +1835,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 +71 -4
112 lines not on this page · raw message
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +71 -4
112 lines not on this page · raw message
Signature · 1 line
2.46.0
PATCH v2 10/12 media: mediatek: jpeg: fix decoding buffer number setting timing issue
In reply to kyrie.wumove decoding buffer increase code into spinlock
protecting aera for multi-core
--- 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
@@ -1778,7 +1778,6 @@ static void mtk_jpegdec_worker(struct work_struct *work)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);if (mtk_jpeg_check_resolution_change (ctx, &jpeg_src_buf->dec_param)) {
@@ -1787,11 +1786,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 ) {
@@ -1816,6 +1810,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);
drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +1 -0
@@ -518,6 +518,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
@@ -258,6 +258,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.46.0
PATCH v2 11/12 media: mediatek: jpeg: refactor decoding resolution change operation
In reply to kyrie.wuFor multi-core:
1.if there are only two src buffers, hw0 and hw1 are decoding at the same time. When resolution change occurred on one hw, the src buffer cannot be got in the stop streaming function, which will cause a crash.
2.When a resolution change occurs, immediately set the new resolution parameter to save the new resolution;
3.After a resolution change occurred, decoding should not continue, needs to wait until new buffers are ready and the state machine changed.
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +7 -2
@@ -890,7 +890,8 @@ static void mtk_jpeg_dec_stop_streaming(struct vb2_queue *q) vb =v4l2_m2m_next_src_buf (ctx->fh.m2m_ctx); src_buf =mtk_jpeg_vb2_to_srcbuf (&vb->vb2_buf); -mtk_jpeg_set_queue_data (ctx, &src_buf->dec_param); +if (!IS_ERR_OR_NULL (src_buf)) +mtk_jpeg_set_queue_data (ctx, &src_buf->dec_param); ctx->state =MTK_JPEG_RUNNING ; }else if (V4L2_TYPE_IS_OUTPUT (q->type)) { ctx->state =MTK_JPEG_INIT ;
@@ -1781,11 +1782,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.46.0
PATCH v2 12/12 media: mediatek: jpeg: fix remove buffer operation for multi-core
In reply to kyrie.wumove remove buffer code to spinlock protect area for multi-core
--- 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
@@ -1681,9 +1681,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 ));
@@ -1705,6 +1702,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);jpeg_buf_queue_inc (ctx);v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx);spin_unlock_irqrestore (&comp_jpeg[hw_id]->hw_lock, flags);
@@ -1799,9 +1798,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,
@@ -1830,6 +1826,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);jpeg_buf_queue_inc (ctx);v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx);
Signature · 1 line
2.46.0