ARM 设备树

https://www.kernel.org/doc/Documentation/devicetree/usage-model.txt

The “ Open Firmware Device Tree” , or simply Device Tree (DT), is a data
structure and language for describing hardware. More specifically, it is a
description of hardware that is readable by an operating system
so that the operating system doesn’t need to hard code details of the
machine.

提供一种语言来解耦硬件配置信息

  • 最早: 2005 PowerPC Linux
  • 现在: arm, microblaze, mips, powerpc, sparc, x86 Openrisc, c6x
    X86: arch/x86/platform/ce4100 (intel凌动处理器)

设备端

使用设备树之前, 硬件的描述信息放置到一个个arch/xxx/mach-xxx/board-xxx.c的C文件中,例如下面的程序

static struct resource dm9000_resource1[] = {
   
    {
   
    .start = 0x20100000,
    .end = 0x20100000 + 1,
    .flags = IORESOURCE_MEM
    …
    .start = IRQ_PF15,
    .end = IRQ_PF15,
    .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE
    }
};

static struct platform_device dm9000_device1 = {
   
    .name = "dm9000",
    .id = 0,
    .num_resources = ARRAY_SIZE(dm9000_resource1),
    .resource = dm9000_resource1,
};

static struct platform_device *ip0x_devices[] __initdata = {
   
    &dm9000_device1,
    &dm9000_device2,
};
static int __init ip0x_init(void)
{
   
    platform_add_devices(ip0x_devices, ARRAY_SIZE(ip0x_devices));
}

由于硬件的信息使用代码描述 Linus 发邮件给 ARM 社区

ARM: F*cking pain in the ass

Gaah. Guys, this whole ARM thing is a
f*cking pain in the ass.

Linus, 2011,
http://lkml.org/lkml/2011/3/17/492

使用设备树之后, 硬件的描述信息,放置到一个个arch/xxx/boot/dts目录的.dtsi和.dts文件中 arch/powerpc/boot/dts 和 arch/arm/boot/dts

使用了设备树之后就可以很好的用 DTS 进行描述硬件资源,驱动可以在 c 里实现

驱动端

驱动从 DTS 读取硬件信息: drivers/xxx/

static int dm9000_probe(struct platform_device *pdev)
{
   
    …
    db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
    db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
    db->irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);}
static struct dm9000_plat_data *dm9000_parse_dt(struct device *dev)
{
   
    ...
    if (of_find_property(np, "davicom,ext-phy", NULL))
        pdata->flags |= DM9000_PLATF_EXT_PHY;
    if (of_find_property(np, "davicom,no-eeprom", NULL))
        pdata->flags |= DM9000_PLATF_NO_EEPROM;
    mac_addr = of_get_mac_address(np);
    ...
}
static struct platform_driver dm9000_driver = {
   
    .driver = {
   
    .name = "dm9000",
    .pm = &dm9000_drv_pm_ops
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值