From patchwork Sun Sep 17 22:39:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Bara X-Patchwork-Id: 13388724 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 02E87CD13D3 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=GxR+6VcbBd4wcqa6slsEC6dclMk0ORhgWVy6YAM/skY=; b=ZcHNxZloY81tP7 JnGHiaRmeObF7bS8huFVgRtD7Zp+3E+O8ZdfWZHbV02U9+MpBkGQRQWCugnd6JHml3xokPkHuSO4/ ZTj9uyqnZ9CzxAITjVT6CMxsb/n/vt6bAMz23XWc8Pt92pvXKyMB4audzwid+hqkC6tV/1n02J/OT 2uZgzWcmOSUe7n/5/nz7NySFuDivDAkfdLuEtZmWpkl5A0uocr/ENNOfZpEoNXSFsV8ZucbGjvYGb 5x62OvdGg66QQTK081cCQC+Jy0wLDxtYBgu/3l/tomRy9w09AypUo0CRLjLfKDNdq5jBkqIJ6+Jmt QwQBGNzxTWaDBWdbc3Iw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qi0RY-00E52X-1s; Sun, 17 Sep 2023 22:40:44 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qi0RP-00E4xb-1r for linux-arm-kernel@lists.infradead.org; Sun, 17 Sep 2023 22:40:39 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-401187f8071so25374415e9.0 for ; Sun, 17 Sep 2023 15:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694990434; x=1695595234; 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=AJPaLL3gJNqPRX6sTrQa6Jnq3juPdy0EeCdpo1oNzQw=; b=StM2J/VvNrtUwy7hZ88NIOH7v7XhoBjpOMMUBwlBev9feFVHwZHJEIr8Hv71H67EVq i7AJHibYwUtQv7BMoAiw7Qfeoy8fXf2XlagvR5XX4mjLpu6oN9ThfaxhDwHAwY8RB1sf XP10FCkfyGLcJscYT5I3NTDRXNqTpt3rckgw2Gtq7xZlPHoDDI29Q3Erksqqu3KKN335 WyHhCwTqvhnNgdmuY6j+9H9R1gOjC0xxi1glddrx1rQZNtYAzTu1CzMG3J4xCLwKMHND /v99LuUbrpJ3nHjyRUXWD9Gt+T5uDf0voQOLin1oodLa2al1TsCLipW6qiMJvmgURiRb XpLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694990434; x=1695595234; 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=AJPaLL3gJNqPRX6sTrQa6Jnq3juPdy0EeCdpo1oNzQw=; b=K0GK6bGF2Y72q0mg2noYWPi8Q8bkQUuF9f6zXqBZurJSKPPf92EzmLEEq/TtRd+FMk p4Tp0ZcpbbNLn7QKtJ0l5PV39a3b7WsgP6IVz/ufh6L2BEQhvWBxJlCAFhuQpxKbT3DH cKXV6gytE6iEyP9k42NDgpxpXbGq+aMzAbElSID4RCAoatGBCQkW7KL/rP7bX+ROjDMk +7zf7WjLbO8nl+R3SfXekl8duhPJpByX+9VzY61jMWsq0OS/XBAmjsJ0/vqxVhQeXJZx Vi/TpMZrI/kBuDBJOGNCafrZr+fQTGxpbBDdvohUobc7VvjXeLIcCStCXdl2qk4e4Oig 3rwA== X-Gm-Message-State: AOJu0YyCHFLW+ZUr2BgfcNziTUyZbc1FPIOingpKOcBXcijC8mWu3a61 mzTHJHi0MLKbOS2VoyCEANc= X-Google-Smtp-Source: AGHT+IHAtcxw7kNPCGsfPeyvRci6B2TGJjm5SaBwDRo/wssjZoEUG1YriSdAYHy4qrPTLAuYhmg79A== X-Received: by 2002:a05:600c:1914:b0:401:bcec:be3e with SMTP id j20-20020a05600c191400b00401bcecbe3emr7808004wmq.17.1694990433512; Sun, 17 Sep 2023 15:40:33 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 15:40:33 -0700 (PDT) From: Benjamin Bara Date: Mon, 18 Sep 2023 00:39:59 +0200 Subject: [PATCH 03/13] clk: implement clk_hw_set_rate() MIME-Version: 1.0 Message-Id: <20230918-imx8mp-dtsi-v1-3-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_154035_611595_FF5A7FD4 X-CRM114-Status: GOOD ( 14.85 ) 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 This function can be used to set the rate of a clock hardware from a driver, e.g. to adapt the rate to a clock change coming from the parent. Signed-off-by: Benjamin Bara --- drivers/clk/clk.c | 15 +++++++++++++++ include/linux/clk-provider.h | 1 + 2 files changed, 16 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index c249f9791ae8..3e222802b712 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2462,6 +2462,21 @@ static int clk_core_set_rate_nolock(struct clk_core *core, return ret; } +int clk_hw_set_rate(struct clk_hw *hw, unsigned long req_rate) +{ + /* A rate change is ongoing, so just target the required rate. + * Note: this does not work if one clock along the line has + * CLK_RECALC_NEW_RATES active, as this overwrites the new_rate again. + */ + if (hw->core->new_rate != hw->core->rate) { + hw->core->new_rate = req_rate; + return 0; + } + + return clk_core_set_rate_nolock(hw->core, req_rate); +} +EXPORT_SYMBOL_GPL(clk_hw_set_rate); + /** * clk_set_rate - specify a new rate for clk * @clk: the clk whose rate is being changed diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index ec32ec58c59f..3fb99ed5e8d9 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -1316,6 +1316,7 @@ int clk_hw_get_parent_index(struct clk_hw *hw); int clk_hw_set_parent(struct clk_hw *hw, struct clk_hw *new_parent); unsigned int __clk_get_enable_count(struct clk *clk); unsigned long clk_hw_get_rate(const struct clk_hw *hw); +int clk_hw_set_rate(struct clk_hw *hw, unsigned long req_rate); unsigned long clk_hw_get_flags(const struct clk_hw *hw); #define clk_hw_can_set_rate_parent(hw) \ (clk_hw_get_flags((hw)) & CLK_SET_RATE_PARENT)