From patchwork Wed Sep 22 12:54:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 12510603 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 669EDC4332F for ; Wed, 22 Sep 2021 12:59:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 318CC61181 for ; Wed, 22 Sep 2021 12:59:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 318CC61181 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cerno.tech Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=c2GdUuVTssvCwhJViz3EsXyPFfv582exreVemZ8utKg=; b=Bn/C1EiMdRwIh2 e4T0soNpOEBniDP6iwbUqMxTjvNM2gMKAnCbsTiYRuXjYd+1Lbe99SeQr+i3h5EpdS8ozHeK2bfz/ Zjn+Q8YFeafQsuRocYdNlRVEnN5qKEWlah6JRBoAH0c74LqBws76REu2Tg4N/VCuZIxmzWCOowV5u 0mXJmLJ6H+4cu6SYAKKrMULg4afxMLrRCbjmZBHQArTFK+8LLNqUbSZhypIvGN3eLmro8RZWGaCHE HKpH9XJefjtGky0DTk+3WlwjYm4PEJDem1XtXXrSKpjKVaz4jiYUQeSxJ4ZcxJ5grm4PDVDLRZHo5 F7wwNTe0muSwoIe0eRjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mT1oZ-008THo-8Y; Wed, 22 Sep 2021 12:57:32 +0000 Received: from wnew3-smtp.messagingengine.com ([64.147.123.17]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mT1le-008S7u-7b; Wed, 22 Sep 2021 12:54:31 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.west.internal (Postfix) with ESMTP id C8B0F2B015E6; Wed, 22 Sep 2021 08:54:28 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 22 Sep 2021 08:54:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=mct8oUUoPQCmb XzWWfTX5bHQO1PQnsAmowWUCVA6sbM=; b=kPF2S1eZC/yeq7ngJhq+C5+2SGDMc 6g4R1BAPfpAat8lECFY5Qkoq65WHuTO4E9HX6wzqtzj7+ox3OBgqrBqJ/T3b8A5e YF/1b8e9aNnEFQ8TqltOXD3/V9EowkY0/51V3bT0fLv3S6kreDMiWHYPiP1nZw9L RLwvioBr+1SE8H3YchGUGW3p6JO1Cgm2Fog8Y3OIAiy6zb6zWHXEmp8L16CNAQBh vk/zMEcmZ9yO50LS4ngIOh1Zm0A9cliUHFPRn26rG0ndnhGpf3oTfHq7V7SR4i1M BfmrwlDPXF6Ue84DaTvUMHbS3+54opSA4lpCNoksBRbmnW+QBbCqCsU8Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=mct8oUUoPQCmbXzWWfTX5bHQO1PQnsAmowWUCVA6sbM=; b=DN6t97Tw jSFK2L1Ng+NOpe/Ux3Nfrhg911RsZFPi5WMrMM948WsA/MdHOePn22GLZtktEoN5 yp/6eDN3XI3krIVZFZKEHxnOw+PaE7b7+pe4oZ5QJ/kG+ki1w8sMytUUE1cQGxGf Wau11+mkxauchihXfXmrq9t+ARPJ8vr4ScdI5aJ0nMx9PMlDtPOaouycXxJpzPxH /8QtimTVWDikFMxhNvFE0iilOKSll7dm7BxzwGiE+32/e2xf5fc3Gf7lqvpCObj/ 8beVmUwFb0na+XbUrFkZnnSbQJmISEzrkjDynGnYwfUcZKifY+aLzZWYHtImHaui gM8setN182W/YQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudeijedgheeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepvdekleevfeffkeejhfffueelteelfeduieefheduudfggffhhfffheevveeh hedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmh grgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 22 Sep 2021 08:54:27 -0400 (EDT) From: Maxime Ripard To: Maarten Lankhorst , Thomas Zimmermann , Maxime Ripard , Daniel Vetter , David Airlie Cc: linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, Mike Turquette , Stephen Boyd , Nicolas Saenz Julienne , Florian Fainelli , Michael Stapelberg , Linus Torvalds Subject: [PATCH 1/5] clk: bcm-2835: Pick the closest clock rate Date: Wed, 22 Sep 2021 14:54:15 +0200 Message-Id: <20210922125419.4125779-2-maxime@cerno.tech> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210922125419.4125779-1-maxime@cerno.tech> References: <20210922125419.4125779-1-maxime@cerno.tech> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210922_055430_341183_E3F19928 X-CRM114-Status: GOOD ( 13.87 ) 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 The driver currently tries to pick the closest rate that is lower than the rate being requested. This causes an issue with clk_set_min_rate() since it actively checks for the rounded rate to be above the minimum that was just set. Let's change the logic a bit to pick the closest rate to the requested rate, no matter if it's actually higher or lower. Fixes: 6d18b8adbe67 ("clk: bcm2835: Support for clock parent selection") Signed-off-by: Maxime Ripard Reviewed-by: Nicolas Saenz Julienne Tested-by: Nicolas Saenz Julienne # boot and basic functionality Acked-by: Stephen Boyd --- drivers/clk/bcm/clk-bcm2835.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c index a254512965eb..bf97b2b2a63f 100644 --- a/drivers/clk/bcm/clk-bcm2835.c +++ b/drivers/clk/bcm/clk-bcm2835.c @@ -1216,7 +1216,7 @@ static int bcm2835_clock_determine_rate(struct clk_hw *hw, rate = bcm2835_clock_choose_div_and_prate(hw, i, req->rate, &div, &prate, &avgrate); - if (rate > best_rate && rate <= req->rate) { + if (abs(req->rate - rate) < abs(req->rate - best_rate)) { best_parent = parent; best_prate = prate; best_rate = rate;