Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7541191
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: 嵌入式

2011-02-25 10:46:14

  1. #include <linux/device.h>
  2. #include <linux/module.h>
  3. #include <linux/kernel.h>
  4. #include <linux/init.h>
  5. #include <linux/string.h>

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

  8. extern struct bus_type my_bus_type;

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

  14. static int my_remove(struct device *dev)
  15. {
  16.     printk("Driver found device unpluged!\n");
  17.     return 0;
  18. }

  19. struct device_driver my_driver = {
  20.     .name = "my_dev",
  21.     .bus = &my_bus_type,
  22.     .probe = my_probe,
  23.         .remove    = my_remove,
  24. };

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

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

  33. static int __init my_driver_init(void)
  34. {
  35.     int ret = 0;
  36.         
  37.         /*注册驱动*/
  38.     driver_register(&my_driver);
  39.         
  40.     /*创建属性文件*/
  41.     driver_create_file(&my_driver, &driver_attr_drv);
  42.     
  43.     return ret;    

  44. }

  45. static void my_driver_exit(void)
  46. {
  47.     driver_unregister(&my_driver);
  48. }

  49. module_init(my_driver_init);
  50. module_exit(my_driver_exit);
阅读(2060) | 评论(0) | 转发(4) |
0

上一篇:device

下一篇:platform

给主人留下些什么吧!~~