From patchwork Mon Jul 13 06:08:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Courbot X-Patchwork-Id: 11658809 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 873D313B1 for ; Mon, 13 Jul 2020 06:10:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B6EC20791 for ; Mon, 13 Jul 2020 06:10:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Aai3HAWx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729037AbgGMGJZ (ORCPT ); Mon, 13 Jul 2020 02:09:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729144AbgGMGJT (ORCPT ); Mon, 13 Jul 2020 02:09:19 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA535C08C5DB for ; Sun, 12 Jul 2020 23:09:19 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id a14so5560817pfi.2 for ; Sun, 12 Jul 2020 23:09:19 -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=od+s8D7sQgTmw85zfRSLd23Y+ImDYFPzNWcvRKsmRCA=; b=Aai3HAWxaz+GjbxPniSs9/JhAru3ScS+cyevS+ZxJ/l5ccQVp9CucQqLRC/b8i9m0g pPkCrb3A6OEQhRzJos63eQ85MSK7RlhNH4iHm2a4TMuJXRFvZ8EuJ2ZC/JxKdzw2uFtr gUd66HFgfByRQnCCefpO5/pBFw0SPpKnIU8Jc= 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=od+s8D7sQgTmw85zfRSLd23Y+ImDYFPzNWcvRKsmRCA=; b=eMfjp0EHhePRNAv9+cET2fOJVfyuyo2e+WlK4PLpDcIFL4ihu/6fpDDCPr2268b44L wMbFn5QGd3MdPfidvzrO8FUde5jciK/CtEqFgZXLYP1F9kMG7kWH3dsHrObvnMMoC3Yf XLWPYdYdGclBMeTy0YR91RleWGzpyhF0zBSzk9BCkxPhV9vU4V5GwW8AEVEVvm1poDek a+vIfXr6EUzXn8FxghG+TIgMeQr0IlYlWVlbaDPDSUokoIFSlj/pOCYQaOVGlpvRvclB UGmh70VVgoTt7uAf8LlCWD0zn0F/c7WTu7g2IjSBmxisBZL5hE3emk3xA+8AtMEfnOpO 4gfA== X-Gm-Message-State: AOAM5329krL+Bc1dGcQUb1SRuz031jATWhXEQ4kpGaHafSb5npZsEWGX QTDG5V/qwyKtsLa/MRzrZAosJA== X-Google-Smtp-Source: ABdhPJxyNM8fIDHdgOQy1/cK6WWjOgJvKXYgZI7TVpcd1Y8lDhvPZ0utoPQ6H5JQk35/uyGkYF88JQ== X-Received: by 2002:a63:b06:: with SMTP id 6mr65423158pgl.116.1594620559230; Sun, 12 Jul 2020 23:09:19 -0700 (PDT) Received: from acourbot.tok.corp.google.com ([2401:fa00:8f:203:eeb1:d7ff:fe57:b7e5]) by smtp.gmail.com with ESMTPSA id c134sm13134934pfc.115.2020.07.12.23.09.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jul 2020 23:09:18 -0700 (PDT) From: Alexandre Courbot To: Tiffany Lin , Andrew-CT Chen , Hans Verkuil , Yunfei Dong , Maoguang Meng Cc: linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Alexandre Courbot Subject: [PATCH v3 03/16] media: mtk-vcodec: add SCP firmware ops Date: Mon, 13 Jul 2020 15:08:29 +0900 Message-Id: <20200713060842.471356-4-acourbot@chromium.org> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog In-Reply-To: <20200713060842.471356-1-acourbot@chromium.org> References: <20200713060842.471356-1-acourbot@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Yunfei Dong Add support for communicating with the SCP firmware, which will be used by MT8183. Signed-off-by: Yunfei Dong [acourbot: refactor, cleanup and split] Co-developed-by: Alexandre Courbot Signed-off-by: Alexandre Courbot Acked-by: Tiffany Lin --- drivers/media/platform/Kconfig | 1 + .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 3 + .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 3 + .../media/platform/mtk-vcodec/mtk_vcodec_fw.c | 56 +++++++++++++++++++ .../media/platform/mtk-vcodec/mtk_vcodec_fw.h | 2 + 5 files changed, 65 insertions(+) diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig index c57ee78fa99d..f0dbe048efea 100644 --- a/drivers/media/platform/Kconfig +++ b/drivers/media/platform/Kconfig @@ -256,6 +256,7 @@ config VIDEO_MEDIATEK_VCODEC select VIDEOBUF2_DMA_CONTIG select V4L2_MEM2MEM_DEV select VIDEO_MEDIATEK_VPU + select MTK_SCP help Mediatek video codec driver provides HW capability to encode and decode in a range of video formats 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 4f07a5fcce7f..5b5765b98e57 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c @@ -225,6 +225,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev) if (!of_property_read_u32(pdev->dev.of_node, "mediatek,vpu", &rproc_phandle)) { fw_type = VPU; + } else if (!of_property_read_u32(pdev->dev.of_node, "mediatek,scp", + &rproc_phandle)) { + fw_type = SCP; } else { mtk_v4l2_err("Could not get vdec IPI device"); return -ENODEV; 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 4340ea10afd0..42530cd01a30 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c @@ -233,6 +233,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev) if (!of_property_read_u32(pdev->dev.of_node, "mediatek,vpu", &rproc_phandle)) { fw_type = VPU; + } else if (!of_property_read_u32(pdev->dev.of_node, "mediatek,scp", + &rproc_phandle)) { + fw_type = SCP; } else { mtk_v4l2_err("Could not get venc IPI device"); return -ENODEV; diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c index 967bb100a990..f2a62ea62fc6 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c @@ -19,6 +19,7 @@ struct mtk_vcodec_fw { enum mtk_vcodec_fw_type type; const struct mtk_vcodec_fw_ops *ops; struct platform_device *pdev; + struct mtk_scp *scp; }; static int mtk_vcodec_vpu_load_firmware(struct mtk_vcodec_fw *fw) @@ -71,6 +72,48 @@ static const struct mtk_vcodec_fw_ops mtk_vcodec_vpu_msg = { .ipi_send = mtk_vcodec_vpu_ipi_send, }; +static int mtk_vcodec_scp_load_firmware(struct mtk_vcodec_fw *fw) +{ + return rproc_boot(scp_get_rproc(fw->scp)); +} + +static unsigned int mtk_vcodec_scp_get_vdec_capa(struct mtk_vcodec_fw *fw) +{ + return scp_get_vdec_hw_capa(fw->scp); +} + +static unsigned int mtk_vcodec_scp_get_venc_capa(struct mtk_vcodec_fw *fw) +{ + return scp_get_venc_hw_capa(fw->scp); +} + +static void *mtk_vcodec_vpu_scp_dm_addr(struct mtk_vcodec_fw *fw, + u32 dtcm_dmem_addr) +{ + return scp_mapping_dm_addr(fw->scp, dtcm_dmem_addr); +} + +static int mtk_vcodec_scp_set_ipi_register(struct mtk_vcodec_fw *fw, int id, + mtk_vcodec_ipi_handler handler, const char *name, void *priv) +{ + return scp_ipi_register(fw->scp, id, handler, priv); +} + +static int mtk_vcodec_scp_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf, + unsigned int len, unsigned int wait) +{ + return scp_ipi_send(fw->scp, id, buf, len, wait); +} + +static const struct mtk_vcodec_fw_ops mtk_vcodec_rproc_msg = { + .load_firmware = mtk_vcodec_scp_load_firmware, + .get_vdec_capa = mtk_vcodec_scp_get_vdec_capa, + .get_venc_capa = mtk_vcodec_scp_get_venc_capa, + .map_dm_addr = mtk_vcodec_vpu_scp_dm_addr, + .ipi_register = mtk_vcodec_scp_set_ipi_register, + .ipi_send = mtk_vcodec_scp_ipi_send, +}; + static void mtk_vcodec_reset_handler(void *priv) { struct mtk_vcodec_dev *dev = priv; @@ -94,6 +137,7 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_select(struct mtk_vcodec_dev *dev, const struct mtk_vcodec_fw_ops *ops; struct mtk_vcodec_fw *fw; struct platform_device *fw_pdev = NULL; + struct mtk_scp *scp = NULL; switch (type) { case VPU: @@ -106,6 +150,14 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_select(struct mtk_vcodec_dev *dev, vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_reset_handler, dev, rst_id); break; + case SCP: + ops = &mtk_vcodec_rproc_msg; + scp = scp_get(dev->plat_dev); + if (!scp) { + mtk_v4l2_err("could not get vdec scp handle"); + return ERR_PTR(-EPROBE_DEFER); + } + break; default: mtk_v4l2_err("invalid vcodec fw type"); return ERR_PTR(-EINVAL); @@ -118,6 +170,7 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_select(struct mtk_vcodec_dev *dev, fw->type = type; fw->ops = ops; fw->pdev = fw_pdev; + fw->scp = scp; return fw; } @@ -129,6 +182,9 @@ void mtk_vcodec_fw_release(struct mtk_vcodec_fw *fw) case VPU: put_device(&fw->pdev->dev); break; + case SCP: + scp_put(fw->scp); + break; } } EXPORT_SYMBOL_GPL(mtk_vcodec_fw_release); diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.h index ff25b0c19f74..ced1b6a10e07 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.h @@ -4,6 +4,7 @@ #define _MTK_VCODEC_FW_H_ #include +#include #include "../mtk-vpu/mtk_vpu.h" @@ -11,6 +12,7 @@ struct mtk_vcodec_dev; enum mtk_vcodec_fw_type { VPU, + SCP, }; struct mtk_vcodec_fw;