diff mbox

[4/6,v2] ARM: integrator: initial device tree support

Message ID 1346471760-23993-4-git-send-email-linus.walleij@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Linus Walleij Sept. 1, 2012, 3:55 a.m. UTC
This is initial device tree support for the ARM Integrator family,
we create a very basic device tree, #ifdef out the non-DT machines
when compiling for device tree.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
ChangeLog v1->v2:
- Also switch over clocksource and clockevent to device tree.
  Else the IRQ mapping goes bananas.
---
 Documentation/devicetree/bindings/arm/arm-boards |  12 ++
 arch/arm/boot/dts/integratorap.dts               |  51 ++++++++
 arch/arm/boot/dts/integratorcp.dts               |  69 ++++++++++
 arch/arm/mach-integrator/integrator_ap.c         | 137 ++++++++++++++++----
 arch/arm/mach-integrator/integrator_cp.c         | 152 ++++++++++++++++-------
 5 files changed, 353 insertions(+), 68 deletions(-)
 create mode 100644 arch/arm/boot/dts/integratorap.dts
 create mode 100644 arch/arm/boot/dts/integratorcp.dts

Comments

Arnd Bergmann Sept. 1, 2012, 6:41 p.m. UTC | #1
On Saturday 01 September 2012, Linus Walleij wrote:

> diff --git a/arch/arm/boot/dts/integratorcp.dts b/arch/arm/boot/dts/integratorcp.dts
> new file mode 100644
> index 0000000..8fad5a1
> --- /dev/null
> +++ b/arch/arm/boot/dts/integratorcp.dts
> @@ -0,0 +1,69 @@
> +/*
> + * Device Tree for the ARM Integrator/CP platform
> + */
> +
> +/dts-v1/;
> +/include/ "skeleton.dtsi"
> +
> +/ {
> +	model = "ARM Integrator/CP";
> +	compatible = "arm,integrator-cp";
> +	ranges;
> +
> +	aliases {
> +		arm,integrator-clocksource = &timer2;
> +		arm,integrator-clockevent = &timer1;
> +	};

It looks like this file is almost a direct superset of the integratorap.dts
file. How about including the other file from here and just adding the
extra nodes and overriding the few bits that are actually different?

>  
> +#ifdef CONFIG_OF
> +
...
> +DT_MACHINE_START(INTEGRATOR_AP_DT, "ARM Integrator/AP (Device Tree)")
> +	.reserve	= integrator_reserve,
> +	.map_io		= ap_map_io,
> +	.nr_irqs	= NR_IRQS_INTEGRATOR_AP,
> +	.init_early	= ap_init_early,
> +	.init_irq	= ap_init_irq_of,
> +	.handle_irq	= fpga_handle_irq,
> +	.timer		= &ap_of_timer,
> +	.init_machine	= ap_init,
> +	.restart	= integrator_restart,
> +	.dt_compat      = ap_dt_board_compat,
> +MACHINE_END
> +
> +#else
> +
...
>  MACHINE_START(INTEGRATOR, "ARM-Integrator")
>  	/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
>  	.atag_offset	= 0x100,
> @@ -486,3 +571,5 @@ MACHINE_START(INTEGRATOR, "ARM-Integrator")
>  	.init_machine	= ap_init,
>  	.restart	= integrator_restart,
>  MACHINE_END
> +
> +#endif

I think we discussed this before. It would be nice to replace the #if/#else
with 

#ifdef CONFIG_OF
...
#endif
#ifdef CONFIG_ATAG
...
#endif

so you can actually support both in the same binary. The other alternative
would be to remove the ATAG boot capability right away, as some other
platforms have done when they moved to DT.

	Arnd
Rob Herring Sept. 2, 2012, 10:59 p.m. UTC | #2
On 08/31/2012 10:55 PM, Linus Walleij wrote:
> This is initial device tree support for the ARM Integrator family,
> we create a very basic device tree, #ifdef out the non-DT machines
> when compiling for device tree.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> ChangeLog v1->v2:
> - Also switch over clocksource and clockevent to device tree.
>   Else the IRQ mapping goes bananas.
> ---

snip

> +++ b/arch/arm/boot/dts/integratorcp.dts
> @@ -0,0 +1,69 @@
> +/*
> + * Device Tree for the ARM Integrator/CP platform
> + */
> +
> +/dts-v1/;
> +/include/ "skeleton.dtsi"
> +
> +/ {
> +	model = "ARM Integrator/CP";
> +	compatible = "arm,integrator-cp";
> +	ranges;
> +
> +	aliases {
> +		arm,integrator-clocksource = &timer2;
> +		arm,integrator-clockevent = &timer1;

This is linux specific and a common issue we need a solution for. Grant
had done something for versatile and we discussed it some, but nothing
ever got close to finalized. IIRC, Grant's solution was just add a
"linux,clockevent" or "linux,clocksource" to the nodes that are to be
used. But he wasn't really happy with it. Perhaps using these names as
aliases would be better.

Rob
Linus Walleij Sept. 3, 2012, 9:43 p.m. UTC | #3
On Sat, Sep 1, 2012 at 8:41 PM, Arnd Bergmann <arnd@arndb.de> wrote:

> On Saturday 01 September 2012, Linus Walleij wrote:
>> diff --git a/arch/arm/boot/dts/integratorcp.dts b/arch/arm/boot/dts/integratorcp.dts
>> +/ {
>> +     model = "ARM Integrator/CP";
>> +     compatible = "arm,integrator-cp";
>> +     ranges;
>> +
>> +     aliases {
>> +             arm,integrator-clocksource = &timer2;
>> +             arm,integrator-clockevent = &timer1;
>> +     };
>
> It looks like this file is almost a direct superset of the integratorap.dts
> file. How about including the other file from here and just adding the
> extra nodes and overriding the few bits that are actually different?

Isn't it more apropriate to create an integrator.dtsi for the common
stuff and include that into integratorap.dts and integratorcp.dts?

>> +#ifdef CONFIG_OF
>> +
> ...
>> +DT_MACHINE_START(INTEGRATOR_AP_DT, "ARM Integrator/AP (Device Tree)")
>> +     .reserve        = integrator_reserve,
>> +     .map_io         = ap_map_io,
>> +     .nr_irqs        = NR_IRQS_INTEGRATOR_AP,
>> +     .init_early     = ap_init_early,
>> +     .init_irq       = ap_init_irq_of,
>> +     .handle_irq     = fpga_handle_irq,
>> +     .timer          = &ap_of_timer,
>> +     .init_machine   = ap_init,
>> +     .restart        = integrator_restart,
>> +     .dt_compat      = ap_dt_board_compat,
>> +MACHINE_END
>> +
>> +#else
>> +
> ...
>>  MACHINE_START(INTEGRATOR, "ARM-Integrator")
>>       /* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
>>       .atag_offset    = 0x100,
>> @@ -486,3 +571,5 @@ MACHINE_START(INTEGRATOR, "ARM-Integrator")
>>       .init_machine   = ap_init,
>>       .restart        = integrator_restart,
>>  MACHINE_END
>> +
>> +#endif
>
> I think we discussed this before. It would be nice to replace the #if/#else
> with
>
> #ifdef CONFIG_OF
> ...
> #endif
> #ifdef CONFIG_ATAG
> ...
> #endif

Sure, have you applied Nico's patch adding CONFIG_ATAG to and
ARM SoC branch so I can base my patches on it?

I was under the impression that his patch would go through Russell's
tree and I would thus not be able to rely on it until it has landed there
and you have pulled Russell's stuff into your tree.

Currently I would make it impossible to use ATAGs if I do this since
the symbol does not exist, so I really need to base such an
approach in a tree which has CONFIG_ATAG in the first place.

Yours,
Linus Walleij
Linus Walleij Sept. 3, 2012, 9:51 p.m. UTC | #4
On Mon, Sep 3, 2012 at 12:59 AM, Rob Herring <robherring2@gmail.com> wrote:
> On 08/31/2012 10:55 PM, Linus Walleij wrote:

>> +/ {
>> +     model = "ARM Integrator/CP";
>> +     compatible = "arm,integrator-cp";
>> +     ranges;
>> +
>> +     aliases {
>> +             arm,integrator-clocksource = &timer2;
>> +             arm,integrator-clockevent = &timer1;
>
> This is linux specific and a common issue we need a solution for. Grant
> had done something for versatile and we discussed it some, but nothing
> ever got close to finalized. IIRC, Grant's solution was just add a
> "linux,clockevent" or "linux,clocksource" to the nodes that are to be
> used. But he wasn't really happy with it. Perhaps using these names as
> aliases would be better.

Atleast I'm honest about what this is, IMHO this is better than
any of the solutions we already have in boot/dts.

Look at the versatile express
arch/arm/boot/dts/vexpress-v2m.dtsi:

        aliases {
                arm,v2m_timer = &v2m_timer01;
        };

It's quite hard to tell that this "vtm_timer" is actually the block
serving as clock source and clockevent for the Vexpress,
but if you inspect the code you can see that this is what it is.

I can of course skip the aliases and go for the timer nodes
I want directly, but that isn't any helpful for people reading the
device tree, is it?

Maybe primary-timer, secondary-timer is sufficiently
good and neutral aliases?

Yours,
Linus Walleij
Russell King - ARM Linux Sept. 3, 2012, 9:55 p.m. UTC | #5
On Mon, Sep 03, 2012 at 11:43:37PM +0200, Linus Walleij wrote:
> On Sat, Sep 1, 2012 at 8:41 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> > I think we discussed this before. It would be nice to replace the #if/#else
> > with
> >
> > #ifdef CONFIG_OF
> > ...
> > #endif
> > #ifdef CONFIG_ATAG
> > ...
> > #endif
> 
> Sure, have you applied Nico's patch adding CONFIG_ATAG to and
> ARM SoC branch so I can base my patches on it?
> 
> I was under the impression that his patch would go through Russell's
> tree and I would thus not be able to rely on it until it has landed there
> and you have pulled Russell's stuff into your tree.

One of them is already in my tree - I put it in on Saturday though on an
unstable branch.

> Currently I would make it impossible to use ATAGs if I do this since
> the symbol does not exist, so I really need to base such an
> approach in a tree which has CONFIG_ATAG in the first place.

I've just merged that patch though.
Linus Walleij Sept. 4, 2012, 7:19 a.m. UTC | #6
On Mon, Sep 3, 2012 at 11:55 PM, Russell King - ARM Linux
<linux@arm.linux.org.uk> wrote:
> [Me]
>> Currently I would make it impossible to use ATAGs if I do this since
>> the symbol does not exist, so I really need to base such an
>> approach in a tree which has CONFIG_ATAG in the first place.
>
> I've just merged that patch though.

OK great, Arnd do you have a Russell baseline in ARM SoC or is it
easier if I try to submit this series directly to Russell?

Yours,
Linus Walleij
Olof Johansson Sept. 5, 2012, 5:34 a.m. UTC | #7
On Tue, Sep 04, 2012 at 09:19:10AM +0200, Linus Walleij wrote:
> On Mon, Sep 3, 2012 at 11:55 PM, Russell King - ARM Linux
> <linux@arm.linux.org.uk> wrote:
> > [Me]
> >> Currently I would make it impossible to use ATAGs if I do this since
> >> the symbol does not exist, so I really need to base such an
> >> approach in a tree which has CONFIG_ATAG in the first place.
> >
> > I've just merged that patch though.
> 
> OK great, Arnd do you have a Russell baseline in ARM SoC or is it
> easier if I try to submit this series directly to Russell?

Since Russell said he hasn't applied it to a stable branch we can't pull
anything in yet. But once he does, especially if he does it on a separate topic
branch, we can easily pull that in as a prerequisite in arm-soc. Russell?

There probably isn't much conflicting development in this release cycle
on integrator though, so having all changes go through Russell could be
OK as well. Only time that becomes awkward is if there's changes in both
trees that end up needing manual merge resolution. I don't think that's
high risk in this case.

So, Linus, it's up to you (and Russell) what you prefer, but I'd be
happy to take it through arm-soc if we get a stable base.


-Olof
Linus Walleij Sept. 5, 2012, 5:47 a.m. UTC | #8
On Wed, Sep 5, 2012 at 7:34 AM, Olof Johansson <olof@lixom.net> wrote:

> So, Linus, it's up to you (and Russell) what you prefer, but I'd be
> happy to take it through arm-soc if we get a stable base.

I'll fix up the usage of CONFIG_ATAGS in this patch and put it into
Russell's tracker to minimize the hazzle.

Yours,
Linus Walleij
Rob Herring Sept. 6, 2012, 1:20 p.m. UTC | #9
On 09/03/2012 04:51 PM, Linus Walleij wrote:
> On Mon, Sep 3, 2012 at 12:59 AM, Rob Herring <robherring2@gmail.com> wrote:
>> On 08/31/2012 10:55 PM, Linus Walleij wrote:
> 
>>> +/ {
>>> +     model = "ARM Integrator/CP";
>>> +     compatible = "arm,integrator-cp";
>>> +     ranges;
>>> +
>>> +     aliases {
>>> +             arm,integrator-clocksource = &timer2;
>>> +             arm,integrator-clockevent = &timer1;
>>
>> This is linux specific and a common issue we need a solution for. Grant
>> had done something for versatile and we discussed it some, but nothing
>> ever got close to finalized. IIRC, Grant's solution was just add a
>> "linux,clockevent" or "linux,clocksource" to the nodes that are to be
>> used. But he wasn't really happy with it. Perhaps using these names as
>> aliases would be better.
> 
> Atleast I'm honest about what this is, IMHO this is better than
> any of the solutions we already have in boot/dts.
> 
> Look at the versatile express
> arch/arm/boot/dts/vexpress-v2m.dtsi:
> 
>         aliases {
>                 arm,v2m_timer = &v2m_timer01;
>         };
> 
> It's quite hard to tell that this "vtm_timer" is actually the block
> serving as clock source and clockevent for the Vexpress,
> but if you inspect the code you can see that this is what it is.

Yeah, we really need to unify all this.

> I can of course skip the aliases and go for the timer nodes
> I want directly, but that isn't any helpful for people reading the
> device tree, is it?

Well, the dts doesn't really need to describe how Linux is using things.
I'd like to get to common DT code for sp804 so all platforms just have a
call to sp804_dt_init() which does all the initialization.

> 
> Maybe primary-timer, secondary-timer is sufficiently
> good and neutral aliases?

That doesn't distinguish clk-event vs. clk-source. Perhaps we can use
presence of interrupt to distinguish that. It shouldn't really matter
which timer Linux picks as long as the h/w has the necessary features.
We just need to make sure dts describes those features. Some of the
things we have to deal with:

Highbank has interrupt for timer0, but not on timer1, so timer0 must be
clk-event. It also users timer1 for sched clock, but ARM Ltd platforms
use a different timer.

Realview and Versatile use timer0 for clk-event and timer3 for clk-src.
Is there something broken with timer1 and timer2? It is certainly
possible the h/w has the clock tied off for 1 of the 2 timers.

VExpress CA9 has broken timers on the core tile (at least they were
ifdef'ed out before the last clean-up). We could just remove/disable
them in the dts so they are not used.

Rob
Linus Walleij Sept. 6, 2012, 1:56 p.m. UTC | #10
On Thu, Sep 6, 2012 at 3:20 PM, Rob Herring <robherring2@gmail.com> wrote:
> [Me]
>> I can of course skip the aliases and go for the timer nodes
>> I want directly, but that isn't any helpful for people reading the
>> device tree, is it?
>
> Well, the dts doesn't really need to describe how Linux is using things.

The arm,integrator-clocksource and arm,integrator-clockevent
are renamed arm,timer-primary and arm,timer-secondary in the
last patch set.

Are you OK with this for now, going forward? I'd be happy to
take a round refactoring it for the next cycle as outlined
below.

> I'd like to get to common DT code for sp804 so all platforms just have a
> call to sp804_dt_init() which does all the initialization.

The Integrator/AP does not have the SP804 timer, it has a
precursor with similar, yet different register setup. The
driver is in the integrator_ab. core file.

(I could look into merging this SP804 ancestor into the SP804
driver with some flag or so, but that would be a different
TODO item.)

The Integrator/CP has the SP804 however.

>> Maybe primary-timer, secondary-timer is sufficiently
>> good and neutral aliases?
>
> That doesn't distinguish clk-event vs. clk-source. Perhaps we can use
> presence of interrupt to distinguish that.

They all have interrupts in the Integrator case so all timers
are equal. But I vaguely recall someone whisper bad things about
timer0.

> It shouldn't really matter
> which timer Linux picks as long as the h/w has the necessary features.

That is true, what I've been doing so far is just a 1-to-1 mapping
to current usage without much massaging of the abstract resource
concept.

> We just need to make sure dts describes those features. Some of the
> things we have to deal with:
>
> Highbank has interrupt for timer0, but not on timer1, so timer0 must be
> clk-event. It also users timer1 for sched clock, but ARM Ltd platforms
> use a different timer.

So I guess this SP804? They just didn't route the IRQ line
I guess... :-(

> Realview and Versatile use timer0 for clk-event and timer3 for clk-src.
> Is there something broken with timer1 and timer2? It is certainly
> possible the h/w has the clock tied off for 1 of the 2 timers.

Integrator use timer2 for clockevent and timer1 for clocksource,
and legends tell that timer0 should be avoided. But I guess
I could try to find out by experience, I fear that it could work
but be instable so that it appears to work but in reality does not...

> VExpress CA9 has broken timers on the core tile (at least they were
> ifdef'ed out before the last clean-up). We could just remove/disable
> them in the dts so they are not used.

There is something about the DT ambition here (or for that matter
the boardfile ambition). On the RealView PB1176 there is
a broken DMA engine, we just deleted it from the resource
list. Other people might want to have all available resources
listed but marked "broken" in the DT for completeness.

The latter has the upside of providing hints to the next
engineer who would otherwise come around and ask why
the hardware in the refman is not listed in the DT and start
to try to add it and find out it is broken. Knowing it's there
and it's broken is encoding real knowledge at the expense
of a few DT bytes.

(I'm fine with either.)

Yours,
Linus Walleij
Russell King - ARM Linux Sept. 6, 2012, 2:14 p.m. UTC | #11
On Thu, Sep 06, 2012 at 08:20:30AM -0500, Rob Herring wrote:
> Well, the dts doesn't really need to describe how Linux is using things.
> I'd like to get to common DT code for sp804 so all platforms just have a
> call to sp804_dt_init() which does all the initialization.

They don't all have SP804 timers.  The Integrator/AP does not have SP804,
and it would be wrong to try and merge them into the clean SP804 driver.

Integrator/AP timers are strictly 16-bit only affairs, which need special
clocking handling to ensure that their rollover rate is sufficiently long.
SP804 timers are 32-bit or 16-bit timers, we drive the only in 32-bit mode,
and so they don't suffer from the above issue.  Polluting this code with
the legacy 16-bit stuff just for one platform is not a good idea.  They
weren't even called SP804 in the Integrator/AP days - they were just a
random timer design embedded into a FPGA.

> Realview and Versatile use timer0 for clk-event and timer3 for clk-src.
> Is there something broken with timer1 and timer2? It is certainly
> possible the h/w has the clock tied off for 1 of the 2 timers.

I don't believe so, that's the way the timers were used when I received
the initial code drop from ARM Ltd, before it got cleaned up.  The
selection of what timers are used appears to me to be completely random.

> VExpress CA9 has broken timers on the core tile (at least they were
> ifdef'ed out before the last clean-up). We could just remove/disable
> them in the dts so they are not used.

The motherboard timers can be switched between 32kHz and 1MHz mode.  The
core tile timers can probably be switched between 32kHz and 1MHz mode but
god knows how - they default to 32kHz.  So given that choice, I opted for
the higher resolution motherboard timers and left the hooks for the core
tile timers in place, in the hope that someone would tell me or implement
the switching to 1MHz mode.

Obviously, no one did, and the code got removed.  I doubt it makes any
difference what so ever.

And that's a very good point - in the current way things are handled on
these platforms, the tweaking of the SP804 input clocks has been divorced
from the SP804 initialization.  This is bad, because it means that
dependency has been hidden by the DT conversion...

So, selection of the right SP804s to use is also a function of "do we know
how to control its clock rate".  If we don't, we can't be certain of the
rate at which the timer ticks.
Arnd Bergmann Sept. 6, 2012, 2:19 p.m. UTC | #12
On Thursday 06 September 2012, Linus Walleij wrote:
> On Thu, Sep 6, 2012 at 3:20 PM, Rob Herring <robherring2@gmail.com> wrote:
> > [Me]
> >> I can of course skip the aliases and go for the timer nodes
> >> I want directly, but that isn't any helpful for people reading the
> >> device tree, is it?
> >
> > Well, the dts doesn't really need to describe how Linux is using things.
> 
> The arm,integrator-clocksource and arm,integrator-clockevent
> are renamed arm,timer-primary and arm,timer-secondary in the
> last patch set.
> 
> Are you OK with this for now, going forward? I'd be happy to
> take a round refactoring it for the next cycle as outlined
> below.

If the timers are really free for use by anything and you want to
encode how Linux uses them, I would suggest naming the aliases
"linux.clocksource" and "linux,clockevent" to make it clear that
you are not describing the hardware here but rather picking
a configuration.

	Arnd
Rob Herring Sept. 6, 2012, 3:35 p.m. UTC | #13
On 09/06/2012 08:56 AM, Linus Walleij wrote:
> On Thu, Sep 6, 2012 at 3:20 PM, Rob Herring <robherring2@gmail.com> wrote:
>> [Me]
>>> I can of course skip the aliases and go for the timer nodes
>>> I want directly, but that isn't any helpful for people reading the
>>> device tree, is it?
>>
>> Well, the dts doesn't really need to describe how Linux is using things.
> 
> The arm,integrator-clocksource and arm,integrator-clockevent
> are renamed arm,timer-primary and arm,timer-secondary in the
> last patch set.
> 
> Are you OK with this for now, going forward? I'd be happy to
> take a round refactoring it for the next cycle as outlined
> below.
> 
>> I'd like to get to common DT code for sp804 so all platforms just have a
>> call to sp804_dt_init() which does all the initialization.
> 
> The Integrator/AP does not have the SP804 timer, it has a
> precursor with similar, yet different register setup. The
> driver is in the integrator_ab. core file.

Right, that was really just an example. We have the general problem that
platforms have N timers and how do we assign them to clk source and clk
event. I'm fine with aliases if we decide that other options have issues
or are not worth the complexity. A "linux,X" property really needs to be
a last resort.

> (I could look into merging this SP804 ancestor into the SP804
> driver with some flag or so, but that would be a different
> TODO item.)
> 
> The Integrator/CP has the SP804 however.
> 
>>> Maybe primary-timer, secondary-timer is sufficiently
>>> good and neutral aliases?
>>
>> That doesn't distinguish clk-event vs. clk-source. Perhaps we can use
>> presence of interrupt to distinguish that.
> 
> They all have interrupts in the Integrator case so all timers
> are equal. But I vaguely recall someone whisper bad things about
> timer0.

Then that is a "feature" of the h/w. So perhaps a "arm,timer-horked"
should be added as a property. Certainly wouldn't be the first timer
with that feature. :)

>> It shouldn't really matter
>> which timer Linux picks as long as the h/w has the necessary features.
> 
> That is true, what I've been doing so far is just a 1-to-1 mapping
> to current usage without much massaging of the abstract resource
> concept.
> 
>> We just need to make sure dts describes those features. Some of the
>> things we have to deal with:
>>
>> Highbank has interrupt for timer0, but not on timer1, so timer0 must be
>> clk-event. It also users timer1 for sched clock, but ARM Ltd platforms
>> use a different timer.
> 
> So I guess this SP804? They just didn't route the IRQ line
> I guess... :-(
> 
>> Realview and Versatile use timer0 for clk-event and timer3 for clk-src.
>> Is there something broken with timer1 and timer2? It is certainly
>> possible the h/w has the clock tied off for 1 of the 2 timers.
> 
> Integrator use timer2 for clockevent and timer1 for clocksource,
> and legends tell that timer0 should be avoided. But I guess
> I could try to find out by experience, I fear that it could work
> but be instable so that it appears to work but in reality does not...
> 
>> VExpress CA9 has broken timers on the core tile (at least they were
>> ifdef'ed out before the last clean-up). We could just remove/disable
>> them in the dts so they are not used.
> 
> There is something about the DT ambition here (or for that matter
> the boardfile ambition). On the RealView PB1176 there is
> a broken DMA engine, we just deleted it from the resource
> list. Other people might want to have all available resources
> listed but marked "broken" in the DT for completeness.
> 
> The latter has the upside of providing hints to the next
> engineer who would otherwise come around and ask why
> the hardware in the refman is not listed in the DT and start
> to try to add it and find out it is broken. Knowing it's there
> and it's broken is encoding real knowledge at the expense
> of a few DT bytes.
> 

Yes, saving that information somewhere is useful.

Rob
Linus Walleij Sept. 12, 2012, 4:52 p.m. UTC | #14
On Thu, Sep 6, 2012 at 4:19 PM, Arnd Bergmann <arnd@arndb.de> wrote:
> On Thursday 06 September 2012, Linus Walleij wrote:
>> On Thu, Sep 6, 2012 at 3:20 PM, Rob Herring <robherring2@gmail.com> wrote:
>> > [Me]
>> >> I can of course skip the aliases and go for the timer nodes
>> >> I want directly, but that isn't any helpful for people reading the
>> >> device tree, is it?
>> >
>> > Well, the dts doesn't really need to describe how Linux is using things.
>>
>> The arm,integrator-clocksource and arm,integrator-clockevent
>> are renamed arm,timer-primary and arm,timer-secondary in the
>> last patch set.
>>
>> Are you OK with this for now, going forward? I'd be happy to
>> take a round refactoring it for the next cycle as outlined
>> below.
>
> If the timers are really free for use by anything and you want to
> encode how Linux uses them, I would suggest naming the aliases
> "linux.clocksource" and "linux,clockevent" to make it clear that
> you are not describing the hardware here but rather picking
> a configuration.

So the renaming of the aliases to arm,timer-primary and
arm-timer-secondary is to be taken as a hint to the OS to use
these two as primary and secondary respectively.

linux.foo seems bad in comparison, but if you insist...

Yours,
Linus Walleij
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/arm/arm-boards b/Documentation/devicetree/bindings/arm/arm-boards
index 91f2614..fc81a7d 100644
--- a/Documentation/devicetree/bindings/arm/arm-boards
+++ b/Documentation/devicetree/bindings/arm/arm-boards
@@ -1,3 +1,15 @@ 
+ARM Integrator/AP (Application Platform) and Integrator/CP (Compact Platform)
+-----------------------------------------------------------------------------
+ARM's oldest Linux-supported platform with connectors for different core
+tiles of ARMv4, ARMv5 and ARMv6 type.
+
+Required properties (in root node):
+	compatible = "arm,integrator-ap";  /* Application Platform */
+	compatible = "arm,integrator-cp";  /* Compact Platform */
+
+FPGA type interrupt controllers, see the versatile-fpga-irq binding doc.
+
+
 ARM Versatile Application and Platform Baseboards
 -------------------------------------------------
 ARM's development hardware platform with connectors for customizable
diff --git a/arch/arm/boot/dts/integratorap.dts b/arch/arm/boot/dts/integratorap.dts
new file mode 100644
index 0000000..928a7be
--- /dev/null
+++ b/arch/arm/boot/dts/integratorap.dts
@@ -0,0 +1,51 @@ 
+/*
+ * Device Tree for the ARM Integrator/AP platform
+ */
+
+/dts-v1/;
+/include/ "skeleton.dtsi"
+
+/ {
+	model = "ARM Integrator/AP";
+	compatible = "arm,integrator-ap";
+	ranges;
+
+	aliases {
+		arm,integrator-clocksource = &timer2;
+		arm,integrator-clockevent = &timer1;
+	};
+
+	chosen {
+		bootargs = "root=/dev/ram0 console=ttyAM0,38400n8 earlyprintk";
+	};
+
+	timer0: timer@13000000 {
+		compatible = "arm,integrator-timer";
+		reg = <0x13000000 0x100>;
+		interrupt-parent = <&pic>;
+		interrupts = <5>;
+	};
+
+	timer1: timer@13000100 {
+		compatible = "arm,integrator-timer";
+		reg = <0x13000100 0x100>;
+		interrupt-parent = <&pic>;
+		interrupts = <6>;
+	};
+
+	timer2: timer@13000200 {
+		compatible = "arm,integrator-timer";
+		reg = <0x13000200 0x100>;
+		interrupt-parent = <&pic>;
+		interrupts = <7>;
+	};
+
+	pic: pic@14000000 {
+		compatible = "arm,versatile-fpga-irq";
+		#interrupt-cells = <1>;
+		interrupt-controller;
+		reg = <0x14000000 0x100>;
+		clear-mask = <0xffffffff>;
+		valid-mask = <0x003fffff>;
+	};
+};
diff --git a/arch/arm/boot/dts/integratorcp.dts b/arch/arm/boot/dts/integratorcp.dts
new file mode 100644
index 0000000..8fad5a1
--- /dev/null
+++ b/arch/arm/boot/dts/integratorcp.dts
@@ -0,0 +1,69 @@ 
+/*
+ * Device Tree for the ARM Integrator/CP platform
+ */
+
+/dts-v1/;
+/include/ "skeleton.dtsi"
+
+/ {
+	model = "ARM Integrator/CP";
+	compatible = "arm,integrator-cp";
+	ranges;
+
+	aliases {
+		arm,integrator-clocksource = &timer2;
+		arm,integrator-clockevent = &timer1;
+	};
+
+	chosen {
+		bootargs = "root=/dev/ram0 console=ttyAMA0,38400n8 earlyprintk";
+	};
+
+	timer0: timer@13000000 {
+		compatible = "arm,sp804", "arm,primecell";
+		reg = <0x13000000 0x100>;
+		interrupt-parent = <&pic>;
+		interrupts = <5>;
+	};
+
+	timer1: timer@13000100 {
+		compatible = "arm,sp804", "arm,primecell";
+		reg = <0x13000100 0x100>;
+		interrupt-parent = <&pic>;
+		interrupts = <6>;
+	};
+
+	timer2: timer@13000200 {
+		compatible = "arm,sp804", "arm,primecell";
+		reg = <0x13000200 0x100>;
+		interrupt-parent = <&pic>;
+		interrupts = <7>;
+	};
+
+	pic: pic@14000000 {
+		compatible = "arm,versatile-fpga-irq";
+		#interrupt-cells = <1>;
+		interrupt-controller;
+		reg = <0x14000000 0x100>;
+		clear-mask = <0xffffffff>;
+		valid-mask = <0x1fc003ff>;
+	};
+
+	cic: cic@10000040 {
+		compatible = "arm,versatile-fpga-irq";
+		#interrupt-cells = <1>;
+		interrupt-controller;
+		reg = <0x10000040 0x100>;
+		clear-mask = <0xffffffff>;
+		valid-mask = <0x00000007>;
+	};
+
+	sic: sic@ca000000 {
+		compatible = "arm,versatile-fpga-irq";
+		#interrupt-cells = <1>;
+		interrupt-controller;
+		reg = <0xca000000 0x100>;
+		clear-mask = <0x00000fff>;
+		valid-mask = <0x00000fff>;
+	};
+};
diff --git a/arch/arm/mach-integrator/integrator_ap.c b/arch/arm/mach-integrator/integrator_ap.c
index ff966d8..26d4d8c 100644
--- a/arch/arm/mach-integrator/integrator_ap.c
+++ b/arch/arm/mach-integrator/integrator_ap.c
@@ -34,6 +34,8 @@ 
 #include <linux/mtd/physmap.h>
 #include <linux/clk.h>
 #include <linux/platform_data/clk-integrator.h>
+#include <linux/of_irq.h>
+#include <linux/of_address.h>
 #include <video/vga.h>
 
 #include <mach/hardware.h>
@@ -161,23 +163,6 @@  static void __init ap_map_io(void)
 	vga_base = PCI_MEMORY_VADDR;
 }
 
-#define INTEGRATOR_SC_VALID_INT	0x003fffff
-
-static void __init ap_init_irq(void)
-{
-	/* Disable all interrupts initially. */
-	/* Do the core module ones */
-	writel(-1, VA_CMIC_BASE + IRQ_ENABLE_CLEAR);
-
-	/* do the header card stuff next */
-	writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
-	writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
-
-	fpga_irq_init(VA_IC_BASE, "SC", IRQ_PIC_START,
-		-1, INTEGRATOR_SC_VALID_INT, NULL);
-	integrator_clk_init(false);
-}
-
 #ifdef CONFIG_PM
 static unsigned long ic_irq_enable;
 
@@ -330,9 +315,9 @@  static u32 notrace integrator_read_sched_clock(void)
 	return -readl((void __iomem *) TIMER2_VA_BASE + TIMER_VALUE);
 }
 
-static void integrator_clocksource_init(unsigned long inrate)
+static void integrator_clocksource_init(unsigned long inrate,
+					void __iomem *base)
 {
-	void __iomem *base = (void __iomem *)TIMER2_VA_BASE;
 	u32 ctrl = TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC;
 	unsigned long rate = inrate;
 
@@ -349,7 +334,7 @@  static void integrator_clocksource_init(unsigned long inrate)
 	setup_sched_clock(integrator_read_sched_clock, 16, rate);
 }
 
-static void __iomem * const clkevt_base = (void __iomem *)TIMER1_VA_BASE;
+static void __iomem * clkevt_base;
 
 /*
  * IRQ handler for the timer
@@ -421,11 +406,13 @@  static struct irqaction integrator_timer_irq = {
 	.dev_id		= &integrator_clockevent,
 };
 
-static void integrator_clockevent_init(unsigned long inrate)
+static void integrator_clockevent_init(unsigned long inrate,
+				void __iomem *base, int irq)
 {
 	unsigned long rate = inrate;
 	unsigned int ctrl = 0;
 
+	clkevt_base = base;
 	/* Calculate and program a divisor */
 	if (rate > 0x100000 * HZ) {
 		rate /= 256;
@@ -437,7 +424,7 @@  static void integrator_clockevent_init(unsigned long inrate)
 	timer_reload = rate / HZ;
 	writel(ctrl, clkevt_base + TIMER_CTRL);
 
-	setup_irq(IRQ_TIMERINT1, &integrator_timer_irq);
+	setup_irq(irq, &integrator_timer_irq);
 	clockevents_config_and_register(&integrator_clockevent,
 					rate,
 					1,
@@ -448,9 +435,89 @@  void __init ap_init_early(void)
 {
 }
 
+#ifdef CONFIG_OF
+
+static void __init ap_init_timer_of(void)
+{
+	struct device_node *node;
+	const char *path;
+	void __iomem *base;
+	int err;
+	int irq;
+	struct clk *clk;
+	unsigned long rate;
+
+	clk = clk_get_sys("ap_timer", NULL);
+	BUG_ON(IS_ERR(clk));
+	clk_prepare_enable(clk);
+	rate = clk_get_rate(clk);
+
+	err = of_property_read_string(of_aliases,
+				"arm,integrator-clocksource", &path);
+	if (WARN_ON(err))
+		return;
+	node = of_find_node_by_path(path);
+	base = of_iomap(node, 0);
+	if (WARN_ON(!base))
+		return;
+	writel(0, base + TIMER_CTRL);
+	integrator_clocksource_init(rate, base);
+
+	err = of_property_read_string(of_aliases,
+				"arm,integrator-clockevent", &path);
+	if (WARN_ON(err))
+		return;
+	node = of_find_node_by_path(path);
+	base = of_iomap(node, 0);
+	if (WARN_ON(!base))
+		return;
+	irq = irq_of_parse_and_map(node, 0);
+	writel(0, base + TIMER_CTRL);
+	integrator_clockevent_init(rate, base, irq);
+}
+
+static struct sys_timer ap_of_timer = {
+	.init		= ap_init_timer_of,
+};
+
+static const struct of_device_id fpga_irq_of_match[] __initconst = {
+	{ .compatible = "arm,versatile-fpga-irq", .data = fpga_irq_of_init, },
+	{ /* Sentinel */ }
+};
+
+static void __init ap_init_irq_of(void)
+{
+	/* disable core module IRQs */
+	writel(0xffffffffU, VA_CMIC_BASE + IRQ_ENABLE_CLEAR);
+	of_irq_init(fpga_irq_of_match);
+	integrator_clk_init(false);
+}
+
+static const char * ap_dt_board_compat[] = {
+	"arm,integrator-ap",
+	NULL,
+};
+
+DT_MACHINE_START(INTEGRATOR_AP_DT, "ARM Integrator/AP (Device Tree)")
+	.reserve	= integrator_reserve,
+	.map_io		= ap_map_io,
+	.nr_irqs	= NR_IRQS_INTEGRATOR_AP,
+	.init_early	= ap_init_early,
+	.init_irq	= ap_init_irq_of,
+	.handle_irq	= fpga_handle_irq,
+	.timer		= &ap_of_timer,
+	.init_machine	= ap_init,
+	.restart	= integrator_restart,
+	.dt_compat      = ap_dt_board_compat,
+MACHINE_END
+
+#else
+
 /*
- * Set up timer(s).
+ * This is where non-devicetree initialization code is collected and stashed
+ * for eventual deletion.
  */
+
 static void __init ap_init_timer(void)
 {
 	struct clk *clk;
@@ -465,14 +532,32 @@  static void __init ap_init_timer(void)
 	writel(0, TIMER1_VA_BASE + TIMER_CTRL);
 	writel(0, TIMER2_VA_BASE + TIMER_CTRL);
 
-	integrator_clocksource_init(rate);
-	integrator_clockevent_init(rate);
+	integrator_clocksource_init(rate, (void __iomem *)TIMER2_VA_BASE);
+	integrator_clockevent_init(rate, (void __iomem *)TIMER1_VA_BASE,
+				IRQ_TIMERINT1);
 }
 
 static struct sys_timer ap_timer = {
 	.init		= ap_init_timer,
 };
 
+#define INTEGRATOR_SC_VALID_INT	0x003fffff
+
+static void __init ap_init_irq(void)
+{
+	/* Disable all interrupts initially. */
+	/* Do the core module ones */
+	writel(-1, VA_CMIC_BASE + IRQ_ENABLE_CLEAR);
+
+	/* do the header card stuff next */
+	writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
+	writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
+
+	fpga_irq_init(VA_IC_BASE, "SC", IRQ_PIC_START,
+		-1, INTEGRATOR_SC_VALID_INT, NULL);
+	integrator_clk_init(false);
+}
+
 MACHINE_START(INTEGRATOR, "ARM-Integrator")
 	/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
 	.atag_offset	= 0x100,
@@ -486,3 +571,5 @@  MACHINE_START(INTEGRATOR, "ARM-Integrator")
 	.init_machine	= ap_init,
 	.restart	= integrator_restart,
 MACHINE_END
+
+#endif
diff --git a/arch/arm/mach-integrator/integrator_cp.c b/arch/arm/mach-integrator/integrator_cp.c
index 2b40bc1..e7f2fb6 100644
--- a/arch/arm/mach-integrator/integrator_cp.c
+++ b/arch/arm/mach-integrator/integrator_cp.c
@@ -23,6 +23,8 @@ 
 #include <linux/gfp.h>
 #include <linux/mtd/physmap.h>
 #include <linux/platform_data/clk-integrator.h>
+#include <linux/of_irq.h>
+#include <linux/of_address.h>
 
 #include <mach/hardware.h>
 #include <mach/platform.h>
@@ -53,10 +55,6 @@ 
 
 #define INTCP_PA_CLCD_BASE		0xc0000000
 
-#define INTCP_VA_CIC_BASE		__io_address(INTEGRATOR_HDR_BASE + 0x40)
-#define INTCP_VA_PIC_BASE		__io_address(INTEGRATOR_IC_BASE)
-#define INTCP_VA_SIC_BASE		__io_address(INTEGRATOR_CP_SIC_BASE)
-
 #define INTCP_ETH_SIZE			0x10
 
 #define INTCP_VA_CTRL_BASE		IO_ADDRESS(INTEGRATOR_CP_CTL_BASE)
@@ -143,37 +141,6 @@  static void __init intcp_map_io(void)
 	iotable_init(intcp_io_desc, ARRAY_SIZE(intcp_io_desc));
 }
 
-static void __init intcp_init_irq(void)
-{
-	u32 pic_mask, cic_mask, sic_mask;
-
-	/* These masks are for the HW IRQ registers */
-	pic_mask = ~((~0u) << (11 - IRQ_PIC_START));
-	pic_mask |= (~((~0u) << (29 - 22))) << 22;
-	cic_mask = ~((~0u) << (1 + IRQ_CIC_END - IRQ_CIC_START));
-	sic_mask = ~((~0u) << (1 + IRQ_SIC_END - IRQ_SIC_START));
-
-	/*
-	 * Disable all interrupt sources
-	 */
-	writel(0xffffffff, INTCP_VA_PIC_BASE + IRQ_ENABLE_CLEAR);
-	writel(0xffffffff, INTCP_VA_PIC_BASE + FIQ_ENABLE_CLEAR);
-	writel(0xffffffff, INTCP_VA_CIC_BASE + IRQ_ENABLE_CLEAR);
-	writel(0xffffffff, INTCP_VA_CIC_BASE + FIQ_ENABLE_CLEAR);
-	writel(sic_mask, INTCP_VA_SIC_BASE + IRQ_ENABLE_CLEAR);
-	writel(sic_mask, INTCP_VA_SIC_BASE + FIQ_ENABLE_CLEAR);
-
-	fpga_irq_init(INTCP_VA_PIC_BASE, "PIC", IRQ_PIC_START,
-		      -1, pic_mask, NULL);
-
-	fpga_irq_init(INTCP_VA_CIC_BASE, "CIC", IRQ_CIC_START,
-		      -1, cic_mask, NULL);
-
-	fpga_irq_init(INTCP_VA_SIC_BASE, "SIC", IRQ_SIC_START,
-		      IRQ_CP_CPPLDINT, sic_mask, NULL);
-	integrator_clk_init(true);
-}
-
 /*
  * Flash handling.
  */
@@ -356,17 +323,114 @@  static void __init intcp_init_early(void)
 #endif
 }
 
-static void __init intcp_init(void)
+static void __init intcp_timer_init_of(void)
+{
+	struct device_node *node;
+	const char *path;
+	void __iomem *base;
+	int err;
+	int irq;
+
+	err = of_property_read_string(of_aliases,
+				"arm,integrator-clocksource", &path);
+	if (WARN_ON(err))
+		return;
+	node = of_find_node_by_path(path);
+	base = of_iomap(node, 0);
+	if (WARN_ON(!base))
+		return;
+	writel(0, base + TIMER_CTRL);
+	sp804_clocksource_init(base, node->name);
+
+	err = of_property_read_string(of_aliases,
+				"arm,integrator-clockevent", &path);
+	if (WARN_ON(err))
+		return;
+	node = of_find_node_by_path(path);
+	base = of_iomap(node, 0);
+	if (WARN_ON(!base))
+		return;
+	irq = irq_of_parse_and_map(node, 0);
+	writel(0, base + TIMER_CTRL);
+	sp804_clockevents_init(base, irq, node->name);
+}
+
+static struct sys_timer cp_of_timer = {
+	.init		= intcp_timer_init_of,
+};
+
+#ifdef CONFIG_OF
+
+static const struct of_device_id fpga_irq_of_match[] __initconst = {
+	{ .compatible = "arm,versatile-fpga-irq", .data = fpga_irq_of_init, },
+	{ /* Sentinel */ }
+};
+
+static void __init intcp_init_irq_of(void)
 {
-	int i;
+	of_irq_init(fpga_irq_of_match);
+	integrator_clk_init(true);
+}
 
-	platform_add_devices(intcp_devs, ARRAY_SIZE(intcp_devs));
+static const char * intcp_dt_board_compat[] = {
+	"arm,integrator-cp",
+	NULL,
+};
 
-	for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
-		struct amba_device *d = amba_devs[i];
-		amba_device_register(d, &iomem_resource);
-	}
-	integrator_init(true);
+DT_MACHINE_START(INTEGRATOR_CP_DT, "ARM Integrator/CP (Device Tree)")
+	.reserve	= integrator_reserve,
+	.map_io		= intcp_map_io,
+	.nr_irqs	= NR_IRQS_INTEGRATOR_CP,
+	.init_early	= intcp_init_early,
+	.init_irq	= intcp_init_irq_of,
+	.handle_irq	= fpga_handle_irq,
+	.timer		= &cp_of_timer,
+	.init_machine	= intcp_init,
+	.restart	= integrator_restart,
+	.dt_compat      = intcp_dt_board_compat,
+MACHINE_END
+
+#else
+
+/*
+ * This is where non-devicetree initialization code is collected and stashed
+ * for eventual deletion.
+ */
+
+#define INTCP_VA_CIC_BASE		__io_address(INTEGRATOR_HDR_BASE + 0x40)
+#define INTCP_VA_PIC_BASE		__io_address(INTEGRATOR_IC_BASE)
+#define INTCP_VA_SIC_BASE		__io_address(INTEGRATOR_CP_SIC_BASE)
+
+static void __init intcp_init_irq(void)
+{
+	u32 pic_mask, cic_mask, sic_mask;
+
+	/* These masks are for the HW IRQ registers */
+	pic_mask = ~((~0u) << (11 - IRQ_PIC_START));
+	pic_mask |= (~((~0u) << (29 - 22))) << 22;
+	cic_mask = ~((~0u) << (1 + IRQ_CIC_END - IRQ_CIC_START));
+	sic_mask = ~((~0u) << (1 + IRQ_SIC_END - IRQ_SIC_START));
+
+	/*
+	 * Disable all interrupt sources
+	 */
+	writel(0xffffffff, INTCP_VA_PIC_BASE + IRQ_ENABLE_CLEAR);
+	writel(0xffffffff, INTCP_VA_PIC_BASE + FIQ_ENABLE_CLEAR);
+	writel(0xffffffff, INTCP_VA_CIC_BASE + IRQ_ENABLE_CLEAR);
+	writel(0xffffffff, INTCP_VA_CIC_BASE + FIQ_ENABLE_CLEAR);
+	writel(sic_mask, INTCP_VA_SIC_BASE + IRQ_ENABLE_CLEAR);
+	writel(sic_mask, INTCP_VA_SIC_BASE + FIQ_ENABLE_CLEAR);
+
+	fpga_irq_init(INTCP_VA_PIC_BASE, "PIC", IRQ_PIC_START,
+		      -1, pic_mask, NULL);
+
+	fpga_irq_init(INTCP_VA_CIC_BASE, "CIC", IRQ_CIC_START,
+		      -1, cic_mask, NULL);
+
+	fpga_irq_init(INTCP_VA_SIC_BASE, "SIC", IRQ_SIC_START,
+		      IRQ_CP_CPPLDINT, sic_mask, NULL);
+
+	integrator_clk_init(true);
 }
 
 #define TIMER0_VA_BASE __io_address(INTEGRATOR_TIMER0_BASE)
@@ -400,3 +464,5 @@  MACHINE_START(CINTEGRATOR, "ARM-IntegratorCP")
 	.init_machine	= intcp_init,
 	.restart	= integrator_restart,
 MACHINE_END
+
+#endif