blob: 2676c9a8acf5509f1b63af68d27a4754c54ce57a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include <linux/init.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include "main.h"
#include "platform.h"
struct class* class;
static int mod_init(void) {
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;
// create attribute under /sys/bus/platform/drivers/gpio-extern
err = driver_create_file(&lork_driver.driver, &attr);
if (err) goto return_err;
printk("%s() OK\n", __PRETTY_FUNCTION__);
return 0;
return_err:
free_class:
class_destroy(class);
printk("%s() -> %d\n", __PRETTY_FUNCTION__, err);
return err;
}
static void mod_exit(void) {
driver_remove_file(&lork_driver.driver, &attr);
platform_driver_unregister(&lork_driver);
class_destroy(class);
printk("%s()\n", __PRETTY_FUNCTION__);
}
module_init(mod_init);
module_exit(mod_exit);
MODULE_LICENSE("Dual MIT/GPL");
|