led.c修改为:
1 #include <linux/init.h> 2 #include <linux/module.h> 3 #include <linux/miscdevice.h> 4 #include <linux/fs.h> 5 #include <linux/io.h> 6 7 8 #define GPMCON 0x7F008820 9 #define GPMDAT 0x7F008824 10 11 static int * __gp_gpmdat; 12 13 static int led_open (struct inode *p_inode, struct file *p_file) 14 { 15 int *p_gpmcon = NULL; 16 17 p_gpmcon = ioremap(GPMCON, 4); 18 writel(0x1111, p_gpmcon); 19 20 __gp_gpmdat = ioremap(GPMDAT, 4); 21 22 return 0; 23 } 24 25 static long led_ioctl (struct file *p_file, unsigned int cmd, unsigned long arg) 26 { 27 switch (cmd) { 28 case 0: 29 writel(0x0, __gp_gpmdat); 30 break; 31 32 case 1: 33 writel(0xF, __gp_gpmdat); 34 break; 35 36 default: 37 return -1; 38 } 39 return 0; 40 } 41 42 static struct file_operations fops = { 43 .owner = THIS_MODULE, 44 .open = led_open, 45 .unlocked_ioctl = led_ioctl, 46 }; 47 48 49 static struct miscdevice led_dev = { 50 .minor = MISC_DYNAMIC_MINOR, 51 .name = "myled", 52 .fops = &fops, 53 }; 54 55 static __init int led_init (void) 56 { 57 misc_register(&led_dev); 58 59 return 0; 60 } 61 62 static __exit void led_exit (void) 63 { 64 misc_deregister(&led_dev); 65 } 66 67 module_init(led_init); 68 module_exit(led_exit); 69 70 MODULE_LICENSE("GPL");
其他文件同上一章一样,但是使用led时只需要先insmod led.ko,不需要再创建设备节点便可以使用led_app控制led