分类: LINUX
2010-07-28 15:39:35
cpu: s3c2410;
board: mini2440;
网卡: dm9000;
static int __init mini2440_led_init(void)
{
……
err = platform_driver_register(&mini2440_led_driver);
……
}
static void __exit mini2440_led_exit(void)
{
platform_driver_unregister(&mini2440_led_driver);
}
module_init(mini2440_led_init);
module_exit(mini2440_led_exit);
上面的函数是用于注册平台driver的。
还要平台驱动所需要的platform_driver:
static struct platform_driver mini2440_led_driver = {
.probe = s3c24xx_led_probe,
.remove = s3c24xx_led_remove,
.driver = {
.name = "mini2440_led",
.owner = THIS_MODULE,
},
};
这样如果没有注册名为“mini2440_led”的平台设备,probe是不能够执行的。
static struct s3c24xx_led_platdata mini2440_pdata_led0 = {
.gpio = S3C2410_GPB5,
.flags = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
.name = "mini2440_led5",
.def_trigger = "mini2440_led",
};
static struct s3c24xx_led_platdata mini2440_pdata_led1 = {
.gpio = S3C2410_GPB6,
.flags = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
.name = "mini2440_led6",
.def_trigger = "mini2440_led",
};
static struct platform_device mini2440_led0 = {
.name = "mini2440_led",
.id = 0,
.dev = {
.platform_data = &mini2440_pdata_led0,
},
};
static struct platform_device mini2440_led1 = {
.name = "mini2440_led",
.id = 1,
.dev = {
.platform_data = &mini2440_pdata_led1,
},
};
static struct platform_device __initdata *mini2440_devs[] = {
&mini2440_led0,
&mini2440_led1,
};
由上面的struct可以看出将要注册两个led相关的平台设备mini2440_led,分别名为:mini2440_led5,mini2440_led6。
还需要把这两个设备注册到平台设备总线上:
使用函数:
platform_add_devices(mini2440_devs, ARRAY_SIZE(mini2440_devs));
由于有两个平台设备,所以平台驱动probe将会执行两次。
static int s3c24xx_led_probe(struct platform_device *dev);
static int s3c24xx_led_remove(struct platform_device *dev)