免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 702 | 回复: 0
打印 上一主题 下一主题

platform [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-02-25 10:48 |只看该作者 |倒序浏览
  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. #include <linux/platform_device.h>

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

  9. static struct platform_device *my_device;

  10. static int __init my_device_init(void)
  11. {
  12.     int ret = 0;
  13.         
  14.         /* 分配结构 */
  15.     my_device = platform_device_alloc("my_dev", -1);
  16.         
  17.         /*注册设备*/
  18.     ret = platform_device_add(my_device);
  19.     
  20.     /*注册失败,释放相关内存*/
  21.     if (ret)
  22.      platform_device_put(my_device);
  23.     
  24.     return ret;    
  25. }

  26. static void my_device_exit(void)
  27. {
  28.     platform_device_unregister(my_device);
  29. }

  30. module_init(my_device_init);
  31. module_exit(my_device_exit);
  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. #include <linux/platform_device.h>

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

  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. static struct platform_driver my_driver = {
  20.     .probe        = my_probe,
  21.     .remove        = my_remove,
  22.     .driver        = {
  23.         .owner    = THIS_MODULE,
  24.         .name    = "my_dev",
  25.     },
  26. };

  27. static int __init my_driver_init(void)
  28. {
  29.         /*注册平台驱动*/
  30.     return platform_driver_register(&my_driver);
  31. }

  32. static void my_driver_exit(void)
  33. {
  34.     platform_driver_unregister(&my_driver);
  35. }

  36. module_init(my_driver_init);
  37. module_exit(my_driver_exit);
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP