#include
#include
#include
#define LIGHT_MAJOR 231
struct cdev *led_cdevp;
int led_open(struct inode * inode, struct file * filp) {
return 0;
}
int led_release(struct inode *inode, struct file * filp) {
return 0;
}
int led_ioctl(struct inode *inode, struct file * filp, unsigned int cmd, unsigned long arg) {
return 0;
}
static struct file_operations led_ops = { /* linux/fs.h */
.owner = THIS_MODULE,
.open = led_open,
.release = led_release,
.ioctl = led_ioctl,
};
static int __init mini2440_led_init(void)
{
int result;
dev_t dev = MKDEV(LIGHT_MAJOR, 0);
result = register_chrdev_region(dev, 1, "LED");
if(result < 0)
{
printk(KERN_INFO "device num is illegal!");
return result;
}
led_cdevp = kmalloc(sizeof(struct cdev), GFP_KERNEL);
memset( led_cdevp, 0,sizeof(struct cdev));
cdev_init( led_cdevp , &led_ops);
cdev_add( led_cdevp, dev, 1);
return 0;
}
static void __exit mini2440_led_exit(void)
{
cdev_del(led_cdevp);
kfree(led_cdevp);
unregister_chrdev_region(MKDEV(LIGHT_MAJOR, 0), 1);
}
module_init(mini2440_led_init);
module_exit(mini2440_led_exit);
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Zhousm");
阅读(1579) | 评论(0) | 转发(0) |