Received: by 10.223.176.46 with SMTP id f43csp2223486wra; Thu, 25 Jan 2018 06:47:53 -0800 (PST) X-Google-Smtp-Source: AH8x227Ewmgt8ty2U2x4yRJzqlGrip4a3iBvqoKHXQx7lh+1C6DnsJHZMjzSDY6U4vHWiU285Njj X-Received: by 2002:a17:902:6544:: with SMTP id d4-v6mr11175243pln.117.1516891673077; Thu, 25 Jan 2018 06:47:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516891673; cv=none; d=google.com; s=arc-20160816; b=EzwtYgswUAYDmNmG3k4OTmVVKyZE+QPKVJVxKMXrnKyGgycWrYNqdqiVhPIfRXhkCm KAa8rWz0SnxycveeKdFM039yndFg90MpMsyPuAUTUgUmLwoHQ2z0L2jSreeNWaDj9pcF aOdxRpL7QFjnDmqhXHsgmavxwEFiCuPFqC+xQZMqRidO45g5SjjONr9Gf8xuLp2FTf0E iCNKbU2gArBGdI4B25OZOU8S3yxFAt6oPDiJi29vqpmtFp6XVvxX7lBmwMzEG84WxuTZ Yva7PcbxO9qtICtIacm2x1ZQGEYQqws56Jm3jSrKB5KeDly3T17n3frOZATcQcBhW4iV 7OCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=00LgLuIbZCfV7SUbKy8euWzsAMo5n02Nge2oQE22VTs=; b=ymOg5HjnolOVDuh6i1XpDkFWjEJiLjzP1rCsbMW6ipB+0WaWQ+jqXQt/pEczPhOOpu AWjIhdfpWH7zM+sr6BucRxq0o1r/RhIj8yvRyrvwB46ydVSKFRi2lra/IZ3Q9xOoPHDI l7KTTsqBjlSloq0YWyatmuO1jOUgrpqtXI+vV2apPUkOSuU36mAYarSQTn/TpyMNXiSK X2P0wo6mjPJkfHQWSL3fPflYiU7Gn51DtOO8Mmk/SLVwiR1hdX9YwoTZgC24kGljqfXk uaI+4BqhQB6Ebu/VnHDzDIwAuW3Y4lc2QccDCaastXa5CXo6HvdPLyAi621OuptrQbXc dRGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=I4z+KdSy; 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 63-v6si2084540pla.526.2018.01.25.06.47.39; Thu, 25 Jan 2018 06:47:53 -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=fail header.i=@gmail.com header.s=20161025 header.b=I4z+KdSy; 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 S1751897AbeAYOjh (ORCPT + 99 others); Thu, 25 Jan 2018 09:39:37 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:34699 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751443AbeAYOje (ORCPT ); Thu, 25 Jan 2018 09:39:34 -0500 Received: by mail-qt0-f195.google.com with SMTP id a27so19737025qtd.1; Thu, 25 Jan 2018 06:39:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=00LgLuIbZCfV7SUbKy8euWzsAMo5n02Nge2oQE22VTs=; b=I4z+KdSyJlM0lc3LPaqrSWn+IL+nO4zP8syDBcbRP4tYPbhuAOmVSC24CSR7ghw98v G6xmlOCsLIBBrs1jPcKGxRtaHmlDC3/VUYUNyY2WLsRK6f/jkHEgPZgInN9gZIuUaRGt ANm0XkyN5Z6ZEfjusFPCi7qSfTcTw5BOIdf+RcTKfkIbNx7pVQjVUdkhWGqACxeEL/MW bg7auU5Lqmslsexhvy6JxbXVOXqPlGqQHldjGg/NWIFWWNab49VydTkytnUSYsXI0Nrp PnZOom6iIW9i2sbuSdQZUBueDt+CcqvV4Uik+Z5R/y2BOegbnOsBO++5Q8RvD5/8ylbU fk8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=00LgLuIbZCfV7SUbKy8euWzsAMo5n02Nge2oQE22VTs=; b=r4kxX3oizxPpFCjFLXB4nofznqvXal8NIfQHTrAduM3FeHZ7dro8/PVYSe2PyyMMdF Ym+KgZkWB2wn9aqv2qs5GWA6Ns8s/456+meJNVnlXZkkgc3N6HqOVycSc0pbWmTctN1d hUTB/U2iP7Lg21ZEmVhhjNTCUQrmXQfu8m5osrM7mZMuCL+exzkyOFVJlJ1hH62KkqJh j3pw9XBNKfsg4rP7baGUZ9P6y6vHtccEWqy/Q1s0bOBrvTqlwZ4EHMnI+kiGkG9HhGnd QpzsGromANNymQypcrKkwqD75Y78skHy2TZW841v+jXBx0SJSQB7yRNF4AITugJciaUg oFiA== X-Gm-Message-State: AKwxyteqTpirjOs+rM0KNIXVihLr9p2Q6q9SFEoB3eID4nEcsMsbLBZ1 WnQK6/JLemNu2Z1i/ZJHUdZM4XPEhObXa+CyLgA= X-Received: by 10.237.50.99 with SMTP id y90mr17353083qtd.274.1516891173147; Thu, 25 Jan 2018 06:39:33 -0800 (PST) MIME-Version: 1.0 Received: by 10.200.45.161 with HTTP; Thu, 25 Jan 2018 06:39:32 -0800 (PST) In-Reply-To: <20180125141407.GH17416@w540> References: <1516879493-24637-1-git-send-email-jacopo+renesas@jmondi.org> <20180125141407.GH17416@w540> From: Geert Uytterhoeven Date: Thu, 25 Jan 2018 15:39:32 +0100 X-Google-Sender-Auth: kwj5HUbAa7GMqqHGhUc4RJh0MOM Message-ID: Subject: Re: [PATCH] sh: clk: Relax clk rate match test To: jacopo mondi Cc: Jacopo Mondi , Magnus Damm , Kuninori Morimoto , Laurent Pinchart , Yoshinori Sato , Rich Felker , Linux-sh list , Linux-Renesas , Linux Media Mailing List , Linux Kernel Mailing List , linux-clk Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jacopo, On Thu, Jan 25, 2018 at 3:14 PM, jacopo mondi wrote: > On Thu, Jan 25, 2018 at 02:53:41PM +0100, Geert Uytterhoeven wrote: >> CC linux-clk (yes I know this is about the legacy SH clock framework, but >> the public API is/should be the same) >> >> On Thu, Jan 25, 2018 at 12:24 PM, Jacopo Mondi >> wrote: >> > When asking for a clk rate to be set, the sh core clock matches only >> > exact rate values against the calculated frequency table entries. If the >> > rate does not match exactly the test fails, and the whole frequency >> > table is walked, resulting in selection of the last entry, corresponding to >> > the lowest available clock rate. >> >> IIUIC, the code does not select the last entry, but returns an error code, >> which is propagated all the way up? >> >> > Ie. when asking for a 10MHz clock rate on div6 clocks (ie. "video_clk" line), >> > the calculated clock frequency 10088572 Hz gets ignored, and the clock is >> > actually set to 5201920 Hz, which is the last available entry of the frequencies >> > table. >> >> Perhaps 5201920 is just the default (or old value)? >> >> > Relax the clock frequency match test, allowing selection of clock rates >> > immediately slower than the required one. >> > >> > Signed-off-by: Jacopo Mondi >> > >> > --- >> > Hello renesas lists, >> > >> > I'm now working on handling frame rate for the ov7720 image sensor to have that >> > driver accepted as part of v4l2. The sensor is installed on on Migo-R board. >> > In order to properly calculate pixel clock and the framerate I noticed the >> > clock signal fed to the sensor from the SH7722 chip was always the lowest >> > available one. >> > >> > This patch fixes the issues and allows me to properly select which clock >> > frequency supply to the sensor, which according to datasheet does not support >> > input clock frequencies slower than 10MHz (but works anyhow). >> > >> > As all patches for SH architecture I wonder where they should be picked up from, >> > as SH seems not maintained at the moment. >> > >> > Thanks >> > j >> > >> > --- >> > 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. >> (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. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds