drivers/i2c/busses/i2c-s3c2410.c
static int __init i2c_adap_s3c_init(void) { return platform_driver_register(&s3c24xx_i2c_driver); } subsys_initcall(i2c_adap_s3c_init); static void __exit i2c_adap_s3c_exit(void) { platform_driver_unregister(&s3c24xx_i2c_driver); } module_exit(i2c_adap_s3c_exit);
i2c控制器属于soc的内部外设,所以这里使用平台总线来进行实现
platform_driver
static struct platform_driver s3c24xx_i2c_driver = { .probe = s3c24xx_i2c_probe, .remove = s3c24xx_i2c_remove, .id_table = s3c24xx_driver_ids, .driver = { .owner = THIS_MODULE, .name = "s3c-i2c", .pm = S3C24XX_DEV_PM_OPS, }, };
s3c24xx_driver_ids
static struct platform_device_id s3c24xx_driver_ids[] = { { .name = "s3c2410-i2c", .driver_data = TYPE_S3C2410, }, { .name = "s3c2440-i2c", .driver_data = TYPE_S3C2440, }, { }, };
这里的.name会在匹配阶段进行比较
platform_device
static struct platform_device *smdkc110_devices[] __initdata = { ... &s3c_device_i2c0, #ifdef CONFIG_S3C_DEV_I2C1 &s3c_device_i2c1, #endif #ifdef CONFIG_S3C_DEV_I2C2 &s3c_device_i2c2, #endif ... };
arch/arm/plat-samsung/dev-i2c0.c
struct platform_device s3c_device_i2c0 = { .name = "s3c2410-i2c", .id = 0, .num_resources = ARRAY_SIZE(s3c_i2c_resource), .resource = s3c_i2c_resource, };
arch/arm/plat-samsu