-
Notifications
You must be signed in to change notification settings - Fork 540
/
Copy pathdevicemodel.c
103 lines (81 loc) · 2.16 KB
/
devicemodel.c
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* devicemodel.c
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/version.h>
struct devicemodel_data {
char *greeting;
int number;
};
static int devicemodel_probe(struct platform_device *dev)
{
struct devicemodel_data *pd =
(struct devicemodel_data *)(dev->dev.platform_data);
pr_info("devicemodel probe\n");
pr_info("devicemodel greeting: %s; %d\n", pd->greeting, pd->number);
/* Your device initialization code */
return 0;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0)
static int devicemodel_remove(struct platform_device *dev)
#else
static void devicemodel_remove(struct platform_device *dev)
#endif
{
pr_info("devicemodel example removed\n");
/* Your device removal code */
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0)
return 0;
#endif
}
static int devicemodel_suspend(struct device *dev)
{
pr_info("devicemodel example suspend\n");
/* Your device suspend code */
return 0;
}
static int devicemodel_resume(struct device *dev)
{
pr_info("devicemodel example resume\n");
/* Your device resume code */
return 0;
}
static const struct dev_pm_ops devicemodel_pm_ops = {
.suspend = devicemodel_suspend,
.resume = devicemodel_resume,
.poweroff = devicemodel_suspend,
.freeze = devicemodel_suspend,
.thaw = devicemodel_resume,
.restore = devicemodel_resume,
};
static struct platform_driver devicemodel_driver = {
.driver =
{
.name = "devicemodel_example",
.pm = &devicemodel_pm_ops,
},
.probe = devicemodel_probe,
.remove = devicemodel_remove,
};
static int __init devicemodel_init(void)
{
int ret;
pr_info("devicemodel init\n");
ret = platform_driver_register(&devicemodel_driver);
if (ret) {
pr_err("Unable to register driver\n");
return ret;
}
return 0;
}
static void __exit devicemodel_exit(void)
{
pr_info("devicemodel exit\n");
platform_driver_unregister(&devicemodel_driver);
}
module_init(devicemodel_init);
module_exit(devicemodel_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Linux Device Model example");