From patchwork Wed May 19 14:30:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Courbot X-Patchwork-Id: 12267629 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.1 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,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 68418C43460 for ; Wed, 19 May 2021 14:31:44 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 E81516135C for ; Wed, 19 May 2021 14:31:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E81516135C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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=desiato.20200630; 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=U1PvFAkSJqq3Gxf3VTdAdpFuhn3yxAbXc7sROJFHnr8=; b=pDSRER5u3A6JjyjXgufmBs+Gt qim2uhGvh2PIPTAdu1aHguy+Zu0Ry7CZs+ebrCcic+mbNnsjqtl/wm91KBqldMpLtxdMO1WVCix41 kG4/hJp3Tm80eXXVZnoM6nlc3HQIiAi9zzMEN6nE/mI0zsW5ia65f8sBJOsb3SAhzPztKbci+oiGc 3EPE9CQEerNE7o9iM0owskbSaA5g8zCIwwYoxzj6HUggbuldtWx/1yKKMNysKqB8abUwjyhi5uYkP 47VuyLjTR82MrcPAVaeVbcopV13u1t/mHbglujM2idKk8IRPur5rQrr5+Lr/syZzzbORHmmTRsdoR Eo3VMNsOg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1ljNEK-004Grz-SV; Wed, 19 May 2021 14:31:25 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljNEC-004GoG-IW for linux-mediatek@desiato.infradead.org; Wed, 19 May 2021 14:31:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=8y/ha/FPZsoMxbJFZEZYOwhwW0U101I92QCL32b5TqE=; b=T1yCK2a2x0TG2QqV6lmugkWmO4 /W6gUtXKVYhvw8TF+K431BmxvfzuPNMTf0ceqoI99nL5JcYkxHq8DIeZ0WV5fmU8VAESKKDbtmArE cgJMsUJ/VzXNkvJIs9xOZkTq+U4taQsFu1ANJprg/hMLfajYUtaSDzvOCcApGlxxVJSdZj2ZsnmQq ogkPsqHrgjRrizEfT0vIDOY36Oq7KvELfZTZ6DpP/Ync3fBa2j7ezqigEb0Q0s49rG4gm9UUsfXRp q7rRB9/nwfAzvFC43uQnuWWw8mCwxMpv+t62UvVt9d/WSCkP93NbUHnmZl1ZBY94SX7EvW19Qu5VN STiN8JkA==; Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ljNE9-00FXup-Uy for linux-mediatek@lists.infradead.org; Wed, 19 May 2021 14:31:15 +0000 Received: by mail-pj1-x1036.google.com with SMTP id ep16-20020a17090ae650b029015d00f578a8so3513946pjb.2 for ; Wed, 19 May 2021 07:31:12 -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=8y/ha/FPZsoMxbJFZEZYOwhwW0U101I92QCL32b5TqE=; b=avfaESek715RFTyXbq05MZ8Vdjq8zqgoj94kiVAF40We4ACV28aYRmUATUEx2a+o0p FWc3ZUZhutO6JOsmp9GcHh/bknAu53T3mI7seM/oExf03iTJUv+3FlHsl3ynix8gVJek iw7XQhTM1Pd3etGONo3sxQhrA4a/HIFs3FmMM= 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=8y/ha/FPZsoMxbJFZEZYOwhwW0U101I92QCL32b5TqE=; b=Qy+0nhbmbC2KKFyE8w/b0qy4X8dwHb/b0x9CtAVkeoQbGKB6OfJmFBbjzF/jRrBQ63 jcKPtQ3uKa4cbX6ahQSw+YN1rm+9SW9dIQksJvxpk3qZ6Y4A3qsrgo4Vrjik48EzEhgA x2ZeTOMx0dvMLZuQ71AnSmKTfyLfShncLRy7vhlch6ektKyDcmc5i3l86/g8uIfhtyAO pEhcDnSPZfL/BbZy6wOkMT0Z8g/DUPM/LWQLgWZeFwHrM46XA1epazWnvhj36njGpxAr EOAC0p/upJvzHxy2nNPLSTPFzy24hH0bd4LCQjksNXznUwoircmwWq4k6BxHQ5hy0uQM nl8w== X-Gm-Message-State: AOAM531HuRV9u/pwhsOsRxpbugSanCTPEZX1ljvlTjo+XRrlY0TBtkBp pRA4OvZMASDmScHrXDTolbzJiA== X-Google-Smtp-Source: ABdhPJxH1tz01Q0da2mWDlUrbzufgc5do6iCp33WKQ3N+uuhUKbAuRp+mujPPpU3Fx+PiXm2gLYqlg== X-Received: by 2002:a17:90a:e291:: with SMTP id d17mr11342081pjz.42.1621434672130; Wed, 19 May 2021 07:31:12 -0700 (PDT) Received: from acourbot.tok.corp.google.com ([2401:fa00:8f:203:87ab:ff82:1544:697]) by smtp.gmail.com with ESMTPSA id 3sm14337661pff.132.2021.05.19.07.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 May 2021 07:31:11 -0700 (PDT) From: Alexandre Courbot To: Tiffany Lin , Andrew-CT Chen , Hans Verkuil , Dafna Hirschfeld , Yunfei Dong Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Alexandre Courbot Subject: [PATCH v5 12/14] media: mtk-vcodec: vdec: add media device if using stateless api Date: Wed, 19 May 2021 23:30:09 +0900 Message-Id: <20210519143011.1175546-13-acourbot@chromium.org> X-Mailer: git-send-email 2.31.1.751.gd2f1c929bd-goog In-Reply-To: <20210519143011.1175546-1-acourbot@chromium.org> References: <20210519143011.1175546-1-acourbot@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210519_073114_003902_436B122A X-CRM114-Status: GOOD ( 15.48 ) 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 From: Yunfei Dong The stateless API requires a media device for issuing requests. Add one if we are being instantiated as a stateless decoder. Signed-off-by: Yunfei Dong [acourbot: refactor, cleanup and split] Co-developed-by: Alexandre Courbot Signed-off-by: Alexandre Courbot Reviewed-by: Tzung-Bi Shih --- drivers/media/platform/Kconfig | 2 + .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 39 +++++++++++++++++++ .../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 ae1468aa1b4e..aa277a19e275 100644 --- a/drivers/media/platform/Kconfig +++ b/drivers/media/platform/Kconfig @@ -315,6 +315,8 @@ config VIDEO_MEDIATEK_VCODEC select VIDEO_MEDIATEK_VCODEC_VPU if VIDEO_MEDIATEK_VPU select VIDEO_MEDIATEK_VCODEC_SCP if MTK_SCP select V4L2_H264 + select MEDIA_CONTROLLER + select MEDIA_CONTROLLER_REQUEST_API help Mediatek video codec driver provides HW capability to encode and decode in a range of video formats on MT8173 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 1460951f302c..f1e9261cbcf0 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "mtk_vcodec_drv.h" #include "mtk_vcodec_dec.h" @@ -316,6 +317,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_VIDEO, 0); if (ret) { mtk_v4l2_err("Failed to register video device"); @@ -328,6 +354,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); @@ -360,6 +392,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 e0737165ecdc..1b61d722d313 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h @@ -387,6 +387,7 @@ struct mtk_vcodec_enc_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 @@ -422,6 +423,7 @@ struct mtk_vcodec_enc_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;