#include <linux/init.h>
#include <linux/module.h>
#include <asm/io.h>
#include <linux/ioport.h>
#define GPIO2_BASE 0xFF230000
#define GPIO2_MEM_SIZE 0x00010000
#define GPIO2_DIR (volatile unsigned long *)ioremap(GPIO2_BASE + 4, 4)
#define GPIO2_OUT (volatile unsigned long *)ioremap(GPIO2_BASE + 0, 4)
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
unsigned int res;
unsigned int set;
printk(KERN_INFO "Hello, world\n");
//request_mem_region(GPIO2_BASE, GPIO2_MEM_SIZE, "GPIO2_LED");
res = __raw_readl(GPIO2_DIR);
printk(KERN_INFO "Before set GPIO2_DIR value :%d\n", res);
res = __raw_readl(GPIO2_OUT);
printk(KERN_INFO "Before set GPIO2_OUT value :%d\n", res);
//GPIO2_B7 output
set = __raw_readl(GPIO2_DIR);
set |= ~(1 << 23);
set = 0; //全out
__raw_writel(set, GPIO2_DIR);
//GPIO2_D2 = 1
set = __raw_readl(GPIO2_OUT);
set |= (1 << 23);
set = 0xffffffff; //全高电平
__raw_writel(set, GPIO2_OUT);
res = __raw_readl(GPIO2_DIR);
printk(KERN_INFO "After set GPIO2_DIR value :%d\n", res);
res = __raw_readl(GPIO2_OUT);
printk(KERN_INFO "After set GPIO2_OUT value :%d\n", res);
//ERR:
return 0;
}
static void hello_exit(void)
{
printk(KERN_INFO "Goodbye, cruel world\n");
//release_mem_region(GPIO2_BASE, GPIO2_MEM_SIZE);
}
module_init(hello_init);
module_exit(hello_exit);
这样写有问题吗?(实际上灯没被点亮)