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
|
#include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/platform_device.h>
#define MODULE_NAME "hello_dev"
void hello_device_release(struct device *pdev) { printk("[INFO]hello_device_release is called!\n"); }
struct resource hello_device_res[] = { [0] = {.start = 0x1000, .end = 0x1003, .name = "reg1", .flags = IORESOURCE_MEM}, [1] = {.start = 0x2000, .end = 0x2003, .name = "reg2", .flags = IORESOURCE_MEM}, [2] = {.start = 10, .end = 10, .name = "irq1", .flags = IORESOURCE_IRQ}, [3] = {.start = 0x3000, .end = 0x3003, .name = "reg3", .flags = IORESOURCE_MEM}, [4] = {.start = 100, .end = 100, .name = "irq2", .flags = IORESOURCE_IRQ}, [5] = {.start = 62, .end = 62, .name = "irq3", .flags = IORESOURCE_IRQ}, };
struct platform_device_id hello_id = { .name = MODULE_NAME, };
struct platform_device hello_device = { .name = MODULE_NAME, .dev.release = hello_device_release, .resource = hello_device_res, .num_resources = ARRAY_SIZE(hello_device_res), .id_entry = &hello_id, };
int __init hello_device_init(void) { platform_device_register(&hello_device); printk("[INFO]This module [%s](device) is loaded!\n", MODULE_NAME); return 0; }
void __exit hello_device_exit(void) { platform_device_unregister(&hello_device); printk("[INFO]This module [%s](device) is exited!\n", MODULE_NAME); }
module_init(hello_device_init); module_exit(hello_device_exit);
MODULE_LICENSE("GPL"); MODULE_AUTHOR("qidaink"); MODULE_DESCRIPTION("Description"); MODULE_ALIAS("module's other name");
|