Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1016071ybe; Thu, 19 Sep 2019 07:25:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzjsxF+TPUAPT/h4q2drjAJtqZbikvrCkZdLAnAoHCpVFswDC82td+pdsZhFNl1Aw9TE29 X-Received: by 2002:a05:6402:128c:: with SMTP id w12mr10114122edv.158.1568903135946; Thu, 19 Sep 2019 07:25:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568903135; cv=none; d=google.com; s=arc-20160816; b=FBKXhtPAslb1Y8NpdPmsg1HemxR+xbYJDKpFimO5v9qFYTKQw24qq6yvaDGNdv6GzT fLw3K2MZX//oJINj/0YVscuZimYozZVfAAoRNuG8fCk08Xme/G07yvWIQTAOLRZcJxNs /ycLehyO+d+dI74N0utYYJ/QYXR5gkeAAcDVFYXbhT3+XLblXQcFCrBOFb9FbJh4PdYv wPcPCyQqCe192kj7h37fPZgRhZs+6AckqtaQ4EGc/Jrq9OBv5rXmhyCs1vz9RUulcMEP VD6sep9swuu4yJd5WkO5SrKyiJWvrSBDEOAfQCdoZvddlzf+3aDfCh7AZbsYGzhUp6cj iP7g== 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=RQH3sxdCSDhIfGdbCjdRoLM/sLLm5iODyAbQ5C/Ltw0=; b=sYUK5V64zkcJvVOIgybvZ+Hglk6ZcxcVBrXJhdY6umzcTURPB/XOwKjfyTovlL5Y49 2Ue/j0yT8pfV9BRKbJVM0dwFUBJV2koQkE7FwNOp0GeHWO+tgL+bqNGWvX3ou0fRHHFU P44+Z1RTmvrX0Y4TAcdafNUTn+qaTOrs2FwyMC8vUXVlUpSnrsmZKE+sdRz3H08WJegT jvxUvtjJ+/fZKBsec7TZx61hCuRZfoRzWkMlghLYPmdadw59xHabzICSraEETwOfgBYl /AHsS3LVnonIGZgHIoOpnt1HhtWLL5mFMUmvAjH7RV4k1CcSK/A4rNMZ4QQR++idSEZW jZwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=E+UHiJSG; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n2si5281240edq.264.2019.09.19.07.25.11; Thu, 19 Sep 2019 07:25:35 -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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=E+UHiJSG; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389252AbfISKZ3 (ORCPT + 99 others); Thu, 19 Sep 2019 06:25:29 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:39064 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389208AbfISKZ1 (ORCPT ); Thu, 19 Sep 2019 06:25:27 -0400 Received: by mail-wr1-f68.google.com with SMTP id r3so2494945wrj.6 for ; Thu, 19 Sep 2019 03:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RQH3sxdCSDhIfGdbCjdRoLM/sLLm5iODyAbQ5C/Ltw0=; b=E+UHiJSGEVWW51Mla00YaqY1xV4mU3Y+5rJsa4CDkZOUugcHeGYU8NUsvjyGdh1Y9W 6ARRrK0ebicbUwvDp1hlZN1n7QfctXKyAu4DzKH5+41QbuAvDnrH33FdTGNAFkSJvfLy QM3+A4NxjDFI/AEFwzPmTTBsJZuL/7hvlJu+Vf8r89v9tYTyaECETWLTqQFVOI9fDTz6 jp3aKuYmkkDyi97/DKgrXUPLbOji6zSqzZFO5bhxbSC7m+BZtVgnQ7VgA2ecK075aFiW fC7vMa1LtUIZ2tLG8H1NDl9Y2sjMBKz05YG90pNkgwuuimMWh0mQX+blFA/9c8gYS99O ce4w== 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=RQH3sxdCSDhIfGdbCjdRoLM/sLLm5iODyAbQ5C/Ltw0=; b=EX4vbQbkQtb4slmX2aw6g7V6Y3km6B2FiQWEvv4J4oW7czDt0NqIrvm3B4NY4d6Oii rrK7E1xF5ec29bxDOrPgq+V4M4WVSgZMnRZby/g3v0gFKeUXOyJlFRMxuEMOvE8aDM9A A/E1pZmNGD0aTEdulY3C301Ojpzmyq6AlU6VFId6uY72iEtH1bgscQS/DhRwWXy7pb4J svXV8gmRpzy4LOxzePFd0UPf4gPer7C3LatOjjuDn01cmMBChUbkhjzkxrRoBMgnwAj6 bE6VJChcPUdHsS7akgmofn3G+CDIIln6DG2FA1XNLV7HNQpNeKc7r4LgBX9W06Y92yTd 0zpQ== X-Gm-Message-State: APjAAAU29NtU00siMXRGg46I/JNpdOlxp7NAHCbmePhdSJYcu/8f2DYL 2kM8hWNRSc55IuYyvEICYKWCFA== X-Received: by 2002:adf:eccd:: with SMTP id s13mr6749982wro.288.1568888723655; Thu, 19 Sep 2019 03:25:23 -0700 (PDT) Received: from bender.baylibre.local (wal59-h01-176-150-251-154.dsl.sta.abo.bbox.fr. [176.150.251.154]) by smtp.gmail.com with ESMTPSA id a18sm19542000wrh.25.2019.09.19.03.25.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2019 03:25:23 -0700 (PDT) From: Neil Armstrong To: sboyd@kernel.org, jbrunet@baylibre.com, mturquette@baylibre.com Cc: Neil Armstrong , linux-clk@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC 1/2] clk: introduce clk_invalidate_rate() Date: Thu, 19 Sep 2019 12:25:17 +0200 Message-Id: <20190919102518.25126-2-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190919102518.25126-1-narmstrong@baylibre.com> References: <20190919102518.25126-1-narmstrong@baylibre.com> 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 This introduces the clk_invalidate_rate() call used to recalculate the rate and parent tree of a particular clock if it's known that the underlying registers set has been altered by the firmware, like from a suspend/resume handler running in trusted cpu mode. The call refreshes the actual parent and when changed, instructs CCF the parent has changed. Finally the call will recalculate the rate of each part of the tree to make sure the CCF cached tree is in sync with the hardware. Signed-off-by: Neil Armstrong --- drivers/clk/clk.c | 70 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/clk.h | 13 +++++++++ 2 files changed, 83 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index ca99e9db6575..8acf38ce3cc4 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2557,6 +2557,76 @@ int clk_set_parent(struct clk *clk, struct clk *parent) } EXPORT_SYMBOL_GPL(clk_set_parent); +/** + * __clk_invalidate_tree + * @core: first clk in the subtree + * + * Walks the subtree of clks starting with clk and recalculates the parents, + * then accuracies and rates as it goes. + */ +static int __clk_invalidate_tree(struct clk_core *core) +{ + struct clk_core *parent, *old_parent; + int ret, i, num_parents; + + num_parents = core->num_parents; + + for (i = 0; i < num_parents; i++) { + parent = clk_core_get_parent_by_index(core, i); + if (!parent) + continue; + + ret = __clk_invalidate_tree(parent); + if (ret) + return ret; + } + + parent = __clk_init_parent(core); + + if (parent != core->parent) { + old_parent = __clk_set_parent_before(core, parent); + __clk_set_parent_after(core, parent, old_parent); + } + + __clk_recalc_accuracies(core); + __clk_recalc_rates(core, 0); + + return 0; +} + +static int clk_core_invalidate_rate(struct clk_core *core) +{ + int ret; + + clk_prepare_lock(); + + ret = __clk_invalidate_tree(core); + + clk_prepare_unlock(); + + return ret; +} + +/** + * clk_invalidate_rate - invalidate and recalc rate of the clock and it's tree + * @clk: the clk whose rate is too be invalidated + * + * If it's known the actual hardware state of a clock tree has changed, + * this call will invalidate the cached rate of the clk and it's possible + * parents tree to permit recalculation of the actual rate. + * + * Returns 0 on success, -EERROR otherwise. + * If clk is NULL then returns 0. + */ +int clk_invalidate_rate(struct clk *clk) +{ + if (!clk) + return 0; + + return clk_core_invalidate_rate(clk->core); +} +EXPORT_SYMBOL_GPL(clk_invalidate_rate); + static int clk_core_set_phase_nolock(struct clk_core *core, int degrees) { int ret = -EINVAL; diff --git a/include/linux/clk.h b/include/linux/clk.h index 853a8f181394..46db47ffb7b2 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -629,6 +629,19 @@ long clk_round_rate(struct clk *clk, unsigned long rate); */ int clk_set_rate(struct clk *clk, unsigned long rate); +/** + * clk_invalidate_rate - invalidate and recalc rate of the clock and it's tree + * @clk: the clk whose rate is too be invalidated + * + * If it's known the actual hardware state of a clock tree has changed, + * this call will invalidate the cached rate of the clk and it's possible + * parents tree to permit recalculation of the actual rate. + * + * Returns 0 on success, -EERROR otherwise. + * If clk is NULL then returns 0. + */ +int clk_invalidate_rate(struct clk *clk); + /** * clk_set_rate_exclusive- set the clock rate and claim exclusivity over * clock source -- 2.22.0