二、注册驱动程序
1.为驱动程序编写platform_driver结构体
struct platform_driver {
int (*probe)(struct platform_device *); //设备探测
int (*remove)(struct platform_device *); //设备移除
void (*shutdown)(struct platform_device *); //设备关闭
int (*suspend)(struct platform_device *, pm_message_t state); //设备暂停
int (*suspend_late)(struct platform_device *, pm_message_t state);
int (*resume_early)(struct platform_device *);
int (*resume)(struct platform_device *); //设备恢复
struct device_driver driver;
};
2.注册platform_driver结构体
int platform_driver_register(struct platform_driver *);
platform设备注册例子:
linux2.6.26.8内核中NAND FLASH设备驱动注册实例:
linux/drivers/mtd/nand/s3c2410.c:
static struct platform_driver s3c2410_nand_driver = {
.probe = s3c2410_nand_probe,
.remove = s3c2410_nand_remove,
.suspend = s3c24xx_nand_suspend,
.resume = s3c24xx_nand_resume,
.driver = {
.name = "s3c2410-nand",
.owner = THIS_MODULE,
},
};
static int __init s3c2410_nand_init(void)
{
printk("S3C24XX NAND Driver, (c) 2004 Simtec Electronics\n");
platform_driver_register(&s3c2412_nand_driver);
platform_driver_register(&s3c2440_nand_driver);
return platform_driver_register(&s3c2410_nand_driver); //注册设备驱动
}
module_init(s3c2410_nand_init);