platform_device创建过程
发表于:2022-03-07 | 分类: Linux

[[toc]]

设备树解析与Platform_device创建过程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/ platform probe函数
static int led_probe(static platform_device *pdev)
{
led_gpio_init(pdev->dev.of_node);
printk("led_probe\n");
return 0;
}

// platform remove函数
static int led_remove(static platform_device *dev)
{
printk("led_remove\n");
return 0;
}
//匹配列表
static const sturct of_device_id led_of_match[] = {
{.compatible = "atk,led"},
{},
}
// platform驱动结构体

struct platform_device led_device
{
.driver = {
.name = "atkmp157_led",
.of_match_table = led_of_match,
},
.probe = led_probe, .remove = led_remove,
};

// platform驱动加载函数
static int __init leddriver_init(void)
{
return platform_deiver_register(&led_device);
}

// platform驱动卸载函数
static void __exit leddriver_exit(void)
{
platform_deiver_unregister(&led_device);
}

在platform_device的probe函数中有一个参数static platform_device *pdev关于这个参数的作用。

drivers\of\platform.c中,of_platform_bus_create()为节点及其子节点创建设备。会忽略几类node,比如没有compatible属性的。然后of_platform_device_create_pdata 函数来创建节点.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
* of_platform_bus_create() - 为节点及其子节点创建设备.
* @bus: device node of the bus to instantiate
* @matches: match table for bus nodes
* @lookup: auxdata table for matching id and platform_data with device nodes
* @parent: parent for new device, or NULL for top level.
* @strict: require compatible property
*
* Creates a platform_device for the provided device_node, and optionally
* recursively create devices for all the child nodes.
*/
static int of_platform_bus_create(struct device_node *bus,
const struct of_device_id *matches,
const struct of_dev_auxdata *lookup,
struct device *parent, bool strict)
{
上一篇:
linux驱动GPIO的使用
下一篇:
from_time()