From patchwork Tue Aug 4 03:40:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xia Jiang X-Patchwork-Id: 256278 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=-11.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_BASE64_TEXT, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY,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 9B9A0C433E3 for ; Tue, 4 Aug 2020 03:41:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9DA1222BED for ; Tue, 4 Aug 2020 03:41:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="EFJHRf5W" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729723AbgHDDlz (ORCPT ); Mon, 3 Aug 2020 23:41:55 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:34765 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729710AbgHDDlz (ORCPT ); Mon, 3 Aug 2020 23:41:55 -0400 X-UUID: 00c439a70f124bb4b4d22e1f1ba59d34-20200804 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=T206XQpMfXYf+0AvODKQPGGQsO7Nm22nEW5m9gZP/gU=; b=EFJHRf5WdNhRdfgHWC/cp3Pooedvtk0+R+3pOucoFnzZalxECC1PHNxqzQ0rCtIiW6CRWyQutXgLerfp36b7Gi8BKeseZWIxlhvnqxGZ1uc71MraY6ap5UNb4Io+ByFwwbFAGyYhKs5xzvQTDnVSxgUQqIvIMSHBKB5eW4ba3Cc=; X-UUID: 00c439a70f124bb4b4d22e1f1ba59d34-20200804 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1675386594; Tue, 04 Aug 2020 11:41:53 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 4 Aug 2020 11:41:51 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 4 Aug 2020 11:41:50 +0800 From: Xia Jiang To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Rick Chang CC: , , , , , Marek Szyprowski , Tomasz Figa , , , , , , Xia Jiang Subject: [PATCH v11 08/28] media: platform: Add mechanism to handle jpeg hardware's locking up Date: Tue, 4 Aug 2020 11:40:42 +0800 Message-ID: <20200804034102.22983-9-xia.jiang@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20200804034102.22983-1-xia.jiang@mediatek.com> References: <20200804034102.22983-1-xia.jiang@mediatek.com> MIME-Version: 1.0 X-MTK: N Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org There is a delayed work scheduled before starting the hardware and canceled in the interrupt handler. If the delayed work is executed, it resets the hardware and reports the failure to V4L2, so that the execution can continue from next frames. Reviewed-by: Tomasz Figa Signed-off-by: Xia Jiang --- v11: no changes --- .../media/platform/mtk-jpeg/mtk_jpeg_core.c | 25 +++++++++++++++++++ .../media/platform/mtk-jpeg/mtk_jpeg_core.h | 4 +++ 2 files changed, 29 insertions(+) -- 2.18.0 diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c index ee4aaf618551..9baeeacb4452 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c @@ -816,6 +816,9 @@ static void mtk_jpeg_device_run(void *priv) if (ret < 0) goto dec_end; + schedule_delayed_work(&jpeg->job_timeout_work, + msecs_to_jiffies(MTK_JPEG_HW_TIMEOUT_MSEC)); + mtk_jpeg_set_dec_src(ctx, &src_buf->vb2_buf, &bs); if (mtk_jpeg_set_dec_dst(ctx, &jpeg_src_buf->dec_param, &dst_buf->vb2_buf, &fb)) goto dec_end; @@ -911,6 +914,8 @@ static irqreturn_t mtk_jpeg_dec_irq(int irq, void *priv) u32 dec_ret; int i; + cancel_delayed_work(&jpeg->job_timeout_work); + dec_ret = mtk_jpeg_dec_get_int_status(jpeg->dec_reg_base); dec_irq_ret = mtk_jpeg_dec_enum_result(dec_ret); ctx = v4l2_m2m_get_curr_priv(jpeg->m2m_dev); @@ -1066,6 +1071,25 @@ static int mtk_jpeg_clk_init(struct mtk_jpeg_dev *jpeg) return PTR_ERR_OR_ZERO(jpeg->clk_jdec_smi); } +static void mtk_jpeg_job_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 vb2_v4l2_buffer *src_buf, *dst_buf; + + ctx = v4l2_m2m_get_curr_priv(jpeg->m2m_dev); + src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); + dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); + + mtk_jpeg_dec_reset(jpeg->dec_reg_base); + + pm_runtime_put(jpeg->dev); + + v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR); + v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_ERROR); + v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); +} static int mtk_jpeg_probe(struct platform_device *pdev) { struct mtk_jpeg_dev *jpeg; @@ -1080,6 +1104,7 @@ static int mtk_jpeg_probe(struct platform_device *pdev) mutex_init(&jpeg->lock); spin_lock_init(&jpeg->hw_lock); jpeg->dev = &pdev->dev; + INIT_DELAYED_WORK(&jpeg->job_timeout_work, mtk_jpeg_job_timeout_work); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); jpeg->dec_reg_base = devm_ioremap_resource(&pdev->dev, res); diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h index 999bd1427809..320c4f8a014a 100644 --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.h @@ -28,6 +28,8 @@ #define MTK_JPEG_DEFAULT_SIZEIMAGE (1 * 1024 * 1024) +#define MTK_JPEG_HW_TIMEOUT_MSEC 1000 + enum mtk_jpeg_ctx_state { MTK_JPEG_INIT = 0, MTK_JPEG_RUNNING, @@ -48,6 +50,7 @@ enum mtk_jpeg_ctx_state { * @clk_jdec: JPEG hw working clock * @clk_jdec_smi: JPEG SMI bus clock * @larb: SMI device + * @job_timeout_work: IRQ timeout structure */ struct mtk_jpeg_dev { struct mutex lock; @@ -62,6 +65,7 @@ struct mtk_jpeg_dev { struct clk *clk_jdec; struct clk *clk_jdec_smi; struct device *larb; + struct delayed_work job_timeout_work; }; /**