blob: 87757276930ca7c263ef98ef664f2d7abda5082d (
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
51
52
53
54
55
56
57
58
59
60
|
#include <linux/init.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include "platform.h"
static const struct of_device_id lork_ids[] = {
{ .compatible = "gpio-extern" },
{},
};
struct platform_driver lork_driver = {
.probe = lork_probe,
.remove = lork_remove,
.driver = {
.name = "gpio-extern",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(lork_ids),
}
};
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;
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) {
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");
|