Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7541364
  • 博文数量: 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:44:06

  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 device my_bus;
  9. extern struct bus_type my_bus_type;

  10. /* Why need this ?*/
  11. static void my_dev_release(struct device *dev)
  12. {
  13.     
  14. }

  15. struct device my_dev = {
  16.     .bus = &my_bus_type,
  17.     .parent = &my_bus,
  18.     .release = my_dev_release,
  19. };

  20. /*
  21.  * Export a simple attribute.
  22.  */
  23. static ssize_t mydev_show(struct device *dev, char *buf)
  24. {
  25.     return sprintf(buf, "%s\n", "This is my device!");
  26. }

  27. static DEVICE_ATTR(dev, S_IRUGO, mydev_show, NULL);

  28. static int __init my_device_init(void)
  29. {
  30.     int ret = 0;
  31.         
  32.         /* 初始化设备 */
  33.     strncpy(my_dev.bus_id, "my_dev", BUS_ID_SIZE);
  34.         
  35.         /*注册设备*/
  36.     device_register(&my_dev);
  37.         
  38.     /*创建属性文件*/
  39.     device_create_file(&my_dev, &dev_attr_dev);
  40.     
  41.     return ret;    

  42. }

  43. static void my_device_exit(void)
  44. {
  45.     device_unregister(&my_dev);
  46. }

  47. module_init(my_device_init);
  48. module_exit(my_device_exit);
阅读(2094) | 评论(0) | 转发(2) |
0

上一篇:bus_basic

下一篇:driver

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