From patchwork Sun Sep 17 22:40:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 13388726 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 4356CCD13CF for ; Sun, 17 Sep 2023 22:41:15 +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=u8v7E6m0jtcJOJ7f4hVckaCHH+wVZORNEet4M3sYWCw=; b=QAqZKDjKEEUjXU 96vAP42J/ycSmAf9avPsfzUlWdmPxh09VJCtiAH1H5fevrOrjvzi6dKIoDmJ4s9HcoxqHT9r5JT0b X9DcNUa6RhkaPoaT0wnW1b+3wlIE2GbdkmwJojlq+ypUX55QSNbX2Orf4ApoBTirE48ugdLqTON1Z bP4rI9C8uTYmfm6ljcNwLzYx0USurP8MRER0M9Jf8WnB4kWOOROwejSpl7xNWM5RBCPGENcfJeTYu o3TUQuBuKQWPDrfG7g3Qpf7wveiMfWpAMIBrxb07URHO4dIL3/MDigUl3ZC6wdm/JZu1yD/pvQkK2 GlpE6u8/sjFtD8WyuEuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qi0RZ-00E53T-2u; Sun, 17 Sep 2023 22:40:45 +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-00E4yI-25 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-404c023ef5eso20885435e9.2 for ; Sun, 17 Sep 2023 15:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694990435; x=1695595235; 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=gCq7gxZ6dHwUyWczpY7Vh5cbaVAZn1kPig1Zw4rFZSA=; b=Dd8hBf6L5B84q5HWz0/ExwvRE9HnTjauHNRJEbDXdaPayt/WdpKcJE+Vi6wJsu+Pop gao+qZ/ToGTM86e6IgmXP3j6pVblKJuOA3SKpgI80qRBfd9Uz1DSTD8dAPT5wLP6O6Zj iNQKibKzKcVShvE4B0yR2X1fRWZ2yVGwqYUtIFQpbh0w0elASjpSuXMvtEX5FmV9dUA6 S05rG4We8KPIYg2GEDMr+Yz8cfU0RrQk+cCmPnW92t6Zif2dfBqJihSeNbFrazjvU6n9 7/CLrZ0eeLPbEd1t6Za5plzTykFp4YsbWd5UtgR3LR4ftmMlahaAuohhkbFjW95YPEKx L3Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694990435; x=1695595235; 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=gCq7gxZ6dHwUyWczpY7Vh5cbaVAZn1kPig1Zw4rFZSA=; b=aHx2iWG95Zx4NbBipHMaXTsJv/qCEymbGTZI2udvAIUsifZKS/quwj3q10TI7CxSAZ yiDj/oNaKPJCxKCNuohyRgv7WemmpkNOgL6io5a9LO6NOkmuCEea1ZltAhbd03WX5vNj xs1bOTW97vK58IGNJEOvpkRpakZxpTNoSLqmiPIffSPoq7UsiN0dDEjv2gU1ruSzEI2z OTIE2Mul0JX6u2ulnL0QPa+4HW5OEflNHCeqTPbLWq2Yib3zvTqliUJZWRYkCA3rLHQL rKLI5W6pfySlqrP1dyscS27xyfyMO49CHSQiWjbDAGPuR5dJpNqpSXNaaePQmfAcZQ+2 bB8A== X-Gm-Message-State: AOJu0Yy5owfIvHbRfezY2QkeBj7k2kO4WslgcrULqeu/6RyGpAZg9n6Y sQm2vdjfAAJuN80M8dWfhc0= X-Google-Smtp-Source: AGHT+IE9Gpa9OGGS1u8fMnQqhz/589mtCuJtM8X+qAmxlIvQ+ije0qLFWk06/6xK0LIv4W/DRv7WnA== X-Received: by 2002:a05:600c:21d7:b0:3fe:d1e9:e6b8 with SMTP id x23-20020a05600c21d700b003fed1e9e6b8mr6261880wmj.12.1694990435584; Sun, 17 Sep 2023 15:40:35 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 15:40:35 -0700 (PDT) From: Benjamin Bara Date: Mon, 18 Sep 2023 00:40:01 +0200 Subject: [PATCH 05/13] clk: keep track of the trigger of an ongoing clk_set_rate MIME-Version: 1.0 Message-Id: <20230918-imx8mp-dtsi-v1-5-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_686190_1F38BA05 X-CRM114-Status: GOOD ( 16.57 ) 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 of the rate change trigger, we can easily check if an affected clock is affiliated with the trigger. Additionally, the trigger is added to the notify data, so that drivers can implement workarounds that might be necessary if a shared parent changes. Signed-off-by: Benjamin Bara --- drivers/clk/clk.c | 12 ++++++++++++ include/linux/clk.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 4954d31899ce..8f4f92547768 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -33,6 +33,9 @@ static struct task_struct *enable_owner; static int prepare_refcnt; static int enable_refcnt; +/* responsible for ongoing rate change, protected by prepare_lock */ +static struct clk *rate_trigger_clk; + static HLIST_HEAD(clk_root_list); static HLIST_HEAD(clk_orphan_list); static LIST_HEAD(clk_notifier_list); @@ -1742,6 +1745,7 @@ static int __clk_notify(struct clk_core *core, unsigned long msg, cnd.old_rate = old_rate; cnd.new_rate = new_rate; + cnd.trigger = rate_trigger_clk ? : core->parent->hw->clk; list_for_each_entry(cn, &clk_notifier_list, node) { if (cn->clk->core == core) { @@ -2513,6 +2517,8 @@ int clk_set_rate(struct clk *clk, unsigned long rate) /* prevent racing with updates to the clock topology */ clk_prepare_lock(); + rate_trigger_clk = clk; + if (clk->exclusive_count) clk_core_rate_unprotect(clk->core); @@ -2521,6 +2527,8 @@ int clk_set_rate(struct clk *clk, unsigned long rate) if (clk->exclusive_count) clk_core_rate_protect(clk->core); + rate_trigger_clk = NULL; + clk_prepare_unlock(); return ret; @@ -2556,6 +2564,8 @@ int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) /* prevent racing with updates to the clock topology */ clk_prepare_lock(); + rate_trigger_clk = clk; + /* * The temporary protection removal is not here, on purpose * This function is meant to be used instead of clk_rate_protect, @@ -2568,6 +2578,8 @@ int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) clk->exclusive_count++; } + rate_trigger_clk = NULL; + clk_prepare_unlock(); return ret; diff --git a/include/linux/clk.h b/include/linux/clk.h index 06f1b292f8a0..f0fe78c7a0f1 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -60,6 +60,7 @@ struct clk_notifier { /** * struct clk_notifier_data - rate data to pass to the notifier callback * @clk: struct clk * being changed + * @trigger: struct clk * being responsible for the change * @old_rate: previous rate of this clk * @new_rate: new rate of this clk * @@ -70,6 +71,7 @@ struct clk_notifier { */ struct clk_notifier_data { struct clk *clk; + struct clk *trigger; unsigned long old_rate; unsigned long new_rate; };