- 論壇徽章:
- 0
|
Eric Fang 2010-01-22
--------------------------------------------------------------
本站分析linux內(nèi)核源碼,版本號(hào)為2.6.32.3
轉(zhuǎn)載請(qǐng)注明出處:
http://ericfang.cublog.cn/
--------------------------------------------------------------
接上一篇文章:
我們?cè)诜治鰌latform總線時(shí)已經(jīng)知道platform_driver_probe(&i8042_driver, i8042_probe)函數(shù)注冊(cè)驅(qū)動(dòng)并進(jìn)行一次設(shè)備的匹配,而以后注冊(cè)設(shè)備時(shí)時(shí)不會(huì)再匹配驅(qū)動(dòng)的,換句話說我們確信系統(tǒng)不會(huì)再添加同類型的設(shè)備,這里我們要看一下i8042_probe函數(shù)做了什么事。
static int __init i8042_probe(struct platform_device *dev)
{
int error;
error = i8042_controller_selftest();
if (error)
return error;
error = i8042_controller_init();
if (error)
return error;
#ifdef CONFIG_X86
if (i8042_dritek)
i8042_dritek_enable();
#endif
if (!i8042_noaux) {
error = i8042_setup_aux();
if (error && error != -ENODEV && error != -EBUSY)
goto out_fail;
}
if (!i8042_nokbd) {
error = i8042_setup_kbd();
if (error)
goto out_fail;
}
/*
* Ok, everything is ready, let's register all serio ports
*/
i8042_register_ports();
return 0;
out_fail:
i8042_free_aux_ports(); /* in case KBD failed but AUX not */
i8042_free_irqs();
i8042_controller_reset();
return error;
}
一眼掃過去一共調(diào)用了這幾個(gè)函數(shù):
i8042_controller_selftest();
i8042_controller_init();
i8042_dritek_enable();
i8042_setup_aux();
i8042_setup_kbd();
i8042_register_ports();
逐個(gè)進(jìn)行分析:
static int i8042_controller_selftest(void)
{
unsigned char param;
int i = 0;
if (!i8042_reset)
return 0;
在前面已經(jīng)知道了i8042_reset被設(shè)為1。
/*
* We try this 5 times; on some really fragile systems this does not
* take the first time...
*/
do {
if (i8042_command(¶m, I8042_CMD_CTL_TEST)) {
printk(KERN_ERR "i8042.c: i8042 controller self test timeout.\n");
return -ENODEV;
}
if (param == I8042_RET_CTL_TEST)
return 0;
printk(KERN_ERR "i8042.c: i8042 controller selftest failed. (%#x != %#x)\n",
param, I8042_RET_CTL_TEST);
msleep(50);
} while (i++
#ifdef CONFIG_X86
/*
* On x86, we don't fail entire i8042 initialization if controller
* reset fails in hopes that keyboard port will still be functional
* and user will still get a working keyboard. This is especially
* important on netbooks. On other arches we trust hardware more.
*/
printk(KERN_INFO
"i8042: giving up on controller selftest, continuing anyway...\n");
return 0;
#else
return -EIO;
#endif
}
該函數(shù)連續(xù)5次向i8042發(fā)送自檢命令,每次間隔50毫秒,如果每次i8042都反饋?zhàn)詼y(cè)通過信息就成功跳出。
我們來看一下這個(gè)發(fā)送命令的函數(shù):
int i8042_command(unsigned char *param, int command)
{
<
本文來自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u3/92745/showart_2157872.html |
|