dtsof.c 772 B

123456789101112131415161718192021222324252627282930
  1. #include <linux/module.h>
  2. #include <linux/init.h>
  3. #include <linux/of.h>
  4. struct device_node *nd; /* 设备节点 */
  5. static int __init helloworld_init(void) {
  6. pr_info("Hello world initialization!\n");
  7. // 第一个参数设置为 NULL,从根节点开始查找
  8. nd = of_find_node_by_name(NULL, "my_backlight");
  9. if (nd == NULL) {
  10. printk("my_backlight node not found!\n");
  11. return -EINVAL;
  12. } else {
  13. printk("my_backlight node found!\n");
  14. }
  15. return 0;
  16. }
  17. static void __exit helloworld_exit(void) {
  18. pr_info("Hello world exit\n");
  19. }
  20. module_init(helloworld_init);
  21. module_exit(helloworld_exit);
  22. MODULE_LICENSE("GPL");
  23. MODULE_AUTHOR("John Madieu <john.madieu@gmail.com>");
  24. MODULE_DESCRIPTION("Linux kernel module skeleton");