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
| #include<linux/module.h> #include<linux/init.h> #include<asm/io.h>
volatile unsigned long virt,phys;
volatile unsigned long*GPBCON,*GPBDAT,*GPBUP; void led_device_init(void){ phys=0x56000010; virt=(unsigned long)ioremap(phys,0x10); } void led_device_init(void) { 器地址 phys=0x56000010 ; virt到virt+0x10 virt=(unsigned long)ioremap(phys,0x10); GPBCON=(unsigned long*)(virt+0x00); GPBDAT=(unsigned long*)(virt+0x04); GPBUP=(unsigned long*)(virt+0x08); }
void led_configure(void) { *GPBCON&=~(3<<10)&~(3<<12)&~(3<<16)&~(3<<20); }
void led_configure(void) { *GPBCON&=~(3<<10)&~(3<<12)&~(3<<16)&~(3<<20); *GPBCON|=(1<<10)|(1<<12)|(1<<16)|(1<<20); *GPBUP|=(1<<5)|(1<<6)|(1<<8)|(1<<10); }
void led_on(void) { *GPBDAT&=~(1<<5)&~(1<<6)&~(1<<8)&~(1<<10); }
void led_off(void) { *GPBDAT&=~(1<<5)&~(1<<6)&~(1<<8)&~(1<<10); }
void led_off(void) { *GPBDAT|=(1<<5)|(1<<6)|(1<<8)|(1<<10); }
static int __init led_init(void) { led_device_init(); led_configure(); led_on(); printk("hello ON!\n"); return 0 ; }
static void __exit led_exit(void) { led_on(); printk("hello ON!\n"); return 0 ; }
static void __exit led_exit(void) { led_off(); iounmap((void*)virt); printk("led OFF!\n"); } module_init(led_init); module_exit(led_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("hurryliu<>"); MODULE_VERSION(“2012-8-5.1.0”);
|