From patchwork Thu Feb 15 15:09:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xiwen via B4 Relay X-Patchwork-Id: 201525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp463152dyb; Thu, 15 Feb 2024 07:09:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVc51RaBQjVJaAyakp1yizRVMDTRmrfa+OmvFOcJKqVkbx/VMfW1noRb0UU3+UdlXt4kGyV1/rlP/DT15PAMoj4igh4nA== X-Google-Smtp-Source: AGHT+IFsaG8Pkc1HL1YuW74SKv9R6DReUdYWqKJ9FBaqINSftNS2ioXV46HY/3dCk/KHXoNE5HBG X-Received: by 2002:ad4:5743:0:b0:68f:280f:14d2 with SMTP id q3-20020ad45743000000b0068f280f14d2mr1193448qvx.34.1708009764443; Thu, 15 Feb 2024 07:09:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708009764; cv=pass; d=google.com; s=arc-20160816; b=PZBmF2myocqS1hNnjqF4vn2aPQjkKMU+4CycO+87Unv0kxWTGm0JIVQ5jCViBbk4JN MyNM9z0of5xEjgN90JZw/Ms9jTQVsYE2J9oB4ZWnnbI2sq0e9keEDVtwutn14DC+BYlL 40oWCwZJumFev3tlJvMLq5HE0pKUT3RJhGh3E6M1oGXna5tOt+ZZjwrWAGwVnPFXRdHp lQZ1n4Nymk4h2K90+6p35WaTEqz0Tjv8TUfho1+fWSGrR+gYqz+wcyt9d4x1J4Oface6 mzLzStj1zV9o7gNVXcaB11abeCdcnd7I8qCGN6uFQlIwFR6moJfuRagwrvbz4FruuCwr TYFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=reply-to:cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=/49QG7Y9ZC8s3ZWt3sAGsAe+4ZBDeDkZ0IMj7Vub35w=; fh=utIdiGrj5Jo6nUagmhsgB1Yak5swVpCUOlGu/v2oCG4=; b=MdweO/tqKNxb+5bLsDbTlTglvzF7PP9wcHQs3yy0veO6utG/eNmL5+EBZYxhGcKcmD WUQrefoWbm+AmHp82Pt8HRosdg2DYPPEVoHm7gqW+IUr7bjVj/RjZptJJKapwh+RIf+9 6SvGE+ExWL5Zladq65h29qp7FB6QfvbGhN0rfbyaXzKz/165x1NwDiK+vPr0pUZe0oOZ 4w+jXqDQQc0wnsOhVDuMqFn4jCKlpWMraTZh6+mnybUhvuMpGGTghcfrmOC2hyDbrQpO qq5LsVedV3Zo6iZiA5Ebb8hju1ZzyYEWqcSlC6PceVwTKOMv4PlpmkCYppf/qNDguez+ CDwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Xude8sqO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-67139-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67139-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id fo9-20020ad45f09000000b0068cc632e7dfsi1649740qvb.50.2024.02.15.07.09.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 07:09:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67139-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Xude8sqO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-67139-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67139-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3FDE61C218A8 for ; Thu, 15 Feb 2024 15:09:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 613EA132C1B; Thu, 15 Feb 2024 15:09:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xude8sqO" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B654D13248B; Thu, 15 Feb 2024 15:09:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708009750; cv=none; b=ZS0TNRfEONbuuj3Uu+SOkBufrxyet6KfJP0gCZoIRSjcI71Ld1skzE/u74u6miQfF5On6HI7ejADJ66n6YOjKOKGXTxvJ1gks5kxk+KvWuRJuge3tPPTVNsPyF5I+CU+rtdB1R9HjfJO6NU1wQ7yYIJsnd5tm7ZofPf8uTIq8wE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708009750; c=relaxed/simple; bh=jPhUX7fseszIBa5Cz4g6HtJ32wY5HpFdNrxQegeyAcU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=NvTFK7ob65JjjQRxYT0b8MsQ527COx/nNBg/Z1/linjnvrd0T3DYpdDlUnjwldsJrMi6waJS1tKAcltQuQxAByOw7mU9qYMHM1Ku1Up+Q6h60JDIxokK2uO2KdhEFm9R1hezOzfR8AIlNSYOuvCxsm5Jz3WlFGwKQmJdmAskE70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xude8sqO; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPS id 833DAC433C7; Thu, 15 Feb 2024 15:09:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708009750; bh=jPhUX7fseszIBa5Cz4g6HtJ32wY5HpFdNrxQegeyAcU=; h=From:Date:Subject:To:Cc:Reply-To:From; b=Xude8sqOiVdg231+aBTlQVEWxWUncmugjUAZEc0e7eyRqBCGubPrQQnuxVjpYahyl SyWkj+WsA758DXkerF6rhcrP2IdoOgzYq/ErVepbUZYetP+fEWqEXLMjzG3DCu7Xco LddQ4tsH/psTEwtMApnURTE+kBVQigwCzXEd+H0pLrmz1Z2941NFh61JX5YGiK9OIP xMB2KIBKcpPDhtP1wl96WpdxWpuhYK9/eTo4W3tkpCigpMaUYqbW29dQhd9oNSbfmQ QxEplSeiaQhTaqzKh5JbuuWkpj9x40iyKry3A5PqbV/wOQcD9zSjTCbEp6TseGHvu1 CjyVjlgcGbxXw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C5E7C4829E; Thu, 15 Feb 2024 15:09:10 +0000 (UTC) From: Yang Xiwen via B4 Relay Date: Thu, 15 Feb 2024 23:09:11 +0800 Subject: [PATCH] clk: set initial best mux parent to current parent when determining rate Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240215-mux-v1-1-ebb2fba31d49@outlook.com> X-B4-Tracking: v=1; b=H4sIABYpzmUC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxMDI0NT3dzSCl2zlCSLJGNzQxNTSwMloMqCotS0zAqwKdGxtbUALxNcR1U AAAA= To: Michael Turquette , Stephen Boyd Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Yang Xiwen X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1708009751; l=1451; i=forbidden405@outlook.com; s=20230724; h=from:subject:message-id; bh=fggch9mxMQ8SzPlFXnQcVvzDJCD3ro+vLZXoDYu1RGE=; b=wxjkbfTu/rBP44OMka17mBI8BMrBoao1MdhKtAdERg9Fwk4DSHxtLiTFHjXE1Uzk37ksKfWK6 Vqg0qaYsmCACkojwPFrwYG6rvVm8oPv0ZySlUoc58fjg8jpb2yMSbLX X-Developer-Key: i=forbidden405@outlook.com; a=ed25519; pk=qOD5jhp891/Xzc+H/PZ8LWVSWE3O/XCQnAg+5vdU2IU= X-Endpoint-Received: by B4 Relay for forbidden405@outlook.com/20230724 with auth_id=67 X-Original-From: Yang Xiwen Reply-To: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790978047094880356 X-GMAIL-MSGID: 1790978047094880356 From: Yang Xiwen Originally, the initial clock rate is hardcoded to 0, this can lead to some problem when setting a very small rate with CLK_MUX_ROUND_NEAREST. For example, if the lowest possible rate privided by the mux is 1000Hz, setting a rate below 500Hz will fail, because no clock can provide a better rate than the non-existant 0. But it should succeed with 1000Hz being set. Setting the initial best parent to current parent could solve this bug very well. Signed-off-by: Yang Xiwen --- This is actually a v2 of [1], but seems too simple to have a unittest. It's tested in a mmc host driver. [1]: https://lore.kernel.org/linux-clk/20230421-clk-v3-1-9ff79e7e7fed@outlook.com/ --- drivers/clk/clk.c | 4 ++++ 1 file changed, 4 insertions(+) --- base-commit: 8d3dea210042f54b952b481838c1e7dfc4ec751d change-id: 20240215-mux-6db8b3714590 Best regards, diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 2253c154a824..d98cebd7ff03 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -649,6 +649,10 @@ int clk_mux_determine_rate_flags(struct clk_hw *hw, /* find the parent that can provide the fastest rate <= rate */ num_parents = core->num_parents; + if (core->parent) { + best_parent = core->parent; + best = clk_core_get_rate_nolock(best_parent); + } for (i = 0; i < num_parents; i++) { unsigned long parent_rate;