From patchwork Thu Mar 17 08:22:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Irui Wang X-Patchwork-Id: 12783751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 02335C433F5 for ; Thu, 17 Mar 2022 08:36:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=gjgCRdM6SxoU7T9dePnh/9vRCerS1yBnTWj/s+Vz0tw=; b=V1Iw7PMyqmRqsu eDfi+iYbEqzWshGx6AaJzBsEORQGUZUqzKcm1ys9E0FdE0g0PzSHoVgYcvQljezbAx1sT1bz5daTR e+f1fBr9pOLauzJG8RuBvAR7SA0TSo0BnKdAKRz0TT/1geDPPSIASm0xHcdug+BU0XrvFePyLC5Qx Daq44L8uXtAnCtW3UmRQpYWqP6oHvtihTEqRdT5jGH8xHQcc16FZ69QSE8psh7rWe9zITygpqp4qb 4WhyQFrB86V8jhqCHY4SutgusFFCdnIG4JJKBqp5xdouu5vogkyje2iFZNgfaD62YkCq8KJDdiwmW QDRJ498Oq0yupVqE9ofQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUlbM-00FLyR-TK; Thu, 17 Mar 2022 08:35:21 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nUlZS-00FKmS-Sc; Thu, 17 Mar 2022 08:33:25 +0000 X-UUID: a7b04e4f3bc3449db8bc67207e03a962-20220317 X-UUID: a7b04e4f3bc3449db8bc67207e03a962-20220317 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1630042119; Thu, 17 Mar 2022 01:33:14 -0700 Received: from mtkmbs10n2.mediatek.inc (172.21.101.183) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 17 Mar 2022 01:23:11 -0700 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Thu, 17 Mar 2022 16:23:09 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 17 Mar 2022 16:23:07 +0800 From: Irui Wang To: Hans Verkuil , Tzung-Bi Shih , Rob Herring , Alexandre Courbot , Mauro Carvalho Chehab , Matthias Brugger , Tomasz Figa , , Yong Wu , Tiffany Lin , Andrew-CT Chen CC: Hsin-Yi Wang , Maoguang Meng , Longfei Wang , Yunfei Dong , Fritz Koenig , Irui Wang , , , , , , , Subject: [PATCH v3, 04/10] media: mtk-vcodec: Enable venc dual core usage Date: Thu, 17 Mar 2022 16:22:24 +0800 Message-ID: <20220317082230.23622-5-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220317082230.23622-1-irui.wang@mediatek.com> References: <20220317082230.23622-1-irui.wang@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220317_013323_018010_D1237643 X-CRM114-Status: GOOD ( 31.69 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Adds new property to indicate whether the encoder has multiple cores. Use of_platform_populate to probe each venc cores, the core device can use the init_clk/request_irq helper to initialize their own power/clk/irq, and the main device doesn't need use these helper anymore. Signed-off-by: Irui Wang --- drivers/media/platform/mtk-vcodec/Makefile | 4 +- .../platform/mtk-vcodec/mtk_vcodec_drv.h | 14 ++ .../platform/mtk-vcodec/mtk_vcodec_enc_core.c | 138 ++++++++++++++++++ .../platform/mtk-vcodec/mtk_vcodec_enc_core.h | 36 +++++ .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 77 +++++----- 5 files changed, 235 insertions(+), 34 deletions(-) create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.h diff --git a/drivers/media/platform/mtk-vcodec/Makefile b/drivers/media/platform/mtk-vcodec/Makefile index 93e7a343b5b0..c472b221bd6b 100644 --- a/drivers/media/platform/mtk-vcodec/Makefile +++ b/drivers/media/platform/mtk-vcodec/Makefile @@ -3,7 +3,8 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-dec.o \ mtk-vcodec-enc.o \ mtk-vcodec-common.o \ - mtk-vcodec-dec-hw.o + mtk-vcodec-dec-hw.o \ + mtk-vcodec-enc-core.o mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ vdec/vdec_vp8_if.o \ @@ -32,6 +33,7 @@ mtk-vcodec-enc-y := venc/venc_vp8_if.o \ venc_drv_if.o \ venc_vpu_if.o \ +mtk-vcodec-enc-core-y := mtk_vcodec_enc_core.o mtk-vcodec-common-y := mtk_vcodec_intr.o \ mtk_vcodec_util.o \ diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h index 3affb2d4a4ec..43e1349d6a54 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h @@ -117,6 +117,15 @@ enum mtk_vdec_hw_count { MTK_VDEC_MAX_HW_COUNT, }; +/* + * enum mtk_venc_core_id -- encoder core id + */ +enum mtk_venc_core_id { + MTK_VENC_CORE0 = 0, + MTK_VENC_CORE1, + MTK_VENC_CORE_MAX, +}; + /* * struct mtk_video_fmt - Structure used to store information about pixelformats */ @@ -476,6 +485,8 @@ struct mtk_vcodec_enc_pdata { * @subdev_dev: subdev hardware device * @subdev_prob_done: check whether all used hw device is prob done * @subdev_bitmap: used to record hardware is ready or not + * @venc_multi_core: indicates whether the encoder has multiple cores or not + * @enc_core_dev: used to store venc core device */ struct mtk_vcodec_dev { struct v4l2_device v4l2_dev; @@ -521,6 +532,9 @@ struct mtk_vcodec_dev { void *subdev_dev[MTK_VDEC_HW_MAX]; int (*subdev_prob_done)(struct mtk_vcodec_dev *vdec_dev); DECLARE_BITMAP(subdev_bitmap, MTK_VDEC_HW_MAX); + + bool venc_multi_core; + void *enc_core_dev[MTK_VENC_CORE_MAX]; }; static inline struct mtk_vcodec_ctx *fh_to_ctx(struct v4l2_fh *fh) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c new file mode 100644 index 000000000000..9d3ea5a8afe4 --- /dev/null +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c @@ -0,0 +1,138 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2021 MediaTek Inc. + */ + +#include +#include +#include +#include +#include +#include + +#include "mtk_vcodec_drv.h" +#include "mtk_vcodec_enc.h" +#include "mtk_vcodec_enc_core.h" +#include "mtk_vcodec_intr.h" + +static const struct of_device_id mtk_venc_core_ids[] = { + { + .compatible = "mediatek,mtk-venc-core", + }, + {}, +}; +MODULE_DEVICE_TABLE(of, mtk_venc_core_ids); + +static void clean_irq_status(unsigned int irq_status, void __iomem *addr) +{ + if (irq_status & MTK_VENC_IRQ_STATUS_PAUSE) + writel(MTK_VENC_IRQ_STATUS_PAUSE, addr); + + if (irq_status & MTK_VENC_IRQ_STATUS_SWITCH) + writel(MTK_VENC_IRQ_STATUS_SWITCH, addr); + + if (irq_status & MTK_VENC_IRQ_STATUS_DRAM) + writel(MTK_VENC_IRQ_STATUS_DRAM, addr); + + if (irq_status & MTK_VENC_IRQ_STATUS_SPS) + writel(MTK_VENC_IRQ_STATUS_SPS, addr); + + if (irq_status & MTK_VENC_IRQ_STATUS_PPS) + writel(MTK_VENC_IRQ_STATUS_PPS, addr); + + if (irq_status & MTK_VENC_IRQ_STATUS_FRM) + writel(MTK_VENC_IRQ_STATUS_FRM, addr); +} + +static irqreturn_t mtk_enc_core_irq_handler(int irq, void *priv) +{ + struct mtk_venc_core_dev *core = priv; + struct mtk_vcodec_ctx *ctx; + unsigned long flags; + void __iomem *addr; + + spin_lock_irqsave(&core->main_dev->irqlock, flags); + ctx = core->curr_ctx; + spin_unlock_irqrestore(&core->main_dev->irqlock, flags); + if (!ctx) + return IRQ_HANDLED; + + mtk_v4l2_debug(1, "id=%d core :%d", ctx->id, core->core_id); + + addr = core->reg_base + MTK_VENC_IRQ_ACK_OFFSET; + ctx->irq_status = readl(core->reg_base + MTK_VENC_IRQ_STATUS_OFFSET); + clean_irq_status(ctx->irq_status, addr); + + wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0); + return IRQ_HANDLED; +} + +static int mtk_venc_core_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct mtk_venc_core_dev *core; + struct mtk_vcodec_dev *main_dev; + int ret; + + if (!dev->parent) + return dev_err_probe(dev, -ENODEV, + "No parent for venc core device\n"); + + main_dev = dev_get_drvdata(dev->parent); + if (!main_dev) + return dev_err_probe(dev, -EINVAL, + "Failed to get parent driver data\n"); + + core = devm_kzalloc(&pdev->dev, sizeof(*core), GFP_KERNEL); + if (!core) + return dev_err_probe(dev, -ENOMEM, + "Failed to get alloc core data\n"); + + core->plat_dev = pdev; + + platform_set_drvdata(pdev, core); + + core->reg_base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(core->reg_base)) + return dev_err_probe(dev, PTR_ERR(core->reg_base), + "Failed to get reg base\n"); + + core->enc_irq = platform_get_irq(pdev, 0); + if (core->enc_irq < 0) + return dev_err_probe(dev, -EINVAL, + "Failed to get irq resource\n"); + + ret = devm_request_irq(dev, core->enc_irq, + mtk_enc_core_irq_handler, 0, + pdev->name, core); + if (ret) + return dev_err_probe(dev, -EINVAL, + "Failed to install core->enc_irq %d\n", + core->enc_irq); + + of_property_read_u32(dev->of_node, "mediatek,core-id", + &core->core_id); + + if (core->core_id < 0 || core->core_id >= MTK_VENC_CORE_MAX) + return dev_err_probe(dev, -EINVAL, + "Invalid core id %d\n", core->core_id); + + main_dev->enc_core_dev[core->core_id] = core; + core->main_dev = main_dev; + + dev_dbg(dev, "Venc core :%d probe done\n", core->core_id); + + return 0; +} + +static struct platform_driver mtk_venc_core_driver = { + .probe = mtk_venc_core_probe, + .driver = { + .name = "mtk-venc-core", + .of_match_table = mtk_venc_core_ids, + }, +}; +module_platform_driver(mtk_venc_core_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Mediatek video encoder core driver"); diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.h new file mode 100644 index 000000000000..9c0f661509df --- /dev/null +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2021 MediaTek Inc. + */ + +#ifndef _MTK_VCODEC_ENC_CORE_H_ +#define _MTK_VCODEC_ENC_CORE_H_ + +#include +#include "mtk_vcodec_drv.h" + +/** + * struct mtk_venc_core_dev - driver data + * @plat_dev: platform_device + * @main_dev: main device + * @pm: power management data + * @curr_ctx: the context that is waiting for venc hardware + * @reg_base: mapped address of venc registers + * @irq_status: venc core irq status + * @enc_irq: venc device irq + * @core id: for venc core id: core#0, core#1... + */ +struct mtk_venc_core_dev { + struct platform_device *plat_dev; + struct mtk_vcodec_dev *main_dev; + + struct mtk_vcodec_pm pm; + struct mtk_vcodec_ctx *curr_ctx; + + void __iomem *reg_base; + unsigned int irq_status; + int enc_irq; + int core_id; +}; + +#endif /* _MTK_VCODEC_ENC_CORE_H_ */ diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c index f12f887e4bdc..d540d52191d9 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c @@ -230,10 +230,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev) { struct mtk_vcodec_dev *dev; struct video_device *vfd_enc; - struct resource *res; phandle rproc_phandle; enum mtk_vcodec_fw_type fw_type; - int ret; + int ret, core_type; dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); if (!dev) @@ -259,39 +258,48 @@ static int mtk_vcodec_probe(struct platform_device *pdev) return PTR_ERR(dev->fw_handler); dev->venc_pdata = of_device_get_match_data(&pdev->dev); - ret = mtk_vcodec_init_enc_clk(dev); - if (ret < 0) { - dev_err(&pdev->dev, "Failed to get mtk vcodec clock source!"); - goto err_enc_pm; + core_type = dev->venc_pdata->core_type; + + if (of_property_read_bool(pdev->dev.of_node, + "mediatek,venc-multi-core")) { + dev->venc_multi_core = true; + ret = of_platform_populate(pdev->dev.of_node, + NULL, NULL, &pdev->dev); + if (ret) { + mtk_v4l2_err("Venc main device populate failed"); + goto err_enc_pm; + } } - pm_runtime_enable(&pdev->dev); + if (!dev->venc_multi_core) { + ret = mtk_vcodec_init_enc_clk(dev); + if (ret < 0) { + dev_err(&pdev->dev, + "Failed to get mtk vcodec clock source!"); + goto err_enc_pm; + } - dev->reg_base[dev->venc_pdata->core_type] = - devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(dev->reg_base[dev->venc_pdata->core_type])) { - ret = PTR_ERR(dev->reg_base[dev->venc_pdata->core_type]); - goto err_res; - } + pm_runtime_enable(&pdev->dev); - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (res == NULL) { - dev_err(&pdev->dev, "failed to get irq resource"); - ret = -ENOENT; - goto err_res; - } + dev->reg_base[core_type] = + devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(dev->reg_base[core_type])) { + ret = PTR_ERR(dev->reg_base[core_type]); + goto err_res; + } - dev->enc_irq = platform_get_irq(pdev, 0); - irq_set_status_flags(dev->enc_irq, IRQ_NOAUTOEN); - ret = devm_request_irq(&pdev->dev, dev->enc_irq, - mtk_vcodec_enc_irq_handler, - 0, pdev->name, dev); - if (ret) { - dev_err(&pdev->dev, - "Failed to install dev->enc_irq %d (%d) core_type (%d)", - dev->enc_irq, ret, dev->venc_pdata->core_type); - ret = -EINVAL; - goto err_res; + dev->enc_irq = platform_get_irq(pdev, 0); + irq_set_status_flags(dev->enc_irq, IRQ_NOAUTOEN); + ret = devm_request_irq(&pdev->dev, dev->enc_irq, + mtk_vcodec_enc_irq_handler, + 0, pdev->name, dev); + if (ret) { + dev_err(&pdev->dev, + "Failed to install irq %d (%d) core_type (%d)", + dev->enc_irq, ret, core_type); + ret = -EINVAL; + goto err_res; + } } mutex_init(&dev->enc_mutex); @@ -358,7 +366,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev) } mtk_v4l2_debug(0, "encoder %d registered as /dev/video%d", - dev->venc_pdata->core_type, vfd_enc->num); + core_type, vfd_enc->num); return 0; @@ -371,7 +379,8 @@ static int mtk_vcodec_probe(struct platform_device *pdev) err_enc_alloc: v4l2_device_unregister(&dev->v4l2_dev); err_res: - pm_runtime_disable(dev->pm.dev); + if (!dev->venc_multi_core) + pm_runtime_disable(dev->pm.dev); err_enc_pm: mtk_vcodec_fw_release(dev->fw_handler); return ret; @@ -455,7 +464,9 @@ static int mtk_vcodec_enc_remove(struct platform_device *pdev) video_unregister_device(dev->vfd_enc); v4l2_device_unregister(&dev->v4l2_dev); - pm_runtime_disable(dev->pm.dev); + if (!dev->venc_multi_core) + pm_runtime_disable(dev->pm.dev); + mtk_vcodec_fw_release(dev->fw_handler); return 0; }