Author Topic: Device Tree, "ata-generic", any example?  (Read 1980 times)

0 Members and 1 Guest are viewing this topic.

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Device Tree, "ata-generic", any example?
« on: November 08, 2019, 11:41:58 am »
Code: [Select]
                localbus@0xfe000000
                {
                        #address-cells = <2>;
                        #size-cells = <1>;
                        compatible = "fsl,localbus","fsl,pq2-localbus","simple-bus";
                        reg    = <0x0xfe0001f0 0x100>;
                        ranges = <0x0 0x0 0xfe000000 0x100000
                                  0x3 0x0 0xe8000000 0x10000 >; /* the CF-PATA controller is mapped here */

                        pata@3,0 /* wrong code, here only as example */
                        {
                                 compatible = "ata-generic";
                                 reg = <0x3 0x0 0x10 0x4 0xC 0x2>; /* what is the meaning of this??? */
                                 reg-shift = <1>; /* what is the meaining of this??? */
                                 pio-mode = <0>;
                                 // interrupts = <0x19 0x8>;
                                 // interrupt-parent = <&PIC>;
                        };
                };

I have a PCI-PATA controller set into "legacy" mode, hence it works attached to a local bus and responds to a fixed addresses mapped in CPU RAM (beyond the first 2Gbyte, hence it doesn't conflict with the RAM).

The Linux Kernel has a SATA driver called OF_ATA, which uses the DeviceTree to initialize its internal strucutre. Unfortunately I cannot find any good doc about this, neither an example.

The above is it should look like. Anyone has ever implemented it?

It was/is usually used to map and handle a Compact Flash in embedded machines, typically routers  :-//


Code: [Select]
0xfe0001f0, size=8
0xfe0003f4, size=1
0xfe000170, size=8
0xfe000374, size=1
0xfe000800, size=64

Registers are physically mapped here

Code: [Select]
                                 reg = <0x3 0x0 0x10 0x4 0xC 0x2>; /* what is the meaning of this??? */

This line looks wrong (and for sure it is), it was found in a chunk of semi example found on the internet and it still needs to be analyzed, understood, and fixed.
 

Offline thinkfat

  • Supporter
  • ****
  • Posts: 2161
  • Country: de
  • This is just a hobby I spend too much time on.
    • Matthias' Hackerstübchen
Re: Device Tree, "ata-generic", any example?
« Reply #1 on: November 08, 2019, 01:49:58 pm »
That doesn't look like valid devicetree lingo. The "reg" property of the localbus node seems to be invalid for sure. The "reg" property in the pata node seems invalid, too.

Apart from that, this is the driver that handles "ata-generic". The probe function tells you which attributes it reads from the devicetree:

https://elixir.bootlin.com/linux/v4.20.17/source/drivers/ata/pata_of_platform.c#L25

Explanation for the "ranges" property in "simple-bus" nodes: https://elinux.org/Device_Tree_Usage#Ranges_.28Address_Translation.29
Everybody likes gadgets. Until they try to make them.
 
The following users thanked this post: legacy

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: Device Tree, "ata-generic", any example?
« Reply #2 on: November 08, 2019, 01:54:24 pm »
The probe function tells you which attributes it reads from the devicetree:

https://elixir.bootlin.com/linux/v4.20.17/source/drivers/ata/pata_of_platform.c#L25

I know, but it's not clear
 

Offline thinkfat

  • Supporter
  • ****
  • Posts: 2161
  • Country: de
  • This is just a hobby I spend too much time on.
    • Matthias' Hackerstübchen
Re: Device Tree, "ata-generic", any example?
« Reply #3 on: November 08, 2019, 02:55:42 pm »
The probe function tells you which attributes it reads from the devicetree:

https://elixir.bootlin.com/linux/v4.20.17/source/drivers/ata/pata_of_platform.c#L25

I know, but it's not clear

I'm not sure what you mean with that. The probe function says you need to declare two IO resources in the "reg" property and optionally an additional IRQ resource. You need to set "reg_shift" to the correct value, depending on the alignment of the controller registers and define which PIO mode you want to use. That's all.

The link I posted to the devicetree documentation explains how the content of the properties needs to look like.
Everybody likes gadgets. Until they try to make them.
 
The following users thanked this post: legacy

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: Device Tree, "ata-generic", any example?
« Reply #4 on: November 08, 2019, 03:19:49 pm »
are reg relative or absolute values?

Code: [Select]
        external-bus
        {
                #address-cells = <2>;
                #size-cells = <1>;
                ranges = <0 0  0xfe000100   0x1000 // not yet defined
                          2 0  0xfe000000   0x1000>; // Chipselect 2, PATA controller

                        pata@0,2
                        {
                                compatible = "ata-generic";
                                /*
                                 *  reg #address-cells #size-cells
                                 */
                                reg = < 0x1f0 0x08
                                        0x3f4 0x01
                                        0x170 0x08
                                        0x374 0x01
                                        0x800 0x64 >;
                                reg-shift = <0>; /* no offset */
                                pio-mode = <0>;
                                // interrupts = <0x19 0x8>;
                                // interrupt-parent = <&PIC>;
                        };
        };

something like that?
 

Offline thinkfat

  • Supporter
  • ****
  • Posts: 2161
  • Country: de
  • This is just a hobby I spend too much time on.
    • Matthias' Hackerstübchen
Re: Device Tree, "ata-generic", any example?
« Reply #5 on: November 08, 2019, 09:26:20 pm »
are reg relative or absolute values?

Code: [Select]
        external-bus
        {
                #address-cells = <2>;
                #size-cells = <1>;
                ranges = <0 0  0xfe000100   0x1000 // not yet defined
                          2 0  0xfe000000   0x1000>; // Chipselect 2, PATA controller

                        pata@0,2
                        {
                                compatible = "ata-generic";
                                /*
                                 *  reg #address-cells #size-cells
                                 */
                                reg = < 0x1f0 0x08
                                        0x3f4 0x01
                                        0x170 0x08
                                        0x374 0x01
                                        0x800 0x64 >;
                                reg-shift = <0>; /* no offset */
                                pio-mode = <0>;
                                // interrupts = <0x19 0x8>;
                                // interrupt-parent = <&PIC>;
                        };
        };

something like that?

Well, yes, not quite. First, "reg" are relative to the surrounding "ranges" property. Your pata@0,2 is correct with regards to this.

However:
"reg" must by bound to a specific range. You declare two ranges, one at index (cs) 0, one at index (cs) 2. You need to specify which range your device belongs to. Also, the format of a resource entry depends on the innermost #address-cells and #size-cells. In your case, 2 and 1. That means, reg should probably look like this:
Code: [Select]
                        pata@0,2
                        {
                                compatible = "ata-generic";
                                /*
                                 *  reg #address-cells #size-cells
                                 */
                                reg = <2 0x0 0x1f0 0x08
                                        2 0x0 0x3f4 0x01
                                        2 0x0 0x170 0x08
                                        2 0x0 0x374 0x01
                                        2 0x0 0x800 0x64 >;



Also, the probe function in the pata driver will only accept two IO resources and one interrupt resource. The interrupt seems to be optional, but if you look at the very first check in the probe function, if it doesn't find exactly two or three resource entries, it will bail out with an error immediately. If you want to declare two IDE ports, you need a separate device node for the second one.

Everybody likes gadgets. Until they try to make them.
 
The following users thanked this post: legacy


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf