dtsof.c 1021 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <linux/module.h>
  2. #include <linux/init.h>
  3. #include <linux/of.h>
  4. struct device_node *nd; /* 设备节点 */
  5. struct property *comppro;
  6. static int __init helloworld_init(void) {
  7. pr_info("Hello world initialization!\n");
  8. // 第一个参数设置为 NULL,从根节点开始查找
  9. nd = of_find_node_by_path("/my_backlight");
  10. if (nd == NULL) {
  11. printk("my_backlight node not found!\n");
  12. return -EINVAL;
  13. } else {
  14. printk("my_backlight node found!\n");
  15. }
  16. comppro = of_find_property(nd, "compatible", NULL);
  17. if(comppro == NULL){
  18. ret = -EINVAL;
  19. goto fail_finish;
  20. }else{
  21. printk("compatible=%s\r\n",(char *)comppro->value);
  22. }
  23. goto fail_finish:
  24. return ret;
  25. }
  26. static void __exit helloworld_exit(void) {
  27. pr_info("Hello world exit\n");
  28. }
  29. module_init(helloworld_init);
  30. module_exit(helloworld_exit);
  31. MODULE_LICENSE("GPL");
  32. MODULE_AUTHOR("John Madieu <john.madieu@gmail.com>");
  33. MODULE_DESCRIPTION("Linux kernel module skeleton");