From patchwork Tue Apr 27 11:15:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Courbot X-Patchwork-Id: 12226465 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.0 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 65947C433B4 for ; Tue, 27 Apr 2021 11:16:24 +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 B4AF1613DD for ; Tue, 27 Apr 2021 11:16:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B4AF1613DD 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=aY/JWmifgX5dsyMOtYRDFvwCFGm+SzLC53rmyzkgKAs=; b=AT/DJ5i+YQGzp+/XKjhq1gSFl YrI2qPz+khdZ4nJ6wrno7KTglSBTh4arNeVbaH+VX10HyOUSHyH/Q3zZKczSfDTd4RBJDkQoF0cIv k1NlaRMeJov9yPSgFWbNWzUjkVwkGUrZUiVs0iqpTY+puyV39Mmy+EAmw5WCrdxTeLsYId4+UrswN WztIgad5t3iJzq0vXwq3YaT1/QwTduv3e0J28TsZPyZAJmWopLx5UOXxFxs61soXfT+2OQBnkeAej 2BSD6UW1vT5YMvWFbr1wOuKGj3B7fmoQXPecWXTci+BhZbMC3TWbiil9b0javmZipynuoCiVvmGLI ZCZoUbFsQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lbLhK-001Tnp-Jo; Tue, 27 Apr 2021 11:16:10 +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 1lbLhA-001Tkp-79 for linux-mediatek@desiato.infradead.org; Tue, 27 Apr 2021 11:16:00 +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=QD8g8QtMR9mpPcoC1rfeRlCGN5ll1uaX8wQBVCSMJTc=; b=MBwda7L/4E82nNZt+Gx4+VISkr TcBP9+pqlTZMFIyUzSKE8K/wVEnx2pXDioWr2RhPXbXP9KvRZ5ZaPH44Fvr26NxgtG0fmuhmCFpKF qtbtHw5TnrFKBrbaYm8p57aYt1UIRjtx93PRZygmRh4CzBrSxWFHzTJYkA+IaxmuyeZw9iREXpAi2 q4Ecshldyq6w5UJ8MdSuaLiNsJGtkDqrhczkgsLzv4gpJP4n2iMEtrpkgg+rRDRQat2/u6QGkvoDp 4P5N63pKJbckaM6kXpuBri68qs0d7nBrUSnyHqHJrokt0nx+gV4uu6nYiyI1JOX5I39Q0ULksM2MI GAtyLbGQ==; Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lbLh7-00GgE3-09 for linux-mediatek@lists.infradead.org; Tue, 27 Apr 2021 11:15:59 +0000 Received: by mail-pj1-x102b.google.com with SMTP id s14so23850631pjl.5 for ; Tue, 27 Apr 2021 04:15:56 -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=QD8g8QtMR9mpPcoC1rfeRlCGN5ll1uaX8wQBVCSMJTc=; b=nPABj/Cish6SgPUQ8XYvj+SzZyxriG5w8KtoxZytVL9ou5j1X+V0lHPBamQ5xpfwLU ODxrIXIJu5iB6fS4dxfxkhNYt1D1FtIWE/nKty8ToLYWOd6EdtEA/BZs+Fg+7DmmuM7E KqoL4/V4C0Dcg4XhHJ/kLPw4wsjFZieq8vrGY= 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=QD8g8QtMR9mpPcoC1rfeRlCGN5ll1uaX8wQBVCSMJTc=; b=rjjARBRpVr+bC070YUVAL6daONaL4Aaw+hPcccm+L8Agt8SjnMuvBxHRrACdw43B1m pqZPd55EGyGY35t1NyoFymyzjWdsBmgD5MhWWouWFMyjlRpAjD89zp8yyNB/o5YtQ7cP US++mdSUlAVwDVEWHSjYscsYnb3A7AWv+gAnKScgOpGDQERjmmtmRzS7Vd+Qrvukd+PP JGRJ1L+b2OJ4AIy/hKgxdi0Tz4+m3OMhXOl3eebE+K72wfbQEYdDARvtpXfNDXWdDdgH 06IORVRVf2cqr2R/3IBmFFPlpMzHHGOteflI32ckxpuWaXQZ7aP4IT98HizqBCLo9YNo oKxg== X-Gm-Message-State: AOAM5315bQ874Jwkd5Tv0bU3SgYihbX6gJyfWqMSxgFPEkw1WLnVs3ko Bhno1h+AoVG2/q/jz9p4rYTHgA== X-Google-Smtp-Source: ABdhPJz+A9BzLlNjYZM4tpj0FL/5bjM65ep+D5dag3j8sd/V87mnSYXPnrG6LnMogdDf4JNPZdeq5g== X-Received: by 2002:a17:902:b209:b029:ed:10cd:859e with SMTP id t9-20020a170902b209b02900ed10cd859emr14200359plr.19.1619522156275; Tue, 27 Apr 2021 04:15:56 -0700 (PDT) Received: from acourbot.tok.corp.google.com ([2401:fa00:8f:203:b182:d363:32d0:53a2]) by smtp.gmail.com with ESMTPSA id c21sm2347210pfc.165.2021.04.27.04.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Apr 2021 04:15:55 -0700 (PDT) From: Alexandre Courbot To: Tiffany Lin , Andrew-CT Chen , Rob Herring , Yunfei Dong Cc: Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Alexandre Courbot Subject: [PATCH v4 07/15] media: mtk-vcodec: vdec: add media device if using stateless api Date: Tue, 27 Apr 2021 20:15:18 +0900 Message-Id: <20210427111526.1772293-8-acourbot@chromium.org> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog In-Reply-To: <20210427111526.1772293-1-acourbot@chromium.org> References: <20210427111526.1772293-1-acourbot@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210427_041557_066561_E10BDFDF X-CRM114-Status: GOOD ( 15.29 ) 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 --- drivers/media/platform/Kconfig | 1 + .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 39 +++++++++++++++++++ .../platform/mtk-vcodec/mtk_vcodec_drv.h | 2 + 3 files changed, 42 insertions(+) diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig index ae1468aa1b4e..4154fdec2efb 100644 --- a/drivers/media/platform/Kconfig +++ b/drivers/media/platform/Kconfig @@ -315,6 +315,7 @@ 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 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 533781d4680a..e942e28f96fe 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" @@ -324,6 +325,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"); @@ -336,6 +362,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); @@ -368,6 +400,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 78d4a7728ddf..10edd238c939 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h @@ -383,6 +383,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 @@ -418,6 +419,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;