diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-05-14 19:58:20 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-05-14 19:58:20 +0200 |
commit | 469db2b98acd9f016197c00f2fd88a9fcc66d75c (patch) | |
tree | 57f683cbad2a74e66c22a4ed1ccb788566a4cd71 /driver/main.c | |
parent | 5ce3f5c841eb64854af1c7fe47fac003ca31419a (diff) |
add device class
Diffstat (limited to 'driver/main.c')
-rw-r--r-- | driver/main.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/driver/main.c b/driver/main.c index 76ba1d8..8775727 100644 --- a/driver/main.c +++ b/driver/main.c @@ -21,14 +21,37 @@ struct platform_driver lork_driver = { } }; +struct class* class; + static int mod_init(void) { - printk("%s()\n", __PRETTY_FUNCTION__); - return platform_driver_register(&lork_driver); + int err; + + // create /sys/class/lork + class = class_create("lork"); + if (IS_ERR_OR_NULL(class)) { + err = PTR_ERR(class); + printk(KERN_ERR "class_create error %d\n", err); + goto free_class; + } + + // create platform driver + err = platform_driver_register(&lork_driver); + if (err) goto return_err; + + printk("%s() OK\n", __PRETTY_FUNCTION__); + return 0; + +free_class: + class_destroy(class); +return_err: + printk("%s() -> %d\n", __PRETTY_FUNCTION__, err); + return err; } static void mod_exit(void) { - printk("%s()\n", __PRETTY_FUNCTION__); platform_driver_unregister(&lork_driver); + class_destroy(class); + printk("%s()\n", __PRETTY_FUNCTION__); } module_init(mod_init); |