註冊裝置的兩種方式:
方法一:
一:對於平台裝置可以直接在板檔案中添加代碼(arch / arm / mach-s3cxxxx / mach-smdk2440.c)
代碼 1: static struct platfrom_device hello_device = {
.name = "hello ",
.id = -1,
.resource = hello_resource,
...................
.......................
}; 添加裝置結構體
代碼2:繼續添加裝置資源(arch / arm / mach-s3cxxxx / mach-smdk2440.c)
static struct resource hello_resource[] = {
[0] = { //IO連接埠資源
.start = S3C24XX_PA_WATCHDOG,
.end = S3C24XX_PA_WATCHDOG + S3C24XX_SZ_WATCHDOG - 1,
.flags = IORESOURCE_MEM,
},
[1] = { //中斷資源
.start = IRQ_WDT, .end = IRQ_WDT,
.flags = IORESOURCE_IRQ,
}
};
3:繼續把裝置加入到裝置數組中去arch / arm / mach-s3cxxxx / mach-smdk2440.c
static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&hello_device,
};
之後系統在載入該驅動的時候會自動的調用platform_add_devices把裝置註冊到系統中去,該函數內部會調用platfrom_device_register().裝置註冊完閉
方法二:
直接定義即可:1。定義裝置結構體
static struct platfrom_device hello_device = {
.name = "hello ",
.id = -1,
.resource = hello_resource,
...................
.......................
};
2。定義裝置資源
static struct resource hello_resource[] = {
[0] = { //IO連接埠資源
.start = S3C24XX_PA_WATCHDOG,
.end = S3C24XX_PA_WATCHDOG + S3C24XX_SZ_WATCHDOG - 1,
.flags = IORESOURCE_MEM,
},
3。註冊裝置 platfrom_device_register().
static int __init hello_init(void)
{
printk(banner);
return platform_device_register(&hello_device);
}
static void __exit hello_exit(void)
{
platform_device_unregister(&hello_device );
}
module_init(hello_init);
module_exit(hello_exit);