linux设备驱动:xx_driver结构体中成员driver.of_match_table、id_table和设备树的关系

内容属个人理解

linux设备驱动:xx_driver结构体中成员driver.of_match_table、id_table和设备树的关系_第1张图片
id_table
driver.of_mach_table
设备树中
compatible = “myvendor,wm5102”
匹配优先级
of_match_table>id_table
of_match_table表中的厂商和设备树中条目compatible(包含供应商字符串) 的厂商“myvendor”不匹配,则会用id_table去匹配设备树条目compatible (不包含供应商字符串)。

添加I2C设备驱动的方法

一、确定I2C总线号的情况

1.1
static struct i2c_board_info h4_i2c_board_info[] __initdata = {
	{
		I2C_BOARD_INFO("isp1301_omap", 0x2d),
		.irq		= OMAP_GPIO_IRQ(125),
	},
	{	/* EEPROM on mainboard */
		I2C_BOARD_INFO("24c01", 0x52),
		.platform_data	= &m24c01,
	},
	{	/* EEPROM on cpu card */
		I2C_BOARD_INFO("24c01", 0x57),
		.platform_data	= &m24c01,
	},
};

static void __init omap_h4_init(void)
{
	(...)
	i2c_register_board_info(1, h4_i2c_board_info,
			ARRAY_SIZE(h4_i2c_board_info));
	(...)
}

1.2 通过标题设备树
Example:

	i2c1: i2c@400a0000 {
		/* ... master properties skipped ... */
		clock-frequency = <100000>;

		flash@50 {
			compatible = "atmel,24c256";
			reg = <0x50>;
		};

		pca9532: gpio@60 {
			compatible = "nxp,pca9532";
			gpio-controller;
			#gpio-cells = <2>;
			reg = <0x60>;
		};
	};

Here, two devices are attached to the bus using a speed of 100kHz. For
additional properties which might be needed to set up the device, please refer
to its devicetree documentation in Documentation/devicetree/bindings/.

1c、通过ACPI
这个地方暂时忽略

二、不确定总线号的情况

static struct i2c_board_info sfe4001_hwmon_info = {
	I2C_BOARD_INFO("max6647", 0x4e),
};

int sfe4001_init(struct efx_nic *efx)
{
	(...)
	efx->board_info.hwmon_client =
		i2c_new_device(&efx->i2c_adap, &sfe4001_hwmon_info);

	(...)
}

这部分参考:i2c设备驱动示例说明
参考:
1、linux id_table与of_match_table
2、设备树说明文档
添加链接描述linux设备驱动:xx_driver结构体中成员driver.of_match_table、id_table和设备树的关系_第2张图片

你可能感兴趣的:(LINUX)