Received: by 10.223.176.5 with SMTP id f5csp2779027wra; Mon, 29 Jan 2018 03:57:19 -0800 (PST) X-Google-Smtp-Source: AH8x225cwJQOGRmJlYVzge9BTxVhz6LAwEVPDGtZ/+lRgGqUFbXVWUzUEkgnqyd2ookh8Se9PRBT X-Received: by 10.101.77.207 with SMTP id q15mr21657899pgt.163.1517227039328; Mon, 29 Jan 2018 03:57:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517227039; cv=none; d=google.com; s=arc-20160816; b=IQP96NwyglFM7l6b/MC+Q3Sz2VXc4wN9hJo1U6xqWOIMJicZhrAVD4eiUhPYI3UDxN Zg1kGmQOdLzcAq9UOCWmv/5XMaYpiBFhMqtFhQbEn/823hPIevlA9GQYDpjisYmx23Yv w0W6OTuRulCzvMOow71NJxfv5c6edJ47Ruuy3T4rPRd2zAjzorcP1LN7fP2dpMWwP6Xu MGLvVb+hDqt1iO2qCZGx2Tulr3XdJVFG00OIx92Xbp+wjRHUE9GS8xvHVUPnJwO/ksPz eHZeJkUiXTU7A7/RAS/Ssl7D99wF1wGURA3jra7EZ2/cvuhEJgdBfkX9c1uR5DtyiQj0 bZew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:organization:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=xiMNHAR4Z8p4G/aGkc74Qw4017BYPaqL19alg8oXKyA=; b=hxHXKY+OAICW68VPG/tN/5/7dSDHnpYHdqjqNAwe/gbfUGlHkH+8k/6Mp4QavFZfWs EsD9VbTSZQlT8xkWAoPjKB4csggtX1zPQ2jOniUgtwck1k4kl76+xcYFZeiG02FLz4E9 8vbT19RTAySH8//wzhF52dUYWmxs8r6ptsDKhctitcqKYruH2ZyhNRtzF/iqi98/bMNG EmqUAwVpRPcqHLfUNBNKtuxPGXs64Ufajtiof0Vjc+LrebtduPOsDOr5pmPIVSM9hzv6 Aw+Qi1OKV7WO5NVQNmcGirl6fPHKb88Im2JNzZ/5CnwvVaTzKolHAHQM5FExhzw3nijr pQmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=SsXfkEK3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b184si7252709pgc.786.2018.01.29.03.57.04; Mon, 29 Jan 2018 03:57:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=SsXfkEK3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751959AbeA2LzK (ORCPT + 99 others); Mon, 29 Jan 2018 06:55:10 -0500 Received: from galahad.ideasonboard.com ([185.26.127.97]:53972 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751330AbeA2LzH (ORCPT ); Mon, 29 Jan 2018 06:55:07 -0500 Received: from avalon.localnet (unknown [IPv6:2a02:a03f:52fb:2b00:ac86:2f77:64c9:83c0]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id D7D64200AD; Mon, 29 Jan 2018 12:53:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1517226836; bh=Y+B8H+epNmnZv9PTJ7uuxs8qxzHg0sM1vSTpLElekoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SsXfkEK3p76KMF2X0r6yNd3eksljixUvZ9UNw5ArcGTNRGfSAC9tJR8++tJfuS2er OvobxLSQwU5a7uJ+ymlhEyYJdAEWGvgubqOOWigJTcd72CMQPXCmb1yDlelJ3bfsuc UQ1ukypdcErqNXlFX5JNAFt+sk9QdjGfEdz9Tke8= From: Laurent Pinchart To: jacopo mondi Cc: Geert Uytterhoeven , Jacopo Mondi , Magnus Damm , Kuninori Morimoto , Yoshinori Sato , Rich Felker , Linux-sh list , Linux-Renesas , Linux Media Mailing List , Linux Kernel Mailing List , linux-clk Subject: Re: [PATCH] sh: clk: Relax clk rate match test Date: Mon, 29 Jan 2018 13:55:20 +0200 Message-ID: <1598767.1mUcEZddqr@avalon> Organization: Ideas on Board Oy In-Reply-To: <20180126162454.GA11798@w540> References: <1516879493-24637-1-git-send-email-jacopo+renesas@jmondi.org> <20180126162454.GA11798@w540> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jacopo, On Friday, 26 January 2018 18:24:54 EET jacopo mondi wrote: > On Thu, Jan 25, 2018 at 03:39:32PM +0100, Geert Uytterhoeven wrote: > > Hi Jacopo, > > [snip] > > >>>> --- > >>>> > >>>> drivers/sh/clk/core.c | 9 ++++++--- > >>>> 1 file changed, 6 insertions(+), 3 deletions(-) > >>>> > >>>> diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c > >>>> index 92863e3..d2cb94c 100644 > >>>> --- a/drivers/sh/clk/core.c > >>>> +++ b/drivers/sh/clk/core.c > >>>> @@ -198,9 +198,12 @@ int clk_rate_table_find(struct clk *clk, > >>>> { > >>>> struct cpufreq_frequency_table *pos; > >>>> > >>>> - cpufreq_for_each_valid_entry(pos, freq_table) > >>>> - if (pos->frequency == rate) > >>>> - return pos - freq_table; > >>>> + cpufreq_for_each_valid_entry(pos, freq_table) { > >>>> + if (pos->frequency > rate) > >>>> + continue; > >>> > >>> This assumes all frequency tables are sorted. > >>> > >>> Shouldn't you pick the closest frequency? > >>> > >>> However, that's what clk_rate_table_round() does, which is called from > >>> > >>> sh_clk_div_round_rate(), and thus already used as .round_rate: > >>> > >>> static struct sh_clk_ops sh_clk_div_enable_clk_ops = { > >>> .recalc = sh_clk_div_recalc, > >>> .set_rate = sh_clk_div_set_rate, > >>> .round_rate = sh_clk_div_round_rate, > >>> .enable = sh_clk_div_enable, > >>> .disable = sh_clk_div_disable, > >>> > >>> }; > >> > >> Does this implies clock rates should be set using clk_round_rate() and > >> not clk_set_rate() if I understand this right? > > > > Not necessarily... > > > > Note that both cpg_div6_clock_round_rate() and cpg_div6_clock_set_rate() > > in the CCF implementation for DIV6 clocks use rounding. > > Yeah but it doesn't seem to me that CCF implementation for DIV6 clocks does > have to walk static tables like the old sh clock driver does. They > perform rounding, but on the clock dividers given a requested rate > and the respective parent clock, if I'm not wrong. While clk_set_rate() doesn't explicitly document that the rate will be rounded, the clk_round_rate() documentation does: /** * clk_round_rate - adjust a rate to the exact rate a clock can provide * @clk: clock source * @rate: desired clock rate in Hz * * This answers the question "if I were to pass @rate to clk_set_rate(), * what clock rate would I end up with?" without changing the hardware * in any way. In other words: * * rate = clk_round_rate(clk, r); * * and: * * clk_set_rate(clk, r); * rate = clk_get_rate(clk); * * are equivalent except the former does not modify the clock hardware * in any way. * * Returns rounded clock rate in Hz, or negative errno. */ So I think the SH implementation of clk_set_rate() should round rates. (And feel free to send a patch for the clk_set_rate() documentation in include/linux/clk.h to state explicitly that the rate will be rounded). > Anyway, in this case a much simpler: > clk_set_rate(video_clk, clk_round_rate(video_clk, 10000000)); > does the job for Migo-R. > > I will include this in next CEU iterations, since I already have a > small comment from you to fix there ;) That should not be needed, but if the above code is in a board file, I can live with that until drivers/sh/clk/ gets fixed. > >>> (clk_rate_table_find() is called from sh_clk_div_set_rate()) > >>> > >>> Or are you supposed to ask for the exact clock rate? Where does the 10 > >>> MHz come from? > >> > >> From board initialization code, in order to provide a valid input > >> clock to OV7720 sensor. -- Regards, Laurent Pinchart