Linux IIC subsystem analysis (5) - I2C plaform device initialization


The platform mechanism is not complicated, but it is difficult to understand. It consists of platform device and platform driver.

I2C platform device initialization is performed in the mach-smdk2440.c file

 /arch/arm/mach-s3c2440/mach-smdk2440.c

static void __init smdk2440_machine_init(void)
{
	s3c24xx_fb_set_platdata(&smdk2440_fb_info);
	s3c_i2c0_set_platdata(NULL);                                          (1.0)
	platform_add_devices(smdk2440_devices, ARRAY_SIZE(smdk2440_devices)); (2.0)
	smdk_machine_init();
}

(1.0) Build the device information s3c_device_i2c0 of the platform device, which stores the default information of the I2C adapter in the kernel. See the code below for details:

 arch/arm/plat-s3c/dev-i2c0.c

static struct resource s3c_i2c_resource[] = {
	[0] = {
		.start = S3C_PA_IIC, (1.1)
		.end = S3C_PA_IIC + SZ_4K - 1, (1.2)
		.flags = IORESOURCE_MEM,                  
	},
	[1] = {
		.start = IRQ_IIC,
		.end   = IRQ_IIC,
		.flags = IORESOURCE_IRQ,
	},
};

struct platform_device s3c_device_i2c0 = {
	.name		  = "s3c2410-i2c",                 (1.3)
#ifdef CONFIG_S3C_DEV_I2C1
	.id		  = 0,                              
#else
	.id		  = -1,
#endif
	.num_resources	  = ARRAY_SIZE(s3c_i2c_resource),
	.resource	  = s3c_i2c_resource,
};

static struct s3c2410_platform_i2c default_i2c_data0 __initdata = {
	.flags		= 0,
	.slave_addr	= 0x10,                             (1.4)
	.frequency	= 100*1000,                         (1.5)
	.sda_delay	= 100,
};

void __init s3c_i2c0_set_platdata(struct s3c2410_platform_i2c *pd)
{
	struct s3c2410_platform_i2c *npd;

	if (!pd)
		pd = &default_i2c_data0;

	npd = kmemdup(pd, sizeof(struct s3c2410_platform_i2c), GFP_KERNEL);
	if (!npd)
		printk(KERN_ERR "%s: no memory for platform data\n", __func__);
	else if (!npd->cfg_gpio)
		npd->cfg_gpio = s3c_i2c0_cfg_gpio;

	s3c_device_i2c0.dev.platform_data = npd;
}
(1.1) Chip I2C register start address

(1.2) End address of chip I2C register

(1.3) The name of the default platform device is s3c2410-i2c , which is used to match the platform driver.

(1.4) The device address of the default slave device

(1.5) Default I2C clock frequency

(2.0) Call platform_add_devices to add the I2C platform device platform device.


At this point of initialization, the platform device is not bound to the driver, because the i2c platform driver has not been initialized.


illustrate:

1. The analyzed kernel version is linux2.6.32.2

2. The development board is the friendly arm mini2440, using the ARM9 (S3C2440A) processor

3. The linked IIC device is EEPROM (AT24C02)

4. Analyze the registration order of the kernel I2C subsystem.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324764450&siteId=291194637