All of lore.kernel.org
 help / color / mirror / Atom feed
* Setting CPU clock frequency on early boot
@ 2017-09-05 15:37 ` Alexey Brodkin
  0 siblings, 0 replies; 18+ messages in thread
From: Alexey Brodkin @ 2017-09-05 15:37 UTC (permalink / raw)
  To: linux-clk; +Cc: linux-arch, mturquette, sboyd, linux-snps-arc, devicetree

Hello,

I'd like to get some feedback on our idea as well as check
if somebody faces similar situations and if so what would be the best
way to implement some generic solution that suits everyone.

So that's our problem:
1. On power-on hardware might start clocking CPU with either
   too high frequency (such that CPU may get stuck at some point)
   or too low frequency.

   That all sounds stupid but let me elaborate a bit here.
   I'm talking about FPGA-based devboards firmware for which
   (here I mean just image loaded in FPGA with CPU implementation
   but not some software yet) might not be stable or be even experimental.

   For example we may deal with dual-core or quad-core designs.
   Former might be OK running @100MHz and latter is only usable
   @75MHz and lower. The simplest solution might be to use some safe
   value before something like CPUfreq kicks in. But we don't yet have
   CPUfreq for ARC (we do plan to get it working sometime soon) which
   means simple change of CPU frequency once time-keeping infrastructure
   was brought-up is not an option... I.e. we'll end up with the system running
   much slower compared what could have been possible.

2. Up until now we used to do dirty hacks in early platform init code.
   Namely (see axs103_early_init() in arch/arc/plat-axs10x/axs10x.c):
    1) Read CPU's "clock-frequency" from .dtb (remember we're on very early
       boot stage still so no expanded DevTree yet exists).
    2) Check how many cores we have and which freq is usable
    3) Update PLL settings right in place if new freq != existing in PLL.

   Even though it is proven to work but with more platforms in the pipeline
   we'll need to copy-paste pretty much the same stuff across all affected
   plats. Which is not nice.

   Moreover back in the day we didn't have a proper clk driver for CPU's PLL.
   Thus acting on PLL registers right in place was the only thing we were able
   to do. Now with introduction of normal clk driver
   (see drivers/clk/axs10x/pll_clock.c in linux-next) we'd like to utilize
   it and have a cleaner and more universal solution to the problem.

   That's how it could be done - http://patchwork.ozlabs.org/patch/801240/
   Basically in architecture's time_init() we check if there's explicitly
   specified "clock-frequency" parameter in cpu's node in Device Tree and
   if there's one we set it via just instantiated clk driver.

We may indeed proceed with mentioned solution for ARC but if that makes
sense for somebody else it might worth getting something similar in generic
init code. Any thoughts?

All comments and suggestions are more than welcome.

-Alexey

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Setting CPU clock frequency on early boot
@ 2017-09-05 15:37 ` Alexey Brodkin
  0 siblings, 0 replies; 18+ messages in thread
From: Alexey Brodkin @ 2017-09-05 15:37 UTC (permalink / raw)
  To: linux-clk; +Cc: linux-arch, mturquette, sboyd, linux-snps-arc, devicetree

SGVsbG8sDQoNCkknZCBsaWtlIHRvIGdldCBzb21lIGZlZWRiYWNrIG9uIG91ciBpZGVhIGFzIHdl
bGwgYXMgY2hlY2sNCmlmIHNvbWVib2R5IGZhY2VzIHNpbWlsYXIgc2l0dWF0aW9ucyBhbmQgaWYg
c28gd2hhdCB3b3VsZCBiZSB0aGUgYmVzdA0Kd2F5IHRvIGltcGxlbWVudCBzb21lIGdlbmVyaWMg
c29sdXRpb24gdGhhdCBzdWl0cyBldmVyeW9uZS4NCg0KU28gdGhhdCdzIG91ciBwcm9ibGVtOg0K
MS4gT24gcG93ZXItb24gaGFyZHdhcmUgbWlnaHQgc3RhcnQgY2xvY2tpbmcgQ1BVIHdpdGggZWl0
aGVyDQrCoCDCoHRvbyBoaWdoIGZyZXF1ZW5jeSAoc3VjaCB0aGF0IENQVSBtYXkgZ2V0IHN0dWNr
IGF0IHNvbWUgcG9pbnQpDQrCoCDCoG9yIHRvbyBsb3cgZnJlcXVlbmN5Lg0KDQrCoCDCoFRoYXQg
YWxsIHNvdW5kcyBzdHVwaWQgYnV0IGxldCBtZSBlbGFib3JhdGUgYSBiaXQgaGVyZS4NCsKgIMKg
SSdtIHRhbGtpbmcgYWJvdXQgRlBHQS1iYXNlZCBkZXZib2FyZHMgZmlybXdhcmUgZm9yIHdoaWNo
DQrCoCDCoChoZXJlIEkgbWVhbiBqdXN0IGltYWdlIGxvYWRlZCBpbiBGUEdBIHdpdGggQ1BVIGlt
cGxlbWVudGF0aW9uDQrCoCDCoGJ1dCBub3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J2QgbGlrZSB0byB1dGlsaXplDQrCoCDCoGl0
IGFuZCBoYXZlIGEgY2xlYW5lciBhbmQgbW9yZSB1bml2ZXJzYWwgc29sdXRpb24gdG8gdGhlIHBy
b2JsZW0uDQoNCsKgIMKgVGhhdCdzIGhvdyBpdCBjb3VsZCBiZSBkb25lIC3CoGh0dHA6Ly9wYXRj
aHdvcmsub3psYWJzLm9yZy9wYXRjaC84MDEyNDAvDQrCoCDCoEJhc2ljYWxseSBpbiBhcmNoaXRl
Y3R1cmUncyB0aW1lX2luaXQoKSB3ZSBjaGVjayBpZiB0aGVyZSdzIGV4cGxpY2l0bHkNCsKgIMKg
c3BlY2lmaWVkICJjbG9jay1mcmVxdWVuY3kiIHBhcmFtZXRlciBpbiBjcHUncyBub2RlIGluIERl
dmljZSBUcmVlIGFuZA0KwqAgwqBpZiB0aGVyZSdzIG9uZSB3ZSBzZXQgaXQgdmlhIGp1c3QgaW5z
dGFudGlhdGVkIGNsayBkcml2ZXIuDQoNCldlIG1heSBpbmRlZWQgcHJvY2VlZCB3aXRoIG1lbnRp
b25lZCBzb2x1dGlvbiBmb3IgQVJDIGJ1dCBpZiB0aGF0IG1ha2VzDQpzZW5zZSBmb3Igc29tZWJv
ZHkgZWxzZSBpdCBtaWdodCB3b3J0aCBnZXR0aW5nIHNvbWV0aGluZyBzaW1pbGFyIGluIGdlbmVy
aWMNCmluaXQgY29kZS4gQW55IHRob3VnaHRzPw0KDQpBbGwgY29tbWVudHMgYW5kIHN1Z2dlc3Rp
b25zIGFyZSBtb3JlIHRoYW4gd2VsY29tZS4NCg0KLUFsZXhleQ==

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Setting CPU clock frequency on early boot
@ 2017-09-05 15:37 ` Alexey Brodkin
  0 siblings, 0 replies; 18+ messages in thread
From: Alexey Brodkin @ 2017-09-05 15:37 UTC (permalink / raw)
  To: linux-snps-arc

Hello,

I'd like to get some feedback on our idea as well as check
if somebody faces similar situations and if so what would be the best
way to implement some generic solution that suits everyone.

So that's our problem:
1. On power-on hardware might start clocking CPU with either
? ?too high frequency (such that CPU may get stuck at some point)
? ?or too low frequency.

? ?That all sounds stupid but let me elaborate a bit here.
? ?I'm talking about FPGA-based devboards firmware for which
? ?(here I mean just image loaded in FPGA with CPU implementation
? ?but not some software yet) might not be stable or be even experimental.

? ?For example we may deal with dual-core or quad-core designs.
? ?Former might be OK running @100MHz and latter is only usable
? ?@75MHz and lower. The simplest solution might be to use some safe
? ?value before something like CPUfreq kicks in. But we don't yet have
? ?CPUfreq for ARC (we do plan to get it working sometime soon) which
? ?means simple change of CPU frequency once time-keeping infrastructure
? ?was brought-up is not an option... I.e. we'll end up with the system running
? ?much slower compared what could have been possible.

2. Up until now we used to do dirty hacks in early platform init code.
? ?Namely (see?axs103_early_init() in?arch/arc/plat-axs10x/axs10x.c):
? ? 1) Read CPU's "clock-frequency" from .dtb (remember we're on very early
? ? ? ?boot stage still so no expanded DevTree yet exists).
? ? 2) Check how many cores we have and which freq is usable
? ? 3) Update PLL settings right in place if new freq != existing in PLL.

? ?Even though it is proven to work but with more platforms in the pipeline
? ?we'll need to copy-paste pretty much the same stuff across all affected
? ?plats. Which is not nice.

? ?Moreover back in the day we didn't have a proper clk driver for CPU's PLL.
? ?Thus acting on PLL registers right in place was the only thing we were able
? ?to do. Now with introduction of normal clk driver
? ?(see?drivers/clk/axs10x/pll_clock.c in linux-next) we'd like to utilize
? ?it and have a cleaner and more universal solution to the problem.

? ?That's how it could be done -?http://patchwork.ozlabs.org/patch/801240/
? ?Basically in architecture's time_init() we check if there's explicitly
? ?specified "clock-frequency" parameter in cpu's node in Device Tree and
? ?if there's one we set it via just instantiated clk driver.

We may indeed proceed with mentioned solution for ARC but if that makes
sense for somebody else it might worth getting something similar in generic
init code. Any thoughts?

All comments and suggestions are more than welcome.

-Alexey

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Setting CPU clock frequency on early boot
  2017-09-05 15:37 ` Alexey Brodkin
@ 2017-09-05 22:03   ` Rob Herring
  -1 siblings, 0 replies; 18+ messages in thread
From: Rob Herring @ 2017-09-05 22:03 UTC (permalink / raw)
  To: Alexey Brodkin
  Cc: linux-clk, linux-arch, mturquette, sboyd, linux-snps-arc, devicetree

On Tue, Sep 5, 2017 at 10:37 AM, Alexey Brodkin
<Alexey.Brodkin@synopsys.com> wrote:
> Hello,
>
> I'd like to get some feedback on our idea as well as check
> if somebody faces similar situations and if so what would be the best
> way to implement some generic solution that suits everyone.
>
> So that's our problem:
> 1. On power-on hardware might start clocking CPU with either
>    too high frequency (such that CPU may get stuck at some point)
>    or too low frequency.
>
>    That all sounds stupid but let me elaborate a bit here.
>    I'm talking about FPGA-based devboards firmware for which
>    (here I mean just image loaded in FPGA with CPU implementation
>    but not some software yet) might not be stable or be even experimental.
>
>    For example we may deal with dual-core or quad-core designs.
>    Former might be OK running @100MHz and latter is only usable
>    @75MHz and lower. The simplest solution might be to use some safe
>    value before something like CPUfreq kicks in. But we don't yet have
>    CPUfreq for ARC (we do plan to get it working sometime soon) which
>    means simple change of CPU frequency once time-keeping infrastructure
>    was brought-up is not an option... I.e. we'll end up with the system running
>    much slower compared what could have been possible.
>
> 2. Up until now we used to do dirty hacks in early platform init code.
>    Namely (see axs103_early_init() in arch/arc/plat-axs10x/axs10x.c):
>     1) Read CPU's "clock-frequency" from .dtb (remember we're on very early
>        boot stage still so no expanded DevTree yet exists).
>     2) Check how many cores we have and which freq is usable
>     3) Update PLL settings right in place if new freq != existing in PLL.
>
>    Even though it is proven to work but with more platforms in the pipeline
>    we'll need to copy-paste pretty much the same stuff across all affected
>    plats. Which is not nice.
>
>    Moreover back in the day we didn't have a proper clk driver for CPU's PLL.
>    Thus acting on PLL registers right in place was the only thing we were able
>    to do. Now with introduction of normal clk driver
>    (see drivers/clk/axs10x/pll_clock.c in linux-next) we'd like to utilize
>    it and have a cleaner and more universal solution to the problem.
>
>    That's how it could be done - http://patchwork.ozlabs.org/patch/801240/
>    Basically in architecture's time_init() we check if there's explicitly
>    specified "clock-frequency" parameter in cpu's node in Device Tree and
>    if there's one we set it via just instantiated clk driver.

The patch looks generally okay. I'd move all the logic to the clock
driver unless perhaps how to set the cpu freq is defined by the
architecture.

> We may indeed proceed with mentioned solution for ARC but if that makes
> sense for somebody else it might worth getting something similar in generic
> init code. Any thoughts?

If any ARM platforms are doing something similar, then it's done in
their clock driver via of_clk_init. Or they just wait for cpufreq to
kick in and expect the bootloader has initialized things to a
reasonable frequency.

Rob

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Setting CPU clock frequency on early boot
@ 2017-09-05 22:03   ` Rob Herring
  0 siblings, 0 replies; 18+ messages in thread
From: Rob Herring @ 2017-09-05 22:03 UTC (permalink / raw)
  To: linux-snps-arc

On Tue, Sep 5, 2017 at 10:37 AM, Alexey Brodkin
<Alexey.Brodkin@synopsys.com> wrote:
> Hello,
>
> I'd like to get some feedback on our idea as well as check
> if somebody faces similar situations and if so what would be the best
> way to implement some generic solution that suits everyone.
>
> So that's our problem:
> 1. On power-on hardware might start clocking CPU with either
>    too high frequency (such that CPU may get stuck at some point)
>    or too low frequency.
>
>    That all sounds stupid but let me elaborate a bit here.
>    I'm talking about FPGA-based devboards firmware for which
>    (here I mean just image loaded in FPGA with CPU implementation
>    but not some software yet) might not be stable or be even experimental.
>
>    For example we may deal with dual-core or quad-core designs.
>    Former might be OK running @100MHz and latter is only usable
>    @75MHz and lower. The simplest solution might be to use some safe
>    value before something like CPUfreq kicks in. But we don't yet have
>    CPUfreq for ARC (we do plan to get it working sometime soon) which
>    means simple change of CPU frequency once time-keeping infrastructure
>    was brought-up is not an option... I.e. we'll end up with the system running
>    much slower compared what could have been possible.
>
> 2. Up until now we used to do dirty hacks in early platform init code.
>    Namely (see axs103_early_init() in arch/arc/plat-axs10x/axs10x.c):
>     1) Read CPU's "clock-frequency" from .dtb (remember we're on very early
>        boot stage still so no expanded DevTree yet exists).
>     2) Check how many cores we have and which freq is usable
>     3) Update PLL settings right in place if new freq != existing in PLL.
>
>    Even though it is proven to work but with more platforms in the pipeline
>    we'll need to copy-paste pretty much the same stuff across all affected
>    plats. Which is not nice.
>
>    Moreover back in the day we didn't have a proper clk driver for CPU's PLL.
>    Thus acting on PLL registers right in place was the only thing we were able
>    to do. Now with introduction of normal clk driver
>    (see drivers/clk/axs10x/pll_clock.c in linux-next) we'd like to utilize
>    it and have a cleaner and more universal solution to the problem.
>
>    That's how it could be done - http://patchwork.ozlabs.org/patch/801240/
>    Basically in architecture's time_init() we check if there's explicitly
>    specified "clock-frequency" parameter in cpu's node in Device Tree and
>    if there's one we set it via just instantiated clk driver.

The patch looks generally okay. I'd move all the logic to the clock
driver unless perhaps how to set the cpu freq is defined by the
architecture.

> We may indeed proceed with mentioned solution for ARC but if that makes
> sense for somebody else it might worth getting something similar in generic
> init code. Any thoughts?

If any ARM platforms are doing something similar, then it's done in
their clock driver via of_clk_init. Or they just wait for cpufreq to
kick in and expect the bootloader has initialized things to a
reasonable frequency.

Rob

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Setting CPU clock frequency on early boot
  2017-09-05 22:03   ` Rob Herring
@ 2017-09-05 23:40     ` Vineet Gupta
  -1 siblings, 0 replies; 18+ messages in thread
From: Vineet Gupta @ 2017-09-05 23:40 UTC (permalink / raw)
  To: Rob Herring, Alexey Brodkin
  Cc: linux-arch, devicetree, mturquette, sboyd, linux-snps-arc, linux-clk

On 09/05/2017 03:04 PM, Rob Herring wrote:
> On Tue, Sep 5, 2017 at 10:37 AM, Alexey Brodkin
> <Alexey.Brodkin@synopsys.com> wrote:
>> Hello,
>>
>> I'd like to get some feedback on our idea as well as check
>> if somebody faces similar situations and if so what would be the best
>> way to implement some generic solution that suits everyone.
>>
>> So that's our problem:
>> 1. On power-on hardware might start clocking CPU with either
>>     too high frequency (such that CPU may get stuck at some point)
>>     or too low frequency.
>>
>>     That all sounds stupid but let me elaborate a bit here.
>>     I'm talking about FPGA-based devboards firmware for which
>>     (here I mean just image loaded in FPGA with CPU implementation
>>     but not some software yet) might not be stable or be even experimental.
>>
>>     For example we may deal with dual-core or quad-core designs.
>>     Former might be OK running @100MHz and latter is only usable
>>     @75MHz and lower. The simplest solution might be to use some safe
>>     value before something like CPUfreq kicks in. But we don't yet have
>>     CPUfreq for ARC (we do plan to get it working sometime soon)

But even if we had cpufreq driver going - I don't think it would be usable for 
doing large freq switches, since in current implementations of SoCs (or fpga), the 
clk/pll etc driving core (and all timers etc) are not fixed like say ARM. And as 
discussed before (and pointed to by tglx), timer subsys can't tolerate (on 
purpose) such large drifts.

>> which
>>     means simple change of CPU frequency once time-keeping infrastructure
>>     was brought-up is not an option... I.e. we'll end up with the system running
>>     much slower compared what could have been possible.
>>
>> 2. Up until now we used to do dirty hacks in early platform init code.
>>     Namely (see axs103_early_init() in arch/arc/plat-axs10x/axs10x.c):
>>      1) Read CPU's "clock-frequency" from .dtb (remember we're on very early
>>         boot stage still so no expanded DevTree yet exists).
>>      2) Check how many cores we have and which freq is usable
>>      3) Update PLL settings right in place if new freq != existing in PLL.
>>
>>     Even though it is proven to work but with more platforms in the pipeline
>>     we'll need to copy-paste pretty much the same stuff across all affected
>>     plats. Which is not nice.
>>
>>     Moreover back in the day we didn't have a proper clk driver for CPU's PLL.
>>     Thus acting on PLL registers right in place was the only thing we were able
>>     to do. Now with introduction of normal clk driver
>>     (see drivers/clk/axs10x/pll_clock.c in linux-next) we'd like to utilize
>>     it and have a cleaner and more universal solution to the problem.
>>
>>     That's how it could be done - https://urldefense.proofpoint.com/v2/url?u=http-3A__patchwork.ozlabs.org_patch_801240_&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=c14YS-cH-kdhTOW89KozFhBtBJgs1zXscZojEZQ0THs&m=wuUcceY8Cz5EhVklWLAgj7RzU3rvpanujvQ3qTJK0Gw&s=N5IBjq_eCyOf_GRkZskzqGhczBPTbxLJW_MUfauKvuA&e=
>>     Basically in architecture's time_init() we check if there's explicitly
>>     specified "clock-frequency" parameter in cpu's node in Device Tree and
>>     if there's one we set it via just instantiated clk driver.
> The patch looks generally okay. I'd move all the logic to the clock
> driver unless perhaps how to set the cpu freq is defined by the
> architecture.

But the above patch is clk driver agnostic and it would have to be added each clk 
driver (axs10x, hsdk - both in linux-next) ?
Also note that this code is using a new / adhoc DT binding cpu-freq in cou node to 
do the override - is that acceptable ?

-Vineet

>
>> We may indeed proceed with mentioned solution for ARC but if that makes
>> sense for somebody else it might worth getting something similar in generic
>> init code. Any thoughts?
> If any ARM platforms are doing something similar, then it's done in
> their clock driver via of_clk_init. Or they just wait for cpufreq to
> kick in and expect the bootloader has initialized things to a
> reasonable frequency.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Setting CPU clock frequency on early boot
@ 2017-09-05 23:40     ` Vineet Gupta
  0 siblings, 0 replies; 18+ messages in thread
From: Vineet Gupta @ 2017-09-05 23:40 UTC (permalink / raw)
  To: linux-snps-arc

On 09/05/2017 03:04 PM, Rob Herring wrote:
> On Tue, Sep 5, 2017 at 10:37 AM, Alexey Brodkin
> <Alexey.Brodkin@synopsys.com> wrote:
>> Hello,
>>
>> I'd like to get some feedback on our idea as well as check
>> if somebody faces similar situations and if so what would be the best
>> way to implement some generic solution that suits everyone.
>>
>> So that's our problem:
>> 1. On power-on hardware might start clocking CPU with either
>>     too high frequency (such that CPU may get stuck at some point)
>>     or too low frequency.
>>
>>     That all sounds stupid but let me elaborate a bit here.
>>     I'm talking about FPGA-based devboards firmware for which
>>     (here I mean just image loaded in FPGA with CPU implementation
>>     but not some software yet) might not be stable or be even experimental.
>>
>>     For example we may deal with dual-core or quad-core designs.
>>     Former might be OK running @100MHz and latter is only usable
>>     @75MHz and lower. The simplest solution might be to use some safe
>>     value before something like CPUfreq kicks in. But we don't yet have
>>     CPUfreq for ARC (we do plan to get it working sometime soon)

But even if we had cpufreq driver going - I don't think it would be usable for 
doing large freq switches, since in current implementations of SoCs (or fpga), the 
clk/pll etc driving core (and all timers etc) are not fixed like say ARM. And as 
discussed before (and pointed to by tglx), timer subsys can't tolerate (on 
purpose) such large drifts.

>> which
>>     means simple change of CPU frequency once time-keeping infrastructure
>>     was brought-up is not an option... I.e. we'll end up with the system running
>>     much slower compared what could have been possible.
>>
>> 2. Up until now we used to do dirty hacks in early platform init code.
>>     Namely (see axs103_early_init() in arch/arc/plat-axs10x/axs10x.c):
>>      1) Read CPU's "clock-frequency" from .dtb (remember we're on very early
>>         boot stage still so no expanded DevTree yet exists).
>>      2) Check how many cores we have and which freq is usable
>>      3) Update PLL settings right in place if new freq != existing in PLL.
>>
>>     Even though it is proven to work but with more platforms in the pipeline
>>     we'll need to copy-paste pretty much the same stuff across all affected
>>     plats. Which is not nice.
>>
>>     Moreover back in the day we didn't have a proper clk driver for CPU's PLL.
>>     Thus acting on PLL registers right in place was the only thing we were able
>>     to do. Now with introduction of normal clk driver
>>     (see drivers/clk/axs10x/pll_clock.c in linux-next) we'd like to utilize
>>     it and have a cleaner and more universal solution to the problem.
>>
>>     That's how it could be done - https://urldefense.proofpoint.com/v2/url?u=http-3A__patchwork.ozlabs.org_patch_801240_&d=DwICAg&c=DPL6_X_6JkXFx7AXWqB0tg&r=c14YS-cH-kdhTOW89KozFhBtBJgs1zXscZojEZQ0THs&m=wuUcceY8Cz5EhVklWLAgj7RzU3rvpanujvQ3qTJK0Gw&s=N5IBjq_eCyOf_GRkZskzqGhczBPTbxLJW_MUfauKvuA&e=
>>     Basically in architecture's time_init() we check if there's explicitly
>>     specified "clock-frequency" parameter in cpu's node in Device Tree and
>>     if there's one we set it via just instantiated clk driver.
> The patch looks generally okay. I'd move all the logic to the clock
> driver unless perhaps how to set the cpu freq is defined by the
> architecture.

But the above patch is clk driver agnostic and it would have to be added each clk 
driver (axs10x, hsdk - both in linux-next) ?
Also note that this code is using a new / adhoc DT binding cpu-freq in cou node to 
do the override - is that acceptable ?

-Vineet

>
>> We may indeed proceed with mentioned solution for ARC but if that makes
>> sense for somebody else it might worth getting something similar in generic
>> init code. Any thoughts?
> If any ARM platforms are doing something similar, then it's done in
> their clock driver via of_clk_init. Or they just wait for cpufreq to
> kick in and expect the bootloader has initialized things to a
> reasonable frequency.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Setting CPU clock frequency on early boot
  2017-09-05 23:40     ` Vineet Gupta
  (?)
@ 2017-09-06 13:51       ` Alexey Brodkin
  -1 siblings, 0 replies; 18+ messages in thread
From: Alexey Brodkin @ 2017-09-06 13:51 UTC (permalink / raw)
  To: robh, Vineet Gupta
  Cc: linux-clk, linux-arch, mturquette, sboyd, devicetree, linux-snps-arc

Hi Vineet, Rob,

On Tue, 2017-09-05 at 16:40 -0700, Vineet Gupta wrote:
> On 09/05/2017 03:04 PM, Rob Herring wrote:
> > 
> > On Tue, Sep 5, 2017 at 10:37 AM, Alexey Brodkin
> > <Alexey.Brodkin@synopsys.com> wrote:
> > > 
> > > Hello,
> > > 
> > > I'd like to get some feedback on our idea as well as check
> > > if somebody faces similar situations and if so what would be the best
> > > way to implement some generic solution that suits everyone.
> > > 
> > > So that's our problem:
> > > 1. On power-on hardware might start clocking CPU with either
> > >     too high frequency (such that CPU may get stuck at some point)
> > >     or too low frequency.
> > > 
> > >     That all sounds stupid but let me elaborate a bit here.
> > >     I'm talking about FPGA-based devboards firmware for which
> > >     (here I mean just image loaded in FPGA with CPU implementation
> > >     but not some software yet) might not be stable or be even experimental.
> > > 
> > >     For example we may deal with dual-core or quad-core designs.
> > >     Former might be OK running @100MHz and latter is only usable
> > >     @75MHz and lower. The simplest solution might be to use some safe
> > >     value before something like CPUfreq kicks in. But we don't yet have
> > >     CPUfreq for ARC (we do plan to get it working sometime soon)
> 
> But even if we had cpufreq driver going - I don't think it would be usable for 
> doing large freq switches, since in current implementations of SoCs (or fpga), the 
> clk/pll etc driving core (and all timers etc) are not fixed like say ARM. And as 
> discussed before (and pointed to by tglx), timer subsys can't tolerate (on 
> purpose) such large drifts.

Essentially cpufreq only makes sense for "compatible" systems and unfortunately
most of our current boards are not capable due to missing constant [decoupled from
CPU frequency] clock source. But looking forward we are planning to improve on that
so that hopefully even our FPGA-based boards will be usable with cpufreq.

> > > which
> > >     means simple change of CPU frequency once time-keeping infrastructure
> > >     was brought-up is not an option... I.e. we'll end up with the system running
> > >     much slower compared what could have been possible.
> > > 
> > > 2. Up until now we used to do dirty hacks in early platform init code.
> > >     Namely (see axs103_early_init() in arch/arc/plat-axs10x/axs10x.c):
> > >      1) Read CPU's "clock-frequency" from .dtb (remember we're on very early
> > >         boot stage still so no expanded DevTree yet exists).
> > >      2) Check how many cores we have and which freq is usable
> > >      3) Update PLL settings right in place if new freq != existing in PLL.
> > > 
> > >     Even though it is proven to work but with more platforms in the pipeline
> > >     we'll need to copy-paste pretty much the same stuff across all affected
> > >     plats. Which is not nice.
> > > 
> > >     Moreover back in the day we didn't have a proper clk driver for CPU's PLL.
> > >     Thus acting on PLL registers right in place was the only thing we were able
> > >     to do. Now with introduction of normal clk driver
> > >     (see drivers/clk/axs10x/pll_clock.c in linux-next) we'd like to utilize
> > >     it and have a cleaner and more universal solution to the problem.
> > > 
> > >     That's how it could be done - https://urldefense.proofpoint.com/v2/url?u=http-3A__patchwork.ozlabs.org_patch_801240_&d=DwICAg&c=DPL6_X_6JkXF
> > > x7AXWqB0tg&r=c14YS-cH-
> > > kdhTOW89KozFhBtBJgs1zXscZojEZQ0THs&m=wuUcceY8Cz5EhVklWLAgj7RzU3rvpanujvQ3qTJK0Gw&s=N5IBjq_eCyOf_GRkZskzqGhczBPTbxLJW_MUfauKvuA&e=
> > >     Basically in architecture's time_init() we check if there's explicitly
> > >     specified "clock-frequency" parameter in cpu's node in Device Tree and
> > >     if there's one we set it via just instantiated clk driver.
> > The patch looks generally okay. I'd move all the logic to the clock
> > driver unless perhaps how to set the cpu freq is defined by the
> > architecture.

Yeah, that's an interesting question. We may indeed move more smarts to the clock driver
but:
 1. We'll have duplicate code in different clock drivers. Even today that kind of clock
    setup is applicable to AXS10x and HSDK platforms (and they use different clock drivers).

 2. Print out of CPU frequency which is used during boot process for us is important as well
    especially during bring-up of new HW.

 3. If there's no dedicated "clock-frequency" parameter in CPU node we won't
    change anything so that non-affected platforms will live as they used to.

That said IMHO proposed implementation is what we want to kep for now.

> Also note that this code is using a new / adhoc DT binding cpu-freq in cou node to 
> do the override - is that acceptable ?

I think we'll switch to more common "clock-frequency" in the next respin.
Indeed "cpu-freq" might be a bit misleading.

Also FWIW one MIPS platform uses something similar
(even though their property name is not standard but "mips-hpt-frequency"),
see http://elixir.free-electrons.com/linux/latest/source/arch/mips/boot/dts/brcm/bcm3368.dtsi#L10
http://elixir.free-electrons.com/linux/latest/source/arch/mips/bmips/setup.c#L141.

-Alexey

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Setting CPU clock frequency on early boot
@ 2017-09-06 13:51       ` Alexey Brodkin
  0 siblings, 0 replies; 18+ messages in thread
From: Alexey Brodkin @ 2017-09-06 13:51 UTC (permalink / raw)
  To: robh, Vineet Gupta
  Cc: linux-clk, linux-arch, mturquette, sboyd, devicetree, linux-snps-arc

SGkgVmluZWV0LCBSb2IsDQoNCk9uIFR1ZSwgMjAxNy0wOS0wNSBhdCAxNjo0MCAtMDcwMCwgVmlu
ZWV0IEd1cHRhIHdyb3RlOg0KPiBPbiAwOS8wNS8yMDE3IDAzOjA0IFBNLCBSb2IgSGVycmluZyB3
cm90ZToNCj4gPiANCj4gPiBPbiBUdWUsIFNlcCA1LCAyMDE3IGF0IDEwOjM3IEFNLCBBbGV4ZXkg
QnJvZGtpbg0KPiA+IDxBbGV4ZXkuQnJvZGtpbkBzeW5vcHN5cy5jb20+IHdyb3RlOg0KPiA+ID4g
DQo+ID4gPiBIZWxsbywNCj4gPiA+IA0KPiA+ID4gSSdkIGxpa2UgdG8gZ2V0IHNvbWUgZmVlZGJh
Y2sgb24gb3VyIGlkZWEgYXMgd2VsbCBhcyBjaGVjaw0KPiA+ID4gaWYgc29tZWJvZHkgZmFjZXMg
c2ltaWxhciBzaXR1YXRpb25zIGFuZCBpZiBzbyB3aGF0IHdvdWxkIGJlIHRoZS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UgPw0KDQpJIHRoaW5rIHdlJ2xsIHN3aXRjaCB0byBtb3JlIGNvbW1vbiAiY2xv
Y2stZnJlcXVlbmN5IiBpbiB0aGUgbmV4dCByZXNwaW4uDQpJbmRlZWQgImNwdS1mcmVxIiBtaWdo
dCBiZSBhIGJpdCBtaXNsZWFkaW5nLg0KDQpBbHNvIEZXSVcgb25lIE1JUFMgcGxhdGZvcm0gdXNl
cyBzb21ldGhpbmcgc2ltaWxhcg0KKGV2ZW4gdGhvdWdoIHRoZWlyIHByb3BlcnR5IG5hbWUgaXMg
bm90IHN0YW5kYXJkIGJ1dCAibWlwcy1ocHQtZnJlcXVlbmN5IiksDQpzZWXCoGh0dHA6Ly9lbGl4
aXIuZnJlZS1lbGVjdHJvbnMuY29tL2xpbnV4L2xhdGVzdC9zb3VyY2UvYXJjaC9taXBzL2Jvb3Qv
ZHRzL2JyY20vYmNtMzM2OC5kdHNpI0wxMA0KaHR0cDovL2VsaXhpci5mcmVlLWVsZWN0cm9ucy5j
b20vbGludXgvbGF0ZXN0L3NvdXJjZS9hcmNoL21pcHMvYm1pcHMvc2V0dXAuYyNMMTQxLg0KDQot
QWxleGV5

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Setting CPU clock frequency on early boot
@ 2017-09-06 13:51       ` Alexey Brodkin
  0 siblings, 0 replies; 18+ messages in thread
From: Alexey Brodkin @ 2017-09-06 13:51 UTC (permalink / raw)
  To: linux-snps-arc

Hi Vineet, Rob,

On Tue, 2017-09-05@16:40 -0700, Vineet Gupta wrote:
> On 09/05/2017 03:04 PM, Rob Herring wrote:
> > 
> > On Tue, Sep 5, 2017 at 10:37 AM, Alexey Brodkin
> > <Alexey.Brodkin@synopsys.com> wrote:
> > > 
> > > Hello,
> > > 
> > > I'd like to get some feedback on our idea as well as check
> > > if somebody faces similar situations and if so what would be the best
> > > way to implement some generic solution that suits everyone.
> > > 
> > > So that's our problem:
> > > 1. On power-on hardware might start clocking CPU with either
> > > ????too high frequency (such that CPU may get stuck at some point)
> > > ????or too low frequency.
> > > 
> > > ????That all sounds stupid but let me elaborate a bit here.
> > > ????I'm talking about FPGA-based devboards firmware for which
> > > ????(here I mean just image loaded in FPGA with CPU implementation
> > > ????but not some software yet) might not be stable or be even experimental.
> > > 
> > > ????For example we may deal with dual-core or quad-core designs.
> > > ????Former might be OK running @100MHz and latter is only usable
> > > ????@75MHz and lower. The simplest solution might be to use some safe
> > > ????value before something like CPUfreq kicks in. But we don't yet have
> > > ????CPUfreq for ARC (we do plan to get it working sometime soon)
> 
> But even if we had cpufreq driver going - I don't think it would be usable for?
> doing large freq switches, since in current implementations of SoCs (or fpga), the?
> clk/pll etc driving core (and all timers etc) are not fixed like say ARM. And as?
> discussed before (and pointed to by tglx), timer subsys can't tolerate (on?
> purpose) such large drifts.

Essentially cpufreq only makes sense for "compatible" systems and unfortunately
most of our current boards are not capable due to missing constant [decoupled from
CPU frequency] clock source. But looking forward we are planning to improve on that
so that hopefully even our FPGA-based boards will be usable with cpufreq.

> > > which
> > > ????means simple change of CPU frequency once time-keeping infrastructure
> > > ????was brought-up is not an option... I.e. we'll end up with the system running
> > > ????much slower compared what could have been possible.
> > > 
> > > 2. Up until now we used to do dirty hacks in early platform init code.
> > > ????Namely (see axs103_early_init() in arch/arc/plat-axs10x/axs10x.c):
> > > ?????1) Read CPU's "clock-frequency" from .dtb (remember we're on very early
> > > ????????boot stage still so no expanded DevTree yet exists).
> > > ?????2) Check how many cores we have and which freq is usable
> > > ?????3) Update PLL settings right in place if new freq != existing in PLL.
> > > 
> > > ????Even though it is proven to work but with more platforms in the pipeline
> > > ????we'll need to copy-paste pretty much the same stuff across all affected
> > > ????plats. Which is not nice.
> > > 
> > > ????Moreover back in the day we didn't have a proper clk driver for CPU's PLL.
> > > ????Thus acting on PLL registers right in place was the only thing we were able
> > > ????to do. Now with introduction of normal clk driver
> > > ????(see drivers/clk/axs10x/pll_clock.c in linux-next) we'd like to utilize
> > > ????it and have a cleaner and more universal solution to the problem.
> > > 
> > > ????That's how it could be done - https://urldefense.proofpoint.com/v2/url?u=http-3A__patchwork.ozlabs.org_patch_801240_&d=DwICAg&c=DPL6_X_6JkXF
> > > x7AXWqB0tg&r=c14YS-cH-
> > > kdhTOW89KozFhBtBJgs1zXscZojEZQ0THs&m=wuUcceY8Cz5EhVklWLAgj7RzU3rvpanujvQ3qTJK0Gw&s=N5IBjq_eCyOf_GRkZskzqGhczBPTbxLJW_MUfauKvuA&e=
> > > ????Basically in architecture's time_init() we check if there's explicitly
> > > ????specified "clock-frequency" parameter in cpu's node in Device Tree and
> > > ????if there's one we set it via just instantiated clk driver.
> > The patch looks generally okay. I'd move all the logic to the clock
> > driver unless perhaps how to set the cpu freq is defined by the
> > architecture.

Yeah, that's an interesting question. We may indeed move more smarts to the clock driver
but:
?1. We'll have duplicate code in different clock drivers. Even today that kind of clock
? ? setup is applicable to AXS10x and HSDK platforms (and they use different clock drivers).

?2. Print out of CPU frequency which is used during boot process for us is important as well
? ? especially during bring-up of new HW.

?3. If there's no dedicated "clock-frequency" parameter in CPU node we won't
? ? change anything so that non-affected platforms will live as they used to.

That said IMHO proposed implementation is what we want to kep for now.

> Also note that this code is using a new / adhoc DT binding cpu-freq in cou node to?
> do the override - is that acceptable ?

I think we'll switch to more common "clock-frequency" in the next respin.
Indeed "cpu-freq" might be a bit misleading.

Also FWIW one MIPS platform uses something similar
(even though their property name is not standard but "mips-hpt-frequency"),
see?http://elixir.free-electrons.com/linux/latest/source/arch/mips/boot/dts/brcm/bcm3368.dtsi#L10
http://elixir.free-electrons.com/linux/latest/source/arch/mips/bmips/setup.c#L141.

-Alexey

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Setting CPU clock frequency on early boot
  2017-09-06 13:51       ` Alexey Brodkin
@ 2017-09-06 15:25         ` Rob Herring
  -1 siblings, 0 replies; 18+ messages in thread
From: Rob Herring @ 2017-09-06 15:25 UTC (permalink / raw)
  To: Alexey Brodkin
  Cc: Vineet Gupta, linux-clk, linux-arch, mturquette, sboyd,
	devicetree, linux-snps-arc

On Wed, Sep 6, 2017 at 8:51 AM, Alexey Brodkin
<Alexey.Brodkin@synopsys.com> wrote:
> Hi Vineet, Rob,
>
> On Tue, 2017-09-05 at 16:40 -0700, Vineet Gupta wrote:
>> On 09/05/2017 03:04 PM, Rob Herring wrote:
>> >
>> > On Tue, Sep 5, 2017 at 10:37 AM, Alexey Brodkin
>> > <Alexey.Brodkin@synopsys.com> wrote:
>> > >
>> > > Hello,
>> > >
>> > > I'd like to get some feedback on our idea as well as check
>> > > if somebody faces similar situations and if so what would be the best
>> > > way to implement some generic solution that suits everyone.
>> > >
>> > > So that's our problem:
>> > > 1. On power-on hardware might start clocking CPU with either
>> > >     too high frequency (such that CPU may get stuck at some point)
>> > >     or too low frequency.
>> > >
>> > >     That all sounds stupid but let me elaborate a bit here.
>> > >     I'm talking about FPGA-based devboards firmware for which
>> > >     (here I mean just image loaded in FPGA with CPU implementation
>> > >     but not some software yet) might not be stable or be even experimental.
>> > >
>> > >     For example we may deal with dual-core or quad-core designs.
>> > >     Former might be OK running @100MHz and latter is only usable
>> > >     @75MHz and lower. The simplest solution might be to use some safe
>> > >     value before something like CPUfreq kicks in. But we don't yet have
>> > >     CPUfreq for ARC (we do plan to get it working sometime soon)
>>
>> But even if we had cpufreq driver going - I don't think it would be usable for
>> doing large freq switches, since in current implementations of SoCs (or fpga), the
>> clk/pll etc driving core (and all timers etc) are not fixed like say ARM. And as
>> discussed before (and pointed to by tglx), timer subsys can't tolerate (on
>> purpose) such large drifts.
>
> Essentially cpufreq only makes sense for "compatible" systems and unfortunately
> most of our current boards are not capable due to missing constant [decoupled from
> CPU frequency] clock source. But looking forward we are planning to improve on that
> so that hopefully even our FPGA-based boards will be usable with cpufreq.
>
>> > > which
>> > >     means simple change of CPU frequency once time-keeping infrastructure
>> > >     was brought-up is not an option... I.e. we'll end up with the system running
>> > >     much slower compared what could have been possible.
>> > >
>> > > 2. Up until now we used to do dirty hacks in early platform init code.
>> > >     Namely (see axs103_early_init() in arch/arc/plat-axs10x/axs10x.c):
>> > >      1) Read CPU's "clock-frequency" from .dtb (remember we're on very early
>> > >         boot stage still so no expanded DevTree yet exists).
>> > >      2) Check how many cores we have and which freq is usable
>> > >      3) Update PLL settings right in place if new freq != existing in PLL.
>> > >
>> > >     Even though it is proven to work but with more platforms in the pipeline
>> > >     we'll need to copy-paste pretty much the same stuff across all affected
>> > >     plats. Which is not nice.
>> > >
>> > >     Moreover back in the day we didn't have a proper clk driver for CPU's PLL.
>> > >     Thus acting on PLL registers right in place was the only thing we were able
>> > >     to do. Now with introduction of normal clk driver
>> > >     (see drivers/clk/axs10x/pll_clock.c in linux-next) we'd like to utilize
>> > >     it and have a cleaner and more universal solution to the problem.
>> > >
>> > >     That's how it could be done - https://urldefense.proofpoint.com/v2/url?u=http-3A__patchwork.ozlabs.org_patch_801240_&d=DwICAg&c=DPL6_X_6JkXF
>> > > x7AXWqB0tg&r=c14YS-cH-
>> > > kdhTOW89KozFhBtBJgs1zXscZojEZQ0THs&m=wuUcceY8Cz5EhVklWLAgj7RzU3rvpanujvQ3qTJK0Gw&s=N5IBjq_eCyOf_GRkZskzqGhczBPTbxLJW_MUfauKvuA&e=
>> > >     Basically in architecture's time_init() we check if there's explicitly
>> > >     specified "clock-frequency" parameter in cpu's node in Device Tree and
>> > >     if there's one we set it via just instantiated clk driver.
>> > The patch looks generally okay. I'd move all the logic to the clock
>> > driver unless perhaps how to set the cpu freq is defined by the
>> > architecture.
>
> Yeah, that's an interesting question. We may indeed move more smarts to the clock driver
> but:
>  1. We'll have duplicate code in different clock drivers. Even today that kind of clock
>     setup is applicable to AXS10x and HSDK platforms (and they use different clock drivers).

No, you could provide a common, shared function to call. Then each
platform can opt-in. If you can make something that applies to every
single platform now or in the future, then I'd put it in arch. If you
have plans to decouple the timer and cpu clocks, then sounds like you
can't.

IMO, if it's not part of the defined CPU architecture, then don't put
it in arch/. That's how we end up with multiple copies of the same
thing done arbitrarily different ways because few people look across
architectures.

>  2. Print out of CPU frequency which is used during boot process for us is important as well
>     especially during bring-up of new HW.
>
>  3. If there's no dedicated "clock-frequency" parameter in CPU node we won't
>     change anything so that non-affected platforms will live as they used to.
>
> That said IMHO proposed implementation is what we want to kep for now.
>
>> Also note that this code is using a new / adhoc DT binding cpu-freq in cou node to
>> do the override - is that acceptable ?

No, I meant to point that out.

> I think we'll switch to more common "clock-frequency" in the next respin.
> Indeed "cpu-freq" might be a bit misleading.

Ideally, you'd use the clock binding eventually. "clock-frequency" is
still allowed, but not both. You have to pick. Either you have simple
needs or you don't...

>
> Also FWIW one MIPS platform uses something similar
> (even though their property name is not standard but "mips-hpt-frequency"),
> see http://elixir.free-electrons.com/linux/latest/source/arch/mips/boot/dts/brcm/bcm3368.dtsi#L10
> http://elixir.free-electrons.com/linux/latest/source/arch/mips/bmips/setup.c#L141.

That's fine, but you need a good reason.

Rob

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Setting CPU clock frequency on early boot
@ 2017-09-06 15:25         ` Rob Herring
  0 siblings, 0 replies; 18+ messages in thread
From: Rob Herring @ 2017-09-06 15:25 UTC (permalink / raw)
  To: linux-snps-arc

On Wed, Sep 6, 2017 at 8:51 AM, Alexey Brodkin
<Alexey.Brodkin@synopsys.com> wrote:
> Hi Vineet, Rob,
>
> On Tue, 2017-09-05@16:40 -0700, Vineet Gupta wrote:
>> On 09/05/2017 03:04 PM, Rob Herring wrote:
>> >
>> > On Tue, Sep 5, 2017 at 10:37 AM, Alexey Brodkin
>> > <Alexey.Brodkin@synopsys.com> wrote:
>> > >
>> > > Hello,
>> > >
>> > > I'd like to get some feedback on our idea as well as check
>> > > if somebody faces similar situations and if so what would be the best
>> > > way to implement some generic solution that suits everyone.
>> > >
>> > > So that's our problem:
>> > > 1. On power-on hardware might start clocking CPU with either
>> > >     too high frequency (such that CPU may get stuck at some point)
>> > >     or too low frequency.
>> > >
>> > >     That all sounds stupid but let me elaborate a bit here.
>> > >     I'm talking about FPGA-based devboards firmware for which
>> > >     (here I mean just image loaded in FPGA with CPU implementation
>> > >     but not some software yet) might not be stable or be even experimental.
>> > >
>> > >     For example we may deal with dual-core or quad-core designs.
>> > >     Former might be OK running @100MHz and latter is only usable
>> > >     @75MHz and lower. The simplest solution might be to use some safe
>> > >     value before something like CPUfreq kicks in. But we don't yet have
>> > >     CPUfreq for ARC (we do plan to get it working sometime soon)
>>
>> But even if we had cpufreq driver going - I don't think it would be usable for
>> doing large freq switches, since in current implementations of SoCs (or fpga), the
>> clk/pll etc driving core (and all timers etc) are not fixed like say ARM. And as
>> discussed before (and pointed to by tglx), timer subsys can't tolerate (on
>> purpose) such large drifts.
>
> Essentially cpufreq only makes sense for "compatible" systems and unfortunately
> most of our current boards are not capable due to missing constant [decoupled from
> CPU frequency] clock source. But looking forward we are planning to improve on that
> so that hopefully even our FPGA-based boards will be usable with cpufreq.
>
>> > > which
>> > >     means simple change of CPU frequency once time-keeping infrastructure
>> > >     was brought-up is not an option... I.e. we'll end up with the system running
>> > >     much slower compared what could have been possible.
>> > >
>> > > 2. Up until now we used to do dirty hacks in early platform init code.
>> > >     Namely (see axs103_early_init() in arch/arc/plat-axs10x/axs10x.c):
>> > >      1) Read CPU's "clock-frequency" from .dtb (remember we're on very early
>> > >         boot stage still so no expanded DevTree yet exists).
>> > >      2) Check how many cores we have and which freq is usable
>> > >      3) Update PLL settings right in place if new freq != existing in PLL.
>> > >
>> > >     Even though it is proven to work but with more platforms in the pipeline
>> > >     we'll need to copy-paste pretty much the same stuff across all affected
>> > >     plats. Which is not nice.
>> > >
>> > >     Moreover back in the day we didn't have a proper clk driver for CPU's PLL.
>> > >     Thus acting on PLL registers right in place was the only thing we were able
>> > >     to do. Now with introduction of normal clk driver
>> > >     (see drivers/clk/axs10x/pll_clock.c in linux-next) we'd like to utilize
>> > >     it and have a cleaner and more universal solution to the problem.
>> > >
>> > >     That's how it could be done - https://urldefense.proofpoint.com/v2/url?u=http-3A__patchwork.ozlabs.org_patch_801240_&d=DwICAg&c=DPL6_X_6JkXF
>> > > x7AXWqB0tg&r=c14YS-cH-
>> > > kdhTOW89KozFhBtBJgs1zXscZojEZQ0THs&m=wuUcceY8Cz5EhVklWLAgj7RzU3rvpanujvQ3qTJK0Gw&s=N5IBjq_eCyOf_GRkZskzqGhczBPTbxLJW_MUfauKvuA&e=
>> > >     Basically in architecture's time_init() we check if there's explicitly
>> > >     specified "clock-frequency" parameter in cpu's node in Device Tree and
>> > >     if there's one we set it via just instantiated clk driver.
>> > The patch looks generally okay. I'd move all the logic to the clock
>> > driver unless perhaps how to set the cpu freq is defined by the
>> > architecture.
>
> Yeah, that's an interesting question. We may indeed move more smarts to the clock driver
> but:
>  1. We'll have duplicate code in different clock drivers. Even today that kind of clock
>     setup is applicable to AXS10x and HSDK platforms (and they use different clock drivers).

No, you could provide a common, shared function to call. Then each
platform can opt-in. If you can make something that applies to every
single platform now or in the future, then I'd put it in arch. If you
have plans to decouple the timer and cpu clocks, then sounds like you
can't.

IMO, if it's not part of the defined CPU architecture, then don't put
it in arch/. That's how we end up with multiple copies of the same
thing done arbitrarily different ways because few people look across
architectures.

>  2. Print out of CPU frequency which is used during boot process for us is important as well
>     especially during bring-up of new HW.
>
>  3. If there's no dedicated "clock-frequency" parameter in CPU node we won't
>     change anything so that non-affected platforms will live as they used to.
>
> That said IMHO proposed implementation is what we want to kep for now.
>
>> Also note that this code is using a new / adhoc DT binding cpu-freq in cou node to
>> do the override - is that acceptable ?

No, I meant to point that out.

> I think we'll switch to more common "clock-frequency" in the next respin.
> Indeed "cpu-freq" might be a bit misleading.

Ideally, you'd use the clock binding eventually. "clock-frequency" is
still allowed, but not both. You have to pick. Either you have simple
needs or you don't...

>
> Also FWIW one MIPS platform uses something similar
> (even though their property name is not standard but "mips-hpt-frequency"),
> see http://elixir.free-electrons.com/linux/latest/source/arch/mips/boot/dts/brcm/bcm3368.dtsi#L10
> http://elixir.free-electrons.com/linux/latest/source/arch/mips/bmips/setup.c#L141.

That's fine, but you need a good reason.

Rob

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Setting CPU clock frequency on early boot
  2017-09-06 15:25         ` Rob Herring
  (?)
  (?)
@ 2017-09-06 16:22             ` Alexey Brodkin
  -1 siblings, 0 replies; 18+ messages in thread
From: Alexey Brodkin @ 2017-09-06 16:22 UTC (permalink / raw)
  To: robh-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-snps-arc-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	Vineet.Gupta1-HKixBCOQz3hWk0Htik3J/w,
	linux-arch-u79uwXL29TY76Z2rM5mHXA,
	mturquette-rdvid1DuHRBWk0Htik3J/w, sboyd-sgV2jX0FEOL9JmXXK+q4OQ,
	linux-clk-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA

Hi Rob,

On Wed, 2017-09-06 at 10:25 -0500, Rob Herring wrote:
> On Wed, Sep 6, 2017 at 8:51 AM, Alexey Brodkin
> <Alexey.Brodkin@synopsys.com> wrote:
> > 
> > Hi Vineet, Rob,
> > 
> > On Tue, 2017-09-05 at 16:40 -0700, Vineet Gupta wrote:
> > > 
> > > On 09/05/2017 03:04 PM, Rob Herring wrote:
> > > > 
> > > > 
> > > > On Tue, Sep 5, 2017 at 10:37 AM, Alexey Brodkin
> > > > <Alexey.Brodkin@synopsys.com> wrote:

[snip]

> > Yeah, that's an interesting question. We may indeed move more smarts to the clock driver
> > but:
> >  1. We'll have duplicate code in different clock drivers. Even today that kind of clock
> >     setup is applicable to AXS10x and HSDK platforms (and they use different clock drivers).
> 
> No, you could provide a common, shared function to call. Then each
> platform can opt-in. If you can make something that applies to every
> single platform now or in the future, then I'd put it in arch. If you
> have plans to decouple the timer and cpu clocks, then sounds like you
> can't.

Right so we'll implement a function which is called by a platform if required.
That way we escape copy-pasting while keeping enough flexibility for current
and future platforms.

> IMO, if it's not part of the defined CPU architecture, then don't put
> it in arch/. That's how we end up with multiple copies of the same
> thing done arbitrarily different ways because few people look across
> architectures.

So do you propose to have the function [that reads "clock-frequency" from say
CPU node and passes its value to CPU's parent clock driver] in generic
[i.e. architecture agnostic] code somewhere in "init/main.c"?

> > 
> >  2. Print out of CPU frequency which is used during boot process for us is important as well
> >     especially during bring-up of new HW.
> > 
> >  3. If there's no dedicated "clock-frequency" parameter in CPU node we won't
> >     change anything so that non-affected platforms will live as they used to.
> > 
> > That said IMHO proposed implementation is what we want to kep for now.
> > 
> > > 
> > > Also note that this code is using a new / adhoc DT binding cpu-freq in cou node to
> > > do the override - is that acceptable ?
> 
> No, I meant to point that out.

Sorry, but for me it's not clear what did you mean here.
Care to elaborate a bit more?

> > I think we'll switch to more common "clock-frequency" in the next respin.
> > Indeed "cpu-freq" might be a bit misleading.
> 
> Ideally, you'd use the clock binding eventually.

Again I'm probably missing something :)

I meant we will have both clock phandle and "clock-frequency" at the same time.
Something like this:
-------------------------------->8---------------------------
	cpus {
		#address-cells = <1>;
		#size-cells = <0>;

		cpu@0 {
			device_type = "cpu";
			compatible = "snps,archs38";
			reg = <0>;
			clocks = <&core_clk>;
			clock-frequency = <100000000>;  <-- That's where we want to set desired value
		};
	...
	}

	core_clk: core-clk@80 {
		compatible = "snps,axs10x-arc-pll-clock";
		reg = <0x80 0x10>, <0x100 0x10>;
		#clock-cells = <0>;
		clocks = <&input_clk>;
	};
-------------------------------->8---------------------------

Or alternatively we may move "clock-frequency" right to the clock's node and have
it like that:
-------------------------------->8---------------------------
	core_clk: core-clk@80 {
		compatible = "snps,axs10x-arc-pll-clock";
		reg = <0x80 0x10>, <0x100 0x10>;
		
#clock-cells = <0>;
		clocks = <&input_clk>;
		clock-frequency = <100000000>;  <-- That's where we want to set desired value
	
};
-------------------------------->8---------------------------

-Alexey

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Setting CPU clock frequency on early boot
@ 2017-09-06 16:22             ` Alexey Brodkin
  0 siblings, 0 replies; 18+ messages in thread
From: Alexey Brodkin @ 2017-09-06 16:22 UTC (permalink / raw)
  To: robh
  Cc: linux-snps-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GtAODAgew0KCQljb21wYXRpYmxl
ID0gInNucHMsYXhzMTB4LWFyYy1wbGwtY2xvY2siOw0KCQlyZWcgPSA8MHg4MCAweDEwPiwgPDB4
MTAwIDB4MTA+Ow0KCQkjY2xvY2stY2VsbHMgPSA8MD47DQoJCWNsb2NrcyA9IDwmaW5wdXRfY2xr
PjsNCgl9Ow0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0+OC0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLS0tLQ0KDQpPciBhbHRlcm5hdGl2ZWx5IHdlIG1heSBtb3ZlICJjbG9jay1mcmVx
dWVuY3kiIHJpZ2h0IHRvIHRoZSBjbG9jaydzIG5vZGUgYW5kIGhhdmUNCml0IGxpa2UgdGhhdDoN
Ci0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tPjgtLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0NCgljb3JlX2NsazrCoGNvcmUtY2xrQDgwwqB7DQoJCWNvbXBhdGlibGUgPSAic25wcyxh
eHMxMHgtYXJjLXBsbC1jbG9jayI7DQoJCXJlZyA9IDwweDgwIDB4MTA+LCA8MHgxMDAgMHgxMD47
DQoJCQ0KI2Nsb2NrLWNlbGxzID0gPDA+Ow0KCQljbG9ja3MgPSA8JmlucHV0X2Nsaz47DQoJCWNs
b2NrLWZyZXF1ZW5jeSA9IDwxMDAwMDAwMDA+OyDCoDwtLSBUaGF0J3Mgd2hlcmUgd2Ugd2FudCB0
byBzZXQgZGVzaXJlZCB2YWx1ZQ0KCQ0KfTsNCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tPjgtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0NCg0KLUFsZXhleQ==

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Setting CPU clock frequency on early boot
@ 2017-09-06 16:22             ` Alexey Brodkin
  0 siblings, 0 replies; 18+ messages in thread
From: Alexey Brodkin @ 2017-09-06 16:22 UTC (permalink / raw)
  To: robh
  Cc: linux-snps-arc, Vineet.Gupta1, linux-arch, mturquette, sboyd,
	linux-clk, devicetree

Hi Rob,

On Wed, 2017-09-06 at 10:25 -0500, Rob Herring wrote:
> On Wed, Sep 6, 2017 at 8:51 AM, Alexey Brodkin
> <Alexey.Brodkin@synopsys.com> wrote:
> > 
> > Hi Vineet, Rob,
> > 
> > On Tue, 2017-09-05 at 16:40 -0700, Vineet Gupta wrote:
> > > 
> > > On 09/05/2017 03:04 PM, Rob Herring wrote:
> > > > 
> > > > 
> > > > On Tue, Sep 5, 2017 at 10:37 AM, Alexey Brodkin
> > > > <Alexey.Brodkin@synopsys.com> wrote:

[snip]

> > Yeah, that's an interesting question. We may indeed move more smarts to the clock driver
> > but:
> >  1. We'll have duplicate code in different clock drivers. Even today that kind of clock
> >     setup is applicable to AXS10x and HSDK platforms (and they use different clock drivers).
> 
> No, you could provide a common, shared function to call. Then each
> platform can opt-in. If you can make something that applies to every
> single platform now or in the future, then I'd put it in arch. If you
> have plans to decouple the timer and cpu clocks, then sounds like you
> can't.

Right so we'll implement a function which is called by a platform if required.
That way we escape copy-pasting while keeping enough flexibility for current
and future platforms.

> IMO, if it's not part of the defined CPU architecture, then don't put
> it in arch/. That's how we end up with multiple copies of the same
> thing done arbitrarily different ways because few people look across
> architectures.

So do you propose to have the function [that reads "clock-frequency" from say
CPU node and passes its value to CPU's parent clock driver] in generic
[i.e. architecture agnostic] code somewhere in "init/main.c"?

> > 
> >  2. Print out of CPU frequency which is used during boot process for us is important as well
> >     especially during bring-up of new HW.
> > 
> >  3. If there's no dedicated "clock-frequency" parameter in CPU node we won't
> >     change anything so that non-affected platforms will live as they used to.
> > 
> > That said IMHO proposed implementation is what we want to kep for now.
> > 
> > > 
> > > Also note that this code is using a new / adhoc DT binding cpu-freq in cou node to
> > > do the override - is that acceptable ?
> 
> No, I meant to point that out.

Sorry, but for me it's not clear what did you mean here.
Care to elaborate a bit more?

> > I think we'll switch to more common "clock-frequency" in the next respin.
> > Indeed "cpu-freq" might be a bit misleading.
> 
> Ideally, you'd use the clock binding eventually.

Again I'm probably missing something :)

I meant we will have both clock phandle and "clock-frequency" at the same time.
Something like this:
-------------------------------->8---------------------------
	cpus {
		#address-cells = <1>;
		#size-cells = <0>;

		cpu@0 {
			device_type = "cpu";
			compatible = "snps,archs38";
			reg = <0>;
			clocks = <&core_clk>;
			clock-frequency = <100000000>;  <-- That's where we want to set desired value
		};
	...
	}

	core_clk: core-clk@80 {
		compatible = "snps,axs10x-arc-pll-clock";
		reg = <0x80 0x10>, <0x100 0x10>;
		#clock-cells = <0>;
		clocks = <&input_clk>;
	};
-------------------------------->8---------------------------

Or alternatively we may move "clock-frequency" right to the clock's node and have
it like that:
-------------------------------->8---------------------------
	core_clk: core-clk@80 {
		compatible = "snps,axs10x-arc-pll-clock";
		reg = <0x80 0x10>, <0x100 0x10>;
		
#clock-cells = <0>;
		clocks = <&input_clk>;
		clock-frequency = <100000000>;  <-- That's where we want to set desired value
	
};
-------------------------------->8---------------------------

-Alexey

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Setting CPU clock frequency on early boot
@ 2017-09-06 16:22             ` Alexey Brodkin
  0 siblings, 0 replies; 18+ messages in thread
From: Alexey Brodkin @ 2017-09-06 16:22 UTC (permalink / raw)
  To: linux-snps-arc

Hi Rob,

On Wed, 2017-09-06@10:25 -0500, Rob Herring wrote:
> On Wed, Sep 6, 2017 at 8:51 AM, Alexey Brodkin
> <Alexey.Brodkin@synopsys.com> wrote:
> > 
> > Hi Vineet, Rob,
> > 
> > On Tue, 2017-09-05@16:40 -0700, Vineet Gupta wrote:
> > > 
> > > On 09/05/2017 03:04 PM, Rob Herring wrote:
> > > > 
> > > > 
> > > > On Tue, Sep 5, 2017 at 10:37 AM, Alexey Brodkin
> > > > <Alexey.Brodkin@synopsys.com> wrote:

[snip]

> > Yeah, that's an interesting question. We may indeed move more smarts to the clock driver
> > but:
> > ?1. We'll have duplicate code in different clock drivers. Even today that kind of clock
> > ????setup is applicable to AXS10x and HSDK platforms (and they use different clock drivers).
> 
> No, you could provide a common, shared function to call. Then each
> platform can opt-in. If you can make something that applies to every
> single platform now or in the future, then I'd put it in arch. If you
> have plans to decouple the timer and cpu clocks, then sounds like you
> can't.

Right so we'll implement a function which is called by a platform if required.
That way we escape copy-pasting while keeping enough flexibility for current
and future platforms.

> IMO, if it's not part of the defined CPU architecture, then don't put
> it in arch/. That's how we end up with multiple copies of the same
> thing done arbitrarily different ways because few people look across
> architectures.

So do you propose to have the function [that reads "clock-frequency" from say
CPU node and passes its value to CPU's parent clock driver] in generic
[i.e. architecture agnostic] code somewhere in "init/main.c"?

> > 
> > ?2. Print out of CPU frequency which is used during boot process for us is important as well
> > ????especially during bring-up of new HW.
> > 
> > ?3. If there's no dedicated "clock-frequency" parameter in CPU node we won't
> > ????change anything so that non-affected platforms will live as they used to.
> > 
> > That said IMHO proposed implementation is what we want to kep for now.
> > 
> > > 
> > > Also note that this code is using a new / adhoc DT binding cpu-freq in cou node to
> > > do the override - is that acceptable ?
> 
> No, I meant to point that out.

Sorry, but for me it's not clear what did you mean here.
Care to elaborate a bit more?

> > I think we'll switch to more common "clock-frequency" in the next respin.
> > Indeed "cpu-freq" might be a bit misleading.
> 
> Ideally, you'd use the clock binding eventually.

Again I'm probably missing something :)

I meant we will have both clock phandle and "clock-frequency" at the same time.
Something like this:
-------------------------------->8---------------------------
	cpus {
		#address-cells = <1>;
		#size-cells = <0>;

		cpu at 0 {
			device_type = "cpu";
			compatible = "snps,archs38";
			reg = <0>;
			clocks = <&core_clk>;
			clock-frequency = <100000000>; ?<-- That's where we want to set desired value
		};
	...
	}

	core_clk: core-clk at 80 {
		compatible = "snps,axs10x-arc-pll-clock";
		reg = <0x80 0x10>, <0x100 0x10>;
		#clock-cells = <0>;
		clocks = <&input_clk>;
	};
-------------------------------->8---------------------------

Or alternatively we may move "clock-frequency" right to the clock's node and have
it like that:
-------------------------------->8---------------------------
	core_clk:?core-clk at 80?{
		compatible = "snps,axs10x-arc-pll-clock";
		reg = <0x80 0x10>, <0x100 0x10>;
		
#clock-cells = <0>;
		clocks = <&input_clk>;
		clock-frequency = <100000000>; ?<-- That's where we want to set desired value
	
};
-------------------------------->8---------------------------

-Alexey

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Setting CPU clock frequency on early boot
  2017-09-06 16:22             ` Alexey Brodkin
@ 2017-09-06 19:20               ` Rob Herring
  -1 siblings, 0 replies; 18+ messages in thread
From: Rob Herring @ 2017-09-06 19:20 UTC (permalink / raw)
  To: Alexey Brodkin
  Cc: linux-snps-arc, Vineet.Gupta1, linux-arch, mturquette, sboyd,
	linux-clk, devicetree

On Wed, Sep 6, 2017 at 11:22 AM, Alexey Brodkin
<Alexey.Brodkin@synopsys.com> wrote:
> Hi Rob,
>
> On Wed, 2017-09-06 at 10:25 -0500, Rob Herring wrote:
>> On Wed, Sep 6, 2017 at 8:51 AM, Alexey Brodkin
>> <Alexey.Brodkin@synopsys.com> wrote:
>> >
>> > Hi Vineet, Rob,
>> >
>> > On Tue, 2017-09-05 at 16:40 -0700, Vineet Gupta wrote:
>> > >
>> > > On 09/05/2017 03:04 PM, Rob Herring wrote:
>> > > >
>> > > >
>> > > > On Tue, Sep 5, 2017 at 10:37 AM, Alexey Brodkin
>> > > > <Alexey.Brodkin@synopsys.com> wrote:
>
> [snip]
>
>> > Yeah, that's an interesting question. We may indeed move more smarts to the clock driver
>> > but:
>> >  1. We'll have duplicate code in different clock drivers. Even today that kind of clock
>> >     setup is applicable to AXS10x and HSDK platforms (and they use different clock drivers).
>>
>> No, you could provide a common, shared function to call. Then each
>> platform can opt-in. If you can make something that applies to every
>> single platform now or in the future, then I'd put it in arch. If you
>> have plans to decouple the timer and cpu clocks, then sounds like you
>> can't.
>
> Right so we'll implement a function which is called by a platform if required.
> That way we escape copy-pasting while keeping enough flexibility for current
> and future platforms.
>
>> IMO, if it's not part of the defined CPU architecture, then don't put
>> it in arch/. That's how we end up with multiple copies of the same
>> thing done arbitrarily different ways because few people look across
>> architectures.
>
> So do you propose to have the function [that reads "clock-frequency" from say
> CPU node and passes its value to CPU's parent clock driver] in generic
> [i.e. architecture agnostic] code somewhere in "init/main.c"?

No, just like you said above and have the platform's clock driver
initialize frequencies.

I haven't seen anyone else want such a thing as generally the
bootloader should initialize things to something reasonable.

>> >  2. Print out of CPU frequency which is used during boot process for us is important as well
>> >     especially during bring-up of new HW.
>> >
>> >  3. If there's no dedicated "clock-frequency" parameter in CPU node we won't
>> >     change anything so that non-affected platforms will live as they used to.
>> >
>> > That said IMHO proposed implementation is what we want to kep for now.
>> >
>> > >
>> > > Also note that this code is using a new / adhoc DT binding cpu-freq in cou node to
>> > > do the override - is that acceptable ?
>>
>> No, I meant to point that out.
>
> Sorry, but for me it's not clear what did you mean here.
> Care to elaborate a bit more?

I noticed the same thing and meant to highlight that in my first
reply. Use clock-frequency, don't invent something new.

>> > I think we'll switch to more common "clock-frequency" in the next respin.
>> > Indeed "cpu-freq" might be a bit misleading.
>>
>> Ideally, you'd use the clock binding eventually.
>
> Again I'm probably missing something :)

"clock-frequency" property and the clock bindings (i.e. clocks =
<&phandle>) are generally mutually exclusive at least within clock
consumer side. There's the assigned-clocks binding which provides the
ability to set both parent clocks and frequency.

> I meant we will have both clock phandle and "clock-frequency" at the same time.
> Something like this:
> -------------------------------->8---------------------------
>         cpus {
>                 #address-cells = <1>;
>                 #size-cells = <0>;
>
>                 cpu@0 {
>                         device_type = "cpu";
>                         compatible = "snps,archs38";
>                         reg = <0>;
>                         clocks = <&core_clk>;
>                         clock-frequency = <100000000>;  <-- That's where we want to set desired value
>                 };
>         ...
>         }
>
>         core_clk: core-clk@80 {
>                 compatible = "snps,axs10x-arc-pll-clock";
>                 reg = <0x80 0x10>, <0x100 0x10>;
>                 #clock-cells = <0>;
>                 clocks = <&input_clk>;
>         };
> -------------------------------->8---------------------------
>
> Or alternatively we may move "clock-frequency" right to the clock's node and have
> it like that:
> -------------------------------->8---------------------------
>         core_clk: core-clk@80 {
>                 compatible = "snps,axs10x-arc-pll-clock";
>                 reg = <0x80 0x10>, <0x100 0x10>;
>
> #clock-cells = <0>;
>                 clocks = <&input_clk>;
>                 clock-frequency = <100000000>;  <-- That's where we want to set desired value

I think this is how it should be done if you use clock-frequency prop.
This is inline with how fixed-clock binding is done.

Rob

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Setting CPU clock frequency on early boot
@ 2017-09-06 19:20               ` Rob Herring
  0 siblings, 0 replies; 18+ messages in thread
From: Rob Herring @ 2017-09-06 19:20 UTC (permalink / raw)
  To: linux-snps-arc

On Wed, Sep 6, 2017 at 11:22 AM, Alexey Brodkin
<Alexey.Brodkin@synopsys.com> wrote:
> Hi Rob,
>
> On Wed, 2017-09-06@10:25 -0500, Rob Herring wrote:
>> On Wed, Sep 6, 2017 at 8:51 AM, Alexey Brodkin
>> <Alexey.Brodkin@synopsys.com> wrote:
>> >
>> > Hi Vineet, Rob,
>> >
>> > On Tue, 2017-09-05@16:40 -0700, Vineet Gupta wrote:
>> > >
>> > > On 09/05/2017 03:04 PM, Rob Herring wrote:
>> > > >
>> > > >
>> > > > On Tue, Sep 5, 2017 at 10:37 AM, Alexey Brodkin
>> > > > <Alexey.Brodkin@synopsys.com> wrote:
>
> [snip]
>
>> > Yeah, that's an interesting question. We may indeed move more smarts to the clock driver
>> > but:
>> >  1. We'll have duplicate code in different clock drivers. Even today that kind of clock
>> >     setup is applicable to AXS10x and HSDK platforms (and they use different clock drivers).
>>
>> No, you could provide a common, shared function to call. Then each
>> platform can opt-in. If you can make something that applies to every
>> single platform now or in the future, then I'd put it in arch. If you
>> have plans to decouple the timer and cpu clocks, then sounds like you
>> can't.
>
> Right so we'll implement a function which is called by a platform if required.
> That way we escape copy-pasting while keeping enough flexibility for current
> and future platforms.
>
>> IMO, if it's not part of the defined CPU architecture, then don't put
>> it in arch/. That's how we end up with multiple copies of the same
>> thing done arbitrarily different ways because few people look across
>> architectures.
>
> So do you propose to have the function [that reads "clock-frequency" from say
> CPU node and passes its value to CPU's parent clock driver] in generic
> [i.e. architecture agnostic] code somewhere in "init/main.c"?

No, just like you said above and have the platform's clock driver
initialize frequencies.

I haven't seen anyone else want such a thing as generally the
bootloader should initialize things to something reasonable.

>> >  2. Print out of CPU frequency which is used during boot process for us is important as well
>> >     especially during bring-up of new HW.
>> >
>> >  3. If there's no dedicated "clock-frequency" parameter in CPU node we won't
>> >     change anything so that non-affected platforms will live as they used to.
>> >
>> > That said IMHO proposed implementation is what we want to kep for now.
>> >
>> > >
>> > > Also note that this code is using a new / adhoc DT binding cpu-freq in cou node to
>> > > do the override - is that acceptable ?
>>
>> No, I meant to point that out.
>
> Sorry, but for me it's not clear what did you mean here.
> Care to elaborate a bit more?

I noticed the same thing and meant to highlight that in my first
reply. Use clock-frequency, don't invent something new.

>> > I think we'll switch to more common "clock-frequency" in the next respin.
>> > Indeed "cpu-freq" might be a bit misleading.
>>
>> Ideally, you'd use the clock binding eventually.
>
> Again I'm probably missing something :)

"clock-frequency" property and the clock bindings (i.e. clocks =
<&phandle>) are generally mutually exclusive at least within clock
consumer side. There's the assigned-clocks binding which provides the
ability to set both parent clocks and frequency.

> I meant we will have both clock phandle and "clock-frequency" at the same time.
> Something like this:
> -------------------------------->8---------------------------
>         cpus {
>                 #address-cells = <1>;
>                 #size-cells = <0>;
>
>                 cpu at 0 {
>                         device_type = "cpu";
>                         compatible = "snps,archs38";
>                         reg = <0>;
>                         clocks = <&core_clk>;
>                         clock-frequency = <100000000>;  <-- That's where we want to set desired value
>                 };
>         ...
>         }
>
>         core_clk: core-clk at 80 {
>                 compatible = "snps,axs10x-arc-pll-clock";
>                 reg = <0x80 0x10>, <0x100 0x10>;
>                 #clock-cells = <0>;
>                 clocks = <&input_clk>;
>         };
> -------------------------------->8---------------------------
>
> Or alternatively we may move "clock-frequency" right to the clock's node and have
> it like that:
> -------------------------------->8---------------------------
>         core_clk: core-clk at 80 {
>                 compatible = "snps,axs10x-arc-pll-clock";
>                 reg = <0x80 0x10>, <0x100 0x10>;
>
> #clock-cells = <0>;
>                 clocks = <&input_clk>;
>                 clock-frequency = <100000000>;  <-- That's where we want to set desired value

I think this is how it should be done if you use clock-frequency prop.
This is inline with how fixed-clock binding is done.

Rob

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2017-09-06 19:20 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-05 15:37 Setting CPU clock frequency on early boot Alexey Brodkin
2017-09-05 15:37 ` Alexey Brodkin
2017-09-05 15:37 ` Alexey Brodkin
2017-09-05 22:03 ` Rob Herring
2017-09-05 22:03   ` Rob Herring
2017-09-05 23:40   ` Vineet Gupta
2017-09-05 23:40     ` Vineet Gupta
2017-09-06 13:51     ` Alexey Brodkin
2017-09-06 13:51       ` Alexey Brodkin
2017-09-06 13:51       ` Alexey Brodkin
2017-09-06 15:25       ` Rob Herring
2017-09-06 15:25         ` Rob Herring
     [not found]         ` <CAL_Jsq+B74keQ3N=8x6jx1URkLq8fa9gwsc5JAuiV86Wwczi9Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-09-06 16:22           ` Alexey Brodkin
2017-09-06 16:22             ` Alexey Brodkin
2017-09-06 16:22             ` Alexey Brodkin
2017-09-06 16:22             ` Alexey Brodkin
2017-09-06 19:20             ` Rob Herring
2017-09-06 19:20               ` Rob Herring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.