i2c_add_adapter、i2c_add_numbered_adapter 是注册 i2c_adapter,这两个 API 最终是调用 i2c_register_adapter。
static int i2c_register_adapter(struct i2c_adapter *adap)
{
......
dev_set_name(&adap- >dev, "i2c-%d", adap- >nr);
adap- >dev.bus = &i2c_bus_type;
adap- >dev.type = &i2c_adapter_type;
res = device_register(&adap- >dev);
/* create pre-declared device nodes */
of_i2c_register_devices(adap);
i2c_acpi_install_space_handler(adap);
i2c_acpi_register_devices(adap);
.....
}
dev_set_name(&adap->dev, "i2c-%d", adap->nr) 会在 Linux 中自动创建 /sys/devices/platform/11f00000.i2c6/i2c-6 节点。
of_i2c_register_devices 会调用 i2c_new_client_device
struct i2c_client *i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
{
......
client- >dev.parent = &client- >adapter- >dev;
client- >dev.bus = &i2c_bus_type;
client- >dev.type = &i2c_client_type;
client- >dev.of_node = of_node_get(info- >of_node);
client- >dev.fwnode = info- >fwnode;
device_enable_async_suspend(&client- >dev);
i2c_dev_set_name(adap, client, info);
......
status = device_register(&client- >dev);
......
}
i2c_dev_set_name 会在 Linux 系统中自动创建 /sys/devices/platform/11f00000.i2c6/i2c-6/6-0058 ,这里是挂在某个 i2c bus 上的,从机地址为 0x58 的设备节点。
到这里,大家应该能看懂下图,这些节点在 I2C 控制器驱动加载时,自动创建的。大家在 I2C 控制器的子节点中声明的 I2C 从机设备,也会在这一步创建节点。
全部0条评论
快来发表一下你的评论吧 !