当前位置:网站首页>platform驱动平台下,关于probe函数中,形参dev的“dev->dev.of_node;”的理解
platform驱动平台下,关于probe函数中,形参dev的“dev->dev.of_node;”的理解
2022-07-28 10:32:00 【打蛋王子】
驱动函数里通过int platform_driver_register (struct platform_driver *driver)函数注册的驱动,
183 static int __init miscbeep_init(void)
184 {
185 return platform_driver_register(&beep_driver);
186 }
198 module_init(miscbeep_init);当platform总线检测到设备树有和该驱动匹配的设备节点后,就执行probe函数( int (*probe) (struct device *dev); ),此时probe函数的形参dev指针指向的变量是platform_device类型,platform_device结构体保存的是platform平台下的设备信息。
22 struct platform_device {
23 const char *name;
24 int id;
25 bool id_auto;
26 struct device dev;
27 u32 num_resources;
28 struct resource *resource;
29
30 const struct platform_device_id *id_entry;
31 char *driver_override; /* Driver name to force a match */
32
33 /* MFD cell pointer */
34 struct mfd_cell *mfd_cell;
35
36 /* arch specific additions */
37 struct pdev_archdata archdata;
38 };其 26行的“struct device dev” 成员(类似于C++的父类,platform_device继承了struct device )已经获取到了设备树中的节点信息,可以通过此成员获取节点信息,即“ miscbeep.nd = dev->dev.of_node;”
static int miscbeep_probe(struct platform_device *dev)
{
int ret = 0;
printk("beep driver and device was matched!\r\n");
/* 设置 BEEP 所使用的 GPIO */
/* 1、获取设备节点:beep */
//miscbeep.nd = of_find_node_by_path("/beep");
miscbeep.nd = dev->dev.of_node;//用这种方式替代上一行“miscbeep.nd = of_find_node_by_path("/beep");”的方式来获取设备节点device结构体:设备驱动模型中的基础结构体之一。结构体定义如下:
struct device {
/*设备所依附的父设备,大多数情况下,这样的设备是某种总线或主控制器,如果该成员变量的值为NULL,表示当前设备是一个最顶端设备,通常这样的设备都不是你想得到的那个*/
struct device *parent;
struct device_private *p;
struct kobject kobj;
const char *init_name; /* initial name of the device */
const struct device_type *type;
struct mutex mutex; /* mutex to synchronize calls to its driver.*/
struct bus_type *bus; /* type of bus device is on */
struct device_driver *driver; /* which driver has allocated this device */
void *platform_data; /* Platform specific data, device core doesn't touch it */
struct dev_pm_info power;
struct dev_pm_domain *pm_domain;
#ifdef CONFIG_NUMA
int numa_node; /* NUMA node this device is close to */
#endif
u64 *dma_mask; /* dma mask (if dma'able device) */
u64 coherent_dma_mask;/* Like dma_mask, but for alloc_coherent mappings as not all hardware supports
64 bit addresses for consistent allocations such descriptors. */
struct device_dma_parameters *dma_parms;
struct list_head dma_pools; /* dma pools (if dma'ble) */
struct dma_coherent_mem *dma_mem; /* internal for coherent mem override */
/* arch specific additions */
struct dev_archdata archdata;
struct device_node *of_node; /* associated device tree node */
dev_t devt; /* dev_t, creates the sysfs "dev" */
u32 id; /* device instance */
spinlock_t devres_lock;
struct list_head devres_head;
struct klist_node knode_class;
struct class *class;
const struct attribute_group **groups; /* optional groups */
void (*release)(struct device *dev);
};边栏推荐
- 适合中小企业的进销存软件,搞定5大难题
- Development environment configuration of nodemcu
- 1. Sum of two numbers
- Blue Bridge Cup embedded Hal library LCD
- OCR 知识 概括
- 3. MapReduce explanation and source code analysis
- Ten questions about low code: tell everything about low code!
- Andorid 开发三 (Intent)
- CTF skill tree - file upload
- Picture slide effect
猜你喜欢

Preliminary understanding of float

Batch Normlization

GKNoiseMap

Batch Normlization

Inventory: exciting data visualization chart

Sword finger offer 06. print linked list from end to end

Product side data analysis thinking

6. MapReduce custom partition implementation

PyQt5快速开发与实战 4.12 日历与时间

The 10th Landbridge cup embedded electronic provincial competition
随机推荐
andorid 开发
Samba server configuration
cortex-M4与cortex-A7内核启动流程分析
samba学习
6. MapReduce custom partition implementation
Samba learning
BOM部分属性及理解
GKCircleObstacle
蓝桥杯嵌入式-HAL库-USART_TX
STM32中的APB2和APB1
PyQt5快速开发与实战 4.11 拖曳与剪贴板
粒子群解决tsp的技术问题
MySQL Architecture Principle
Andorid 开发三 (Intent)
02.1.2. logic type bool
Aike AI frontier promotion (7.28)
CRM+零代码:轻松实现企业信息化
图片滑动特效
两年CRUD,二本毕业,备战两个月面试阿里,侥幸拿下offer定级P6
Learn how to do e-commerce data analysis (with operation analysis index framework)