Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3623117pxb; Mon, 24 Jan 2022 13:45:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxCROeTN58Lx9W9UhhcC2xTNQu3FQoGOv8lIaf+J9G7RMgy4Jm47ZwNAQqI4XpEzjAF/dH8 X-Received: by 2002:a17:90a:ab8d:: with SMTP id n13mr193653pjq.133.1643060623228; Mon, 24 Jan 2022 13:43:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643060623; cv=none; d=google.com; s=arc-20160816; b=yRnog/2Nbe4Ohmlg9Yqb+m0oWQqCmSs4PVq27jpVRAmPtqj1KmPCppEP/aCwEnCVWB 54JyAfoZjGf9iFGjdMJlQSGFcEmi1ivUkm284LBIeH2p2+SiChAKhOMvLPliZm2ABKG/ MHxmakUe8XUEqkTg45ALUTqmQ2G6DarclIbDjA+F0k8lm49aTKuBRA+Wp1M4+OS10HTG KfmAAXTUNqmKplueIVSgek7IZevN6HyK3Mmgo/rxmjF4jC5ZSh7st0ivOpz4kb65kBPP vjd46hGBLv/7t3FoohOTyCRgGlLX2+/nX85Nvqux31Ssp0u5g37fsixYa2vjjDC5l3jL Ya/A== 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=GvTpkmUZnOvv6QA5pGJScJDchyGJni5c/tvQmvO1PyzBbSy9xkJHSC9Q/En9K2j5Sm EwfvlRaAvGp+rvsq5RL7VG8ivOpp6D9356mYj0VqOOI22S7sJARrR9sq8cGZqPQFd4UF dkqRZhL6l4xu/EFiksFDMEgXvDV06R1b4nSn2IeRhT+G/43LiUAX2UfMx6G01eA+KOqh zPdo8fruIsNJwyurNAl5LSN2XTKbZZB8EYCL3YbIeANcKMR6OHjvRRleXuzmyB3pmKtZ Pgw0KxGSoJlvARv91mjPGsa/GWsrH3RIjGe7vRpOdKvoMIGcQ6y3p/BXJC5uucrsku0N vqCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gE2sETQk; 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 q7si6518pfs.281.2022.01.24.13.43.26; Mon, 24 Jan 2022 13:43:43 -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=gE2sETQk; 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 S1452143AbiAXVYJ (ORCPT + 99 others); Mon, 24 Jan 2022 16:24:09 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:49988 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443526AbiAXU5M (ORCPT ); Mon, 24 Jan 2022 15:57:12 -0500 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 1549D60907; Mon, 24 Jan 2022 20:57:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF01EC340E5; Mon, 24 Jan 2022 20:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643057831; bh=nLAh1WwS4fr/AUWaPNjL/z4wUxnfEXp/q678GyhCGxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gE2sETQkVLDyHe0vjqti6FY/AACWlBIqEASC7C2vUktLQ4hK7d5zBR/no8ZUbyG3w hsyt6RGHy4qkCrI8Hnp2G5ZZJXPWr4yO6ZZhURXwzpnPZ7tzy06z6T40Py2KmtKNxV qBdFpISQwcwYin7qhEYN/764m0CPO28WCvj0UOiM= 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.16 0094/1039] clk: bcm-2835: Pick the closest clock rate Date: Mon, 24 Jan 2022 19:31:23 +0100 Message-Id: <20220124184128.313189119@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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