platform_driver_register2种方式学习
1.platform_device_register与platform_driver_register配合使用:
实例代码摘自下述网址:
这样当两个name一样时,就会嗲用mt65xx_leds_probe这个函数了。
static struct platform_driver mt65xx_leds_driver = { .driver = { .name = "leds-mt65xx", .owner = THIS_MODULE, }, .probe = mt65xx_leds_probe, .remove = mt65xx_leds_remove, }; static struct platform_device mt65xx_leds_device = { .name = "leds-mt65xx", .id = -1 }; static int __init mt65xx_leds_init(void) { platform_device_register(&mt65xx_leds_device); platform_driver_register(&mt65xx_leds_driver); }
2.platform_driver_register与dts配合使用,用compatable name,在c code里面配置compatible name,在dts中配置同样的name,就能probe了。
static const struct of_device_id mtkfb_of_ids[] = { {.compatible = "mediatek,mtkfb",}, {} }; static struct platform_driver mtkfb_driver = { .driver = { .name = MTKFB_DRIVER, .probe = mtkfb_probe, .of_match_table = mtkfb_of_ids, }, }; int __init mtkfb_init(void) { int r = 0; platform_driver_register(&mtkfb_driver); }
https://blog.csdn.net/qianjin2531/article/details/78109825
probe是否启动与硬件关系:
Vibr为啥会probe起来:只要platform_driver_register与platform_device_register的Name一样,就会probe,所以probe这个函数起起来,与硬件是否存在无关,硬件是否存在,可以在Probe中用一些摸硬件的方法,看其返回值来判断,比如i2c读取设备号是否有返回呀等等。