Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1480787
  • 博文数量: 108
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 997
  • 用 户 组: 普通用户
  • 注册时间: 2013-06-29 09:58
个人简介

兴趣是坚持一件事永不衰竭的动力

文章分类

全部博文(108)

文章存档

2021年(1)

2020年(10)

2019年(19)

2018年(9)

2016年(23)

2015年(43)

2013年(3)

我的朋友

分类: 嵌入式

2015-07-06 00:09:59

#include <linux/device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/string.h>


MODULE_AUTHOR("David Xie");
MODULE_LICENSE("Dual BSD/GPL");


extern struct bus_type my_bus_type;


static int my_probe(struct device *dev)
{
    printk("Driver found device which my driver can handle!\n");
    return 0;
}


static int my_remove(struct device *dev)
{
    printk("Driver found device unpluged!\n");
    return 0;
}


struct device_driver my_driver = {
.name = "my_dev",
.bus = &my_bus_type,
.probe = my_probe,
    .remove = my_remove,
};


/*
 * Export a simple attribute.
 */
static ssize_t mydriver_show(struct device_driver *driver, char *buf)
{
return sprintf(buf, "%s\n", "This is my driver!");
}


static DRIVER_ATTR(drv, S_IRUGO, mydriver_show, NULL);


static int __init my_driver_init(void)
{
int ret = 0;
    printk("[call my_driver_init]\n");      
        /*注册驱动*/
driver_register(&my_driver);

/*创建属性文件*/
driver_create_file(&my_driver, &driver_attr_drv);

return ret;


}


static void my_driver_exit(void)
{
printk("[call my_driver_exit]\n");
driver_unregister(&my_driver);
}


module_init(my_driver_init);
module_exit(my_driver_exit);
阅读(1727) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~