- 論壇徽章:
- 0
|
我是個(gè)菜鳥(niǎo),最近在弄串口驅(qū)動(dòng),有兩問(wèn)題弄了好久都不明白,向各位請(qǐng)教,您看到請(qǐng)一定幫我理一下頭緒,這兩天都被這兩問(wèn)題弄挺不爽的,以下按調(diào)用順序貼上部分代碼:
問(wèn)題1,平臺(tái)設(shè)備注冊(cè)(將串口作為平臺(tái)設(shè)備向內(nèi)核注冊(cè)):
static int __init s3c2440_serial_init(void)
{
return s3c24xx_serial_init(&s3c2440_serial_drv, &s3c2440_uart_inf);
}
調(diào)用s3c24xx_serial_init:
int s3c24xx_serial_init(struct platform_driver *drv, struct s3c24xx_uart_info *info)
{
dbg("s3c24xx_serial_init(%p,%p)\n", drv, info);
#ifdef CONFIG_PM
drv->suspend = s3c24xx_serial_suspend;
drv->resume = s3c24xx_serial_resume;
#endif
return platform_driver_register(drv);
}
調(diào)用platform_driver_register:
int platform_driver_register(struct platform_driver *drv)
{
drv->driver.bus = &platform_bus_type;
if (drv->probe)
drv->driver.probe = platform_drv_probe;
if (drv->remove)
drv->driver.remove = platform_drv_remove;
if (drv->shutdown)
drv->driver.shutdown = platform_drv_shutdown;
if (drv->suspend)
drv->driver.suspend = platform_drv_suspend;
if (drv->resume)
drv->driver.resume = platform_drv_resume;
return driver_register(&drv->driver);
}
函數(shù)platform_drv_probe:
static int platform_drv_probe(struct device *_dev)
{
struct platform_driver *drv = to_platform_driver(_dev->driver);
struct platform_device *dev = to_platform_device(_dev);
return drv->probe(dev);
}
看不懂、不明白的地方:
語(yǔ)句drv->driver.probe = platform_drv_probe其作用應(yīng)該是給drv->driver.probe 賦值drv->probe(dev),那在函數(shù)platform_drv_probe里面
struct platform_driver *drv = to_platform_driver(_dev->driver);
struct platform_device *dev = to_platform_device(_dev);
這兩條語(yǔ)句是做什么用的?主要是看不懂to_platform_driver,to_platform_device這兩個(gè)宏的意思,更具體是看不懂container_of
#define to_platform_driver(drv) (container_of((drv), struct platform_driver, driver))
************************************************************************************************************
問(wèn)題2.這個(gè)問(wèn)題跟問(wèn)題1可能是有關(guān)聯(lián),也許1就是2的答案,敘述起來(lái)比較麻煩,我就按函數(shù)執(zhí)行的順序?qū)⒑瘮?shù)名貼上來(lái):
接問(wèn)題1當(dāng)內(nèi)核找到一個(gè)匹配的設(shè)備開(kāi)始調(diào)用static struct platform_drivers3c2440_serial_drv的成員.probe = s3c2440_serial_probe,執(zhí)行
static int s3c2440_serial_probe(struct platform_device *dev)---->s3c24xx_serial_probe(dev, &s3c2440_uart_inf)---->
ret = s3c24xx_serial_init_port(ourport, info, dev)
在函數(shù):static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
struct s3c24xx_uart_info *info,
struct platform_device *platdev) 里面有一條語(yǔ)句 cfg = s3c24xx_dev_to_cfg(&platdev->dev);
(cfg定義過(guò)了:struct s3c2410_uartcfg *cfg)
不懂的地方:
s3c24xx_dev_to_cfg也是個(gè)宏:
#define s3c24xx_dev_to_cfg(__dev) (struct s3c2410_uartcfg *)((__dev)->platform_data)
那么上面的語(yǔ)句cfg = s3c24xx_dev_to_cfg(&platdev->dev);其作用就是為cfg賦值platdev->dev.platform_data,問(wèn)題是這個(gè)platdev->dev.platform_data又沒(méi)有初始化過(guò),
(還是已經(jīng)初始化過(guò)了,我自己找不到地方?直覺(jué)這種可能性很大)它本身是個(gè)什么東西都不知道呢,那將它賦值給cfg還有什么意義呢 |
|