Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3586217pxb; Mon, 24 Jan 2022 12:53:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJxCorwusbNAyjhEPkLrCvtWbTroDT5V/++wH44g0k3fISDU0ayFB8uSsa1VAPRfEftXWsdt X-Received: by 2002:a63:79c3:: with SMTP id u186mr13189905pgc.488.1643057598811; Mon, 24 Jan 2022 12:53:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057598; cv=none; d=google.com; s=arc-20160816; b=pkvownjx824ygc2EWhV/GJgkah5wHvWRxeRJgEhUeCDgphpSluHzt6MLVdny/+yood q8DOfJWnXVW7Gs1CE9it1P5wdh8eCjs4CiMNdEoGMdYmzgTWHfVpel+ZBmtQyB5Xo1zE Dt7FBv5nK/Yl4qZVeocRXRW4vVrQkeCT4JvLae/c49wPDYvPv/KxxIvgupbXcKrudGmJ g2usvTd4b0R0UfMBK+xo35Z0y8X+1ACkJIsRvq5j9LKHL2qmk6U1aJeGBcza59mrNfr6 eTMD6pJso32RzR04odaIri0TG8q22ehn12uZimc5q7cUZ4XV/G0WX8J38HKpfrnD0Rhs YD3Q== 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=WRlC3me926R7rd9ED3pMOoc9OdPRze61On5GMdh1wQU=; b=p1j9Kf8cEBCSv4+sa38Gc0DRSJWbzpCdxIBVp9ejyWqxyOjhhVr1phJ++0e2n9ByeG upcT0bMzSFn3jJvC2xqwFs9HLeYWfa9zLqL78y2gmqWMYLw9qozPQ0R2Unf8zXkyPHgv AmteSOqxRRghO+24orf2v7YWXb/3vJ3lADbr5VXVqAv9srFu47nXy16nLy+9u9eg8dys mEd0kc6j2uSvkerwpcr13NLR1Pgy8rgoAVDTVZHeRMr4nLDLfto7AM1KZ3oLzkU311zs Z59S4BFyg2SJyPdsqEZ4nZSKAdc/KLn2wBrosYBbouehuxGAc/ak/p11RuJy8BNH2+no 2UgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tLW8eWyo; 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 d68si9853524pgc.193.2022.01.24.12.53.06; Mon, 24 Jan 2022 12:53:18 -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=tLW8eWyo; 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 S1379190AbiAXUKd (ORCPT + 99 others); Mon, 24 Jan 2022 15:10:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352195AbiAXTwp (ORCPT ); Mon, 24 Jan 2022 14:52:45 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB36DC061394; Mon, 24 Jan 2022 11:26:16 -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 ams.source.kernel.org (Postfix) with ESMTPS id 7286CB81239; Mon, 24 Jan 2022 19:26:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90EB5C340E5; Mon, 24 Jan 2022 19:26:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052374; bh=l2qkhwyajAQCjSYqn/KNwyizSyty6BnN/EXpCzFQ+wo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tLW8eWyoX1+p02EU0QUytJiG+npQONmDhc1fatLSU7/guTU/fPsJrMGzhBQFOWNQr AyVep+D4wolJ3HWpddkHuHTsdjJ/3djIeQH7QGvmz8rXkSf6Rrftxtb3/k4Y9rAcjE Q5rpfscjmnVTkmzi9kYigTqRk2/YHP9fvxByMWXQ= 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.4 038/320] clk: bcm-2835: Pick the closest clock rate Date: Mon, 24 Jan 2022 19:40:22 +0100 Message-Id: <20220124183955.050123837@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@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 c5486537b9284..b2af320d1b6c5 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