From patchwork Thu Feb 23 08:13:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SXJ1aSBXYW5nICjnjovnkZ4p?= X-Patchwork-Id: 60830 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp200326wrd; Thu, 23 Feb 2023 00:28:47 -0800 (PST) X-Google-Smtp-Source: AK7set/6kC91EkSu3By64cLW9q/MlSFPCkcTlsoJisNH9aP+v6PWldghYd1JG4iT7ySJnW7uUzTE X-Received: by 2002:a05:6a20:548a:b0:c6:d235:ac8c with SMTP id i10-20020a056a20548a00b000c6d235ac8cmr13264277pzk.4.1677140927493; Thu, 23 Feb 2023 00:28:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677140927; cv=none; d=google.com; s=arc-20160816; b=OnXXvSLUkoNC/RLh7dn6Ihkc6nb9tXqlKrB2sZjX69nnYRQnXFwqixhThI4JpltstY V8A0gu7pES8dAxj3IoH9COiV6lpC43IxIY+ZEqTMfjtLsv+o/BtAJTW88R0Qx9+kgn88 vfx41Nl7VOcgjYJVQ9YU1+p9hHhkUIxMbp2H5YqGSnDg/r7zHjccoOamJoa2OkRGEZtn TUcdVnwREKazTXRV/t9h3NJFcauyRoKUwCxKu+G+fC2n6FwJgaNMivPGZK/C/zcCnnlS JPOsP3PuzXnyyqMAEW3XmEdmcGQ0RStZAW3jemUjG/yHeTXSnERd7ZQ4d9ylLUKy8u6X JN2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Gn2kibkOu2BpBaNvPK5fRP0sBK77AQfIg4Roa4SkH2Q=; b=Gl4bF5ajzgrudDfuLIYkUICivmQRKC0qP+QzVAdt9LEocxQS2PABLiac5RZi2Bdy8v XZYkQKhvCoxFkKX+XiH7M0H8xqVpyzk5tcScrRKsgkKQSn10sahfDG3DYjgvlpY8y9gK Q1tHaOOfj3P4/nLc0nHlDYXk8HaEP32q/jcTdSgvFNED1oVkxk/G5ts9q6Ir2oQznBl/ VrUa1cZE5d5ifguJZ4S+OgtrFlDk6SxPJt6IOmjM4sPRFiKEPecWcJX9Psv/tgpgc3Ll Vxp7aEvKVMvdSASdRinO/XjrQ5Eh+1yAFUxolHWgL6P41ICoVFK8/TAyxG2gG3E1jaIs XLcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=e+D7LlVM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a64-20020a639043000000b0049b37046fbcsi4146762pge.391.2023.02.23.00.28.34; Thu, 23 Feb 2023 00:28:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=e+D7LlVM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233556AbjBWINu (ORCPT + 99 others); Thu, 23 Feb 2023 03:13:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233338AbjBWINb (ORCPT ); Thu, 23 Feb 2023 03:13:31 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7CFF498A7; Thu, 23 Feb 2023 00:13:28 -0800 (PST) X-UUID: ef9117e6b35111ed945fc101203acc17-20230223 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=Gn2kibkOu2BpBaNvPK5fRP0sBK77AQfIg4Roa4SkH2Q=; b=e+D7LlVMEpRcYj30QUVcRp1Z21pNGyrr4Exxpd/1ZIq8ykn6fLYGRXkYTUisLz3yVsZ3Q78EYa2F75++Gk7IFNtfFVy1j7anaGykUtOWzgkCl1dQghWgaSV8MLUxX4C3sHEf0bOyuuN+EaU5A+WOzli8WSDznrphXU1JlvODRQ8=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.20,REQID:c5b493c1-79ee-49ad-9967-7170850c1d84,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:70 X-CID-INFO: VERSION:1.1.20,REQID:c5b493c1-79ee-49ad-9967-7170850c1d84,IP:0,URL :0,TC:0,Content:-25,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTI ON:quarantine,TS:70 X-CID-META: VersionHash:25b5999,CLOUDID:b20159b1-beed-4dfc-bd9c-e1b22fa6ccc4,B ulkID:230223161322DDLYE2TR,BulkQuantity:1,Recheck:0,SF:38|29|28|17|19|48,T C:nil,Content:0,EDM:-3,IP:nil,URL:11|1,File:nil,Bulk:43,QS:nil,BEC:nil,COL :0,OSI:0,OSA:0,AV:0 X-CID-BVR: 0,NGT X-UUID: ef9117e6b35111ed945fc101203acc17-20230223 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1897907847; Thu, 23 Feb 2023 16:13:21 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.3; Thu, 23 Feb 2023 16:13:20 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Thu, 23 Feb 2023 16:13:19 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Matthias Brugger , , , kyrie wu CC: , , , , , Tomasz Figa , , , Yunfei Dong , "Irui Wang" Subject: [V1,6/7] media: mtk-jpeg: refactor some variables Date: Thu, 23 Feb 2023 16:13:11 +0800 Message-ID: <20230223081312.29296-7-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230223081312.29296-1-irui.wang@mediatek.com> References: <20230223081312.29296-1-irui.wang@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758609725112609683?= X-GMAIL-MSGID: =?utf-8?q?1758609725112609683?= From: kyrie wu Refactor some variables to reduce redundancy and optimize the initialization process. Signed-off-by: kyrie wu Signed-off-by: irui wang --- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 31 ++++++++++++++----- .../platform/mediatek/jpeg/mtk_jpeg_core.h | 18 ++++------- .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 16 +++------- .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 16 +++------- 4 files changed, 37 insertions(+), 44 deletions(-) diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c index e89195f1989c..ab06c1ee80d4 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c @@ -1004,8 +1004,8 @@ static void mtk_jpegenc_worker(struct work_struct *work) retry_select: hw_id = mtk_jpegenc_get_hw(ctx); if (hw_id < 0) { - ret = wait_event_interruptible(jpeg->enc_hw_wq, - atomic_read(&jpeg->enchw_rdy) > 0); + ret = wait_event_interruptible(jpeg->hw_wq, + atomic_read(&jpeg->hw_rdy) > 0); if (ret != 0 || (i++ > MTK_JPEG_MAX_RETRY_TIME)) { dev_err(jpeg->dev, "%s : %d, all HW are busy\n", __func__, __LINE__); @@ -1016,7 +1016,7 @@ static void mtk_jpegenc_worker(struct work_struct *work) goto retry_select; } - atomic_dec(&jpeg->enchw_rdy); + atomic_dec(&jpeg->hw_rdy); src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); if (!src_buf) goto getbuf_fail; @@ -1073,7 +1073,7 @@ static void mtk_jpegenc_worker(struct work_struct *work) v4l2_m2m_buf_done(src_buf, buf_state); v4l2_m2m_buf_done(dst_buf, buf_state); getbuf_fail: - atomic_inc(&jpeg->enchw_rdy); + atomic_inc(&jpeg->hw_rdy); mtk_jpegenc_put_hw(jpeg, hw_id); v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); } @@ -1198,8 +1198,8 @@ static void mtk_jpegdec_worker(struct work_struct *work) retry_select: hw_id = mtk_jpegdec_get_hw(ctx); if (hw_id < 0) { - ret = wait_event_interruptible_timeout(jpeg->dec_hw_wq, - atomic_read(&jpeg->dechw_rdy) > 0, + ret = wait_event_interruptible_timeout(jpeg->hw_wq, + atomic_read(&jpeg->hw_rdy) > 0, MTK_JPEG_HW_TIMEOUT_MSEC); if (ret != 0 || (i++ > MTK_JPEG_MAX_RETRY_TIME)) { dev_err(jpeg->dev, "%s : %d, all HW are busy\n", @@ -1211,7 +1211,7 @@ static void mtk_jpegdec_worker(struct work_struct *work) goto retry_select; } - atomic_dec(&jpeg->dechw_rdy); + atomic_dec(&jpeg->hw_rdy); src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); if (!src_buf) goto getbuf_fail; @@ -1290,7 +1290,7 @@ static void mtk_jpegdec_worker(struct work_struct *work) v4l2_m2m_buf_done(src_buf, buf_state); v4l2_m2m_buf_done(dst_buf, buf_state); getbuf_fail: - atomic_inc(&jpeg->dechw_rdy); + atomic_inc(&jpeg->hw_rdy); mtk_jpegdec_put_hw(jpeg, hw_id); v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); } @@ -1710,6 +1710,8 @@ static int mtk_jpeg_single_core_init(struct platform_device *pdev, static int mtk_jpeg_probe(struct platform_device *pdev) { struct mtk_jpeg_dev *jpeg; + struct device_node *child; + int num_child = 0; int ret; jpeg = devm_kzalloc(&pdev->dev, sizeof(*jpeg), GFP_KERNEL); @@ -1733,6 +1735,19 @@ static int mtk_jpeg_probe(struct platform_device *pdev) v4l2_err(&jpeg->v4l2_dev, "mtk_jpeg_single_core_init failed."); return -EINVAL; } + } else { + init_waitqueue_head(&jpeg->hw_wq); + + for_each_child_of_node(pdev->dev.of_node, child) + num_child++; + + atomic_set(&jpeg->hw_rdy, num_child); + + jpeg->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME, + WQ_MEM_RECLAIM + | WQ_FREEZABLE); + if (!jpeg->workqueue) + return -EINVAL; } ret = v4l2_device_register(&pdev->dev, &jpeg->v4l2_dev); diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h index 83cf35a12b7a..89242e407dc9 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h @@ -203,14 +203,11 @@ struct mtk_jpegdec_comp_dev { * @job_timeout_work: IRQ timeout structure * @variant: driver variant to be used * @reg_encbase: jpg encode register base addr - * @enc_hw_dev: jpg encode hardware device - * @enc_hw_wq: jpg encode wait queue - * @enchw_rdy: jpg encode hw ready flag + * @enc_hw_dev: jpg encode hardware device + * @hw_wq: jpg wait queue + * @hw_rdy: jpg hw ready flag * @reg_decbase: jpg decode register base addr - * @dec_hw_dev: jpg decode hardware device - * @dec_hw_wq: jpg decode wait queue - * @dec_workqueue: jpg decode work queue - * @dechw_rdy: jpg decode hw ready flag + * @dec_hw_dev: jpg decode hardware device */ struct mtk_jpeg_dev { struct mutex lock; @@ -227,14 +224,11 @@ struct mtk_jpeg_dev { void __iomem *reg_encbase[MTK_JPEGENC_HW_MAX]; struct mtk_jpegenc_comp_dev *enc_hw_dev[MTK_JPEGENC_HW_MAX]; - wait_queue_head_t enc_hw_wq; - atomic_t enchw_rdy; + wait_queue_head_t hw_wq; + atomic_t hw_rdy; void __iomem *reg_decbase[MTK_JPEGDEC_HW_MAX]; struct mtk_jpegdec_comp_dev *dec_hw_dev[MTK_JPEGDEC_HW_MAX]; - wait_queue_head_t dec_hw_wq; - struct workqueue_struct *dec_workqueue; - atomic_t dechw_rdy; }; /** diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c index 5b47bd83c5ce..b7c2de2489b0 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c @@ -503,8 +503,8 @@ static void mtk_jpegdec_timeout_work(struct work_struct *work) clk_disable_unprepare(cjpeg->jdec_clk.clks->clk); pm_runtime_put(cjpeg->dev); cjpeg->hw_state = MTK_JPEG_HW_IDLE; - atomic_inc(&master_jpeg->dechw_rdy); - wake_up(&master_jpeg->dec_hw_wq); + atomic_inc(&master_jpeg->hw_rdy); + wake_up(&master_jpeg->hw_wq); v4l2_m2m_buf_done(src_buf, buf_state); mtk_jpegdec_put_buf(cjpeg); } @@ -551,8 +551,8 @@ static irqreturn_t mtk_jpegdec_hw_irq_handler(int irq, void *priv) clk_disable_unprepare(jpeg->jdec_clk.clks->clk); jpeg->hw_state = MTK_JPEG_HW_IDLE; - wake_up(&master_jpeg->dec_hw_wq); - atomic_inc(&master_jpeg->dechw_rdy); + wake_up(&master_jpeg->hw_wq); + atomic_inc(&master_jpeg->hw_rdy); return IRQ_HANDLED; } @@ -608,20 +608,12 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev) dev->plat_dev = pdev; dev->dev = &pdev->dev; - init_waitqueue_head(&master_dev->dec_hw_wq); - master_dev->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME, - WQ_MEM_RECLAIM - | WQ_FREEZABLE); - if (!master_dev->workqueue) - return -EINVAL; - ret = devm_add_action_or_reset(&pdev->dev, mtk_jpegdec_destroy_workqueue, master_dev->workqueue); if (ret) return ret; - atomic_set(&master_dev->dechw_rdy, MTK_JPEGDEC_HW_MAX); spin_lock_init(&dev->hw_lock); dev->hw_state = MTK_JPEG_HW_IDLE; diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c index c2bc0b531b32..e35ee1bdce3d 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c @@ -248,8 +248,8 @@ static void mtk_jpegenc_timeout_work(struct work_struct *work) clk_disable_unprepare(cjpeg->venc_clk.clks->clk); pm_runtime_put(cjpeg->dev); cjpeg->hw_state = MTK_JPEG_HW_IDLE; - atomic_inc(&master_jpeg->enchw_rdy); - wake_up(&master_jpeg->enc_hw_wq); + atomic_inc(&master_jpeg->hw_rdy); + wake_up(&master_jpeg->hw_wq); v4l2_m2m_buf_done(src_buf, buf_state); mtk_jpegenc_put_buf(cjpeg); } @@ -288,8 +288,8 @@ static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv) clk_disable_unprepare(jpeg->venc_clk.clks->clk); jpeg->hw_state = MTK_JPEG_HW_IDLE; - wake_up(&master_jpeg->enc_hw_wq); - atomic_inc(&master_jpeg->enchw_rdy); + wake_up(&master_jpeg->hw_wq); + atomic_inc(&master_jpeg->hw_rdy); return IRQ_HANDLED; } @@ -340,14 +340,6 @@ static int mtk_jpegenc_hw_probe(struct platform_device *pdev) dev->plat_dev = pdev; dev->dev = &pdev->dev; - init_waitqueue_head(&master_dev->enc_hw_wq); - master_dev->workqueue = alloc_ordered_workqueue(MTK_JPEG_NAME, - WQ_MEM_RECLAIM - | WQ_FREEZABLE); - if (!master_dev->workqueue) - return -EINVAL; - - atomic_set(&master_dev->enchw_rdy, MTK_JPEGENC_HW_MAX); spin_lock_init(&dev->hw_lock); dev->hw_state = MTK_JPEG_HW_IDLE;