From patchwork Wed Jun 30 07:27:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?S3lyaWUgV3UgKOWQtOaZlyk=?= X-Patchwork-Id: 12351423 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60D40C11F65 for ; Wed, 30 Jun 2021 07:28:40 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 246F261CD0 for ; Wed, 30 Jun 2021 07:28:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 246F261CD0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NQLQ23+b3jC5P/1ZgAjZE/tlwBsn050vwBvJCqxoaQM=; b=XK90RxSpkI5M7J 79DUnDGkGDHvZ394b+GD8oy/fIHaQdYqn67bpYawrQYOTjQ91cuRpJclaVRTjoPNO4Qx09SL630gx wgCCIcfSMMuV7RoCmo531toXtgnF+jIxAhNessvU9W8OvMxIq8L6aEjsGez9+pWXL4SM69jpH78ns 1bT8zHLIJp/kwgvOywNf3Feqjeu/sCF2q6bkfdfUvbS6xLYTxf6k1qqzC0Tgt7Zx+oWTgYlGRMX62 nE7gGeuwNr6rly0SUpMsDXn35MLxEn5l85ciZQVLXVuZs1pME/uSnZg7Q4s2Zhj7q3M8QwyPc6j61 2zXRYybpBDSvgbSFCWVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUe4-00D2le-TF; Wed, 30 Jun 2021 07:28:28 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUdo-00D2ff-7V; Wed, 30 Jun 2021 07:28:15 +0000 X-UUID: e2129b07999547039fba8d98822c11ac-20210630 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=+brlJa9UdiApAzjHvwbXXR7GWBJFYiJCDU0ygoBW2VA=; b=qdL5HHfov1lAlNqDvNtWZS1Upfq6gm+NyHK8ef6bBo1TqNY6HyPnfhlW36eGSNsGPONZPjW1USPqcnHUpLyJ3bZvgB32DwNasuct2fMvKLtMKM2h/UGd33//OSpgIH+TTeMns+ktYS4wx5awPR6FFFsz5c9IfWKLUdL2W7q1As8=; X-UUID: e2129b07999547039fba8d98822c11ac-20210630 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 701861551; Wed, 30 Jun 2021 00:28:08 -0700 Received: from mtkmbs07n1.mediatek.inc (172.21.101.16) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 00:28:06 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 15:28:05 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 30 Jun 2021 15:28:04 +0800 From: kyrie.wu To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Bin Liu , Matthias Brugger , "Tzung-Bi Shih" CC: , , , , , , Tomasz Figa , , , , kyrie.wu Subject: [PATCH v2, 1/9] dt-bindings: mediatek: Add mediatek, mt8195-jpgenc compatible Date: Wed, 30 Jun 2021 15:27:51 +0800 Message-ID: <1625038079-25815-2-git-send-email-kyrie.wu@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> References: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_002813_779537_B4BF4326 X-CRM114-Status: GOOD ( 10.08 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Add mediatek, mt8195-jpgenc compatible to binding document Signed-off-by: kyrie.wu --- Documentation/devicetree/bindings/media/mediatek-jpeg-encoder.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/media/mediatek-jpeg-encoder.yaml b/Documentation/devicetree/bindings/media/mediatek-jpeg-encoder.yaml index fcd9b82..e93ccf5 100644 --- a/Documentation/devicetree/bindings/media/mediatek-jpeg-encoder.yaml +++ b/Documentation/devicetree/bindings/media/mediatek-jpeg-encoder.yaml @@ -18,6 +18,9 @@ properties: - enum: - mediatek,mt2701-jpgenc - mediatek,mt8183-jpgenc + - mediatek,mt8195-jpgenc + - mediatek,mt8195-jpgenc0 + - mediatek,mt8195-jpgenc1 - const: mediatek,mtk-jpgenc reg: maxItems: 1 From patchwork Wed Jun 30 07:27:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?S3lyaWUgV3UgKOWQtOaZlyk=?= X-Patchwork-Id: 12351443 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CB64C11F68 for ; Wed, 30 Jun 2021 07:35:20 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 389FD61D01 for ; Wed, 30 Jun 2021 07:35:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 389FD61D01 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JPFkx61usvNVnxJlYAXdcdrB0GmS30ck7HqF/jdKNUo=; b=XytLfZEcVl2DYX 30XbQVb4xSfIJM/agJfaG3006tBBCyqp3amZkSzymzTS/3P2VuLcpBqOWenXEoujUasc1U/fL/Xx5 jRr1XV4zqZspVWGm+AWMBQ44pdiYmCQORBY3yZpbklqM66KDLgBF2qJeEr29wSNuyWAvakuzx2o67 DirA65sbOnOBCyJ8loknYEQsHWuefyyr2Ab3cSKx3c7i5zBrl9qtLBWHFksJMFbsR2qDKMgboqmVV 8d0Hn4TbOlW/LhovT/27a2rplt13xN9PIJLDZKrjNC3EBYyqrCQhVCz8S3yrJrsZ8Ozl92T4VeGQY y5tVQfOhUQgJ2IPwdM8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUkV-00D6EQ-90; Wed, 30 Jun 2021 07:35:07 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUht-00D4xP-P5; Wed, 30 Jun 2021 07:32:27 +0000 X-UUID: bba198cfac0647d098ee7fb188cc5c49-20210630 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=SIbgN7GmtKCTtm3mefhLSWTOwkQvXNdFdtqSR/57TO8=; b=QOD3M/S0sPkLoGrxK2kfv1+mN95M0/1oIxU/hm2B+MPMoB3Fp+cLIujdDsW6T2o/0LburSG6n1DryLVGoqhuEcX5fWiP3a0KsBblOSSLebRU7sVukqk/IKPna9x9+Bq267sCiOwkT+0BYvZDYHJF2EYNvZMu0AnizTcKlV5B73s=; X-UUID: bba198cfac0647d098ee7fb188cc5c49-20210630 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1500508680; Wed, 30 Jun 2021 00:32:21 -0700 Received: from mtkmbs07n1.mediatek.inc (172.21.101.16) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 00:28:09 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 15:28:08 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 30 Jun 2021 15:28:07 +0800 From: kyrie.wu To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Bin Liu , Matthias Brugger , "Tzung-Bi Shih" CC: , , , , , , Tomasz Figa , , , , kyrie.wu Subject: [PATCH v2,2/9] media: mtk-jpegenc: Add MT8195 JPEG venc driver Date: Wed, 30 Jun 2021 15:27:52 +0800 Message-ID: <1625038079-25815-3-git-send-email-kyrie.wu@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> References: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_003225_871527_CDDBE7FA X-CRM114-Status: GOOD ( 13.98 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Add MT8195 JPEG venc driver's compatible and device private data. compatible = "mediatek,mt8195-jpgenc": this node would only register jpgenc device node; compatible = "mediatek,mt8195-jpgenc0": HW0 node, this node would not register jpgenc device node, but register irq, init clk and power, remmap register base and do other resource options; compatible = "mediatek,mt8195-jpgenc1": HW1 node, just like HW0 node; Signed-off-by: kyrie.wu --- drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 11 +++++------ drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h | 1 + drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c | 12 ++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c index 88a23bc..908aa1f 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c @@ -1524,13 +1524,13 @@ static const struct mtk_jpeg_variant mt8173_jpeg_drvdata = { .cap_q_default_fourcc = V4L2_PIX_FMT_YUV420M, }; -static const struct mtk_jpeg_variant mtk_jpeg_drvdata = { +static const struct mtk_jpeg_variant mtk_jpegenc_drvdata = { + .is_encoder = true, .clks = mtk_jpeg_clocks, .num_clks = ARRAY_SIZE(mtk_jpeg_clocks), .formats = mtk_jpeg_enc_formats, .num_formats = MTK_JPEG_ENC_NUM_FORMATS, .qops = &mtk_jpeg_enc_qops, - .irq_handler = mtk_jpeg_enc_irq, .hw_reset = mtk_jpeg_enc_reset, .m2m_ops = &mtk_jpeg_enc_m2m_ops, .dev_name = "mtk-jpeg-enc", @@ -1540,6 +1540,9 @@ static const struct mtk_jpeg_variant mtk_jpeg_drvdata = { }; static const struct of_device_id mtk_jpeg_match[] = { + { .compatible = "mediatek,mt8195-jpgenc", + .data = &mtk_jpegenc_drvdata, + }, { .compatible = "mediatek,mt8173-jpgdec", .data = &mt8173_jpeg_drvdata, @@ -1548,10 +1551,6 @@ static const struct of_device_id mtk_jpeg_match[] = { .compatible = "mediatek,mt2701-jpgdec", .data = &mt8173_jpeg_drvdata, }, - { - .compatible = "mediatek,mtk-jpgenc", - .data = &mtk_jpeg_drvdata, - }, {}, }; diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h index 595f7f1..bdbd768 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h @@ -60,6 +60,7 @@ enum mtk_jpeg_ctx_state { * @cap_q_default_fourcc: capture queue default fourcc */ struct mtk_jpeg_variant { + bool is_encoder; struct clk_bulk_data *clks; int num_clks; struct mtk_jpeg_fmt *formats; diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c index 1cf037b..3da1011 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c @@ -152,3 +152,15 @@ void mtk_jpeg_set_enc_params(struct mtk_jpeg_ctx *ctx, void __iomem *base) writel(ctx->restart_interval, base + JPEG_ENC_RST_MCU_NUM); } + +#if defined(CONFIG_OF) +static const struct of_device_id mtk_jpegenc_hw_ids[] = { + { + .compatible = "mediatek,mt8195-jpgenc0", + }, + { .compatible = "mediatek,mt8195-jpgenc1", + }, + {}, +}; +MODULE_DEVICE_TABLE(of, mtk_jpegenc_hw_ids); +#endif From patchwork Wed Jun 30 07:27:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?S3lyaWUgV3UgKOWQtOaZlyk=?= X-Patchwork-Id: 12351463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB583C11F65 for ; Wed, 30 Jun 2021 07:38:34 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B71A261D03 for ; Wed, 30 Jun 2021 07:38:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B71A261D03 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Br6LNRdQ6frsv+mxrivzjzrhpaKAPn565iTnHNSEljQ=; b=pLkvjXveMN2Ybv zRDZzXi+XNJE5DDIbauBEUSZTO07Li3YFyZrBjXnKhbSUt/2r+WEKn9pp4/JdD25RuySgoXM6QMDb Vvm2gZYfvKlvswBkxWoWo+Mt+9iDhA2WNkPTDKeu3bVP+Dt1M/3NVkXDExOeX2xUdQWXsLJJhabNf /4u7B3Qa7kj6DtCTQzgnIQctj7x8pNOq2KbDIrdRtJizYa23aI1nzMxJIdEQMjONfQA6yU/R2Uh2K sqiTF9OFe0fQUGHpQUSgMj72+MrK3OjX3ytOTlR3/hVXaCfpGbfoEO9a5gYVh2pCzaItHM//T8BAN BJMP6Figgdrk6S189VGw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUnc-00D8Nb-1T; Wed, 30 Jun 2021 07:38:20 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUnT-00D8HB-CY; Wed, 30 Jun 2021 07:38:12 +0000 X-UUID: b7321baee2644a53891c37e1c4811ab0-20210630 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=rKDl8LchLGMjH3pGPLk7iyqoKQhlWdGYD3FLNOg+JrE=; b=FdjvecsxumPnSfMOmCaBeSwGCdir7LY4r5cima1ykZLttXejXfqdQdUTdFoiMgU8akvmfwPJe66nPWKfJE5fa+FQ5sf163brS7Mt/NLL6Yp0d8Z+X/rPDhrIs87A0bQbj4DIrmRtclJbBmHOsUwi8+YQAZMxNapKCHATZRNIY44=; X-UUID: b7321baee2644a53891c37e1c4811ab0-20210630 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1358402234; Wed, 30 Jun 2021 00:38:08 -0700 Received: from mtkmbs07n1.mediatek.inc (172.21.101.16) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 00:28:12 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 15:28:10 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 30 Jun 2021 15:28:09 +0800 From: kyrie.wu To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Bin Liu , Matthias Brugger , "Tzung-Bi Shih" CC: , , , , , , Tomasz Figa , , , , kyrie.wu Subject: [PATCH v2,3/9] media: mtk-jpegenc: remove redundant code of irq Date: Wed, 30 Jun 2021 15:27:53 +0800 Message-ID: <1625038079-25815-4-git-send-email-kyrie.wu@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> References: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_003811_516244_DF39E7B8 X-CRM114-Status: GOOD ( 11.86 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org the func of jpgenc irq handler would not compatible, remove those code. Signed-off-by: kyrie.wu --- drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 48 ------------------------- 1 file changed, 48 deletions(-) diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c index 908aa1f..24edd87 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c @@ -1072,54 +1072,6 @@ static void mtk_jpeg_clk_off(struct mtk_jpeg_dev *jpeg) mtk_smi_larb_put(jpeg->larb); } -static irqreturn_t mtk_jpeg_enc_done(struct mtk_jpeg_dev *jpeg) -{ - struct mtk_jpeg_ctx *ctx; - struct vb2_v4l2_buffer *src_buf, *dst_buf; - enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR; - u32 result_size; - - ctx = v4l2_m2m_get_curr_priv(jpeg->m2m_dev); - if (!ctx) { - v4l2_err(&jpeg->v4l2_dev, "Context is NULL\n"); - return IRQ_HANDLED; - } - - src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); - dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); - - result_size = mtk_jpeg_enc_get_file_size(jpeg->reg_base); - vb2_set_plane_payload(&dst_buf->vb2_buf, 0, result_size); - - buf_state = VB2_BUF_STATE_DONE; - - v4l2_m2m_buf_done(src_buf, buf_state); - v4l2_m2m_buf_done(dst_buf, buf_state); - v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); - pm_runtime_put(ctx->jpeg->dev); - return IRQ_HANDLED; -} - -static irqreturn_t mtk_jpeg_enc_irq(int irq, void *priv) -{ - struct mtk_jpeg_dev *jpeg = priv; - u32 irq_status; - irqreturn_t ret = IRQ_NONE; - - cancel_delayed_work(&jpeg->job_timeout_work); - - irq_status = readl(jpeg->reg_base + JPEG_ENC_INT_STS) & - JPEG_ENC_INT_STATUS_MASK_ALLIRQ; - if (irq_status) - writel(0, jpeg->reg_base + JPEG_ENC_INT_STS); - - if (!(irq_status & JPEG_ENC_INT_STATUS_DONE)) - return ret; - - ret = mtk_jpeg_enc_done(jpeg); - return ret; -} - static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv) { struct mtk_jpeg_dev *jpeg = priv; From patchwork Wed Jun 30 07:27:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?S3lyaWUgV3UgKOWQtOaZlyk=?= X-Patchwork-Id: 12351427 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D6F8C11F65 for ; Wed, 30 Jun 2021 07:29:11 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5652A61CE4 for ; Wed, 30 Jun 2021 07:29:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5652A61CE4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2xr8DHDtSD7kp93hagXD8JwqQ7KKUDGfAzg+ZAhYau0=; b=W5owgpGbQhfvfB P3dMHIP0hgWQPrQ+WHfp7cxM0vnFl3e48JDnAO5byAR4SqCyKZpmoRS5IjFh8bKnyjeIGv1Mh+rUH TymPl2wGlDQsgK4I1IjIhNgVc8S9rOop3PN49lhBoF7GSFb8mY0tbqawSrGZDcNPWsWdfgYPSJWFh 1QNaOQzgh/LZLBiZJ+60chhbCY5UuBzsxxfpc7Z9nSMmrFt21sWtxASrVRblQKN2iA9Ms9zIYKJkp e/B+mK+wn81G7VMnuT+8dhsvTHkcPr1/4VuKfz2hAbRb33sDlaD0Fp9NjAo1CmgHNEuHwjPzfn8KD EGFj/Z8aHEgGqr85mTpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUea-00D2x1-5b; Wed, 30 Jun 2021 07:29:00 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUdx-00D2i3-To; Wed, 30 Jun 2021 07:28:23 +0000 X-UUID: 8ce69a71b7b44caabc5ea586c7f7a34d-20210630 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=+mCaUpaUO3TAcCYObWQUI86m46lQ5x16L9yJoHRjHro=; b=ioEqs7UPdNOCEO7JuPkKjppWpQKEwGjZky56vmkl6+XuOT0QJ7YWVZUlXHgnwOmlamaHcw9atpSQZf0AXXDYgi3mf97cD6T2KWhuAem0R8JyQgjjIt6OOthldlQlXTchK38myALA1EuxG9rTX1y7yVsh2PpiqWSiZ8WC+hR2duA=; X-UUID: 8ce69a71b7b44caabc5ea586c7f7a34d-20210630 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 354227374; Wed, 30 Jun 2021 00:28:15 -0700 Received: from MTKMBS07N2.mediatek.inc (172.21.101.141) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 00:28:13 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 15:28:12 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 30 Jun 2021 15:28:11 +0800 From: kyrie.wu To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Bin Liu , Matthias Brugger , "Tzung-Bi Shih" CC: , , , , , , Tomasz Figa , , , , kyrie.wu Subject: [PATCH v2,4/9] media: mtk-jpegenc: Refactor jpeg clock interface Date: Wed, 30 Jun 2021 15:27:54 +0800 Message-ID: <1625038079-25815-5-git-send-email-kyrie.wu@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> References: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_002822_034902_E5E83F74 X-CRM114-Status: GOOD ( 16.30 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Using the needed param for lock on/off function. Signed-off-by: kyrie.wu --- drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 46 ++++++++++++++++++++++++- drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h | 28 +++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c index 24edd87..7c053e3 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c @@ -1053,7 +1053,32 @@ static int mtk_jpeg_queue_init(void *priv, struct vb2_queue *src_vq, static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg) { - int ret; + struct mtk_jpeg_dev *comp_dev; + struct mtk_jpegenc_pm *pm; + struct mtk_jpegenc_clk *jpegclk; + struct mtk_jpegenc_clk_info *clk_info; + int ret, i; + + if (jpeg->variant->is_encoder) { + for (i = 0; i < MTK_JPEGENC_HW_MAX; i++) { + comp_dev = jpeg->hw_dev[i]; + if (!comp_dev) { + dev_err(jpeg->dev, "Failed to get hw dev\n"); + return; + } + + pm = &comp_dev->pm; + jpegclk = &pm->venc_clk; + clk_info = jpegclk->clk_info; + ret = clk_prepare_enable(clk_info->jpegenc_clk); + if (ret) { + dev_err(jpeg->dev, "jpegenc clk enable %d %s fail\n", + i, jpegclk->clk_info->clk_name); + return; + } + } + return; + } ret = mtk_smi_larb_get(jpeg->larb); if (ret) @@ -1067,6 +1092,25 @@ static void mtk_jpeg_clk_on(struct mtk_jpeg_dev *jpeg) static void mtk_jpeg_clk_off(struct mtk_jpeg_dev *jpeg) { + struct mtk_jpeg_dev *comp_dev; + struct mtk_jpegenc_pm *pm; + struct mtk_jpegenc_clk *jpegclk; + int i; + + if (jpeg->variant->is_encoder) { + for (i = 0; i < MTK_JPEGENC_HW_MAX; i++) { + comp_dev = jpeg->hw_dev[i]; + if (!comp_dev) { + dev_err(jpeg->dev, "Failed to get hw dev\n"); + return; + } + + pm = &comp_dev->pm; + jpegclk = &pm->venc_clk; + clk_disable_unprepare(jpegclk->clk_info->jpegenc_clk); + } + return; + } clk_bulk_disable_unprepare(jpeg->variant->num_clks, jpeg->variant->clks); mtk_smi_larb_put(jpeg->larb); diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h index bdbd768..93ea71c 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h @@ -75,6 +75,31 @@ struct mtk_jpeg_variant { u32 cap_q_default_fourcc; }; +enum mtk_jpegenc_hw_id { + MTK_JPEGENC_HW0, + MTK_JPEGENC_HW1, + MTK_JPEGENC_HW_MAX, +}; + +/** * struct mtk_jpegenc_clk_info - Structure used to store clock name */ +struct mtk_jpegenc_clk_info { + const char *clk_name; + struct clk *jpegenc_clk; +}; + +/* struct mtk_vcodec_clk - Structure used to store vcodec clock information */ +struct mtk_jpegenc_clk { + struct mtk_jpegenc_clk_info *clk_info; + int clk_num; +}; + +/** * struct mtk_vcodec_pm - Power management data structure */ +struct mtk_jpegenc_pm { + struct mtk_jpegenc_clk venc_clk; + struct device *dev; + struct mtk_jpeg_dev *mtkdev; +}; + /** * struct mtk_jpeg_dev - JPEG IP abstraction * @lock: the mutex protecting this structure @@ -103,6 +128,9 @@ struct mtk_jpeg_dev { struct device *larb; struct delayed_work job_timeout_work; const struct mtk_jpeg_variant *variant; + + struct mtk_jpeg_dev *hw_dev[MTK_JPEGENC_HW_MAX]; + struct mtk_jpegenc_pm pm; }; /** From patchwork Wed Jun 30 07:27:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?S3lyaWUgV3UgKOWQtOaZlyk=?= X-Patchwork-Id: 12351425 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42DBFC11F65 for ; Wed, 30 Jun 2021 07:28:56 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 66B5D61CD5 for ; Wed, 30 Jun 2021 07:28:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 66B5D61CD5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uDfeD+6yWqD5c/Oez1/Bcl7YHkZhQq8kc6bd6ne5x+w=; b=ZFmxTQryGyBTKo t7M8LeN+QbLqDOA7+jg9rYt3u5t7a1Lku4IswJ9LDngqEQngLSU1PuONlxfZ0Lm6I8IPTI3VpKlzd 2DfG0LU5xBa4WMjxEOaf2RN8Fq4IG4pmZAbZFW8WgUwaHfkSYT9Y+rlSb7qKnGKayUeMFTpHR7xR8 4kMWpgKHeCDK1A1C6h+ePYFDA7WeyZpjmhGcYt6NEwTwk4Q6StUVVJOpoz4EwceU+wfLF/ehuMfmz iNh1SqBnWnlFuF+a9wgoXDiqc5+gbEzaMI7qqX75xvNR2ShYKGWh5CKFC0pkJtB2ZdPNug8loO7co ZBnJDUDRmIW+LBwACUkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUeJ-00D2ql-Mt; Wed, 30 Jun 2021 07:28:43 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUdx-00D2iv-83; Wed, 30 Jun 2021 07:28:23 +0000 X-UUID: f7d0cd5cd5cd4a1f9bf7e5907d4090dd-20210630 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=x7rvrQTabmZ/ehlw9TCDKjiUMiZjMP4mWbART+Rco90=; b=HgXUG/Jq62K5iYMj9nFFSqsbpQMvdAN/ZMVsvKNO9H9CvYVYIL83QImWL8R3zijM/CSSwkL7ss+19JmBZzBQxspf+svi8baXVo8+OHOEQmmpMhtsWDupzpfSFBdJp6ejF5jcrkIMTU83HP47RktutCPPGNu5LGkXXQFmvfT5wa4=; X-UUID: f7d0cd5cd5cd4a1f9bf7e5907d4090dd-20210630 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 540479770; Wed, 30 Jun 2021 00:28:18 -0700 Received: from mtkmbs07n1.mediatek.inc (172.21.101.16) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 00:28:16 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 15:28:14 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 30 Jun 2021 15:28:13 +0800 From: kyrie.wu To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Bin Liu , Matthias Brugger , "Tzung-Bi Shih" CC: , , , , , , Tomasz Figa , , , , kyrie.wu Subject: [PATCH v2, 5/9] media: mtk-jpegenc: Generalize jpeg encode irq interfaces Date: Wed, 30 Jun 2021 15:27:55 +0800 Message-ID: <1625038079-25815-6-git-send-email-kyrie.wu@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> References: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_002821_384625_98299975 X-CRM114-Status: GOOD ( 19.18 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Generalizes jpeg encode irq interfaces to support different hardware. Signed-off-by: kyrie.wu --- drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 124 +++++++++++++++++++++++- drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h | 24 ++++- 2 files changed, 146 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c index 7c053e3..062feab 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c @@ -106,10 +106,40 @@ static struct mtk_jpeg_fmt mtk_jpeg_dec_formats[] = { #define MTK_JPEG_ENC_NUM_FORMATS ARRAY_SIZE(mtk_jpeg_enc_formats) #define MTK_JPEG_DEC_NUM_FORMATS ARRAY_SIZE(mtk_jpeg_dec_formats) +/* + * mtk_jpeg_enc_param: General jpeg encoding parameters + * @enc_w: image width + * @enc_h: image height + * @enable_exif: EXIF enable for jpeg encode mode + * @enc_quality: destination image quality in encode mode + * @enc_format: input image format + * @restart_interval: JPEG restart interval for JPEG encoding + * @img_stride: jpeg encoder image stride + * @mem_stride: jpeg encoder memory stride + * @total_encdu: total 8x8 block number + */ +struct mtk_jpeg_enc_param { + u32 enc_w; + u32 enc_h; + u32 enable_exif; + u32 enc_quality; + u32 enc_format; + u32 restart_interval; + u32 img_stride; + u32 mem_stride; + u32 total_encdu; +}; + struct mtk_jpeg_src_buf { struct vb2_v4l2_buffer b; struct list_head list; + u32 frame_num; + u32 bs_size; + int flags; struct mtk_jpeg_dec_param dec_param; + + struct mtk_jpeg_enc_param enc_param; + struct mtk_jpeg_ctx *curr_ctx; }; static int debug; @@ -1163,6 +1193,98 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv) return IRQ_HANDLED; } +void mtk_jpeg_put_buf(struct mtk_jpeg_dev *jpeg) +{ + struct mtk_jpeg_ctx *ctx; + struct vb2_v4l2_buffer *dst_buffer; + struct list_head *temp_entry; + struct list_head *pos; + struct mtk_jpeg_src_buf *dst_done_buf, *tmp_dst_done_buf; + unsigned long flags; + + ctx = jpeg->hw_param.curr_ctx; + if (!ctx) { + dev_err(jpeg->dev, "comp_jpeg ctx fail !!!\n"); + return; + } + + dst_buffer = jpeg->hw_param.dst_buffer; + if (!dst_buffer) { + dev_err(jpeg->dev, "comp_jpeg dst_buffer fail !!!\n"); + return; + } + + dst_done_buf = mtk_jpeg_vb2_to_srcbuf(&dst_buffer->vb2_buf); + + spin_lock_irqsave(&ctx->done_queue_lock, flags); + list_add_tail(&dst_done_buf->list, &ctx->dst_done_queue); + while (!list_empty(&ctx->dst_done_queue) && + (pos != &ctx->dst_done_queue)) { + list_for_each_prev_safe(pos, temp_entry, + (&ctx->dst_done_queue)) { + tmp_dst_done_buf = list_entry(pos, + struct mtk_jpeg_src_buf, + list); + if (tmp_dst_done_buf->frame_num == + ctx->last_done_frame_num) { + list_del(&tmp_dst_done_buf->list); + v4l2_m2m_buf_done(&tmp_dst_done_buf->b, + VB2_BUF_STATE_DONE); + ctx->last_done_frame_num++; + } + } + } + spin_unlock_irqrestore(&ctx->done_queue_lock, flags); +} + +irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv) +{ + struct mtk_jpeg_dev *jpeg = priv; + struct mtk_jpeg_ctx *ctx; + struct mtk_jpeg_dev *master_jpeg; + struct vb2_v4l2_buffer *src_buf, *dst_buf; + + enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR; + u32 result_size; + u32 irq_status; + + cancel_delayed_work(&jpeg->job_timeout_work); + + src_buf = jpeg->hw_param.src_buffer; + dst_buf = jpeg->hw_param.dst_buffer; + ctx = jpeg->hw_param.curr_ctx; + master_jpeg = ctx->jpeg; + irq_status = readl(jpeg->reg_base[MTK_JPEGENC_HW0] + JPEG_ENC_INT_STS) & + JPEG_ENC_INT_STATUS_MASK_ALLIRQ; + if (irq_status) + writel(0, jpeg->reg_base[MTK_JPEGENC_HW0] + JPEG_ENC_INT_STS); + if (!(irq_status & JPEG_ENC_INT_STATUS_DONE)) { + dev_err(jpeg->dev, "jpeg encode failed !!!\n"); + goto irq_end; + } + + result_size = mtk_jpeg_enc_get_file_size(jpeg->reg_base[0]); + vb2_set_plane_payload(&dst_buf->vb2_buf, 0, result_size); + + buf_state = VB2_BUF_STATE_DONE; + +irq_end: + v4l2_m2m_buf_done(src_buf, buf_state); + mtk_jpeg_put_buf(jpeg); + pm_runtime_put(jpeg->pm.dev); + clk_disable_unprepare(jpeg->pm.venc_clk.clk_info->jpegenc_clk); + if (ctx->fh.m2m_ctx && + (!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->hw_wq); + atomic_inc(&jpeg->hw_rdy); + return IRQ_HANDLED; +} + static void mtk_jpeg_set_default_params(struct mtk_jpeg_ctx *ctx) { struct mtk_jpeg_q_data *q = &ctx->out_q; @@ -1352,7 +1474,7 @@ static int mtk_jpeg_probe(struct platform_device *pdev) INIT_DELAYED_WORK(&jpeg->job_timeout_work, mtk_jpeg_job_timeout_work); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - jpeg->reg_base = devm_ioremap_resource(&pdev->dev, res); + jpeg->reg_base[0] = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(jpeg->reg_base)) { ret = PTR_ERR(jpeg->reg_base); return ret; diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h index 93ea71c..03ff060 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h @@ -75,6 +75,17 @@ struct mtk_jpeg_variant { u32 cap_q_default_fourcc; }; +struct mtk_jpeg_hw_param { + struct vb2_v4l2_buffer *src_buffer; + struct vb2_v4l2_buffer *dst_buffer; + struct mtk_jpeg_ctx *curr_ctx; +}; + +enum mtk_jpeg_hw_state { + MTK_JPEG_HW_IDLE = 0, + MTK_JPEG_HW_BUSY = 1, +}; + enum mtk_jpegenc_hw_id { MTK_JPEGENC_HW0, MTK_JPEGENC_HW1, @@ -124,13 +135,18 @@ struct mtk_jpeg_dev { struct v4l2_m2m_dev *m2m_dev; void *alloc_ctx; struct video_device *vdev; - void __iomem *reg_base; struct device *larb; struct delayed_work job_timeout_work; const struct mtk_jpeg_variant *variant; + void __iomem *reg_base[MTK_JPEGENC_HW_MAX]; + int jpegenc_irq; struct mtk_jpeg_dev *hw_dev[MTK_JPEGENC_HW_MAX]; struct mtk_jpegenc_pm pm; + enum mtk_jpeg_hw_state hw_state; + struct mtk_jpeg_hw_param hw_param; + wait_queue_head_t hw_wq; + atomic_t hw_rdy; }; /** @@ -189,6 +205,12 @@ struct mtk_jpeg_ctx { u8 enc_quality; u8 restart_interval; struct v4l2_ctrl_handler ctrl_hdl; + + struct list_head dst_done_queue; + spinlock_t done_queue_lock; /* spinlock protecting done queue */ + u32 total_frame_num; + u32 last_done_frame_num; + struct work_struct jpeg_work; }; #endif /* _MTK_JPEG_CORE_H */ From patchwork Wed Jun 30 07:27:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?S3lyaWUgV3UgKOWQtOaZlyk=?= X-Patchwork-Id: 12351441 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6A80C11F65 for ; Wed, 30 Jun 2021 07:33:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E82061D01 for ; Wed, 30 Jun 2021 07:33:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E82061D01 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jL1Gzjl6eaKwvpAv3U7kpRhGAZC5T6nQTditOFjbpPk=; b=tzwz0/NuYVsjZj KK3vQBgC60Yd2xDnngcyaSy4YWCBs8d19Of3PINrxd0I9AvCHNqKb2gZ4CZq3kn7ZtM3f55Y1hjNd MXK8s5uBHs5qpQbsMzjWqPOqXrDxECc2M4oeiXgQyq9oIroU//Eu98GUOQH9optyeeBFxJXjHvEYW p1ztS5N+xwF1okvzQ+/mA9PLVkpM695iZwYlsiQCKXvmFBDkKvvV15l1d9iHsSSq+KVNWONYvRN35 /iMGdt4JNWa24tgLpxTAv9gN9syYg379eEA83ZHd75t1VOlhm8ObJwumyZisT64QFRJCiKFGMp+tK fGCBtVppHO/KIzm3qCCg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUj5-00D5bq-Pj; Wed, 30 Jun 2021 07:33:39 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUhr-00D4xP-Ko; Wed, 30 Jun 2021 07:32:25 +0000 X-UUID: ec75c038d99d41bda33b370a7a398162-20210630 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=+dopp3qfa/4Lmdd8bk37wcsxvXpNAAl9wXxDwD1SsG4=; b=Uful+diX6Jo+GGZZ1P3FplTReXrFt56/FpndzypLWz/97JtzQOHKBn3dKgSL496HKdoJVIgF6VoXHvyMncoYxgoONJkqB76fe0Xg9dzrqfNkem5ctHD208hgSyExXeZNhjX7Wo/5IbD6tR7lFOZLys73L82i8JZF/YiwbRpfg9Y=; X-UUID: ec75c038d99d41bda33b370a7a398162-20210630 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1153101145; Wed, 30 Jun 2021 00:32:21 -0700 Received: from MTKMBS07N2.mediatek.inc (172.21.101.141) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 00:28:18 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 15:28:16 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 30 Jun 2021 15:28:15 +0800 From: kyrie.wu To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Bin Liu , Matthias Brugger , "Tzung-Bi Shih" CC: , , , , , , Tomasz Figa , , , , kyrie.wu Subject: [PATCH v2, 6/9] media: mtk-jpegenc: Generalize jpegenc HW timeout interfaces Date: Wed, 30 Jun 2021 15:27:56 +0800 Message-ID: <1625038079-25815-7-git-send-email-kyrie.wu@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> References: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_003223_809070_DB8BEB2E X-CRM114-Status: GOOD ( 11.03 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Generalizes jpegenc HW timeout interfaces to handle HW timeout. Signed-off-by: kyrie.wu --- drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c index 062feab..39101d1 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c @@ -1285,6 +1285,43 @@ irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv) return IRQ_HANDLED; } +void mtk_jpegenc_timeout_work(struct work_struct *work) +{ + struct mtk_jpeg_dev *jpeg = container_of(work, struct mtk_jpeg_dev, + job_timeout_work.work); + struct mtk_jpeg_ctx *ctx; + struct mtk_jpeg_dev *master_jpeg; + struct vb2_v4l2_buffer *src_buf, *dst_buf; + struct mtk_jpeg_src_buf *jpeg_src_buf, *jpeg_dst_buf; + enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR; + + src_buf = jpeg->hw_param.src_buffer; + dst_buf = jpeg->hw_param.dst_buffer; + ctx = jpeg->hw_param.curr_ctx; + if (!ctx) { + v4l2_err(&jpeg->v4l2_dev, "Context is NULL\n"); + return; + } + + master_jpeg = ctx->jpeg; + if (!master_jpeg) { + v4l2_err(&jpeg->v4l2_dev, "master_jpeg is NULL\n"); + return; + } + + jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf); + jpeg_dst_buf = mtk_jpeg_vb2_to_srcbuf(&dst_buf->vb2_buf); + + mtk_jpeg_enc_reset(jpeg->reg_base[MTK_JPEGENC_HW0]); + pm_runtime_put(jpeg->pm.dev); + clk_disable_unprepare(jpeg->pm.venc_clk.clk_info->jpegenc_clk); + jpeg->hw_state = MTK_JPEG_HW_IDLE; + atomic_inc(&jpeg->hw_rdy); + wake_up(&master_jpeg->hw_wq); + v4l2_m2m_buf_done(src_buf, buf_state); + mtk_jpeg_put_buf(jpeg); +} + static void mtk_jpeg_set_default_params(struct mtk_jpeg_ctx *ctx) { struct mtk_jpeg_q_data *q = &ctx->out_q; From patchwork Wed Jun 30 07:27:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?S3lyaWUgV3UgKOWQtOaZlyk=?= X-Patchwork-Id: 12351461 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7206C11F65 for ; Wed, 30 Jun 2021 07:38:28 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 782B861D1B for ; Wed, 30 Jun 2021 07:38:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 782B861D1B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Px9yIIevgA01obLvXBwsQEYWxfI8dKsO0f+h08+mtR0=; b=1yXpzOi5aGXqhn OvQC3bNmsMnaOaFAe8C8VMfLuppxT0XGJGqhRBL77HPQkkclvE6XEVOPGWRhyxW62KdLvA0IAiFfK KBD7H1iLJt2naFqqz9i9Esruq6YdIbm2Lc7LuXe5Y3o9D3MNzTFbvqM6M54B6suHWPmr2Oa+YvZhJ 6LHnnozUhBsmhBo4yk12mC+Ov9SVTZRyH9dB7+JaH1Q17FrbJTNdBAx/Dr4/u8dib2smpaxZcnpqJ bQlmkjGGwjmkoz+6VoRk1olgJUxjiIJcWrp/juSfnHD6gFmfoTCsTU2KZIyTbmoEv2sVhuQt7f6Pe Y7Sgykp4DVaS9SUDwWdA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUnX-00D8LN-P8; Wed, 30 Jun 2021 07:38:15 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUnS-00D8GR-Jw; Wed, 30 Jun 2021 07:38:13 +0000 X-UUID: 1a321beb902d417696aa46e049cd8b17-20210630 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=zQP9kwR3awu+9hP79tQ4HH5oe/ZbOFV6NkDP9AkHEiA=; b=YIjE5QG+GemwujAaGwpsT7TVuN3IyU1zQv3BiU3oNNzra97YLQHyLA2bNjeMaH8Bz//zjAxaO3pUACMs6zk0o4y3IlsikWT76831QvVn8AAtIjsBa73/TZ9I6YUMu5nYTYC3xLfOw6b/h9ufQpS5rx9vPLLYeRavzhOKyCxk80c=; X-UUID: 1a321beb902d417696aa46e049cd8b17-20210630 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1051852373; Wed, 30 Jun 2021 00:38:08 -0700 Received: from MTKMBS07N2.mediatek.inc (172.21.101.141) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 00:28:20 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 15:28:18 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 30 Jun 2021 15:28:18 +0800 From: kyrie.wu To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Bin Liu , Matthias Brugger , "Tzung-Bi Shih" CC: , , , , , , Tomasz Figa , , , , kyrie.wu Subject: [PATCH v2, 7/9] media: mtk-jpegenc: Use component framework to manage each hardware information Date: Wed, 30 Jun 2021 15:27:57 +0800 Message-ID: <1625038079-25815-8-git-send-email-kyrie.wu@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> References: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_003810_730261_F99A55D5 X-CRM114-Status: GOOD ( 26.47 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Uses component framework to manage each hardware information which includes irq/power/clk. The hardware includes jpegenc0, jpegenc1. Signed-off-by: kyrie.wu --- drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 185 +++++++++++++++++--- drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h | 16 +- drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c | 196 ++++++++++++++++++++++ 3 files changed, 372 insertions(+), 25 deletions(-) diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c index 39101d1..bf519ba 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -1493,12 +1494,99 @@ static inline void mtk_jpeg_clk_release(struct mtk_jpeg_dev *jpeg) put_device(jpeg->larb); } +static const struct of_device_id mtk_jpegenc_drv_ids[] = { + { + .compatible = "mediatek,mt8195-jpgenc0", + .data = (void *)MTK_JPEGENC_HW0, + }, + { + .compatible = "mediatek,mt8195-jpgenc1", + .data = (void *)MTK_JPEGENC_HW1, + }, + {}, +}; + +static inline int mtk_vdec_compare_of(struct device *dev, void *data) +{ + return dev->of_node == data; +} + +static inline void mtk_vdec_release_of(struct device *dev, void *data) +{ + of_node_put(data); +} + +static inline int mtk_jpegenc_bind(struct device *dev) +{ + struct mtk_jpeg_dev *data = dev_get_drvdata(dev); + + return component_bind_all(dev, data); +} + +static inline void mtk_jpegenc_unbind(struct device *dev) +{ + struct mtk_jpeg_dev *data = dev_get_drvdata(dev); + + component_unbind_all(dev, data); +} + +static const struct component_master_ops mtk_jpegenc_ops = { + .bind = mtk_jpegenc_bind, + .unbind = mtk_jpegenc_unbind, +}; + +static struct component_match *mtk_jpegenc_match_add(struct mtk_jpeg_dev *jpeg) +{ + struct device *dev = jpeg->dev; + struct component_match *match = NULL; + int i; + char compatible[128] = {0}; + + for (i = 0; i < ARRAY_SIZE(mtk_jpegenc_drv_ids); i++) { + struct device_node *comp_node; + enum mtk_jpegenc_hw_id comp_idx; + const struct of_device_id *of_id; + + memcpy(compatible, mtk_jpegenc_drv_ids[i].compatible, + sizeof(mtk_jpegenc_drv_ids[i].compatible)); + + comp_node = of_find_compatible_node(NULL, NULL, + compatible); + if (!comp_node) + continue; + + if (!of_device_is_available(comp_node)) { + of_node_put(comp_node); + v4l2_err(&jpeg->v4l2_dev, "Fail to get jpeg enc HW node\n"); + continue; + } + + of_id = of_match_node(mtk_jpegenc_drv_ids, comp_node); + if (!of_id) { + v4l2_err(&jpeg->v4l2_dev, "Failed to get match node\n"); + return ERR_PTR(-EINVAL); + } + + comp_idx = (enum mtk_jpegenc_hw_id)of_id->data; + v4l2_info(&jpeg->v4l2_dev, "Get component:hw_id(%d),jpeg_dev(0x%p),comp_node(0x%p)\n", + comp_idx, jpeg, comp_node); + + jpeg->component_node[comp_idx] = comp_node; + + component_match_add_release(dev, &match, mtk_vdec_release_of, + mtk_vdec_compare_of, comp_node); + } + + return match; +} + static int mtk_jpeg_probe(struct platform_device *pdev) { struct mtk_jpeg_dev *jpeg; struct resource *res; int jpeg_irq; int ret; + struct component_match *match; jpeg = devm_kzalloc(&pdev->dev, sizeof(*jpeg), GFP_KERNEL); if (!jpeg) @@ -1510,31 +1598,47 @@ static int mtk_jpeg_probe(struct platform_device *pdev) jpeg->variant = of_device_get_match_data(jpeg->dev); INIT_DELAYED_WORK(&jpeg->job_timeout_work, mtk_jpeg_job_timeout_work); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - jpeg->reg_base[0] = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(jpeg->reg_base)) { - ret = PTR_ERR(jpeg->reg_base); - return ret; - } + if (!jpeg->variant->is_encoder) { + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + jpeg->reg_base[MTK_JPEGENC_HW0] = + devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(jpeg->reg_base[MTK_JPEGENC_HW0])) { + ret = PTR_ERR(jpeg->reg_base[MTK_JPEGENC_HW0]); + return ret; + } - jpeg_irq = platform_get_irq(pdev, 0); - if (jpeg_irq < 0) { - dev_err(&pdev->dev, "Failed to get jpeg_irq %d.\n", jpeg_irq); - return jpeg_irq; - } + jpeg_irq = platform_get_irq(pdev, 0); + if (jpeg_irq < 0) { + dev_err(&pdev->dev, "Failed to get jpeg_irq %d.\n", + jpeg_irq); + 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); - goto err_req_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); + goto err_req_irq; + } - ret = mtk_jpeg_clk_init(jpeg); - if (ret) { - dev_err(&pdev->dev, "Failed to init clk, err %d\n", ret); - goto err_clk_init; + ret = mtk_jpeg_clk_init(jpeg); + if (ret) { + dev_err(&pdev->dev, "Failed to init clk\n"); + goto err_clk_init; + } + } else { + init_waitqueue_head(&jpeg->hw_wq); + + jpeg->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME, + WQ_MEM_RECLAIM | + WQ_FREEZABLE); + if (!jpeg->workqueue) { + dev_err(&pdev->dev, "Failed to create jpeg workqueue!\n"); + ret = -EINVAL; + goto err_alloc_workqueue; + } } ret = v4l2_device_register(&pdev->dev, &jpeg->v4l2_dev); @@ -1583,7 +1687,20 @@ static int mtk_jpeg_probe(struct platform_device *pdev) platform_set_drvdata(pdev, jpeg); - pm_runtime_enable(&pdev->dev); + if (jpeg->variant->is_encoder) { + match = mtk_jpegenc_match_add(jpeg); + if (IS_ERR_OR_NULL(match)) + goto err_vfd_jpeg_register; + + video_set_drvdata(jpeg->vdev, jpeg); + platform_set_drvdata(pdev, jpeg); + ret = component_master_add_with_match(&pdev->dev, + &mtk_jpegenc_ops, match); + if (ret < 0) + goto err_vfd_jpeg_register; + } else { + pm_runtime_enable(&pdev->dev); + } return 0; @@ -1601,6 +1718,8 @@ static int mtk_jpeg_probe(struct platform_device *pdev) err_clk_init: +err_alloc_workqueue: + err_req_irq: return ret; @@ -1721,7 +1840,25 @@ static struct platform_driver mtk_jpeg_driver = { }, }; -module_platform_driver(mtk_jpeg_driver); +static struct platform_driver * const mtk_jpeg_source_drivers[] = { + &mtk_jpegenc_hw_driver, + &mtk_jpeg_driver, +}; + +static int __init mtk_jpeg_init(void) +{ + return platform_register_drivers(mtk_jpeg_source_drivers, + ARRAY_SIZE(mtk_jpeg_source_drivers)); +} + +static void __exit mtk_jpeg_exit(void) +{ + platform_unregister_drivers(mtk_jpeg_source_drivers, + ARRAY_SIZE(mtk_jpeg_source_drivers)); +} + +module_init(mtk_jpeg_init); +module_exit(mtk_jpeg_exit); MODULE_DESCRIPTION("MediaTek JPEG codec driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h index 03ff060..03ef719 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h @@ -125,6 +125,8 @@ struct mtk_jpegenc_pm { * @larb: SMI device * @job_timeout_work: IRQ timeout structure * @variant: driver variant to be used + * @irqlock: spinlock protecting for irq + * @dev_mutex: the mutex protecting for device */ struct mtk_jpeg_dev { struct mutex lock; @@ -136,12 +138,18 @@ struct mtk_jpeg_dev { void *alloc_ctx; struct video_device *vdev; struct device *larb; - struct delayed_work job_timeout_work; const struct mtk_jpeg_variant *variant; + struct clk *clk_jpeg; + struct delayed_work job_timeout_work; + struct platform_device *plat_dev; + spinlock_t irqlock; /* spinlock protecting for irq */ + struct mutex dev_mutex; /* the mutex protecting for device */ void __iomem *reg_base[MTK_JPEGENC_HW_MAX]; int jpegenc_irq; struct mtk_jpeg_dev *hw_dev[MTK_JPEGENC_HW_MAX]; + struct device_node *component_node[MTK_JPEGENC_HW_MAX]; + int comp_idx; struct mtk_jpegenc_pm pm; enum mtk_jpeg_hw_state hw_state; struct mtk_jpeg_hw_param hw_param; @@ -149,6 +157,8 @@ struct mtk_jpeg_dev { atomic_t hw_rdy; }; +extern struct platform_driver mtk_jpegenc_hw_driver; + /** * struct mtk_jpeg_fmt - driver's internal color format data * @fourcc: the fourcc code, 0 if not applicable @@ -194,6 +204,7 @@ struct mtk_jpeg_q_data { * @enc_quality: jpeg encoder quality * @restart_interval: jpeg encoder restart interval * @ctrl_hdl: controls handler + * @done_queue_lock: spinlock protecting for buffer done queue */ struct mtk_jpeg_ctx { struct mtk_jpeg_dev *jpeg; @@ -213,4 +224,7 @@ struct mtk_jpeg_ctx { struct work_struct jpeg_work; }; +void mtk_jpegenc_timeout_work(struct work_struct *work); +irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv); + #endif /* _MTK_JPEG_CORE_H */ diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c index 3da1011..9dc6d99 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c @@ -5,11 +5,21 @@ * */ +#include +#include +#include +#include #include #include +#include +#include +#include +#include +#include #include #include +#include "mtk_jpeg_core.h" #include "mtk_jpeg_enc_hw.h" static const struct mtk_jpeg_enc_qlt mtk_jpeg_enc_quality[] = { @@ -153,6 +163,182 @@ void mtk_jpeg_set_enc_params(struct mtk_jpeg_ctx *ctx, void __iomem *base) writel(ctx->restart_interval, base + JPEG_ENC_RST_MCU_NUM); } +static int mtk_jpegenc_hw_bind(struct device *dev, + struct device *master, void *data) +{ + struct mtk_jpeg_dev *comp_priv = dev_get_drvdata(dev); + struct mtk_jpeg_dev *master_priv = data; + int i; + + for (i = 0; i < MTK_JPEGENC_HW_MAX; i++) { + if (dev->of_node != master_priv->component_node[i]) + continue; + master_priv->hw_dev[i] = comp_priv; + comp_priv->comp_idx = i; + master_priv->reg_base[i] = comp_priv->reg_base[MTK_JPEGENC_HW0]; + break; + } + if (i == MTK_JPEGENC_HW_MAX) { + dev_err(dev, "Failed to get component node\n"); + return -EINVAL; + } + return 0; +} + +static void mtk_jpegenc_hw_unbind(struct device *dev, + struct device *master, void *data) +{ + struct mtk_jpeg_dev *comp_priv = dev_get_drvdata(dev); + + comp_priv->reg_base[MTK_JPEGENC_HW0] = 0; +} + +static const struct component_ops mtk_jpegenc_hw_component_ops = { + .bind = mtk_jpegenc_hw_bind, + .unbind = mtk_jpegenc_hw_unbind, +}; + +int mtk_jpegenc_init_pm(struct mtk_jpeg_dev *mtkdev) +{ + struct platform_device *pdev; + struct mtk_jpegenc_pm *pm; + struct mtk_jpegenc_clk *jpegenc_clk; + struct mtk_jpegenc_clk_info *clk_info; + int i, ret; + + pdev = mtkdev->plat_dev; + pm->dev = &pdev->dev; + pm = &mtkdev->pm; + pm->mtkdev = mtkdev; + jpegenc_clk = &pm->venc_clk; + jpegenc_clk->clk_num = + of_property_count_strings(pdev->dev.of_node, "clock-names"); + if (!jpegenc_clk->clk_num) { + dev_err(&pdev->dev, "Failed to get jpegenc clock count\n"); + return -EINVAL; + } + + jpegenc_clk->clk_info = devm_kcalloc(&pdev->dev, + jpegenc_clk->clk_num, + sizeof(*clk_info), + GFP_KERNEL); + if (!jpegenc_clk->clk_info) + return -ENOMEM; + + for (i = 0; i < jpegenc_clk->clk_num; i++) { + clk_info = &jpegenc_clk->clk_info[i]; + ret = of_property_read_string_index(pdev->dev.of_node, + "clock-names", i, + &clk_info->clk_name); + if (ret) { + dev_err(&pdev->dev, "Failed to get jpegenc clock name\n"); + return ret; + } + + clk_info->jpegenc_clk = devm_clk_get(&pdev->dev, + clk_info->clk_name); + if (IS_ERR(clk_info->jpegenc_clk)) { + dev_err(&pdev->dev, "devm_clk_get (%d)%s fail", + i, clk_info->clk_name); + return PTR_ERR(clk_info->jpegenc_clk); + } + } + + pm_runtime_enable(&pdev->dev); + + return ret; +} + +void mtk_jpegenc_release_pm(struct mtk_jpeg_dev *mtkdev) +{ + struct platform_device *pdev = mtkdev->plat_dev; + + pm_runtime_disable(&pdev->dev); +} + +static int mtk_jpegenc_hw_init_irq(struct mtk_jpeg_dev *dev) +{ + struct platform_device *pdev = dev->plat_dev; + int ret; + + dev->jpegenc_irq = platform_get_irq(pdev, 0); + if (dev->jpegenc_irq < 0) { + dev_err(&pdev->dev, "Failed to get irq resource"); + return dev->jpegenc_irq; + } + + ret = devm_request_irq(&pdev->dev, dev->jpegenc_irq, + mtk_jpegenc_hw_irq_handler, 0, pdev->name, dev); + if (ret) { + dev_err(&pdev->dev, "Failed to devm_request_irq %d (%d)", + dev->jpegenc_irq, ret); + + return -ENOENT; + } + + return 0; +} + +static int mtk_jpegenc_hw_probe(struct platform_device *pdev) +{ + struct mtk_jpeg_dev *dev; + int ret; + + dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); + if (!dev) + return -ENOMEM; + dev->plat_dev = pdev; + spin_lock_init(&dev->irqlock); + mutex_init(&dev->dev_mutex); + atomic_set(&dev->hw_rdy, 1U); + spin_lock_init(&dev->hw_lock); + + dev->hw_state = MTK_JPEG_HW_IDLE; + INIT_DELAYED_WORK(&dev->job_timeout_work, mtk_jpegenc_timeout_work); + + ret = mtk_jpegenc_init_pm(dev); + if (ret) { + dev_err(&pdev->dev, "Failed to get jpeg enc clock source"); + return ret; + } + + dev->reg_base[MTK_JPEGENC_HW0] = + devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR((__force void *)dev->reg_base[MTK_JPEGENC_HW0])) { + ret = PTR_ERR((__force void *)dev->reg_base[MTK_JPEGENC_HW0]); + goto err; + } + + ret = mtk_jpegenc_hw_init_irq(dev); + if (ret) { + dev_err(&pdev->dev, "Failed to register JPEGENC irq handler.\n"); + goto err; + } + + platform_set_drvdata(pdev, dev); + + ret = component_add(&pdev->dev, &mtk_jpegenc_hw_component_ops); + if (ret) { + dev_err(&pdev->dev, "Failed to component_add: %d\n", ret); + goto err; + } + + return 0; + +err: + mtk_jpegenc_release_pm(dev); + return ret; +} + +static int mtk_jpegenc_remove(struct platform_device *pdev) +{ + struct mtk_jpeg_dev *dev = platform_get_drvdata(pdev); + + mtk_jpegenc_release_pm(dev); + + return 0; +} + #if defined(CONFIG_OF) static const struct of_device_id mtk_jpegenc_hw_ids[] = { { @@ -164,3 +350,13 @@ static const struct of_device_id mtk_jpegenc_hw_ids[] = { }; MODULE_DEVICE_TABLE(of, mtk_jpegenc_hw_ids); #endif + +struct platform_driver mtk_jpegenc_hw_driver = { + .probe = mtk_jpegenc_hw_probe, + .remove = mtk_jpegenc_remove, + .driver = { + .name = "mtk-jpegenc-hw", + .of_match_table = of_match_ptr(mtk_jpegenc_hw_ids), + }, +}; + From patchwork Wed Jun 30 07:27:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?S3lyaWUgV3UgKOWQtOaZlyk=?= X-Patchwork-Id: 12351429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34B59C11F65 for ; Wed, 30 Jun 2021 07:32:38 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0142F61CD0 for ; Wed, 30 Jun 2021 07:32:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0142F61CD0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=r1Z9uNXjORO8yLORzVa5kpqqAodeInq7J+DsofOZgxE=; b=kmvOKb6nMR0MMk wOS1l3KM7aash1ueOhEfZ50eHS6ly2afcVRZIfd2jxEZtCO8t4ra+kbBCWscQa/WAakvSOC0JyAwx KEHPRLfAoJarhj9XOzx+b9dgNly9UPMRN/5UNHUPS9xyAEbZReTJnMkPncE19BqEgNATJfzg0wGMj 8Azv1iPdKzAdp/rmSJvU6gGaebwhc7ygvaZpGpOONjgdJTdhtZTBQpJjPOom1s4Cq5YVuPVEwVT1l uBx7XG52SZluQ+58awCzjGoSLCYnpM7MaYyBD3NkCR2+HzB0NpGhvJ+DoaF40Tmf2+leugPi11NuS bTF3eSKvyPFXiz0Ba7sw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUhv-00D51S-Dj; Wed, 30 Jun 2021 07:32:27 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUhq-00D4wg-Gv; Wed, 30 Jun 2021 07:32:24 +0000 X-UUID: 9b9c85b79768472e89b8937ebbc7d317-20210630 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=jfF3FqhEXSgK5SXU/nQ/hxOF8lLd4AdK3vKgwoH6sis=; b=k08TIYrr/cC2TtN29mCyWUMTF1CLDMzB7F4MSyqjaCZaalMhybwJoM0zU6V40s3+Dspu3Ve/N/veMJ/7tZJK47aIDhNfjhDXYlbXiLAAZZ3oMBGQ5FgM/1a3Pw7++Yf+TKbcFKiRPTT09+uEHyg6YVVGi13Usr4Iv+YXgCkT34c=; X-UUID: 9b9c85b79768472e89b8937ebbc7d317-20210630 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 33073240; Wed, 30 Jun 2021 00:32:21 -0700 Received: from mtkmbs07n1.mediatek.inc (172.21.101.16) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 00:28:22 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 15:28:20 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 30 Jun 2021 15:28:20 +0800 From: kyrie.wu To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Bin Liu , Matthias Brugger , "Tzung-Bi Shih" CC: , , , , , , Tomasz Figa , , , , kyrie.wu Subject: [PATCH v2, 8/9] media: mtk-jpegenc: Generalize jpegenc HW operations interfaces Date: Wed, 30 Jun 2021 15:27:58 +0800 Message-ID: <1625038079-25815-9-git-send-email-kyrie.wu@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> References: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_003222_640448_B6708C12 X-CRM114-Status: GOOD ( 13.56 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Generalizes jpegenc select/deselect HW and set params interfaces. Signed-off-by: kyrie.wu --- drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c index bf519ba..0143baf8 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c @@ -939,6 +939,52 @@ static int mtk_jpeg_set_dec_dst(struct mtk_jpeg_ctx *ctx, return 0; } +static int mtk_jpeg_select_hw(struct mtk_jpeg_ctx *ctx) +{ + int hw_id = -1; + int i; + unsigned long flags; + struct mtk_jpeg_dev *jpeg = ctx->jpeg, *comp_jpeg = NULL; + + spin_lock_irqsave(&jpeg->hw_lock, flags); + for (i = 0; i < MTK_JPEGENC_HW_MAX; i++) { + comp_jpeg = jpeg->hw_dev[i]; + if (comp_jpeg->hw_state == MTK_JPEG_HW_IDLE) { + hw_id = i; + comp_jpeg->hw_state = MTK_JPEG_HW_BUSY; + break; + } + } + spin_unlock_irqrestore(&jpeg->hw_lock, flags); + + return hw_id; +} + +static int mtk_jpeg_deselect_hw(struct mtk_jpeg_dev *jpeg, int hw_id) +{ + unsigned long flags; + + spin_lock_irqsave(&jpeg->hw_lock, flags); + jpeg->hw_dev[hw_id]->hw_state = MTK_JPEG_HW_IDLE; + spin_unlock_irqrestore(&jpeg->hw_lock, flags); + + return 0; +} + +static int mtk_jpeg_set_hw_param(struct mtk_jpeg_ctx *ctx, + int hw_id, + struct vb2_v4l2_buffer *src_buf, + struct vb2_v4l2_buffer *dst_buf) +{ + struct mtk_jpeg_dev *jpeg = ctx->jpeg->hw_dev[hw_id]; + + jpeg->hw_param.curr_ctx = ctx; + jpeg->hw_param.src_buffer = src_buf; + jpeg->hw_param.dst_buffer = dst_buf; + + return 0; +} + static void mtk_jpeg_enc_device_run(void *priv) { struct mtk_jpeg_ctx *ctx = priv; From patchwork Wed Jun 30 07:27:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?S3lyaWUgV3UgKOWQtOaZlyk=?= X-Patchwork-Id: 12351465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1378C11F65 for ; Wed, 30 Jun 2021 07:40:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A97B660C3F for ; Wed, 30 Jun 2021 07:40:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A97B660C3F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SPNaIxHaWItkD74t4QK4IY1sNQsnB2NVe0i/W+y1ozk=; b=fo2ShHwBD1moiq crOxuUVVouJAY+z1YCMPZ3eCA+HzP4DxWHhb0hXot6dVre4tlRKUAMAWiTmAkR6apSrW1qPlUFmNy RMo+38C+JYr4iM8gaShGM3llZk1RsE2Z/qfXcShzmO36lDOag0HQGR6KkBpOe4DzDHT3KCz4ifT0H LZ59/tsE+2j/XMIHsItDIJmRJvZqUWa9E+rJi/OHrafxaHsg3nL71QGqlE3V7rgTR4Wnb01FulXkg A6NN4JEs1FnzRTVlJgXYUhJsodlxHhpe1gEilMZRoWUiIjDaIAPDRi4dY+/IkzWmf905JdXckHTFD HfO3L280PjEQM/0pEcQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUpO-00D9Ec-60; Wed, 30 Jun 2021 07:40:10 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyUnt-00D8aD-GO; Wed, 30 Jun 2021 07:38:39 +0000 X-UUID: b7e85b4be29640beb1f66d549e7b7161-20210630 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=hAAqTd87Ivkb5KPR+upcyXIU+gTd67RWai42vi/jBM8=; b=Tq4zJIjIsf9uJnpjJL1uKPdcRHDNduhhcFhwKPS0/pl7UEDWsa0DfiPiSOdXDQwy+vf+A5xuorYoGaOvVL1DAwRNX7n7RR/IOWB9KmmhbyF5yG9HboSi8F/KIi4i4lYb926bYkQgjMxTFOcg1bZjt1DK/PJsxsNUKQdtJMKnEQ0=; X-UUID: b7e85b4be29640beb1f66d549e7b7161-20210630 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1466985736; Wed, 30 Jun 2021 00:38:33 -0700 Received: from MTKMBS07N2.mediatek.inc (172.21.101.141) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 00:28:31 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 15:28:29 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 30 Jun 2021 15:28:22 +0800 From: kyrie.wu To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Bin Liu , Matthias Brugger , "Tzung-Bi Shih" CC: , , , , , , Tomasz Figa , , , , kyrie.wu Subject: [PATCH v2, 9/9] media: mtk-jpegenc: Refactor jpegenc device run interface Date: Wed, 30 Jun 2021 15:27:59 +0800 Message-ID: <1625038079-25815-10-git-send-email-kyrie.wu@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> References: <1625038079-25815-1-git-send-email-kyrie.wu@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210630_003837_623367_33DB6186 X-CRM114-Status: GOOD ( 19.66 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org modify jpegenc device run func interface and add worker for encode Signed-off-by: kyrie.wu --- drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 109 ++++++++++++++++++++---- 1 file changed, 94 insertions(+), 15 deletions(-) diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c index 0143baf8..190e405 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c @@ -985,38 +985,99 @@ static int mtk_jpeg_set_hw_param(struct mtk_jpeg_ctx *ctx, return 0; } -static void mtk_jpeg_enc_device_run(void *priv) +static void mtk_jpegenc_worker(struct work_struct *work) { - struct mtk_jpeg_ctx *ctx = priv; + struct mtk_jpeg_ctx *ctx = container_of(work, struct mtk_jpeg_ctx, + jpeg_work); struct mtk_jpeg_dev *jpeg = ctx->jpeg; + struct mtk_jpeg_dev *comp_jpeg[MTK_JPEGENC_HW_MAX]; struct vb2_v4l2_buffer *src_buf, *dst_buf; enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR; unsigned long flags; - int ret; + struct mtk_jpeg_src_buf *jpeg_src_buf, *jpeg_dst_buf; + int ret, i, hw_id = 0; + atomic_t *hw_rdy[MTK_JPEGENC_HW_MAX]; + struct clk *jpegenc_clk; + + for (i = 0; i < MTK_JPEGENC_HW_MAX; i++) { + comp_jpeg[i] = jpeg->hw_dev[i]; + hw_rdy[i] = &comp_jpeg[i]->hw_rdy; + } + +retry_select: + hw_id = mtk_jpeg_select_hw(ctx); + if (hw_id < 0) { + ret = wait_event_interruptible(jpeg->hw_wq, + (atomic_read(hw_rdy[0]) || + atomic_read(hw_rdy[1])) > 0); + if (ret != 0) { + dev_err(jpeg->dev, "all HW are busy\n"); + v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); + return; + } + dev_err(jpeg->dev, "NEW HW IDLE, please retry selcet!!!\n"); + goto retry_select; + } + atomic_dec(&comp_jpeg[hw_id]->hw_rdy); src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); + if (!src_buf) { + dev_err(jpeg->dev, "get src_buf fail !!!\n"); + goto getbuf_fail; + } + dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); + if (!dst_buf) { + dev_err(jpeg->dev, "get dst_buf fail !!!\n"); + goto getbuf_fail; + } - ret = pm_runtime_get_sync(jpeg->dev); - if (ret < 0) + jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf); + jpeg_dst_buf = mtk_jpeg_vb2_to_srcbuf(&dst_buf->vb2_buf); + + 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; + ctx->total_frame_num++; + + v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); + v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); + + mtk_jpeg_set_hw_param(ctx, hw_id, src_buf, dst_buf); + + ret = pm_runtime_get_sync(comp_jpeg[hw_id]->pm.dev); + if (ret < 0) { + dev_err(jpeg->dev, "pm_runtime_get_sync fail !!!\n"); goto enc_end; + } - schedule_delayed_work(&jpeg->job_timeout_work, - msecs_to_jiffies(MTK_JPEG_HW_TIMEOUT_MSEC)); + jpegenc_clk = comp_jpeg[hw_id]->pm.venc_clk.clk_info->jpegenc_clk; + ret = clk_prepare_enable(jpegenc_clk); + if (ret) { + dev_err(jpeg->dev, "jpegenc clk_prepare_enable fail !!!\n"); + goto enc_end; + } - spin_lock_irqsave(&jpeg->hw_lock, flags); + schedule_delayed_work(&comp_jpeg[hw_id]->job_timeout_work, + msecs_to_jiffies(MTK_JPEG_HW_TIMEOUT_MSEC)); /* * Resetting the hardware every frame is to ensure that all the * registers are cleared. This is a hardware requirement. */ - mtk_jpeg_enc_reset(jpeg->reg_base); - - mtk_jpeg_set_enc_src(ctx, jpeg->reg_base, &src_buf->vb2_buf); - mtk_jpeg_set_enc_dst(ctx, jpeg->reg_base, &dst_buf->vb2_buf); - mtk_jpeg_set_enc_params(ctx, jpeg->reg_base); - mtk_jpeg_enc_start(jpeg->reg_base); - spin_unlock_irqrestore(&jpeg->hw_lock, flags); + spin_lock_irqsave(&comp_jpeg[hw_id]->hw_lock, flags); + mtk_jpeg_enc_reset(comp_jpeg[hw_id]->reg_base[0]); + mtk_jpeg_set_enc_dst(ctx, + comp_jpeg[hw_id]->reg_base[0], + &dst_buf->vb2_buf); + mtk_jpeg_set_enc_src(ctx, + comp_jpeg[hw_id]->reg_base[0], + &src_buf->vb2_buf); + mtk_jpeg_set_enc_params(ctx, comp_jpeg[hw_id]->reg_base[0]); + mtk_jpeg_enc_start(comp_jpeg[hw_id]->reg_base[0]); + v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); + spin_unlock_irqrestore(&comp_jpeg[hw_id]->hw_lock, flags); return; enc_end: @@ -1024,9 +1085,20 @@ static void mtk_jpeg_enc_device_run(void *priv) v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); v4l2_m2m_buf_done(src_buf, buf_state); v4l2_m2m_buf_done(dst_buf, buf_state); +getbuf_fail: + atomic_inc(&comp_jpeg[hw_id]->hw_rdy); + mtk_jpeg_deselect_hw(jpeg, hw_id); v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); } +static void mtk_jpeg_enc_device_run(void *priv) +{ + struct mtk_jpeg_ctx *ctx = priv; + struct mtk_jpeg_dev *jpeg = ctx->jpeg; + + queue_work(jpeg->workqueue, &ctx->jpeg_work); +} + static void mtk_jpeg_dec_device_run(void *priv) { struct mtk_jpeg_ctx *ctx = priv; @@ -1419,6 +1491,11 @@ static int mtk_jpeg_open(struct file *file) goto free; } + if (jpeg->variant->is_encoder) { + INIT_WORK(&ctx->jpeg_work, mtk_jpegenc_worker); + INIT_LIST_HEAD(&ctx->dst_done_queue); + } + v4l2_fh_init(&ctx->fh, vfd); file->private_data = &ctx->fh; v4l2_fh_add(&ctx->fh); @@ -1781,6 +1858,8 @@ static int mtk_jpeg_remove(struct platform_device *pdev) v4l2_m2m_release(jpeg->m2m_dev); v4l2_device_unregister(&jpeg->v4l2_dev); mtk_jpeg_clk_release(jpeg); + flush_workqueue(jpeg->workqueue); + destroy_workqueue(jpeg->workqueue); return 0; }