Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3564300pxb; Mon, 24 Jan 2022 12:19:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJzglyHRqT2O4OBCFy3wSnN3pKlPl5hyUxUvvXIYy9cGnIxUSlk60iOGyo8IZPBvtCP0Q7Vj X-Received: by 2002:a05:6a00:1151:b0:4c4:b2c6:6060 with SMTP id b17-20020a056a00115100b004c4b2c66060mr15566656pfm.11.1643055473657; Mon, 24 Jan 2022 12:17:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055473; cv=none; d=google.com; s=arc-20160816; b=niyLfy9fDwmRB1v7JUclLhufd8LkvcnS8JF249XiIzBUVWXNiKS4uEnKJQPibKY9wV K8i++/UP6zfmOTq3gH2Z66ktCBPu1RuDWHKF6gjsoGmR1DXNn4ZpzS+Y7H7r1vRGMeoB EW1EXLy2gKYWG7lKZA3Hpvdeqs7TW+vru6NJIuwfOappEE7N3nB7NMPprXM0+dKamUvn ot1VLtQxLIEPX5kF5eqm1PKiFIS6hHuw9heBotVD293V+1Uyvl72EcancVlzAw18x667 hMR9XhAtDrhQ8nZH0X8ToM9ELymOJihsU44LK7MiL2au8LY2/6g38OgqMxPqKgnY9qJL FvXQ== 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=xfWr3JpCG3Y5202k3m2VuhITt8avvxTJH+cFnM6EJGI=; b=FwA/RTP3noxtiWv6WIRuJtMslyI88knq7gUcknypY5Uc5kmzt1pHqejjxRyuT5iagC XY/S7gH/geOMRt8SClssSljIJ+1EQ6w4iD23kYs+QTDquQU9Y/FjjBH5ukL21eHkTeJe 9RRHjPSuAU8EHCCs2y/ZJDH6Pb+tqMrQIsWr03HqNmlF2orOqI1OwEAQmrAwLsZA+hgF gfBLbK19M2qM2KcASKm0C/ED/D9HxBLE2abHD0MInXJyXmZoW6E+vLHMPDLOK9CaPkpo m6J1NpPvxXID8pKJs73f5RMLv3AoJO6MnukbDK+lUyuS9qIDdGkP/lx5SP9olHCFRqtM xHJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UMl2Qlau; 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 q7si16086973pgu.776.2022.01.24.12.17.41; Mon, 24 Jan 2022 12:17:53 -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=UMl2Qlau; 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 S1349584AbiAXTVA (ORCPT + 99 others); Mon, 24 Jan 2022 14:21:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238400AbiAXTM7 (ORCPT ); Mon, 24 Jan 2022 14:12:59 -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 663A5C0604D4; Mon, 24 Jan 2022 11:04:02 -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 070A060FED; Mon, 24 Jan 2022 19:04:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D38F5C340E5; Mon, 24 Jan 2022 19:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051041; bh=Mm29p/MNKCC/N2fGHWjrloJ+iJd7CPkhYTkIPF/7R3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UMl2QlauKj7R8TuC+SL2NCD0s0+UxkFynMdnhlhSki+o9qHtCEKleTX+Si8kFATF6 Lb7EQ+LTuje7HfK/M8Lrg1KK07I2Wao8S3Ew7Smj6fBEaB1Fx92J6IyxboD3myYl4Q OmYCPGfMmmo8qkGpkNfgymsUfCELCcRwnyux/tSs= 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 4.14 034/186] clk: bcm-2835: Pick the closest clock rate Date: Mon, 24 Jan 2022 19:41:49 +0100 Message-Id: <20220124183938.221804577@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183937.101330125@linuxfoundation.org> References: <20220124183937.101330125@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 98295b9703178..d6cd1cc3f8e4d 100644 --- a/drivers/clk/bcm/clk-bcm2835.c +++ b/drivers/clk/bcm/clk-bcm2835.c @@ -1233,7 +1233,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