aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-05-14 19:58:20 +0200
committerlonkaars <loek@pipeframe.xyz>2024-05-14 19:58:20 +0200
commit469db2b98acd9f016197c00f2fd88a9fcc66d75c (patch)
tree57f683cbad2a74e66c22a4ed1ccb788566a4cd71
parent5ce3f5c841eb64854af1c7fe47fac003ca31419a (diff)
add device class
-rw-r--r--driver/main.c29
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);