Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp292365pxb; Thu, 25 Feb 2021 02:41:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJzqDl1LcUlxfTP9QaT64yqSJm6dncKrwXl0khLzJET4FCVS9zSTwesNTFTRW4JL4w8B37WI X-Received: by 2002:a17:907:3e04:: with SMTP id hp4mr2152985ejc.188.1614249687837; Thu, 25 Feb 2021 02:41:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614249687; cv=none; d=google.com; s=arc-20160816; b=A6/H4Lj/iXDx+DOdxwFAZ05KDrrayv4sNwqgPHsycxkWhhL+wS1p1VtQBVUPxFApI9 VpEN63intlnYitTo/yTQ7pIxghbK+gBG1+K2NzRszASC2rOgQd8Sz8m/hbveEv894fs1 q6JeFmaFPe+mX4pGjUtvErqXP6Qa4gqFUlAfTGfFNBy8nkek/lfWmJICeoHeNwfjWITb o1qwc3/y+q5T/lSaBhooGNnZXuKf7M29E7ERDLxCZiEhcKoh13wDTMqoZWTRjNOr2Mh/ O8OKYhapM4IcVg1REwBFjvgQpfy+LeEcsTdXJbrwzriw7XKGnFXmRoCKKyv9Vq8ABBDS 5rTQ== 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=rPds8Sv7GUEEyk1zAIR4OmJkrFu7mzc9HWc+V93Z198=; b=qRx9qCjZ6xOaqevnvzHZlbB+ZUEf24G0IdLSeMgfFZjS1rBnYkZ9NvujvHBjmyMPow im+c2Hn6+fYxA6YnIfuTYLt1Pj7JwOSTw3zqqYjGv6BPVr50Q0ajcbAj7Ay0WcJ/q+cn p2SkHlEeI/urtRd41xwOm/OIeij5ece37SV0p0F9PTZc7hGNmvDQe9MHB3UwwTGuUayh ZmFJj+Z3FUEUWue2UVSxfyO+XJMT1vlMubVIJEeuU40aHh9hF9yBSnxESRjqmIr9kXaG kdx1Di6QV93vuhstqWSmBZolv5K7uMeSjGHG73yHGb9iAp/jgt5ERnZpgg/j2hDfk4Os 0v+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CKCsGqiA; 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 e13si2874998eds.140.2021.02.25.02.41.05; Thu, 25 Feb 2021 02:41:27 -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=CKCsGqiA; 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 S235092AbhBYKkY (ORCPT + 99 others); Thu, 25 Feb 2021 05:40:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235425AbhBYKSL (ORCPT ); Thu, 25 Feb 2021 05:18:11 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB63AC061221 for ; Thu, 25 Feb 2021 02:16:43 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id u12so3016612pjr.2 for ; Thu, 25 Feb 2021 02:16:43 -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=rPds8Sv7GUEEyk1zAIR4OmJkrFu7mzc9HWc+V93Z198=; b=CKCsGqiAB/HRbKsOO7yduvsdNknZ8XUSNFN//yKVMirfy2a2RDYD8QFKysTP49c9JN MJfnyRH3fgCHajl3+wef+FuzDmmwE6GeU2X1USMZlwMVJpWK4jBGTes8e+WKuDJl39SN gh08iC6o/idUnrGwqb5H2Hl1BmrYSJkXpPNz0= 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=rPds8Sv7GUEEyk1zAIR4OmJkrFu7mzc9HWc+V93Z198=; b=QQelMBaYb2RsjPo31iF5psqgx2m61w/qLy8cLpChF04YZdBLE06iQS7pL3p1RLk3mF gi+HCvvi5LJsKwR/0iRh4CZiGZrMZXqK5iw+nYr+0PsrZJe5MOnSeut+LU/Ckj7I59s4 h0IpSzMwc+wqysIE+iOCY3/nVwf3WOdCZQTYu3uMIgoadUVPOTax/PdcdFzLF16kIdIN /a4+ivmUKOSSMaddh95bWY28aj9huuozQc0ksBxRUCbd19CpFbIF5+XmfrQyh9FtVXqY cZQjYucSP+Kdn9wzUVWex8JJXN5VRpN+MAs/08PrYEdDWHvKtsLCAyQYmCFLAJFclNHW +Nug== X-Gm-Message-State: AOAM533Q2ZHoDPCScQ8WKyDODpTamI5HYoUPRcBsOJST3xWApetWFNk+ n575TkivJLiMf9qLPoTUj2mUnmt9zYRQ3w== X-Received: by 2002:a17:902:9304:b029:e4:12f4:bdb0 with SMTP id bc4-20020a1709029304b02900e412f4bdb0mr2483934plb.55.1614248203466; Thu, 25 Feb 2021 02:16:43 -0800 (PST) Received: from acourbot.tok.corp.google.com ([2401:fa00:8f:203:2550:3154:2c53:b6e7]) by smtp.gmail.com with ESMTPSA id z2sm5848193pfc.8.2021.02.25.02.16.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Feb 2021 02:16:42 -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 v2 6/8] media: mtk-vcodec: vdec: add media device if using stateless api Date: Thu, 25 Feb 2021 19:16:10 +0900 Message-Id: <20210225101612.2832444-7-acourbot@chromium.org> X-Mailer: git-send-email 2.30.0.617.g56c4b15f3c-goog In-Reply-To: <20210225101612.2832444-1-acourbot@chromium.org> References: <20210225101612.2832444-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.0.617.g56c4b15f3c-goog