Chinaunix首页 | 论坛 | 博客
  • 博客访问: 140052
  • 博文数量: 19
  • 博客积分: 501
  • 博客等级: 下士
  • 技术积分: 261
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-04 20:15
文章分类
文章存档

2015年(1)

2013年(1)

2012年(2)

2011年(15)

我的朋友

分类: LINUX

2011-03-28 13:36:06

#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");
阅读(1588) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~