int (*probe)(…)指向platform驅動程序中的探測函數的指針。當platform核心有一個它認為驅動程序需要控制的struct platform_device時,就會調用該函數。所以我們會在這個函數中寫驅動程序的邏輯。 int (*remove)(…)指向一個移除函數的指針,當struct platform_device被從系統中移除,或者platform驅動程序正在從內核中卸載時,platform核心調用該函數。 為了把struct platform_driver注冊到platform核心中,需要調用以struct platform_driver為參數的platform_driver_register函數。通常在platform驅動程序的模塊化代碼中完成該工程。
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 "); } }