OK, so I had to wrongly described something because in my company this is popular approach to use /sys as some abstract layer to get access to registers.
So maybe in other words.
Let's say You have many socs. In one soc reset_reason can be gotten from devmem 0xfff.... In other soc reset_reason can be gotten through i2c read from some device.
Apart from reset_reason You have many other functionalities like kernel boot source (tftp, spi).
And let's assume you are tester. It is hard for those people to remember addresses, remembering and checking all the time how to read reset_reason or routing, then extract value from proper bits. Instead of raw addresses they have interface in /sys in the form of files. For example they read
cat /sys/resetreg/reason
as output they got in string format for example COLD_REBOOT.
They read:
/sys/bootreg/source
As output they got in string format TFTP.
And that is on each soc. This is good that registers, the way of access is hidden under interface. It is easier and faster to debug anything with such approach even for developers not only testers.
And there is separate kernel module which implements read/write access to each of directory in /sys. So we use here linux API:
kobj = kobject_create_and_add("bootreg", NULL);
sysfs_create_groups(kobj, ...)
So hope that You have now good understanding.
I cannot show the code as I don't if I am allowed. I am about half an year in kernel development team, so sometimes I have some doubts. And now my doubts are where to put API for read/write operations as I mentioned above.