[U-Boot] [PATCH 0/3] dm: add dev_get_reg() for getting device node's reg

Stephen Warren
2015-12-16T19:07:55Z

On 12/16/2015 11:53 AM, Stephen Warren wrote:
> On 12/15/2015 09:32 AM, Przemyslaw Marczak wrote:
>> commit: dm: core: Enable optional use of fdt_translate_address()
>>
>> enables device's bus/child address translation method, depending
>> on bus 'ranges' property and including child 'reg' property.
>> This change makes impossible to decode the 'reg' for node with
>> '#size-cells' equal to 0.
>>
>> Such case is possible by the specification and is also used in U-Boot,
>> e.g. by I2C uclass or S5P GPIO - the last one is broken at present.
>
> Can you please explain the problem you're seeing in more detail? Without
> any context, my initial reaction is that this is simply a bug somewhere.
> That bug should be fixed, rather than introducing new APIs to hide the
> problem.

Ah, I guess the problem is caused by the following code in
__of_translate_address():

bus->count_cells(blob, parent, &na, &ns);
if (!OF_CHECK_COUNTS(na, ns)) {
printf("%s: Bad cell count for %s\n", __FUNCTION__,

That's because the function assumes it's called for MMIO addresses.
However, reg values for I2C devices aren't MMIO addresses, so those
assumptions don't apply. So, there is an argument for introducing some
new functionality. I'm not sure that a whole new function is the correct
way to go though. Rather, the existing translation functions should be
enhanced to know the location of root of the address space that contains
the address that's being translated. Then, translation can stop there.

Something like skipping the check on ns in the above code if parent ==
addr_space_root_offset, and also terminating the for (;;) loop in that
function under a similar condition.

This would allow for translation to occur for buses other than the CPU's
root MMIO space, yet not attempt to translate across known address space
boundaries (i.e. where address translation is known to be impossible).