学习永无止境!!
分类: 嵌入式
2017-07-05 10:38:56
Device Tree就是为了取代板级信息代码而推出的。所以,大量在arch/arm/plat-xxxx, arch/arm/mach-xxxx中做的工作不再是必要的了。
A: 注册platform_device,绑定resource,即内存、IRQ等板级信息
形如:
static struct resource xxx_resources[] = {
[0] = {
.start = …,
.end = …,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = …,
.end = …,
.flags = IORESOURCE_IRQ,
},
};
static struct platform_device xxx_device = {
.name = "xxx",
.id = -1,
.dev = {
.platform_data = &xxx_data,
},
.resource = xxx_resources,
.num_resources = ARRAY_SIZE(xxx_resources),
};
之类的platform_device代码都不再需要,其中platform_device会由kernel通过解析fdt自动展开。而这些resource实际来源于.dts中设备结点的reg、interrupts属性。典型地,大多数总线都与“simple_bus”兼容,而在SoC对应的machine的.init_machine成员函数中,调用of_platform_bus_probe(NULL, xxx_of_bus_ids, NULL);即可自动展开所有的platform_device。譬如,假设我们有个XXX SoC,则可在arch/arm/mach-xxx/的板文件中透过如下方式展开.dts中的设备结点对应的platform_device:
static struct of_device_id xxx_of_bus_ids[] __initdata = {
{ .compatible = "simple-bus", },
{},
};
void __init xxx_mach_init(void)
{
of_platform_bus_probe(NULL, xxx_of_bus_ids, NULL);
}
#ifdef CONFIG_ARCH_XXX
DT_MACHINE_START(XXX_DT, "Generic XXX (Flattened Device Tree)")
…
.init_machine = xxx_mach_init,
…
MACHINE_END
#endif
B. 注册i2c_board_info,指定IRQ等board级别信息:
static struct i2c_board_info __initdata inv_mpu9250_i2c0_board_info[] = {
{
I2C_BOARD_INFO(MPU_GYRO_NAME, MPU_GYRO_ADDR),// MPU_GYRO_ADDR=0x68
.platform_data = &mpu9250_gyro_data,
},
{
I2C_BOARD_INFO(MPU_BMP_NAME, MPU_BMP_ADDR),
.platform_data = &mpu_bmp_pdata,
},
{
I2C_BOARD_INFO(MPU_COMPASS_NAME, MPU_COMPASS_ADDR),
.platform_data = &mpu_compass_data,
},
};
inv_mpu9250_i2c0_board_info[0].irq = gpio_to_irq(MPU_GYRO_IRQ_GPIO);
i2c_register_board_info(gyro_bus_num, inv_mpu9250_i2c0_board_info, ARRAY_SIZE(inv_mpu9250_i2c0_board_info));
可以在dtsi中修改为:
/ {
{
{
compatible = "invensense,mpu6515";
reg = <0x68>;
interrupt-parent = <&gpio>;
interrupts = <169 0x01>;
invensense,int_config = <0x10>;
invensense,level_shifter = <0>;
invensense,orientation = [ff 00 00 00 01 00 00 00 ff];
invensense,sec_slave_type = <0>;
invensense,key = [4e cc 7e eb f6 1e 35 22
00 34 0d 65 32 e9 94 89];
vlogic-supply = <&palmas_smps8>;
vdd-supply = <&palmas_smps9>;
};
{
compatible = "ak,ak8963";
reg = <0x0c>;
orientation = [ff 00 00 00 01 00 00 00 ff];
config = "mpu";
vid-supply = <&palmas_smps8>;
vdd-supply = <&palmas_smps9>;
};
};
};