I've got a linux kernel module and I'm trying to update the /sys entries for it. Searching around on google and other sources, I've seen lots of code along the lines of:
Code:
static dev_t MyDev;
static struct class *c1;
static int __init start_func(void) {
...
MyDev = MKDEV(nMajor, MINOR_VERSION);
register_chrdev_region(MyDev, 1, MODULE_NAME);
c1 = class_create(THIS_MODULE, "chardrv");
device_create(c1, NULL, MyDev, NULL, MODULE_NAME);
....
And I've verified this code works, and that it correctly creates a:
Code:
/sys/class/chardrv/<MODULE_NAME>
entry.
What I'd like to know is how do you create a device in an existing class.
For example lets say my device is now showing up in /sys/class/chardrv as per the above example, now I want a second kernel module to be able to populate its own devices also in the /sys/class/chardrv directory.
I can't call class_create() again, because that "chardrv" class already exists...
So I can run a check to see if /sys/class/chardrv exists, and this can help me decide if I need to call class_create() or not, that's not a problem. Lets put some pseudo code in here to clarify:
Code:
if ( path "/sys/class/chardrv" does not exist)
new_class = class_create("chardrv")
else
new_class = some how get class "chardrv" handle, or properties, or whatever device_create(new_class, ...)
So as per this example, if my class already exists, and I just want to add my new device into it I assume I need to create a class structure and somehow populate it with the correct "chardrv class" attributes then call device_create as before, but I'm not sure how to do that.
Any advice?