Device Tree, "ata-generic", any example? - Page 1
Forum section: electronics / general

author: legacy
author_rank: Super Contributor
timestamp: November 08, 2019, 11:41:58 am
content: Code:localbus@0xfe000000{#address-cells = <2>;#size-cells = <1>;compatible = "fsl,localbus","fsl,pq2-localbus","simple-bus";reg = <0x0xfe0001f0 0x100>;ranges = <0x0 0x0 0xfe000000 0x1000000x3 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 routersCode:0xfe0001f0, size=80xfe0003f4, size=10xfe000170, size=80xfe000374, size=10xfe000800, size=64Registers are physically mapped hereCode: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.

author: thinkfat
author_rank: Unknown
timestamp: November 08, 2019, 01:49:58 pm
content: 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#L25Explanation for the "ranges" property in "simple-bus" nodes:https://elinux.org/Device_Tree_Usage#Ranges_.28Address_Translation.29

author: legacy
author_rank: Super Contributor
timestamp: November 08, 2019, 01:54:24 pm
content: Quote from: thinkfat on November 08, 2019, 01:49:58 pmI know, but it's not clear

author: thinkfat
author_rank: Unknown
timestamp: November 08, 2019, 02:55:42 pm
content: Quote from: legacy on November 08, 2019, 01:54:24 pmI'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.

author: legacy
author_rank: Super Contributor
timestamp: November 08, 2019, 03:19:49 pm
content: are reg relative or absolute values?Code:external-bus{#address-cells = <2>;#size-cells = <1>;ranges = <0 0 0xfe000100 0x1000 // not yet defined2 0 0xfe000000 0x1000>; // Chipselect 2, PATA controllerpata@0,2{compatible = "ata-generic";/** reg #address-cells #size-cells*/reg = < 0x1f0 0x080x3f4 0x010x170 0x080x374 0x010x800 0x64 >;reg-shift = <0>; /* no offset */pio-mode = <0>;// interrupts = <0x19 0x8>;// interrupt-parent = <&PIC>;};};something like that?

author: thinkfat
author_rank: Unknown
timestamp: November 08, 2019, 09:26:20 pm
content: Quote from: legacy on November 08, 2019, 03:19:49 pmWell, 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:pata@0,2{compatible = "ata-generic";/** reg #address-cells #size-cells*/reg = <2 0x0 0x1f0 0x082 0x0 0x3f4 0x012 0x0 0x170 0x082 0x0 0x374 0x012 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.