From patchwork Tue Apr 4 10:11:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 79109 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3038109vqo; Tue, 4 Apr 2023 06:42:41 -0700 (PDT) X-Google-Smtp-Source: AKy350b6hINJys50qn6vQKE1h9GVZb9CPwggyrxJCoTDDnrjNhoXe4otdh2w2tIdlQPAGZwygA09 X-Received: by 2002:aa7:8bd2:0:b0:627:fc31:1de with SMTP id s18-20020aa78bd2000000b00627fc3101demr1994137pfd.7.1680615761077; Tue, 04 Apr 2023 06:42:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680615761; cv=none; d=google.com; s=arc-20160816; b=O8/rp7Rkb9wVAg0JG3vwuO8lbObPeO9HTAWpu3vSuidCWdMZslWck4PrRJAmW/m6+S LY+JZMr3VNUALu8QcnCFLa0KENSC+HkZQXYlYwFL6GHQhrRRhBoCMR8XM/rhI1v4d5up ThXUGGnSbsJ/gq28LigAZo3TaVHi5zEOErtL8Uc2tuKpQJR6RD4Jy2oYckBar2RSJ4LV 9n7dSQUzOouU8OlryyaDejc/jkg8fcxGjlvZ3epTn6/P7f7sogT0AvqKbXWqrV5RRFLR SIEQ3Q+y3vc705IwSEuyD40E744xoF9kOtwZxCfKra+awOXvnfLyc+azw1b9on92aSj2 ZnhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :feedback-id:dkim-signature:dkim-signature; bh=IRvUmfFNsMs7DLQdJ6TJDFMMQsz+lSIX5Vyvpb8PIeY=; b=vv6Jpoq58xmuYh4UDF8Bgz54timnqYp5Ty6ISuyLtv/awVI6uCr6F43/OWoNa57pVQ 75mHkN2vPUSIUjyY/Udsu8VHzJ18vf6JsFfVSOk3SOuHYW4AzTrLDSVkD0btHXzxcawP n5fv+iT3jIA+k6Duh8ZLy7uH5uVgOWaa6lT2DuWrpxeBL/FfsRA1i5icmBii5M4YMwvm FrzZTh9wYAIiSBYNOFFriePDnZAAOGn777gO1t80NbHbUUymc+5Bajo4bhilBx8TYZg/ Z2iLy6Gvcp4RKM5wDNXi5eezC8s2eMkEorEZzZu/wTYMZ3EoqZoJj4f4Hh/ZeyGo29KH 1c7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm3 header.b="f/utoZt/"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=V0M+xj0x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g15-20020aa796af000000b0062618f027e2si10463461pfk.119.2023.04.04.06.42.27; Tue, 04 Apr 2023 06:42:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm3 header.b="f/utoZt/"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=V0M+xj0x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235335AbjDDNiR (ORCPT + 99 others); Tue, 4 Apr 2023 09:38:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235299AbjDDNiH (ORCPT ); Tue, 4 Apr 2023 09:38:07 -0400 Received: from new3-smtp.messagingengine.com (new3-smtp.messagingengine.com [66.111.4.229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 759E61B4; Tue, 4 Apr 2023 06:37:57 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.nyi.internal (Postfix) with ESMTP id A04DF5821B9; Tue, 4 Apr 2023 09:37:56 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 04 Apr 2023 09:37:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm3; t= 1680615476; x=1680622676; bh=IRvUmfFNsMs7DLQdJ6TJDFMMQsz+lSIX5Vy vpb8PIeY=; b=f/utoZt/EY/+6xUFuUlwzaCTmj8zHoU93k79pb1hMLYuJJQ5CPs bmuRX+u5323KUis2v67Jj5VIWnM5Hb3TTEpYCg5h5qPoF0uGlGG38gC7GfA82Heh 3EmMb0jDeZEUiF0Be5HP9cQFhDO0ExbqTupz7aIow9luBdMfzmtCYJUm8se2UxNh OQM7z3VPX65GOapRINgb0wMUIuBJGPJ0OZ0gcM+GaZNNCp1hTeZgFWRYHK9gTWMC 9YWf+2ZIU+fOY8yfvz26/eNUeY0bMLm4t+PsmAyIWGVmsS5yO/ipWyvTlM/jknGB glMPYCk0xyxkESSxIryZ9ix8lTnXchf98/Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1680615476; x=1680622676; bh=IRvUmfFNsMs7DLQdJ6TJDFMMQsz+lSIX5Vy vpb8PIeY=; b=V0M+xj0xoPYOYAoF+VdxIL9uGLttsB4q7a6eYq+dMtuAYsOA3Vp sChat0+XLi5/Hj6qPD637/O9MW0eqELPdqKHP4djzXEg4dnu4hsPU8pvJSVCDuH7 ZtofqzV4APHrIHGrigyFqBZrxS4z3J4fgtq6E4rxEf2gKvqxf19CxRXT9Qe3kTCh UYA+le0mLUzr2nsp0p+Mqr+5r8e9epr3pxH43svKZvO+cGyRB7cy4FmZHt810YN/ t2w/AYfC+2s25tRi1RKFVExTWXo6ho+L1SoQ1CjD664c1vCTBysIRipEhGZSAyCD 7j2jwyjVFoKS4x4xj8YZDz/LBxwBt3xgGNw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeiledgieeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforgig ihhmvgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrf grthhtvghrnhepvedvleeijeegvdekffehkeehieelhfeggfffheetkeeuledvtdeuffeh teeltdffnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomh epmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 4 Apr 2023 09:37:54 -0400 (EDT) From: Maxime Ripard Date: Tue, 04 Apr 2023 12:11:36 +0200 Subject: [PATCH v3 46/65] clk: at91: smd: Switch to determine_rate MIME-Version: 1.0 Message-Id: <20221018-clk-range-checks-fixes-v3-46-9a1358472d52@cerno.tech> References: <20221018-clk-range-checks-fixes-v3-0-9a1358472d52@cerno.tech> In-Reply-To: <20221018-clk-range-checks-fixes-v3-0-9a1358472d52@cerno.tech> To: Michael Turquette , Stephen Boyd , =?utf-8?q?Andreas_F=C3=A4rber?= , Manivannan Sadhasivam , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Max Filippov , Charles Keepax , Richard Fitzgerald , Maxime Coquelin , Alexandre Torgue , Luca Ceresoli , David Lechner , Sekhar Nori , Abel Vesa , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Matthias Brugger , Geert Uytterhoeven , Dinh Nguyen , Peter De Schrijver , Prashant Gaikwad , Thierry Reding , Jonathan Hunter , Ulf Hansson , Linus Walleij , David Airlie , Daniel Vetter , Vinod Koul , Kishon Vijay Abraham I , Alessandro Zummo , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Paul Cercueil , Orson Zhai , Baolin Wang , Chunyan Zhang Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, AngeloGioacchino Del Regno , linux-arm-kernel@lists.infradead.org, linux-actions@lists.infradead.org, patches@opensource.cirrus.com, linux-stm32@st-md-mailman.stormreply.com, linux-mediatek@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-tegra@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-phy@lists.infradead.org, linux-rtc@vger.kernel.org, linux-sunxi@lists.linux.dev, alsa-devel@alsa-project.org, linux-mips@vger.kernel.org, Maxime Ripard X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3353; i=maxime@cerno.tech; h=from:subject:message-id; bh=dnanpEYQNgfEiWyEet2BPZYrOEJEAi5KqsKheoPaYRc=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDCna37cnsgv9/Lrp3JsQ3WN6O+/lzxBZrq9tcfrjwstTjwce 2ZNh2FHKwiDGxSArpsgSI2y+JO7UrNedbHzzYOawMoEMYeDiFICJmEgx/M+4lnLjfc+9Bwdz2rbMMZ nzwqdpj+31R8YdT7WLzgZ2//zPyPCs9USLkeo+c/v8fd/Frq1gTtNsznHetKNp3qzzPokMj/gB X-Developer-Key: i=maxime@cerno.tech; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=0.2 required=5.0 tests=DATE_IN_PAST_03_06,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762253352601937855?= X-GMAIL-MSGID: =?utf-8?q?1762253352601937855?= The Atmel SAM9x5 SMD clocks implements a mux with a set_parent hook, but doesn't provide a determine_rate implementation. This is a bit odd, since set_parent() is there to, as its name implies, change the parent of a clock. However, the most likely candidate to trigger that parent change is a call to clk_set_rate(), with determine_rate() figuring out which parent is the best suited for a given rate. The other trigger would be a call to clk_set_parent(), but it's far less used, and it doesn't look like there's any obvious user for that clock. So, the set_parent hook is effectively unused, possibly because of an oversight. However, it could also be an explicit decision by the original author to avoid any reparenting but through an explicit call to clk_set_parent(). The driver does implement round_rate() though, which means that we can change the rate of the clock, but we will never get to change the parent. However, It's hard to tell whether it's been done on purpose or not. Since we'll start mandating a determine_rate() implementation, let's convert the round_rate() implementation to a determine_rate(), which will also make the current behavior explicit. And if it was an oversight, the clock behaviour can be adjusted later on. Signed-off-by: Maxime Ripard Reviewed-by: Claudiu Beznea Tested-by: Claudiu Beznea --- drivers/clk/at91/clk-smd.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/clk/at91/clk-smd.c b/drivers/clk/at91/clk-smd.c index 160378438f1b..09c649c8598e 100644 --- a/drivers/clk/at91/clk-smd.c +++ b/drivers/clk/at91/clk-smd.c @@ -36,26 +36,31 @@ static unsigned long at91sam9x5_clk_smd_recalc_rate(struct clk_hw *hw, return parent_rate / (smddiv + 1); } -static long at91sam9x5_clk_smd_round_rate(struct clk_hw *hw, unsigned long rate, - unsigned long *parent_rate) +static int at91sam9x5_clk_smd_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) { unsigned long div; unsigned long bestrate; unsigned long tmp; - if (rate >= *parent_rate) - return *parent_rate; + if (req->rate >= req->best_parent_rate) { + req->rate = req->best_parent_rate; + return 0; + } - div = *parent_rate / rate; - if (div > SMD_MAX_DIV) - return *parent_rate / (SMD_MAX_DIV + 1); + div = req->best_parent_rate / req->rate; + if (div > SMD_MAX_DIV) { + req->rate = req->best_parent_rate / (SMD_MAX_DIV + 1); + return 0; + } - bestrate = *parent_rate / div; - tmp = *parent_rate / (div + 1); - if (bestrate - rate > rate - tmp) + bestrate = req->best_parent_rate / div; + tmp = req->best_parent_rate / (div + 1); + if (bestrate - req->rate > req->rate - tmp) bestrate = tmp; - return bestrate; + req->rate = bestrate; + return 0; } static int at91sam9x5_clk_smd_set_parent(struct clk_hw *hw, u8 index) @@ -98,7 +103,7 @@ static int at91sam9x5_clk_smd_set_rate(struct clk_hw *hw, unsigned long rate, static const struct clk_ops at91sam9x5_smd_ops = { .recalc_rate = at91sam9x5_clk_smd_recalc_rate, - .round_rate = at91sam9x5_clk_smd_round_rate, + .determine_rate = at91sam9x5_clk_smd_determine_rate, .get_parent = at91sam9x5_clk_smd_get_parent, .set_parent = at91sam9x5_clk_smd_set_parent, .set_rate = at91sam9x5_clk_smd_set_rate,