- 论坛徽章:
- 0
|
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/cdev.h>
#include <asm/io.h>
#include <asm/system.h>
#include <asm/uaccess.h>
#define LED_MAJOR 111
#define LED_SIZE 0x1000
int led_major=LED_MAJOR;
struct led_dev{
struct cdev cdev;
unsigned char mem[LED_SIZE];
};
struct led_dev *led_devp;
int led_open(struct inode *inode,struct file *file)
{
printk("this is my first device driver program");
return 0;
}
int led_write(struct file *file,char __user *buf,size_t size ,loff_t *ppos)
{
printk("write something here");
return 0;
}
struct file_operations led_fops={
.owner=THIS_MODULE,
.open=led_open,
.write=led_write,
};
int led_setup_dev(struct led_dev *dev,int index)
{
dev_t devno=MKDEV(led_major,0);
cdev_init(&dev->cdev,&led_fops);
dev->cdev.owner=THIS_MODULE;
cdev_add(&dev->cdev,devno,1);
}
int led_init(void)
{
dev_t devno=MKDEV(led_major,0);
register_chrdev_region(devno,1,"led");
led_devp=kmalloc(sizeof(struct led_dev),GFP_KERNEL);
memset(led_devp,0,sizeof(struct led_dev));
led_setup_dev(led_devp,0);
}
int led_exit(void)
{
dev_t devno=MKDEV(led_major,0);
cdev_del(&led_devp->cdev);
kfree(led_devp);
unregister_chrdev_region(devno,1);
}
MODULE_LICENSE("Dual BSD/GPL");
module_init(led_init);
module_exit(led_exit);
为何不打印出 printk 的内容,也没有出错信息 |
|