设备树中设备的禁用和启用

device tree中的status标识了设备的状态,使用status可以去禁止设备或者启用设备,看下设备树规范中的status可选值

这里写图片描述

默认情况下不设置status属性设备是使能的,下面看两具体的例子 
这里写图片描述 
这里写图片描述

下面是设备树中节点属性status的处理代码,位于内核的drivers/of/base.c中

static bool __of_device_is_available(const struct device_node *device)
{
    const char *status;
    int statlen;

    if (!device)
        return false;

    status = __of_get_property(device, "status", &statlen);
    if (status == NULL)
        return true; //默认为使能

    if (statlen > 0) {
        if (!strcmp(status, "okay") || !strcmp(status, "ok")) //ok和okay都可以
            return true;
    }
    //表中的fail和fail-sss没做具体处理
    return false;
}

/**
 *  of_device_is_available - check if a device is available for use
 *
 *  @device: Node to check for availability
 *
 *  Returns true if the status property is absent or set to "okay" or "ok",
 *  false otherwise
 */
bool of_device_is_available(const struct device_node *device)
{
    unsigned long flags;
    bool res;

    raw_spin_lock_irqsave(&devtree_lock, flags);
    res = __of_device_is_available(device);
    raw_spin_unlock_irqrestore(&devtree_lock, flags);
    return res;

}
EXPORT_SYMBOL(of_device_is_available);

猜你喜欢

转载自blog.csdn.net/michaelcao1980/article/details/79423452