| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/of.h>
- struct device_node *nd; /* 设备节点 */
- struct property *comppro;
- static int __init helloworld_init(void) {
- pr_info("Hello world initialization!\n");
- // 第一个参数设置为 NULL,从根节点开始查找
- nd = of_find_node_by_path("/my_backlight");
- if (nd == NULL) {
- printk("my_backlight node not found!\n");
- return -EINVAL;
- } else {
- printk("my_backlight node found!\n");
- }
- comppro = of_find_property(nd, "compatible", NULL);
- if(comppro == NULL){
- ret = -EINVAL;
- goto fail_finish;
- }else{
- printk("compatible=%s\r\n",(char *)comppro->value);
- }
- goto fail_finish:
- return ret;
- }
- static void __exit helloworld_exit(void) {
- pr_info("Hello world exit\n");
- }
- module_init(helloworld_init);
- module_exit(helloworld_exit);
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("John Madieu <john.madieu@gmail.com>");
- MODULE_DESCRIPTION("Linux kernel module skeleton");
|