2017-03-08 9 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

あなたはデバイスツリーまたはOpen Firmwareのために意図されていないガイドを使用しています。作者はおそらく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

私は同様の問題がありました。プローブ機能も何も印刷できませんでした。私の場合の理由は:私のLinuxで私はデバイスにバインドされた準備ができたドライバを持っていた。このドライバをアンバインドすると、プローブ機能が正常に動作しました。

(アンバインドするために、注意:

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

関連する問題