Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3635475pxb; Mon, 24 Jan 2022 14:04:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyKhBrBMArBYrwhLht4GsupIgh+LecBuyo2cIT1uVgjHVvqMtMUyQOEwTIOOQP7cBCceapW X-Received: by 2002:a63:213:: with SMTP id 19mr5624734pgc.429.1643061862014; Mon, 24 Jan 2022 14:04:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643061862; cv=none; d=google.com; s=arc-20160816; b=uBXssHd9Ioq/wmuHJ3MtAMEGMqDc2FEKlSBVDJ/s7Az76BoQMwNyQv4vyqCH9l3yhw YO/Ubz0QPJIx3NGsD/SIgkfuNKDGrICeD5NmW0/oClXKCEG0+O2TOGb7yM13PyGtl5BP faoC/AMLB3lUOdrhU7GSEQ4Tmd2HXjw2BP43LaR4VR+1UkiZ5WhuWRSfMOTvmC9viE/7 FsEfGMKsy4sKz9ZcJKKFu1B86AHojqqRlIwjLxcdpp5bauRLEgV3UL+x/dwTbLNEzPdC 2Grc/WWqarxoDPz+FNW7F0V5VqvhhZ4U5BtvEnPkueqRN+SQJTbQqKSEG9yJIYacI8d8 lRpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zS2ZqGAbX4f+yAa4nv/9LLaCZytyKWBQ7dtE44mV1cs=; b=elY80yj1brgkm4Vvq9gAUPe2d6X8viCPB69lvjaJoJZUgaoZOCmkLKtFUEI3hL92ZT iX8S7PzmMyq+a4A8wnp9PC4LID8fEsv13tV4bsHkPuieNs8bgVzZ9KQmr8IVyIXtE/Fe GLX/cMn8T7boEd3RmciuPAxoyY2nNXu/KQUGAcWTRaiATSog5xPrzmPQ72mY5TK2QOuk lekgiSupwO9UJDsy9+RL/PqHXjWbtxLkiu/NhvQTBn7x3RIbk1uebT6tllN0h5htd3VV 2xX++MhOiCrUZTVe5vRXTDBwB1MOtY0PCxBijofFcQGhjla3wTAK7lX09sPXNYwkPjDg zeKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xWESEjb7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v11si1678416pgb.140.2022.01.24.14.04.09; Mon, 24 Jan 2022 14:04:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xWESEjb7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1575727AbiAXVwZ (ORCPT + 99 others); Mon, 24 Jan 2022 16:52:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1450151AbiAXVTu (ORCPT ); Mon, 24 Jan 2022 16:19:50 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57E36C06F8FA; Mon, 24 Jan 2022 12:14:01 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EBD066136F; Mon, 24 Jan 2022 20:14:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC5E8C340E5; Mon, 24 Jan 2022 20:13:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055240; bh=nLAh1WwS4fr/AUWaPNjL/z4wUxnfEXp/q678GyhCGxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xWESEjb7M6nR+sQk9RKokRf/1h1hsNvNrfTxNJlQ6Bwl6v6uEnOSS/X0W3QRAkwH9 amOiD8RMxAe2ZvaQcvPtshrnN2Kw4r3R5Z2VuU0xN1eGz8w3oYT9KztDlvPmsvNxIQ 28Nml+OhwMZJdb4msqQmV1HMMtBmsxw0QG+ai70A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Maxime Ripard , Stephen Boyd , Nicolas Saenz Julienne , Michael Stapelberg , Sasha Levin Subject: [PATCH 5.15 087/846] clk: bcm-2835: Pick the closest clock rate Date: Mon, 24 Jan 2022 19:33:24 +0100 Message-Id: <20220124184103.987362267@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Maxime Ripard [ Upstream commit 5517357a4733d7cf7c17fc79d0530cfa47add372 ] 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 Acked-by: Stephen Boyd Reviewed-by: Nicolas Saenz Julienne Tested-by: Nicolas Saenz Julienne # boot and basic functionality Tested-by: Michael Stapelberg Link: https://patchwork.freedesktop.org/patch/msgid/20210922125419.4125779-2-maxime@cerno.tech Signed-off-by: Sasha Levin --- 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 a254512965eb8..bf97b2b2a63f8 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; -- 2.34.1