how to loop over multiple registers in linux device tree node?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



how to loop over multiple registers in linux device tree node?



I implemented a generic driver, in the driver I just want to go over each registered device and do something.

my driver is generic so I don't want to know anything in advance about the devices.



I have some device tree nodes:


uart0: uart@1000000
compatible = "generic-driver";
reg = <0x1000000 0x1000>,<0x1001000 0x1000>,<0x1002000 0x1000>;
;

uart1: uart@2000000
compatible = "generic-driver";
reg = <0x2000000 0x1000>,<0x2001000 0x1000>,<0x2002000 0x1000>;
;



in the driver I know how to get first offset and size with platform_get_resource, but what if I have multiple ranges?

I saw an option to get it by add reg-names:


reg = <0x2000000 0x1000>,<0x2001000 0x1000>,<0x2002000 0x1000>;
reg-names = "uart0_0","urat0_1","uart0_2";



so in the driver I can use platform_get_resource_byname, but there I need to know in the driver the regs names in advance - but it'll be no more generic - unwanted!!



so my question is, is there a way to loop over these regs without early information in the driver?



Thanks in advance!!





How you are supposed to write a “generic” stuff for different hardware?! You need to know what tho hardware is and what the resources driver is expecting.
– 0andriy
Aug 15 at 17:13





I want to implement a "generic" driver because of it fits my needs. I want ONE driver that will do same work for each registered device. I don't think you're right.
– Tirtsah Dreyfus
Aug 16 at 18:08






There’s no universal or the driver. You’re conceptually wrong.
– 0andriy
Aug 17 at 12:07




1 Answer
1



If you go through the definition for platform_get_resource you will find that the last parameter is the resource number. So, for the example you gave resource numbers will range from 0 to 2.


platform_get_resource



In case you don't know the number of resource then you can run an loop till you get a NULL as response to platform_get_resource.


NULL


platform_get_resource






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS