| 
 | 
 
#include <linux/module.h> 
#include <linux/kernel.h> 
#include <linux/init.h> 
#include <linux/fs.h> 
#include <linux/types.h> 
#include <linux/uaccess.h> 
#include <linux/cdev.h> 
#include <asm/io.h> 
#include <linux/device.h> 
static struct class *led_class; 
static unsigned long gpfbase; 
#define GPBCON (*(volatile unsigned long *)(gpfbase +0x0)) 
#define GPBDAT (*(volatile unsigned long *)(gpfbase +0x4)) 
#define GPBUP (*(volatile unsigned long *)(gpfbase +0x8)) 
 
static int tq2440_led_open(struct inode *inode, struct file *file) 
{ 
        printk("first dirver open call! \n"); 
        GPBCON= (GPBCON & ~(0xff<<10))|(0x55<<10); 
        GPBUP = (GPBUP & ~(0xf<<5))|(0xf<<5); 
        GPBDAT=0x0; 
        return 0; 
} 
 
 
static int tq2440_led_release(struct inode * inode, struct file * file) 
{ 
        printk("first dirver release call! \n"); 
        GPBDAT=0xf<<5; 
        return 0; 
} 
 
 
static char led_states = 0x0; 
static ssize_t tq2440_led_write(struct file *file, const char __user *userbuf,size_t bytes, loff_t *off) 
{ 
        char val; 
        copy_from_user(&val,userbuf,1); 
        printk("dirver write call%d\n",val); 
        GPBDAT = ~(val<<5); 
        led_states = val; 
        return sizeof(int); 
} 
 
 
static ssize_t tq2440_led_read(struct file *file, char __user *userbuf,size_t bytes, loff_t *off) 
{ 
        copy_to_user(userbuf, &led_states, sizeof(char)); 
        printk("first dirver read call! \n"); 
        return sizeof(char); 
} 
 
static struct file_operations fops = { 
        .owner = THIS_MODULE, 
        .open = tq2440_led_open, 
        .release = tq2440_led_release, 
        .write = tq2440_led_write, 
        .read = tq2440_led_read, 
}; 
 
static int major = 0; 
static struct cdev * tq2440_led_cdev; 
#define FIRST_DRV_NAME "led23" 
 
static int __init tq2440_led_init(void) 
{ 
        dev_t dev; 
        alloc_chrdev_region(&dev, 0, 1, FIRST_DRV_NAME); 
        major = MAJOR(dev); 
        tq2440_led_cdev = cdev_alloc(); 
        cdev_init(tq2440_led_cdev, &fops); 
        tq2440_led_cdev->owner = THIS_MODULE; 
        gpfbase = ioremap(0x56000010, 12); 
        if(gpfbase == NULL) 
        { 
                printk("ioremap error! \n"); 
                return - 1; 
        } 
        cdev_add(tq2440_led_cdev, dev, 1); 
        led_class = class_create(THIS_MODULE, "led23"); 
        device_create(led_class, NULL, dev, NULL, "led23"); 
        return 0; 
} 
 
static void __exit tq2440_led_exit(void) 
{ 
        dev_t dev; 
        dev = MKDEV(major,0); 
        cdev_del(tq2440_led_cdev); 
        unregister_chrdev_region(dev, 1); 
        iounmap(gpfbase); 
        device_destroy(led_class, dev); 
        class_destroy(led_class); 
} 
 
module_init(tq2440_led_init); 
module_exit(tq2440_led_exit); 
MODULE_LICENSE("GPL"); 
 
为什么led灯控制还是不正常,我用了虚拟映射,报了个warming,应用请问有什么问题,求指教 |   
 
 
 
 |