s3c_arch_init函数如下: /* arch/arm/mach-3sc2410/cpu.c */ static int __init s3c_arch_init(void) { int ret; …… /* 这里board指针指向在mach-smdk2410.c里的定义的smdk2410_board,里面包含了预先定义的I2C Platform_device等. */ if (board != NULL) { struct platform_device **ptr = board->devices; int i; for (i = 0; i board->devices_count; i++, ptr++) { ret = platform_device_register(*ptr); //在这里进行注册 if (ret) { printk(KERN_ERR "s3c24xx: failed to add board device %s (%d) @%p\n", (*ptr)->name, ret, *ptr); } } /* mask any error, we may not need all these board * devices */ ret = 0; } return ret; }
/* setup info block for the i2c core */ i2c->adap.algo_data = i2c; i2c->adap.dev.parent = &pdev->dev;
/* initialise the i2c controller */ ret = s3c24xx_i2c_init(i2c); if (ret != 0) goto out; /* find the IRQ for this unit (note, this relies on the init call to ensure no current IRQs pending */
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); /* 获取设备IRQ中断号 */ if (res == NULL) { dev_err(&pdev->dev, "cannot find IRQ\n"); ret = -ENOENT; goto out; }
ret = request_irq(res->start, s3c24xx_i2c_irq, IRQF_DISABLED, /* 申请IRQ */ pdev->name, i2c);
…… return ret;
}
小思考: 那什么情况可以使用platform driver机制编写驱动呢? 我的理解是只要和内核本身运行依赖性不大的外围设备(换句话说只要不在内核运行所需的一个最小系统之内的设备),相对独立的,拥有各自独自的资源(addresses and IRQs),都可以用platform_driver实现。如:lcd,usb,uart等,都可以用platfrom_driver写,而timer,irq等最小系统之内的设备则最好不用platfrom_driver机制,实际上内核实现也是这样的。