dtsof.c 974 B

12345678910111213141516171819202122232425262728293031323334353637
  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. return -EINVAL;
  19. }else{
  20. printk("compatible=%s\r\n",(char *)comppro->value);
  21. }
  22. return 0;
  23. }
  24. static void __exit helloworld_exit(void) {
  25. pr_info("Hello world exit\n");
  26. }
  27. module_init(helloworld_init);
  28. module_exit(helloworld_exit);
  29. MODULE_LICENSE("GPL");
  30. MODULE_AUTHOR("John Madieu <john.madieu@gmail.com>");
  31. MODULE_DESCRIPTION("Linux kernel module skeleton");