搜尋此網誌

Kernel 2.6 platform device add method.

  1.device_initcall
static struct platform_device bl23xx_dying_gasp_device = {

.name = BL_2348_DGASP_DEV_NAME,
.id = 0,
.num_resources = ARRAY_SIZE(bl2348_dying_gasp_resources),
.resource = bl2348_dying_gasp_resources,
};

static struct platform_device bl23xx_led_device = {
.name = BL_2348_LED_DEV_NAME,
.id = -1,
.num_resources = 0,
.resource = NULL ,
};static struct platform_device *bl2348_devices[] __initdata = {

&bl23xx_led_device,
&bl23xx_dying_gasp_device,
};
void bl2348_add_platform_device(void){
int ret;
ret =platform_add_devices(bl2348_devices, ARRAY_SIZE(bl2348_devices));
#ifdef PLATFORM_DEVICE_DEBUG
if(!ret)
printk(KERN_ALERT "========> bl2348 Platform device add success\n");
else
printk(KERN_ALERT "========> bl2348 Platform device add fail\n");
#endif
}

device_initcall(bl2348_add_platform_device);/*Jacky.Xue : extra device resource required */

2. kernel API : platform_device_register_simple
EXAMPLE:
led2348pdev = platform_device_register_simple(BL_2348_LED_DEV_NAME, -1, NULL, 0);

if (IS_ERR(led2348pdev)) {
ret = PTR_ERR(led2348pdev);
platform_driver_unregister(&bl2348_led_driver);
goto out;