Device Driver's Probe Routine

本文详细解析了设备驱动中probe()函数的调用流程及参数来源,并以TCC UART设备驱动为例,阐述了从驱动注册到probe()函数被调用的具体过程。

This post tries to answer two questions:

  • Who calls device driver’s probe() routine, and when?
  • Where is probe() parameter from?

  • Who calls device driver’s probe() routine, and when?

The story started from where the driver was registed.

TCC UART device driver (drivers/serial/tcc_serial.c), For example, its entry point defined like below:

        static int __init tcc_seril_modinit(void)
        {
            ...
            platform_driver_register(drv);
            ...
        }

        module_init(tcc_serial_moinit);

The function call stack thereafter is:
1. XXX_driver_register(drv)
2. driver_register(&drv->driver);
3. bus_add_driver(drv);
4. driver_attach(drv);
5. bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
6. __driver_attach(struct device *dev, void *data);
7. driver_probe_device(drv, dev);
8. really_probe(dev, drv)
{

ret = drv->probe(dev);

}

Now it’s clear that the driver’s register function eventually called
driver’s probe() routine.

And, the “__init” symbol denotes this happened on kernel start up.


  • Where is probe() parameter from?
    The XXX_driver_register() passes a single parameter, drv. In case of TCC serial driver, its type is struct platform_driver.However, the driver’s probe() routine get a parameter dev, which type is struct platform_device.

Go through above functions call stack, we have noticed that from step 1 to step 4, the parameter is struct platform_driver; from step 6 to step 8, there is at least one struct platform_device parameter.
The step 5, however, references member struct bus_type of the driver.
The bus found(match) the driver’s partnership, the device, and passes struct device to __driver_attach.

NOTE:
Registing device MUST be prior to the driver’s registration.

The camera module init routine, for example:
int __init camera_core_init(void)
{
    platform_device_register(&camera_core_device);
    platform_driver_register(&camera_core_driver);
    return 0;
}

In the case of TCC serial device driver, the dev parameter of probe() is exact the data passed to platform_device_register().
In arch/arm/mach-tcc8900/devices.c

platform_device_register(&tcc8900_uart0_device); 

static struct resource uart0_resources[] = {
/* PA -> VA */
    [0] = {
        .start  = 0xF0532000,
        .end    = 0xF05320FF,
        .flags  = IORESOURCE_MEM,
    },
    [1] = {
        .start  = INT_UART0,
        .end    = INT_UART0,
        .flags  = IORESOURCE_IRQ,
    },
};

static struct platform_device tcc8900_uart0_device = {
    .name           = "tcc8900-uart",
    .id             = 0,
    .resource       = uart0_resources,
    .num_resources  = ARRAY_SIZE(uart0_resources),
};  
appyorangedog@happyorangedog-Legion-Y9000P-IAX10:~/桌面$ dmesg | grep -i -E 'nvidia|pci|02:00.0' | tail -n 50 [19757.401402] nvidia-nvlink: Nvlink Core is being initialized, major device number 508 [19757.402388] nvidia 0000:02:00.0: vgaarb: changed VGA decodes: olddecodes=none,decodes=none:owns=none [19757.402416] NVRM: The NVIDIA GPU 0000:02:00.0 (PCI ID: 10de:2d59) NVRM: NVIDIA 470.256.02 driver release. NVRM: Please see 'Appendix A - Supported NVIDIA GPU Products' NVRM: specific graphics driver download page at www.nvidia.com. [19757.402472] nvidia: probe of 0000:02:00.0 failed with error -1 [19757.402492] NVRM: The NVIDIA probe routine failed for 1 device(s). [19757.402493] NVRM: None of the NVIDIA devices were initialized. [19757.403351] nvidia-nvlink: Unregistered the Nvlink Core, major device number 508 [19757.683000] nvidia-nvlink: Nvlink Core is being initialized, major device number 508 [19757.684018] nvidia 0000:02:00.0: vgaarb: changed VGA decodes: olddecodes=none,decodes=none:owns=none [19757.684044] NVRM: The NVIDIA GPU 0000:02:00.0 (PCI ID: 10de:2d59) NVRM: NVIDIA 470.256.02 driver release. NVRM: Please see 'Appendix A - Supported NVIDIA GPU Products' NVRM: specific graphics driver download page at www.nvidia.com. [19757.684094] nvidia: probe of 0000:02:00.0 failed with error -1 [19757.684112] NVRM: The NVIDIA probe routine failed for 1 device(s). [19757.684113] NVRM: None of the NVIDIA devices were initialized. [19757.684375] nvidia-nvlink: Unregistered the Nvlink Core, major device number 508 [19758.122468] nvidia-nvlink: Nvlink Core is being initialized, major device number 508 [19758.123418] nvidia 0000:02:00.0: vgaarb: changed VGA decodes: olddecodes=none,decodes=none:owns=none [19758.123445] NVRM: The NVIDIA GPU 0000:02:00.0 (PCI ID: 10de:2d59) NVRM: NVIDIA 470.256.02 driver release. NVRM: Please see 'Appendix A - Supported NVIDIA GPU Products' NVRM: specific graphics driver download page at www.nvidia.com. [19758.123501] nvidia: probe of 0000:02:00.0 failed with error -1 [19758.123521] NVRM: The NVIDIA probe routine failed for 1 device(s). [19758.123521] NVRM: None of the NVIDIA devices were initialized. [19758.123921] nvidia-nvlink: Unregistered the Nvlink Core, major device number 508 [19758.416138] nvidia-nvlink: Nvlink Core is being initialized, major device number 508 [19758.417011] nvidia 0000:02:00.0: vgaarb: changed VGA decodes: olddecodes=none,decodes=none:owns=none [19758.417035] NVRM: The NVIDIA GPU 0000:02:00.0 (PCI ID: 10de:2d59) NVRM: NVIDIA 470.256.02 driver release. NVRM: Please see 'Appendix A - Supported NVIDIA GPU Products' NVRM: specific graphics driver download page at www.nvidia.com. [19758.417085] nvidia: probe of 0000:02:00.0 failed with error -1 [19758.417102] NVRM: The NVIDIA probe routine failed for 1 device(s). [19758.417103] NVRM: None of the NVIDIA devices were initialized. [19758.418271] nvidia-nvlink: Unregistered the Nvlink Core, major device number 508 [19758.664889] nvidia-nvlink: Nvlink Core is being initialized, major device number 508 [19758.665906] nvidia 0000:02:00.0: vgaarb: changed VGA decodes: olddecodes=none,decodes=none:owns=none [19758.665935] NVRM: The NVIDIA GPU 0000:02:00.0 (PCI ID: 10de:2d59) NVRM: NVIDIA 470.256.02 driver release. NVRM: Please see 'Appendix A - Supported NVIDIA GPU Products' NVRM: specific graphics driver download page at www.nvidia.com. [19758.666002] nvidia: probe of 0000:02:00.0 failed with error -1 [19758.666025] NVRM: The NVIDIA probe routine failed for 1 device(s). [19758.666026] NVRM: None of the NVIDIA devices were initialized. [19758.666742] nvidia-nvlink: Unregistered the Nvlink Core, major device number 508
07-22
基于51单片机,实现对直流电机的调速、测速以及正反转控制。项目包含完整的仿真文件、源程序、原理图和PCB设计文件,适合学习和实践51单片机在电机控制方面的应用。 功能特点 调速控制:通过按键调整PWM占空比,实现电机的速度调节。 测速功能:采用霍尔传感器非接触式测速,实时显示电机转速。 正反转控制:通过按键切换电机的正转和反转状态。 LCD显示:使用LCD1602液晶显示屏,显示当前的转速和PWM占空比。 硬件组成 主控制器:STC89C51/52单片机(与AT89S51/52、AT89C51/52通用)。 测速传感器:霍尔传感器,用于非接触式测速。 显示模块:LCD1602液晶显示屏,显示转速和占空比。 电机驱动:采用双H桥电路,控制电机的正反转和调速。 软件设计 编程语言:C语言。 开发环境:Keil uVision。 仿真工具:Proteus。 使用说明 液晶屏显示: 第一行显示电机转速(单位:转/分)。 第二行显示PWM占空比(0~100%)。 按键功能: 1键:加速键,短按占空比加1,长按连续加。 2键:减速键,短按占空比减1,长按连续减。 3键:反转切换键,按下后电机反转。 4键:正转切换键,按下后电机正转。 5键:开始暂停键,按一下开始,再按一下暂停。 注意事项 磁铁和霍尔元件的距离应保持在2mm左右,过近可能会在电机转动时碰到霍尔元件,过远则可能导致霍尔元件无法检测到磁铁。 资源文件 仿真文件:Proteus仿真文件,用于模拟电机控制系统的运行。 源程序:Keil uVision项目文件,包含完整的C语言源代码。 原理图:电路设计原理图,详细展示了各模块的连接方式。 PCB设计:PCB布局文件,可用于实际电路板的制作。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值