Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Apr 2019 12:19:47 +0200
From:      Manuel =?iso-8859-15?Q?St=FChn?= <freebsdnewbie@freenet.de>
To:        freebsd-hackers@freebsd.org
Subject:   Allocate resources from dts-node
Message-ID:  <20190413101947.GA5005@freebsd-t450.fritz.box>

next in thread | raw e-mail | index | archive | help

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@1c22c00 section of the sunxi-h3-h5.dtsi there is a xref to 
another node containing a needed register address and width:

codec: codec@1c22c00 {
   [..]
   reg = <0x01c22c00 0x400>;
   allwinner,codec-analog-controls = <&codec_analog>
   [..]
}

codec_analog: codec-analog@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@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





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20190413101947.GA5005>