Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1088737pxb; Fri, 26 Feb 2021 02:09:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJyVd4YBDuFd7Bt1YDSgCP+TfSc/CernTmrkZ0BVWdP/E53sjsH4P3ccR+NoNS4oULi+S4MV X-Received: by 2002:a17:906:503:: with SMTP id j3mr2491109eja.172.1614334178483; Fri, 26 Feb 2021 02:09:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614334178; cv=none; d=google.com; s=arc-20160816; b=Rnr2GCa3yG8mtcMLsZ2UUzlLsjJywFPE0hSS9pZJzHeQwY5Cxs8695nf5AhsPQ5uzc 4yZUvzmsw6XqpcJJjWIBWWtz48+hAyHEcQ0DliFG7KgnyWAtkjJ5469QaLi2jhmexbwU hTFoT+wxD7fFtr6b1NsiO5XGonvspyqlO4iQmW2VwxsdVMCZPRsbk2QGE1rt8vyw9Fw0 An5T1qCdWEHH2EdxKMwBko2fmGyznR8o4mx7U60cNgU9xMQJ5/fIizH/wpXUDZRo4kDN 7aR/0vtpQSg6dPiHAnvlEKOUECL0WYXu9rhbEQnuTxEvCRBn7VN0StOncQeQ2uQLbUE8 8nvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ULJfNkdw83Y6AFx0P3bzeBO6g6jj3XubfTKkzYBLpyk=; b=wkQCfnU6msxV5DjPkjU3oa5SiKiLfaBJgn0OdDneqcKg0CBLTXFZkiR2GOtjd0qu2C zSRoLyWgoTBqG955z5GKKoxxLC2OBmGV3SjLhzW9bqxFHckCBdaPipPrZiIbhXUdlfcv OiKhdBaS2GOZOz5xnVKU+HT8Gz7D/sNAVaIVI3LKdGl1yE04pM3xta01p2NBeTIKVNqx u/gjApU3ptS1mnT9zVY4tVAqvcl7LOBmabyBbi6hFObrzEbQTFUs1Joj3z720ciu+yaz aZbkTweCaDqlRf7rr8kIU25wqT2UIUiTj4Xdfk5mBJKg1aN74x0Fdr7A+h65z/rqfsby se/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KQ3bT1Cn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e22si5232664edu.9.2021.02.26.02.09.15; Fri, 26 Feb 2021 02:09:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KQ3bT1Cn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230507AbhBZKGx (ORCPT + 99 others); Fri, 26 Feb 2021 05:06:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230518AbhBZKEZ (ORCPT ); Fri, 26 Feb 2021 05:04:25 -0500 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E058C06121D for ; Fri, 26 Feb 2021 02:02:21 -0800 (PST) Received: by mail-pl1-x635.google.com with SMTP id z7so5040647plk.7 for ; Fri, 26 Feb 2021 02:02:21 -0800 (PST) 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=ULJfNkdw83Y6AFx0P3bzeBO6g6jj3XubfTKkzYBLpyk=; b=KQ3bT1Cn8YRGUWPxuuAF7zF/GRt6M4dziANQw9TGeTgcdm4DzIn+ebvMzOuXYtayaD c8JDBvScczV1pZmNf35uF0g3kvsk4dMSoQw3Gmi8V+OPRl+GdqTEyfv2HR/BykeUcj0J KD+hhp8oOwt8cvrP6oBXJUfYlv73hvMi0kVjA= 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=ULJfNkdw83Y6AFx0P3bzeBO6g6jj3XubfTKkzYBLpyk=; b=Bvp2+XHBhlxRevnfiCMpVhyOnu6GwbeZxGB+A/rRha81+MYsMfscEeZwiKP0Z1IpQw 4ibO115zC07ENbCU9yquiBLOF4+KL4DuUmMGdeaBOlwbT7mzTIuNB5LnyrJB5E+YbhXC b1Xxvi5KJwtSeeqL8yCyqUMv9EjBoJ/SqB+j2UMlEJ5YrlUIVpk30R8b+GQkGH/JR1R6 teIkBjVJj9gCI4j0zZNsmOdSQR+LQvAwYpj8WAC3ohvsv0YHG1d2ZDVU8+rXbaknwtZt aQSuvbezV3x+mE1nJY4odJ8G6r9CWS3WXMYF/wKR5b/+OXzj1OjMvi2BM6F6hW8wcnHR 7p4g== X-Gm-Message-State: AOAM533sXtbI9KeOJDNiCgnKtb4uDYM4jb9YNTQlDhmNpjDL87E16bsz ft0UbRQf+fXLbuitvHSlYbV5xQ== X-Received: by 2002:a17:902:8687:b029:e1:601e:bd29 with SMTP id g7-20020a1709028687b02900e1601ebd29mr2363880plo.47.1614333740761; Fri, 26 Feb 2021 02:02:20 -0800 (PST) Received: from acourbot.tok.corp.google.com ([2401:fa00:8f:203:5c91:233c:dd5b:b1b0]) by smtp.gmail.com with ESMTPSA id o23sm9201565pfp.89.2021.02.26.02.02.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Feb 2021 02:02:20 -0800 (PST) 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 v3 07/15] media: mtk-vcodec: vdec: add media device if using stateless api Date: Fri, 26 Feb 2021 19:01:40 +0900 Message-Id: <20210226100148.1663389-8-acourbot@chromium.org> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog In-Reply-To: <20210226100148.1663389-1-acourbot@chromium.org> References: <20210226100148.1663389-1-acourbot@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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 c27db5643712..9d83b4223ecc 100644 --- a/drivers/media/platform/Kconfig +++ b/drivers/media/platform/Kconfig @@ -296,6 +296,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 3b884a321883..79d6a1e6c916 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h @@ -384,6 +384,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 @@ -420,6 +421,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; -- 2.30.1.766.gb4fecdf3b7-goog