Allocate resources from dts-node
Manuel Stühn
freebsdnewbie at freenet.de
Sat Apr 13 10:22:16 UTC 2019
Hi,
during the process of preparing a NanoPI NEO2 port i found some bugs in
allwinners a10_codec implementation i'm now trying to fix. But i'm
struggeling with the resource management.
In the codec at 1c22c00 section of the sunxi-h3-h5.dtsi there is a xref to
another node containing a needed register address and width:
codec: codec at 1c22c00 {
[..]
reg = <0x01c22c00 0x400>;
allwinner,codec-analog-controls = <&codec_analog>
[..]
}
codec_analog: codec-analog at 1f015c0 {
compatible = "allwinner,sun8i-h3-codec-analog";
reg = <0x01f015c0 0x4>;
};
The driver kept crashing until i changed the dts file to something like
this:
codec: codec at 1c22c00 {
[..]
reg = <0x01c22c00 0x400 0x01f015c0 0x4>;
[..]
}
The driver wants to allocate both registers at once with
bus_alloc_resources() and a struct resource_spec describing two memory
sections and an interrupt section.
I'm failing in glueing the resource described by "reg" in codec_analog
into the a10_codec driver. The raw content I managed to retrieve
correctly by using these OF_* stuff in the drivers attach()-function:
[..]
phandle_t analognode, analogref;
OF_getencprop(node, "allwinner,codec-analog-controls",
&analogref, sizeof(analogref))
analognode = OF_node_from_xref(analogref);
pcell_t reg[2];
OF_getencprop(analognode, "reg", reg, sizeof(reg))
[..]
The contents of reg[2] are the correct values, but now i do not find how
to correctly make them available to the driver as resource:
int rid = 2;
struct resource *res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
reg[0], reg[0]+reg[1]-1, reg[1], RF_ACTIVE );
This does not return a valid resource pointer. Is this anyhow the
correct way to do?
Any help greatly appreciated :)
--
Manuel
More information about the freebsd-hackers
mailing list