下面开始分析 linux/drivers/i2c/busses/i2c-s3c2410.c,在设备与驱动匹配成功后,会执行
s3c24xx_i2c_probe()函数,其源码如下:
/* s3c24xx_i2c_probe called by the bus driver when a suitable device is found*/
static int s3c24xx_i2c_probe(struct platform_device *pdev)
{
struct s3c24xx_i2c *i2c;
struct s3c2410_platform_i2c *pdata;
struct resource *res;
int ret;
/*这里 pdev->dev.platform_data 在 s3c_i2c0_set_platdata()函数中设置,指向了系统初始化
时的设置过的 s3c2410_platform_i2c 结构体*/
pdata = pdev->dev.platform_data;
if (!pdata) {
dev_err(&pdev->dev, "no platform data");
return -EINVAL;
}
/*申请一段 sizeof(struct s3c24xx_i2c)的内存,并清 0 */
i2c = kzalloc(sizeof(struct s3c24xx_i2c), GFP_KERNEL);
if (!i2c) {
dev_err(&pdev->dev, "no memory for state");
return -ENOMEM;
}
strlcpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name));