From patchwork Sun Sep 17 22:40:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 13388723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6A0EACD13CF for ; Sun, 17 Sep 2023 22:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7lnqOZ3Ikxygv/G5Pd7fFOtnPLsmwlEQhEtOfx0kpHI=; b=knL42Lag2cG2+5 V6wwLUZtyAwukbJfMz3eviHvO2jqYDHmmiQR1XpuMOd48DvULIaaoazrckqY246xr9Lq9BoLC6sxR mieercxO4MCi7BFvgsS9mLzDtaQK1t4GAgW9rQaq7oE1kAliM7KNGdpjqtuCWjgxOnf3lKrBQP03Y Nvjoa8kwxQGK4DQsfSLwDutKzG5LIUdYFAyQUKGzoPQZUUUkwiWoEB/XeYSz32JLDDdxEtxZ0C3iy 1BrZHt5LRpbipy4MhL4gP+4Jnlay3y4Qb0G6bW6HQEDovK+ACfTV1HtgAeM8QNiEJrzuDXT1riULe ++Kfxih/dZ5RnlXh0O3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qi0Ra-00E53p-1P; Sun, 17 Sep 2023 22:40:46 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qi0RR-00E4yS-2h for linux-arm-kernel@lists.infradead.org; Sun, 17 Sep 2023 22:40:40 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-403012f27e1so41840185e9.1 for ; Sun, 17 Sep 2023 15:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694990436; x=1695595236; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=a4cz3ddudUKiI7NnTMxIyuudgr4C+r48kicDtdOb7Wo=; b=BiDN8pe1oXknBZZk5JL2/gW0+OerwPhgST8qPqJg3DdNeb+3FhATvck3JZ2nXUnAzg d3iIuyjFvzNcahkPRB/432AJOS1+hBUYUkmGioLiEtDRJY1hXXKxhucApqzoI7R6PV6C fa04xTTs50ITp9GbkDNtGX5XT9DDFX9LqajmFu12L1X4DcxHAo6IqhJ7h1bOAKofLWcu BEi8LYj5SyVAOcTL2VALFV4DEHrp+NsagphJqJSpUgQUkFYyho1ZIDYFrAFEU65jCPr/ tjhTgKYnMyB7CLl5mwQNhD3O/+M9fzNI1KoERNlRwScfgcB+7WZPJHuGZEbJn0NPyc6M Mq0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694990436; x=1695595236; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a4cz3ddudUKiI7NnTMxIyuudgr4C+r48kicDtdOb7Wo=; b=GwIKtBKsXBJ1xZtJeJQPkGGD/0joRJZhCkJ5YAw1IeLR5egLqUc1HlfM0a8jfZZ42E ZDmkr4368Lay31/w2BuN73Zf2D2L9a9MnUFlvHYEEI235aObLqlUCGkqnCG7NUi8ppUx +OC1OW0VOqv4OFzmx8Lt+nDHmV1FwgzUB1+WGKSBNHqr1TLlbxanF/TIjiIFyQUS1Zkz fSZK9tNouhtP6URYyYOn+yrI/17H8/dhWCNjdF8UfHWLEthZhGDlUyW3Ve1K+fOOs0Bs Nyoez2R0xDLmIiMTEHndSXRDDkjhqEJ4sP+W4UXxk6Y1OysFwVPqr5wm7LxS94GYBh7k MgyA== X-Gm-Message-State: AOJu0YzRpSGIgYowL6T6+SuDfEHSGpwwSQRWxbgQJ4xXuYT3jR1IsLQC iG1amEW4qJKRFvID6kfxevI= X-Google-Smtp-Source: AGHT+IE2H/LAUCgWRax7Ln7Pf/RNykjRml+cUSy7LIhvq+pmSE6UUuK6rKrg8wHXJMeh2LS9XviDXg== X-Received: by 2002:a05:600c:3781:b0:401:b2c7:349b with SMTP id o1-20020a05600c378100b00401b2c7349bmr5879782wmr.7.1694990436518; Sun, 17 Sep 2023 15:40:36 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id x14-20020a1c7c0e000000b003fe2b081661sm13642931wmc.30.2023.09.17.15.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 15:40:36 -0700 (PDT) From: Benjamin Bara Date: Mon, 18 Sep 2023 00:40:02 +0200 Subject: [PATCH 06/13] clk: keep track if a clock is explicitly configured MIME-Version: 1.0 Message-Id: <20230918-imx8mp-dtsi-v1-6-1d008b3237c0@skidata.com> References: <20230918-imx8mp-dtsi-v1-0-1d008b3237c0@skidata.com> In-Reply-To: <20230918-imx8mp-dtsi-v1-0-1d008b3237c0@skidata.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Michael Turquette , Stephen Boyd , Russell King , Abel Vesa , Peng Fan Cc: Frank Oltmanns , Maxime Ripard , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Benjamin Bara X-Mailer: b4 0.12.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230917_154037_878661_932954E6 X-CRM114-Status: GOOD ( 15.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Benjamin Bara When we keep track if a clock has a given rate explicitly set by a consumer, we can identify unintentional clock rate changes in an easy way. This also helps during debugging, as one can see if a rate is set by accident or due to a consumer-related change. Signed-off-by: Benjamin Bara --- drivers/clk/clk.c | 25 +++++++++++++++++++++++++ include/linux/clk-provider.h | 1 + 2 files changed, 26 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 8f4f92547768..82c65ed432c5 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -70,6 +70,7 @@ struct clk_core { unsigned long rate; unsigned long req_rate; unsigned long new_rate; + unsigned long set_rate; struct clk_core *new_parent; struct clk_core *new_child; unsigned long flags; @@ -541,6 +542,12 @@ bool __clk_is_enabled(struct clk *clk) } EXPORT_SYMBOL_GPL(__clk_is_enabled); +bool __clk_is_rate_set(struct clk *clk) +{ + return clk->core->set_rate > 0; +} +EXPORT_SYMBOL_GPL(__clk_is_rate_set); + static bool mux_is_better_rate(unsigned long rate, unsigned long now, unsigned long best, unsigned long flags) { @@ -578,6 +585,19 @@ static bool clk_core_has_parent(struct clk_core *core, const struct clk_core *pa return false; } +static bool clk_core_is_ancestor(struct clk_core *core, const struct clk_core *ancestor) +{ + struct clk_core *tmp = core->parent; + + while (tmp) { + if (tmp == ancestor) + return true; + tmp = tmp->parent; + } + + return false; +} + static void clk_core_forward_rate_req(struct clk_core *core, const struct clk_rate_request *old_req, @@ -2358,6 +2378,9 @@ static void clk_change_rate(struct clk_core *core) trace_clk_set_rate_complete(core, core->new_rate); + if (rate_trigger_clk && clk_core_is_ancestor(rate_trigger_clk->core, core)) + core->set_rate = core->new_rate; + core->rate = clk_recalc(core, best_parent_rate); if (core->flags & CLK_SET_RATE_UNGATE) { @@ -2528,6 +2551,7 @@ int clk_set_rate(struct clk *clk, unsigned long rate) clk_core_rate_protect(clk->core); rate_trigger_clk = NULL; + clk->core->set_rate = rate; clk_prepare_unlock(); @@ -2579,6 +2603,7 @@ int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) } rate_trigger_clk = NULL; + clk->core->set_rate = rate; clk_prepare_unlock(); diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 3fb99ed5e8d9..e3732e0bbed9 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -1325,6 +1325,7 @@ bool clk_hw_is_prepared(const struct clk_hw *hw); bool clk_hw_rate_is_protected(const struct clk_hw *hw); bool clk_hw_is_enabled(const struct clk_hw *hw); bool __clk_is_enabled(struct clk *clk); +bool __clk_is_rate_set(struct clk *hw); struct clk *__clk_lookup(const char *name); int __clk_mux_determine_rate(struct clk_hw *hw, struct clk_rate_request *req);