12EXPORT_SYMBOL(of_device_get_match_data); 这个函数的返回值类型可强制转换成任何类型,取决于驱动程序中例化数据结构 of_device_id data。当然,由于 of_device_get_match_data 的函数返回值类型决定了不做强制类型转换,也不会有问题。 代码中增加下面的内容,来追踪 of_device_get_match_data 执行流程。 #定...
由of_device_id_match_data获取到不同的init_fn,按照不同的dev.of_node,执行return init_fn(np); 以上应用场景核心的数据结构是of_device_id,关键的处理函数是of_device_get_match_data(),当然,关于of_device_id的应用场景不仅仅限于上面说的这两种。 数据结构of_device_id 1 of_device_id数据结构如下,定...
mdesc = of_flat_dt_match_machine(mdesc_best, arch_get_next_mach); // 找到最匹配的machine_desc, drivers/of/ftd.c while ((data = get_next_compat(&compat))) { score = of_flat_dt_match(dt_root, compat); if (score > 0 && score < best_score) { best_data = data; best_score =...
matches: of_device_id 匹配表,也就是在此匹配表里面查找节点; match: 找到的匹配的 of_device_id; 成功返回找到的节点,失败时返回NULL。 二、获取父子设备节点API 2.1 of_get_parent of_find_node_by_path函数用于获取某一节点的父节点,函数原型: struct device_node *of_get_parent(const struct device_no...
structdevice_node *of_find_matching_node_and_match(structdevice_node *from,conststructof_device_id *matches,conststructof_device_id `match); 函数参数和返回值含义如下: from:开始查找的节点,如果为 NULL 表示从根节点开始查找整个设备树。 matches:of_device_id 匹配表,也就是在此匹配表里面查找节点。
match =device_get_match_data(&spi->dev);if(match) { status =match(&spi->dev);if(status)returnstatus; }/* Allocate driver data */spidev =kzalloc(sizeof(*spidev), GFP_KERNEL);/* 分配结构体 */if(!spidev)return-ENOMEM;/* Initialize the driver data */spidev->spi = spi;/* spide...
struct device_node *of_find_matching_node_and_match(struct device_node *from,const struct of_device_id *matches, const struct of_device_id **match) 函数参数和返回值含义如下: from:开始查找的节点,如果为 NULL 表示从根节点开始查找整个设备树。 matches: of_device_id 匹配表,也就是在此匹配表里面...
while((data = get_next_compat(&compat))) { score = of_flat_dt_match(dt_root, compat); if(score >0&& score < best_score) { best_data = data; best_score = score; } } machine_desc = mdesc; 第03节_对设备树中运行时配置信息的处理 ...
第6行,通过MODULE_DEVICE_TABLE声明一下leds_of_match这个设备匹配表。第11行,设置platform_driver中的of_match_table匹配表为上面创建的leds_of_match,至此我们就设置好了platform驱动的匹配表了。3、编写platform驱动 基于设备树的platform驱动和上一章无设备树的platform驱动基本一样,都是当驱动和设备匹配成功以后...
对于能够支持设备树的platform_driver,需要定义其of_match_table成员。 of_match_table为struct of_device_id数组。该数组必须以空项结尾。而struct of_device_id原型如下 struct of_device_id{char name[32];char type[32];char compatible[128];const void*data;}; ...