88 beep_pin = res->start;
89
90
91 /* 注册字符设备驱动程序 */
92 major = register_chrdev(0,DEVICE_NAME,&beep_fops);
93 //创建类,然后再类下面创建设备节点
94 beep_class = class_create(THIS_MODULE,DEVICE_NAME);
95 device_create(beep_class,NULL,MKDEV(major,0),NULL,DEVICE_NAME);//dev/beep_dev
96
97 return 0;
98 }
99
100 static int beep_remove(struct platform_device *pdev){
101 printk('<0> beep_remove, remove beepnn');
102 //删除类
103 device_destroy(beep_class,MKDEV(major,0));
104 class_destroy(beep_class);
105 /* 卸载字符设备驱动程序 */
106 unregister_chrdev(major,DEVICE_NAME); /* iounmap */
107 //解除地址映射
108 iounmap((void __iomem *)base_iomux);
109 iounmap((void __iomem *)base_gpio1);
110 return 0;
111 }
112
113 //定义一个平台驱动结构体
114 struct platform_driver beep_drv = {
115 .probe = beep_probe,
116 .remove = beep_remove,
117 .driver = {
118 .name = DRIVER_NAME,
119 }
120 };
121
122
123 static int beep_drv_init(void){
124 platform_driver_register(&beep_drv);
125 return 0;
126 }
127
128 static void beep_drv_exit(void){
129 platform_driver_unregister(&beep_drv);
130 }
131
132 module_init(beep_drv_init);
133 module_exit(beep_drv_exit);
134
135 MODULE_AUTHOR('Lover雪儿');
136 MODULE_VERSION('0.1.0');
137 MODULE_LICENSE('GPL');
附 应用程序 beep_test.c 程序:
1 #include 2 #include 3 #include 4 #include 5 6 /* beep_test on 7 * beep_test off 8 */ 9 int main(int argc, char **argv) 10 { 11 int fd; 12 int i = 0; 13 int val = 1; 14 fd = open('/dev/beep_dev', O_RDWR); 15 if (fd < 0){ 16 printf('can't open!n'); 17 } 18 if (argc != 2){ 19 printf('Usage :n'); 20 printf('%s 21 return 0; 22 } 23 if (strcmp(argv[1], 'on') == 0){ 24 val = 1; 25 write(fd, &val, 4); 26 }else if (strcmp(argv[1], 'off') == 0){ 27 val = 0; 28 write(fd, &val, 4); 29 }else{ 30 i=5; 31 while(i--){ 32 val = 0; 33 write(fd, &val, 4); 34 val = 1; 35 write(fd, &val, 4); 36 } 37 val = 0; 38 write(fd, &val, 4); 39 } 40 return 0; 41 }
上一篇:构建Linux下IMX257 开发环境
下一篇:NorFlash驱动