Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1994086ybg; Thu, 30 Jul 2020 07:52:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYYc77lQ2zpJS1tTGx+cDUQ8MpdYB7f0LcOhQ1XD8hdNcsTvdbJuKw6mBMj/tS96UBmG3C X-Received: by 2002:a17:906:6ad8:: with SMTP id q24mr2913614ejs.192.1596120752570; Thu, 30 Jul 2020 07:52:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596120752; cv=none; d=google.com; s=arc-20160816; b=aYP9C/fuyTDQEGRDClMz0B3O46ixg2/9TDig1PQwjyp3QtxI8TVlgt2WIxieHdkJqO f+8C/Dt2YdyoiMJqSb/q7+lrPGH3W4tB7bR22b2sdF6JejqWz1x0JnxRHfEEV8ZsgpGE odViYmx+jz0R89snyVt43kUALaig6HTS8Tk4fbvYxhAjoqox6McdFnKHfSxe/e6Bxlf6 BblsCgDUuWQcgCZ05GOdWnN6ceQ1RSmjowhAdaAjfG55FY3U+gCN5h9ZbUumGTEBGniY 5Rf/ng1RKvhJWmSRh1uw0Y4+0E2IIe4bCQmYtSonzXVB46bBtroQVhhs4uo+14F4GuuK cmlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gUVHf7pjz79eBEh+tIPCA/D+2iQEziFi0FluLsYiEGI=; b=nMw2WmsWE/8mZKhyK3oSOjUQ3QmwJ5aiEw/snte9j+YE9UerdNJNZCLA4NZbF2/KGA Sur/CjXKQiIl2caaWhzJY3VQR1BosHW1hCAMALgww4IJ5y2M81hH2TtdiGZwweWfYyJO y50eFZRmpi193Co4dTNaUKaSPLuaMagE3xF+Lbn+bAOnbDjuaqLmAt4cEQDZs5nO/OMJ cyRrK3CWau3CPyhKaXK1UfKOOS6umrzTrAenFw3eegAsB+HMNZzXuBJWifouHZCtaKJl NfACHahFsyZD7T0w/FksE/DAnjILkz6PM/Q8JocOMQIMUm2rFzt7hhskzq7wE6crdHDi uTmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@crapouillou.net header.s=mail header.b=AgDmNK7p; 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=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dg23si3411958edb.12.2020.07.30.07.52.10; Thu, 30 Jul 2020 07:52:32 -0700 (PDT) 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=fail header.i=@crapouillou.net header.s=mail header.b=AgDmNK7p; 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=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729629AbgG3OtA (ORCPT + 99 others); Thu, 30 Jul 2020 10:49:00 -0400 Received: from crapouillou.net ([89.234.176.41]:35838 "EHLO crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726275AbgG3OtA (ORCPT ); Thu, 30 Jul 2020 10:49:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1596120517; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gUVHf7pjz79eBEh+tIPCA/D+2iQEziFi0FluLsYiEGI=; b=AgDmNK7pSkDHnwXR8XpeuDJHMGJSudAOPqXg2CXYQx/zOnMu1XCLRuqBRO9PZO3jo80Kih KZSCOkmALkQLuBC1pFH3zKTFICr2HVJrQX9OolHS7tGGdxhuRfWK+59l/8IUfr74UaSBCb jpqzVu9Bh6Tvw9HW4KoDNqFaulo+F2Y= From: Paul Cercueil To: David Airlie , Daniel Vetter Cc: Sam Ravnborg , od@zcrc.me, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Paul Cercueil Subject: [PATCH v2 3/3] drm/ingenic: ipu: Only enable clock when needed Date: Thu, 30 Jul 2020 16:48:30 +0200 Message-Id: <20200730144830.10479-4-paul@crapouillou.net> In-Reply-To: <20200730144830.10479-1-paul@crapouillou.net> References: <20200730144830.10479-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of keeping the IPU clock enabled constantly, enable and disable it on demand, when the IPU plane is used. That way, we won't use any extra power when the IPU is not used. v2: Explain the reason of this patch Signed-off-by: Paul Cercueil --- drivers/gpu/drm/ingenic/ingenic-ipu.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/ingenic/ingenic-ipu.c b/drivers/gpu/drm/ingenic/ingenic-ipu.c index 7dd2a6ae4994..fc8c6e970ee3 100644 --- a/drivers/gpu/drm/ingenic/ingenic-ipu.c +++ b/drivers/gpu/drm/ingenic/ingenic-ipu.c @@ -49,6 +49,7 @@ struct ingenic_ipu { struct regmap *map; struct clk *clk; const struct soc_info *soc_info; + bool clk_enabled; unsigned int num_w, num_h, denom_w, denom_h; @@ -288,12 +289,23 @@ static void ingenic_ipu_plane_atomic_update(struct drm_plane *plane, const struct drm_format_info *finfo; u32 ctrl, stride = 0, coef_index = 0, format = 0; bool needs_modeset, upscaling_w, upscaling_h; + int err; if (!state || !state->fb) return; finfo = drm_format_info(state->fb->format->format); + if (!ipu->clk_enabled) { + err = clk_enable(ipu->clk); + if (err) { + dev_err(ipu->dev, "Unable to enable clock: %d\n", err); + return; + } + + ipu->clk_enabled = true; + } + /* Reset all the registers if needed */ needs_modeset = drm_atomic_crtc_needs_modeset(state->crtc->state); if (needs_modeset) { @@ -578,6 +590,11 @@ static void ingenic_ipu_plane_atomic_disable(struct drm_plane *plane, regmap_clear_bits(ipu->map, JZ_REG_IPU_CTRL, JZ_IPU_CTRL_CHIP_EN); ingenic_drm_plane_disable(ipu->master, plane); + + if (ipu->clk_enabled) { + clk_disable(ipu->clk); + ipu->clk_enabled = false; + } } static const struct drm_plane_helper_funcs ingenic_ipu_plane_helper_funcs = { @@ -761,9 +778,9 @@ static int ingenic_ipu_bind(struct device *dev, struct device *master, void *d) drm_object_attach_property(&plane->base, ipu->sharpness_prop, ipu->sharpness); - err = clk_prepare_enable(ipu->clk); + err = clk_prepare(ipu->clk); if (err) { - dev_err(dev, "Unable to enable clock\n"); + dev_err(dev, "Unable to prepare clock\n"); return err; } @@ -775,7 +792,7 @@ static void ingenic_ipu_unbind(struct device *dev, { struct ingenic_ipu *ipu = dev_get_drvdata(dev); - clk_disable_unprepare(ipu->clk); + clk_unprepare(ipu->clk); } static const struct component_ops ingenic_ipu_ops = { -- 2.27.0