Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9101533pxu; Mon, 28 Dec 2020 06:40:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJzg9xK2/BJafFG0Eixw9d5CTcMY/YfYbVE3oQSkZWIIsK0mSy8zig3Xw3zXzKr0k5269dWN X-Received: by 2002:aa7:cf8f:: with SMTP id z15mr42558085edx.17.1609166439448; Mon, 28 Dec 2020 06:40:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609166439; cv=none; d=google.com; s=arc-20160816; b=lQcMrjZiNkxVGqqTuMyf8YmmqoxYHQ5iowJkF8CYM6KfQLJv0ucKf4UNB7gizBCEPM c4eIEBYOQl/7MfkcOX0GcZ7v64/QT298bwuYqBmjJbmeCJyGhz5A9xftDSN9TXf1IOsT W25VGBnHHU5pU+e9M5fIRvZw+UN8UX4NSM7EPi3lp6JrCW8vk1w7ISvjr+EM1gFcXCUW Ct2hXsPcwl3DKilo7T3zBR2rAT9+RvplVyeHh+nj+qsWkVyd1kiOsiSmGFar6uQUHCTg 1shBHjmUY+1INMYeI2uScJWsH/hUgKVF1XYDMCuGUg0BEMiJbblaS2MwVTt5QoCcRzTS py6A== 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=N4pAmQ3/TmdbPtvuHGJA8bAc+7VIS9MdrBPCsw4ZKAg=; b=bdonJAoBeM6cds9Zm+7DZulDOQkPO3+F5xJQA/OANyHwXUweeiogYusaJ8S7gs5wEP /tzC7IAJ10WuqvnEWiyQ7yAd0FiJtFsWnLfqFcKUWbbUdtyKh0TLbiryJxQxGd2/SC0O cdFR2D8Lr1JcSFfetfOuDq47TnwxfTk5PKsqTKkZdx+Qz7ADs3OR19/1228DY4MW5HW1 d60xho1C3NTzAbVJjyWuhDmKYb6O4mql0nTIzbA2fyFW2UCzG4eai2djpFgu0mNI1aLL J3r+IHToHEWdEQrEqZT0mmoUp325Uo+VQsyjJ31AfsOhtEXN3wyuZ1LPc1qxb7l5UZv/ YgvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c92njSTq; 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 g3si17506316ejf.612.2020.12.28.06.40.16; Mon, 28 Dec 2020 06:40:39 -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=c92njSTq; 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 S2504603AbgL1OiU (ORCPT + 99 others); Mon, 28 Dec 2020 09:38:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:40144 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389082AbgL1OcA (ORCPT ); Mon, 28 Dec 2020 09:32:00 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 75E02229C5; Mon, 28 Dec 2020 14:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165880; bh=6KMEH1bve/4MgV21p22avlgY6vY+npyznjrhFxmLHPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c92njSTqDoqQVpa7CT4h2nMEip29G44t2kJc9h5xmJaIHW6pzlH7HiDIYLW5G0MKm Ss5QJDGb6TgpW0T6k/JkdjfcDoZaCzdcFKVq3YH1BpmcyTCTEnZngLE/XlXyhC4duc yNy7Wf9ZOCBEPcMy/4iSoSQkNsi4FavyohsbkLkY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paul Cercueil , Stephen Boyd Subject: [PATCH 5.10 688/717] clk: ingenic: Fix divider calculation with div tables Date: Mon, 28 Dec 2020 13:51:26 +0100 Message-Id: <20201228125053.932528023@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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: Paul Cercueil commit 11a163f2c7d6a9f27ce144cd7e367a81c851621a upstream. The previous code assumed that a higher hardware value always resulted in a bigger divider, which is correct for the regular clocks, but is an invalid assumption when a divider table is provided for the clock. Perfect example of this is the PLL0_HALF clock, which applies a /2 divider with the hardware value 0, and a /1 divider otherwise. Fixes: a9fa2893fcc6 ("clk: ingenic: Add support for divider tables") Cc: # 5.2 Signed-off-by: Paul Cercueil Link: https://lore.kernel.org/r/20201212135733.38050-1-paul@crapouillou.net Signed-off-by: Stephen Boyd Signed-off-by: Greg Kroah-Hartman --- drivers/clk/ingenic/cgu.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/drivers/clk/ingenic/cgu.c +++ b/drivers/clk/ingenic/cgu.c @@ -392,15 +392,21 @@ static unsigned int ingenic_clk_calc_hw_div(const struct ingenic_cgu_clk_info *clk_info, unsigned int div) { - unsigned int i; + unsigned int i, best_i = 0, best = (unsigned int)-1; for (i = 0; i < (1 << clk_info->div.bits) && clk_info->div.div_table[i]; i++) { - if (clk_info->div.div_table[i] >= div) - return i; + if (clk_info->div.div_table[i] >= div && + clk_info->div.div_table[i] < best) { + best = clk_info->div.div_table[i]; + best_i = i; + + if (div == best) + break; + } } - return i - 1; + return best_i; } static unsigned