From patchwork Wed Jun 13 15:07:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 138485 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp847777lji; Wed, 13 Jun 2018 08:09:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ3+Y5AhDBZsrGPkUwoemg7TxGkRUnbZ4E8QcabFapJkav+c5YFSeXkgivLqiRXSnKprv9B X-Received: by 2002:a62:c4dd:: with SMTP id h90-v6mr5426335pfk.86.1528902571876; Wed, 13 Jun 2018 08:09:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528902571; cv=none; d=google.com; s=arc-20160816; b=J0DCBbFl2AmOW7aarPMECZqfVbgT55PihMALnOYk9MxlX/0RFD+wQ/SFgjV1TldURZ M7LNuRd2nfXfSEPCq4RPV0yehfNlPcQ/E+nrrv8RTumJJFNU5dUeOhqqU5XGhbQ0oovf jpe28BFVA8Hf2v8/d2a3sBqOyGL/UIjMvljml1dLH+nEx5E2/SSIwuuLXDltISW1vqdJ ypEZ+FVo7Gsel9RnZ0N/V5P9tSOhc3at1vfDTo15Z/6xp50qA/Z+e+WL07z9mNfyRjct ev4RpNCY8lBXyTM12gKiqBkHrBh6Cp/px59D9UoDEW+3comrz2sIu4XYcs4ro7l3GR13 he5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=2uDxGwnkJEDIEjqGMUQjkdR51PtdwGqouV1zq5IG5iU=; b=zCr3xq0FHQx+NziGcHO/pP/2mdrml2H7vcp9sSYlFYOnHP2MweBDJFme46wuBqDf1W en1VBQcemDlIFkYPsRL+4FENWbDUAILIWT9idtEyelbwo0OlPGnYVPtnNADUsD7C/Ssv TTb0Sx+eP5BPNaH/gt6j6fDgyuyWcm9C2Gp97LnB7O5WeIfiHkxFG1qsf/Cfv7txvEqw 7AVQTaR1grXlmwiwgibbLT5xmifErZHeCo+8J5SC8+TnXII+8q0l75BVxD8NXnI3gpRC ZSuX0z5Kxb+AxddfvvqmmL053vqa1aiJIkqFuMiNEBBzwIt1okNY24PiEJOZV29JyPdp 0oYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jl4nee7p; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h33-v6si3271727plh.124.2018.06.13.08.09.31; Wed, 13 Jun 2018 08:09:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jl4nee7p; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935723AbeFMPJ3 (ORCPT + 30 others); Wed, 13 Jun 2018 11:09:29 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:37073 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936020AbeFMPJX (ORCPT ); Wed, 13 Jun 2018 11:09:23 -0400 Received: by mail-wr0-f193.google.com with SMTP id d8-v6so3153455wro.4 for ; Wed, 13 Jun 2018 08:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2uDxGwnkJEDIEjqGMUQjkdR51PtdwGqouV1zq5IG5iU=; b=jl4nee7ptqemroRPd0+/SoFQEz/x/Htx5Cxe5LzMiJLqUO2e4Q+lRsDpU2QqJ7JQRW QTeNFnbum3m3xOuqo7RGvKHTm8LtuGl6/uBbrgxcB5uRwnriRW5nbiENzfX1whStWEsj G695U6MawWxjUODxKIi+LHM88wXqZRVp2K1go= 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; bh=2uDxGwnkJEDIEjqGMUQjkdR51PtdwGqouV1zq5IG5iU=; b=eXyOD1ZF9/7c0F2bBHqEBTmkkbM0Y5igeW43ianAgjCj+6mULVQWrw5qoOb6oFBVek QJbH1kSAGU0QKraUn0P+cpU9XO3ZDDG21rUgbcsSRuCqoyj6HrDTRb+TPOMfdqqVFKV6 3069MX48Std7gvE6KD3qRAcf8F2nW1tj3hfbk8ylNoPOIw1KSl//WRML5Xx8mjkvLfBC +DXyxlksui2FewgH2Pv6rwY9SongVfZr7z1HJm83eqyJO6bSzqInwE4tHiYAHwuJJdLJ qLMc9eZjEv3HrQG952TSkRqFMMb3yE5X/VFn1CRwk2rtZ2LM4FWJmJ2GnV4B7ERGK3tD Lftg== X-Gm-Message-State: APt69E23D1Si1HTFib+oRu7kNKfHx/YzbGKUulYFpA1Yf36u9NhQV6zV +3mQjqqiIqHWEHaYvkEcs0wdbw== X-Received: by 2002:adf:99a7:: with SMTP id y36-v6mr4493135wrb.64.1528902562007; Wed, 13 Jun 2018 08:09:22 -0700 (PDT) Received: from mms-0440.qualcomm.mm-sol.com ([37.157.136.206]) by smtp.gmail.com with ESMTPSA id e13-v6sm2886548wrm.45.2018.06.13.08.09.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 08:09:21 -0700 (PDT) From: Stanimir Varbanov To: Mauro Carvalho Chehab , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Vikash Garodia , Tomasz Figa , Stanimir Varbanov Subject: [PATCH v3 11/27] venus: core, helpers: add two more clocks found in Venus 4xx Date: Wed, 13 Jun 2018 18:07:45 +0300 Message-Id: <20180613150801.11702-12-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180613150801.11702-1-stanimir.varbanov@linaro.org> References: <20180613150801.11702-1-stanimir.varbanov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add two more clocks for Venus 4xx in core structure and create a new power enable function to handle it for 3xx/4xx versions. Signed-off-by: Stanimir Varbanov --- drivers/media/platform/qcom/venus/core.h | 4 +++ drivers/media/platform/qcom/venus/helpers.c | 51 +++++++++++++++++++++++++++++ drivers/media/platform/qcom/venus/helpers.h | 2 ++ drivers/media/platform/qcom/venus/vdec.c | 44 ++++++++++++++++++++----- drivers/media/platform/qcom/venus/venc.c | 44 ++++++++++++++++++++----- 5 files changed, 129 insertions(+), 16 deletions(-) -- 2.14.1 diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h index 8d3e150800c9..2bf8839784fa 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -65,6 +65,8 @@ struct venus_format { * @clks: an array of struct clk pointers * @core0_clk: a struct clk pointer for core0 * @core1_clk: a struct clk pointer for core1 + * @core0_bus_clk: a struct clk pointer for core0 bus clock + * @core1_bus_clk: a struct clk pointer for core1 bus clock * @vdev_dec: a reference to video device structure for decoder instances * @vdev_enc: a reference to video device structure for encoder instances * @v4l2_dev: a holder for v4l2 device structure @@ -94,6 +96,8 @@ struct venus_core { struct clk *clks[VIDC_CLKS_NUM_MAX]; struct clk *core0_clk; struct clk *core1_clk; + struct clk *core0_bus_clk; + struct clk *core1_bus_clk; struct video_device *vdev_dec; struct video_device *vdev_enc; struct v4l2_device v4l2_dev; diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c index d9065cc8a7d3..228084e72fb7 100644 --- a/drivers/media/platform/qcom/venus/helpers.c +++ b/drivers/media/platform/qcom/venus/helpers.c @@ -13,6 +13,7 @@ * */ #include +#include #include #include #include @@ -24,6 +25,7 @@ #include "core.h" #include "helpers.h" #include "hfi_helper.h" +#include "hfi_venus_io.h" struct intbuf { struct list_head list; @@ -781,3 +783,52 @@ void venus_helper_init_instance(struct venus_inst *inst) } } EXPORT_SYMBOL_GPL(venus_helper_init_instance); + +int venus_helper_power_enable(struct venus_core *core, u32 session_type, + bool enable) +{ + void __iomem *ctrl, *stat; + u32 val; + int ret; + + if (!IS_V3(core) && !IS_V4(core)) + return 0; + + if (IS_V3(core)) { + if (session_type == VIDC_SESSION_TYPE_DEC) + ctrl = core->base + WRAPPER_VDEC_VCODEC_POWER_CONTROL; + else + ctrl = core->base + WRAPPER_VENC_VCODEC_POWER_CONTROL; + if (enable) + writel(0, ctrl); + else + writel(1, ctrl); + + return 0; + } + + if (session_type == VIDC_SESSION_TYPE_DEC) { + ctrl = core->base + WRAPPER_VCODEC0_MMCC_POWER_CONTROL; + stat = core->base + WRAPPER_VCODEC0_MMCC_POWER_STATUS; + } else { + ctrl = core->base + WRAPPER_VCODEC1_MMCC_POWER_CONTROL; + stat = core->base + WRAPPER_VCODEC1_MMCC_POWER_STATUS; + } + + if (enable) { + writel(0, ctrl); + + ret = readl_poll_timeout(stat, val, val & BIT(1), 1, 100); + if (ret) + return ret; + } else { + writel(1, ctrl); + + ret = readl_poll_timeout(stat, val, !(val & BIT(1)), 1, 100); + if (ret) + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(venus_helper_power_enable); diff --git a/drivers/media/platform/qcom/venus/helpers.h b/drivers/media/platform/qcom/venus/helpers.h index 971392be5df5..0e64aa95624a 100644 --- a/drivers/media/platform/qcom/venus/helpers.h +++ b/drivers/media/platform/qcom/venus/helpers.h @@ -43,4 +43,6 @@ int venus_helper_set_color_format(struct venus_inst *inst, u32 fmt); void venus_helper_acquire_buf_ref(struct vb2_v4l2_buffer *vbuf); void venus_helper_release_buf_ref(struct venus_inst *inst, unsigned int idx); void venus_helper_init_instance(struct venus_inst *inst); +int venus_helper_power_enable(struct venus_core *core, u32 session_type, + bool enable); #endif diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c index 261a51adeef2..3cf243ddcdb8 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -1081,12 +1081,18 @@ static int vdec_probe(struct platform_device *pdev) if (!core) return -EPROBE_DEFER; - if (core->res->hfi_version == HFI_VERSION_3XX) { + if (IS_V3(core) || IS_V4(core)) { core->core0_clk = devm_clk_get(dev, "core"); if (IS_ERR(core->core0_clk)) return PTR_ERR(core->core0_clk); } + if (IS_V4(core)) { + core->core0_bus_clk = devm_clk_get(dev, "bus"); + if (IS_ERR(core->core0_bus_clk)) + return PTR_ERR(core->core0_bus_clk); + } + platform_set_drvdata(pdev, core); vdev = video_device_alloc(); @@ -1131,15 +1137,21 @@ static int vdec_remove(struct platform_device *pdev) static __maybe_unused int vdec_runtime_suspend(struct device *dev) { struct venus_core *core = dev_get_drvdata(dev); + int ret; - if (core->res->hfi_version == HFI_VERSION_1XX) + if (IS_V1(core)) return 0; - writel(0, core->base + WRAPPER_VDEC_VCODEC_POWER_CONTROL); + ret = venus_helper_power_enable(core, VIDC_SESSION_TYPE_DEC, true); + + if (IS_V4(core)) + clk_disable_unprepare(core->core0_bus_clk); + clk_disable_unprepare(core->core0_clk); - writel(1, core->base + WRAPPER_VDEC_VCODEC_POWER_CONTROL); - return 0; + ret |= venus_helper_power_enable(core, VIDC_SESSION_TYPE_DEC, false); + + return ret; } static __maybe_unused int vdec_runtime_resume(struct device *dev) @@ -1147,13 +1159,29 @@ static __maybe_unused int vdec_runtime_resume(struct device *dev) struct venus_core *core = dev_get_drvdata(dev); int ret; - if (core->res->hfi_version == HFI_VERSION_1XX) + if (IS_V1(core)) return 0; - writel(0, core->base + WRAPPER_VDEC_VCODEC_POWER_CONTROL); + ret = venus_helper_power_enable(core, VIDC_SESSION_TYPE_DEC, true); + if (ret) + return ret; + ret = clk_prepare_enable(core->core0_clk); - writel(1, core->base + WRAPPER_VDEC_VCODEC_POWER_CONTROL); + if (ret) + goto err_power_disable; + + if (IS_V4(core)) + ret = clk_prepare_enable(core->core0_bus_clk); + if (ret) + goto err_unprepare_core0; + + return venus_helper_power_enable(core, VIDC_SESSION_TYPE_DEC, false); + +err_unprepare_core0: + clk_disable_unprepare(core->core0_clk); +err_power_disable: + venus_helper_power_enable(core, VIDC_SESSION_TYPE_DEC, false); return ret; } diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c index 947001170a77..2cd7b342b208 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -1225,12 +1225,18 @@ static int venc_probe(struct platform_device *pdev) if (!core) return -EPROBE_DEFER; - if (core->res->hfi_version == HFI_VERSION_3XX) { + if (IS_V3(core) || IS_V4(core)) { core->core1_clk = devm_clk_get(dev, "core"); if (IS_ERR(core->core1_clk)) return PTR_ERR(core->core1_clk); } + if (IS_V4(core)) { + core->core1_bus_clk = devm_clk_get(dev, "bus"); + if (IS_ERR(core->core1_bus_clk)) + return PTR_ERR(core->core1_bus_clk); + } + platform_set_drvdata(pdev, core); vdev = video_device_alloc(); @@ -1275,15 +1281,21 @@ static int venc_remove(struct platform_device *pdev) static __maybe_unused int venc_runtime_suspend(struct device *dev) { struct venus_core *core = dev_get_drvdata(dev); + int ret; - if (core->res->hfi_version == HFI_VERSION_1XX) + if (IS_V1(core)) return 0; - writel(0, core->base + WRAPPER_VENC_VCODEC_POWER_CONTROL); + ret = venus_helper_power_enable(core, VIDC_SESSION_TYPE_ENC, true); + + if (IS_V4(core)) + clk_disable_unprepare(core->core1_bus_clk); + clk_disable_unprepare(core->core1_clk); - writel(1, core->base + WRAPPER_VENC_VCODEC_POWER_CONTROL); - return 0; + ret |= venus_helper_power_enable(core, VIDC_SESSION_TYPE_ENC, false); + + return ret; } static __maybe_unused int venc_runtime_resume(struct device *dev) @@ -1291,13 +1303,29 @@ static __maybe_unused int venc_runtime_resume(struct device *dev) struct venus_core *core = dev_get_drvdata(dev); int ret; - if (core->res->hfi_version == HFI_VERSION_1XX) + if (IS_V1(core)) return 0; - writel(0, core->base + WRAPPER_VENC_VCODEC_POWER_CONTROL); + ret = venus_helper_power_enable(core, VIDC_SESSION_TYPE_ENC, true); + if (ret) + return ret; + ret = clk_prepare_enable(core->core1_clk); - writel(1, core->base + WRAPPER_VENC_VCODEC_POWER_CONTROL); + if (ret) + goto err_power_disable; + + if (IS_V4(core)) + ret = clk_prepare_enable(core->core1_bus_clk); + if (ret) + goto err_unprepare_core1; + + return venus_helper_power_enable(core, VIDC_SESSION_TYPE_ENC, false); + +err_unprepare_core1: + clk_disable_unprepare(core->core1_clk); +err_power_disable: + venus_helper_power_enable(core, VIDC_SESSION_TYPE_ENC, false); return ret; }