int (*probe)(…)指向platform驅(qū)動程序中的探測函數(shù)的指針。當(dāng)platform核心有一個它認(rèn)為驅(qū)動程序需要控制的struct platform_device時,就會調(diào)用該函數(shù)。所以我們會在這個函數(shù)中寫驅(qū)動程序的邏輯。 int (*remove)(…)指向一個移除函數(shù)的指針,當(dāng)struct platform_device被從系統(tǒng)中移除,或者platform驅(qū)動程序正在從內(nèi)核中卸載時,platform核心調(diào)用該函數(shù)。 為了把struct platform_driver注冊到platform核心中,需要調(diào)用以struct platform_driver為參數(shù)的platform_driver_register函數(shù)。通常在platform驅(qū)動程序的模塊化代碼中完成該工程。
int main(int argc, char **argv) { int fd; int val; fd = open("/dev/sr501", O_RDWR); if (fd == -1) { printf("can not open file %s ", argv[1]); return -1; }
while (1) { read(fd, &val, 4); if (val == 0x1) { printf("detect people "); } }