2017-03-08 4 views
1

Linux 플랫폼 드라이버에 대해 배우려고합니다. 나는 다음 튜토리얼에서 드라이버를 촬영 한 :장치 드라이버가있는 장치 부착

http://linuxseekernel.blogspot.com/2014/05/platform-device-driver-practical.html

그것은 기본 플랫폼 드라이버입니다. 모듈을 컴파일하고로드했습니다. 그러나 잘로드 되더라도 프로브 기능은 실행되지 않습니다. 장치 ID와 드라이버 ID가 일치하는 한 많은 설명서가 있는데 검사 기능이 호출됩니다. 그럼 난 다음 드라이버가 :

#include <linux/module.h> 
#include <linux/kernel.h> 
//for platform drivers.... 
#include <linux/platform_device.h> 
#define DRIVER_NAME "twl12xx" 

MODULE_LICENSE("GPL"); 

/**************/ 
static int sample_drv_probe(struct platform_device *pdev){ 
    printk(KERN_ALERT "twl12xx: Probed\n"); 
    return 0; 
} 
static int sample_drv_remove(struct platform_device *pdev){ 
    printk(KERN_ALERT "twl12xx: Removing twl12xx\n"); 
    return 0; 
} 

static const struct platform_device_id twl12xx_id_table[] = { 
    { "twl12xx", 0}, 
    {} 
}; 
MODULE_DEVICE_TABLE(platform, twl12xx_id_table); 

static struct platform_driver sample_pldriver = { 
    .probe   = sample_drv_probe, 
    .remove   = sample_drv_remove, 
    .driver = { 
      .name = DRIVER_NAME, 
    }, 
}; 
/**************/ 

int ourinitmodule(void) 
{ 
    printk(KERN_ALERT "\n Welcome to twl12xx driver.... \n"); 

    /* Registering with Kernel */ 
    platform_driver_register(&sample_pldriver); 

    return 0; 
} 

void ourcleanupmodule(void) 
{ 
    printk(KERN_ALERT "\n Thanks....Exiting twl12xx driver... \n"); 

    /* Unregistering from Kernel */ 
    platform_driver_unregister(&sample_pldriver); 

    return; 
} 

module_init(ourinitmodule); 
module_exit(ourcleanupmodule); 

나는 또한 내 장치 트리에 다음 항목이 : 내 장치 트리를 정의하는 잘못 뭔가를 누락되었거나해야하고 같은 느낌

twl12xx: [email protected] { 
    compatible = "twl12xx"; 
}; 

합니다.

+0

; 저자는 아마도 x86 중심 일 것이다. 서면으로 작성된 드라이버가 DT 준비가되지 않았습니다. ** linux/of.h **를 포함하지 않으며 호환 가능한 문자열과 함께'struct of_device_id'를 갖지 않습니다. 예제로 사용할 커널에는 수많은 플랫폼 드라이버가 있습니다. 또한 http://stackoverflow.com/questions/26840267/driver-code-in-kernel-module-doesnt-execute/26855205#26855205 – sawdust

+0

[커널 모듈의 드라이버 코드가 실행되지 않습니다?] (http : //stackoverflow.com/questions/26840267/driver-code-in-kernel-module-doesnt-execute) – sawdust

+0

@sawdust, 더 이상 x86 중심의 코드는 없으며 필자는 DT 중심적이어야한다고 말합니다. 가이드가 오래된 것일 수 있습니다. 요즘에는 다른 기능과 통합 된 장치 속성을 통해 드라이버를 작성하는 사람이 누구인지를 무시할 수 있습니다. 따라서 아키텍처를 비난하지 말고 개발자에게 XYZ 중심 코드를 작성해야한다고 비난하지 마십시오. – 0andriy

답변

0

읽은 내용이 모두 정확합니다. 드라이버와 장치 ID가 일치해야합니다.

드라이버의 골격을 만들었으므로 장치 트리를 사용하고 있습니다. 그래서 괜찮아 보인다. 그러나 코드에 of_match_table 항목이 누락되었습니다. 장치 ID 일치 (장치 트리에서 전달한 문자열과 동일한 문자열) 및 드라이버 검색 호출에 매우 중요합니다.

그래서 아래 코드를 변경 추가 :

#ifdef CONFIG_OF 
static const struct of_device_id twl12xx_dt_ids[] = { 
.compatible = "ti,twl12xx", 
{} 
}; 
MODULE_DEVICE_TABLE(of, twl12xx_dt_ids); 
#endif 

static struct platform_driver sample_pldriver = { 
.probe   = sample_drv_probe, 
.remove   = sample_drv_remove, 
.driver = { 
     .name = DRIVER_NAME, 
     .of_match_table = of_match_ptr(twl12xx_dt_ids), 
}, 
.id_table = twl12xx_id_table, 
}; 
0

나는 비슷한 문제가 있었다. 프로브 기능도 아무것도 인쇄 할 수 없었습니다. 제 경우의 이유는 : 제 리눅스에서 나는 장치에 묶여있는 준비된 드라이버를 가지고있었습니다. 이 드라이버의 연결을 해제하면 Probe 기능이 성공적으로 작동했습니다.

(참고, 바인딩을 해제하려면 :

cd /sys/bus/platform/drivers/<driver_name> 
    echo "device_name" > unbind 

을) 당신은 장치 트리 또는 오픈 펌웨어위한 것이 아닙니다 가이드를 사용하는