From patchwork Tue May 28 05:56:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Courbot X-Patchwork-Id: 10963749 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 43BE414C0 for ; Tue, 28 May 2019 05:57:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32CA42871A for ; Tue, 28 May 2019 05:57:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2686C28725; Tue, 28 May 2019 05:57:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A862C2871A for ; Tue, 28 May 2019 05:57:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Hknu58MxTGpDHPTyzXA2wVVvy7+ECShfqv7kgJVSpn4=; b=dZixJRduYucCL9 52dqRIIt6jjxu4Gs2+J0lfdXdEH2N1PWyUVHI2lnwRwwyyijXGliKyuWHBuQ8aFKX1cjiwprZFb+b wVDYW2SjgZ8O/NkMBv6MhrB2YQYqEiYxLv7bHbJiFNhndkhEJsro8JhdI7ISUZzS8Som68SrfGaUF IKTguqSTU51JDtPA3yW+dp8V+GjzKfbIR4/kmG9i24L57vP6uGBtwclinv1goTUWfB/AtMZdFbBkG W0pel1FoYcYxZ0xzxv+BKxyErWvEik6qTO/u19b7ZYfS/nNUrfQ4ohYhqlscUiz+KIvblKsB389vU jOYr9fbiBYlIQDAe06HQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hVV7M-0002kN-Ap; Tue, 28 May 2019 05:57:48 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hVV7G-0002dD-FP for linux-mediatek@lists.infradead.org; Tue, 28 May 2019 05:57:45 +0000 Received: by mail-pf1-x442.google.com with SMTP id c6so10766681pfa.10 for ; Mon, 27 May 2019 22:57:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z8mj9qGbzot8Xj37nuez+wWnw7XkoYPD1tlUP7ZA3qY=; b=GUdlc/vZi39Kmj7FgkmdCG+O8kOKEKk39Z6dNSk/VYAd7L1TB7MXDZ/TYYkrEQ/qOa aJLBYZdc9afN00AOL3+z1ztKDs8usbb6wS1xFC2qNMg0zV2RDZFS2zK4paCH2pOPxw2X 05f5lVryqfltU1mATDlnZzsjiYfQERqMKjr9A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z8mj9qGbzot8Xj37nuez+wWnw7XkoYPD1tlUP7ZA3qY=; b=t6ipuRJN7uGpAg/Y1cEMKHIJLQMKKdanr0UtKeFWuGsgea2f5/qc/+k/2311O9Jfzd u357vnbYV9UlBokFtviDJxBTt1F34Qod75ogOmfQU5eMOJ2xWuiWJB2DTSf+f2fGp0GT UdPSoM2dn+e7/oKKB4FmgbfLBeZOGPifuhqEBlV1/M2tEVHeMxn9/x+oFRopW3y17CnX oqRda+t8reJdUKHDajlU9UNTUrqxpOqwm/NZfPQAWZYEpQ/yjgfalvuTHmcBlv1mbGln 2OqylFfKUDKX1mWF+LYRWULoZ1ILt/im7MymnbOMVZBQAv5TW1BL1rpg6sRbM9HBMI9K 9OLg== X-Gm-Message-State: APjAAAXhe3l9Bb6OX9bBX3W9aEZjQUgmrmGLPJkRv5bkopbzUAsYLHP0 C0yl2xLjy+8ss0ev14q+qwFlJA== X-Google-Smtp-Source: APXvYqwIV6GdnU24EfH5xLs3vWriiE99LZ1YsYg0z958dKGDjwKOgLO6Gf6ZE/d554C3ffc0PPtXOA== X-Received: by 2002:a65:624f:: with SMTP id q15mr130429358pgv.436.1559023061943; Mon, 27 May 2019 22:57:41 -0700 (PDT) Received: from acourbot.tok.corp.google.com ([2401:fa00:4:4:9712:8cf1:d0f:7d33]) by smtp.gmail.com with ESMTPSA id w1sm13950551pfg.51.2019.05.27.22.57.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 May 2019 22:57:41 -0700 (PDT) From: Alexandre Courbot To: Yunfei Dong , Tiffany Lin , Andrew-CT Chen , Hans Verkuil , Mauro Carvalho Chehab Subject: [RFCv1 11/12] media: mtk-vcodec: vdec: add media device if using stateless api Date: Tue, 28 May 2019 14:56:34 +0900 Message-Id: <20190528055635.12109-12-acourbot@chromium.org> X-Mailer: git-send-email 2.22.0.rc1.257.g3120a18244-goog In-Reply-To: <20190528055635.12109-1-acourbot@chromium.org> References: <20190528055635.12109-1-acourbot@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190527_225742_894093_A1E9C33B X-CRM114-Status: GOOD ( 13.15 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Alexandre Courbot , linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Yunfei Dong The stateless API requires a media device for issuing requests. Add one if it turns out we are using it. Signed-off-by: Yunfei Dong Co-developed-by: Alexandre Courbot Signed-off-by: Alexandre Courbot [acourbot: refactor, cleanup and split] --- drivers/media/platform/Kconfig | 1 + .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 40 +++++++++++++++++++ .../platform/mtk-vcodec/mtk_vcodec_drv.h | 2 + 3 files changed, 43 insertions(+) diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig index 853330c642f1..f5476827259b 100644 --- a/drivers/media/platform/Kconfig +++ b/drivers/media/platform/Kconfig @@ -247,6 +247,7 @@ config VIDEO_MEDIATEK_VCODEC select VIDEOBUF2_DMA_CONTIG select V4L2_MEM2MEM_DEV select VIDEO_MEDIATEK_VPU + select MEDIA_CONTROLLER help Mediatek video codec driver provides HW capability to encode and decode in a range of video formats diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c index ffa6f3d0869d..8be0c04f7e81 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "mtk_vcodec_drv.h" #include "mtk_vcodec_dec.h" @@ -337,6 +338,31 @@ static int mtk_vcodec_probe(struct platform_device *pdev) goto err_event_workq; } + if (dev->vdec_pdata->uses_stateless_api) { + dev->mdev_dec.dev = &pdev->dev; + strscpy(dev->mdev_dec.model, MTK_VCODEC_DEC_NAME, + sizeof(dev->mdev_dec.model)); + + media_device_init(&dev->mdev_dec); + dev->mdev_dec.ops = &mtk_vcodec_media_ops; + dev->v4l2_dev.mdev = &dev->mdev_dec; + + ret = v4l2_m2m_register_media_controller(dev->m2m_dev_dec, + dev->vfd_dec, MEDIA_ENT_F_PROC_VIDEO_DECODER); + if (ret) { + mtk_v4l2_err("Failed to register media controller"); + goto err_reg_cont; + } + + ret = media_device_register(&dev->mdev_dec); + if (ret) { + mtk_v4l2_err("Failed to register media device"); + goto err_media_reg; + } + + mtk_v4l2_debug(0, "media registered as /dev/media%d", + vfd_dec->num); + } ret = video_register_device(vfd_dec, VFL_TYPE_GRABBER, 0); if (ret) { mtk_v4l2_err("Failed to register video device"); @@ -349,6 +375,12 @@ static int mtk_vcodec_probe(struct platform_device *pdev) return 0; err_dec_reg: + if (dev->vdec_pdata->uses_stateless_api) + media_device_unregister(&dev->mdev_dec); +err_media_reg: + if (dev->vdec_pdata->uses_stateless_api) + v4l2_m2m_unregister_media_controller(dev->m2m_dev_dec); +err_reg_cont: destroy_workqueue(dev->decode_workqueue); err_event_workq: v4l2_m2m_release(dev->m2m_dev_dec); @@ -362,6 +394,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev) } extern const struct mtk_vcodec_dec_pdata mtk_frame_8173_pdata; +extern const struct mtk_vcodec_dec_pdata mtk_req_8183_pdata; static const struct of_device_id mtk_vcodec_match[] = { { @@ -379,6 +412,13 @@ static int mtk_vcodec_dec_remove(struct platform_device *pdev) flush_workqueue(dev->decode_workqueue); destroy_workqueue(dev->decode_workqueue); + + if (media_devnode_is_registered(dev->mdev_dec.devnode)) { + media_device_unregister(&dev->mdev_dec); + v4l2_m2m_unregister_media_controller(dev->m2m_dev_dec); + media_device_cleanup(&dev->mdev_dec); + } + if (dev->m2m_dev_dec) v4l2_m2m_release(dev->m2m_dev_dec); diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h index 6ce7b3a14193..38e499bb7d2b 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h @@ -353,6 +353,7 @@ struct mtk_vcodec_dec_pdata { * struct mtk_vcodec_dev - driver data * @v4l2_dev: V4L2 device to register video devices for. * @vfd_dec: Video device for decoder + * @mdev_dec: Media device for decoder * @vfd_enc: Video device for encoder. * * @m2m_dev_dec: m2m device for decoder @@ -389,6 +390,7 @@ struct mtk_vcodec_dec_pdata { struct mtk_vcodec_dev { struct v4l2_device v4l2_dev; struct video_device *vfd_dec; + struct media_device mdev_dec; struct video_device *vfd_enc; struct v4l2_m2m_dev *m2m_dev_dec;