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: 12267599 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,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 B3AB2C433B4 for ; Wed, 19 May 2021 14:31:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92A7E61353 for ; Wed, 19 May 2021 14:31:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354247AbhESOc7 (ORCPT ); Wed, 19 May 2021 10:32:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354123AbhESOck (ORCPT ); Wed, 19 May 2021 10:32:40 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8783BC06138F for ; Wed, 19 May 2021 07:31:12 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id ot16so5479391pjb.3 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=WD5GqJfWnDHMIdCV/0m4N83f1YVuutP1pTisfz9tMfVaNHlqvkCq9mEHfNZq7sJF39 4jDDfpN61HImNC2tMCflZzizvMAh+FgTpKp2dOGlQ06YhjjTlAopnAu3NqxvV0iR9ri2 2YynuSDZLV1h9G8IRh6eF79hVcmHpg6FwfpIRqOtZFC5xGtCeWZFtvB+rXTasOkpv4FA JSLCoyEZjc6Ns+TIU8sv9umjTq3KMHo/9KGEbYTdisBqQCLV4Y3fK5Z/ishGCOzcn1am 3hRUBNxsZtC5GLsriDnomYdktTgTzmeVGmpkn8yKzyDArmS4+CM0kN3t2/KAgza9xzgi Ldvg== X-Gm-Message-State: AOAM530X60K0678kZDQpIOQZTPDmksOHGXQvPmJB64J+YVrUri4taXt8 9b70cVuQJkgfTivJZKuHwT0EAQ== 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 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.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;