UIO + ADC example.

*On 7 November 2015 at 02:53, William Hermans <yyrkoon@gmail.com
<yyrkoon@gmail.com>> wrote:*

*OK, thanks. That uio guide I've already run into, and I was afraid you

were going to link to that . . . heh. Beaglebone register address I did
not need help with, but understanding how to interface the uio adc "driver"
once running.*

*One problem I'm seeing thus far, is the ADC clock needs to be enabled
etc. Which is in a completely different memory location . . . but my
imagination is not that limited, so would not slow me down too much . . .*
*Happens automagically when you open /dev/uio/adc (and the kernel will
disable the clock again when you close it).*

*The reason for that is that my DTS fragment reuses the existing DT node
for the ADC. A standalone definition would be:*

*tscadc@44e0d000 {
  reg = <0x44e0d000 0x1000>;
  interrupt-parent = <&intc>;
  interrupts = <16>;
  ti,hwmods = "adc_tsc";
  compatible = "uio";
  uio-alias = "adc";
};*

*The magic clock enabling part is due to "ti,hwmods", which associates the
node with platform data still hardcoded into the kernel. I'm not entirely
sure how the mechanism works exactly, and my understanding is that it's
destined to become deprecated eventually ("replaced by genpd along the
lines of simple-pm-bus"). I don't know how things will look after that.*

*(the two child nodes declared in the main DT are ignored by uio and
harmless)*

Matthijs

*PS although your reply was by direct email I'm sending this to the list

again since, although off-topic, I think it may still be of interest to
other readers.*

Matthijs,

So doing some digging, am33xxx.dtsi has this fragment:
tscadc: tscadc@44e0d000 {
            compatible = "ti,am3359-tscadc";
            reg = <0x44e0d000 0x1000>;
            interrupt-parent = <&intc>;
            interrupts = <16>;
            ti,hwmods = "adc_tsc";
            status = "disabled";

            tsc {
                compatible = "ti,am3359-tsc";
            };
            am335x_adc: adc {
                #io-channel-cells = <1>;
                compatible = "ti,am3359-adc";
            };
        };

So I am thinking the code snippet for the /dev/uio/adc would not work
without modifying that file to reflect those changes. Am I wrong ?
Everything, well most everything looks the same except for the compatible
field, status field is disabled instead of "ok", and you have an additional
field for a uio alias I suppose.

You had mentioned you do not use overlays. How do you enable all this then
? Perhaps I'd learn more from that.

Additionally I’m curious if this could somehow be modified to make the changes for the uio adc deceive. I do not understand device tree files all that well. Well, more correctly I get the addresses, etc for the various hardware modules, but I do not understand a lot of the device tree specific keywords( I guess they are ). So as an example fragment@0{…} All inside that set of brackets I do not “get”. Although I do understand the adc-channels<. . .> part well enough I suppose. That just enabling channels 0-6, and channel 8(0x7) is setup as a touchscreen channel.

fixups {
tscadc = “/fragment@0:target:0”;
};


NO idea what this does . . . Anyway, below is just the basic BBB-ADC overlay provided from the bb.org-overlay git. Atleast, I do not think I’ve modified it any . . .

`
/dts-v1/;

/ {
compatible = “ti,beaglebone”, “ti,beaglebone-black”, “ti,beaglebone-green”;
part-number = “BB-ADC”;
version = “00A0”;
exclusive-use = “P9.31”, “P9.40”, “P9.37”, “P9.38”, “P9.33”, “P9.36”, “P9.35”, “tscadc”;

fragment@0 {
target = <0xdeadbeef>;

overlay {
status = “okay”;

adc {
ti,adc-channels = <0x0 0x1 0x2 0x3 0x4 0x5 0x6>;
};
};
};

fixups {
tscadc = “/fragment@0:target:0”;
};
};
`

Ok, I got something working, partly by luck, and partly by intuition. I still do not know what the hell I’m doing with device tree files . . . but everything makes sense.

`
/dts-v1/;
/plugin/;

/ {
compatible = “ti,beaglebone”, “ti,beaglebone-black”;

/* identification */
part-number = “WH-ADC”;
version = “00A0”;

fragment@0 {
target = <&tscadc>;
overlay {
compatible = “uio”;
uio-alias = “adc”;
status = “okay”;
};
};
};
`

`
$ dtc -O dtb -o WH-ADC-00A0.dtbo -b 0 -@ WH-ADC-00A0.dts
$ sudo cp WH-ADC-00A0.dtbo /lib/firmware/
$ sudo sh -c “echo ‘WH-ADC’ > /sys/devices/platform/bone_capemgr/slots”

$ dmesg | grep WH-ADC
[ 1290.096328] bone_capemgr bone_capemgr: part_number ‘WH-ADC’, version ‘N/A’
[ 1290.116039] bone_capemgr bone_capemgr: slot #5: ‘Override Board Name,00A0,Override Manuf,WH-ADC’
[ 1290.137733] bone_capemgr bone_capemgr: slot #5: dtbo ‘WH-ADC-00A0.dtbo’ loaded; overlay id #0

$ ls /dev/uio
adc

$ ./lsuio
uio0: name=tscadc, version=devicetree, events=0
map[0]: addr=0x44E0D000, size=4096
`


fixups {


tscadc = “/fragment@0:target:0”;


};


*``*NO idea what this does . . . Anyway, below is just the basic BBB-ADC overlay provided from the bb.org-overlay git. Atleast, I do not think I’ve modified it any . . .

Now, I know what the above “code” is doing. Pretty obvious, now that I do not have everything related on my mind :wink: