Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp266795imm; Tue, 15 May 2018 01:08:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrveVo5WO1Dm+boHY7H1CPd9vD7Gh+RwvaAy4KqOiwXZhBjpHwtBrALDHzcA8/TXvkypLBM X-Received: by 2002:a62:981d:: with SMTP id q29-v6mr14047348pfd.65.1526371710034; Tue, 15 May 2018 01:08:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526371710; cv=none; d=google.com; s=arc-20160816; b=vPmpQofxJjRLAuWqhaLJsUhutjkyTnBfYEc0a7sW8xqo2kmdYw9JufMMaHKRShRbS6 rxbb/tyDoEntz8vOM544tEaw5gNYMt+RnwTUc2Q2FGjbp4AKQw33pHG15VqIVEIWk3ye 2IxChb2T5qBvQRDb442LBOx03J1d0b0xcMbdQ8GFRNsWLbSSR5GcyHldaIEwWScYSRy5 6KEHq4GLK32Trj5+hehkSd4ZhdZDxFF8qOXK7t0O45JElZoeg2a0aM6v9LqBvG3zCUVE mFsLBBaAZKDvcIC8dIFpl1XYDzvMKkG84c3HM9Bqb2Btj/Ne/MyHD7ukX5H//jjdqu/D MuAQ== 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=AgTV2frz+JnsXbRehwAah0N6hQFx1qc3MEVpSuKS6yo=; b=Qg++WRI0rkzC6f6UreZ7jQZpnxeELoYGzRl/ouxHjfIJBGnk2sRaEIUiNXY1fv7Z6g u2AxR6/KWPrnKr9spTFniG97Ac6izBbmuNkjj7xVLcaqyW87LodG1VojXqO6uzYr8n7U lL6BnFM0kq8bguea7Tdj2TMGg/SCSHemd/rtx1v2kVqQ+qCgdu92OW8R7K2XDJO5AQp/ dgrnSvqYMAywvvPzMes3+L0PQLItI/utx0Jbz8VGvnSEkBU46cbx969r7oeYxgGARozF qnk7risiD0dxRYu3K0ksbDsQGmlW/p79QiAwR30wBhmxpOXyjCFOIYU3un3pd3n2rauu NwpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vp7Agj9r; 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 w18-v6si12149376pfl.359.2018.05.15.01.08.15; Tue, 15 May 2018 01:08:29 -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=Vp7Agj9r; 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 S1752547AbeEOIGf (ORCPT + 99 others); Tue, 15 May 2018 04:06:35 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:54958 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752305AbeEOH7n (ORCPT ); Tue, 15 May 2018 03:59:43 -0400 Received: by mail-wm0-f68.google.com with SMTP id f6-v6so17674494wmc.4 for ; Tue, 15 May 2018 00:59:42 -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=AgTV2frz+JnsXbRehwAah0N6hQFx1qc3MEVpSuKS6yo=; b=Vp7Agj9r55QTUylf22aPaVCnsOoqN7gzjBr79YPqelDDl686HMqfdRgG5JdchcAkHn euGbxAxh0z5otqbRJiHewH/9cBvqEE2tzkGXn4ewOvssO09m4gzAPQRY3Hpk7Le8R2xt WRitdZfiEChTslvcWV5dEW8hiBw6pTMis9xZM= 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=AgTV2frz+JnsXbRehwAah0N6hQFx1qc3MEVpSuKS6yo=; b=drU4bISGR9kT2MPYYx1J4OcK6VuVmkEpSJwiaZnCHSJ8QKMMz9Vd7RdgXafZl8CTvL 76Uj9ELZGRwxunxBpePlSuYUznome9DdHDHPoj6WnWT39ld7vRP7MdA8b87QfyQXXiEX ufgHoIyX7leGtDZ/9pX0f0lVYV70ta/tnSppXxmVPYjU+0jfWMCgZ2d6CMaY/3iUooXO nKua4TSfrvEWfEjMkJw/ElYOmG1fnek4BoXjZVSgsRpqtSbzKk4u2WKWWlDrhe/B+LES Kt2WD6yxowV2l6sO0Az9OTAmMtZ9FBVwGdVB5i7m78pAiAYEUN1rvyMlVXznu7UMBpTX rS0g== X-Gm-Message-State: ALKqPwf6z+4hdcDtQz1JGhfxBPQqpffaN4oEQqiXp03bfuHhvTwdyFzM CaTfpHgFtJR0o9JFnwy15SN43g== X-Received: by 2002:a1c:7c05:: with SMTP id x5-v6mr6605882wmc.7.1526371181646; Tue, 15 May 2018 00:59:41 -0700 (PDT) Received: from mms-0440.qualcomm.mm-sol.com ([37.157.136.206]) by smtp.gmail.com with ESMTPSA id 4-v6sm10918510wmg.40.2018.05.15.00.59.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 May 2018 00:59:40 -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 , Stanimir Varbanov Subject: [PATCH v2 13/29] venus: helpers: make a commmon function for power_enable Date: Tue, 15 May 2018 10:58:43 +0300 Message-Id: <20180515075859.17217-14-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180515075859.17217-1-stanimir.varbanov@linaro.org> References: <20180515075859.17217-1-stanimir.varbanov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make common function which will enable power when enabling/disabling clocks and also covers Venus 3xx/4xx versions. Signed-off-by: Stanimir Varbanov --- drivers/media/platform/qcom/venus/helpers.c | 51 +++++++++++++++++++++++++++++ drivers/media/platform/qcom/venus/helpers.h | 2 ++ drivers/media/platform/qcom/venus/vdec.c | 25 ++++---------- drivers/media/platform/qcom/venus/venc.c | 25 ++++---------- 4 files changed, 67 insertions(+), 36 deletions(-) diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c index d9065cc8a7d3..2b21f6ed7502 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 -EINVAL; + + 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 3b38bd1241b0..2bd81de6328a 100644 --- a/drivers/media/platform/qcom/venus/vdec.c +++ b/drivers/media/platform/qcom/venus/vdec.c @@ -1123,26 +1123,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 (IS_V1(core)) return 0; - if (IS_V3(core)) - writel(0, core->base + WRAPPER_VDEC_VCODEC_POWER_CONTROL); - else if (IS_V4(core)) - writel(0, core->base + WRAPPER_VCODEC0_MMCC_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); - if (IS_V3(core)) - writel(1, core->base + WRAPPER_VDEC_VCODEC_POWER_CONTROL); - else if (IS_V4(core)) - writel(1, core->base + WRAPPER_VCODEC0_MMCC_POWER_CONTROL); + ret |= venus_helper_power_enable(core, VIDC_SESSION_TYPE_DEC, false); - return 0; + return ret; } static __maybe_unused int vdec_runtime_resume(struct device *dev) @@ -1153,20 +1148,14 @@ static __maybe_unused int vdec_runtime_resume(struct device *dev) if (IS_V1(core)) return 0; - if (IS_V3(core)) - writel(0, core->base + WRAPPER_VDEC_VCODEC_POWER_CONTROL); - else if (IS_V4(core)) - writel(0, core->base + WRAPPER_VCODEC0_MMCC_POWER_CONTROL); + ret = venus_helper_power_enable(core, VIDC_SESSION_TYPE_DEC, true); - ret = clk_prepare_enable(core->core0_clk); + ret |= clk_prepare_enable(core->core0_clk); if (IS_V4(core)) ret |= clk_prepare_enable(core->core0_bus_clk); - if (IS_V3(core)) - writel(1, core->base + WRAPPER_VDEC_VCODEC_POWER_CONTROL); - else if (IS_V4(core)) - writel(1, core->base + WRAPPER_VCODEC0_MMCC_POWER_CONTROL); + ret |= 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 be8ea3326386..f87d891325ea 100644 --- a/drivers/media/platform/qcom/venus/venc.c +++ b/drivers/media/platform/qcom/venus/venc.c @@ -1267,26 +1267,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 (IS_V1(core)) return 0; - if (IS_V3(core)) - writel(0, core->base + WRAPPER_VENC_VCODEC_POWER_CONTROL); - else if (IS_V4(core)) - writel(0, core->base + WRAPPER_VCODEC1_MMCC_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); - if (IS_V3(core)) - writel(1, core->base + WRAPPER_VENC_VCODEC_POWER_CONTROL); - else if (IS_V4(core)) - writel(1, core->base + WRAPPER_VCODEC1_MMCC_POWER_CONTROL); + ret |= venus_helper_power_enable(core, VIDC_SESSION_TYPE_ENC, false); - return 0; + return ret; } static __maybe_unused int venc_runtime_resume(struct device *dev) @@ -1297,20 +1292,14 @@ static __maybe_unused int venc_runtime_resume(struct device *dev) if (IS_V1(core)) return 0; - if (IS_V3(core)) - writel(0, core->base + WRAPPER_VENC_VCODEC_POWER_CONTROL); - else if (IS_V4(core)) - writel(0, core->base + WRAPPER_VCODEC1_MMCC_POWER_CONTROL); + ret = venus_helper_power_enable(core, VIDC_SESSION_TYPE_ENC, true); - ret = clk_prepare_enable(core->core1_clk); + ret |= clk_prepare_enable(core->core1_clk); if (IS_V4(core)) ret |= clk_prepare_enable(core->core1_bus_clk); - if (IS_V3(core)) - writel(1, core->base + WRAPPER_VENC_VCODEC_POWER_CONTROL); - else if (IS_V4(core)) - writel(1, core->base + WRAPPER_VCODEC1_MMCC_POWER_CONTROL); + ret |= venus_helper_power_enable(core, VIDC_SESSION_TYPE_ENC, false); return ret; } -- 2.14.1