From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexey.Brodkin@synopsys.com (Alexey Brodkin) Date: Tue, 28 Feb 2017 15:11:03 +0000 Subject: [PATCH] arc: get rate from clk driver instead of reading device tree In-Reply-To: References: <1487759796-14418-1-git-send-email-vzakhar@synopsys.com> List-ID: Message-ID: <1488294662.3913.11.camel@synopsys.com> To: linux-snps-arc@lists.infradead.org Hi Vineet, On Wed, 2017-02-22@10:34 -0800, Vineet Gupta wrote: > On 02/22/2017 02:36 AM, Vlad Zakharov wrote: > > > > We were reading clock rate directly from device tree "clock-frequency" > > property of corresponding clock node in show_cpuinfo function. > > > > Such approach is correct only in case cpu is always clocked by > > "fixed-clock". If we use clock driver that allows rate to be changed > > this won't work as rate may change during the time or even > > "clock-frequency" property may not be presented at all. > > > > So this commit replaces reading device tree with getting rate from clock > > driver. This approach is much more flexible and will work for both fixed > > and mutable clocks. > > > > Signed-off-by: Vlad Zakharov > > --- > > ?arch/arc/kernel/setup.c | 6 ++++-- > > ?1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c > > index 3093fa8..49b0804 100644 > > --- a/arch/arc/kernel/setup.c > > +++ b/arch/arc/kernel/setup.c > > @@ -10,6 +10,7 @@ > > ?#include > > ?#include > > ?#include > > +#include > > ?#include > > ?#include > > ?#include > > @@ -488,7 +489,8 @@ static int show_cpuinfo(struct seq_file *m, void *v) > > ?{ > > ? char *str; > > ? int cpu_id = ptr_to_cpu(v); > > - struct device_node *core_clk = of_find_node_by_name(NULL, "core_clk"); > > + struct device *cpu_dev = get_cpu_device(cpu_id); > > + struct clk *cpu_clk = clk_get(cpu_dev, "core_clk"); > > ? u32 freq = 0; > > ? > > ? if (!cpu_online(cpu_id)) { > > @@ -502,7 +504,7 @@ static int show_cpuinfo(struct seq_file *m, void *v) > > ? > > ? seq_printf(m, arc_cpu_mumbojumbo(cpu_id, str, PAGE_SIZE)); > > ? > > - of_property_read_u32(core_clk, "clock-frequency", &freq); > > + freq = clk_get_rate(cpu_clk); > > ? if (freq) > > ? seq_printf(m, "CPU speed\t: %u.%02u Mhz\n", > > ? ???freq / 1000000, (freq / 10000) % 100); > > I'm not too familiar with clk API, do u need to clk_put() afterwards ? @Alexey can > u please check ! I'm not really sure why clk_put() got in the picture here at all. As it is mentioned here?http://elixir.free-electrons.com/source/include/linux/clk.h?v=4.10#L305 clk_put() means "free" the clock source. Anyways this patch alone was not sufficient due to missing changes in .dts files and Vlad is going to send v2 soonish. -Alexey From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752684AbdB1Pub (ORCPT ); Tue, 28 Feb 2017 10:50:31 -0500 Received: from smtprelay2.synopsys.com ([198.182.60.111]:45585 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751599AbdB1PtE (ORCPT ); Tue, 28 Feb 2017 10:49:04 -0500 From: Alexey Brodkin To: Vineet Gupta CC: "linux-kernel@vger.kernel.org" , "Vlad Zakharov" , "linux-snps-arc@lists.infradead.org" Subject: Re: [PATCH] arc: get rate from clk driver instead of reading device tree Thread-Topic: [PATCH] arc: get rate from clk driver instead of reading device tree Thread-Index: AQHSjPeUBjlzCc2JREmuKN2gFTqvmqF1SfGAgAk1GwA= Date: Tue, 28 Feb 2017 15:11:03 +0000 Message-ID: <1488294662.3913.11.camel@synopsys.com> References: <1487759796-14418-1-git-send-email-vzakhar@synopsys.com> In-Reply-To: Accept-Language: en-US, ru-RU Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.121.8.102] Content-Type: text/plain; charset="utf-8" Content-ID: <90E38FA0A2CDEC439B60D6570913FFDB@internal.synopsys.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id v1SFobV0008336 Hi Vineet, On Wed, 2017-02-22 at 10:34 -0800, Vineet Gupta wrote: > On 02/22/2017 02:36 AM, Vlad Zakharov wrote: > > > > We were reading clock rate directly from device tree "clock-frequency" > > property of corresponding clock node in show_cpuinfo function. > > > > Such approach is correct only in case cpu is always clocked by > > "fixed-clock". If we use clock driver that allows rate to be changed > > this won't work as rate may change during the time or even > > "clock-frequency" property may not be presented at all. > > > > So this commit replaces reading device tree with getting rate from clock > > driver. This approach is much more flexible and will work for both fixed > > and mutable clocks. > > > > Signed-off-by: Vlad Zakharov > > --- > >  arch/arc/kernel/setup.c | 6 ++++-- > >  1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arc/kernel/setup.c b/arch/arc/kernel/setup.c > > index 3093fa8..49b0804 100644 > > --- a/arch/arc/kernel/setup.c > > +++ b/arch/arc/kernel/setup.c > > @@ -10,6 +10,7 @@ > >  #include > >  #include > >  #include > > +#include > >  #include > >  #include > >  #include > > @@ -488,7 +489,8 @@ static int show_cpuinfo(struct seq_file *m, void *v) > >  { > >   char *str; > >   int cpu_id = ptr_to_cpu(v); > > - struct device_node *core_clk = of_find_node_by_name(NULL, "core_clk"); > > + struct device *cpu_dev = get_cpu_device(cpu_id); > > + struct clk *cpu_clk = clk_get(cpu_dev, "core_clk"); > >   u32 freq = 0; > >   > >   if (!cpu_online(cpu_id)) { > > @@ -502,7 +504,7 @@ static int show_cpuinfo(struct seq_file *m, void *v) > >   > >   seq_printf(m, arc_cpu_mumbojumbo(cpu_id, str, PAGE_SIZE)); > >   > > - of_property_read_u32(core_clk, "clock-frequency", &freq); > > + freq = clk_get_rate(cpu_clk); > >   if (freq) > >   seq_printf(m, "CPU speed\t: %u.%02u Mhz\n", > >      freq / 1000000, (freq / 10000) % 100); > > I'm not too familiar with clk API, do u need to clk_put() afterwards ? @Alexey can > u please check ! I'm not really sure why clk_put() got in the picture here at all. As it is mentioned here http://elixir.free-electrons.com/source/include/linux/clk.h?v=4.10#L305 clk_put() means "free" the clock source. Anyways this patch alone was not sufficient due to missing changes in .dts files and Vlad is going to send v2 soonish. -Alexey